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
171 tmp_number = stof(tmp_string);
172 else if (argc > 2) // no, it's two tokens? # 1
173 tmp_number = stof(argv(2));
174 else tmp_number = -1;
176 else // maybe it's ONLY a number?
178 tmp_number = stof(argv(1));
180 if ((tmp_number == 0) && (argv(1) != "0")) tmp_number = -1; }
184 Ban_Delete(tmp_number);
191 case CMD_REQUEST_USAGE:
193 LOG_INFO("\nUsage:^3 sv_cmd unban banid\n");
194 LOG_INFO(" Where 'banid' is the ID of the ban of which to remove.\n");
195 LOG_INFO("See also: ^2ban, banlist, kickban^7\n");
201 void BanCommand_unmute(float request, float argc)
205 case CMD_REQUEST_COMMAND:
209 entity client = GetFilteredEntity(argv(1));
210 float accepted = VerifyClientEntity(client, true, false);
214 client.muted = false;
219 LOG_INFO("unmute: ", GetClientErrorString(accepted, argv(1)), ".\n");
225 LOG_INFO("Incorrect parameters for ^2mute^7\n");
226 case CMD_REQUEST_USAGE:
228 LOG_INFO("\nUsage:^3 sv_cmd unmute client\n");
229 LOG_INFO(" 'client' is the entity number or name of the player to unmute.\n");
230 LOG_INFO("See also: ^2mute^7\n");
236 /* use this when creating a new command, making sure to place it in alphabetical order... also,
237 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
238 void BanCommand_(float request)
242 case CMD_REQUEST_COMMAND:
249 case CMD_REQUEST_USAGE:
251 print("\nUsage:^3 sv_cmd \n");
252 print(" No arguments required.\n");
260 // ==================================
261 // Macro system for server commands
262 // ==================================
264 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
265 #define BAN_COMMANDS(request, arguments, command) \
266 BAN_COMMAND("ban", BanCommand_ban(request, arguments, command), "Ban an IP address or a range of addresses (like 1.2.3)") \
267 BAN_COMMAND("banlist", BanCommand_banlist(request), "List all existing bans") \
268 BAN_COMMAND("kickban", BanCommand_kickban(request, arguments, command), "Disconnect a client and ban it at the same time") \
269 BAN_COMMAND("mute", BanCommand_mute(request, arguments, command), "Disallow a client from talking by muting them") \
270 BAN_COMMAND("unban", BanCommand_unban(request, arguments), "Remove an existing ban") \
271 BAN_COMMAND("unmute", BanCommand_unmute(request, arguments), "Unmute a client") \
274 void BanCommand_macro_help()
276 #define BAN_COMMAND(name, function, description) \
277 { if (strtolower(description) != "") { LOG_INFO(" ^2", name, "^7: ", description, "\n"); } }
279 BAN_COMMANDS(0, 0, "");
283 float BanCommand_macro_command(float argc, string command)
285 #define BAN_COMMAND(name, function, description) \
286 { if (name == strtolower(argv(0))) { function; return true; } }
288 BAN_COMMANDS(CMD_REQUEST_COMMAND, argc, command);
294 float BanCommand_macro_usage(float argc)
296 #define BAN_COMMAND(name, function, description) \
297 { if (name == strtolower(argv(1))) { function; return true; } }
299 BAN_COMMANDS(CMD_REQUEST_USAGE, argc, "");
305 void BanCommand_macro_write_aliases(float fh)
307 #define BAN_COMMAND(name, function, description) \
308 { if (strtolower(description) != "") { CMD_Write_Alias("qc_cmd_sv", name, description); } }
310 BAN_COMMANDS(0, 0, "");
314 float BanCommand(string command)
316 float argc = tokenize_console(command);
318 // Guide for working with argc arguments by example:
319 // argc: 1 - 2 - 3 - 4
320 // argv: 0 - 1 - 2 - 3
321 // cmd vote - master - login - password
323 if (BanCommand_macro_command(argc, command)) // continue as usual and scan for normal commands
324 return true; // handled by one of the above GenericCommand_* functions