From 9e0b72200d0c0a9df6f60b8facbc7f84bfde1ee3 Mon Sep 17 00:00:00 2001 From: Samual Date: Sun, 18 Dec 2011 11:00:18 -0500 Subject: [PATCH] Add "separator" support to who command, limit nicknames to 20 characters, better privacy calculation across sv_cmd/cmd, and other various fixes --- commands.cfg | 6 +++--- qcsrc/common/util.qc | 3 ++- qcsrc/server/command/cmd.qc | 2 +- qcsrc/server/command/common.qc | 28 ++++++++++++++++------------ qcsrc/server/command/sv_cmd.qc | 2 +- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/commands.cfg b/commands.cfg index 4bfd5087f..8d8e08655 100644 --- a/commands.cfg +++ b/commands.cfg @@ -16,8 +16,8 @@ alias if_dedicated "${* asis}" _if_dedicated alias if_client "" if_client alias if_dedicated "" -if_client alias cmd_prefix "cmd" -if_dedicated alias cmd_prefix "sv_cmd" +if_client set cmd_prefix "cmd" +if_dedicated set cmd_prefix "sv_cmd" // ======== @@ -37,7 +37,7 @@ alias time "${cmd_prefix !} time" alias timein "${cmd_prefix !} timein" alias timeout "${cmd_prefix !} timeout" alias vote "${cmd_prefix !} vote ${* ?}" -alias who "${cmd_prefix !} who" +alias who "${cmd_prefix !} who ${* ?}" alias g_hitplots_add "qc_cmd rpn /g_hitplots_individuals g_hitplots_individuals ${1 !} union def" alias g_hitplots_remove "qc_cmd rpn /g_hitplots_individuals g_hitplots_individuals ${1 !} difference def" diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 5bb7943fe..afcefd0d3 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -2108,13 +2108,14 @@ float lowestbit(float f) return f; } +/* string strlimitedlen(string input, string truncation, float strip_colors, float limit) { if(strlen((strip_colors ? strdecolorize(input) : input)) <= limit) return input; else return strcat(substring(input, 0, (strlen(input) - strlen(truncation))), truncation); -} +}*/ #ifdef CSQC entity ReadCSQCEntity() diff --git a/qcsrc/server/command/cmd.qc b/qcsrc/server/command/cmd.qc index 21521d753..908d01905 100644 --- a/qcsrc/server/command/cmd.qc +++ b/qcsrc/server/command/cmd.qc @@ -565,7 +565,7 @@ void ClientCommand_(float request) CLIENT_COMMAND("timeout", CommonCommand_timeout(request, self), "Call a timeout which pauses the game for certain amount of time unless unpaused") \ CLIENT_COMMAND("voice", ClientCommand_voice(request, arguments, command), "Send voice message via sound") \ CLIENT_COMMAND("vote", VoteCommand(request, self, arguments, command), "Request an action to be voted upon by players") \ - CLIENT_COMMAND("who", CommonCommand_who(request, self), "Display detailed client information about all players") \ + CLIENT_COMMAND("who", CommonCommand_who(request, self, arguments), "Display detailed client information about all players") \ /* nothing */ void ClientCommand_macro_help() diff --git a/qcsrc/server/command/common.qc b/qcsrc/server/command/common.qc index d6d4a2dd2..3d10c8137 100644 --- a/qcsrc/server/command/common.qc +++ b/qcsrc/server/command/common.qc @@ -454,18 +454,21 @@ void CommonCommand_timeout(float request, entity caller) // DEAR GOD THIS COMMAN } } -void CommonCommand_who(float request, entity caller) +void CommonCommand_who(float request, entity caller, float argc) { switch(request) { case CMD_REQUEST_COMMAND: { float total_listed_players, tmp_hours, tmp_minutes, tmp_seconds; - entity tmp_player; - //string tmp_player_name; + entity tmp_player; - print_to(caller, strcat("List of client information", (autocvar_sv_status_privacy ? " (some data is hidden for privacy)" : string_null), ":")); - print_to(caller, sprintf(" %-4s %-20s %-5s %-3s %-9s %-16s %s", "ent", "nickname", "ping", "pl", "time", "ip", "crypto_id")); + string separator = strcat((argv(1) ? argv(1) : " "), "^7"); + float privacy = (caller && autocvar_sv_status_privacy); + + print_to(caller, strcat("List of client information", (privacy ? " (some data is hidden for privacy)" : string_null), ":")); + print_to(caller, sprintf(strreplace(" ", separator, " %-4s %-20s %-5s %-3s %-9s %-16s %s "), + "ent", "nickname", "ping", "pl", "time", "ip", "crypto_id")); FOR_EACH_CLIENT(tmp_player) { @@ -478,13 +481,14 @@ void CommonCommand_who(float request, entity caller) if(tmp_minutes) { tmp_seconds -= (tmp_minutes * 60); } if(tmp_hours) { tmp_minutes -= (tmp_hours * 60); } - print_to(caller, sprintf(" %-4s %-20s %-5d %-3d %-9s %-16s %s", + print_to(caller, sprintf(strreplace(" ", separator, " %-4s %-20.20s %-5d %-3d %-9s %-16s %s "), strcat("#", ftos(num_for_edict(tmp_player))), - tmp_player.netname, //strcat(tmp_player_name, sprintf("%*s", (20 - strlen(strdecolorize(tmp_player_name))), "")), - tmp_player.ping, tmp_player.ping_packetloss, + tmp_player.netname, + tmp_player.ping, + tmp_player.ping_packetloss, sprintf("%02d:%02d:%02d", tmp_hours, tmp_minutes, tmp_seconds), - (autocvar_sv_status_privacy ? "hidden" : tmp_player.netaddress), - (autocvar_sv_status_privacy ? "hidden" : tmp_player.crypto_idfp))); + (privacy ? "hidden" : tmp_player.netaddress), + (privacy ? "hidden" : tmp_player.crypto_idfp))); ++total_listed_players; } @@ -497,8 +501,8 @@ void CommonCommand_who(float request, entity caller) default: case CMD_REQUEST_USAGE: { - print_to(caller, strcat("\nUsage:^3 ", GetCommandPrefix(caller), " who")); - print_to(caller, " No arguments required."); + print_to(caller, strcat("\nUsage:^3 ", GetCommandPrefix(caller), " who [separator]")); + print_to(caller, " Where 'separator' is the optional string to separate the values with, default is a space."); return; } } diff --git a/qcsrc/server/command/sv_cmd.qc b/qcsrc/server/command/sv_cmd.qc index 34e302458..6b43308db 100644 --- a/qcsrc/server/command/sv_cmd.qc +++ b/qcsrc/server/command/sv_cmd.qc @@ -1760,7 +1760,7 @@ void GameCommand_(float request) 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") \ - SERVER_COMMAND("who", CommonCommand_who(request, world), "Display detailed client information about all players") \ + SERVER_COMMAND("who", CommonCommand_who(request, world, arguments), "Display detailed client information about all players") \ SERVER_COMMAND("vote", VoteCommand(request, world, arguments, command), "Server side control of voting") \ /* nothing */ -- 2.39.2