From 1d33a05a855bec8018ee207e7e0327bd8f9b84cb Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 1 Dec 2025 21:57:44 +0100 Subject: [PATCH] Fix some Serverbrowser issues - Fix serverlist results not being properly reset, which lead to reopening/refreshing the serverlist to show the old state, selecting one of those "old" servers then lead to just connecting to nothing - Fix the resfresh button making servers disappear if hit too often too fast (from srb2) https://codeberg.org/srb2classic/srb2classic/commit/3acc312923da0fe5e07c0517d9bff9e8b657b1eb --- src/d_clisrv.c | 65 +++++++++++++------------------------------------- src/d_clisrv.h | 2 -- src/d_main.c | 1 - src/m_menu.c | 27 +++++++++++---------- 4 files changed, 31 insertions(+), 64 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 628fdefc2..6d9cd48e7 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2191,12 +2191,8 @@ static void SendAskInfo(INT32 node) HSendPacket(node, false, 0, sizeof (askinfo_pak)); } -serverelem_t serverlist[MAXSERVERLIST]; +serverelem_t serverlist[MAXSERVERLIST] = {}; UINT32 serverlistcount = 0; -UINT32 serverlistultimatecount = 0; - -static boolean resendserverlistnode[MAXNETNODES]; -static tic_t serverlistepoch; static void SL_ClearServerList(INT32 connectedserver) { @@ -2209,8 +2205,7 @@ static void SL_ClearServerList(INT32 connectedserver) serverlist[i].node = 0; } serverlistcount = 0; - - memset(resendserverlistnode, 0, sizeof resendserverlistnode); + //memset(serverlist, 0, sizeof(serverlist)); } static UINT32 SL_SearchServer(INT32 node) @@ -2227,8 +2222,6 @@ static void SL_InsertServer(serverinfo_pak* info, SINT8 node) { UINT32 i; - resendserverlistnode[node] = false; - // search if not already on it i = SL_SearchServer(node); if (i == UINT32_MAX) @@ -2262,7 +2255,7 @@ static void SL_InsertServer(serverinfo_pak* info, SINT8 node) M_SortServerList(); } -void CL_UpdateServerList (void) +void CL_UpdateServerList(void) { SL_ClearServerList(0); @@ -2280,14 +2273,12 @@ void CL_UpdateServerList (void) SendAskInfo(BROADCASTADDR); } -void CL_QueryServerList (msg_server_t *server_list) +void CL_QueryServerList(msg_server_t *server_list) { INT32 i; CL_UpdateServerList(); - serverlistepoch = I_GetTime(); - for (i = 0; server_list[i].header.buffer[0]; i++) { // Make sure MS version matches our own, to @@ -2300,42 +2291,20 @@ void CL_QueryServerList (msg_server_t *server_list) if (node == -1) continue; // no more node free, or resolution failure SendAskInfo(node); - resendserverlistnode[node] = true; - // Leave this node open. It'll be closed if the - // request times out (CL_TimeoutServerList). - } - } - serverlistultimatecount = i; -} - -#define SERVERLISTRESENDRATE NEWTICRATE - -void CL_TimeoutServerList(void) -{ - if (netgame && serverlistultimatecount > serverlistcount) - { - const tic_t timediff = I_GetTime() - serverlistepoch; - const tic_t timetoresend = timediff % SERVERLISTRESENDRATE; - const boolean timedout = timediff > connectiontimeout; - - if (timedout || (timediff > 0 && timetoresend == 0)) - { - INT32 node; - - for (node = 1; node < MAXNETNODES; ++node) - { - if (resendserverlistnode[node]) - { - if (timedout) - Net_CloseConnection(node|FORCECLOSE); - else - SendAskInfo(node); - } - } - - if (timedout) - serverlistultimatecount = serverlistcount; + // Force close the connection so that servers can't eat + // up nodes forever if we never get a reply back from them + // (usually when they've not forwarded their ports). + // + // Don't worry, we'll get in contact with the working + // servers again when they send SERVERINFO to us later! + // + // (Note: as a side effect this probably means every + // server in the list will probably be using the same node (e.g. node 1), + // not that it matters which nodes they use when + // the connections are closed afterwards anyway) + // -- Monster Iestyn 12/11/18 + Net_CloseConnection(node|FORCECLOSE); } } } diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 5919b54ce..430729bc2 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -516,7 +516,6 @@ typedef struct extern serverelem_t serverlist[MAXSERVERLIST]; extern UINT32 serverlistcount; -extern UINT32 serverlistultimatecount; extern INT32 mapchangepending; // Points inside doomcom @@ -627,7 +626,6 @@ void CL_ClearPlayer(INT32 playernum); void CL_RemovePlayer(INT32 playernum, INT32 reason); void CL_QueryServerList(msg_server_t *list); void CL_UpdateServerList(void); -void CL_TimeoutServerList(void); void CL_AbortConnection(void); diff --git a/src/d_main.c b/src/d_main.c index cc437f15a..522096e28 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -885,7 +885,6 @@ void D_ClearState(void) CURLAbortFile(); SV_StopServer(); SV_ResetServer(); - serverlistultimatecount = 0; for (i = 0; i < MAXPLAYERS; i++) CL_ClearPlayer(i); diff --git a/src/m_menu.c b/src/m_menu.c index 399c39696..324423a71 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1939,8 +1939,6 @@ void M_Ticker(void) } I_unlock_mutex(ms_ServerList_mutex); #endif - - CL_TimeoutServerList(); } // @@ -6820,12 +6818,22 @@ static void M_Connect(INT32 choice) COM_BufAddText(va("connect node %d\n", serverlist[serverlistsearched[choice-FIRSTSERVERLINE + serverlistpage * SERVERS_PER_PAGE]].node)); } +static void M_ResetServerList(void) +{ + serverlistpage = 0; + oldserverlistpage = 0; + + serverlistslidex = 0.0f; + memset(serverlistsearched, 0, sizeof(serverlistsearched)); + serverlistsearchedcount = 0; +} + static void M_Refresh(INT32 choice) { (void)choice; // first page of servers - serverlistpage = 0; + M_ResetServerList(); CL_UpdateServerList(); @@ -6856,14 +6864,7 @@ static void M_DrawServerCountAndHorizontalBar(void) break; default: - if (serverlistultimatecount > serverlistcount) - { - text = va("%d/%d servers found%.*s", - serverlistcount, - serverlistultimatecount, - I_GetTime() / NEWTICRATE % 4, "..."); - } - else if (serverlistcount > 0) + if (serverlistcount > 0) { text = va("%d servers found", serverlistcount); } @@ -7047,7 +7048,7 @@ static int ServerListEntryComparator_modified(const void *entry1, const void *en void M_SortServerList(void) { - switch(cv_serversort.value) + switch (cv_serversort.value) { case 0: // Ping. qs22j(serverlist, serverlistcount, sizeof(serverelem_t), ServerListEntryComparator_time); @@ -7122,7 +7123,7 @@ static void M_ConnectMenu(INT32 choice) // we don't request a restart unless the filelist differs // first page of servers - serverlistpage = 0; + M_ResetServerList(); CL_UpdateServerList();