]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/command/common.qc
Comment out old debug print for GetIndexedEntity() function
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / common.qc
index c333910ec6ab6e6a63cd5f68587b474c30706cc2..7bda0e0569e321f72376c7bc3c8e3cb8b8cc11dc 100644 (file)
@@ -55,6 +55,57 @@ float VerifyClientNumber(float tmp_number)
                return TRUE;
 }
 
+entity GetIndexedEntity(float argc, float start_index)
+{
+       entity tmp_player, selection;
+       float tmp_number, index;
+       string tmp_string;
+       
+       next_token = -1;
+       index = start_index;
+       
+       if(argc > start_index)
+       {
+               if(substring(argv(index), 0, 1) == "#")
+               {
+                       tmp_string = substring(argv(index), 1, -1);
+                       ++index;
+                       
+                       if(tmp_string != "") // is it all one token? like #1
+                       {
+                               tmp_number = stof(tmp_string);
+                       }
+                       else if(argc > index) // no, it's two tokens? # 1
+                       {
+                               tmp_number = stof(argv(index));
+                               ++index;
+                       }
+               }
+               else // maybe it's ONLY a number?
+               {
+                       tmp_number = stof(argv(index));
+                       ++index;
+               }
+               
+               if(VerifyClientNumber(tmp_number))
+               {
+                       selection = edict_num(tmp_number); // yes, it was a number
+               }
+               else // no, maybe it's a name?
+               {
+                       FOR_EACH_CLIENT(tmp_player)
+                               if (strdecolorize(tmp_player.netname) == strdecolorize(argv(start_index)))
+                                       selection = tmp_player;
+                                       
+                       index = (start_index + 1);
+               }
+       }
+       
+       next_token = index;
+       //print(strcat("start_index: ", ftos(start_index), ", next_token: ", ftos(next_token), ", edict: ", ftos(num_for_edict(selection)), ".\n"));
+       return selection;
+}
+
 // find a player which matches the input string, and return their entity
 entity GetFilteredEntity(string input)
 {
@@ -157,7 +208,7 @@ void timeout_handler_think()
                
                case TIMEOUT_LEADTIME:
                {
-                       if (timeout_leadtime > 0) // countdown is still going
+                       if(timeout_leadtime > 0) // countdown is still going
                        {
                                // centerprint the information to every player
                                FOR_EACH_REALPLAYER(tmp_player) 
@@ -185,6 +236,8 @@ void timeout_handler_think()
                                
                                self.nextthink = time; // think again next frame to handle it under TIMEOUT_ACTIVE code
                        }
+                       
+                       return;
                }
                
                
@@ -245,7 +298,7 @@ void CommonCommand_cvar_purechanges(float request, entity caller)
        }
 }
 
-void CommonCommand_info(float request, entity caller, float argc) // legacy
+void CommonCommand_info(float request, entity caller, float argc) 
 {      
        switch(request)
        {
@@ -331,7 +384,7 @@ void CommonCommand_lsnewmaps(float request, entity caller)
        }
 }
 
-void CommonCommand_maplist(float request, entity caller)
+void CommonCommand_printmaplist(float request, entity caller)
 {
        switch(request)
        {
@@ -344,37 +397,13 @@ void CommonCommand_maplist(float request, entity caller)
                default:
                case CMD_REQUEST_USAGE:
                {
-                       print_to(caller, strcat("\nUsage:^3 ", GetCommandPrefix(caller), " maplist"));
+                       print_to(caller, strcat("\nUsage:^3 ", GetCommandPrefix(caller), " printmaplist"));
                        print_to(caller, "  No arguments required.");
                        return;
                }
        }
 }
 
