本文整理汇总了C++中OutputMessage_ptr::addBytes方法的典型用法代码示例。如果您正苦于以下问题:C++ OutputMessage_ptr::addBytes方法的具体用法?C++ OutputMessage_ptr::addBytes怎么用?C++ OutputMessage_ptr::addBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutputMessage_ptr
的用法示例。
在下文中一共展示了OutputMessage_ptr::addBytes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sendStatusString
void ProtocolStatus::sendStatusString()
{
OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false);
if (!output) {
getConnection()->close();
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(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(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(g_config.getNumber(ConfigManager::RATE_EXPERIENCE)).c_str();
rates.append_attribute("skill") = std::to_string(g_config.getNumber(ConfigManager::RATE_SKILL)).c_str();
rates.append_attribute("loot") = std::to_string(g_config.getNumber(ConfigManager::RATE_LOOT)).c_str();
rates.append_attribute("magic") = std::to_string(g_config.getNumber(ConfigManager::RATE_MAGIC)).c_str();
rates.append_attribute("spawn") = std::to_string(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()->close();
}