mirror of https://github.com/OpenTTD/OpenTTD.git
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:
parent
43ddf19df3
commit
19ae88fb63
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -63,9 +63,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);
|
||||
|
@ -112,13 +118,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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue