]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/command/sv_cmd.qc
Soft reset: Fix warmup limit and repeatable restart
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / sv_cmd.qc
index 81ef50aeda4a3120c08b71c2c80e77f09ead2c63..3e4195e509491e8cf41b9fcfb8850d63acab9228 100644 (file)
@@ -161,7 +161,13 @@ void GameCommand_allready(int request)
        {
                case CMD_REQUEST_COMMAND:
                {
-                       ReadyRestart();
+                       if(warmup_stage)
+                       {
+                               ReadyRestart(true);
+                       }
+                       else
+                               LOG_INFO("Not in warmup.");
+
                        return;
                }
 
@@ -184,8 +190,7 @@ void GameCommand_allspec(int request, int argc)
                        string reason = argv(1);
                        int n = 0;
                        FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
-                               if (it.caplayer) it.caplayer = 0;
-                               PutObserverInServer(it);
+                               PutObserverInServer(it, true);
                                ++n;
                        });
                        if (n)   bprint(strcat("Successfully forced all (", ftos(n), ") players to spectate", (reason ? strcat(" for reason: '", reason, "'") : ""), ".\n"));
@@ -745,7 +750,7 @@ void GameCommand_gametype(int request, int argc)
                                }
                                else
                                {
-                                       bprint("Game type switch to ", s, " failed: this type does not exist!\n");
+                                       bprint("Failed to switch to ", s, ": this game type does not exist!\n");
                                }
 
                                return;
@@ -1002,99 +1007,91 @@ void GameCommand_moveplayer(int request, int argc)
 
                                        if (accepted <= 0)
                                        {
-                                               LOG_INFO("moveplayer: ", GetClientErrorString(accepted, t), (targets ? ", skipping to next player.\n" : "."));
-                                               continue;
+                                               LOG_INFO("moveplayer: ", GetClientErrorString(accepted, t), ".");
                                        }
-
-                                       // Where are we putting this player?
-                                       if (destination == "spectator")
+                                       else if (destination == "spectator")
                                        {
+                                               string pl_name = playername(client.netname, client.team, false);
                                                if (!IS_SPEC(client) && !IS_OBSERVER(client))
                                                {
-                                                       if (client.caplayer) client.caplayer = 0;
-                                                       PutObserverInServer(client);
+                                                       PutObserverInServer(client, true);
 
-                                                       successful = strcat(successful, (successful ? ", " : ""), playername(client.netname, client.team, false));
+                                                       successful = strcat(successful, (successful ? ", " : ""), pl_name);
                                                }
                                                else
                                                {
-                                                       LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", playername(client.netname, client.team, false), ") is already spectating.");
+                                                       LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", pl_name, ") is already spectating.");
                                                }
-                                               continue;
                                        }
                                        else
                                        {
-                                               if (!IS_SPEC(client) && !IS_OBSERVER(client))
+                                               if (!teamplay)
                                                {
-                                                       if (teamplay)
-                                                       {
-                                                               // set up
-                                                               string pl_name = playername(client.netname, client.team, false);
-                                                               int save = Player_GetForcedTeamIndex(client);
-                                                               Player_SetForcedTeamIndex(client, TEAM_FORCE_DEFAULT);
-
-                                                               // find the team to move the player to
-                                                               int team_num = Team_ColorToTeam(destination);
-                                                               entity balance;
-                                                               if (team_num == client.team)  // already on the destination team
-                                                               {
-                                                                       // keep the forcing undone
-                                                                       LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", pl_name, ") is already on the ", Team_ColoredFullName(team_num), (targets ? "^7, skipping to next player.\n" : "^7."));
-                                                                       continue;
-                                                               }
-                                                               else if (team_num == 0)  // auto team
-                                                               {
-                                                                       balance = TeamBalance_CheckAllowedTeams(client);
-                                                                       team_num = Team_IndexToTeam(TeamBalance_FindBestTeam(balance, client, false));
-                                                               }
-                                                               else
-                                                               {
-                                                                       balance = TeamBalance_CheckAllowedTeams(client);
-                                                               }
-                                                               Player_SetForcedTeamIndex(client, save);
+                                                       LOG_INFO("Can't change teams when currently not playing a team game.");
+                                                       return;
+                                               }
 
-                                                               // Check to see if the destination team is even available
-                                                               int team_id = Team_TeamToIndex(team_num);
-                                                               if (team_id == -1)
-                                                               {
-                                                                       LOG_INFO("Sorry, can't move player here if team ", destination, " doesn't exist.");
-                                                                       TeamBalance_Destroy(balance);
-                                                                       return;
-                                                               }
-                                                               if (!TeamBalance_IsTeamAllowed(balance, team_id))
-                                                               {
-                                                                       LOG_INFOF("Sorry, can't move player to %s team if it doesn't exist.", destination);
-                                                                       TeamBalance_Destroy(balance);
-                                                                       return;
-                                                               }
-                                                               TeamBalance_Destroy(balance);
+                                               string pl_name = playername(client.netname, client.team, false);
+                                               if (IS_SPEC(client) || IS_OBSERVER(client))
+                                               {
+                                                       // well technically we could, but should we allow that? :P
+                                                       LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", pl_name, ") is not in the game.");
+                                                       continue;
+                                               }
 
