summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game/g_admin.c100
-rw-r--r--src/game/g_admin.h2
2 files changed, 102 insertions, 0 deletions
diff --git a/src/game/g_admin.c b/src/game/g_admin.c
index 9d5d90e..6869920 100644
--- a/src/game/g_admin.c
+++ b/src/game/g_admin.c
@@ -153,6 +153,11 @@ g_admin_cmd_t g_admin_cmds[ ] =
"list all flags understood by this server",
""
},
+
+ {"give", G_admin_give, "give",
+ "give funds to a player",
+ "[^3name|slot#^7] [^3amount^7]"
+ },
{"help", G_admin_help, "help",
"display commands available to you or help on a specific command",
@@ -9858,3 +9863,98 @@ qboolean G_admin_scrim(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_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 d211243..7292fb4 100644
--- a/src/game/g_admin.h
+++ b/src/game/g_admin.h
@@ -347,6 +347,8 @@ qboolean G_admin_rnote( 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 );
void G_admin_buffer_begin( void );