From 1cdb3b33e7425b98470169a83e044f4b9819d99c Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sun, 18 Nov 2012 21:55:40 +0000 Subject: [PATCH] Fix follow command to find clients whose name begins with a number. --- code/game/g_cmds.c | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/code/game/g_cmds.c b/code/game/g_cmds.c index 62364408..3eacfe94 100644 --- a/code/game/g_cmds.c +++ b/code/game/g_cmds.c @@ -153,6 +153,32 @@ char *ConcatArgs( int start ) { return line; } + +/* +================== +StringIsInteger +================== +*/ +qboolean StringIsInteger( const char * s ) { + int i; + int len; + qboolean foundDigit; + + len = strlen( s ); + foundDigit = qfalse; + + for ( i=0 ; i < len ; i++ ) { + if ( !isdigit( s[i] ) ) { + return qfalse; + } + + foundDigit = qtrue; + } + + return foundDigit; +} + + /* ================== ClientNumberFromString @@ -166,20 +192,15 @@ int ClientNumberFromString( gentity_t *to, char *s ) { int idnum; char cleanName[MAX_STRING_CHARS]; - // numeric values are just slot numbers - if (s[0] >= '0' && s[0] <= '9') { + // numeric values could be slot numbers + if ( StringIsInteger( s ) ) { idnum = atoi( s ); - if ( idnum < 0 || idnum >= level.maxclients ) { - trap_SendServerCommand( to-g_entities, va("print \"Bad client slot: %i\n\"", idnum)); - return -1; + if ( idnum >= 0 && idnum < level.maxclients ) { + cl = &level.clients[idnum]; + if ( cl->pers.connected == CON_CONNECTED ) { + return idnum; + } } - - cl = &level.clients[idnum]; - if ( cl->pers.connected != CON_CONNECTED ) { - trap_SendServerCommand( to-g_entities, va("print \"Client %i is not active\n\"", idnum)); - return -1; - } - return idnum; } // check for a name match