diff options
author | IronClawTrem <louie.nutman@gmail.com> | 2019-08-25 17:39:30 +0100 |
---|---|---|
committer | IronClawTrem <louie.nutman@gmail.com> | 2019-08-25 17:39:30 +0100 |
commit | 315da16a666999f85136520c739a86925dec403f (patch) | |
tree | 6342e08655dab34150f5a30a71ce2560335e4b8c /src | |
parent | 3db203fdc9906d700507056b837364e000dc5a7c (diff) |
add give command
Diffstat (limited to 'src')
-rw-r--r-- | src/game/g_admin.c | 101 | ||||
-rw-r--r-- | src/game/g_admin.h | 1 |
2 files changed, 102 insertions, 0 deletions
diff --git a/src/game/g_admin.c b/src/game/g_admin.c index 05f43f4..e729b40 100644 --- a/src/game/g_admin.c +++ b/src/game/g_admin.c @@ -394,6 +394,11 @@ g_admin_cmd_t g_admin_cmds[ ] = {"scrim", G_admin_scrim, "scrim", "toggles scrim mode", "[on|off]", + }, + + {"give", G_admin_give, "give", + "give funds to a player", + "[^3name|slot#^7] [^3amount^7]" } }; @@ -5614,6 +5619,20 @@ static qboolean G_admin_global_unpause( gentity_t *ent, int skiparg ) return qtrue; } +static qboolean is_numeric(const char *str) +{ + const char *p; + + if (!*str) + return qfalse; + + for (p = str; *p; p++) + if (*p < '0' || *p > '9') + return qfalse; + + return qtrue; +} + qboolean G_admin_pause( gentity_t *ent, int skiparg ) { int pids[ MAX_CLIENTS ]; @@ -7635,3 +7654,85 @@ qboolean G_admin_scrim(gentity_t *ent, int skiparg ) return qtrue; } + +qboolean G_admin_give(gentity_t *ent, int skiparg) +{ + char arg_name_raw[MAX_NAME_LENGTH]; + char arg_name[MAX_NAME_LENGTH]; + char arg_amount[30]; + int target_id, amount; + gentity_t *target; + const char *currency; + + if (G_SayArgc() < 3 + skiparg) { + ADMP("^3!give: ^7usage: !give [player] [amount]\n"); + return qfalse; + } + + G_SayArgv(1 + skiparg, arg_name_raw, sizeof(arg_name_raw)); + G_SanitiseString(arg_name_raw, arg_name, sizeof(arg_name)); + + if (is_numeric(arg_name)) { + target_id = atoi(arg_name); + + if (target_id < 0 || target_id >= MAX_CLIENTS) { + ADMP(va("^3!give: ^7invalid client number\n")); + return qfalse; + } + } else { + int pids[ MAX_CLIENTS ]; + + if (G_ClientNumbersFromString(arg_name, pids) != 1) { + char error[MAX_STRING_CHARS]; + + G_MatchOnePlayer(pids, error, sizeof(error)); + ADMP(va("^3!give: ^7%s\n", error)); + return qfalse; + } + + target_id = pids[0]; + } + + + target = g_entities + target_id; + + if (!target->client || + target->client->pers.connected != CON_CONNECTED) { + invalid_target: + ADMP("^3!give: ^7invalid target\n"); + return qfalse; + } + + G_SayArgv(2 + skiparg, arg_amount, sizeof(arg_amount)); + amount = atoi(arg_amount); + + switch (target->client->pers.teamSelection) { + case PTE_ALIENS: + if (amount < -9 || amount > 9) { + too_big: + ADMP("^3!give: ^7amount is too big\n"); + return qfalse; + } + + currency = "evo"; + break; + + case PTE_HUMANS: + if (amount < -2000 || amount > 2000) + goto too_big; + + currency = "credit"; + break; + + default: + goto invalid_target; + } + + G_AddCreditToClient(target->client, amount, qtrue); + AP(va("print \"^3!give: ^7%s^7 was given %i %s%s by ^7%s^7\n\"", + target->client->pers.netname, amount, currency, + (abs(amount) != 1 ? "s" : ""), + ent ? G_admin_adminPrintName(ent) : "console")); + + return qtrue; +} diff --git a/src/game/g_admin.h b/src/game/g_admin.h index f921d2e..c7d61d7 100644 --- a/src/game/g_admin.h +++ b/src/game/g_admin.h @@ -268,6 +268,7 @@ qboolean G_admin_hstage( gentity_t *ent, int skiparg ); qboolean G_admin_astage( gentity_t *ent, int skiparg ); qboolean G_admin_bubble( gentity_t *ent, int skiparg ); qboolean G_admin_scrim( gentity_t *ent, int skiparg ); +qboolean G_admin_give( gentity_t *ent, int skiparg ); void G_admin_print( gentity_t *ent, char *m ); void G_admin_buffer_print( gentity_t *ent, char *m ); |