From 97f79a8866a42f45b48f7aea66a09616afacc07b Mon Sep 17 00:00:00 2001 From: Ashnal Date: Mon, 29 Aug 2022 16:58:33 -0400 Subject: [PATCH] Should fix the dedicated server player node takeover that completely destroys servers --- src/d_clisrv.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 073d2760..e937c518 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4334,6 +4334,11 @@ static void HandleConnect(SINT8 node) // If a server filled out, then it'd overwrite the host and turn everyone into weird husks..... // It's too much effort to legimately fix right now. Just prevent it from reaching that state. UINT8 maxplayers = min((dedicated ? MAXPLAYERS-1 : MAXPLAYERS), cv_maxplayers.value); + UINT8 connectedplayers = 0; + + for (UINT8 i = dedicated ? 1 : 0; i < MAXPLAYERS; i++) + if (playernode[i] != UINT8_MAX) // We use this to count players because it is affected by SV_AddWaitingPlayers when more than one client joins on the same tic, unlike playeringame and D_NumPlayers. UINT8_MAX denotes no node for that player + connectedplayers++; if (bannednode && bannednode[node].banid != SIZE_MAX) { @@ -4391,7 +4396,7 @@ static void HandleConnect(SINT8 node) { SV_SendRefuse(node, M_GetText("The server is not accepting\njoins for the moment.")); } - else if (D_NumPlayers() >= maxplayers) + else if (connectedplayers >= maxplayers) { SV_SendRefuse(node, va(M_GetText("Maximum players reached: %d"), maxplayers)); } @@ -4399,7 +4404,7 @@ static void HandleConnect(SINT8 node) { SV_SendRefuse(node, M_GetText("Too many players from\nthis node.")); } - else if (netgame && D_NumPlayers() + netbuffer->u.clientcfg.localplayers > maxplayers) + else if (netgame && connectedplayers + netbuffer->u.clientcfg.localplayers > maxplayers) { SV_SendRefuse(node, va(M_GetText("Number of local players\nwould exceed maximum: %d"), maxplayers)); }