]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/command/common.qc
When possible use simpler LOG_* macros instead of LOG_*F
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / common.qc
index a252b1f501130a5e2705d1efe391d78f980d4411..6121867e20fd32f1e05504882ba488cbf357e91d 100644 (file)
@@ -1,11 +1,16 @@
-#include "../../common/command/command.qh"
+#include "common.qh"
+
+#include <server/defs.qh>
+#include <server/miscfunctions.qh>
+
+#include <common/command/_mod.qh>
 #include "common.qh"
 
 #include "../scores.qh"
 
-#include "../../common/monsters/all.qh"
-#include "../../common/notifications.qh"
-#include "../../lib/warpzone/common.qh"
+#include <common/monsters/_mod.qh>
+#include <common/notifications/all.qh>
+#include <lib/warpzone/common.qh>
 
 
 // ====================================================
@@ -23,8 +28,8 @@ string GetCommandPrefix(entity caller)
 // if client return player nickname, or if server return admin nickname
 string GetCallerName(entity caller)
 {
-       if (caller) return caller.netname;
-       else return admin_name();  // ((autocvar_sv_adminnick != "") ? autocvar_sv_adminnick : autocvar_hostname);
+       if (caller) return playername(caller, false);
+       else return ((autocvar_sv_adminnick != "") ? autocvar_sv_adminnick : "SERVER ADMIN"); // autocvar_hostname
 }
 
 // verify that the client provided is acceptable for kicking
@@ -71,7 +76,7 @@ float VerifyClientNumber(float tmp_number)
        else return true;
 }
 
-entity GetIndexedEntity(float argc, float start_index)
+entity GetIndexedEntity(int argc, float start_index)
 {
        entity selection;
        float tmp_number, index;
@@ -79,7 +84,7 @@ entity GetIndexedEntity(float argc, float start_index)
 
        next_token = -1;
        index = start_index;
-       selection = world;
+       selection = NULL;
 
        if (argc > start_index)
        {
@@ -114,13 +119,13 @@ entity GetIndexedEntity(float argc, float start_index)
                }
                else  // no, maybe it's a name?
                {
-                       FOREACH_CLIENT(true, LAMBDA(
+                       FOREACH_CLIENT(true, {
                                if(strdecolorize(it.netname) == strdecolorize(argv(start_index)))
                                {
                                        selection = it;
                                        break; // no reason to keep looking
                                }
-                       ));
+                       });
 
                        index = (start_index + 1);
                }
@@ -146,14 +151,14 @@ entity GetFilteredEntity(string input)
        }
        else
        {
-               selection = world;
-               FOREACH_CLIENT(true, LAMBDA(
+               selection = NULL;
+               FOREACH_CLIENT(true, {
                        if(strdecolorize(it.netname) == strdecolorize(input))
                        {
                                selection = it;
                                break; // no reason to keep looking
                        }
-               ));
+               });
        }
 
        return selection;
@@ -174,7 +179,7 @@ float GetFilteredNumber(string input)
 void print_to(entity to, string input)
 {
        if (to) sprint(to, strcat(input, "\n"));
-       else LOG_INFO(input, "\n");
+       else print(input, "\n");
 }
 
 // ==========================================
@@ -182,46 +187,45 @@ void print_to(entity to, string input)
 // ==========================================
 
 // used by CommonCommand_timeout() and CommonCommand_timein() to handle game pausing and messaging and such.
-void timeout_handler_reset()
+void timeout_handler_reset(entity this)
 {
-       SELFPARAM();
-       timeout_caller = world;
+       timeout_caller = NULL;
        timeout_time = 0;
        timeout_leadtime = 0;
 
-       remove(self);
+       delete(this);
 }
 
-void timeout_handler_think()
+void timeout_handler_think(entity this)
 {
-       SELFPARAM();
        switch (timeout_status)
        {
                case TIMEOUT_ACTIVE:
                {
                        if (timeout_time > 0)  // countdown is still going
                        {
-                               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_TIMEOUT_ENDING, timeout_time);
+                               Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_TIMEOUT_ENDING, timeout_time);
 
                                if (timeout_time == autocvar_sv_timeout_resumetime) // play a warning sound when only <sv_timeout_resumetime> seconds are left
-                                       Send_Notification(NOTIF_ALL, world, MSG_ANNCE, ANNCE_PREPARE);
+                                       Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_PREPARE);
 
-                               self.nextthink = time + TIMEOUT_SLOWMO_VALUE;       // think again in one second
+                               this.nextthink = time + TIMEOUT_SLOWMO_VALUE;       // think again in one second
                                timeout_time -= 1;                                  // decrease the time counter
                        }
                        else  // time to end the timeout
                        {
+                               Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_TIMEIN);
                                timeout_status = TIMEOUT_INACTIVE;
 
                                // reset the slowmo value back to normal
                                cvar_set("slowmo", ftos(orig_slowmo));
 
                                // unlock the view for players so they can move around again