-                                                               // If so, lets continue and finally move the player
-                                                               Player_SetForcedTeamIndex(client, TEAM_FORCE_DEFAULT);
-                                                               if (MoveToTeam(client, team_id, 6))
-                                                               {
-                                                                       successful = strcat(successful, (successful ? ", " : ""), pl_name);
-                                                                       LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", pl_name, ") has been moved to the ", Team_ColoredFullName(team_num), "^7.");
-                                                               }
-                                                               else
-                                                               {
-                                                                       LOG_INFO("Unable to move player ", ftos(GetFilteredNumber(t)), " (", pl_name, ")");
-                                                               }
-                                                               continue;
-                                                       }
-                                                       else
-                                                       {
-                                                               LOG_INFO("Can't change teams when currently not playing a team game.");
-                                                               return;
-                                                       }
+                                               // set up
+                                               int save = Player_GetForcedTeamIndex(client);
+                                               Player_SetForcedTeamIndex(client, TEAM_FORCE_DEFAULT);
+
+                                               // find the team to move the player to
+                                               int team_num = Team_ColorToTeam(destination);
+                                               entity balance;
+                                               if (team_num == client.team)  // already on the destination team
+                                               {
+                                                       // keep the forcing undone
+                                                       LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", pl_name, ") is already on the ", Team_ColoredFullName(team_num), ".");
+                                                       continue;
+                                               }
+                                               else if (team_num == 0)  // auto team
+                                               {
+                                                       balance = TeamBalance_CheckAllowedTeams(client);
+                                                       team_num = Team_IndexToTeam(TeamBalance_FindBestTeam(balance, client, false));
                                                }
                                                else
                                                {
-                                                       LOG_INFO("Can't change teams if the player isn't in the game.");  // well technically we could, but should we allow that? :P
+                                                       balance = TeamBalance_CheckAllowedTeams(client);
+                                               }
+                                               Player_SetForcedTeamIndex(client, save);
+
+                                               // Check to see if the destination team is even available
+                                               int team_id = Team_TeamToIndex(team_num);
+                                               if (team_id == -1)
+                                               {
+                                                       LOG_INFO("Sorry, can't move player here if team ", destination, " doesn't exist.");
+                                                       TeamBalance_Destroy(balance);
+                                                       return;
+                                               }
+                                               if (!TeamBalance_IsTeamAllowed(balance, team_id))
+                                               {
+                                                       LOG_INFOF("Sorry, can't move player to %s team if it doesn't exist.", destination);
+                                                       TeamBalance_Destroy(balance);
                                                        return;
                                                }
+                                               TeamBalance_Destroy(balance);
+
+                                               // If so, lets continue and finally move the player
+                                               Player_SetForcedTeamIndex(client, TEAM_FORCE_DEFAULT);
+                                               if (MoveToTeam(client, team_id, 6))
+                                               {
+                                                       successful = strcat(successful, (successful ? ", " : ""), pl_name);
+                                                       LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", pl_name, ") has been moved to the ", Team_ColoredFullName(team_num), "^7.");
+                                               }
+                                               else
+                                               {
+                                                       LOG_INFO("Unable to move player ", ftos(GetFilteredNumber(t)), " (", pl_name, ")");
+                                               }
                                        }
-                               }
+                               } // loop end
 
                                if (successful) bprint("Successfully moved players ", successful, " to destination ", destination, ".\n");
                                else LOG_INFO("No players given (", original_targets, ") are able to move.");
@@ -1309,6 +1306,26 @@ void GameCommand_shuffleteams(int request)
        }
 }
 
+void GameCommand_reset(int request)
+{
+       switch (request)
+       {
+               case CMD_REQUEST_COMMAND:
+               {
+                       ReadyRestart(false);
+                       return;
+               }
+
+               default:
+               case CMD_REQUEST_USAGE:
+               {
+                       LOG_HELP("Usage:^3 sv_cmd reset");
+                       LOG_HELP("  No arguments required.");
+                       return;
+               }
+       }
+}
+
 void GameCommand_stuffto(int request, int argc)
 {
        // This... is a fairly dangerous and powerful command... - It allows any arguments to be sent to a client via rcon.
@@ -1630,7 +1647,7 @@ void GameCommand_(int request)
 
 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
 SERVER_COMMAND(adminmsg, "Send an admin message to a client directly") { GameCommand_adminmsg(request, arguments); }
-SERVER_COMMAND(allready, "Restart the server and reset the players") { GameCommand_allready(request); }
+SERVER_COMMAND(allready, "Ends warmup and starts the match") { GameCommand_allready(request); }
 SERVER_COMMAND(allspec, "Force all players to spectate") { GameCommand_allspec(request, arguments); }
 SERVER_COMMAND(anticheat, "Create an anticheat report for a client") { GameCommand_anticheat(request, arguments); }
 SERVER_COMMAND(animbench, "Benchmark model animation (LAGS)") { GameCommand_animbench(request, arguments); }
@@ -1653,6 +1670,7 @@ SERVER_COMMAND(nospectators, "Automatically remove spectators from a match") { G
 SERVER_COMMAND(printstats, "Dump eventlog player stats and other score information") { GameCommand_printstats(request); }
 SERVER_COMMAND(radarmap, "Generate a radar image of the map") { GameCommand_radarmap(request, arguments); }
 SERVER_COMMAND(reducematchtime, "Decrease the timelimit value incrementally") { GameCommand_reducematchtime(request); }
+SERVER_COMMAND(reset, "Soft restart the server and reset the players") { GameCommand_reset(request); }
 SERVER_COMMAND(setbots, "Adjust how many bots are in the match") { GameCommand_setbots(request, arguments); }
 SERVER_COMMAND(shuffleteams, "Randomly move players to different teams") { GameCommand_shuffleteams(request); }
 SERVER_COMMAND(stuffto, "Send a command to be executed on a client") { GameCommand_stuffto(request, arguments); }