From 4f185449841744317166c88522d40e4c6c67a892 Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Thu, 12 Sep 2024 21:52:43 +1000 Subject: [PATCH] net_slist: timeout-related fixes Ignores refresh requests while a refresh is in progress. This prevents live servers getting timed out, which sometimes happened when Xonotic menu QC responded to a server list mouseover event. Fixes incorrect types in timeout check and ping comparison. Adds some debug messages. Signed-off-by: bones_was_here --- netconn.c | 36 ++++++++++++++++++++++-------------- netconn.h | 2 +- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/netconn.c b/netconn.c index 5cf7e513..e1da0e3d 100644 --- a/netconn.c +++ b/netconn.c @@ -639,13 +639,6 @@ void ServerList_QueryList(qbool resetcache, qbool querydp, qbool queryqw, qbool lhnetaddress_t broadcastaddress; char dpquery[53]; // theoretical max: 14+22+16+1 - if (net_slist_debug.integer) - Con_Printf("^2Querying %s master, favourite and LAN servers, reset=%u\n", - querydp && queryqw ? "DP and QW" : querydp ? "DP" : "QW", - resetcache); - serverlist_querystage = (querydp ? SLIST_QUERYSTAGE_DPMASTERS : 0) | (queryqw ? SLIST_QUERYSTAGE_QWMASTERS : 0); - masterquerycount = 0; - masterreplycount = 0; if (resetcache) { serverquerycount = 0; @@ -657,14 +650,25 @@ void ServerList_QueryList(qbool resetcache, qbool querydp, qbool queryqw, qbool } else { - // refresh all entries - for (i = 0; i < serverlist_cachecount; ++i) + if (serverlist_querystage) { - serverlist_entry_t *entry = &serverlist_cache[i]; - entry->responded = false; + if (net_slist_debug.integer) + Con_Printf(CON_WARN "Ignoring server list refresh request: already refreshing!\n"); + return; // unsetting `responded` now would cause live servers to be timed out } + + // refresh all entries + for (i = 0; i < serverlist_cachecount; ++i) + serverlist_cache[i].responded = false; } + serverlist_querystage = (querydp ? SLIST_QUERYSTAGE_DPMASTERS : 0) | (queryqw ? SLIST_QUERYSTAGE_QWMASTERS : 0); + masterquerycount = 0; + masterreplycount = 0; serverlist_consoleoutput = consoleoutput; + if (net_slist_debug.integer) + Con_Printf("^2Querying %s master, favourite and LAN servers, reset=%u\n", + querydp && queryqw ? "DP and QW" : querydp ? "DP" : "QW", + resetcache); //_ServerList_Test(); @@ -2613,13 +2617,17 @@ void NetConn_QueryQueueFrame(void) if (!entry->responded // no acceptable response during this refresh cycle && entry->info.ping) // visible in the list (has old ping from previous refresh cycle) { - if (currentrealtime > entry->querytime + net_slist_maxping.integer/1000) + if (currentrealtime > entry->querytime + net_slist_maxping.value/1000.0f) { // you have no chance to survive make your timeout serverreplycount--; if(!net_slist_pause.integer) + { + if (net_slist_debug.integer) + Con_Printf(CON_WARN "Removing timed out server %s from viewlist\n", entry->info.cname); ServerList_ViewList_Remove(entry); - entry->info.ping = 0; // removed later if net_slist_pause + } + entry->info.ping = 0; // removed later by ServerList_ViewList_Insert if net_slist_pause } else // still has time return; // continue this pass at the current server on a later frame @@ -2658,7 +2666,7 @@ void NetConn_QueryQueueFrame(void) Con_Printf("^4Finished checking server timeouts in %f\n", currentrealtime - serverlist_cache[serverlist_cachecount - 1].querytime); if (serverlist_cachecount >= SERVERLIST_TOTALSIZE) - Con_Printf(CON_WARN "WARNING: too many servers, some will not be listed!\n"); + Con_Printf(CON_ERROR "ERROR: too many servers, some will not be listed!\n"); } } #endif diff --git a/netconn.h b/netconn.h index a7ef91d2..ef926883 100755 --- a/netconn.h +++ b/netconn.h @@ -276,7 +276,7 @@ typedef struct serverlist_info_s char cname[128]; unsigned cname_len; /// ping time for sorting servers, in milliseconds, 0 means no data - unsigned ping; + int ping; /// name of the game char game[32]; unsigned game_len; -- 2.39.2