X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fcommand%2Fsv_cmd.qc;h=02e984e3c587e5eec84957cf6c628014c64e110c;hb=7050db474245f86c29cb04ae8efbcec8abdc2b6c;hp=c65bd8fa94ab39157fff94068d39c77b4a57a79d;hpb=733758fd5a2cdbb707b19bd9766524855f457656;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/command/sv_cmd.qc b/qcsrc/server/command/sv_cmd.qc index c65bd8fa9..145e75952 100644 --- a/qcsrc/server/command/sv_cmd.qc +++ b/qcsrc/server/command/sv_cmd.qc @@ -1,5 +1,5 @@ -#include "../../common/command/command.qh" #include "sv_cmd.qh" +#include "_mod.qh" #include "banning.qh" #include "cmd.qh" @@ -9,49 +9,46 @@ #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/mapinfo.qh" -#include "../../common/notifications.qh" -#include "../../common/teams.qh" -#include "../../common/util.qh" +#include +#include +#include +#include +#include +#include -#include "../../common/monsters/sv_monsters.qh" +#include -void PutObserverInServer(void); +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() +void make_mapinfo_Think(entity this) { - SELFPARAM(); - 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 { - self.think = make_mapinfo_Think; - self.nextthink = time; + setthink(this, make_mapinfo_Think); + this.nextthink = time; } } @@ -137,12 +134,12 @@ void GameCommand_adminmsg(float request, float argc) } else { - centerprint(client, strcat("^3", admin_name(), ":\n^7", admin_message)); - sprint(client, strcat("\{1}\{13}^3", admin_name(), "^7: ", admin_message, "\n")); + centerprint(client, strcat("^3", GetCallerName(NULL), ":\n^7", admin_message)); + sprint(client, strcat("\{1}\{13}^3", GetCallerName(NULL), "^7: ", admin_message, "\n")); } - successful = strcat(successful, (successful ? ", " : ""), client.netname); - LOG_TRACE("Message sent to ", client.netname, "\n"); + successful = strcat(successful, (successful ? ", " : ""), playername(client, false)); + LOG_TRACE("Message sent to ", playername(client, false)); continue; } @@ -190,22 +187,18 @@ void GameCommand_allready(float request) void GameCommand_allspec(float request, float argc) { - SELFPARAM(); switch (request) { case CMD_REQUEST_COMMAND: { - entity client; string reason = argv(1); - float i = 0; - - FOR_EACH_REALPLAYER(client) - { - if (client.caplayer) client.caplayer = 0; - WITH(entity, self, client, PutObserverInServer()); - ++i; - } - if (i) bprint(strcat("Successfully forced all (", ftos(i), ") players to spectate", (reason ? strcat(" for reason: '", reason, "'") : ""), ".\n")); + int n = 0; + FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA( + if (it.caplayer) it.caplayer = 0; + PutObserverInServer(it); + ++n; + )); + if (n) bprint(strcat("Successfully forced all (", ftos(n), ") players to spectate", (reason ? strcat(" for reason: '", reason, "'") : ""), ".\n")); else LOG_INFO("No players found to spectate.\n"); return; } @@ -223,7 +216,6 @@ void GameCommand_allspec(float request, float argc) void GameCommand_anticheat(float request, float argc) { - SELFPARAM(); switch (request) { case CMD_REQUEST_COMMAND: @@ -233,7 +225,7 @@ void GameCommand_anticheat(float request, float argc) if (accepted > 0) { - WITH(entity, self, client, anticheat_report()); + anticheat_report_to_eventlog(client); return; } else @@ -259,67 +251,59 @@ void GameCommand_bbox(float request) { case CMD_REQUEST_COMMAND: { - LOG_INFO("Original size: ", ftos(world.absmin.x), " ", ftos(world.absmin.y), " ", ftos(world.absmin.z)); - LOG_INFO(" ", ftos(world.absmax.x), " ", ftos(world.absmax.y), " ", ftos(world.absmax.z), "\n"); - LOG_INFO("Currently set size: ", ftos(world.mins.x), " ", ftos(world.mins.y), " ", ftos(world.mins.z)); - LOG_INFO(" ", ftos(world.maxs.x), " ", ftos(world.maxs.y), " ", ftos(world.maxs.z), "\n"); - LOG_INFO("Solid bounding box size:"); - + vector size_min = '0 0 0'; + vector size_max = '0 0 0'; tracebox('1 0 0' * world.absmin.x, '0 1 0' * world.absmin.y + '0 0 1' * world.absmin.z, '0 1 0' * world.absmax.y + '0 0 1' * world.absmax.z, '1 0 0' * world.absmax.x, MOVE_WORLDONLY, - world); - if (trace_startsolid) LOG_INFO(" ", ftos(world.absmin.x)); - else LOG_INFO(" ", ftos(trace_endpos.x)); + NULL); + size_min.x = (trace_startsolid) ? world.absmin.x : trace_endpos.x; tracebox('0 1 0' * world.absmin.y, '1 0 0' * world.absmin.x + '0 0 1' * world.absmin.z, '1 0 0' * world.absmax.x + '0 0 1' * world.absmax.z, '0 1 0' * world.absmax.y, MOVE_WORLDONLY, - world); - if (trace_startsolid) LOG_INFO(" ", ftos(world.absmin.y)); - else LOG_INFO(" ", ftos(trace_endpos.y)); + NULL); + size_min.y = (trace_startsolid) ? world.absmin.y : trace_endpos.y; tracebox('0 0 1' * world.absmin.z, '1 0 0' * world.absmin.x + '0 1 0' * world.absmin.y, '1 0 0' * world.absmax.x + '0 1 0' * world.absmax.y, '0 0 1' * world.absmax.z, MOVE_WORLDONLY, - world); - if (trace_startsolid) LOG_INFO(" ", ftos(world.absmin.z)); - else LOG_INFO(" ", ftos(trace_endpos.z)); + NULL); + size_min.z = (trace_startsolid) ? world.absmin.z : trace_endpos.z; tracebox('1 0 0' * world.absmax.x, '0 1 0' * world.absmin.y + '0 0 1' * world.absmin.z, '0 1 0' * world.absmax.y + '0 0 1' * world.absmax.z, '1 0 0' * world.absmin.x, MOVE_WORLDONLY, - world); - if (trace_startsolid) LOG_INFO(" ", ftos(world.absmax.x)); - else LOG_INFO(" ", ftos(trace_endpos.x)); + NULL); + size_max.x = (trace_startsolid) ? world.absmax.x : trace_endpos.x; tracebox('0 1 0' * world.absmax.y, '1 0 0' * world.absmin.x + '0 0 1' * world.absmin.z, '1 0 0' * world.absmax.x + '0 0 1' * world.absmax.z, '0 1 0' * world.absmin.y, MOVE_WORLDONLY, - world); - if (trace_startsolid) LOG_INFO(" ", ftos(world.absmax.y)); - else LOG_INFO(" ", ftos(trace_endpos.y)); + NULL); + size_max.y = (trace_startsolid) ? world.absmax.y : trace_endpos.y; tracebox('0 0 1' * world.absmax.z, '1 0 0' * world.absmin.x + '0 1 0' * world.absmin.y, '1 0 0' * world.absmax.x + '0 1 0' * world.absmax.y, '0 0 1' * world.absmin.z, MOVE_WORLDONLY, - world); - if (trace_startsolid) LOG_INFO(" ", ftos(world.absmax.z)); - else LOG_INFO(" ", ftos(trace_endpos.z)); + NULL); + size_max.z = (trace_startsolid) ? world.absmax.z : trace_endpos.z; - LOG_INFO("\n"); + LOG_INFOF("Original size: %v %v\n", world.absmin, world.absmax); + LOG_INFOF("Currently set size: %v %v\n", world.mins, world.maxs); + LOG_INFOF("Solid bounding box size: %v %v\n", size_min, size_max); return; } @@ -390,10 +374,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 @@ -415,17 +405,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 + } } } } @@ -435,10 +439,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; } } @@ -454,7 +460,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; } @@ -528,7 +534,7 @@ void GameCommand_defer_clear(float request, float argc) if (accepted > 0) { stuffcmd(client, "defer clear\n"); - LOG_INFO("defer clear stuffed to ", client.netname, "\n"); + LOG_INFO("defer clear stuffed to ", playername(client, false), "\n"); } else { LOG_INFO("defer_clear: ", GetClientErrorString(accepted, argv(1)), ".\n"); } @@ -554,17 +560,15 @@ void GameCommand_defer_clear_all(float request) { case CMD_REQUEST_COMMAND: { - entity client; - float i = 0; + int n = 0; float argc; - FOR_EACH_CLIENT(client) - { - argc = tokenize_console(strcat("defer_clear ", ftos(num_for_edict(client)))); + FOREACH_CLIENT(true, LAMBDA( + argc = tokenize_console(strcat("defer_clear ", ftos(etof(it)))); GameCommand_defer_clear(CMD_REQUEST_COMMAND, argc); - ++i; - } - if (i) LOG_INFO(strcat("Successfully stuffed defer clear to all clients (", ftos(i), ")\n")); // should a message be added if no players were found? + ++n; + )); + if (n) LOG_INFO(strcat("Successfully stuffed defer clear to all clients (", ftos(n), ")\n")); // should a message be added if no players were found? return; } @@ -741,31 +745,6 @@ void GameCommand_extendmatchtime(float request) } } -void GameCommand_find(float request, float argc) // is this even needed? We have prvm_edicts command and such ANYWAY -{ - switch (request) - { - case CMD_REQUEST_COMMAND: - { - entity client; - - for (client = world; (client = find(client, classname, argv(1))); ) - LOG_INFO(etos(client), "\n"); - - return; - } - - default: - LOG_INFO("Incorrect parameters for ^2find^7\n"); - case CMD_REQUEST_USAGE: - { - LOG_INFO("\nUsage:^3 sv_cmd find classname\n"); - LOG_INFO(" Where 'classname' is the classname to search for.\n"); - return; - } - } -} - void GameCommand_gametype(float request, float argc) { switch (request) @@ -775,7 +754,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) { @@ -831,8 +810,8 @@ void GameCommand_gettaginfo(float request, float argc) tmp_entity = spawn(); if (argv(1) == "w") { - int slot = 0; - _setmodel(tmp_entity, (nextent(world)).weaponentity[slot].model); + .entity weaponentity = weaponentities[0]; + _setmodel(tmp_entity, (nextent(NULL)).(weaponentity).model); } else { @@ -863,7 +842,7 @@ void GameCommand_gettaginfo(float request, float argc) LOG_INFO("bone not found\n"); } - remove(tmp_entity); + delete(tmp_entity); return; } } @@ -892,8 +871,8 @@ void GameCommand_animbench(float request, float argc) tmp_entity = spawn(); if (argv(1) == "w") { - int slot = 0; - _setmodel(tmp_entity, (nextent(world)).weaponentity[slot].model); + .entity weaponentity = weaponentities[0]; + _setmodel(tmp_entity, (nextent(NULL)).(weaponentity).model); } else { @@ -922,7 +901,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; } } @@ -1000,9 +979,8 @@ void GameCommand_make_mapinfo(float request) { entity tmp_entity; - tmp_entity = spawn(); - tmp_entity.classname = "make_mapinfo"; - tmp_entity.think = make_mapinfo_Think; + tmp_entity = new(make_mapinfo); + setthink(tmp_entity, make_mapinfo_Think); tmp_entity.nextthink = time; MapInfo_Enumerate(); return; @@ -1021,7 +999,6 @@ void GameCommand_make_mapinfo(float request) void GameCommand_moveplayer(float request, float argc) { - SELFPARAM(); switch (request) { case CMD_REQUEST_COMMAND: @@ -1060,13 +1037,13 @@ void GameCommand_moveplayer(float request, float argc) if (!IS_SPEC(client) && !IS_OBSERVER(client)) { if (client.caplayer) client.caplayer = 0; - WITH(entity, self, client, PutObserverInServer()); + PutObserverInServer(client); - successful = strcat(successful, (successful ? ", " : ""), client.netname); + successful = strcat(successful, (successful ? ", " : ""), playername(client, false)); } else { - LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", client.netname, ") is already spectating.\n"); + LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", playername(client, false), ") is already spectating.\n"); } continue; } @@ -1086,7 +1063,7 @@ void GameCommand_moveplayer(float request, float argc) if (team_id == client.team) // already on the destination team { // keep the forcing undone - LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", client.netname, ") is already on the ", Team_ColoredFullName(client.team), (targets ? "^7, skipping to next player.\n" : "^7.\n")); + LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", playername(client, false), ") is already on the ", Team_ColoredFullName(client.team), (targets ? "^7, skipping to next player.\n" : "^7.\n")); continue; } else if (team_id == 0) // auto team @@ -1115,8 +1092,8 @@ void GameCommand_moveplayer(float request, float argc) // If so, lets continue and finally move the player client.team_forced = 0; MoveToTeam(client, team_id, 6); - successful = strcat(successful, (successful ? ", " : ""), client.netname); - LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", client.netname, ") has been moved to the ", Team_ColoredFullName(team_id), "^7.\n"); + successful = strcat(successful, (successful ? ", " : ""), playername(client, false)); + LOG_INFO("Player ", ftos(GetFilteredNumber(t)), " (", playername(client, false), ") has been moved to the ", Team_ColoredFullName(team_id), "^7.\n"); continue; } else @@ -1163,18 +1140,14 @@ void GameCommand_nospectators(float request) case CMD_REQUEST_COMMAND: { blockSpectators = 1; - entity plr; - FOR_EACH_REALCLIENT(plr) // give every spectator seconds time to become a player - { - if (IS_SPEC(plr) || IS_OBSERVER(plr)) + // give every spectator seconds time to become a player + FOREACH_CLIENT(IS_REAL_CLIENT(it) && (IS_SPEC(it) || IS_OBSERVER(it)) && !it.caplayer, LAMBDA( + if(!it.caplayer) { - if (!plr.caplayer) - { - plr.spectatortime = time; - Send_Notification(NOTIF_ONE_ONLY, plr, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime); - } + it.spectatortime = time; + Send_Notification(NOTIF_ONE_ONLY, it, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime); } - } + )); bprint(strcat("^7All spectators will be automatically kicked when not joining the game after ", ftos(autocvar_g_maxplayers_spectator_blocktime), " seconds!\n")); return; } @@ -1191,7 +1164,6 @@ void GameCommand_nospectators(float request) void GameCommand_playerdemo(float request, float argc) { - SELFPARAM(); switch (request) { case CMD_REQUEST_COMMAND: @@ -1214,7 +1186,7 @@ void GameCommand_playerdemo(float request, float argc) return; } - WITH(entity, self, client, playerdemo_open_read(argv(next_token))); + playerdemo_open_read(client, argv(next_token)); return; } @@ -1229,7 +1201,7 @@ void GameCommand_playerdemo(float request, float argc) return; } - WITH(entity, self, client, playerdemo_open_write(argv(next_token))); + playerdemo_open_write(client, argv(next_token)); return; } @@ -1363,97 +1335,41 @@ void GameCommand_setbots(float request, float argc) void GameCommand_shuffleteams(float request) { - SELFPARAM(); switch (request) { case CMD_REQUEST_COMMAND: { - if (teamplay) - { - entity tmp_player; - int i; - 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; - FOR_EACH_CLIENT(tmp_player) - if (IS_PLAYER(tmp_player) || tmp_player.caplayer) - { - CheckAllowedTeams(tmp_player); - - 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 - FOR_EACH_CLIENT(tmp_player) - if (IS_PLAYER(tmp_player) || tmp_player.caplayer) - { - for ( ; ; ) - { - i = bound(1, floor(random() * maxclients) + 1, maxclients); - - if (shuffleteams_players[i]) - { - continue; // a player is already assigned to this slot - } - else - { - shuffleteams_players[i] = num_for_edict(tmp_player); - 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 - - if (VerifyClientNumber(shuffleteams_players[z])) setself(edict_num(shuffleteams_players[z])); - - if (self.team != team_color) MoveToTeam(self, team_color, 6); - - shuffleteams_players[z] = 0; - shuffleteams_teams[i] = shuffleteams_teams[i] + 1; - } - else - { - break; // move on to next team - } - } - } - - bprint("Successfully shuffled the players around randomly.\n"); - - // clear the buffers now - for (i = 0; i < SHUFFLETEAMS_MAX_PLAYERS; ++i) - shuffleteams_players[i] = 0; - - for (i = 0; i < SHUFFLETEAMS_MAX_TEAMS; ++i) - shuffleteams_teams[i] = 0; - } - else + if (!teamplay) { LOG_INFO("Can't shuffle teams when currently not playing a team game.\n"); + return; } + 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; + } + )); + + 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; } @@ -1475,7 +1391,6 @@ void GameCommand_stuffto(float request, float argc) // we can be certain they understand the risks of it... So to enable, compile server with -DSTUFFTO_ENABLED argument. #ifdef STUFFTO_ENABLED - #message "stuffto command enabled" switch (request) { case CMD_REQUEST_COMMAND: @@ -1551,15 +1466,15 @@ void GameCommand_trace(float request, float argc) start = stov(vtos(start)); end = stov(vtos(end)); - tracebox(start, PL_MIN, PL_MAX, 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, PL_MIN, PL_MAX, 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, PL_MIN, PL_MAX, 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; @@ -1567,7 +1482,7 @@ void GameCommand_trace(float request, float argc) for ( ; ; ) { pos = p * (1 - (safe + unsafe) * 0.5) + start * ((safe + unsafe) * 0.5); - tracebox(pos, PL_MIN, PL_MAX, 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; @@ -1583,7 +1498,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, PL_MIN + '0.1 0.1 0.1', PL_MAX - '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; @@ -1597,7 +1512,7 @@ void GameCommand_trace(float request, float argc) { q = p + normalize(end - p) * (dq + dqf); if (q == q0) break; - tracebox(p, PL_MIN, PL_MAX, 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; @@ -1618,7 +1533,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) @@ -1651,7 +1566,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; @@ -1664,9 +1579,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; } } @@ -1727,7 +1642,7 @@ void GameCommand_warp(float request, float argc) if (argc >= 2) { CampaignLevelWarp(stof(argv(1))); - LOG_INFO("Successfully warped to campaign level ", stof(argv(1)), ".\n"); + LOG_INFO("Successfully warped to campaign level ", argv(1), ".\n"); } else { @@ -1782,79 +1697,66 @@ void GameCommand_(float request) // ================================== // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;) -#define SERVER_COMMANDS(request, arguments, command) \ - SERVER_COMMAND("adminmsg", GameCommand_adminmsg(request, arguments), "Send an admin message to a client directly") \ - SERVER_COMMAND("allready", GameCommand_allready(request), "Restart the server and reset the players") \ - SERVER_COMMAND("allspec", GameCommand_allspec(request, arguments), "Force all players to spectate") \ - SERVER_COMMAND("anticheat", GameCommand_anticheat(request, arguments), "Create an anticheat report for a client") \ - SERVER_COMMAND("animbench", GameCommand_animbench(request, arguments), "Benchmark model animation (LAGS)") \ - SERVER_COMMAND("bbox", GameCommand_bbox(request), "Print detailed information about world size") \ - SERVER_COMMAND("bot_cmd", GameCommand_bot_cmd(request, arguments, command), "Control and send commands to bots") \ - SERVER_COMMAND("cointoss", GameCommand_cointoss(request, arguments), "Flip a virtual coin and give random result") \ - SERVER_COMMAND("database", GameCommand_database(request, arguments), "Extra controls of the serverprogs database") \ - SERVER_COMMAND("defer_clear", GameCommand_defer_clear(request, arguments), "Clear all queued defer commands for a specific client") \ - SERVER_COMMAND("defer_clear_all", GameCommand_defer_clear_all(request), "Clear all queued defer commands for all clients") \ - SERVER_COMMAND("delrec", GameCommand_delrec(request, arguments), "Delete race time record for a map") \ - SERVER_COMMAND("effectindexdump", GameCommand_effectindexdump(request), "Dump list of effects from code and effectinfo.txt") \ - SERVER_COMMAND("extendmatchtime", GameCommand_extendmatchtime(request), "Increase the timelimit value incrementally") \ - SERVER_COMMAND("find", GameCommand_find(request, arguments), "Search through entities for matching classname") \ - SERVER_COMMAND("gametype", GameCommand_gametype(request, arguments), "Simple command to change the active gametype") \ - SERVER_COMMAND("gettaginfo", GameCommand_gettaginfo(request, arguments), "Get specific information about a weapon model") \ - SERVER_COMMAND("gotomap", GameCommand_gotomap(request, arguments), "Simple command to switch to another map") \ - SERVER_COMMAND("lockteams", GameCommand_lockteams(request), "Disable the ability for players to switch or enter teams") \ - SERVER_COMMAND("make_mapinfo", GameCommand_make_mapinfo(request), "Automatically rebuild mapinfo files") \ - SERVER_COMMAND("moveplayer", GameCommand_moveplayer(request, arguments), "Change the team/status of a player") \ - SERVER_COMMAND("nospectators", GameCommand_nospectators(request), "Automatically remove spectators from a match") \ - SERVER_COMMAND("playerdemo", GameCommand_playerdemo(request, arguments), "Control the ability to save demos of players") \ - SERVER_COMMAND("printstats", GameCommand_printstats(request), "Dump eventlog player stats and other score information") \ - SERVER_COMMAND("radarmap", GameCommand_radarmap(request, arguments), "Generate a radar image of the map") \ - SERVER_COMMAND("reducematchtime", GameCommand_reducematchtime(request), "Decrease the timelimit value incrementally") \ - SERVER_COMMAND("setbots", GameCommand_setbots(request, arguments), "Adjust how many bots are in the match") \ - SERVER_COMMAND("shuffleteams", GameCommand_shuffleteams(request), "Randomly move players to different teams") \ - SERVER_COMMAND("stuffto", GameCommand_stuffto(request, arguments), "Send a command to be executed on a client") \ - SERVER_COMMAND("trace", GameCommand_trace(request, arguments), "Various debugging tools with tracing") \ - SERVER_COMMAND("unlockteams", GameCommand_unlockteams(request), "Enable the ability for players to switch or enter teams") \ - SERVER_COMMAND("warp", GameCommand_warp(request, arguments), "Choose different level in campaign") \ - /* nothing */ +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(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); } +SERVER_COMMAND(bbox, "Print detailed information about world size") { GameCommand_bbox(request); } +SERVER_COMMAND(bot_cmd, "Control and send commands to bots") { GameCommand_bot_cmd(request, arguments, command); } +SERVER_COMMAND(cointoss, "Flip a virtual coin and give random result") { GameCommand_cointoss(request, arguments); } +SERVER_COMMAND(database, "Extra controls of the serverprogs database") { GameCommand_database(request, arguments); } +SERVER_COMMAND(defer_clear, "Clear all queued defer commands for a specific client") { GameCommand_defer_clear(request, arguments); } +SERVER_COMMAND(defer_clear_all, "Clear all queued defer commands for all clients") { GameCommand_defer_clear_all(request); } +SERVER_COMMAND(delrec, "Delete race time record for a map") { GameCommand_delrec(request, arguments); } +SERVER_COMMAND(effectindexdump, "Dump list of effects from code and effectinfo.txt") { GameCommand_effectindexdump(request); } +SERVER_COMMAND(extendmatchtime, "Increase the timelimit value incrementally") { GameCommand_extendmatchtime(request); } +SERVER_COMMAND(gametype, "Simple command to change the active gametype") { GameCommand_gametype(request, arguments); } +SERVER_COMMAND(gettaginfo, "Get specific information about a weapon model") { GameCommand_gettaginfo(request, arguments); } +SERVER_COMMAND(gotomap, "Simple command to switch to another map") { GameCommand_gotomap(request, arguments); } +SERVER_COMMAND(lockteams, "Disable the ability for players to switch or enter teams") { GameCommand_lockteams(request); } +SERVER_COMMAND(make_mapinfo, "Automatically rebuild mapinfo files") { GameCommand_make_mapinfo(request); } +SERVER_COMMAND(moveplayer, "Change the team/status of a player") { GameCommand_moveplayer(request, arguments); } +SERVER_COMMAND(nospectators, "Automatically remove spectators from a match") { GameCommand_nospectators(request); } +SERVER_COMMAND(playerdemo, "Control the ability to save demos of players") { GameCommand_playerdemo(request, arguments); } +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(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); } +SERVER_COMMAND(trace, "Various debugging tools with tracing") { GameCommand_trace(request, arguments); } +SERVER_COMMAND(unlockteams, "Enable the ability for players to switch or enter teams") { GameCommand_unlockteams(request); } +SERVER_COMMAND(warp, "Choose different level in campaign") { GameCommand_warp(request, arguments); } void GameCommand_macro_help() { - #define SERVER_COMMAND(name, function, description) \ - { LOG_INFO(" ^2", name, "^7: ", description, "\n"); } - - SERVER_COMMANDS(0, 0, ""); -#undef SERVER_COMMAND + FOREACH(SERVER_COMMANDS, true, LAMBDA(LOG_INFOF(" ^2%s^7: %s\n", it.m_name, it.m_description))); } float GameCommand_macro_command(float argc, string command) { - #define SERVER_COMMAND(name, function, description) \ - { if (name == strtolower(argv(0))) { function; return true; } } - - SERVER_COMMANDS(CMD_REQUEST_COMMAND, argc, command); -#undef SERVER_COMMAND - + string c = strtolower(argv(0)); + FOREACH(SERVER_COMMANDS, it.m_name == c, LAMBDA( + it.m_invokecmd(it, CMD_REQUEST_COMMAND, NULL, argc, command); + return true; + )); return false; } float GameCommand_macro_usage(float argc) { - #define SERVER_COMMAND(name, function, description) \ - { if (name == strtolower(argv(1))) { function; return true; } } - - SERVER_COMMANDS(CMD_REQUEST_USAGE, argc, ""); -#undef SERVER_COMMAND - + string c = strtolower(argv(1)); + FOREACH(SERVER_COMMANDS, it.m_name == c, LAMBDA( + it.m_invokecmd(it, CMD_REQUEST_USAGE, NULL, argc, ""); + return true; + )); return false; } void GameCommand_macro_write_aliases(float fh) { - #define SERVER_COMMAND(name, function, description) \ - { CMD_Write_Alias("qc_cmd_sv", name, description); } - - SERVER_COMMANDS(0, 0, ""); -#undef SERVER_COMMAND + FOREACH(SERVER_COMMANDS, true, LAMBDA(CMD_Write_Alias("qc_cmd_sv", it.m_name, it.m_description))); } @@ -1883,7 +1785,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(); @@ -1897,7 +1799,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; } @@ -1918,7 +1820,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 }