From 60307da80e692990ccbc2514dd3ca6a1ded9afb0 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 12 Aug 2025 20:27:50 +0200 Subject: [PATCH] move dedi idle stuff into function + port smol cleanup from srb2 --- src/d_clisrv.c | 116 +++++++++++++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 48 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 54c7426f1..471715e17 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4396,6 +4396,7 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum) displayplayers[i] = newplayernum; DEBFILE("spawning me\n"); } + D_SendPlayerConfig(); addedtogame = true; } @@ -6770,6 +6771,69 @@ void NetKeepAlive(void) // If a tree falls in the forest but nobody is around to hear it, does it make a tic? #define DEDICATEDIDLETIME (10*TICRATE) +#ifdef DEDICATEDIDLETIME +static void DedicatedIdleUpdate(INT32 *realtics) +{ + INT32 i; + static tic_t dedicatedidle = 0; + + if (!server || !dedicated || gamestate != GS_LEVEL) + return; + + boolean empty = true; + for (i = 0; i < MAXPLAYERS; i++) + if (playeringame[i]) + { + empty = false; + break; + } + + if (empty) + { + if (leveltime == 2) + { + // On next tick... + dedicatedidle = DEDICATEDIDLETIME - 1; + } + else if (dedicatedidle >= DEDICATEDIDLETIME) + { + if (D_GetExistingTextcmd(gametic, 0) || D_GetExistingTextcmd(gametic + 1, 0)) + { + CONS_Printf("DEDICATED: Awakening from idle (Netxcmd detected...)\n"); + dedicatedidle = 0; + } + else + { + (*realtics) = 0; + } + } + else + { + dedicatedidle += (*realtics); + + if (dedicatedidle >= DEDICATEDIDLETIME) + { + const char *idlereason = "at round start"; + if (leveltime > 3) + idlereason = va("for %d seconds", dedicatedidle / TICRATE); + + CONS_Printf("DEDICATED: No players %s, idling...\n", idlereason); + (*realtics) = 0; + dedicatedidle = DEDICATEDIDLETIME; + } + } + } + else + { + if (dedicatedidle >= DEDICATEDIDLETIME) + { + CONS_Printf("DEDICATED: Awakening from idle (Player detected...)\n"); + } + dedicatedidle = 0; + } +} +#endif + void NetUpdate(void) { static tic_t resptime = 0; @@ -6783,54 +6847,6 @@ void NetUpdate(void) if (realtics <= 0) // nothing new to update return; -#ifdef DEDICATEDIDLETIME - if (server && dedicated && gamestate == GS_LEVEL) - { - static tic_t dedicatedidle = 0; - - for (i = 1; i < MAXNETNODES; ++i) - if (nodeingame[i]) - { - if (dedicatedidle == DEDICATEDIDLETIME) - { - CONS_Printf("DEDICATED: Awakening from idle (Node %d detected...)\n", i); - dedicatedidle = 0; - } - break; - } - - if (i == MAXNETNODES) - { - if (leveltime == 2) - { - // On next tick... - dedicatedidle = DEDICATEDIDLETIME-1; - } - else if (dedicatedidle == DEDICATEDIDLETIME) - { - if (D_GetExistingTextcmd(gametic, 0) || D_GetExistingTextcmd(gametic+1, 0)) - { - CONS_Printf("DEDICATED: Awakening from idle (Netxcmd detected...)\n"); - dedicatedidle = 0; - } - else - { - realtics = 0; - } - } - else if (++dedicatedidle == DEDICATEDIDLETIME) - { - const char *idlereason = "at round start"; - if (leveltime > 3) - idlereason = va("for %d seconds", dedicatedidle/TICRATE); - - CONS_Printf("DEDICATED: No nodes %s, idling...\n", idlereason); - realtics = 0; - } - } - } -#endif - if (realtics > 5) { if (server) @@ -6839,6 +6855,10 @@ void NetUpdate(void) realtics = 5; } +#ifdef DEDICATEDIDLETIME + DedicatedIdleUpdate(&realtics); +#endif + gametime = nowtime; UpdatePingTable();