-/*
-void GameCommand_rankings(float request) // this is OLD.... jeez.
-{
-       switch(request)
-       {
-               case CMD_REQUEST_COMMAND:
-               {
-                       strunzone(rankings_reply);
-                       rankings_reply = strzone(getrankings());
-                       print(rankings_reply);
-                       return;
-               }
-                       
-               default:
-               case CMD_REQUEST_USAGE:
-               {
-                       print("\nUsage:^3 sv_cmd rankings");
-                       print("  No arguments required.");
-                       return;
-               }
-       }
-}
-*/
-
 void CommonCommand_rankings(float request, entity caller)
 {
        switch(request)
@@ -404,7 +433,8 @@ void CommonCommand_records(float request, entity caller)
                        float i;
                        
                        for(i = 0; i < 10; ++i)
-                               print_to(caller, records_reply[i]);
+                               if(records_reply[i])
+                                       print_to(caller, records_reply[i]);
                                
                        return; // never fall through to usage
                }
@@ -471,7 +501,7 @@ void CommonCommand_timein(float request, entity caller)
        {
                case CMD_REQUEST_COMMAND:
                {
-                       if(autocvar_sv_timeout)
+                       if(!caller || autocvar_sv_timeout)
                        {
                                if not(timeout_status) { print_to(caller, "^7Error: There is no active timeout called."); }
                                else if(caller && (caller != timeout_caller)) { print_to(caller, "^7Error: You are not allowed to stop the active timeout."); }
@@ -485,7 +515,7 @@ void CommonCommand_timein(float request, entity caller)
                                                        timeout_status = TIMEOUT_INACTIVE;
                                                        timeout_time = 0;
                                                        timeout_handler.nextthink = time; // timeout_handler has to take care of it immediately
-                                                       bprint(strcat("^7The timeout was aborted by ", caller.netname, " !\n"));
+                                                       bprint(strcat("^7The timeout was aborted by ", GetCallerName(caller), " !\n"));
                                                        return;
                                                }
                                                
@@ -493,7 +523,7 @@ void CommonCommand_timein(float request, entity caller)
                                                {
                                                        timeout_time = autocvar_sv_timeout_resumetime;
                                                        timeout_handler.nextthink = time; // timeout_handler has to take care of it immediately
-                                                       bprint(strcat("^1Attention: ^7", caller.netname, " resumed the game! Prepare for battle!\n"));
+                                                       bprint(strcat("^1Attention: ^7", GetCallerName(caller), " resumed the game! Prepare for battle!\n"));
                                                        return;
                                                }
                                                
@@ -501,6 +531,8 @@ void CommonCommand_timein(float request, entity caller)
                                        }
                                }
                        }
+                       else { print_to(caller, "^1Timeins are not allowed to be called, enable them with sv_timeout 1.\n"); }
+                       
                        return; // never fall through to usage
                }
                        
@@ -520,7 +552,7 @@ void CommonCommand_timeout(float request, entity caller) // DEAR GOD THIS COMMAN
        {
                case CMD_REQUEST_COMMAND:
                {
-                       if(autocvar_sv_timeout) 
+                       if(!caller || autocvar_sv_timeout)
                        {
                                float last_possible_timeout = ((autocvar_timelimit * 60) - autocvar_sv_timeout_leadtime - 1);
                                
@@ -536,7 +568,7 @@ void CommonCommand_timeout(float request, entity caller) // DEAR GOD THIS COMMAN
                                {                                       
                                        if(caller) { caller.allowed_timeouts -= 1; }
                                        
-                                       bprint(GetCallerName(caller), " ^7called a timeout", (caller ? strcat(" (", ftos(caller.allowed_timeouts), " timeouts left)") : string_null), "!\n"); // write a bprint who started the timeout (and how many they have left)
+                                       bprint(GetCallerName(caller), " ^7called a timeout", (caller ? strcat(" (", ftos(caller.allowed_timeouts), " timeout(s) left)") : string_null), "!\n"); // write a bprint who started the timeout (and how many they have left)
                                        
                                        timeout_status = TIMEOUT_LEADTIME;
                                        timeout_caller = caller;
@@ -550,6 +582,8 @@ void CommonCommand_timeout(float request, entity caller) // DEAR GOD THIS COMMAN
                                        Announce("timeoutcalled");
                                }
                        }
+                       else { print_to(caller, "^1Timeouts are not allowed to be called, enable them with sv_timeout 1.\n"); }
+                       
                        return; // never fall through to usage
                }
                        
@@ -657,4 +691,72 @@ void CommonCommand_(float request, entity caller)
                }
        }
 }
