diff options
author | Christopher Schwarz <lakitu7@gmail.com> | 2011-02-21 08:26:30 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-01-03 00:18:01 +0000 |
commit | 194bcc454fa4964185c721577d3605fe11a97660 (patch) | |
tree | c8987cb019c6a4e4817e64430af319420cfd3668 /src/game/g_cmds.c | |
parent | 478b8716ac16df2707ebd3fc8be725eead401512 (diff) |
* Add usage statment when /give is used without arguments
* Further protect /give funds against overflows/underflows (thanks /dev/humancontroller/)
Diffstat (limited to 'src/game/g_cmds.c')
-rw-r--r-- | src/game/g_cmds.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c index 47b65fbf..54bd2e97 100644 --- a/src/game/g_cmds.c +++ b/src/game/g_cmds.c @@ -392,6 +392,14 @@ void Cmd_Give_f( gentity_t *ent ) char *name; qboolean give_all = qfalse; + if( trap_Argc( ) < 2 ) + { + ADMP( "usage: give [what]\n" ); + ADMP( "usage: valid choices are: all, health, funds [amount], stamina, " + "poison, gas, ammo\n" ); + return; + } + name = ConcatArgs( 1 ); if( Q_stricmp( name, "all" ) == 0 ) give_all = qtrue; @@ -404,16 +412,26 @@ void Cmd_Give_f( gentity_t *ent ) if( give_all || Q_stricmpn( name, "funds", 5 ) == 0 ) { - float credits = atof( name + 6 ); - const float max = MAX( ALIEN_MAX_CREDITS, HUMAN_MAX_CREDITS ); + int credits; - if( ent->client->pers.teamSelection == TEAM_ALIENS ) - credits *= ALIEN_CREDITS_PER_KILL; + if( give_all || trap_Argc( ) < 3 ) + credits = 30000; + else + { + credits = atof( name + 6 ) * + ( ent->client->pers.teamSelection == + TEAM_ALIENS ? ALIEN_CREDITS_PER_KILL : 1.0f ); - if( give_all || credits > max ) - credits = max; + // clamp credits manually, as G_AddCreditToClient() expects a short int + if( credits > 30000 ) + credits = 30000; + else if( name[ 6 ] == '-' && credits < -30000 ) + credits = -30000; + else if( credits < -30000 ) // overflowed int; didn't want negative + credits = 30000; + } - G_AddCreditToClient( ent->client, credits, qtrue ); + G_AddCreditToClient( ent->client, (short)credits, qtrue ); } if( give_all || Q_stricmp( name, "stamina" ) == 0 ) |