From 2450a0df70c80629a399ebd9f79e3e3bd838a9b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Sat, 11 Nov 2023 19:09:39 +0100 Subject: [PATCH 1/2] Do not send disconnected players' statuses to the MS --- src/netcode/d_clisrv.c | 11 +++++++++++ src/netcode/d_clisrv.h | 1 + src/netcode/server_connection.c | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/netcode/d_clisrv.c b/src/netcode/d_clisrv.c index 7804b068f..ac0b42d49 100644 --- a/src/netcode/d_clisrv.c +++ b/src/netcode/d_clisrv.c @@ -1618,6 +1618,17 @@ INT32 D_NumPlayers(void) return num; } +/** Returns the number of nodes on the server. + */ +INT32 D_NumNodes(void) +{ + INT32 num = 0; + for (INT32 ix = 0; ix < MAXNETNODES; ix++) + if (netnodes[ix].ingame) + num++; + return num; +} + /** Similar to the above, but counts only bots. * Purpose is to remove bots from both the player count and the * max player count on the server view diff --git a/src/netcode/d_clisrv.h b/src/netcode/d_clisrv.h index db9a780cd..092878421 100644 --- a/src/netcode/d_clisrv.h +++ b/src/netcode/d_clisrv.h @@ -121,6 +121,7 @@ extern char motd[254], server_context[8]; extern UINT8 playernode[MAXPLAYERS]; INT32 D_NumPlayers(void); +INT32 D_NumNodes(void); INT32 D_NumBots(void); tic_t GetLag(INT32 node); diff --git a/src/netcode/server_connection.c b/src/netcode/server_connection.c index 2164f411a..258d4cce4 100644 --- a/src/netcode/server_connection.c +++ b/src/netcode/server_connection.c @@ -109,7 +109,7 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime) netbuffer->u.serverinfo.leveltime = (tic_t)LONG(leveltime); // Exclude bots from both counts - netbuffer->u.serverinfo.numberofplayer = (UINT8)(D_NumPlayers() - D_NumBots()); + netbuffer->u.serverinfo.numberofplayer = (UINT8)D_NumNodes(); netbuffer->u.serverinfo.maxplayer = (UINT8)(cv_maxplayers.value - D_NumBots()); netbuffer->u.serverinfo.refusereason = GetRefuseReason(node); @@ -164,7 +164,7 @@ static void SV_SendPlayerInfo(INT32 node) for (UINT8 i = 0; i < MAXPLAYERS; i++) { - if (!playeringame[i]) + if (!netnodes[playernode[i]].ingame) { netbuffer->u.playerinfo[i].num = 255; // This slot is empty. continue; From fe87760c8c89f14186cb1c6395fe8fe0948dba33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Thu, 14 Dec 2023 17:15:07 +0100 Subject: [PATCH 2/2] Fix buffer overflow in SV_SendPlayerInfo --- src/netcode/server_connection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/netcode/server_connection.c b/src/netcode/server_connection.c index 258d4cce4..faff7e8dd 100644 --- a/src/netcode/server_connection.c +++ b/src/netcode/server_connection.c @@ -164,7 +164,7 @@ static void SV_SendPlayerInfo(INT32 node) for (UINT8 i = 0; i < MAXPLAYERS; i++) { - if (!netnodes[playernode[i]].ingame) + if (playernode[i] == UINT8_MAX || !netnodes[playernode[i]].ingame) { netbuffer->u.playerinfo[i].num = 255; // This slot is empty. continue;