Changeset - r27642:94cf4b1c58ae
[Not reviewed]
master
0 2 0
Jonathan G Rennison - 12 months ago 2023-06-16 19:48:41
j.g.rennison@gmail.com
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.
2 files changed with 16 insertions and 14 deletions:
0 comments (0 inline, 0 general)
src/network/core/tcp_admin.cpp
Show inline comments
 
@@ -47,7 +47,13 @@ NetworkRecvStatus NetworkAdminSocketHand
 
{
 
	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 NetworkAdminSocketHand
 
		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;
 
	}
src/network/core/tcp_game.cpp
Show inline comments
 
@@ -63,9 +63,15 @@ NetworkRecvStatus NetworkGameSocketHandl
 
{
 
	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 NetworkGameSocketHandl
 
		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;
 
	}
 
}
0 comments (0 inline, 0 general)