From: Samual Date: Thu, 29 Dec 2011 17:52:28 +0000 (-0500) Subject: Finish re-writing ban command system, and now the hunt for todo's begins :P X-Git-Tag: xonotic-v0.6.0~188^2~28^2~28 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=a154af392071e37f22326d23eb020f27e54adc79;p=xonotic%2Fxonotic-data.pk3dir.git Finish re-writing ban command system, and now the hunt for todo's begins :P --- diff --git a/qcsrc/server/command/banning.qc b/qcsrc/server/command/banning.qc index 3c0bbfd25..0ab9df576 100644 --- a/qcsrc/server/command/banning.qc +++ b/qcsrc/server/command/banning.qc @@ -3,20 +3,33 @@ // Last updated: December 29th, 2011 // ===================================================== -void BanCommand_ban(float request, float argc) +void BanCommand_ban(float request, float argc, string command) { switch(request) { case CMD_REQUEST_COMMAND: { - - return; + if(argc >= 2) + { + string ip = argv(1); + float reason_arg, bantime; + string reason; + + reason_arg = 2; + + GET_BAN_ARG(bantime, autocvar_g_ban_default_bantime); + GET_BAN_REASON(reason, "No reason provided."); + + Ban_Insert(ip, bantime, reason, 1); + return; + } } default: + print("Incorrect parameters for ^2ban^7\n"); case CMD_REQUEST_USAGE: { - print("\nUsage:^3 sv_cmd "); + print("\nUsage:^3 sv_cmd ban address [time] reason"); print(" No arguments required.\n"); return; } @@ -29,31 +42,54 @@ void BanCommand_banlist(float request) { case CMD_REQUEST_COMMAND: { - + Ban_View(); return; } default: case CMD_REQUEST_USAGE: { - print("\nUsage:^3 sv_cmd "); + print("\nUsage:^3 sv_cmd banlist"); print(" No arguments required.\n"); return; } } } -void BanCommand_kickban(float request, float argc) +void BanCommand_kickban(float request, float argc, string command) { switch(request) { case CMD_REQUEST_COMMAND: { - - return; + if(argc >= 3) + { + entity client = GetIndexedEntity(argc, 1); + float accepted = VerifyClientEntity(client, TRUE, FALSE); + float reason_arg, bantime, masksize; + string reason; + + if(accepted > 0) + { + reason_arg = next_token; + + GET_BAN_ARG(bantime, autocvar_g_ban_default_bantime); + GET_BAN_ARG(masksize, autocvar_g_ban_default_masksize); + GET_BAN_REASON(reason, "No reason provided."); + + Ban_KickBanClient(client, bantime, masksize, reason); + + return; + } + else + { + print("kickban: ", GetClientErrorString(accepted, argv(1)), ".\n"); + } + } } default: + print("Incorrect parameters for ^2kickban^7\n"); case CMD_REQUEST_USAGE: { print("\nUsage:^3 sv_cmd "); @@ -69,15 +105,20 @@ void BanCommand_unban(float request, float argc) { case CMD_REQUEST_COMMAND: { - - return; + if(argc >= 2) + { + float who; + who = stof(argv(1)); + Ban_Delete(who); + return; + } } default: case CMD_REQUEST_USAGE: { - print("\nUsage:^3 sv_cmd "); - print(" No arguments required.\n"); + print("\nUsage:^3 sv_cmd unban banid"); + print(" Where 'banid' is the ID of the ban of which to remove.\n"); return; } } @@ -113,9 +154,9 @@ 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) \ - BAN_COMMAND("ban", BanCommand_ban(request, arguments), "Ban an IP address or a range of addresses (like 1.2.3)") \ + 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), "Disconnect a client and ban it at the same time") \ + BAN_COMMAND("kickban", BanCommand_kickban(request, arguments, command), "Disconnect a client and ban it at the same time") \ BAN_COMMAND("unban", BanCommand_unban(request, arguments), "Remove an existing ban") \ /* nothing */ @@ -165,76 +206,17 @@ void BanCommand_macro_write_aliases(float fh) float BanCommand(string command) { - float argc; - float bantime; - entity client; - float entno; - float masksize; - string reason; - float reasonarg; - - argc = tokenize_console(command); - if(argv(0) == "help") - { - print(" kickban # n m p reason - kickban player n for m seconds, using mask size p (1 to 4)\n"); - print(" ban ip m reason - ban an IP or range (incomplete IP, like 1.2.3) for m seconds\n"); - print(" bans - list all existing bans\n"); - print(" unban n - delete the entry #n from the bans list\n"); - return TRUE; - } - if(argv(0) == "kickban") - { -#define INITARG(c) reasonarg = c -#define GETARG(v,d) if((argc > reasonarg) && ((v = stof(argv(reasonarg))) != 0)) ++reasonarg; else v = d -#define RESTARG(v) if(argc > reasonarg) v = substring(command, argv_start_index(reasonarg), strlen(command) - argv_start_index(reasonarg)); else v = "" - if(argc >= 3) - { - entno = stof(argv(2)); - if(entno > maxclients || entno < 1) - return TRUE; - client = edict_num(entno); - - INITARG(3); - GETARG(bantime, autocvar_g_ban_default_bantime); - GETARG(masksize, autocvar_g_ban_default_masksize); - RESTARG(reason); - - Ban_KickBanClient(client, bantime, masksize, reason); - return TRUE; - } - } - else if(argv(0) == "ban") - { - if(argc >= 2) - { - string ip; - ip = argv(1); - - INITARG(2); - GETARG(bantime, autocvar_g_ban_default_bantime); - RESTARG(reason); + float 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 - Ban_Insert(ip, bantime, reason, 1); - return TRUE; - } -#undef INITARG -#undef GETARG -#undef RESTARG - } - else if(argv(0) == "bans") + if(BanCommand_macro_command(argc, command)) // continue as usual and scan for normal commands { - Ban_View(); - return TRUE; - } - else if(argv(0) == "unban") - { - if(argc >= 2) - { - float who; - who = stof(argv(1)); - Ban_Delete(who); - return TRUE; - } + return TRUE; // handled by one of the above GenericCommand_* functions } + return FALSE; } \ No newline at end of file diff --git a/qcsrc/server/command/banning.qh b/qcsrc/server/command/banning.qh index 30b009944..7a6138283 100644 --- a/qcsrc/server/command/banning.qh +++ b/qcsrc/server/command/banning.qh @@ -1,8 +1,11 @@ // ==================================== // Declarations for kick/ban commands -// Last updated: December 14th, 2011 +// Last updated: December 29th, 2011 // ===================================== +#define GET_BAN_ARG(v,d) if((argc > reason_arg) && ((v = stof(argv(reason_arg))) != 0)) ++reason_arg; else v = d +#define GET_BAN_REASON(v,d) if(argc > reason_arg) v = substring(command, argv_start_index(reason_arg), strlen(command) - argv_start_index(reason_arg)); else v = d + void Ban_KickBanClient(entity client, float bantime, float masksize, string reason); void Ban_View(); float Ban_Insert(string ip, float bantime, string reason, float dosync); diff --git a/qcsrc/server/command/common.qc b/qcsrc/server/command/common.qc index fae940495..e117e5e09 100644 --- a/qcsrc/server/command/common.qc +++ b/qcsrc/server/command/common.qc @@ -736,7 +736,7 @@ void CommonCommand_(float request, entity caller) void CommonCommand_macro_help(entity caller) { #define COMMON_COMMAND(name,function,description) \ - { print_to(caller, strcat(" ^2", name, "^7: ", description, "\n")); } + { print_to(caller, strcat(" ^2", name, "^7: ", description)); } COMMON_COMMANDS(0, caller, 0, "") #undef COMMON_COMMAND diff --git a/qcsrc/server/command/sv_cmd.qc b/qcsrc/server/command/sv_cmd.qc index 36bea4342..076fc37a6 100644 --- a/qcsrc/server/command/sv_cmd.qc +++ b/qcsrc/server/command/sv_cmd.qc @@ -1746,7 +1746,7 @@ void GameCommand(string command) GameCommand_macro_help(); print("\nBanning commands:\n"); - BanCommand("help"); + BanCommand_macro_help(); print("\nCommon networked commands:\n"); CommonCommand_macro_help(world); diff --git a/qcsrc/server/command/vote.qc b/qcsrc/server/command/vote.qc index ab047fecf..0a9412338 100644 --- a/qcsrc/server/command/vote.qc +++ b/qcsrc/server/command/vote.qc @@ -899,7 +899,7 @@ void VoteCommand_(float request) VOTE_COMMAND("abstain", VoteCommand_abstain(request, caller), "Abstain your vote in current vote", VC_ASGNMNT_CLIENTONLY) \ VOTE_COMMAND("call", VoteCommand_call(request, caller, arguments, command), "Create a new vote for players to decide on", VC_ASGNMNT_BOTH) \ VOTE_COMMAND("help", VoteCommand_macro_help(caller, arguments), "Shows this information", VC_ASGNMNT_BOTH) \ - VOTE_COMMAND("master", VoteCommand_master(request, caller, arguments, command), "TODO", VC_ASGNMNT_CLIENTONLY) \ + VOTE_COMMAND("master", VoteCommand_master(request, caller, arguments, command), "Full control over all voting and vote commands", VC_ASGNMNT_CLIENTONLY) \ VOTE_COMMAND("no", VoteCommand_no(request, caller), "Select no in current vote", VC_ASGNMNT_CLIENTONLY) \ VOTE_COMMAND("status", VoteCommand_status(request, caller), "Prints information about current vote", VC_ASGNMNT_BOTH) \ VOTE_COMMAND("stop", VoteCommand_stop(request, caller), "Immediately end a vote", VC_ASGNMNT_BOTH) \ @@ -912,17 +912,16 @@ void VoteCommand_macro_help(entity caller, float argc) if(argc == 2) // help display listing all commands { - print_to(caller, strcat("\nUsage:^3 ", command_origin, " vote COMMAND...^7, where possible commands are:")); - + print("\nVoting commands:\n"); #define VOTE_COMMAND(name,function,description,assignment) \ { if(Votecommand_check_assignment(caller, assignment)) { print_to(caller, strcat(" ^2", name, "^7: ", description)); } } VOTE_COMMANDS(0, caller, 0, "") #undef VOTE_COMMAND - print_to(caller, strcat("For help about specific commands, type ", command_origin, " vote help COMMAND")); - print_to(caller, "^7You can call a vote for or execute these commands:"); - print_to(caller, strcat("^3", autocvar_sv_vote_commands, "^7 and maybe further ^3arguments^7")); + print_to(caller, strcat("\nUsage:^3 ", command_origin, " vote COMMAND...^7, where possible commands are listed above.\n")); + print_to(caller, strcat("For help about a specific command, type ", command_origin, " vote help COMMAND")); + print_to(caller, strcat("\n^7You can call a vote for or execute these commands: ^3", autocvar_sv_vote_commands, "^7 and maybe further ^3arguments^7")); } else // usage for individual command {