-                               FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA(
+                               FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
                                        it.fixangle = false;
-                               ));
+                               });
 
-                               timeout_handler_reset();
+                               timeout_handler_reset(this);
                        }
 
                        return;
@@ -231,9 +235,9 @@ void timeout_handler_think()
                {
                        if (timeout_leadtime > 0)  // countdown is still going
                        {
-                               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_TIMEOUT_BEGINNING, timeout_leadtime);
+                               Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_TIMEOUT_BEGINNING, timeout_leadtime);
 
-                               self.nextthink = time + 1; // think again in one second
+                               this.nextthink = time + 1; // think again in one second
                                timeout_leadtime -= 1;     // decrease the time counter
                        }
                        else  // time to begin the timeout
@@ -244,18 +248,18 @@ void timeout_handler_think()
                                cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE));
 
                                // reset all the flood variables
-                               FOREACH_CLIENT(true, LAMBDA(
-                                       it.nickspamcount = it.nickspamtime = it.floodcontrol_chat = 
+                               FOREACH_CLIENT(true, {
+                                       it.nickspamcount = it.nickspamtime = it.floodcontrol_chat =
                                                it.floodcontrol_chatteam = it.floodcontrol_chattell =
                                                        it.floodcontrol_voice = it.floodcontrol_voiceteam = 0;
-                               ));
+                               });
 
                                // copy .v_angle to .lastV_angle for every player in order to fix their view during pause (see PlayerPreThink)
-                               FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA(
+                               FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
                                        it.lastV_angle = it.v_angle;
-                               ));
+                               });
 
-                               self.nextthink = time;  // think again next frame to handle it under TIMEOUT_ACTIVE code
+                               this.nextthink = time;  // think again next frame to handle it under TIMEOUT_ACTIVE code
                        }
 
                        return;
@@ -265,7 +269,7 @@ void timeout_handler_think()
                case TIMEOUT_INACTIVE:
                default:
                {
-                       timeout_handler_reset();
+                       timeout_handler_reset(this);
                        return;
                }
        }
@@ -276,7 +280,7 @@ void timeout_handler_think()
 //  Common commands used in both sv_cmd.qc and cmd.qc
 // ===================================================
 
-void CommonCommand_cvar_changes(float request, entity caller)
+void CommonCommand_cvar_changes(int request, entity caller)
 {
        switch (request)
        {
@@ -297,7 +301,7 @@ void CommonCommand_cvar_changes(float request, entity caller)
        }
 }
 
