本文整理汇总了C++中OutputMessagePool::send方法的典型用法代码示例。如果您正苦于以下问题:C++ OutputMessagePool::send方法的具体用法?C++ OutputMessagePool::send怎么用?C++ OutputMessagePool::send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutputMessagePool
的用法示例。
在下文中一共展示了OutputMessagePool::send方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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");
//.........这里部分代码省略.........