return ((autocvar_sv_adminnick != "") ? autocvar_sv_adminnick : autocvar_hostname);
}
+string GetClientErrorString(float clienterror, string original_input)
+{
+ switch(clienterror)
+ {
+ case CLIENT_DOESNT_EXIST: { return strcat("Client '", original_input, "' doesn't exist"); }
+ case CLIENT_NOT_REAL: { return strcat("Client '", original_input, "' is not real"); }
+ case CLIENT_IS_BOT: { return strcat("Client '", original_input, "' is a bot"); }
+ default: { return "Incorrect usage of GetClientErrorString"; }
+ }
+}
+
+float VerifyClientNumber(float tmp_number)
+{
+ if((tmp_number < 1) || (tmp_number > maxclients))
+ return FALSE;
+ else
+ return TRUE;
+}
+
+float VerifyClientEntity(entity client, float must_be_real, float allow_bots)
+{
+ if not(client.flags & FL_CLIENT)
+ return CLIENT_DOESNT_EXIST;
+ else if(must_be_real && (clienttype(client) != CLIENTTYPE_REAL))
+ return CLIENT_NOT_REAL;
+ else if(!allow_bots && (clienttype(client) == CLIENTTYPE_BOT))
+ return CLIENT_IS_BOT;
+
+ return CLIENT_ACCEPTABLE;
+}
+
+// find a player which matches the input string, and return their entity
entity GetFilteredEntity(string input)
{
entity tmp_player, selection;
else
tmp_number = stof(input);
- if(tmp_number)
+ if(VerifyClientNumber(tmp_number))
{
selection = edict_num(tmp_number);
}
return selection;
}
-// find a player which matches the input string, and return their entity number
+// same thing, but instead return their edict number
float GetFilteredNumber(string input)
{
entity selection = GetFilteredEntity(input);
}
else
{
- centerprint(client, strcat("^3", admin_name(), ":\n\n^7", argv(2)));
+ centerprint(client, strcat("^3", admin_name(), ":\n^7", argv(2)));
sprint(client, strcat("\{1}\{13}^3", admin_name(), "^7: ", argv(2), "\n"));
}
dprint("Message sent to ", client.netname, "\n");
case CMD_REQUEST_COMMAND:
{
entity client;
- float entno = stof(argv(1));
+ float accepted;
if(argc == 2)
{
- // player_id is out of range
- if((entno < 1) | (entno > maxclients)) {
- print("Player ", argv(1), " doesn't exist\n");
- return;
- }
- client = edict_num(entno);
- if not(client.flags & FL_CLIENT) {
- print("Player ", argv(1), " doesn't exist\n");
- return;
- }
- if(clienttype(client) == CLIENTTYPE_BOT) {
- print("Player ", argv(1), " (", client.netname, ") is a bot\n");
- return;
+ client = GetFilteredEntity(argv(1));
+ accepted = VerifyClientEntity(client, TRUE, FALSE);
+
+ if(accepted)
+ {
+ stuffcmd(client, "defer clear\n");
+ print("defer clear stuffed to ", argv(1), " (", client.netname, ")\n");
}
- stuffcmd(client, "defer clear\n");
- print("defer clear stuffed to ", argv(1), " (", client.netname, ")\n");
+ else { print("defer_clear: ", GetClientErrorString(accepted, argv(1)), ".\n"); }
+
return;
}
}
{
case CMD_REQUEST_COMMAND:
{
+ float accepted;
entity client;
string targets = strreplace(",", " ", argv(1));
t = car(targets); targets = cdr(targets);
// Check to see if the player is a valid target
- if((GetFilteredNumber(t) < 1) || (GetFilteredNumber(t) > maxclients)) // player_id is out of range
- {
- print("Player ", ftos(GetFilteredNumber(t)), " doesn't exist (out of range)", (targets ? ", skipping to next player.\n" : ".\n"));
- continue;
- }
client = GetFilteredEntity(t);
- if not(client.flags & FL_CLIENT) // player entity is not a client
+ accepted = VerifyClientEntity(client, TRUE, FALSE);
+
+ if not(accepted)
{
- print("Player ", ftos(GetFilteredNumber(t)), " doesn't exist (not a client)", (targets ? ", skipping to next player.\n" : ".\n"));
+ print("moveplayer: ", GetClientErrorString(accepted, argv(1)), ", skipping to next player.\n");
continue;
}