From cfb3b45ae4d8031a8c4a03cb7ebdd1fd476ad134 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Fri, 6 Sep 2024 15:50:09 +0200 Subject: [PATCH 1/5] Refactor dedicated idling a little --- src/netcode/d_clisrv.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/netcode/d_clisrv.c b/src/netcode/d_clisrv.c index 5fee506af..dd4a25be2 100644 --- a/src/netcode/d_clisrv.c +++ b/src/netcode/d_clisrv.c @@ -1500,18 +1500,15 @@ void NetUpdate(void) { INT32 i; - for (i = 1; i < MAXNETNODES; ++i) + boolean empty = true; + for (i = 1; i < MAXNETNODES; i++) if (netnodes[i].ingame) { - if (dedicatedidle >= dedicatedidletime) - { - CONS_Printf("DEDICATED: Awakening from idle (Node %d detected...)\n", i); - dedicatedidle = 0; - } + empty = false; break; } - if (i == MAXNETNODES) + if (empty) { if (leveltime == 2) { @@ -1541,6 +1538,14 @@ void NetUpdate(void) dedicatedidle = dedicatedidletime; } } + else + { + if (dedicatedidle >= dedicatedidletime) + { + CONS_Printf("DEDICATED: Awakening from idle (Node detected...)\n"); + dedicatedidle = 0; + } + } } else { From ba8b1e084879cfd57894a4c1dd6b8f6ce5b55d3f Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Fri, 6 Sep 2024 15:51:57 +0200 Subject: [PATCH 2/5] Fix dedicated idling ignoring disconnected players --- src/netcode/d_clisrv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/netcode/d_clisrv.c b/src/netcode/d_clisrv.c index dd4a25be2..d9b26e851 100644 --- a/src/netcode/d_clisrv.c +++ b/src/netcode/d_clisrv.c @@ -1501,8 +1501,8 @@ void NetUpdate(void) INT32 i; boolean empty = true; - for (i = 1; i < MAXNETNODES; i++) - if (netnodes[i].ingame) + for (i = 0; i < MAXPLAYERS; i++) + if (playeringame[i]) { empty = false; break; @@ -1542,7 +1542,7 @@ void NetUpdate(void) { if (dedicatedidle >= dedicatedidletime) { - CONS_Printf("DEDICATED: Awakening from idle (Node detected...)\n"); + CONS_Printf("DEDICATED: Awakening from idle (Player detected...)\n"); dedicatedidle = 0; } } From c69df42f6c3c35ede3b644b18506469c1eb00929 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Fri, 6 Sep 2024 15:53:53 +0200 Subject: [PATCH 3/5] Fix dedicated idle timer not resetting when toggled --- src/netcode/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/netcode/d_clisrv.c b/src/netcode/d_clisrv.c index d9b26e851..16405b982 100644 --- a/src/netcode/d_clisrv.c +++ b/src/netcode/d_clisrv.c @@ -1543,8 +1543,8 @@ void NetUpdate(void) if (dedicatedidle >= dedicatedidletime) { CONS_Printf("DEDICATED: Awakening from idle (Player detected...)\n"); - dedicatedidle = 0; } + dedicatedidle = 0; } } else From c09ec5933dbb79c8df5756aeaca332d944988507 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Fri, 6 Sep 2024 16:09:30 +0200 Subject: [PATCH 4/5] Cleanup --- src/netcode/d_clisrv.c | 146 ++++++++++++++++++++++------------------- 1 file changed, 78 insertions(+), 68 deletions(-) diff --git a/src/netcode/d_clisrv.c b/src/netcode/d_clisrv.c index 16405b982..99d1b4728 100644 --- a/src/netcode/d_clisrv.c +++ b/src/netcode/d_clisrv.c @@ -1414,6 +1414,83 @@ static void IdleUpdate(void) } } +static void DedicatedIdleUpdate(INT32 *realtics) +{ + const tic_t dedicatedidletime = cv_dedicatedidletime.value * TICRATE; + static tic_t dedicatedidletimeprev = 0; + static tic_t dedicatedidle = 0; + + if (!server || !dedicated || gamestate != GS_LEVEL) + return; + + if (dedicatedidletime > 0) + { + INT32 i; + + 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 nodes %s, idling...\n", idlereason); + (*realtics) = 0; + dedicatedidle = dedicatedidletime; + } + } + } + else + { + if (dedicatedidle >= dedicatedidletime) + { + CONS_Printf("DEDICATED: Awakening from idle (Player detected...)\n"); + } + dedicatedidle = 0; + } + } + else + { + if (dedicatedidletimeprev > 0 && dedicatedidle >= dedicatedidletimeprev) + { + CONS_Printf("DEDICATED: Awakening from idle (Idle disabled...)\n"); + } + dedicatedidle = 0; + } + + dedicatedidletimeprev = dedicatedidletime; +} + // Handle timeouts to prevent definitive freezes from happenning static void HandleNodeTimeouts(void) { @@ -1490,74 +1567,7 @@ void NetUpdate(void) realtics = 5; } - if (server && dedicated && gamestate == GS_LEVEL) - { - const tic_t dedicatedidletime = cv_dedicatedidletime.value * TICRATE; - static tic_t dedicatedidletimeprev = 0; - static tic_t dedicatedidle = 0; - - if (dedicatedidletime > 0) - { - INT32 i; - - 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 if ((dedicatedidle += realtics) >= 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; - dedicatedidle = dedicatedidletime; - } - } - else - { - if (dedicatedidle >= dedicatedidletime) - { - CONS_Printf("DEDICATED: Awakening from idle (Player detected...)\n"); - } - dedicatedidle = 0; - } - } - else - { - if (dedicatedidletimeprev > 0 && dedicatedidle >= dedicatedidletimeprev) - { - CONS_Printf("DEDICATED: Awakening from idle (Idle disabled...)\n"); - } - dedicatedidle = 0; - } - - dedicatedidletimeprev = dedicatedidletime; - } + DedicatedIdleUpdate(&realtics); gametime = nowtime; From 46309370f07aebf59c93c4f88d16d76cdcc803de Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Fri, 6 Sep 2024 16:17:15 +0200 Subject: [PATCH 5/5] Say "players" instead of "nodes" --- src/netcode/d_clisrv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/netcode/d_clisrv.c b/src/netcode/d_clisrv.c index 99d1b4728..d34dbc4e0 100644 --- a/src/netcode/d_clisrv.c +++ b/src/netcode/d_clisrv.c @@ -1462,9 +1462,9 @@ static void DedicatedIdleUpdate(INT32 *realtics) { const char *idlereason = "at round start"; if (leveltime > 3) - idlereason = va("for %d seconds", dedicatedidle/TICRATE); + idlereason = va("for %d seconds", dedicatedidle / TICRATE); - CONS_Printf("DEDICATED: No nodes %s, idling...\n", idlereason); + CONS_Printf("DEDICATED: No players %s, idling...\n", idlereason); (*realtics) = 0; dedicatedidle = dedicatedidletime; }