From f802e9fbcbc6895183a7106a798a463d1c8e1716 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 3 Jul 2019 17:11:38 -0700 Subject: [PATCH 1/2] Convert from caret colors when sending SERVERINFO --- src/d_clisrv.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index b3b2cc03..13a9297b 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1306,6 +1306,70 @@ static boolean CL_SendJoin(void) return HSendPacket(servernode, false, 0, sizeof (clientconfig_pak)); } +static void +CopyCaretColors (char *p, const char *s, int n) +{ + char *t; + int m; + int c; + if (!n) + return; + while (( t = strchr(s, '^') )) + { + m = ( t - s ); + + if (m >= n) + { + memcpy(p, s, n); + return; + } + else + memcpy(p, s, m); + + p += m; + n -= m; + s += m; + + if (!n) + return; + + if (s[1]) + { + c = toupper(s[1]); + if (isdigit(c)) + c = 0x80 + ( c - '0' ); + else if (c >= 'A' && c <= 'F') + c = 0x80 + ( c - 'A' ); + else + c = 0; + + if (c) + { + *p++ = c; + n--; + + if (!n) + return; + } + else + { + if (n < 2) + break; + + memcpy(p, s, 2); + + p += 2; + n -= 2; + } + + s += 2; + } + else + break; + } + strncpy(p, s, n); +} + static void SV_SendServerInfo(INT32 node, tic_t servertime) { UINT8 *p; @@ -1334,8 +1398,7 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime) (dedicated ? SV_DEDICATED : 0) ); - - strncpy(netbuffer->u.serverinfo.servername, cv_servername.string, + CopyCaretColors(netbuffer->u.serverinfo.servername, cv_servername.string, MAXSERVERNAME); strncpy(netbuffer->u.serverinfo.mapname, G_BuildMapName(gamemap), 7); From 54c3aed86c26eccb1b0863613888ceac0758b200 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 3 Jul 2019 17:41:11 -0700 Subject: [PATCH 2/2] Convert caret color codes to SRB2 color codes --- src/d_clisrv.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 13a9297b..a876e992 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3951,6 +3951,7 @@ static void HandleTimeout(SINT8 node) */ static void HandleServerInfo(SINT8 node) { + char servername[MAXSERVERNAME]; // compute ping in ms const tic_t ticnow = I_GetTime(); const tic_t ticthen = (tic_t)LONG(netbuffer->u.serverinfo.time); @@ -3959,6 +3960,8 @@ static void HandleServerInfo(SINT8 node) netbuffer->u.serverinfo.servername[MAXSERVERNAME-1] = 0; netbuffer->u.serverinfo.application [sizeof netbuffer->u.serverinfo.application - 1] = '\0'; + memcpy(servername, netbuffer->u.serverinfo.servername, MAXSERVERNAME); + CopyCaretColors(netbuffer->u.serverinfo.servername, servername, MAXSERVERNAME); netbuffer->u.serverinfo.gametype = (UINT8)((netbuffer->u.serverinfo.gametype == VANILLA_GT_MATCH) ? GT_MATCH : GT_RACE); SL_InsertServer(&netbuffer->u.serverinfo, node);