]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/command/sv_cmd.qc
Merge branch 'master' into martin-t/shuffleteams
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / sv_cmd.qc
index f056f0ff2f64533954fff7a98651c6b4fc52ec27..8c9d915a213a80e31c35fd2c1fcbfb065921c7c1 100644 (file)
@@ -1,5 +1,5 @@
 #include "sv_cmd.qh"
-#include "all.qh"
+#include "_mod.qh"
 
 #include "banning.qh"
 #include "cmd.qh"
@@ -9,20 +9,19 @@
 
 #include "../anticheat.qh"
 #include "../campaign.qh"
-#include "../cl_client.qh"
-#include "../cl_player.qh"
+#include "../client.qh"
+#include "../player.qh"
 #include "../g_world.qh"
 #include "../ipban.qh"
 #include "../playerdemo.qh"
 #include "../teamplay.qh"
 
-#include "../bot/bot.qh"
-#include "../bot/navigation.qh"
-#include "../bot/scripting.qh"
+#include "../bot/api.qh"
 
-#include "../mutators/all.qh"
+#include "../mutators/_mod.qh"
 
 #include <common/constants.qh>
+#include <common/net_linked.qh>
 #include <common/mapinfo.qh>
 #include <common/notifications/all.qh>
 #include <common/teams.qh>
 #include <common/monsters/sv_monsters.qh>
 
 
-void PutObserverInServer();
+void PutObserverInServer(entity this);
 
 // =====================================================
 //  Server side game commands code, reworked by Samual
-//  Last updated: December 29th, 2011
 // =====================================================
 
 //  used by GameCommand_make_mapinfo()
 void make_mapinfo_Think(entity this)
 {
-       if (MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
+       if (_MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
        {
                LOG_INFO("Done rebuiling mapinfos.\n");
                MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
-               remove(self);
+               delete(this);
        }
        else
        {
-               setthink(self, make_mapinfo_Think);
-               self.nextthink = time;
+               setthink(this, make_mapinfo_Think);
+               this.nextthink = time;
        }
 }
 
@@ -141,7 +139,7 @@ void GameCommand_adminmsg(float request, float argc)
                                        }
 
                                        successful = strcat(successful, (successful ? ", " : ""), client.netname);
-                                       LOG_TRACE("Message sent to ", client.netname, "\n");
+                                       LOG_TRACE("Message sent to ", client.netname);
                                        continue;
                                }
 
@@ -197,7 +195,7 @@ void GameCommand_allspec(float request, float argc)
                        int n = 0;
                        FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA(
                                if (it.caplayer) it.caplayer = 0;
-                               WITHSELF(it, PutObserverInServer());
+                               PutObserverInServer(it);
                                ++n;
                        ));
                        if (n)   bprint(strcat("Successfully forced all (", ftos(n), ") players to spectate", (reason ? strcat(" for reason: '", reason, "'") : ""), ".\n"));
@@ -227,7 +225,7 @@ void GameCommand_anticheat(float request, float argc)
 
                        if (accepted > 0)
                        {
-                               anticheat_report(client);
+                               anticheat_report_to_eventlog(client);
                                return;
                        }
                        else
@@ -264,7 +262,7 @@ void GameCommand_bbox(float request)
                                '0 1 0' * world.absmax.y + '0 0 1' * world.absmax.z,
                                '1 0 0' * world.absmax.x,
                                MOVE_WORLDONLY,
-                               world);
+                               NULL);
                        if (trace_startsolid) LOG_INFO(" ", ftos(world.absmin.x));
                        else LOG_INFO(" ", ftos(trace_endpos.x));
 
@@ -273,7 +271,7 @@ void GameCommand_bbox(float request)
                                '1 0 0' * world.absmax.x + '0 0 1' * world.absmax.z,
                                '0 1 0' * world.absmax.y,
                                MOVE_WORLDONLY,
-                               world);
+                               NULL);
                        if (trace_startsolid) LOG_INFO(" ", ftos(world.absmin.y));
                        else LOG_INFO(" ", ftos(trace_endpos.y));
 
