diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 69c87a157..cab82e2cb 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -75,6 +75,8 @@ #define MAX_REASONLENGTH 30 #define FORCECLOSE 0x8000 +static UINT64 packetstat[NUMPACKETTYPE+1] = {0}; + boolean server = true; // true or false but !server == client #define client (!server) boolean nodownload = false; @@ -3106,6 +3108,17 @@ static void Command_connect(void) botskin = 0; CL_ConnectToServer(); } + +static void Command_Packetstat(void) +{ + CONS_Printf("Number of packets handled:\n"); + + for (UINT8 i = 0; i <= NUMPACKETTYPE; ++i) + { + CONS_Printf("%16s: %lu%s", Net_GetPacketName(i), packetstat[i], (i % 2 == 1) ? "\n" : "\t|\t"); + } +} + #endif static void ResetNode(INT32 node); @@ -3271,6 +3284,7 @@ void CL_Reset(void) // make sure we don't leave any fileneeded gunk over from a failed join fileneedednum = 0; memset(fileneeded, 0, sizeof(fileneeded)); + memset(packetstat, 0, sizeof(packetstat)); #ifndef NONET totalfilesrequestednum = 0; @@ -4025,6 +4039,7 @@ void D_ClientServerInit(void) COM_AddCommand("connect", Command_connect); COM_AddCommand("nodes", Command_Nodes); COM_AddCommand("listplayers", Command_Listplayers); + COM_AddCommand("packetstat", Command_Packetstat); #ifdef HAVE_CURL COM_AddCommand("set_http_login", Command_set_http_login); COM_AddCommand("list_http_logins", Command_list_http_logins); @@ -4123,6 +4138,7 @@ void SV_ResetServer(void) // clear server_context memset(server_context, '-', 8); + memset(packetstat, 0, sizeof(packetstat)); DEBFILE("\n-=-=-=-=-=-=-= Server Reset =-=-=-=-=-=-=-\n\n"); } @@ -5522,6 +5538,10 @@ static void GetPackets(void) if (netbuffer->packettype == PT_PLAYERINFO) continue; // We do nothing with PLAYERINFO, that's for the MS browser. + // We also count unknown packets, hence "<=" + if (netbuffer->packettype <= NUMPACKETTYPE) + ++packetstat[netbuffer->packettype]; + // Packet received from someone already playing if (nodeingame[node]) HandlePacketFromPlayer(node); diff --git a/src/d_net.c b/src/d_net.c index 6b45e009d..04db5f7c5 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -793,7 +793,7 @@ static void fprintfstringnewline(char *s, size_t len) } /// \warning Keep this up-to-date if you add/remove/rename packet types -static const char *packettypename[NUMPACKETTYPE] = +const char *packettypename[NUMPACKETTYPE] = { "NOTHING", "SERVERCFG", @@ -838,11 +838,19 @@ static const char *packettypename[NUMPACKETTYPE] = "PING" }; +const char *Net_GetPacketName(UINT8 packettype) +{ + if (packettype >= NUMPACKETTYPE) + return "UNKNOWN"; + + return packettypename[packettype]; +} + static void DebugPrintpacket(const char *header) { fprintf(debugfile, "%-12s (node %d,ack %d,ackret %d,size %d) type(%d) : %s\n", header, doomcom->remotenode, netbuffer->ack, netbuffer->ackreturn, doomcom->datalength, - netbuffer->packettype, packettypename[netbuffer->packettype]); + netbuffer->packettype, Net_GetPacketName(netbuffer->packettype)); switch (netbuffer->packettype) { diff --git a/src/d_net.h b/src/d_net.h index e267f5268..471881847 100644 --- a/src/d_net.h +++ b/src/d_net.h @@ -65,5 +65,6 @@ void Net_ConnectionTimeout(INT32 node); void Net_AbortPacketType(UINT8 packettype); void Net_SendAcks(INT32 node); void Net_WaitAllAckReceived(UINT32 timeout); +const char *Net_GetPacketName(UINT8 packettype); #endif