]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/gamecommand.qc
Merge remote branch 'origin/master' into samual/updatecommands
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / gamecommand.qc
index d40bc9ec38837ac364a1d8493e72407811cc4acd..74dc541a6751dd35cb4e531ffe7b54502736a12c 100644 (file)
@@ -1,6 +1,6 @@
 // =====================================================
 //  Server side game commands code, reworked by Samual
-//  Last updated: November 8th, 2011
+//  Last updated: November 30th, 2011
 // =====================================================
 
 #define GC_REQUEST_COMMAND 1
@@ -203,7 +203,7 @@ void GameCommand_allspec(float request, float argc)
                        string reason = argv(1);
                        float i;
                        
-                       FOR_EACH_PLAYER(client)
+                       FOR_EACH_REALPLAYER(client)
                        {
                                self = client;
                                PutObserverInServer();
@@ -622,7 +622,7 @@ void GameCommand_defer_clear_all(float request)
                                GameCommand_defer_clear(GC_REQUEST_COMMAND, argc);      
                                ++i;
                        }
-                       if(i) { bprint(strcat("Successfully stuffed defer clear to all clients (", ftos(i), ")\n")); } // should a message be added if no players were found? 
+                       if(i) { print(strcat("Successfully stuffed defer clear to all clients (", ftos(i), ")\n")); } // should a message be added if no players were found? 
                        return;
                }
                
@@ -947,7 +947,9 @@ void GameCommand_lockteams(float request)
                                bprint("^1The teams are now locked.\n");
                        }
                        else
-                               bprint("That command can only be used in a team-based gamemode.\n");
+                       {
+                               bprint("lockteams command can only be used in a team-based gamemode.\n");
+                       }
                        return;
                }
                        
@@ -1121,7 +1123,7 @@ void GameCommand_moveplayer(float request, float argc)
                                }
                                
                                if(successful)
-                                       print("Successfully moved players ", successful, " to destination ", destination, ".\n");
+                                       bprint("Successfully moved players ", successful, " to destination ", destination, ".\n");
                                else
                                        print("No players given (", original_targets, ") are able to move.\n");
                                        