@@ -282,7 +280,7 @@ void GameCommand_bbox(float request)
                                '1 0 0' * world.absmax.x + '0 1 0' * world.absmax.y,
                                '0 0 1' * world.absmax.z,
                                MOVE_WORLDONLY,
-                               world);
+                               NULL);
                        if (trace_startsolid) LOG_INFO(" ", ftos(world.absmin.z));
                        else LOG_INFO(" ", ftos(trace_endpos.z));
 
@@ -291,7 +289,7 @@ void GameCommand_bbox(float request)
                                '0 1 0' * world.absmax.y + '0 0 1' * world.absmax.z,
                                '1 0 0' * world.absmin.x,
                                MOVE_WORLDONLY,
-                               world);
+                               NULL);
                        if (trace_startsolid) LOG_INFO(" ", ftos(world.absmax.x));
                        else LOG_INFO(" ", ftos(trace_endpos.x));
 
@@ -300,7 +298,7 @@ void GameCommand_bbox(float request)
                                '1 0 0' * world.absmax.x + '0 0 1' * world.absmax.z,
                                '0 1 0' * world.absmin.y,
                                MOVE_WORLDONLY,
-                               world);
+                               NULL);
                        if (trace_startsolid) LOG_INFO(" ", ftos(world.absmax.y));
                        else LOG_INFO(" ", ftos(trace_endpos.y));
 
@@ -309,7 +307,7 @@ void GameCommand_bbox(float request)
                                '1 0 0' * world.absmax.x + '0 1 0' * world.absmax.y,
                                '0 0 1' * world.absmin.z,
                                MOVE_WORLDONLY,
-                               world);
+                               NULL);
                        if (trace_startsolid) LOG_INFO(" ", ftos(world.absmax.z));
                        else LOG_INFO(" ", ftos(trace_endpos.z));
 
@@ -384,10 +382,16 @@ void GameCommand_bot_cmd(float request, float argc, string command)
                                                }
                                                else
                                                {
-                                                       // let's start at token 2 so we can skip sv_cmd bot_cmd
-                                                       bot = find_bot_by_number(stof(argv(2)));
-                                                       if (bot == world) bot = find_bot_by_name(argv(2));
-                                                       if (bot) bot_queuecommand(bot, substring(s, argv_start_index(3), -1));
+                                                       if(argv(2) == "*" || argv(2) == "all")
+                                                               FOREACH_CLIENT(IS_BOT_CLIENT(it), {
+                                                                       bot_queuecommand(it, substring(s, argv_start_index(3), -1));
+                                                               });
+                                                       else
+                                                       {
+                                                               bot = find_bot_by_number(stof(argv(2)));
+                                                               if (bot == NULL) bot = find_bot_by_name(argv(2));
+                                                               if (bot) bot_queuecommand(bot, substring(s, argv_start_index(3), -1));
+                                                       }
                                                }
                                        }
                                        else
@@ -409,17 +413,31 @@ void GameCommand_bot_cmd(float request, float argc, string command)
                        }
                        else if (argc >= 3)  // this comes last
                        {
-                               bot = find_bot_by_number(stof(argv(1)));
-                               if (bot == world) bot = find_bot_by_name(argv(1));
-                               if (bot)
+                               if(argv(1) == "*" || argv(1) == "all")
                                {
-                                       LOG_INFO(strcat("Command '", substring(command, argv_start_index(2), -1), "' sent to bot ", bot.netname, "\n"));
-                                       bot_queuecommand(bot, substring(command, argv_start_index(2), -1));
+                                       int bot_num = 0;
+                                       FOREACH_CLIENT(IS_BOT_CLIENT(it), {
+                                               bot_queuecommand(it, substring(command, argv_start_index(2), -1));
+                                               bot_num++;
+                                       });
+                                       if(bot_num)
+                                               LOG_INFO(strcat("Command '", substring(command, argv_start_index(2), -1), "' sent to all bots (", ftos(bot_num), ")\n"));
                                        return;
                                }
                                else
                                {
-                                       LOG_INFO(strcat("Error: Can't find bot with the name or id '", argv(1), "' - Did you mistype the command?\n"));  // don't return so that usage is shown
+                                       bot = find_bot_by_number(stof(argv(1)));
+                                       if (bot == NULL) bot = find_bot_by_name(argv(1));
+                                       if (bot)
+                                       {
+                                               LOG_INFO(strcat("Command '", substring(command, argv_start_index(2), -1), "' sent to bot ", bot.netname, "\n"));
+                                               bot_queuecommand(bot, substring(command, argv_start_index(2), -1));
+                                               return;
+                                       }
+                                       else
+                                       {
+                                               LOG_INFO(strcat("Error: Can't find bot with the name or id '", argv(1), "' - Did you mistype the command?\n"));  // don't return so that usage is shown
+                                       }
                                }
                        }
                }
