Add a way to count number of handled packets (for debugging)

This commit is contained in:
indev committed 2024-06-12 21:05:21 +03:00
1 parent 3412bb5380
commit 86395d4d8b
3 files changed
+31 -2

No files matched your search

+20
View File
@@ -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);
+10 -2
View File
@@ -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)
{
+1
View File
@@ -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