]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/gamecommand.qc
Merge remote-tracking branch 'origin/master' into samual/updatecommands
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / gamecommand.qc
index 93d903063cc8f1446b1921eccbaa0562bb9f88f1..70371f42b782a48634a552a4c0d287b26ac9531b 100644 (file)
@@ -1,6 +1,6 @@
 // =====================================================
 //  Server side game commands code, reworked by Samual
-//  Last updated: July 13th, 2011
+//  Last updated: July 22nd, 2011
 // =====================================================
 
 #define GC_REQUEST_HELP 1
@@ -529,7 +529,7 @@ void GameCommand_adminmsg(float request, float argc)
                                                }
                                                else
                                                {
-                                                       centerprint_atprio(client, CENTERPRIO_ADMIN, strcat("^3", admin_name(), ":\n\n^7", argv(2)));
+                                                       centerprint(client, strcat("^3", admin_name(), ":\n\n^7", argv(2)));
                                                        sprint(client, strcat("\{1}\{13}^3", admin_name(), "^7: ", argv(2), "\n"));
                                                }
                                                dprint("Message sent to ", client.netname, "\n");
@@ -546,7 +546,7 @@ void GameCommand_adminmsg(float request, float argc)
                        print("\nUsage:^3 sv_cmd adminmsg clientnumber \"message\" [infobartime]\n");
                        print("  If infobartime is provided, the message will be sent to infobar.\n");
                        print("  Otherwise, it will just be sent as a centerprint message.\n");
-                       print("Examples: adminmsg 4 \"this message will last for ten seconds\" 10\n");
+                       print("Examples: adminmsg 4 \"this infomessage will last for ten seconds\" 10\n");
                        print("          adminmsg 2 \"this message will be a centerprint\"\n");
                        return;
        }
@@ -572,7 +572,7 @@ void GameCommand_allready(float request)
        }
 }
 
-void GameCommand_allspec(float request) // todo: Add ability to provide a reason string?
+void GameCommand_allspec(float request, float argc)
 {
        entity client;
        float i;
@@ -590,13 +590,14 @@ void GameCommand_allspec(float request) // todo: Add ability to provide a reason
                                PutObserverInServer();
                                ++i;
                        }
-                       if(i) { bprint(strcat("Successfully forced all players to spectate (", ftos(i), ")\n")); } // should a message be added if no players were found? 
+                       if(i) { bprint(strcat("Successfully forced all (", ftos(i), ") players to spectate", (argv(1) ? strcat(" for reason: '", argv(1), "'") : ""), ".\n")); }
+                       else { print("No players found to spectate.\n"); }
                        return;
                        
                default:
                case GC_REQUEST_USAGE:
-                       print("\nUsage:^3 sv_cmd allspec\n");
-                       print("  No arguments required.\n");
+                       print("\nUsage:^3 sv_cmd allspec [reason]\n");
+                       print("  Where 'reason' is an optional argument for explanation of allspec command.\n");
                        print("See also: ^2moveplayer^7\n");
                        return;
        }
@@ -631,7 +632,7 @@ void GameCommand_anticheat(float request, float argc) // FIXME: player entity is
                        print("Incorrect parameters for ^2anticheat^7\n");
                case GC_REQUEST_USAGE:
                        print("\nUsage:^3 sv_cmd anticheat clientnumber\n");
-                       print("  where clientnumber is player entity number.\n");
+                       print("  where 'clientnumber' is player entity number.\n");
                        return;
        }
 }
@@ -814,10 +815,12 @@ void GameCommand_bot_cmd(float request, float argc) // what a mess... old old co
        }
 }
 
-void GameCommand_cointoss(float request) // todo: Perhaps add the ability to give your own arguments to pick between? (Like player names)
+void GameCommand_cointoss(float request, float argc)
 {
        entity client;
-       float choice = (random() > 0.5);
+       string result1 = (argv(2) ? strcat("^7", argv(1), "^3!\n") : "^1HEADS^3!\n");
+       string result2 = (argv(2) ? strcat("^7", argv(2), "^3!\n") : "^4TAILS^3!\n");
+       string choice = ((random() > 0.5) ? result1 : result2);
        
        switch(request)
        {
@@ -827,14 +830,14 @@ void GameCommand_cointoss(float request) // todo: Perhaps add the ability to giv
                        
                case GC_REQUEST_COMMAND:
                        FOR_EACH_CLIENT(client)
-                               centerprint(client, strcat("^3Throwing coin... Result: ", (choice ? "^1HEADS^3!\n" : "^4TAILS^3!\n")));
-                       bprint(strcat("^3Throwing coin... Result: ", (choice ? "^1HEADS^3!\n" : "^4TAILS^3!\n")));
+                               centerprint(client, strcat("^3Throwing coin... Result: ", choice));
+                       bprint(strcat("^3Throwing coin... Result: ", choice));
                        return;
                        
                default:
                case GC_REQUEST_USAGE:
-                       print("\nUsage:^3 sv_cmd cointoss\n");
-                       print("  No arguments required.\n");
+                       print("\nUsage:^3 sv_cmd cointoss [result1 result2]\n");
+                       print("  Where 'result1' and 'result2' are user created options.\n");
                        return;
        }
 }