@@ -429,10 +447,12 @@ void GameCommand_bot_cmd(float request, float argc, string command)
                case CMD_REQUEST_USAGE:
                {
                        LOG_INFO("\nUsage:^3 sv_cmd bot_cmd client command [argument]\n");
-                       LOG_INFO("  'client' can be either the name or entity id of the bot\n");
+                       LOG_INFO("  'client' can be either the name of the bot or a progressive number (not the entity number!)\n");
+                       LOG_INFO("           can also be '*' or 'all' to allow sending the command to all the bots\n");
                        LOG_INFO("  For full list of commands, see bot_cmd help [command].\n");
-                       LOG_INFO("Examples: sv_cmd bot_cmd client cc \"say something\"\n");
-                       LOG_INFO("          sv_cmd bot_cmd client presskey jump\n");
+                       LOG_INFO("Examples: sv_cmd bot_cmd 1 cc \"say something\"\n");
+                       LOG_INFO("          sv_cmd bot_cmd 1 presskey jump\n");
+                       LOG_INFO("          sv_cmd bot_cmd * pause\n");
                        return;
                }
        }
@@ -448,7 +468,7 @@ void GameCommand_cointoss(float request, float argc)
                        string result2 = (argv(2) ? strcat("^7", argv(2)) : "^4TAILS");
                        string choice = ((random() > 0.5) ? result1 : result2);
 
-                       Send_Notification(NOTIF_ALL, world, MSG_MULTI, MULTI_COINTOSS, choice);
+                       Send_Notification(NOTIF_ALL, NULL, MSG_MULTI, MULTI_COINTOSS, choice);
                        return;
                }
 
@@ -742,7 +762,7 @@ void GameCommand_gametype(float request, float argc)
                        if (argv(1) != "")
                        {
                                string s = argv(1);
-                               float t = MapInfo_Type_FromString(s), tsave = MapInfo_CurrentGametype();
+                               Gametype t = MapInfo_Type_FromString(s), tsave = MapInfo_CurrentGametype();
 
                                if (t)
                                {
@@ -799,7 +819,7 @@ void GameCommand_gettaginfo(float request, float argc)
                                if (argv(1) == "w")
                                {
                                        .entity weaponentity = weaponentities[0];
-                                       _setmodel(tmp_entity, (nextent(world)).(weaponentity).model);
+                                       _setmodel(tmp_entity, (nextent(NULL)).(weaponentity).model);
                                }
                                else
                                {
@@ -830,7 +850,7 @@ void GameCommand_gettaginfo(float request, float argc)
                                        LOG_INFO("bone not found\n");
                                }
 
-                               remove(tmp_entity);
+                               delete(tmp_entity);
                                return;
                        }
                }
