本文整理汇总了C++中NetworkMessage::getString方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkMessage::getString方法的具体用法?C++ NetworkMessage::getString怎么用?C++ NetworkMessage::getString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkMessage
的用法示例。
在下文中一共展示了NetworkMessage::getString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onRecvFirstMessage
void ProtocolStatus::onRecvFirstMessage(NetworkMessage& msg)
{
uint32_t ip = getIP();
if (ip != 0x0100007F) {
std::string ipStr = convertIPToString(ip);
if (ipStr != g_config.getString(ConfigManager::IP)) {
std::map<uint32_t, int64_t>::const_iterator it = ipConnectMap.find(ip);
if (it != ipConnectMap.end() && (OTSYS_TIME() < (it->second + g_config.getNumber(ConfigManager::STATUSQUERY_TIMEOUT)))) {
disconnect();
return;
}
}
}
ipConnectMap[ip] = OTSYS_TIME();
switch (msg.getByte()) {
//XML info protocol
case 0xFF: {
if (msg.getString(4) == "info") {
g_dispatcher.addTask(createTask(std::bind(&ProtocolStatus::sendStatusString,
std::static_pointer_cast<ProtocolStatus>(shared_from_this()))));
return;
}
break;
}
//Another ServerInfo protocol
case 0x01: {
uint16_t requestedInfo = msg.get<uint16_t>(); // only a Byte is necessary, though we could add new info here
std::string characterName;
if (requestedInfo & REQUEST_PLAYER_STATUS_INFO) {
characterName = msg.getString();
}
g_dispatcher.addTask(createTask(std::bind(&ProtocolStatus::sendInfo, std::static_pointer_cast<ProtocolStatus>(shared_from_this()),
requestedInfo, characterName)));
return;
}
default:
break;
}
disconnect();
}
示例2: parseSpectatorSay
void ProtocolSpectator::parseSpectatorSay(NetworkMessage& msg)
{
SpeakClasses type = (SpeakClasses)msg.getByte();
uint16_t channelId = 0;
if (type == TALKTYPE_CHANNEL_Y) {
channelId = msg.get<uint16_t>();
} else {
return;
}
const std::string text = msg.getString();
if (text.length() > 255 || channelId != CHANNEL_CAST || !client) {
return;
}
if (client) {
g_dispatcher.addTask(createTask(std::bind(&ProtocolGame::broadcastSpectatorMessage, client, text)));
}
}
示例3: onRecvFirstMessage
void ProtocolSpectator::onRecvFirstMessage(NetworkMessage& msg)
{
if (g_game.getGameState() == GAME_STATE_SHUTDOWN) {
getConnection()->close();
return;
}
operatingSystem = (OperatingSystem_t)msg.get<uint16_t>();
version = msg.get<uint16_t>();
msg.skipBytes(7); // U32 clientVersion, U8 clientType
if (!RSA_decrypt(msg)) {
getConnection()->close();
return;
}
uint32_t key[4];
key[0] = msg.get<uint32_t>();
key[1] = msg.get<uint32_t>();
key[2] = msg.get<uint32_t>();
key[3] = msg.get<uint32_t>();
enableXTEAEncryption();
setXTEAKey(key);
if (operatingSystem >= CLIENTOS_OTCLIENT_LINUX) {
NetworkMessage opcodeMessage;
opcodeMessage.addByte(0x32);
opcodeMessage.addByte(0x00);
opcodeMessage.add<uint16_t>(0x00);
writeToOutputBuffer(opcodeMessage);
}
msg.skipBytes(1); // gamemaster flag
std::string password = msg.getString();
std::string characterName = msg.getString();
uint32_t timeStamp = msg.get<uint32_t>();
uint8_t randNumber = msg.getByte();
if (m_challengeTimestamp != timeStamp || m_challengeRandom != randNumber) {
getConnection()->close();
return;
}
auto dispatchDisconnectClient = [this](const std::string& msg) {
g_dispatcher.addTask(createTask(
std::bind(&ProtocolSpectator::disconnectSpectator, this, msg)));
};
if (version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX) {
dispatchDisconnectClient("Only clients with protocol " CLIENT_VERSION_STR " allowed!");
return;
}
if (g_game.getGameState() == GAME_STATE_STARTUP) {
dispatchDisconnectClient("Gameworld is starting up. Please wait.");
return;
}
if (g_game.getGameState() == GAME_STATE_MAINTAIN) {
dispatchDisconnectClient("Gameworld is under maintenance. Please re-connect in a while.");
return;
}
BanInfo banInfo;
if (IOBan::isIpBanned(getIP(), banInfo)) {
if (banInfo.reason.empty()) {
banInfo.reason = "(none)";
}
std::ostringstream ss;
ss << "Your IP has been banned until " << formatDateShort(banInfo.expiresAt) << " by " << banInfo.bannedBy << ".\n\nReason specified:\n" << banInfo.reason;
dispatchDisconnectClient(ss.str());
return;
}
password.erase(password.begin());
g_dispatcher.addTask(createTask(std::bind(&ProtocolSpectator::login, this, characterName, password)));
}
示例4: onRecvFirstMessage
void ProtocolLogin::onRecvFirstMessage(NetworkMessage& msg)
{
if (g_game.getGameState() == GAME_STATE_SHUTDOWN) {
getConnection()->close();
return;
}
msg.skipBytes(2); // client OS
uint16_t version = msg.get<uint16_t>();
if (version >= 971) {
msg.skipBytes(17);
} else {
msg.skipBytes(12);
}
/*
* Skipped bytes:
* 4 bytes: protocolVersion
* 12 bytes: dat, spr, pic signatures (4 bytes each)
* 1 byte: 0
*/
#define dispatchDisconnectClient(err) g_dispatcher.addTask(createTask(std::bind(&ProtocolLogin::disconnectClient, this, err, version)))
if (version <= 760) {
dispatchDisconnectClient("Only clients with protocol " CLIENT_VERSION_STR " allowed!");
return;
}
if (!Protocol::RSA_decrypt(msg)) {
getConnection()->close();
return;
}
uint32_t key[4];
key[0] = msg.get<uint32_t>();
key[1] = msg.get<uint32_t>();
key[2] = msg.get<uint32_t>();
key[3] = msg.get<uint32_t>();
enableXTEAEncryption();
setXTEAKey(key);
if (version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX) {
dispatchDisconnectClient("Only clients with protocol " CLIENT_VERSION_STR " allowed!");
return;
}
if (g_game.getGameState() == GAME_STATE_STARTUP) {
dispatchDisconnectClient("Gameworld is starting up. Please wait.");
return;
}
if (g_game.getGameState() == GAME_STATE_MAINTAIN) {
dispatchDisconnectClient("Gameworld is under maintenance.\nPlease re-connect in a while.");
return;
}
BanInfo banInfo;
if (IOBan::isIpBanned(getConnection()->getIP(), banInfo)) {
if (banInfo.reason.empty()) {
banInfo.reason = "(none)";
}
std::ostringstream ss;
ss << "Your IP has been banned until " << formatDateShort(banInfo.expiresAt) << " by " << banInfo.bannedBy << ".\n\nReason specified:\n" << banInfo.reason;
dispatchDisconnectClient(ss.str());
return;
}
std::string accountName = msg.getString();
std::string password = msg.getString();
if (accountName.empty()) {
if (!g_config.getBoolean(ConfigManager::ENABLE_LIVE_CASTING)) {
dispatchDisconnectClient("Invalid account name.");
} else {
g_dispatcher.addTask(createTask(std::bind(&ProtocolLogin::getCastingStreamsList, this, password, version)));
}
return;
}
#undef dispatchDisconnectClient
g_dispatcher.addTask(createTask(std::bind(&ProtocolLogin::getCharacterList, this, accountName, password, version)));
}
示例5: parsePacket
void ProtocolManager::parsePacket(NetworkMessage& msg)
{
if(g_game.getGameState() == GAMESTATE_SHUTDOWN)
{
getConnection()->close();
return;
}
uint8_t recvbyte = msg.get<char>();
OutputMessage_ptr output = getOutputBuffer();
if(!output)
return;
TRACK_MESSAGE(output);
switch(m_state)
{
case NO_LOGGED_IN:
{
if((time(NULL) - m_startTime) > 30000)
{
//login timeout
getConnection()->close();
addLogLine(LOGTYPE_WARNING, "Login timeout");
return;
}
if(m_loginTries > 3)
{
output->put<char>(MP_MSG_ERROR);
output->putString("Too many login attempts");
getConnection()->send(output);
getConnection()->close();
addLogLine(LOGTYPE_WARNING, "Too many login attempts");
return;
}
if(recvbyte != MP_MSG_LOGIN)
{
output->put<char>(MP_MSG_ERROR);
output->putString("You are not logged in");
getConnection()->send(output);
getConnection()->close();
addLogLine(LOGTYPE_WARNING, "Wrong command while not logged in");
return;
}
break;
}
case LOGGED_IN:
break;
default:
{
getConnection()->close();
addLogLine(LOGTYPE_ERROR, "No valid connection state");
return;
}
}
m_lastCommand = time(NULL);
switch(recvbyte)
{
case MP_MSG_LOGIN:
{
if(m_state == NO_LOGGED_IN)
{
std::string pass = msg.getString(), word = g_config.getString(ConfigManager::MANAGER_PASSWORD);
_encrypt(word, false);
if(pass == word)
{
if(!Manager::getInstance()->loginConnection(this))
{
output->put<char>(MP_MSG_FAILURE);
output->putString("Unknown connection");
getConnection()->send(output);
getConnection()->close();
addLogLine(LOGTYPE_ERROR, "Login failed due to unknown connection");
return;
}
else
{
m_state = LOGGED_IN;
output->put<char>(MP_MSG_USERS);
addLogLine(LOGTYPE_EVENT, "Logged in, sending users");
std::map<uint32_t, std::string> users;
for(AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it)
{
if(!it->second->isRemoved())
users[it->first] = it->second->getName();
}
output->put<uint16_t>(users.size());
for(std::map<uint32_t, std::string>::iterator it = users.begin(); it != users.end(); ++it)
{
output->put<uint32_t>(it->first);
output->putString(it->second);
//.........这里部分代码省略.........
示例6: onRecvFirstMessage
void ProtocolLogin::onRecvFirstMessage(NetworkMessage& msg)
{
if(
#if defined(WINDOWS) && !defined(_CONSOLE)
!GUI::getInstance()->m_connections ||
#endif
g_game.getGameState() == GAMESTATE_SHUTDOWN)
{
getConnection()->close();
return;
}
uint32_t clientIp = getConnection()->getIP();
msg.get<uint16_t>();
uint16_t version = msg.get<uint16_t>();
msg.skip(12);
#ifdef _MULTIPLATFORM77
if(!RSA_decrypt(msg))
{
getConnection()->close();
return;
}
uint32_t key[4] = {msg.get<uint32_t>(), msg.get<uint32_t>(), msg.get<uint32_t>(), msg.get<uint32_t>()};
enableXTEAEncryption();
setXTEAKey(key);
#endif
uint32_t name = msg.get<uint32_t>();
std::string password = msg.getString();
if(!name)
{
if(!g_config.getBool(ConfigManager::ACCOUNT_MANAGER))
{
disconnectClient(0x0A, "Invalid account name.");
return;
}
name = 1;
password = "1";
}
if(!g_config.getBool(ConfigManager::MANUAL_ADVANCED_CONFIG))
{
if(version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX)
{
disconnectClient(0x0A, CLIENT_VERSION_STRING);
return;
}
else
if(version < g_config.getNumber(ConfigManager::VERSION_MIN) || version > g_config.getNumber(ConfigManager::VERSION_MAX))
{
disconnectClient(0x0A, g_config.getString(ConfigManager::VERSION_MSG).c_str());
return;
}
}
#ifdef CLIENT_VERSION_DATA
if(sprSignature != CLIENT_VERSION_SPR)
{
disconnectClient(0x0A, CLIENT_VERSION_DATA);
return;
}
if(datSignature != CLIENT_VERSION_DAT)
{
disconnectClient(0x0A, CLIENT_VERSION_DATA);
return;
}
if(picSignature != CLIENT_VERSION_PIC)
{
disconnectClient(0x0A, CLIENT_VERSION_DATA);
return;
}
#endif
if(g_game.getGameState() < GAMESTATE_NORMAL)
{
disconnectClient(0x0A, "Server is just starting up, please wait.");
return;
}
if(g_game.getGameState() == GAMESTATE_MAINTAIN)
{
disconnectClient(0x0A, "Server is under maintenance, please re-connect in a while.");
return;
}
if(ConnectionManager::getInstance()->isDisabled(clientIp, protocolId))
{
disconnectClient(0x0A, "Too many connections attempts from your IP address, please try again later.");
return;
}
if(IOBan::getInstance()->isIpBanished(clientIp))
{
disconnectClient(0x0A, "Your IP is banished!");
return;
//.........这里部分代码省略.........
示例7: onRecvFirstMessage
void ProtocolLogin::onRecvFirstMessage(NetworkMessage& msg)
{
if (g_game.getGameState() == GAME_STATE_SHUTDOWN) {
disconnect();
return;
}
/*uint16_t clientos = */
msg.get<uint16_t>();
uint16_t version = msg.get<uint16_t>();
msg.skipBytes(12);
/*
* Skipped bytes:
* 4 bytes: protocolVersion
* 12 bytes: dat, spr, pic signatures (4 bytes each)
* 1 byte: 0
*/
if (version <= 760) {
disconnectClient("Only clients with protocol " CLIENT_VERSION_STR " allowed!");
return;
}
if (!Protocol::RSA_decrypt(msg)) {
disconnect();
return;
}
uint32_t key[4];
key[0] = msg.get<uint32_t>();
key[1] = msg.get<uint32_t>();
key[2] = msg.get<uint32_t>();
key[3] = msg.get<uint32_t>();
enableXTEAEncryption();
setXTEAKey(key);
uint32_t accountName = msg.get<uint32_t>();
std::string password = msg.getString();
if (version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX) {
disconnectClient("Only clients with protocol " CLIENT_VERSION_STR " allowed!");
return;
}
if (g_game.getGameState() == GAME_STATE_STARTUP) {
disconnectClient("Gameworld is starting up. Please wait.");
return;
}
if (g_game.getGameState() == GAME_STATE_MAINTAIN) {
disconnectClient("Gameworld is under maintenance.\nPlease re-connect in a while.");
return;
}
BanInfo banInfo;
auto connection = getConnection();
if (!connection) {
return;
}
if (IOBan::isIpBanned(connection->getIP(), banInfo)) {
if (banInfo.reason.empty()) {
banInfo.reason = "(none)";
}
std::ostringstream ss;
ss << "Your IP has been banned until " << formatDateShort(banInfo.expiresAt) << " by " << banInfo.bannedBy << ".\n\nReason specified:\n" << banInfo.reason;
disconnectClient(ss.str());
return;
}
if (accountName == 0) {
disconnectClient("Invalid account name.");
return;
}
auto thisPtr = std::dynamic_pointer_cast<ProtocolLogin>(shared_from_this());
g_dispatcher.addTask(createTask(std::bind(&ProtocolLogin::getCharacterList, thisPtr, accountName, password)));
}
示例8: parsePacket
//.........这里部分代码省略.........
output->put<char>(AP_MSG_ERROR);
output->putString("you are not logged in");
OutputMessagePool::getInstance()->send(output);
getConnection()->close();
addLogLine(LOGTYPE_EVENT, "wrong command while NO_LOGGED_IN");
return;
}
}
else
m_state = LOGGED_IN;
break;
}
case LOGGED_IN:
break;
default:
{
getConnection()->close();
addLogLine(LOGTYPE_EVENT, "no valid connection state!!!");
return;
}
}
m_lastCommand = time(NULL);
switch(recvbyte)
{
case AP_MSG_LOGIN:
{
if(m_state == NO_LOGGED_IN && g_config.getBool(ConfigManager::ADMIN_REQUIRE_LOGIN))
{
std::string pass = msg.getString(), word = g_config.getString(ConfigManager::ADMIN_PASSWORD);
_encrypt(word, false);
if(pass == word)
{
m_state = LOGGED_IN;
output->put<char>(AP_MSG_LOGIN_OK);
addLogLine(LOGTYPE_EVENT, "login ok");
}
else
{
m_loginTries++;
output->put<char>(AP_MSG_LOGIN_FAILED);
output->putString("wrong password");
addLogLine(LOGTYPE_EVENT, "login failed.("+ pass + ")");
}
}
else
{
output->put<char>(AP_MSG_LOGIN_FAILED);
output->putString("cannot login");
addLogLine(LOGTYPE_EVENT, "wrong state at login");
}
break;
}
case AP_MSG_ENCRYPTION:
{
if(m_state == ENCRYPTION_NO_SET && Admin::getInstance()->isEncypted())
{
uint8_t keyType = msg.get<char>();
switch(keyType)
{