Network: Fix error logging for 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
This commit is contained in:
		@@ -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 '%s' (%s)", this->admin_name.c_str(), this->admin_version.c_str());
 | 
			
		||||
		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 %d from '%s' (%s)", type, this->admin_name.c_str(), this->admin_version.c_str());
 | 
			
		||||
			} else {
 | 
			
		||||
				DEBUG(net, 0, "[tcp/admin] Received illegal packet from '%s' (%s)", this->admin_name.c_str(), this->admin_version.c_str());
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			DEBUG(net, 0, "[tcp/admin] Received invalid packet type %d from '%s' (%s)", type, this->admin_name.c_str(), this->admin_version.c_str());
 | 
			
		||||
			this->CloseConnection();
 | 
			
		||||
			return NETWORK_RECV_STATUS_MALFORMED_PACKET;
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -131,12 +131,18 @@ NetworkRecvStatus NetworkGameSocketHandler::HandlePacket(Packet *p)
 | 
			
		||||
{
 | 
			
		||||
	PacketGameType type = (PacketGameType)p->Recv_uint8();
 | 
			
		||||
 | 
			
		||||
	if (this->HasClientQuit()) {
 | 
			
		||||
		DEBUG(net, 0, "[tcp/game] Received invalid packet from client %d", this->client_id);
 | 
			
		||||
		this->CloseConnection();
 | 
			
		||||
		return NETWORK_RECV_STATUS_MALFORMED_PACKET;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this->last_packet = std::chrono::steady_clock::now();
 | 
			
		||||
	this->last_pkt_type = type;
 | 
			
		||||
 | 
			
		||||
	DEBUG(net, 5, "[tcp/game] received packet type %d (%s) from client %d, %s", type, GetPacketGameTypeName(type), this->client_id, this->GetDebugInfo().c_str());
 | 
			
		||||
 | 
			
		||||
	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);
 | 
			
		||||
@@ -190,13 +196,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 %d from client %d", type, this->client_id);
 | 
			
		||||
			this->CloseConnection();
 | 
			
		||||
 | 
			
		||||
			if (this->HasClientQuit()) {
 | 
			
		||||
				DEBUG(net, 0, "[tcp/game] Received invalid packet type %d from client %d", type, this->client_id);
 | 
			
		||||
			} else {
 | 
			
		||||
				DEBUG(net, 0, "[tcp/game] Received illegal packet from client %d", this->client_id);
 | 
			
		||||
			}
 | 
			
		||||
			return NETWORK_RECV_STATUS_MALFORMED_PACKET;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user