X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fcommand%2Fcommon.qc;h=357a33eba2d5d1cb398a138883ccd83b606fcca5;hb=06ac66a5edaa645e19ed9a6482409e8656a65b1d;hp=484ecb2104d208ac969ba5c50825eeb1e186d1c3;hpb=f1a87492d9fed27a64d0e99c068705aba5509f26;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/command/common.qc b/qcsrc/server/command/common.qc index 484ecb210..357a33eba 100644 --- a/qcsrc/server/command/common.qc +++ b/qcsrc/server/command/common.qc @@ -1,11 +1,12 @@ -#include "../../common/command/command.qh" +#include "common.qh" +#include #include "common.qh" #include "../scores.qh" -#include "../../common/monsters/all.qh" -#include "../../common/notifications.qh" -#include "../../lib/warpzone/common.qh" +#include +#include +#include // ==================================================== @@ -73,13 +74,13 @@ float VerifyClientNumber(float tmp_number) entity GetIndexedEntity(float argc, float start_index) { - entity tmp_player, selection; + entity selection; float tmp_number, index; string tmp_string; next_token = -1; index = start_index; - selection = world; + selection = NULL; if (argc > start_index) { @@ -114,8 +115,13 @@ entity GetIndexedEntity(float argc, float start_index) } else // no, maybe it's a name? { - FOR_EACH_CLIENT(tmp_player) - if (strdecolorize(tmp_player.netname) == strdecolorize(argv(start_index))) selection = tmp_player; + FOREACH_CLIENT(true, LAMBDA( + if(strdecolorize(it.netname) == strdecolorize(argv(start_index))) + { + selection = it; + break; // no reason to keep looking + } + )); index = (start_index + 1); } @@ -129,7 +135,7 @@ entity GetIndexedEntity(float argc, float start_index) // find a player which matches the input string, and return their entity entity GetFilteredEntity(string input) { - entity tmp_player, selection; + entity selection; float tmp_number; if (substring(input, 0, 1) == "#") tmp_number = stof(substring(input, 1, -1)); @@ -141,9 +147,14 @@ entity GetFilteredEntity(string input) } else { - selection = world; - FOR_EACH_CLIENT(tmp_player) - if (strdecolorize(tmp_player.netname) == strdecolorize(input)) selection = tmp_player; + selection = NULL; + FOREACH_CLIENT(true, LAMBDA( + if(strdecolorize(it.netname) == strdecolorize(input)) + { + selection = it; + break; // no reason to keep looking + } + )); } return selection; @@ -172,33 +183,29 @@ 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(); - entity tmp_player; - 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 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 @@ -209,10 +216,11 @@ void timeout_handler_think() cvar_set("slowmo", ftos(orig_slowmo)); // unlock the view for players so they can move around again - FOR_EACH_REALPLAYER(tmp_player) - tmp_player.fixangle = false; + FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA( + it.fixangle = false; + )); - timeout_handler_reset(); + timeout_handler_reset(this); } return; @@ -222,9 +230,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 @@ -235,16 +243,18 @@ void timeout_handler_think() cvar_set("slowmo", ftos(TIMEOUT_SLOWMO_VALUE)); // reset all the flood variables - FOR_EACH_CLIENT(tmp_player) - tmp_player.nickspamcount = tmp_player.nickspamtime = tmp_player.floodcontrol_chat = - tmp_player.floodcontrol_chatteam = tmp_player.floodcontrol_chattell = - tmp_player.floodcontrol_voice = tmp_player.floodcontrol_voiceteam = 0; + FOREACH_CLIENT(true, LAMBDA( + 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) - FOR_EACH_REALPLAYER(tmp_player) - tmp_player.lastV_angle = tmp_player.v_angle; + FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA( + 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; @@ -254,7 +264,7 @@ void timeout_handler_think() case TIMEOUT_INACTIVE: default: { - timeout_handler_reset(); + timeout_handler_reset(this); return; } } @@ -309,7 +319,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: @@ -319,8 +328,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; @@ -352,22 +361,21 @@ 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; } @@ -392,7 +400,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, mon.health + mon.max_health + 200, DEATH_KILL.m_id, mon.origin, '0 0 0'); print_to(caller, strcat("Your pet '", mon.monster_name, "' has been brutally mutilated")); return; } @@ -424,16 +432,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), "\n"); 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; @@ -464,7 +472,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 @@ -731,10 +739,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"); } @@ -759,7 +767,6 @@ void CommonCommand_who(float request, entity caller, float argc) case CMD_REQUEST_COMMAND: { float total_listed_players, is_bot; - entity tmp_player; float privacy = (caller && autocvar_sv_status_privacy); string separator = strreplace("%", " ", strcat((argv(1) ? argv(1) : " "), "^7")); @@ -770,9 +777,8 @@ void CommonCommand_who(float request, entity caller, float argc) "ent", "nickname", "ping", "pl", "time", "ip", "crypto_id")); total_listed_players = 0; - FOR_EACH_CLIENT(tmp_player) - { - is_bot = (IS_BOT_CLIENT(tmp_player)); + FOREACH_CLIENT(true, LAMBDA( + is_bot = (IS_BOT_CLIENT(it)); if (is_bot) { @@ -786,21 +792,21 @@ void CommonCommand_who(float request, entity caller, float argc) } else { - tmp_netaddress = tmp_player.netaddress; - tmp_crypto_idfp = tmp_player.crypto_idfp; + tmp_netaddress = it.netaddress; + tmp_crypto_idfp = it.crypto_idfp; } print_to(caller, sprintf(strreplace(" ", separator, " #%-3d %-20.20s %-5d %-3d %-9s %-16s %s "), - etof(tmp_player), - tmp_player.netname, - tmp_player.ping, - tmp_player.ping_packetloss, - process_time(1, time - tmp_player.jointime), + etof(it), + it.netname, + it.ping, + it.ping_packetloss, + process_time(1, time - 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."));