From 85cac497ea2e1ef1a7ca793ae4abfb8d31710b7d Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 3 Sep 2025 12:25:41 +0200 Subject: [PATCH] fixup building map title string for serverinfo fixes numerous issues, like zonetitle not appearing on bots and serverinfo screen and generally making this more sane by appending stuff if needed also fixes "Zone" not displaying in serverinfo screen --- src/d_clisrv.c | 69 +++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 43 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index f8bf137f9..67799fd62 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1341,7 +1341,11 @@ static inline void CL_DrawConnectionStatus(void) patch_t *current_map = W_LumpExists(map) ? W_CachePatchName(map, PU_CACHE) : W_CachePatchName("BLANKLVL", PU_CACHE); V_DrawSmallScaledPatch(10, 18, 0, current_map); - V_DrawThinString(12 + 80, 38, V_ALLOWLOWERCASE, va("%s", serverlist[joinnode].info.maptitle)); + if (serverlist[joinnode].info.iszone) + V_DrawThinString(12 + 80, 38, V_ALLOWLOWERCASE, va("%s Zone", serverlist[joinnode].info.maptitle)); + else + V_DrawThinString(12 + 80, 38, V_ALLOWLOWERCASE, va("%s", serverlist[joinnode].info.maptitle)); + V_DrawThinString(12 + 80, 48, V_ALLOWLOWERCASE, va("%s", Gametype_Names[serverlist[joinnode].info.gametype])); if (fileneedednum > 0) @@ -1581,59 +1585,38 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime) CopyCaretColors(netbuffer->u.serverinfo.servername, cv_servername.string, MAXSERVERNAME); - strncpy(netbuffer->u.serverinfo.mapname, G_BuildMapName(gamemap), 7); + strncpy(netbuffer->u.serverinfo.mapname, G_BuildMapName(gamemap), sizeof(netbuffer->u.serverinfo.mapname)-1); - M_Memcpy(netbuffer->u.serverinfo.mapmd5, mapmd5, 16); + M_Memcpy(netbuffer->u.serverinfo.mapmd5, mapmd5, sizeof(netbuffer->u.serverinfo.mapmd5)); - if (!(mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE) && !(mapheaderinfo[prevmap]->zonttl[0])) - netbuffer->u.serverinfo.iszone = 1; - else - netbuffer->u.serverinfo.iszone = 0; + netbuffer->u.serverinfo.iszone = 0; - memset(netbuffer->u.serverinfo.maptitle, 0, 33); + memset(netbuffer->u.serverinfo.maptitle, 0, sizeof(netbuffer->u.serverinfo.maptitle)); memset(netbuffer->u.serverinfo.httpsource, 0, MAX_MIRROR_LENGTH); if (!(mapheaderinfo[gamemap-1]->menuflags & LF2_HIDEINMENU) && mapheaderinfo[gamemap-1]->lvlttl[0]) { - //strncpy(netbuffer->u.serverinfo.maptitle, (char *)mapheaderinfo[gamemap-1]->lvlttl, 33); - // set up the levelstring - if (netbuffer->u.serverinfo.iszone || (mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE)) + strncpy(netbuffer->u.serverinfo.maptitle, mapheaderinfo[gamemap-1]->lvlttl, sizeof(netbuffer->u.serverinfo.maptitle)-1); + + if (!(mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE)) { - if (mapheaderinfo[gamemap-1]->actnum[0]) - snprintf(netbuffer->u.serverinfo.maptitle, - 33, - "%s %s", - mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->actnum); + if (mapheaderinfo[gamemap-1]->zonttl[0]) + { + strncat(netbuffer->u.serverinfo.maptitle, " ", sizeof(netbuffer->u.serverinfo.maptitle)-1); + strncat(netbuffer->u.serverinfo.maptitle, mapheaderinfo[gamemap-1]->zonttl, + sizeof(netbuffer->u.serverinfo.maptitle)-1); + } else - snprintf(netbuffer->u.serverinfo.maptitle, - 33, - "%s", - mapheaderinfo[gamemap-1]->lvlttl); + { + netbuffer->u.serverinfo.iszone = 1; // ms and clients will append this themselves + } } - else + + if (mapheaderinfo[gamemap-1]->actnum[0]) { - if (mapheaderinfo[gamemap-1]->actnum[0]) - { - if (snprintf(netbuffer->u.serverinfo.maptitle, - 33, - "%s %s %s", - mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl, mapheaderinfo[gamemap-1]->actnum) < 0) - { - // If there's an encoding error, send UNKNOWN, we accept that the above may be truncated - strncpy(netbuffer->u.serverinfo.maptitle, "Unknown", 33); - } - } - else - { - if (snprintf(netbuffer->u.serverinfo.maptitle, - 33, - "%s %s", - mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl) < 0) - { - // If there's an encoding error, send UNKNOWN, we accept that the above may be truncated - strncpy(netbuffer->u.serverinfo.maptitle, "Unknown", 33); - } - } + strncat(netbuffer->u.serverinfo.maptitle, " ", sizeof(netbuffer->u.serverinfo.maptitle)-1); + strncat(netbuffer->u.serverinfo.maptitle, mapheaderinfo[gamemap-1]->actnum, + sizeof(netbuffer->u.serverinfo.maptitle)-1); } } else