本文整理汇总了C++中OutputMessage_ptr::AddBytes方法的典型用法代码示例。如果您正苦于以下问题:C++ OutputMessage_ptr::AddBytes方法的具体用法?C++ OutputMessage_ptr::AddBytes怎么用?C++ OutputMessage_ptr::AddBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutputMessage_ptr
的用法示例。
在下文中一共展示了OutputMessage_ptr::AddBytes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parsePacket
//.........这里部分代码省略.........
addLogLine(this, LOGTYPE_WARNING, 1, "wrong encrypted packet");
}
} else {
output->AddByte(AP_MSG_ENCRYPTION_FAILED);
output->AddString("no valid key type");
addLogLine(this, LOGTYPE_WARNING, 1, "no valid client key type");
}
} else {
output->AddByte(AP_MSG_ENCRYPTION_FAILED);
output->AddString("can not set encryption");
addLogLine(this, LOGTYPE_EVENT, 1, "can not set encryption");
}
break;
}
case AP_MSG_KEY_EXCHANGE: {
if (m_state == ENCRYPTION_NO_SET && g_adminConfig->requireEncryption()) {
uint8_t keyType = msg.GetByte();
if (keyType == ENCRYPTION_RSA1024XTEA) {
RSA* rsa = g_adminConfig->getRSAKey(ENCRYPTION_RSA1024XTEA);
if (!rsa) {
output->AddByte(AP_MSG_KEY_EXCHANGE_FAILED);
addLogLine(this, LOGTYPE_WARNING, 1, "no valid server key type");
break;
}
output->AddByte(AP_MSG_KEY_EXCHANGE_OK);
output->AddByte(ENCRYPTION_RSA1024XTEA);
char RSAPublicKey[128];
rsa->getPublicKey(RSAPublicKey);
output->AddBytes(RSAPublicKey, 128);
} else {
output->AddByte(AP_MSG_KEY_EXCHANGE_FAILED);
addLogLine(this, LOGTYPE_WARNING, 1, "no valid client key type");
}
} else {
output->AddByte(AP_MSG_KEY_EXCHANGE_FAILED);
output->AddString("can not get public key");
addLogLine(this, LOGTYPE_WARNING, 1, "can not get public key");
}
break;
}
case AP_MSG_COMMAND: {
if (m_state != LOGGED_IN) {
addLogLine(this, LOGTYPE_ERROR, 1, "recvbyte == AP_MSG_COMMAND && m_state != LOGGED_IN !!!");
// We should never reach this point
break;
}
uint8_t command = msg.GetByte();
switch (command) {
case CMD_BROADCAST: {
const std::string message = msg.GetString();
addLogLine(this, LOGTYPE_EVENT, 1, "broadcast: " + message);
g_dispatcher.addTask(createTask(boost::bind(&Game::broadcastMessage, &g_game, message, MSG_STATUS_WARNING)));
output->AddByte(AP_MSG_COMMAND_OK);
break;
}
case CMD_CLOSE_SERVER: {
示例2: sendStatusString
void ProtocolStatus::sendStatusString()
{
OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
if (!output) {
getConnection()->closeConnection();
return;
}
setRawMessages(true);
pugi::xml_document doc;
pugi::xml_node decl = doc.prepend_child(pugi::node_declaration);
decl.append_attribute("version") = "1.0";
pugi::xml_node tsqp = doc.append_child("tsqp");
tsqp.append_attribute("version") = "1.0";
pugi::xml_node serverinfo = tsqp.append_child("serverinfo");
uint64_t uptime = (OTSYS_TIME() - ProtocolStatus::start) / 1000;
serverinfo.append_attribute("uptime") = std::to_string(uptime).c_str();
serverinfo.append_attribute("ip") = g_config.getString(ConfigManager::IP).c_str();
serverinfo.append_attribute("servername") = g_config.getString(ConfigManager::SERVER_NAME).c_str();
serverinfo.append_attribute("port") = std::to_string((uint32_t)g_config.getNumber(ConfigManager::LOGIN_PORT)).c_str();
serverinfo.append_attribute("location") = g_config.getString(ConfigManager::LOCATION).c_str();
serverinfo.append_attribute("url") = g_config.getString(ConfigManager::URL).c_str();
serverinfo.append_attribute("server") = STATUS_SERVER_NAME;
serverinfo.append_attribute("version") = STATUS_SERVER_VERSION;
serverinfo.append_attribute("client") = CLIENT_VERSION_STR;
pugi::xml_node owner = tsqp.append_child("owner");
owner.append_attribute("name") = g_config.getString(ConfigManager::OWNER_NAME).c_str();
owner.append_attribute("email") = g_config.getString(ConfigManager::OWNER_EMAIL).c_str();
pugi::xml_node players = tsqp.append_child("players");
players.append_attribute("online") = std::to_string(g_game.getPlayersOnline()).c_str();
players.append_attribute("max") = std::to_string((uint32_t)g_config.getNumber(ConfigManager::MAX_PLAYERS)).c_str();
players.append_attribute("peak") = std::to_string(g_game.getPlayersRecord()).c_str();
pugi::xml_node monsters = tsqp.append_child("monsters");
monsters.append_attribute("total") = std::to_string(g_game.getMonstersOnline()).c_str();
pugi::xml_node npcs = tsqp.append_child("npcs");
npcs.append_attribute("total") = std::to_string(g_game.getNpcsOnline()).c_str();
pugi::xml_node rates = tsqp.append_child("rates");
rates.append_attribute("experience") = std::to_string((uint32_t)g_config.getNumber(ConfigManager::RATE_EXPERIENCE)).c_str();
rates.append_attribute("skill") = std::to_string((uint32_t)g_config.getNumber(ConfigManager::RATE_SKILL)).c_str();
rates.append_attribute("loot") = std::to_string((uint32_t)g_config.getNumber(ConfigManager::RATE_LOOT)).c_str();
rates.append_attribute("magic") = std::to_string((uint32_t)g_config.getNumber(ConfigManager::RATE_MAGIC)).c_str();
rates.append_attribute("spawn") = std::to_string((uint32_t)g_config.getNumber(ConfigManager::RATE_SPAWN)).c_str();
pugi::xml_node map = tsqp.append_child("map");
map.append_attribute("name") = g_config.getString(ConfigManager::MAP_NAME).c_str();
map.append_attribute("author") = g_config.getString(ConfigManager::MAP_AUTHOR).c_str();
uint32_t mapWidth, mapHeight;
g_game.getMapDimensions(mapWidth, mapHeight);
map.append_attribute("width") = std::to_string(mapWidth).c_str();
map.append_attribute("height") = std::to_string(mapHeight).c_str();
pugi::xml_node motd = tsqp.append_child("motd");
motd.text() = g_config.getString(ConfigManager::MOTD).c_str();
std::ostringstream ss;
doc.save(ss, "", pugi::format_raw);
std::string data = ss.str();
output->AddBytes(data.c_str(), data.size());
OutputMessagePool::getInstance()->send(output);
getConnection()->closeConnection();
}