From 94e36c288c6ce6b5273055e61077c29e81fbd2bf Mon Sep 17 00:00:00 2001 From: MAN-AT-ARMS Date: Sat, 22 Feb 2014 20:47:18 -0500 Subject: [PATCH] Fix colored name padding and allow IPv6 address to fit in output of 'status' command --- code/server/sv_ccmds.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/code/server/sv_ccmds.c b/code/server/sv_ccmds.c index 62dd58c2..ca73290a 100644 --- a/code/server/sv_ccmds.c +++ b/code/server/sv_ccmds.c @@ -1141,6 +1141,25 @@ static void SV_ExceptDel_f(void) SV_DelBanFromList(qtrue); } +/* +** SV_Strlen -- skips color escape codes +*/ +static int SV_Strlen( const char *str ) { + const char *s = str; + int count = 0; + + while ( *s ) { + if ( Q_IsColorString( s ) ) { + s += 2; + } else { + count++; + s++; + } + } + + return count; +} + /* ================ SV_Status_f @@ -1161,20 +1180,20 @@ static void SV_Status_f( void ) { Com_Printf ("map: %s\n", sv_mapname->string ); - Com_Printf ("num score ping name lastmsg address qport rate\n"); - Com_Printf ("--- ----- ---- --------------- ------- --------------------- ----- -----\n"); + Com_Printf ("cl score ping name address rate \n"); + Com_Printf ("-- ----- ---- --------------- --------------------------------------- -----\n"); for (i=0,cl=svs.clients ; i < sv_maxclients->integer ; i++,cl++) { if (!cl->state) continue; - Com_Printf ("%3i ", i); + Com_Printf ("%2i ", i); ps = SV_GameClientNum( i ); Com_Printf ("%5i ", ps->persistant[PERS_SCORE]); if (cl->state == CS_CONNECTED) - Com_Printf ("CNCT "); + Com_Printf ("CON "); else if (cl->state == CS_ZOMBIE) - Com_Printf ("ZMBI "); + Com_Printf ("ZMB "); else { ping = cl->ping < 9999 ? cl->ping : 9999; @@ -1183,10 +1202,7 @@ static void SV_Status_f( void ) { Com_Printf ("%s", cl->name); - // TTimo adding a ^7 to reset the color - // NOTE: colored names in status breaks the padding (WONTFIX) - Com_Printf ("^7"); - l = 14 - strlen(cl->name); + l = 16 - SV_Strlen(cl->name); j = 0; do @@ -1195,11 +1211,11 @@ static void SV_Status_f( void ) { j++; } while(j < l); - Com_Printf ("%7i ", svs.time - cl->lastPacketTime ); + // TTimo adding a ^7 to reset the color s = NET_AdrToString( cl->netchan.remoteAddress ); - Com_Printf ("%s", s); - l = 22 - strlen(s); + Com_Printf ("^7%s", s); + l = 39 - strlen(s); j = 0; do @@ -1208,8 +1224,6 @@ static void SV_Status_f( void ) { j++; } while(j < l); - Com_Printf ("%5i", cl->netchan.qport); - Com_Printf (" %5i", cl->rate); Com_Printf ("\n");