X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fcommand%2Fbanning.qc;h=7607ced7406c8ce227fa159f6e099d9f6d4e7fab;hb=c6494490daa287dd5817c77e9c3d8416df182ed0;hp=e3d3c67591f9888de119f0a3bc1f344156ae689f;hpb=1bc3ab0285f65c7ed0c75cbba00da2460921c973;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/command/banning.qc b/qcsrc/server/command/banning.qc index e3d3c6759..7607ced74 100644 --- a/qcsrc/server/command/banning.qc +++ b/qcsrc/server/command/banning.qc @@ -1,26 +1,30 @@ -#include "../../common/command/command.qh" #include "banning.qh" -#include "../_all.qh" + +#include +#include +#include +#include +#include "banning.qh" #include "common.qh" -#include "../cl_player.qh" +#include "../player.qh" #include "../ipban.qh" -#include "../../common/util.qh" +#include // ===================================================== // Banning and kicking command code, written by Samual // Last updated: December 29th, 2011 // ===================================================== -void BanCommand_ban(float request, float argc, string command) +void BanCommand_ban(int request, int argc, string command) { - switch(request) + switch (request) { case CMD_REQUEST_COMMAND: { - if(argc >= 2) + if (argc >= 2) { string ip = argv(1); float reason_arg, bantime; @@ -37,22 +41,22 @@ void BanCommand_ban(float request, float argc, string command) } default: - print("Incorrect parameters for ^2ban^7\n"); + LOG_INFO("Incorrect parameters for ^2ban^7"); case CMD_REQUEST_USAGE: { - print("\nUsage:^3 sv_cmd ban address [bantime] [reason]\n"); - print(" 'address' is the IP address or range of the player to ban,\n"); - print(" 'bantime' is the amount of time that the ban is active (default if not provided),\n"); - print(" and 'reason' is the string to label the ban with as reason for banning.\n"); - print("See also: ^2banlist, kickban, unban^7\n"); + LOG_HELP("Usage:^3 sv_cmd ban address [bantime] [reason]"); + LOG_HELP(" 'address' is the IP address or range of the player to ban,"); + LOG_HELP(" 'bantime' is the amount of time that the ban is active (default if not provided),"); + LOG_HELP(" and 'reason' is the string to label the ban with as reason for banning."); + LOG_HELP("See also: ^2banlist, kickban, unban^7"); return; } } } -void BanCommand_banlist(float request) +void BanCommand_banlist(int request) { - switch(request) + switch (request) { case CMD_REQUEST_COMMAND: { @@ -63,28 +67,28 @@ void BanCommand_banlist(float request) default: case CMD_REQUEST_USAGE: { - print("\nUsage:^3 sv_cmd banlist\n"); - print(" No arguments required.\n"); - print("See also: ^2ban, kickban, unban^7\n"); + LOG_HELP("Usage:^3 sv_cmd banlist"); + LOG_HELP(" No arguments required."); + LOG_HELP("See also: ^2ban, kickban, unban^7"); return; } } } -void BanCommand_kickban(float request, float argc, string command) +void BanCommand_kickban(int request, int argc, string command) { - switch(request) + switch (request) { case CMD_REQUEST_COMMAND: { - if(argc >= 2) + if (argc >= 2) { entity client = GetIndexedEntity(argc, 1); float accepted = VerifyKickableEntity(client); float reason_arg, bantime, masksize; string reason; - if(accepted > 0) + if (accepted > 0) { reason_arg = next_token; @@ -98,96 +102,89 @@ void BanCommand_kickban(float request, float argc, string command) } else { - print("kickban: ", GetClientErrorString(accepted, argv(1)), ".\n"); + LOG_INFO("kickban: ", GetClientErrorString(accepted, argv(1)), "."); } } } default: - print("Incorrect parameters for ^2kickban^7\n"); + LOG_INFO("Incorrect parameters for ^2kickban^7"); case CMD_REQUEST_USAGE: { - print("\nUsage:^3 sv_cmd kickban client [bantime] [masksize] [reason]\n"); - print(" 'client' is the entity number or name of the player to ban,\n"); - print(" 'bantime' is the amount of time that the ban is active (default if not provided),\n"); - print(" 'masksize' is the range of the IP address (1-thru-4, default if not provided),\n"); - print(" and 'reason' is the string to label the ban with as reason for banning.\n"); - print("See also: ^2ban, banlist, unban^7\n"); + LOG_HELP("Usage:^3 sv_cmd kickban client [bantime] [masksize] [reason]"); + LOG_HELP(" 'client' is the entity number or name of the player to ban,"); + LOG_HELP(" 'bantime' is the amount of time that the ban is active (default if not provided),"); + LOG_HELP(" 'masksize' is the range of the IP address (1-thru-4, default if not provided),"); + LOG_HELP(" and 'reason' is the string to label the ban with as reason for banning."); + LOG_HELP("See also: ^2ban, banlist, unban^7"); return; } } } -void BanCommand_mute(float request, float argc, string command) // TODO: Add a sort of mute-"ban" which allows players to be muted based on IP/cryptokey +void BanCommand_mute(int request, int argc, string command) // TODO: Add a sort of mute-"ban" which allows players to be muted based on IP/cryptokey { - switch(request) + switch (request) { case CMD_REQUEST_COMMAND: { - if(argc >= 2) + if (argc >= 2) { entity client = GetFilteredEntity(argv(1)); float accepted = VerifyClientEntity(client, true, false); - if(accepted > 0) + if (accepted > 0) { - client.muted = true; + CS(client).muted = true; return; } else { - print("mute: ", GetClientErrorString(accepted, argv(1)), ".\n"); + LOG_INFO("mute: ", GetClientErrorString(accepted, argv(1)), "."); } } } default: - print("Incorrect parameters for ^2mute^7\n"); + LOG_INFO("Incorrect parameters for ^2mute^7"); case CMD_REQUEST_USAGE: { - print("\nUsage:^3 sv_cmd mute client\n"); - print(" 'client' is the entity number or name of the player to mute.\n"); - print("See also: ^2unmute^7\n"); + LOG_HELP("Usage:^3 sv_cmd mute client"); + LOG_HELP(" 'client' is the entity number or name of the player to mute."); + LOG_HELP("See also: ^2unmute^7"); return; } } } -void BanCommand_unban(float request, float argc) +void BanCommand_unban(int request, int argc) { - switch(request) + switch (request) { case CMD_REQUEST_COMMAND: { - if(argv(1)) + if (argv(1)) { float tmp_number = -1; string tmp_string; - if(substring(argv(1), 0, 1) == "#") + if (substring(argv(1), 0, 1) == "#") { tmp_string = substring(argv(1), 1, -1); - if(tmp_string != "") // is it all one token? like #1 - { + if (tmp_string != "") // is it all one token? like #1 tmp_number = stof(tmp_string); - } - else if(argc > 2) // no, it's two tokens? # 1 - { + else if (argc > 2) // no, it's two tokens? # 1 tmp_number = stof(argv(2)); - } - else - tmp_number = -1; + else tmp_number = -1; } - else // maybe it's ONLY a number? + else // maybe it's ONLY a number? { tmp_number = stof(argv(1)); - if((tmp_number == 0) && (argv(1) != "0")) - { tmp_number = -1; } - } + if ((tmp_number == 0) && (argv(1) != "0")) tmp_number = -1; } - if(tmp_number >= 0) + if (tmp_number >= 0) { Ban_Delete(tmp_number); return; @@ -198,44 +195,44 @@ void BanCommand_unban(float request, float argc) default: case CMD_REQUEST_USAGE: { - print("\nUsage:^3 sv_cmd unban banid\n"); - print(" Where 'banid' is the ID of the ban of which to remove.\n"); - print("See also: ^2ban, banlist, kickban^7\n"); + LOG_HELP("Usage:^3 sv_cmd unban banid"); + LOG_HELP(" Where 'banid' is the ID of the ban of which to remove."); + LOG_HELP("See also: ^2ban, banlist, kickban^7"); return; } } } -void BanCommand_unmute(float request, float argc) +void BanCommand_unmute(int request, int argc) { - switch(request) + switch (request) { case CMD_REQUEST_COMMAND: { - if(argc >= 2) + if (argc >= 2) { entity client = GetFilteredEntity(argv(1)); float accepted = VerifyClientEntity(client, true, false); - if(accepted > 0) + if (accepted > 0) { - client.muted = false; + CS(client).muted = false; return; } else { - print("unmute: ", GetClientErrorString(accepted, argv(1)), ".\n"); + LOG_INFO("unmute: ", GetClientErrorString(accepted, argv(1)), "."); } } } default: - print("Incorrect parameters for ^2mute^7\n"); + LOG_INFO("Incorrect parameters for ^2mute^7"); case CMD_REQUEST_USAGE: { - print("\nUsage:^3 sv_cmd unmute client\n"); - print(" 'client' is the entity number or name of the player to unmute.\n"); - print("See also: ^2mute^7\n"); + LOG_HELP("Usage:^3 sv_cmd unmute client"); + LOG_HELP(" 'client' is the entity number or name of the player to unmute."); + LOG_HELP("See also: ^2mute^7"); return; } } @@ -243,24 +240,24 @@ void BanCommand_unmute(float request, 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 BanCommand_(float request) +void BanCommand_(int request) { - switch(request) - { - case CMD_REQUEST_COMMAND: - { - - return; - } - - default: - case CMD_REQUEST_USAGE: - { - print("\nUsage:^3 sv_cmd \n"); - print(" No arguments required.\n"); - return; - } - } + switch(request) + { + case CMD_REQUEST_COMMAND: + { + + return; + } + + default: + case CMD_REQUEST_USAGE: + { + LOG_HELP("Usage:^3 sv_cmd "); + LOG_HELP(" No arguments required."); + return; + } + } } */ @@ -270,7 +267,7 @@ void BanCommand_(float request) // ================================== // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;) -#define BAN_COMMANDS(request,arguments,command) \ +#define BAN_COMMANDS(request, arguments, command) \ BAN_COMMAND("ban", BanCommand_ban(request, arguments, command), "Ban an IP address or a range of addresses (like 1.2.3)") \ BAN_COMMAND("banlist", BanCommand_banlist(request), "List all existing bans") \ BAN_COMMAND("kickban", BanCommand_kickban(request, arguments, command), "Disconnect a client and ban it at the same time") \ @@ -281,61 +278,55 @@ void BanCommand_(float request) void BanCommand_macro_help() { - #define BAN_COMMAND(name,function,description) \ - { if(strtolower(description) != "") { print(" ^2", name, "^7: ", description, "\n"); } } + #define BAN_COMMAND(name, function, description) \ + { if (strtolower(description) != "") { LOG_INFO(" ^2", name, "^7: ", description); } } BAN_COMMANDS(0, 0, ""); - #undef BAN_COMMAND - - return; +#undef BAN_COMMAND } -float BanCommand_macro_command(float argc, string command) +float BanCommand_macro_command(int argc, string command) { - #define BAN_COMMAND(name,function,description) \ - { if(name == strtolower(argv(0))) { function; return true; } } + #define BAN_COMMAND(name, function, description) \ + { if (name == strtolower(argv(0))) { function; return true; } } BAN_COMMANDS(CMD_REQUEST_COMMAND, argc, command); - #undef BAN_COMMAND +#undef BAN_COMMAND return false; } -float BanCommand_macro_usage(float argc) +float BanCommand_macro_usage(int argc) { - #define BAN_COMMAND(name,function,description) \ - { if(name == strtolower(argv(1))) { function; return true; } } + #define BAN_COMMAND(name, function, description) \ + { if (name == strtolower(argv(1))) { function; return true; } } BAN_COMMANDS(CMD_REQUEST_USAGE, argc, ""); - #undef BAN_COMMAND +#undef BAN_COMMAND return false; } void BanCommand_macro_write_aliases(float fh) { - #define BAN_COMMAND(name,function,description) \ - { if(strtolower(description) != "") { CMD_Write_Alias("qc_cmd_sv", name, description); } } + #define BAN_COMMAND(name, function, description) \ + { if (strtolower(description) != "") { CMD_Write_Alias("qc_cmd_sv", name, description); } } BAN_COMMANDS(0, 0, ""); - #undef BAN_COMMAND - - return; +#undef BAN_COMMAND } float BanCommand(string command) { - float argc = tokenize_console(command); + int argc = tokenize_console(command); // Guide for working with argc arguments by example: // argc: 1 - 2 - 3 - 4 // argv: 0 - 1 - 2 - 3 // cmd vote - master - login - password - if(BanCommand_macro_command(argc, command)) // continue as usual and scan for normal commands - { - return true; // handled by one of the above GenericCommand_* functions - } + if (BanCommand_macro_command(argc, command)) // continue as usual and scan for normal commands + return true; // handled by one of the above GenericCommand_* functions return false; }