-void CommonCommand_cvar_purechanges(float request, entity caller)
+void CommonCommand_cvar_purechanges(int request, entity caller)
 {
        switch (request)
        {
@@ -320,7 +324,6 @@ void CommonCommand_cvar_purechanges(float request, entity caller)
 
 void CommonCommand_editmob(int request, entity caller, int argc)
 {
-       SELFPARAM();
        switch (request)
        {
                case CMD_REQUEST_COMMAND:
@@ -330,8 +333,8 @@ void CommonCommand_editmob(int request, entity caller, int argc)
 
                        if (caller)
                        {
-                               makevectors(self.v_angle);
-                               WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * 100, MOVE_NORMAL, self);
+                               makevectors(caller.v_angle);
+                               WarpZone_TraceLine(caller.origin + caller.view_ofs, caller.origin + caller.view_ofs + v_forward * 100, MOVE_NORMAL, caller);
                        }
 
                        entity mon = trace_ent;
@@ -363,37 +366,36 @@ void CommonCommand_editmob(int request, entity caller, int argc)
                                        int moveflag, tmp_moncount = 0;
                                        string arg_lower = strtolower(argument);
                                        moveflag = (argv(3)) ? stof(argv(3)) : 1;  // follow owner if not defined
-                                       ret_string = "Monster spawning is currently disabled by a mutator";
 
                                        if (arg_lower == "list") { print_to(caller, monsterlist_reply); return; }
 
-                                       FOR_EACH_MONSTER(mon)
+                                       IL_EACH(g_monsters, it.realowner == caller,
                                        {
-                                               if (mon.realowner == caller) ++tmp_moncount;
-                                       }
+                                               ++tmp_moncount;
+                                       });
 
                                        if (!autocvar_g_monsters) { print_to(caller, "Monsters are disabled"); return; }
                                        if (autocvar_g_monsters_max <= 0 || autocvar_g_monsters_max_perplayer <= 0) { print_to(caller, "Monster spawning is disabled"); return; }
                                        if (!IS_PLAYER(caller)) { print_to(caller, "You must be playing to spawn a monster"); return; }
-                                       if (MUTATOR_CALLHOOK(AllowMobSpawning)) { print_to(caller, ret_string); return; }
+                                       if (MUTATOR_CALLHOOK(AllowMobSpawning, caller)) { print_to(caller, M_ARGV(1, string)); return; }
                                        if (caller.vehicle) { print_to(caller, "You can't spawn monsters while driving a vehicle"); return; }
-                                       if (caller.frozen) { print_to(caller, "You can't spawn monsters while frozen"); return; }
-                                       if (caller.deadflag != DEAD_NO) { print_to(caller, "You can't spawn monsters while dead"); return; }
+                                       if (STAT(FROZEN, caller)) { print_to(caller, "You can't spawn monsters while frozen"); return; }
+                                       if (IS_DEAD(caller)) { print_to(caller, "You can't spawn monsters while dead"); return; }
                                        if (tmp_moncount >= autocvar_g_monsters_max) { print_to(caller, "The maximum monster count has been reached"); return; }
                                        if (tmp_moncount >= autocvar_g_monsters_max_perplayer) { print_to(caller, "You can't spawn any more monsters"); return; }
 
                                        bool found = false;
-                                       for (int i = MON_FIRST; i <= MON_LAST; ++i)
+                                       FOREACH(Monsters, it != MON_Null && it.netname == arg_lower,
                                        {
-                                               mon = get_monsterinfo(i);
-                                               if (mon.netname == arg_lower) { found = true; break; }
-                                       }
+                                               found = true;
+                                               break;
+                                       });
 
-                                       if (!found && arg_lower != "random") { print_to(caller, "Invalid monster"); return; }
+                                       if (!found && arg_lower != "random" && arg_lower != "anyrandom") { print_to(caller, "Invalid monster"); return; }
 
                                        totalspawned += 1;
                                        WarpZone_TraceBox(CENTER_OR_VIEWOFS(caller), caller.mins, caller.maxs, CENTER_OR_VIEWOFS(caller) + v_forward * 150, true, caller);
-                                       mon = spawnmonster(arg_lower, 0, caller, caller, trace_endpos, false, false, moveflag);
+                                       mon = spawnmonster(spawn(), arg_lower, 0, caller, caller, trace_endpos, false, false, moveflag);
                                        print_to(caller, strcat("Spawned ", mon.monster_name));
                                        return;
                                }
@@ -403,7 +405,7 @@ void CommonCommand_editmob(int request, entity caller, int argc)
                                        if (mon.realowner != caller && autocvar_g_monsters_edit < 2) { print_to(caller, "This monster does not belong to you"); return; }
                                        if (!is_visible) { print_to(caller, "You must look at your monster to edit it"); return; }
 
-                                       Damage(mon, world, world, mon.health + mon.max_health + 200, DEATH_KILL.m_id, mon.origin, '0 0 0');
+                                       Damage(mon, NULL, NULL, GetResource(mon, RES_HEALTH) + mon.max_health + 200, DEATH_KILL.m_id, DMG_NOWEP, mon.origin, '0 0 0');
                                        print_to(caller, strcat("Your pet '", mon.monster_name, "' has been brutally mutilated"));
                                        return;
                                }
@@ -435,16 +437,16 @@ void CommonCommand_editmob(int request, entity caller, int argc)
                                case "butcher":
                                {
                                        if (caller) { print_to(caller, "This command is not available to players"); return; }
-                                       if (MUTATOR_CALLHOOK(AllowMobButcher)) { LOG_INFO(ret_string, "\n"); return; }
+                                       if (MUTATOR_CALLHOOK(AllowMobButcher)) { LOG_INFO(M_ARGV(0, string)); return; }
 
                                        int tmp_remcount = 0;
-                                       entity tmp_entity;
 
-                                       FOR_EACH_MONSTER(tmp_entity)
+                                       IL_EACH(g_monsters, true,
                                        {
-                                               Monster_Remove(tmp_entity);
+                                               Monster_Remove(it);
                                                ++tmp_remcount;
-                                       }
+                                       });
+                                       IL_CLEAR(g_monsters);
 
                                        monsters_total = monsters_killed = totalspawned = 0;
 