@@ -860,7 +880,7 @@ void GameCommand_animbench(float request, float argc)
                                if (argv(1) == "w")
                                {
                                        .entity weaponentity = weaponentities[0];
-                                       _setmodel(tmp_entity, (nextent(world)).(weaponentity).model);
+                                       _setmodel(tmp_entity, (nextent(NULL)).(weaponentity).model);
                                }
                                else
                                {
@@ -889,7 +909,7 @@ void GameCommand_animbench(float request, float argc)
                                LOG_INFO("model ", tmp_entity.model, " frame ", ftos(f1), " animtime ", ftos(n / t1), "/s\n");
                                LOG_INFO("model ", tmp_entity.model, " frame ", ftos(f2), " animtime ", ftos(n / t2), "/s\n");
 
-                               remove(tmp_entity);
+                               delete(tmp_entity);
                                return;
                        }
                }
@@ -1025,7 +1045,7 @@ void GameCommand_moveplayer(float request, float argc)
                                                if (!IS_SPEC(client) && !IS_OBSERVER(client))
                                                {
                                                        if (client.caplayer) client.caplayer = 0;
-                                                       WITHSELF(client, PutObserverInServer());
+                                                       PutObserverInServer(client);
 
                                                        successful = strcat(successful, (successful ? ", " : ""), client.netname);
                                                }
@@ -1327,90 +1347,37 @@ void GameCommand_shuffleteams(float request)
        {
                case CMD_REQUEST_COMMAND:
                {
-                       if (teamplay)
+                       if (!teamplay)
                        {
-                               float x, t_teams, t_players, team_color;
-
-                               // count the total amount of players and total amount of teams
-                               t_players = 0;
-                               t_teams = 0;
-                               FOREACH_CLIENT(IS_PLAYER(it) || it.caplayer, LAMBDA(
-                                       CheckAllowedTeams(it);
-
-                                       if (c1 >= 0) t_teams = max(1, t_teams);
-                                       if (c2 >= 0) t_teams = max(2, t_teams);
-                                       if (c3 >= 0) t_teams = max(3, t_teams);
-                                       if (c4 >= 0) t_teams = max(4, t_teams);
-
-                                       ++t_players;
-                               ));
-
-                               // build a list of the players in a random order
-                               FOREACH_CLIENT(IS_PLAYER(it) || it.caplayer, LAMBDA(
-                                       for ( ; ; )
-                                       {
-                                               int idx = bound(1, floor(random() * maxclients) + 1, maxclients);
-
-                                               if (shuffleteams_players[idx])
-                                               {
-                                                       continue;  // a player is already assigned to this slot
-                                               }
-                                               else
-                                               {
-                                                       shuffleteams_players[idx] = etof(it);
-                                                       break;
-                                               }
-                                       }
-                               ));
-
-                               // finally, from the list made earlier, re-join the players in different order.
-                               for (int i = 1; i <= t_teams; ++i)
-                               {
-                                       // find out how many players to assign to this team
-                                       x = (t_players / t_teams);
-                                       x = ((i == 1) ? ceil(x) : floor(x));
-
-                                       team_color = Team_NumberToTeam(i);
-
-                                       // sort through the random list of players made earlier
-                                       for (int z = 1; z <= maxclients; ++z)
-                                       {
-                                               if (!(shuffleteams_teams[i] >= x))
-                                               {
-                                                       if (!(shuffleteams_players[z])) continue;  // not a player, move on to next random slot
-
-                                                       entity e = NULL;
-                                                       if(VerifyClientNumber(shuffleteams_players[z]))
-                                                               e = edict_num(shuffleteams_players[z]);
-
-                                                       if(!e) continue; // unverified
-
-                                                       if (e.team != team_color) MoveToTeam(e, team_color, 6);
+                               LOG_INFO("Can't shuffle teams when currently not playing a team game.\n");
+                               return;
+                       }
 
-                                                       shuffleteams_players[z] = 0;
-                                                       shuffleteams_teams[i] = shuffleteams_teams[i] + 1;
-                                               }
-                                               else
-                                               {
-                                                       break;  // move on to next team
-                                               }
-                                       }
+                       FOREACH_CLIENT(IS_PLAYER(it) || it.caplayer, LAMBDA(
+                               if (it.team_forced) {
+                                       // we could theoretically assign forced players to their teams
+                                       // and shuffle the rest to fill the empty spots but in practise
+                                       // either all players or none are gonna have forced teams
+                                       LOG_INFO("Can't shuffle teams because at least one player has a forced team.\n");
+                                       return;
                                }
+                       ));
 
-                               bprint("Successfully shuffled the players around randomly.\n");
-
-                               // clear the buffers now
-                               for (int i = 0; i < SHUFFLETEAMS_MAX_PLAYERS; ++i)
-                                       shuffleteams_players[i] = 0;
-
-                               for (int i = 0; i < SHUFFLETEAMS_MAX_TEAMS; ++i)
-                                       shuffleteams_teams[i] = 0;
-                       }
-                       else
-                       {
-                               LOG_INFO("Can't shuffle teams when currently not playing a team game.\n");
-                       }
+                       int number_of_teams = 0;
+                       CheckAllowedTeams(NULL);
+                       if (c1 >= 0) number_of_teams = max(1, number_of_teams);
+                       if (c2 >= 0) number_of_teams = max(2, number_of_teams);
+                       if (c3 >= 0) number_of_teams = max(3, number_of_teams);
+                       if (c4 >= 0) number_of_teams = max(4, number_of_teams);
+
+                       int team_index = 0;
+                       FOREACH_CLIENT_RANDOM(IS_PLAYER(it) || it.caplayer, LAMBDA(
+                               int target_team_number = Team_NumberToTeam(team_index + 1);
+                               if (it.team != target_team_number) MoveToTeam(it, target_team_number, 6);
+                               team_index = (team_index + 1) % number_of_teams;
+                       ));
 
+                       bprint("Successfully shuffled the players around randomly.\n");
                        return;
                }
 
@@ -1507,15 +1474,15 @@ void GameCommand_trace(float request, float argc)
                                                start = stov(vtos(start));
                                                end = stov(vtos(end));
 
-                                               tracebox(start, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), end, MOVE_NOMONSTERS, world);
+                                               tracebox(start, PL_MIN_CONST, PL_MAX_CONST, end, MOVE_NOMONSTERS, NULL);
                                                if (!trace_startsolid && trace_fraction < 1)
                                                {
                                                        p = trace_endpos;
-                                                       tracebox(p, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), p, MOVE_NOMONSTERS, world);
+                                                       tracebox(p, PL_MIN_CONST, PL_MAX_CONST, p, MOVE_NOMONSTERS, NULL);
                                                        if (trace_startsolid)
                                                        {
                                                                rint(42);  // do an engine breakpoint on VM_rint so you can get the trace that errnoeously returns startsolid
-                                                               tracebox(start, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), end, MOVE_NOMONSTERS, world);
+                                                               tracebox(start, PL_MIN_CONST, PL_MAX_CONST, end, MOVE_NOMONSTERS, NULL);
 
                                                                // how much do we need to back off?
                                                                safe = 1;
