]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
GetIndexedEntity(argc, start_index) -- allows for players to be described
authorSamual <samual@xonotic.org>
Thu, 29 Dec 2011 02:31:23 +0000 (21:31 -0500)
committerSamual <samual@xonotic.org>
Thu, 29 Dec 2011 02:31:23 +0000 (21:31 -0500)
as: 1, #1, # 1, and by their nickname.

qcsrc/server/command/cmd.qc
qcsrc/server/command/common.qc
qcsrc/server/command/common.qh
qcsrc/server/command/sv_cmd.qc

index 449164e7445d178a8b5cde99c2f2fed8150bec94..5c8d801abee2c51b9c36c35700232f83c039a7bb 100644 (file)
@@ -461,14 +461,14 @@ void ClientCommand_tell(float request, float argc, string command)
                {
                        if(argc >= 3)
                        {
-                               entity tell_to = GetFilteredEntity(argv(1));
+                               entity tell_to = GetIndexedEntity(argc, 1);
                                float tell_accepted = VerifyClientEntity(tell_to, TRUE, FALSE);
                                
                                if(tell_accepted > 0) // the target is a real client
                                {
                                        if(tell_to != self) // and we're allowed to send to them :D
                                        {
-                                               Say(self, FALSE, tell_to, substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)), TRUE);
+                                               Say(self, FALSE, tell_to, substring(command, argv_start_index(next_token), argv_end_index(-1) - argv_start_index(next_token)), TRUE);
                                                return;
                                        }
                                        else { print_to(self, "You can't ^2tell^7 a message to yourself."); return; }
index 912e6e6ad6705d0bde8a15630422c1893c32f7a1..fae94049569bef7e5b70832c86785ea1a4867063 100644 (file)
@@ -55,6 +55,54 @@ float VerifyClientNumber(float tmp_number)
                return TRUE;
 }
 
+entity GetIndexedEntity(float argc, float start_index)
+{
+       entity tmp_player, selection;
+       float tmp_number;
+       string tmp_string;
+       
+       next_token = -1;
+       
+       if(argc > start_index)
+       {
+               if(substring(argv(start_index), 0, 1) == "#")
+               {
+                       tmp_string = substring(argv(start_index), 1, -1);
+                       ++next_token;
+                       
+                       if(tmp_string) // is it all one token? like #1
+                       {
+                               tmp_number = stof(tmp_string);
+                       }
+                       else if(argc > next_token) // no, it's two tokens? # 1
+                       {
+                               tmp_number = stof(argv(next_token));
+                               ++next_token;
+                       }
+               }
+               else // maybe it's ONLY a number?
+               {
+                       tmp_number = stof(argv(start_index));
+                       ++next_token;
+               }
+               
+               if(VerifyClientNumber(tmp_number))
+               {
+                       selection = edict_num(tmp_number); // yes, it was a number
+               }
+               else // no, maybe it's a name?
+               {
+                       next_token = (start_index + 1);
+                       
+                       FOR_EACH_CLIENT(tmp_player)
+                               if (strdecolorize(tmp_player.netname) == strdecolorize(argv(start_index)))
+                                       selection = tmp_player;
+               }
+       }
+       
+       return selection;
+}
+
 // find a player which matches the input string, and return their entity
 entity GetFilteredEntity(string input)
 {
index 9f719892b27cfa28a7d0dd9a44413002c64ecc5a..d3ee9cc27d3692f7a3074789eed462208928c1d1 100644 (file)
@@ -32,4 +32,7 @@ float timeout_status; // (values: 0, 1, 2) contains whether a timeout is not act
 void timeout_handler_think();
 
 // used by common/command/generic.qc:GenericCommand_dumpcommands to list all commands into a .txt file
-void CommonCommand_macro_write_aliases(float fh);
\ No newline at end of file
+void CommonCommand_macro_write_aliases(float fh);
+
+// keep track of the next token to use for argc
+float next_token;
\ No newline at end of file
index 34075853d7c52454bcdb9a3534c4864c9cc74f09..6385a78cc027c0d903a304df59aee51e73d2ba1a 100644 (file)
@@ -196,7 +196,7 @@ void GameCommand_anticheat(float request, float argc)
        {
                case CMD_REQUEST_COMMAND:
                {
-                       entity client = GetFilteredEntity(argv(1));
+                       entity client = GetIndexedEntity(argc, 1);
                        float accepted = VerifyClientEntity(client, FALSE, FALSE);
                        
                        if(accepted > 0) 
@@ -495,7 +495,7 @@ void GameCommand_defer_clear(float request, float argc)
                        
                        if(argc == 2)
                        {
-                               client = GetFilteredEntity(argv(1));
+                               client = GetIndexedEntity(argc, 1);
                                accepted = VerifyClientEntity(client, TRUE, FALSE);
                                
                                if(accepted > 0)
@@ -1067,7 +1067,7 @@ void GameCommand_playerdemo(float request, float argc) // mostly legacy
                                {
                                        case "read":
                                        {
-                                               client = GetFilteredEntity(argv(2));
+                                               client = GetIndexedEntity(argc, 2);
                                                accepted = VerifyClientEntity(client, FALSE, TRUE);
                                                
                                                if not(accepted > 0) 
@@ -1077,13 +1077,13 @@ void GameCommand_playerdemo(float request, float argc) // mostly legacy
                                                }
                                                
                                                self = client;
-                                               playerdemo_open_read(argv(3));
+                                               playerdemo_open_read(argv(next_token));
                                                return;
                                        }
                                        
                                        case "write":
                                        {
-                                               client = GetFilteredEntity(argv(2));
+                                               client = GetIndexedEntity(argc, 2);
                                                accepted = VerifyClientEntity(client, FALSE, FALSE);
                                                
                                                if not(accepted > 0) 
@@ -1093,7 +1093,7 @@ void GameCommand_playerdemo(float request, float argc) // mostly legacy
                                                }
                                                
                                                self = client;
-                                               playerdemo_open_write(argv(3));
+                                               playerdemo_open_write(argv(next_token));
                                                return;
                                        }
                                        
@@ -1341,13 +1341,13 @@ void GameCommand_stuffto(float request, float argc)
                {
                        if(argv(2))
                        {
-                               entity client = GetFilteredEntity(argv(1));
+                               entity client = GetIndexedEntity(argc, 1));
                                float accepted = VerifyClientEntity(client, TRUE, FALSE);
                                
                                if(accepted > 0)
                                {
-                                       stuffcmd(client, strcat("\n", argv(2), "\n"));
-                                       print(strcat("Command: \"", argv(2), "\" sent to ", GetCallerName(client), " (", argv(1) ,").\n"));
+                                       stuffcmd(client, strcat("\n", argv(next_token), "\n"));
+                                       print(strcat("Command: \"", argv(next_token), "\" sent to ", GetCallerName(client), " (", argv(1) ,").\n"));
                                }
                                else
                                        print("stuffto: ", GetClientErrorString(accepted, argv(1)), ".\n");