@@ -1214,7 +1216,7 @@ void GameCommand_playerdemo(float request, float argc) // UNTESTED
                                case "read":
                                {
                                        // TODO: Create a general command for looking this up, save a lot of space everywhere in this file
-                                       entno = stof(argv(2));
+                                       entno = GetFilteredNumber(argv(2));
                                        if((entno < 1) | (entno > maxclients)) {
                                                print("Player ", argv(2), " doesn't exist\n");
                                                return;
@@ -1231,7 +1233,7 @@ void GameCommand_playerdemo(float request, float argc) // UNTESTED
                                
                                case "write":
                                {
-                                       entno = stof(argv(2));
+                                       entno = GetFilteredNumber(argv(2));
                                        if((entno < 1) | (entno > maxclients)) {
                                                print("Player ", argv(2), " doesn't exist\n");
                                                return;
@@ -1245,7 +1247,7 @@ void GameCommand_playerdemo(float request, float argc) // UNTESTED
                                case "auto_read_and_write":
                                {
                                        s = argv(2);
-                                       n = stof(argv(3));
+                                       n = GetFilteredNumber(argv(3));
                                        cvar_set("bot_number", ftos(n));
                                        localcmd("wait; wait; wait\n");
                                        for(i = 0; i < n; ++i)
@@ -1257,7 +1259,7 @@ void GameCommand_playerdemo(float request, float argc) // UNTESTED
                                case "auto_read":
                                {
                                        s = argv(2);
-                                       n = stof(argv(3));
+                                       n = GetFilteredNumber(argv(3));
                                        cvar_set("bot_number", ftos(n));
                                        localcmd("wait; wait; wait\n");
                                        for(i = 0; i < n; ++i)
@@ -1396,16 +1398,17 @@ void GameCommand_setbots(float request, float argc)
        {
                case GC_REQUEST_COMMAND:
                {
-                       if(argc >= 3 && argv(1) == "setbots")
+                       if(argc >= 2)
                        {
                                cvar_settemp("minplayers", "0");
-                               cvar_settemp("bot_number", argv(2));
+                               cvar_settemp("bot_number", argv(1));
                                bot_fixcount();
                                return;
                        }
                }
                        
                default:
+                       print("Incorrect parameters for ^2setbots^7\n");
                case GC_REQUEST_USAGE:
                {
                        print("\nUsage:^3 sv_cmd setbots botnumber\n");
@@ -1425,7 +1428,7 @@ void GameCommand_shuffleteams(float request)
                        if(teamplay)
                        {
                                entity tmp_player;
-                               float i, x, z, t_teams, t_players, random_number, team_color;
+                               float i, x, z, t_teams, t_players, team_color;
 
                                // count the total amount of players and total amount of teams
                                FOR_EACH_PLAYER(tmp_player)
@@ -1445,15 +1448,15 @@ void GameCommand_shuffleteams(float request)
                                {
                                        for(;;)
                                        {
-                                               random_number = bound(1, floor(random() * maxclients) + 1, maxclients);
+                                               i = bound(1, floor(random() * maxclients) + 1, maxclients);
                                                
-                                               if(shuffleteams_players[random_number])
+                                               if(shuffleteams_players[i])
                                                {
                                                        continue; // a player is already assigned to this slot
                                                }
                                                else
                                                {
-                                                       shuffleteams_players[random_number] = num_for_edict(tmp_player);
+                                                       shuffleteams_players[i] = num_for_edict(tmp_player);
                                                        break;
                                                }
                                        }
@@ -1470,24 +1473,28 @@ void GameCommand_shuffleteams(float request)
                                        
                                        // sort through the random list of players made earlier 
                                        for(z = 1; z <= maxclients; ++z)
-                                       {
-                                               if(shuffleteams_teams[i] >= x)
-                                                       break; // move on to next team
-                                               
-                                               if not(shuffleteams_players[z])
-                                                       continue; // not a player, move on to next random slot
-                                                       
-                                               self = edict_num(shuffleteams_players[z]); // TODO: add sanity checks for this entity to make sure it's okay and not some error.
-                                               if(self.team != team_color) 
+                                       {                                                       
+                                               if not(shuffleteams_teams[i] >= x)
                                                {
-                                                       MoveToTeam(self, team_color, 6, 0);
+                                                       if not(shuffleteams_players[z])
+                                                               continue; // not a player, move on to next random slot
+                                                               
+                                                       self = edict_num(shuffleteams_players[z]); // TODO: add sanity checks for this entity to make sure it's okay and not some error.
+                                                               
+                                                       if(self.team != team_color) 
+                                                               MoveToTeam(self, team_color, 6, 0);
+
                                                        shuffleteams_players[z] = 0;
                                                        shuffleteams_teams[i] = shuffleteams_teams[i] + 1;
                                                }
+                                               else
+                                               {
+                                                       break; // move on to next team
+                                               }
                                        }
                                }
                                
-                               print("Successfully shuffled the players around randomly.\n");
+                               bprint("Successfully shuffled the players around randomly.\n");
                                
                                // clear the buffers now
                                for (i=0; i<SHUFFLETEAMS_MAX_PLAYERS; ++i)
@@ -1531,7 +1538,7 @@ void GameCommand_stuffto(float request, float argc)
                        
                        if(argc == 3)
                        {
-                               entno = stof(argv(1));
+                               entno = GetFilteredNumber(argv(1));
                                client = world;
                                if(entno <= maxclients)
                                        client = edict_num(entno);
@@ -1625,6 +1632,7 @@ void GameCommand_trace(float request, float argc)
                        switch(argv(1))
                        {
                                case "debug":
+                               {
                                        print("TEST CASE. If this returns the runaway loop counter error, possibly everything is oaky.\n");
                                        for(;;)
                                        {
@@ -1713,8 +1721,10 @@ void GameCommand_trace(float request, float argc)
                                                }
                                        }
                                        return;
+                               }
                                        
                                case "debug2":
+                               {
                                        e = nextent(world);
                                        tracebox(e.origin + '0 0 32', e.mins, e.maxs, e.origin + '0 0 -1024', MOVE_NORMAL, e);
                                        vv = trace_endpos;
@@ -1742,8 +1752,10 @@ void GameCommand_trace(float request, float argc)
                                        }
                                        print("highest possible dist: ", ftos(f), "\n");
                                        return;
+                               }
                                
                                case "walk":
+                               {
                                        if(argc == 3)
                                        {
                                                e = nextent(world);
@@ -1753,8 +1765,10 @@ void GameCommand_trace(float request, float argc)
                                                        print("cannot walk\n");
                                                return;
                                        }
-                                               
+                               }
+                               
                                case "showline":
+                               {
                                        if(argc == 3)
                                        {
                                                vv = stov(argv(1));
@@ -1764,11 +1778,14 @@ void GameCommand_trace(float request, float argc)
                                                trailparticles(world, particleeffectnum("TR_CRYLINKPLASMA"), trace_endpos, dv);
                                                return;
                                        }
-                               // no default case, just go straight to "invalid arguments"
+                               }
+                               
+                               // no default case, just go straight to invalid
                        }
                }
                        
                default:
+                       print("Incorrect parameters for ^2trace^7\n");
                case GC_REQUEST_USAGE:
                {
                        print("\nUsage:^3 sv_cmd trace command [arguments]\n");
@@ -1790,7 +1807,9 @@ void GameCommand_unlockteams(float request)
                                bprint("^1The teams are now unlocked.\n");
                        }
                        else
-                               bprint("That command can only be used in a team-based gamemode.\n");
+                       {
+                               bprint("unlockteams command can only be used in a team-based gamemode.\n");
+                       }
                        return;
                }
                        
@@ -1908,6 +1927,7 @@ void GameCommand_(float request)
        SERVER_COMMAND("trace", GameCommand_trace(request, arguments), "Various debugging tools with tracing") \
        SERVER_COMMAND("unlockteams", GameCommand_unlockteams(request), "Enable the ability for players to switch or enter teams") \
        SERVER_COMMAND("warp", GameCommand_warp(request, arguments), "Choose different level in campaign") \
+       SERVER_COMMAND("vote", VoteCommand(world, arguments), "Server side control of voting") \
        /* nothing */
 
 void GameCommand_macro_help()
@@ -1959,7 +1979,7 @@ void GameCommand(string command)
                {
                        print("\nUsage:^3 sv_cmd COMMAND...^7, where possible commands are:\n");
                        GameCommand_macro_help();
-                       GameCommand_Vote("help", world);
+                       
                        GameCommand_Ban("help");
                        GameCommand_Generic("help");
                        print("For help about specific commands, type sv_cmd help COMMAND\n");
@@ -1970,10 +1990,6 @@ void GameCommand(string command)
                        return;
                }
        } 
-       else if(GameCommand_Vote(command, world)) 
-       {
-               return; // handled by server/vote.qc 
-       }
        else if(GameCommand_Ban(command)) 
        {
                return; // handled by server/ipban.qc
@@ -1988,7 +2004,7 @@ void GameCommand(string command)
        }
        
        // nothing above caught the command, must be invalid
-       print("Invalid command. For a list of supported commands, try sv_cmd help.\n");
+       print("Unknown server command", ((command != "") ? strcat(" \"", command, "\"") : ""), ". For a list of supported commands, try sv_cmd help.\n");
        
        return;
 }
\ No newline at end of file