X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fcommand%2Fsv_cmd.qc;h=4687403d2a0006124861a204f9e8914bf8081244;hb=db8df15de152221a99a61733cf0e2b89cc6b406e;hp=76e913500db7b53fafe4df3ee69c8f6d35e4c06b;hpb=3ac34e5b003963141cbbde668cf5cda1b2eaacc9;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/command/sv_cmd.qc b/qcsrc/server/command/sv_cmd.qc index 76e913500..4687403d2 100644 --- a/qcsrc/server/command/sv_cmd.qc +++ b/qcsrc/server/command/sv_cmd.qc @@ -34,7 +34,6 @@ void PutObserverInServer(entity this); // ===================================================== // Server side game commands code, reworked by Samual -// Last updated: December 29th, 2011 // ===================================================== // used by GameCommand_make_mapinfo() @@ -135,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); + successful = strcat(successful, (successful ? ", " : ""), playername(client, false)); + LOG_TRACE("Message sent to ", playername(client, false)); continue; } @@ -194,11 +193,11 @@ void GameCommand_allspec(float request, float argc) { string reason = argv(1); int n = 0; - FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA( + FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), { 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; @@ -252,20 +251,15 @@ 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, NULL); - if (trace_startsolid) LOG_INFO(" ", ftos(world.absmin.x)); - else LOG_INFO(" ", ftos(trace_endpos.x)); + 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, @@ -273,8 +267,7 @@ void GameCommand_bbox(float request) '0 1 0' * world.absmax.y, MOVE_WORLDONLY, NULL); - if (trace_startsolid) LOG_INFO(" ", ftos(world.absmin.y)); - else LOG_INFO(" ", ftos(trace_endpos.y)); + 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, @@ -282,8 +275,7 @@ void GameCommand_bbox(float request) '0 0 1' * world.absmax.z, MOVE_WORLDONLY, NULL); - if (trace_startsolid) LOG_INFO(" ", ftos(world.absmin.z)); - else LOG_INFO(" ", ftos(trace_endpos.z)); + 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, @@ -291,8 +283,7 @@ void GameCommand_bbox(float request) '1 0 0' * world.absmin.x, MOVE_WORLDONLY, NULL); - if (trace_startsolid) LOG_INFO(" ", ftos(world.absmax.x)); - else LOG_INFO(" ", ftos(trace_endpos.x)); + 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, @@ -300,8 +291,7 @@ void GameCommand_bbox(float request) '0 1 0' * world.absmin.y, MOVE_WORLDONLY, NULL); - if (trace_startsolid) LOG_INFO(" ", ftos(world.absmax.y)); - else LOG_INFO(" ", ftos(trace_endpos.y)); + 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, @@ -309,10 +299,11 @@ void GameCommand_bbox(float request) '0 0 1' * world.absmin.z, MOVE_WORLDONLY, NULL); - if (trace_startsolid) LOG_INFO(" ", ftos(world.absmax.z)); - else LOG_INFO(" ", ftos(trace_endpos.z)); + 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; } @@ -543,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"); } @@ -572,11 +563,11 @@ void GameCommand_defer_clear_all(float request) int n = 0; float argc; - FOREACH_CLIENT(true, LAMBDA( + FOREACH_CLIENT(true, { argc = tokenize_console(strcat("defer_clear ", ftos(etof(it)))); GameCommand_defer_clear(CMD_REQUEST_COMMAND, argc); ++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; } @@ -1048,11 +1039,11 @@ void GameCommand_moveplayer(float request, float argc) if (client.caplayer) client.caplayer = 0; 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; } @@ -1072,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 @@ -1100,9 +1091,15 @@ 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"); + if (MoveToTeam(client, team_id, 6)) + { + 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"); + } + else + { + LOG_INFO("Unable to move player ", ftos(GetFilteredNumber(t)), " (", playername(client, false), ")"); + } continue; } else @@ -1150,13 +1147,13 @@ void GameCommand_nospectators(float request) { blockSpectators = 1; // give every spectator seconds time to become a player - FOREACH_CLIENT(IS_REAL_CLIENT(it) && (IS_SPEC(it) || IS_OBSERVER(it)) && !it.caplayer, LAMBDA( + FOREACH_CLIENT(IS_REAL_CLIENT(it) && (IS_SPEC(it) || IS_OBSERVER(it)) && !it.caplayer, { if(!it.caplayer) { - it.spectatortime = time; + CS(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; } @@ -1348,90 +1345,37 @@ void GameCommand_shuffleteams(float request) { case CMD_REQUEST_COMMAND: { - if (teamplay) - { - float 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 - int pnum = (t_players / t_teams); - pnum = ((i == 1) ? ceil(pnum) : floor(pnum)); - - 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] >= pnum)) - { - 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); - - 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 (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 + if (!teamplay) { LOG_INFO("Can't shuffle teams when currently not playing a team game.\n"); + return; } + FOREACH_CLIENT(IS_PLAYER(it) || it.caplayer, { + 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, { + 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; } @@ -1528,15 +1472,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, NULL); + 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, NULL); + 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, NULL); + tracebox(start, PL_MIN_CONST, PL_MAX_CONST, end, MOVE_NOMONSTERS, NULL); // how much do we need to back off? safe = 1; @@ -1544,7 +1488,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, NULL); + tracebox(pos, PL_MIN_CONST, PL_MAX_CONST, pos, MOVE_NOMONSTERS, NULL); if (trace_startsolid) { if ((safe + unsafe) * 0.5 == unsafe) break; @@ -1560,7 +1504,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, NULL); + 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; @@ -1574,7 +1518,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, NULL); + 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; @@ -1793,32 +1737,32 @@ SERVER_COMMAND(warp, "Choose different level in campaign") { GameCommand_warp(re void GameCommand_macro_help() { - FOREACH(SERVER_COMMANDS, true, LAMBDA(LOG_INFOF(" ^2%s^7: %s\n", it.m_name, it.m_description))); + FOREACH(SERVER_COMMANDS, true, { LOG_INFOF(" ^2%s^7: %s\n", it.m_name, it.m_description); }); } float GameCommand_macro_command(float argc, string command) { string c = strtolower(argv(0)); - FOREACH(SERVER_COMMANDS, it.m_name == c, LAMBDA( + FOREACH(SERVER_COMMANDS, it.m_name == c, { it.m_invokecmd(it, CMD_REQUEST_COMMAND, NULL, argc, command); return true; - )); + }); return false; } float GameCommand_macro_usage(float argc) { string c = strtolower(argv(1)); - FOREACH(SERVER_COMMANDS, it.m_name == c, LAMBDA( + FOREACH(SERVER_COMMANDS, it.m_name == c, { it.m_invokecmd(it, CMD_REQUEST_USAGE, NULL, argc, ""); return true; - )); + }); return false; } void GameCommand_macro_write_aliases(float fh) { - FOREACH(SERVER_COMMANDS, true, LAMBDA(CMD_Write_Alias("qc_cmd_sv", it.m_name, it.m_description))); + FOREACH(SERVER_COMMANDS, true, { CMD_Write_Alias("qc_cmd_sv", it.m_name, it.m_description); }); }