@@ -1523,7 +1490,7 @@ void GameCommand_trace(float request, float argc)
                                                                for ( ; ; )
                                                                {
                                                                        pos = p * (1 - (safe + unsafe) * 0.5) + start * ((safe + unsafe) * 0.5);
-                                                                       tracebox(pos, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), pos, MOVE_NOMONSTERS, world);
+                                                                       tracebox(pos, PL_MIN_CONST, PL_MAX_CONST, pos, MOVE_NOMONSTERS, NULL);
                                                                        if (trace_startsolid)
                                                                        {
                                                                                if ((safe + unsafe) * 0.5 == unsafe) break;
@@ -1539,7 +1506,7 @@ void GameCommand_trace(float request, float argc)
                                                                LOG_INFO("safe distance to back off: ", ftos(safe * vlen(p - start)), "qu\n");
                                                                LOG_INFO("unsafe distance to back off: ", ftos(unsafe * vlen(p - start)), "qu\n");
 
-                                                               tracebox(p, STAT(PL_MIN, NULL) + '0.1 0.1 0.1', STAT(PL_MAX, NULL) - '0.1 0.1 0.1', p, MOVE_NOMONSTERS, world);
+                                                               tracebox(p, PL_MIN_CONST + '0.1 0.1 0.1', PL_MAX_CONST - '0.1 0.1 0.1', p, MOVE_NOMONSTERS, NULL);
                                                                if (trace_startsolid) LOG_INFO("trace_endpos much in solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p), "\n");
                                                                else LOG_INFO("trace_endpos just in solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p), "\n");
                                                                if (++hitcount >= 10) break;
@@ -1553,7 +1520,7 @@ void GameCommand_trace(float request, float argc)
                                                                {
                                                                        q = p + normalize(end - p) * (dq + dqf);
                                                                        if (q == q0) break;
-                                                                       tracebox(p, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), q, MOVE_NOMONSTERS, world);
+                                                                       tracebox(p, PL_MIN_CONST, PL_MAX_CONST, q, MOVE_NOMONSTERS, NULL);
                                                                        if (trace_startsolid) error("THIS ONE cannot happen");
                                                                        if (trace_fraction > 0) dq += dqf * trace_fraction;
                                                                        dqf *= 0.5;
@@ -1574,7 +1541,7 @@ void GameCommand_trace(float request, float argc)
 
                                case "debug2":
                                {
-                                       e = nextent(world);
+                                       e = nextent(NULL);
                                        tracebox(e.origin + '0 0 32', e.mins, e.maxs, e.origin + '0 0 -1024', MOVE_NORMAL, e);
                                        vv = trace_endpos;
                                        if (trace_fraction == 1)
@@ -1607,7 +1574,7 @@ void GameCommand_trace(float request, float argc)
                                {
                                        if (argc == 4)
                                        {
-                                               e = nextent(world);
+                                               e = nextent(NULL);
                                                if (tracewalk(e, stov(argv(2)), e.mins, e.maxs, stov(argv(3)), MOVE_NORMAL)) LOG_INFO("can walk\n");
                                                else LOG_INFO("cannot walk\n");
                                                return;
@@ -1620,9 +1587,9 @@ void GameCommand_trace(float request, float argc)
                                        {
                                                vv = stov(argv(2));
                                                dv = stov(argv(3));
-                                               traceline(vv, dv, MOVE_NORMAL, world);
-                                               __trailparticles(world, particleeffectnum(EFFECT_TR_NEXUIZPLASMA), vv, trace_endpos);
-                                               __trailparticles(world, particleeffectnum(EFFECT_TR_CRYLINKPLASMA), trace_endpos, dv);
+                                               traceline(vv, dv, MOVE_NORMAL, NULL);
+                                               __trailparticles(NULL, particleeffectnum(EFFECT_TR_NEXUIZPLASMA), vv, trace_endpos);
+                                               __trailparticles(NULL, particleeffectnum(EFFECT_TR_CRYLINKPLASMA), trace_endpos, dv);
                                                return;
                                        }
                                }
@@ -1826,7 +1793,7 @@ void GameCommand(string command)
                        BanCommand_macro_help();
 
                        LOG_INFO("\nCommon networked commands:\n");
-                       CommonCommand_macro_help(world);
+                       CommonCommand_macro_help(NULL);
 
                        LOG_INFO("\nGeneric commands shared by all programs:\n");
                        GenericCommand_macro_help();
@@ -1840,7 +1807,7 @@ void GameCommand(string command)
                {
                        return;
                }
-               else if (CommonCommand_macro_usage(argc, world))  // same here, but for common commands instead
+               else if (CommonCommand_macro_usage(argc, NULL))  // same here, but for common commands instead
                {
                        return;
                }
@@ -1861,7 +1828,7 @@ void GameCommand(string command)
        {
                return;  // handled by server/command/ipban.qc
        }
-       else if (CommonCommand_macro_command(argc, world, command))
+       else if (CommonCommand_macro_command(argc, NULL, command))
        {
                return;  // handled by server/command/common.qc
        }