本文整理汇总了C++中NetworkMessage::GetByte方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkMessage::GetByte方法的具体用法?C++ NetworkMessage::GetByte怎么用?C++ NetworkMessage::GetByte使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkMessage
的用法示例。
在下文中一共展示了NetworkMessage::GetByte方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()) {
if (OTSYS_TIME() < (it->second + g_config.getNumber(ConfigManager::STATUSQUERY_TIMEOUT))) {
getConnection()->closeConnection();
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, 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 infos here
std::string characterName;
if (requestedInfo & REQUEST_PLAYER_STATUS_INFO) {
characterName = msg.GetString();
}
g_dispatcher.addTask(createTask(std::bind(&ProtocolStatus::sendInfo, this, requestedInfo, characterName)));
return;
}
default:
break;
}
getConnection()->closeConnection();
}
示例2: parsePacket
void ProtocolAdmin::parsePacket(NetworkMessage& msg)
{
if (g_game.getGameState() == GAME_STATE_SHUTDOWN) {
getConnection()->closeConnection();
return;
}
uint8_t recvbyte = msg.GetByte();
OutputMessagePool* outputPool = OutputMessagePool::getInstance();
OutputMessage_ptr output = outputPool->getOutputMessage(this, false);
if (!output) {
return;
}
switch (m_state) {
case ENCRYPTION_NO_SET: {
if (g_adminConfig->requireEncryption()) {
if ((time(NULL) - m_startTime) > 30000) {
getConnection()->closeConnection();
addLogLine(this, LOGTYPE_WARNING, 1, "encryption timeout");
return;
}
if (recvbyte != AP_MSG_ENCRYPTION && recvbyte != AP_MSG_KEY_EXCHANGE) {
output->AddByte(AP_MSG_ERROR);
output->AddString("encryption needed");
outputPool->send(output);
getConnection()->closeConnection();
addLogLine(this, LOGTYPE_WARNING, 1, "wrong command while ENCRYPTION_NO_SET");
return;
}
break;
} else {
m_state = NO_LOGGED_IN;
}
}
case NO_LOGGED_IN: {
if (g_adminConfig->requireLogin()) {
if ((time(NULL) - m_startTime) > 30000) {
//login timeout
getConnection()->closeConnection();
addLogLine(this, LOGTYPE_WARNING, 1, "login timeout");
return;
}
if (m_loginTries > 3) {
output->AddByte(AP_MSG_ERROR);
output->AddString("too many login tries");
outputPool->send(output);
getConnection()->closeConnection();
addLogLine(this, LOGTYPE_WARNING, 1, "too many login tries");
return;
}
if (recvbyte != AP_MSG_LOGIN) {
output->AddByte(AP_MSG_ERROR);
output->AddString("you are not logged in");
outputPool->send(output);
getConnection()->closeConnection();
addLogLine(this, LOGTYPE_WARNING, 1, "wrong command while NO_LOGGED_IN");
return;
}
break;
} else {
m_state = LOGGED_IN;
}
}
case LOGGED_IN: {
//can execute commands
break;
}
default: {
getConnection()->closeConnection();
return;
}
}
m_lastCommand = time(NULL);
switch (recvbyte) {
case AP_MSG_LOGIN: {
if (m_state == NO_LOGGED_IN && g_adminConfig->requireLogin()) {
std::string password = msg.GetString();
if (g_adminConfig->passwordMatch(password)) {
m_state = LOGGED_IN;
output->AddByte(AP_MSG_LOGIN_OK);
addLogLine(this, LOGTYPE_EVENT, 1, "login ok");
} else {
m_loginTries++;
output->AddByte(AP_MSG_LOGIN_FAILED);
output->AddString("wrong password");
//.........这里部分代码省略.........