-*/
\ No newline at end of file
+*/
+
+
+// ==================================
+//  Macro system for common commands
+// ==================================
+
+// Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
+#define COMMON_COMMANDS(request,caller,arguments,command) \
+       COMMON_COMMAND("cvar_changes", CommonCommand_cvar_changes(request, caller), "Prints a list of all changed server cvars") \
+       COMMON_COMMAND("cvar_purechanges", CommonCommand_cvar_purechanges(request, caller), "Prints a list of all changed gameplay cvars") \
+       COMMON_COMMAND("info", CommonCommand_info(request, caller, arguments), "Request for unique server information set up by admin") \
+       COMMON_COMMAND("ladder", CommonCommand_ladder(request, caller), "Get information about top players if supported") \
+       COMMON_COMMAND("lsmaps", CommonCommand_lsmaps(request, caller), "List maps which can be used with the current game mode") \
+       COMMON_COMMAND("lsnewmaps", CommonCommand_lsnewmaps(request, caller), "List maps which have no records or are seemingly unplayed yet") \
+       COMMON_COMMAND("printmaplist", CommonCommand_printmaplist(request, caller), "Display full server maplist reply") \
+       COMMON_COMMAND("rankings", CommonCommand_rankings(request, caller), "Print information about rankings") \
+       COMMON_COMMAND("records", CommonCommand_records(request, caller), "List top 10 records for the current map") \
+       COMMON_COMMAND("teamstatus", CommonCommand_teamstatus(request, caller), "Show information about player and team scores") \
+       COMMON_COMMAND("time", CommonCommand_time(request, caller), "Print different formats/readouts of time") \
+       COMMON_COMMAND("timein", CommonCommand_timein(request, caller), "Resume the game from being paused with a timeout") \
+       COMMON_COMMAND("timeout", CommonCommand_timeout(request, caller), "Call a timeout which pauses the game for certain amount of time unless unpaused") \
+       COMMON_COMMAND("vote", VoteCommand(request, caller, arguments, command), "Request an action to be voted upon by players") \
+       COMMON_COMMAND("who", CommonCommand_who(request, caller, arguments), "Display detailed client information about all players") \
+       /* nothing */
+
+void CommonCommand_macro_help(entity caller)
+{
+       #define COMMON_COMMAND(name,function,description) \
+               { print_to(caller, strcat("  ^2", name, "^7: ", description)); }
+               
+       COMMON_COMMANDS(0, caller, 0, "")
+       #undef COMMON_COMMAND
+       
+       return;
+}
+
+float CommonCommand_macro_command(float argc, entity caller, string command)
+{
+       #define COMMON_COMMAND(name,function,description) \
+               { if(name == strtolower(argv(0))) { function; return TRUE; } }
+               
+       COMMON_COMMANDS(CMD_REQUEST_COMMAND, caller, argc, command)
+       #undef COMMON_COMMAND
+       
+       return FALSE;
+}
+
+float CommonCommand_macro_usage(float argc, entity caller)
+{
+       #define COMMON_COMMAND(name,function,description) \
+               { if(name == strtolower(argv(1))) { function; return TRUE; } }
+               
+       COMMON_COMMANDS(CMD_REQUEST_USAGE, caller, argc, "")
+       #undef COMMON_COMMAND
+       
+       return FALSE;
+}
+
+void CommonCommand_macro_write_aliases(float fh)
+{
+       #define COMMON_COMMAND(name,function,description) \
+               { CMD_Write_Alias("qc_cmd_svcmd", name, description); }
+               
+       COMMON_COMMANDS(0, world, 0, "")
+       #undef COMMON_COMMAND
+       
+       return;
+}
\ No newline at end of file