]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
New way to verify client entities and some other fixes
authorSamual <samual@xonotic.org>
Mon, 19 Dec 2011 14:36:04 +0000 (09:36 -0500)
committerSamual <samual@xonotic.org>
Mon, 19 Dec 2011 14:36:04 +0000 (09:36 -0500)
qcsrc/server/command/common.qc
qcsrc/server/command/common.qh
qcsrc/server/command/sv_cmd.qc

index ceedc775c5cccae0d537892003731839cf4d06d9..95c9ceb5200343c39d8409cf0e67243856854ab1 100644 (file)
@@ -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);
index 10c4f9bfb704f17b0192b6ea83de5233577983dc..90be5f79d6aa65f4db012ca36e5e4a4251820e00 100644 (file)
@@ -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
index b02136ef3d3a471690f609edd4f14dc77a041d9a..480372cab55bb6dbc25b6c4b2fabef6c0ed6e0fd 100644 (file)
@@ -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;
                                        }