@@ -853,7 +856,7 @@ void GameCommand_cvar_changes(float request)
                        
                default:
                case GC_REQUEST_USAGE:
-                       print("\nUsage:^3 sv_cmd \n");
+                       print("\nUsage:^3 sv_cmd cvar_changes\n");
                        print("  No arguments required.\n");
                        print("See also: ^2cvar_purechanges^7\n");
                        return;
@@ -1105,7 +1108,7 @@ void GameCommand_effectindexdump(float request)
        }
 }
 
-void GameCommand_extendmatchtime(float request) // todo: Perhaps allows the user to send a specific time to extend it.
+void GameCommand_extendmatchtime(float request)
 {
        switch(request)
        {
@@ -1692,7 +1695,7 @@ void GameCommand_radarmap(float request, float argc)
                                {
                                        switch(argv(i))
                                        {
-                                               case "--force": { radarmapper.count |= 1; break;        }
+                                               case "--force": { radarmapper.count |= 1; break; }
                                                case "--loop": { radarmapper.count |= 2; break; }
                                                case "--quit": { radarmapper.count |= 4; break; }
                                                case "--block": { radarmapper.count &~= 24; break; }
@@ -1776,7 +1779,7 @@ void GameCommand_records(float request)
        }
 }
 
-void GameCommand_reducematchtime(float request) // todo: Perhaps allows the user to send a specific time to reduce it.
+void GameCommand_reducematchtime(float request)
 {
        switch(request)
        {
@@ -1867,6 +1870,32 @@ void GameCommand_teamstatus(float request)
        }
 }
 
+void GameCommand_time(float request)
+{
+       switch(request)
+       {
+               case GC_REQUEST_HELP:
+                       print("  ^2time^7: Print different formats/readouts of time\n");
+                       return;
+                       
+               case GC_REQUEST_COMMAND:
+                       print("time = ", ftos(time), "\n");
+                       print("frame start = ", ftos(gettime(GETTIME_FRAMESTART)), "\n");
+                       print("realtime = ", ftos(gettime(GETTIME_REALTIME)), "\n");
+                       print("hires = ", ftos(gettime(GETTIME_HIRES)), "\n");
+                       print("uptime = ", ftos(gettime(GETTIME_UPTIME)), "\n");
+                       print("localtime = ", strftime(TRUE, "%a %b %e %H:%M:%S %Z %Y"), "\n"); // FIXME: Why is strftime broken? is engine problem, I think.
+                       print("gmtime = ", strftime(FALSE, "%a %b %e %H:%M:%S %Z %Y"), "\n");
+                       return;
+                       
+               default:
+               case GC_REQUEST_USAGE:
+                       print("\nUsage:^3 sv_cmd time\n");
+                       print("  No arguments required.\n");
+                       return;
+       }
+}
+
 void GameCommand_trace(float request, float argc)
 {
        entity e;
@@ -2036,33 +2065,94 @@ void GameCommand_trace(float request, float argc)
        }
 }
 
+void GameCommand_unlockteams(float request)
+{
+       switch(request)
+       {
+               case GC_REQUEST_HELP:
+                       print("  ^2unlockteams^7: Enable the ability for players to switch or enter teams\n");
+                       return;
+                       
+               case GC_REQUEST_COMMAND:
+                       if(teamplay)
+                       {
+                               lockteams = 0;
+                               bprint("^1The teams are now unlocked.\n");
+                       }
+                       else
+                               bprint("That command can only be used in a team-based gamemode.\n");
+                       return;
+                       
+               default:
+               case GC_REQUEST_USAGE:
+                       print("\nUsage:^3 sv_cmd unlockteams\n");
+                       print("  No arguments required.\n");
+                       print("See also: ^2lockteams^7\n");
+                       return;
+       }
+}
+
+void GameCommand_warp(float request, float argc)
+{
+       switch (request)
+       {
+               case GC_REQUEST_HELP:
+                       print("  ^2warp^7: Choose different level in campaign\n");
+                       return;
+               
+               case GC_REQUEST_COMMAND:
+                       if(autocvar_g_campaign)
+                       {
+                               
+                               if(argc >= 2)
+                               {
+                                       CampaignLevelWarp(stof(argv(1)));
+                                       print("Successfully warped to campaign level ", stof(argv(1)), ".\n");
+                               }       
+                               else
+                               {
+                                       CampaignLevelWarp(-1);
+                                       print("Successfully warped to next campaign level.\n");
+                               }
+                       }
+                       else
+                               print("Not in campaign, can't level warp\n");
+                       return;
+               
+               default:
+               case GC_REQUEST_USAGE:
+                       print("\nUsage:^3 sv_cmd level\n");
+                       print("  'level' is the level to change campaign mode to.\n");
+                       return;
+       }
+}
+
 
 // =========================================
 //  Main Function Called By Engine (sv_cmd)
 // =========================================
+// If this function exists, game code handles gamecommand instead of the engine code.
 
 void GameCommand(string command)
 {
        // ===== TODO list =====
-       // Finish adding the rest of the commands
-       
        // find all FIXME's and TODO'S and UNTESTED'S and finish them :P
 
        float search_request_type;
        float argc = tokenize_console(command);
 
-       if(argv(0) == "help") 
+       if(strtolower(argv(0)) == "help") 
        {
                if(argc == 1) 
                {
                        print("\nUsage:^3 sv_cmd COMMAND...^7, where possible commands are:\n");
                        GameCommand_adminmsg(GC_REQUEST_HELP, 0);
                        GameCommand_allready(GC_REQUEST_HELP);
-                       GameCommand_allspec(GC_REQUEST_HELP);
+                       GameCommand_allspec(GC_REQUEST_HELP, 0);
                        GameCommand_anticheat(GC_REQUEST_HELP, 0);
                        GameCommand_bbox(GC_REQUEST_HELP);
                        GameCommand_bot_cmd(GC_REQUEST_HELP, 0);
-                       GameCommand_cointoss(GC_REQUEST_HELP);
+                       GameCommand_cointoss(GC_REQUEST_HELP, 0);
                        GameCommand_cvar_changes(GC_REQUEST_HELP);
                        GameCommand_cvar_purechanges(GC_REQUEST_HELP);
                        GameCommand_database(GC_REQUEST_HELP, 0);
@@ -2090,7 +2180,10 @@ void GameCommand(string command)
                        GameCommand_reducematchtime(GC_REQUEST_HELP);
                        GameCommand_stuffto(GC_REQUEST_HELP, 0);
                        GameCommand_teamstatus(GC_REQUEST_HELP);
+                       GameCommand_time(GC_REQUEST_HELP);
                        GameCommand_trace(GC_REQUEST_HELP, 0);
+                       GameCommand_unlockteams(GC_REQUEST_HELP);
+                       GameCommand_warp(GC_REQUEST_HELP, 0);
                        GameCommand_Vote("help", world);
                        GameCommand_Ban("help");
                        GameCommand_Generic("help");
@@ -2115,18 +2208,18 @@ void GameCommand(string command)
        else
                search_request_type = GC_REQUEST_COMMAND; // continue as usual and scan for normal commands
                
-       switch( ((argv(0) == "help") ? argv(1) : argv(0)) ) // if first argument is help, then search for the second argument. Else, search for first. 
+       switch(strtolower((search_request_type == GC_REQUEST_USAGE) ? argv(1) : argv(0))) // if first argument is help, then search for the second argument. Else, search for first. 
        {
                // Do not hard code aliases for these, instead create them in defaultXonotic.cfg
                // also: keep in alphabetical order, please ;)
                
                case "adminmsg": GameCommand_adminmsg(search_request_type, argc); break;
                case "allready": GameCommand_allready(search_request_type); break;
-               case "allspec": GameCommand_allspec(search_request_type); break;
+               case "allspec": GameCommand_allspec(search_request_type, argc); break;
                case "anticheat": GameCommand_anticheat(search_request_type, argc); break;
                case "bbox": GameCommand_bbox(search_request_type); break;
                case "bot_cmd": GameCommand_bot_cmd(search_request_type, argc); break;
-               case "cointoss": GameCommand_cointoss(search_request_type); break; 
+               case "cointoss": GameCommand_cointoss(search_request_type, argc); break; 
                case "cvar_changes": GameCommand_cvar_changes(search_request_type); break; 
                case "cvar_purechanges": GameCommand_cvar_purechanges(search_request_type); break; 
                case "database": GameCommand_database(search_request_type, argc); break;
@@ -2154,7 +2247,10 @@ void GameCommand(string command)
                case "reducematchtime": GameCommand_reducematchtime(search_request_type); break;
                case "stuffto": GameCommand_stuffto(search_request_type, argc); break;
                case "teamstatus": GameCommand_teamstatus(search_request_type); break;
+               case "time": GameCommand_time(search_request_type); break;
                case "trace": GameCommand_trace(search_request_type, argc); break;
+               case "unlockteams": GameCommand_unlockteams(search_request_type); break;
+               case "warp": GameCommand_warp(search_request_type, argc); break;
                
                default:
                        print("Invalid command. For a list of supported commands, try sv_cmd help.\n");