@@ -467,7 +469,7 @@ void CommonCommand_editmob(int request, entity caller, int argc)
        }
 }
 
-void CommonCommand_info(float request, entity caller, float argc)
+void CommonCommand_info(int request, entity caller, int argc)
 {
        switch (request)
        {
@@ -475,7 +477,7 @@ void CommonCommand_info(float request, entity caller, float argc)
                {
                        string command = builtin_cvar_string(strcat("sv_info_", argv(1)));
 
-                       if (command) wordwrap_sprint(command, 1000);
+                       if (command) wordwrap_sprint(caller, command, 1000);
                        else print_to(caller, "ERROR: unsupported info command");
 
                        return;  // never fall through to usage
@@ -491,7 +493,7 @@ void CommonCommand_info(float request, entity caller, float argc)
        }
 }
 
-void CommonCommand_ladder(float request, entity caller)
+void CommonCommand_ladder(int request, entity caller)
 {
        switch (request)
        {
@@ -511,7 +513,7 @@ void CommonCommand_ladder(float request, entity caller)
        }
 }
 
-void CommonCommand_lsmaps(float request, entity caller)
+void CommonCommand_lsmaps(int request, entity caller)
 {
        switch (request)
        {
@@ -531,7 +533,7 @@ void CommonCommand_lsmaps(float request, entity caller)
        }
 }
 
-void CommonCommand_printmaplist(float request, entity caller)
+void CommonCommand_printmaplist(int request, entity caller)
 {
        switch (request)
        {
@@ -551,7 +553,7 @@ void CommonCommand_printmaplist(float request, entity caller)
        }
 }
 
-void CommonCommand_rankings(float request, entity caller)
+void CommonCommand_rankings(int request, entity caller)
 {
        switch (request)
        {
@@ -571,14 +573,20 @@ void CommonCommand_rankings(float request, entity caller)
        }
 }
 
-void CommonCommand_records(float request, entity caller)
+void CommonCommand_records(int request, entity caller)
 {
        switch (request)
        {
                case CMD_REQUEST_COMMAND:
                {
-                       for (int i = 0; i < 10; ++i)
-                               if (records_reply[i] != "") print_to(caller, records_reply[i]);
+                       int num = stoi(argv(1));
+                       if(num > 0 && num <= 10 && records_reply[num - 1] != "")
+                               print_to(caller, records_reply[num - 1]);
+                       else
+                       {
+                               for (int i = 0; i < 10; ++i)
+                                       if (records_reply[i] != "") print_to(caller, records_reply[i]);
+                       }
 
                        return;  // never fall through to usage
                }
@@ -593,7 +601,7 @@ void CommonCommand_records(float request, entity caller)
        }
 }
 
-void CommonCommand_teamstatus(float request, entity caller)
+void CommonCommand_teamstatus(int request, entity caller)
 {
        switch (request)
        {
@@ -613,7 +621,7 @@ void CommonCommand_teamstatus(float request, entity caller)
        }
 }
 
-void CommonCommand_time(float request, entity caller)
+void CommonCommand_time(int request, entity caller)
 {
        switch (request)
        {
@@ -624,8 +632,8 @@ void CommonCommand_time(float request, entity caller)
                        print_to(caller, strcat("realtime = ", ftos(gettime(GETTIME_REALTIME))));
                        print_to(caller, strcat("hires = ", ftos(gettime(GETTIME_HIRES))));
                        print_to(caller, strcat("uptime = ", ftos(gettime(GETTIME_UPTIME))));
-                       print_to(caller, strcat("localtime = ", strftime(true, "%a %b %e %H:%M:%S %Z %Y")));
-                       print_to(caller, strcat("gmtime = ", strftime(false, "%a %b %e %H:%M:%S %Z %Y")));
+                       print_to(caller, strcat("localtime = ", strftime(true, "%a %b %d %H:%M:%S %Z %Y")));
+                       print_to(caller, strcat("gmtime = ", strftime(false, "%a %b %d %H:%M:%S %Z %Y")));
                        return;
                }
 
@@ -639,7 +647,7 @@ void CommonCommand_time(float request, entity caller)
        }
 }
 
