]> 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 984505ec1c56d54d880d1c580f0df68fde9b313b..6121867e20fd32f1e05504882ba488cbf357e91d 100644 (file)
@@ -1,4 +1,8 @@
 #include "common.qh"
+
+#include <server/defs.qh>
+#include <server/miscfunctions.qh>
+
 #include <common/command/_mod.qh>
 #include "common.qh"
 
@@ -72,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;
@@ -115,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);
                }
@@ -148,13 +152,13 @@ entity GetFilteredEntity(string input)
        else
        {
                selection = NULL;
-               FOREACH_CLIENT(true, LAMBDA(
+               FOREACH_CLIENT(true, {
                        if(strdecolorize(it.netname) == strdecolorize(input))
                        {
                                selection = it;
                                break; // no reason to keep looking
                        }
-               ));
+               });
        }
 
        return selection;
@@ -175,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");
 }
 
 // ==========================================
@@ -217,9 +221,9 @@ void timeout_handler_think(entity this)
                                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(this);
                        }
@@ -244,16 +248,16 @@ void timeout_handler_think(entity this)
                                cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE));
 
                                // reset all the flood variables
-                               FOREACH_CLIENT(true, LAMBDA(
+                               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;
-                               ));
+                               });
 
                                this.nextthink = time;  // think again next frame to handle it under TIMEOUT_ACTIVE code
                        }
@@ -276,7 +280,7 @@ void timeout_handler_think(entity this)
 //  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)
        {
@@ -387,7 +391,7 @@ void CommonCommand_editmob(int request, entity caller, int argc)
                                                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);
@@ -401,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, NULL, NULL, 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;
                                }
@@ -433,7 +437,7 @@ 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(M_ARGV(0, string), "\n"); return; }
+                                       if (MUTATOR_CALLHOOK(AllowMobButcher)) { LOG_INFO(M_ARGV(0, string)); return; }
 
                                        int tmp_remcount = 0;
 
@@ -465,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)
        {
@@ -489,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)
        {
@@ -509,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)
        {
@@ -529,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)
        {
@@ -549,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)
        {
@@ -569,7 +573,7 @@ void CommonCommand_rankings(float request, entity caller)
        }
 }
 
-void CommonCommand_records(float request, entity caller)
+void CommonCommand_records(int request, entity caller)
 {
        switch (request)
        {
@@ -597,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)
        {
@@ -617,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)
        {
@@ -628,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;
                }
 
@@ -643,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)
        {
@@ -698,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)
        {
@@ -721,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.");
                                }
@@ -736,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;
@@ -767,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)
        {
@@ -784,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)
@@ -808,12 +812,12 @@ void CommonCommand_who(float request, entity caller, float argc)
                                        it.netname,
                                        CS(it).ping,
                                        CS(it).ping_packetloss,
-                                       process_time(1, time - it.jointime),
+                                       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."));
 
@@ -832,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)
     {