Allow Caret coloring to work on Description

Hex codes do not work as of yet.
This commit is contained in:
NepDisk 2025-08-19 20:54:31 -04:00
parent a78fc56e8c
commit fbea38e20b
2 changed files with 84 additions and 4 deletions

View file

@ -3658,6 +3658,79 @@ static void Got_Clearscores(UINT8 **cp, INT32 playernum)
CONS_Printf(M_GetText("Scores have been reset by the server.\n"));
}
ATTRINLINE static FUNCINLINE unsigned char GetColorChar(char *input, size_t *curpos)
{
char c = input[*curpos++];
if (c == '^') // oh, nevermind then.
return '^';
if (c >= '0' && c <= '9')
return 0x80+(c-'0');
c = tolower(c);
if (c >= 'a' && c <= 'f')
return 0x80+10+(c-'a');
return 0x80; // Unhandled -- default to no color
}
ATTRINLINE static FUNCINLINE char GetHexChar(char *input, size_t *curpos)
{
char c = input[*curpos++];
char endchr = 0;
if (c == '\\') // oh, nevermind then.
return '\\';
if (c >= '0' && c <= '9')
endchr += (c-'0') << 4;
else if (c >= 'A' && c <= 'F')
endchr += ((c-'A') + 10) << 4;
else if (c >= 'a' && c <= 'f')
endchr += ((c-'a') + 10) << 4;
else // invalid. stop and return a question mark.
return '?';
c = input[*curpos++];
if (c >= '0' && c <= '9')
endchr += (c-'0');
else if (c >= 'A' && c <= 'F')
endchr += ((c-'A') + 10);
else if (c >= 'a' && c <= 'f')
endchr += ((c-'a') + 10);
else // invalid. stop and return a question mark.
return '?';
return endchr;
}
static char *GetSpecialString(char *buf, char *input, size_t bufsize)
{
size_t i = 0;
size_t currentpos = 0;
strncpy(buf, input, bufsize);
// we need one byte for a null terminated string
bufsize--;
while (i < bufsize)
{
char c = buf[currentpos++];
if (c == '^')
{
buf[i++] = GetColorChar(buf, &currentpos);
currentpos++;
}
/*else if (c == '\\')
{
buf[i++] = GetHexChar(buf, &currentpos);
}*/
else if (c != '\r')
buf[i++] = c;
}
return buf;
}
static void Command_ScoreboardAdd(void)
{
UINT8 buf[4];
@ -3673,6 +3746,7 @@ static void Command_ScoreboardAdd(void)
{
size_t i, j = COM_Argc();
char message[MAXSERVERDESCRIPTIONLINE+1];
char *finalstring;
INT32 strlensize = 0;
//Steal from the motd code so you don't have to put the reason in quotes.
@ -3685,17 +3759,23 @@ static void Command_ScoreboardAdd(void)
strlensize = strlen(message);
message[strlensize+1] = '\0';
message[MAXSERVERDESCRIPTIONLINE] = '\0';
finalstring = Z_Calloc(MAXSERVERDESCRIPTIONLINE*sizeof(char), PU_STATIC, NULL);
GetSpecialString(finalstring, message, MAXSERVERDESCRIPTIONLINE);
strlensize = strlen(finalstring);
if ((strlensize+1) > MAXSERVERDESCRIPTIONLINE)
{
CONS_Alert(CONS_WARNING, M_GetText("Scoreboard line is too long to add.\n"));
return;
}
WRITESTRINGN(cp, message, MAXSERVERDESCRIPTIONLINE+1);
WRITESTRINGN(cp, finalstring, MAXSERVERDESCRIPTIONLINE+1);
SendNetXCmd(XD_SCOREBOARDADD, &buf, cp - buf);
Z_Free(finalstring);
}
else
CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n"));

View file

@ -2173,10 +2173,10 @@ INT32 K_DrawNeoTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines
void K_DrawServerDescrption(INT32 x, INT32 y)
{
if (connectedservername[0] != '\0')
V_DrawThinString(x, y, V_SNAPTORIGHT|V_6WIDTHSPACE|V_ALLOWLOWERCASE, connectedservername);
V_DrawThinString(x, y, V_6WIDTHSPACE|V_ALLOWLOWERCASE, connectedservername);
if (serverdescription[0] != '\0')
V_DrawSmallString(x, y+20, V_SNAPTORIGHT|V_6WIDTHSPACE|V_ALLOWLOWERCASE, serverdescription);
V_DrawSmallString(x, y+20, V_6WIDTHSPACE|V_ALLOWLOWERCASE, serverdescription);
}