-void CommonCommand_timein(float request, entity caller)
+void CommonCommand_timein(int request, entity caller)
 {
        switch (request)
        {
@@ -694,7 +702,7 @@ void CommonCommand_timein(float request, entity caller)
        }
 }
 
-void CommonCommand_timeout(float request, entity caller)  // DEAR GOD THIS COMMAND IS TERRIBLE.
+void CommonCommand_timeout(int request, entity caller)  // DEAR GOD THIS COMMAND IS TERRIBLE.
 {
        switch (request)
        {
@@ -717,7 +725,7 @@ void CommonCommand_timeout(float request, entity caller)  // DEAR GOD THIS COMMA
                                {
                                        print_to(caller, "^7Error: You can not call a timeout while the map is being restarted.");
                                }
-                               else if (caller && (caller.allowed_timeouts < 1))
+                               else if (caller && (CS(caller).allowed_timeouts < 1))
                                {
                                        print_to(caller, "^7Error: You already used all your timeout calls for this map.");
                                }
@@ -732,9 +740,9 @@ void CommonCommand_timeout(float request, entity caller)  // DEAR GOD THIS COMMA
 
                                else  // everything should be okay, proceed with starting the timeout
                                {
-                                       if (caller)   caller.allowed_timeouts -= 1;
+                                       if (caller)   CS(caller).allowed_timeouts -= 1;
                                        // 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)") : ""), "!\n");
+                                       bprint(GetCallerName(caller), " ^7called a timeout", (caller ? strcat(" (", ftos(CS(caller).allowed_timeouts), " timeout(s) left)") : ""), "!\n");
 
                                        timeout_status = TIMEOUT_LEADTIME;
                                        timeout_caller = caller;
@@ -742,10 +750,10 @@ void CommonCommand_timeout(float request, entity caller)  // DEAR GOD THIS COMMA
                                        timeout_leadtime = autocvar_sv_timeout_leadtime;
 
                                        timeout_handler = spawn();
-                                       timeout_handler.think = timeout_handler_think;
+                                       setthink(timeout_handler, timeout_handler_think);
                                        timeout_handler.nextthink = time;  // always let the entity think asap
 
-                                       Send_Notification(NOTIF_ALL, world, MSG_ANNCE, ANNCE_TIMEOUT);
+                                       Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_TIMEOUT);
                                }
                        }
                        else { print_to(caller, "^1Timeouts are not allowed to be called, enable them with sv_timeout 1.\n"); }
@@ -763,7 +771,7 @@ void CommonCommand_timeout(float request, entity caller)  // DEAR GOD THIS COMMA
        }
 }
 
-void CommonCommand_who(float request, entity caller, float argc)
+void CommonCommand_who(int request, entity caller, int argc)
 {
        switch (request)
        {
@@ -780,7 +788,7 @@ void CommonCommand_who(float request, entity caller, float argc)
                                "ent", "nickname", "ping", "pl", "time", "ip", "crypto_id"));
 
                        total_listed_players = 0;
-                       FOREACH_CLIENT(true, LAMBDA(
+                       FOREACH_CLIENT(true, {
                                is_bot = (IS_BOT_CLIENT(it));
 
                                if (is_bot)
@@ -802,14 +810,14 @@ void CommonCommand_who(float request, entity caller, float argc)
                                print_to(caller, sprintf(strreplace(" ", separator, " #%-3d %-20.20s %-5d %-3d %-9s %-16s %s "),
                                        etof(it),
                                        it.netname,
-                                       it.ping,
-                                       it.ping_packetloss,
-                                       process_time(1, time - it.jointime),
+                                       CS(it).ping,
+                                       CS(it).ping_packetloss,
+                                       process_time(1, time - CS(it).jointime),
                                        tmp_netaddress,
                                        tmp_crypto_idfp));
 
                                ++total_listed_players;
-                       ));
+                       });
 
                        print_to(caller, strcat("Finished listing ", ftos(total_listed_players), " client(s) out of ", ftos(maxclients), " slots."));
 
@@ -828,7 +836,7 @@ void CommonCommand_who(float request, entity caller, float argc)
 
 /* use this when creating a new command, making sure to place it in alphabetical order... also,
 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
-void CommonCommand_(float request, entity caller)
+void CommonCommand_(int request, entity caller)
 {
     switch(request)
     {