From cbe5479712e5b9b5606de337cb681ac7b99fe532 Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 31 Oct 2022 20:55:52 +0000 Subject: [PATCH] EXPERIMENTAL: Dedicated server idling system - If no clients at server start or after 10 seconds of GS_LEVEL, and no Netxcmd waiting to be digested, halt all SV_MakeTic. - Currently #define'd out, but if we don't get to test it before 1.6 release, I fully encourage community build developers to enable this codepath and trial it on their servers. - It's absolutely netsafe to only have enabled on the host's end, the only risk is that a dedicated server might not re-awaken when presented with certain stimuli. --- src/d_clisrv.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 9e1749b3..53a24056 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -6198,6 +6198,9 @@ FILESTAMP SV_FileSendTicker(); } +// If a tree falls in the forest but nobody is around to hear it, does it make a tic? +//#define DEDICATEDIDLETIME (10*TICRATE) + void NetUpdate(void) { static tic_t resptime = 0; @@ -6210,6 +6213,55 @@ 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) + { + 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)