Fix: Error logging in game and admin server HandlePacket

Don't invent a packet type in the log message if we can't/don't
read a packet type at all.
Fix packet type not being logged when appropriate.
This commit is contained in:
Jonathan G Rennison 2023-06-16 20:48:41 +01:00 committed by Charles Pigott
parent 6dc5c4fff5
commit a19826247e
2 changed files with 16 additions and 14 deletions

View File

@ -47,7 +47,13 @@ NetworkRecvStatus NetworkAdminSocketHandler::HandlePacket(Packet *p)
{
PacketAdminType type = (PacketAdminType)p->Recv_uint8();
switch (this->HasClientQuit() ? INVALID_ADMIN_PACKET : type) {
if (this->HasClientQuit()) {
Debug(net, 0, "[tcp/admin] Received invalid packet from '{}' ({})", this->admin_name, this->admin_version);
this->CloseConnection();
return NETWORK_RECV_STATUS_MALFORMED_PACKET;
}
switch (type) {
case ADMIN_PACKET_ADMIN_JOIN: return this->Receive_ADMIN_JOIN(p);
case ADMIN_PACKET_ADMIN_QUIT: return this->Receive_ADMIN_QUIT(p);
case ADMIN_PACKET_ADMIN_UPDATE_FREQUENCY: return this->Receive_ADMIN_UPDATE_FREQUENCY(p);
@ -87,12 +93,7 @@ NetworkRecvStatus NetworkAdminSocketHandler::HandlePacket(Packet *p)
case ADMIN_PACKET_SERVER_PONG: return this->Receive_SERVER_PONG(p);
default:
if (this->HasClientQuit()) {
Debug(net, 0, "[tcp/admin] Received invalid packet type {} from '{}' ({})", type, this->admin_name, this->admin_version);
} else {
Debug(net, 0, "[tcp/admin] Received illegal packet from '{}' ({})", this->admin_name, this->admin_version);
}
Debug(net, 0, "[tcp/admin] Received invalid packet type {} from '{}' ({})", type, this->admin_name, this->admin_version);
this->CloseConnection();
return NETWORK_RECV_STATUS_MALFORMED_PACKET;
}

View File

@ -64,9 +64,15 @@ NetworkRecvStatus NetworkGameSocketHandler::HandlePacket(Packet *p)
{
PacketGameType type = (PacketGameType)p->Recv_uint8();
if (this->HasClientQuit()) {
Debug(net, 0, "[tcp/game] Received invalid packet from client {}", this->client_id);
this->CloseConnection();
return NETWORK_RECV_STATUS_MALFORMED_PACKET;
}
this->last_packet = std::chrono::steady_clock::now();
switch (this->HasClientQuit() ? PACKET_END : type) {
switch (type) {
case PACKET_SERVER_FULL: return this->Receive_SERVER_FULL(p);
case PACKET_SERVER_BANNED: return this->Receive_SERVER_BANNED(p);
case PACKET_CLIENT_JOIN: return this->Receive_CLIENT_JOIN(p);
@ -113,13 +119,8 @@ NetworkRecvStatus NetworkGameSocketHandler::HandlePacket(Packet *p)
case PACKET_SERVER_CONFIG_UPDATE: return this->Receive_SERVER_CONFIG_UPDATE(p);
default:
Debug(net, 0, "[tcp/game] Received invalid packet type {} from client {}", type, this->client_id);
this->CloseConnection();
if (this->HasClientQuit()) {
Debug(net, 0, "[tcp/game] Received invalid packet type {} from client {}", type, this->client_id);
} else {
Debug(net, 0, "[tcp/game] Received illegal packet from client {}", this->client_id);
}
return NETWORK_RECV_STATUS_MALFORMED_PACKET;
}
}