From: Samual Date: Mon, 19 Dec 2011 14:36:04 +0000 (-0500) Subject: New way to verify client entities and some other fixes X-Git-Tag: xonotic-v0.6.0~188^2~28^2~105 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2326adb0d84b3efbd5614781f8945b506eca8d08;p=xonotic%2Fxonotic-data.pk3dir.git New way to verify client entities and some other fixes --- diff --git a/qcsrc/server/command/common.qc b/qcsrc/server/command/common.qc index ceedc775c..95c9ceb52 100644 --- a/qcsrc/server/command/common.qc +++ b/qcsrc/server/command/common.qc @@ -19,6 +19,38 @@ string GetCallerName(entity caller) 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; @@ -29,7 +61,7 @@ entity GetFilteredEntity(string input) else tmp_number = stof(input); - if(tmp_number) + if(VerifyClientNumber(tmp_number)) { selection = edict_num(tmp_number); } @@ -43,7 +75,7 @@ entity GetFilteredEntity(string input) 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); diff --git a/qcsrc/server/command/common.qh b/qcsrc/server/command/common.qh index 10c4f9bfb..90be5f79d 100644 --- a/qcsrc/server/command/common.qh +++ b/qcsrc/server/command/common.qh @@ -3,4 +3,7 @@ // Last updated: December 13th, 2011 // ============================================================ -// nothing needed here \ No newline at end of file +#define CLIENT_ACCEPTABLE 1 +#define CLIENT_DOESNT_EXIST -1 +#define CLIENT_NOT_REAL -2 +#define CLIENT_IS_BOT -3 \ No newline at end of file diff --git a/qcsrc/server/command/sv_cmd.qc b/qcsrc/server/command/sv_cmd.qc index b02136ef3..480372cab 100644 --- a/qcsrc/server/command/sv_cmd.qc +++ b/qcsrc/server/command/sv_cmd.qc @@ -128,7 +128,7 @@ void GameCommand_adminmsg(float request, float argc) // todo: re-write this, plu } 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"); @@ -510,26 +510,20 @@ void GameCommand_defer_clear(float request, float argc) 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; } } @@ -936,6 +930,7 @@ void GameCommand_moveplayer(float request, float argc) { case CMD_REQUEST_COMMAND: { + float accepted; entity client; string targets = strreplace(",", " ", argv(1)); @@ -953,15 +948,12 @@ void GameCommand_moveplayer(float request, float argc) 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; }