3 #include <server/defs.qh>
4 #include <server/miscfunctions.qh>
5 #include <common/state.qh>
6 #include <common/command/_mod.qh>
11 #include "../player.qh"
12 #include "../ipban.qh"
14 #include <common/util.qh>
16 // =====================================================
17 // Banning and kicking command code, written by Samual
18 // Last updated: December 29th, 2011
19 // =====================================================
21 void BanCommand_ban(float request, float argc, string command)
25 case CMD_REQUEST_COMMAND:
30 float reason_arg, bantime;
35 GET_BAN_ARG(bantime, autocvar_g_ban_default_bantime);
36 GET_BAN_REASON(reason, "No reason provided");
38 Ban_Insert(ip, bantime, reason, 1);
44 LOG_INFO("Incorrect parameters for ^2ban^7");
45 case CMD_REQUEST_USAGE:
47 LOG_INFO("Usage:^3 sv_cmd ban address [bantime] [reason]");
48 LOG_INFO(" 'address' is the IP address or range of the player to ban,");
49 LOG_INFO(" 'bantime' is the amount of time that the ban is active (default if not provided),");
50 LOG_INFO(" and 'reason' is the string to label the ban with as reason for banning.");
51 LOG_INFO("See also: ^2banlist, kickban, unban^7");
57 void BanCommand_banlist(float request)
61 case CMD_REQUEST_COMMAND:
68 case CMD_REQUEST_USAGE:
70 LOG_INFO("Usage:^3 sv_cmd banlist");
71 LOG_INFO(" No arguments required.");
72 LOG_INFO("See also: ^2ban, kickban, unban^7");
78 void BanCommand_kickban(float request, float argc, string command)
82 case CMD_REQUEST_COMMAND:
86 entity client = GetIndexedEntity(argc, 1);
87 float accepted = VerifyKickableEntity(client);
88 float reason_arg, bantime, masksize;
93 reason_arg = next_token;
95 GET_BAN_ARG(bantime, autocvar_g_ban_default_bantime);
96 GET_BAN_ARG(masksize, autocvar_g_ban_default_masksize);
97 GET_BAN_REASON(reason, "No reason provided");
99 Ban_KickBanClient(client, bantime, masksize, reason);
105 LOG_INFO("kickban: ", GetClientErrorString(accepted, argv(1)), ".");
111 LOG_INFO("Incorrect parameters for ^2kickban^7");
112 case CMD_REQUEST_USAGE:
114 LOG_INFO("Usage:^3 sv_cmd kickban client [bantime] [masksize] [reason]");
115 LOG_INFO(" 'client' is the entity number or name of the player to ban,");
116 LOG_INFO(" 'bantime' is the amount of time that the ban is active (default if not provided),");
117 LOG_INFO(" 'masksize' is the range of the IP address (1-thru-4, default if not provided),");
118 LOG_INFO(" and 'reason' is the string to label the ban with as reason for banning.");
119 LOG_INFO("See also: ^2ban, banlist, unban^7");
125 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
129 case CMD_REQUEST_COMMAND:
133 entity client = GetFilteredEntity(argv(1));
134 float accepted = VerifyClientEntity(client, true, false);
138 CS(client).muted = true;
143 LOG_INFO("mute: ", GetClientErrorString(accepted, argv(1)), ".");
149 LOG_INFO("Incorrect parameters for ^2mute^7");
150 case CMD_REQUEST_USAGE:
152 LOG_INFO("Usage:^3 sv_cmd mute client");
153 LOG_INFO(" 'client' is the entity number or name of the player to mute.");
154 LOG_INFO("See also: ^2unmute^7");
160 void BanCommand_unban(float request, float argc)
164 case CMD_REQUEST_COMMAND:
168 float tmp_number = -1;
171 if (substring(argv(1), 0, 1) == "#")
173 tmp_string = substring(argv(1), 1, -1);
175 if (tmp_string != "") // is it all one token? like #1
176 tmp_number = stof(tmp_string);
177 else if (argc > 2) // no, it's two tokens? # 1
178 tmp_number = stof(argv(2));
179 else tmp_number = -1;
181 else // maybe it's ONLY a number?
183 tmp_number = stof(argv(1));
185 if ((tmp_number == 0) && (argv(1) != "0")) tmp_number = -1; }
189 Ban_Delete(tmp_number);
196 case CMD_REQUEST_USAGE:
198 LOG_INFO("Usage:^3 sv_cmd unban banid");
199 LOG_INFO(" Where 'banid' is the ID of the ban of which to remove.");
200 LOG_INFO("See also: ^2ban, banlist, kickban^7");
206 void BanCommand_unmute(float request, float argc)
210 case CMD_REQUEST_COMMAND:
214 entity client = GetFilteredEntity(argv(1));
215 float accepted = VerifyClientEntity(client, true, false);
219 CS(client).muted = false;
224 LOG_INFO("unmute: ", GetClientErrorString(accepted, argv(1)), ".");
230 LOG_INFO("Incorrect parameters for ^2mute^7");
231 case CMD_REQUEST_USAGE:
233 LOG_INFO("Usage:^3 sv_cmd unmute client");
234 LOG_INFO(" 'client' is the entity number or name of the player to unmute.");
235 LOG_INFO("See also: ^2mute^7");
241 /* use this when creating a new command, making sure to place it in alphabetical order... also,
242 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
243 void BanCommand_(float request)
247 case CMD_REQUEST_COMMAND:
254 case CMD_REQUEST_USAGE:
256 print("\nUsage:^3 sv_cmd \n");
257 print(" No arguments required.\n");
265 // ==================================
266 // Macro system for server commands
267 // ==================================
269 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
270 #define BAN_COMMANDS(request, arguments, command) \
271 BAN_COMMAND("ban", BanCommand_ban(request, arguments, command), "Ban an IP address or a range of addresses (like 1.2.3)") \
272 BAN_COMMAND("banlist", BanCommand_banlist(request), "List all existing bans") \
273 BAN_COMMAND("kickban", BanCommand_kickban(request, arguments, command), "Disconnect a client and ban it at the same time") \
274 BAN_COMMAND("mute", BanCommand_mute(request, arguments, command), "Disallow a client from talking by muting them") \
275 BAN_COMMAND("unban", BanCommand_unban(request, arguments), "Remove an existing ban") \
276 BAN_COMMAND("unmute", BanCommand_unmute(request, arguments), "Unmute a client") \
279 void BanCommand_macro_help()
281 #define BAN_COMMAND(name, function, description) \
282 { if (strtolower(description) != "") { LOG_INFO(" ^2", name, "^7: ", description); } }
284 BAN_COMMANDS(0, 0, "");
288 float BanCommand_macro_command(float argc, string command)
290 #define BAN_COMMAND(name, function, description) \
291 { if (name == strtolower(argv(0))) { function; return true; } }
293 BAN_COMMANDS(CMD_REQUEST_COMMAND, argc, command);
299 float BanCommand_macro_usage(float argc)
301 #define BAN_COMMAND(name, function, description) \
302 { if (name == strtolower(argv(1))) { function; return true; } }
304 BAN_COMMANDS(CMD_REQUEST_USAGE, argc, "");
310 void BanCommand_macro_write_aliases(float fh)
312 #define BAN_COMMAND(name, function, description) \
313 { if (strtolower(description) != "") { CMD_Write_Alias("qc_cmd_sv", name, description); } }
315 BAN_COMMANDS(0, 0, "");
319 float BanCommand(string command)
321 float argc = tokenize_console(command);
323 // Guide for working with argc arguments by example:
324 // argc: 1 - 2 - 3 - 4
325 // argv: 0 - 1 - 2 - 3
326 // cmd vote - master - login - password
328 if (BanCommand_macro_command(argc, command)) // continue as usual and scan for normal commands
329 return true; // handled by one of the above GenericCommand_* functions