bool RealmSocket::recv(char *buf, size_t len) { bool ret = recv_soft(buf, len); if (ret) recv_skip(len); return ret; }
/// Read the packet from the client void AuthSocket::OnRead() { #define MAX_AUTH_LOGON_CHALLENGES_IN_A_ROW 3 uint32 challengesInARow = 0; uint8 _cmd; while (1) { if (!recv_soft((char*)&_cmd, 1)) return; if (_cmd == CMD_AUTH_LOGON_CHALLENGE) { ++challengesInARow; if (challengesInARow == MAX_AUTH_LOGON_CHALLENGES_IN_A_ROW) { DETAIL_LOG("Got %u CMD_AUTH_LOGON_CHALLENGE in a row from '%s', possible ongoing DoS", challengesInARow, get_remote_address().c_str()); close_connection(); return; } } size_t i; ///- Circle through known commands and call the correct command handler for (i = 0; i < AUTH_TOTAL_COMMANDS; ++i) { if ((uint8)table[i].cmd == _cmd && (table[i].status == STATUS_CONNECTED || (_authed && table[i].status == STATUS_AUTHED))) { DEBUG_LOG("[Auth] got data for cmd %u recv length %u", (uint32)_cmd, (uint32)recv_len()); if (!(*this.*table[i].handler)()) { DEBUG_LOG("Command handler failed for cmd %u recv length %u", (uint32)_cmd, (uint32)recv_len()); return; } break; } } ///- Report unknown commands in the debug log if (i == AUTH_TOTAL_COMMANDS) { DEBUG_LOG("[Auth] got unknown packet %u", (uint32)_cmd); return; } } }
/// Read the packet from the client bool AuthSocket::process_incoming_data() { uint8 _cmd; while (1) { if (!recv_soft((char*)&_cmd, 1)) return true; size_t i; ///- Circle through known commands and call the correct command handler for (i = 0; i < AUTH_TOTAL_COMMANDS; ++i) { if ((uint8)table[i].cmd == _cmd && (table[i].status == STATUS_CONNECTED || (_authed && table[i].status == STATUS_AUTHED))) { DEBUG_LOG("[Auth] got data for cmd %u recv length %u", (uint32)_cmd, (uint32)recv_len()); if (!(*this.*table[i].handler)()) { DEBUG_LOG("Command handler failed for cmd %u recv length %u", (uint32)_cmd, (uint32)recv_len()); return true; } break; } } ///- Report unknown commands in the debug log if (i == AUTH_TOTAL_COMMANDS) { DEBUG_LOG("[Auth] got unknown packet %u", (uint32)_cmd); return true; } } return true; }