1 #include "../../common/command/command.qh"
6 #include "../cl_player.qh"
9 #include "../../common/util.qh"
11 // =====================================================
12 // Banning and kicking command code, written by Samual
13 // Last updated: December 29th, 2011
14 // =====================================================
16 void BanCommand_ban(float request, float argc, string command)
20 case CMD_REQUEST_COMMAND:
25 float reason_arg, bantime;
30 GET_BAN_ARG(bantime, autocvar_g_ban_default_bantime);
31 GET_BAN_REASON(reason, "No reason provided");
33 Ban_Insert(ip, bantime, reason, 1);
39 LOG_INFO("Incorrect parameters for ^2ban^7\n");
40 case CMD_REQUEST_USAGE:
42 LOG_INFO("\nUsage:^3 sv_cmd ban address [bantime] [reason]\n");
43 LOG_INFO(" 'address' is the IP address or range of the player to ban,\n");
44 LOG_INFO(" 'bantime' is the amount of time that the ban is active (default if not provided),\n");
45 LOG_INFO(" and 'reason' is the string to label the ban with as reason for banning.\n");
46 LOG_INFO("See also: ^2banlist, kickban, unban^7\n");
52 void BanCommand_banlist(float request)
56 case CMD_REQUEST_COMMAND:
63 case CMD_REQUEST_USAGE:
65 LOG_INFO("\nUsage:^3 sv_cmd banlist\n");
66 LOG_INFO(" No arguments required.\n");
67 LOG_INFO("See also: ^2ban, kickban, unban^7\n");
73 void BanCommand_kickban(float request, float argc, string command)
77 case CMD_REQUEST_COMMAND:
81 entity client = GetIndexedEntity(argc, 1);
82 float accepted = VerifyKickableEntity(client);
83 float reason_arg, bantime, masksize;
88 reason_arg = next_token;
90 GET_BAN_ARG(bantime, autocvar_g_ban_default_bantime);
91 GET_BAN_ARG(masksize, autocvar_g_ban_default_masksize);
92 GET_BAN_REASON(reason, "No reason provided");
94 Ban_KickBanClient(client, bantime, masksize, reason);
100 LOG_INFO("kickban: ", GetClientErrorString(accepted, argv(1)), ".\n");
106 LOG_INFO("Incorrect parameters for ^2kickban^7\n");
107 case CMD_REQUEST_USAGE:
109 LOG_INFO("\nUsage:^3 sv_cmd kickban client [bantime] [masksize] [reason]\n");
110 LOG_INFO(" 'client' is the entity number or name of the player to ban,\n");
111 LOG_INFO(" 'bantime' is the amount of time that the ban is active (default if not provided),\n");
112 LOG_INFO(" 'masksize' is the range of the IP address (1-thru-4, default if not provided),\n");
113 LOG_INFO(" and 'reason' is the string to label the ban with as reason for banning.\n");
114 LOG_INFO("See also: ^2ban, banlist, unban^7\n");
120 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
124 case CMD_REQUEST_COMMAND:
128 entity client = GetFilteredEntity(argv(1));
129 float accepted = VerifyClientEntity(client, true, false);
138 LOG_INFO("mute: ", GetClientErrorString(accepted, argv(1)), ".\n");
144 LOG_INFO("Incorrect parameters for ^2mute^7\n");
145 case CMD_REQUEST_USAGE:
147 LOG_INFO("\nUsage:^3 sv_cmd mute client\n");
148 LOG_INFO(" 'client' is the entity number or name of the player to mute.\n");
149 LOG_INFO("See also: ^2unmute^7\n");
155 void BanCommand_unban(float request, float argc)
159 case CMD_REQUEST_COMMAND:
163 float tmp_number = -1;
166 if(substring(argv(1), 0, 1) == "#")
168 tmp_string = substring(argv(1), 1, -1);
170 if(tmp_string != "") // is it all one token? like #1
172 tmp_number = stof(tmp_string);
174 else if(argc > 2) // no, it's two tokens? # 1
176 tmp_number = stof(argv(2));
181 else // maybe it's ONLY a number?
183 tmp_number = stof(argv(1));
185 if((tmp_number == 0) && (argv(1) != "0"))
191 Ban_Delete(tmp_number);
198 case CMD_REQUEST_USAGE:
200 LOG_INFO("\nUsage:^3 sv_cmd unban banid\n");
201 LOG_INFO(" Where 'banid' is the ID of the ban of which to remove.\n");
202 LOG_INFO("See also: ^2ban, banlist, kickban^7\n");
208 void BanCommand_unmute(float request, float argc)
212 case CMD_REQUEST_COMMAND:
216 entity client = GetFilteredEntity(argv(1));
217 float accepted = VerifyClientEntity(client, true, false);
221 client.muted = false;
226 LOG_INFO("unmute: ", GetClientErrorString(accepted, argv(1)), ".\n");
232 LOG_INFO("Incorrect parameters for ^2mute^7\n");
233 case CMD_REQUEST_USAGE:
235 LOG_INFO("\nUsage:^3 sv_cmd unmute client\n");
236 LOG_INFO(" 'client' is the entity number or name of the player to unmute.\n");
237 LOG_INFO("See also: ^2mute^7\n");
243 /* use this when creating a new command, making sure to place it in alphabetical order... also,
244 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
245 void BanCommand_(float request)
249 case CMD_REQUEST_COMMAND:
256 case CMD_REQUEST_USAGE:
258 print("\nUsage:^3 sv_cmd \n");
259 print(" No arguments required.\n");
267 // ==================================
268 // Macro system for server commands
269 // ==================================
271 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
272 #define BAN_COMMANDS(request,arguments,command) \
273 BAN_COMMAND("ban", BanCommand_ban(request, arguments, command), "Ban an IP address or a range of addresses (like 1.2.3)") \
274 BAN_COMMAND("banlist", BanCommand_banlist(request), "List all existing bans") \
275 BAN_COMMAND("kickban", BanCommand_kickban(request, arguments, command), "Disconnect a client and ban it at the same time") \
276 BAN_COMMAND("mute", BanCommand_mute(request, arguments, command), "Disallow a client from talking by muting them") \
277 BAN_COMMAND("unban", BanCommand_unban(request, arguments), "Remove an existing ban") \
278 BAN_COMMAND("unmute", BanCommand_unmute(request, arguments), "Unmute a client") \
281 void BanCommand_macro_help()
283 #define BAN_COMMAND(name,function,description) \
284 { if(strtolower(description) != "") { LOG_INFO(" ^2", name, "^7: ", description, "\n"); } }
286 BAN_COMMANDS(0, 0, "");
292 float BanCommand_macro_command(float argc, string command)
294 #define BAN_COMMAND(name,function,description) \
295 { if(name == strtolower(argv(0))) { function; return true; } }
297 BAN_COMMANDS(CMD_REQUEST_COMMAND, argc, command);
303 float BanCommand_macro_usage(float argc)
305 #define BAN_COMMAND(name,function,description) \
306 { if(name == strtolower(argv(1))) { function; return true; } }
308 BAN_COMMANDS(CMD_REQUEST_USAGE, argc, "");
314 void BanCommand_macro_write_aliases(float fh)
316 #define BAN_COMMAND(name,function,description) \
317 { if(strtolower(description) != "") { CMD_Write_Alias("qc_cmd_sv", name, description); } }
319 BAN_COMMANDS(0, 0, "");
325 float BanCommand(string command)
327 float argc = tokenize_console(command);
329 // Guide for working with argc arguments by example:
330 // argc: 1 - 2 - 3 - 4
331 // argv: 0 - 1 - 2 - 3
332 // cmd vote - master - login - password
334 if(BanCommand_macro_command(argc, command)) // continue as usual and scan for normal commands
336 return true; // handled by one of the above GenericCommand_* functions