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)
24 case CMD_REQUEST_COMMAND:
28 float reason_arg, bantime;
33 GET_BAN_ARG(bantime, autocvar_g_ban_default_bantime);
34 GET_BAN_REASON(reason, "No reason provided");
36 Ban_Insert(ip, bantime, reason, 1);
42 LOG_INFO("Incorrect parameters for ^2ban^7");
43 case CMD_REQUEST_USAGE:
45 LOG_INFO("Usage:^3 sv_cmd ban address [bantime] [reason]");
46 LOG_INFO(" 'address' is the IP address or range of the player to ban,");
47 LOG_INFO(" 'bantime' is the amount of time that the ban is active (default if not provided),");
48 LOG_INFO(" and 'reason' is the string to label the ban with as reason for banning.");
49 LOG_INFO("See also: ^2banlist, kickban, unban^7");
55 void BanCommand_banlist(float request)
58 case CMD_REQUEST_COMMAND:
65 case CMD_REQUEST_USAGE:
67 LOG_INFO("Usage:^3 sv_cmd banlist");
68 LOG_INFO(" No arguments required.");
69 LOG_INFO("See also: ^2ban, kickban, unban^7");
75 void BanCommand_kickban(float request, float argc, string command)
78 case CMD_REQUEST_COMMAND:
81 entity client = GetIndexedEntity(argc, 1);
82 float accepted = VerifyKickableEntity(client);
83 float reason_arg, bantime, masksize;
87 reason_arg = next_token;
89 GET_BAN_ARG(bantime, autocvar_g_ban_default_bantime);
90 GET_BAN_ARG(masksize, autocvar_g_ban_default_masksize);
91 GET_BAN_REASON(reason, "No reason provided");
93 Ban_KickBanClient(client, bantime, masksize, reason);
97 LOG_INFO("kickban: ", GetClientErrorString(accepted, argv(1)), ".");
103 LOG_INFO("Incorrect parameters for ^2kickban^7");
104 case CMD_REQUEST_USAGE:
106 LOG_INFO("Usage:^3 sv_cmd kickban client [bantime] [masksize] [reason]");
107 LOG_INFO(" 'client' is the entity number or name of the player to ban,");
108 LOG_INFO(" 'bantime' is the amount of time that the ban is active (default if not provided),");
109 LOG_INFO(" 'masksize' is the range of the IP address (1-thru-4, default if not provided),");
110 LOG_INFO(" and 'reason' is the string to label the ban with as reason for banning.");
111 LOG_INFO("See also: ^2ban, banlist, unban^7");
117 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
120 case CMD_REQUEST_COMMAND:
123 entity client = GetFilteredEntity(argv(1));
124 float accepted = VerifyClientEntity(client, true, false);
127 CS(client).muted = true;
130 LOG_INFO("mute: ", GetClientErrorString(accepted, argv(1)), ".");
136 LOG_INFO("Incorrect parameters for ^2mute^7");
137 case CMD_REQUEST_USAGE:
139 LOG_INFO("Usage:^3 sv_cmd mute client");
140 LOG_INFO(" 'client' is the entity number or name of the player to mute.");
141 LOG_INFO("See also: ^2unmute^7");
147 void BanCommand_unban(float request, float argc)
150 case CMD_REQUEST_COMMAND:
153 float tmp_number = -1;
156 if (substring(argv(1), 0, 1) == "#") {
157 tmp_string = substring(argv(1), 1, -1);
159 if (tmp_string != "") { // is it all one token? like #1
160 tmp_number = stof(tmp_string);
161 } else if (argc > 2) { // no, it's two tokens? # 1
162 tmp_number = stof(argv(2));
163 } else { tmp_number = -1; }
164 } else { // maybe it's ONLY a number?
165 tmp_number = stof(argv(1));
167 if ((tmp_number == 0) && (argv(1) != "0")) { tmp_number = -1; } }
169 if (tmp_number >= 0) {
170 Ban_Delete(tmp_number);
177 case CMD_REQUEST_USAGE:
179 LOG_INFO("Usage:^3 sv_cmd unban banid");
180 LOG_INFO(" Where 'banid' is the ID of the ban of which to remove.");
181 LOG_INFO("See also: ^2ban, banlist, kickban^7");
187 void BanCommand_unmute(float request, float argc)
190 case CMD_REQUEST_COMMAND:
193 entity client = GetFilteredEntity(argv(1));
194 float accepted = VerifyClientEntity(client, true, false);
197 CS(client).muted = false;
200 LOG_INFO("unmute: ", GetClientErrorString(accepted, argv(1)), ".");
206 LOG_INFO("Incorrect parameters for ^2mute^7");
207 case CMD_REQUEST_USAGE:
209 LOG_INFO("Usage:^3 sv_cmd unmute client");
210 LOG_INFO(" 'client' is the entity number or name of the player to unmute.");
211 LOG_INFO("See also: ^2mute^7");
217 /* use this when creating a new command, making sure to place it in alphabetical order... also,
218 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
219 void BanCommand_(float request)
223 case CMD_REQUEST_COMMAND:
230 case CMD_REQUEST_USAGE:
232 print("\nUsage:^3 sv_cmd \n");
233 print(" No arguments required.\n");
241 // ==================================
242 // Macro system for server commands
243 // ==================================
245 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
246 #define BAN_COMMANDS(request, arguments, command) \
247 BAN_COMMAND("ban", BanCommand_ban(request, arguments, command), "Ban an IP address or a range of addresses (like 1.2.3)") \
248 BAN_COMMAND("banlist", BanCommand_banlist(request), "List all existing bans") \
249 BAN_COMMAND("kickban", BanCommand_kickban(request, arguments, command), "Disconnect a client and ban it at the same time") \
250 BAN_COMMAND("mute", BanCommand_mute(request, arguments, command), "Disallow a client from talking by muting them") \
251 BAN_COMMAND("unban", BanCommand_unban(request, arguments), "Remove an existing ban") \
252 BAN_COMMAND("unmute", BanCommand_unmute(request, arguments), "Unmute a client") \
255 void BanCommand_macro_help()
257 #define BAN_COMMAND(name, function, description) \
258 { if (strtolower(description) != "") { LOG_INFO(" ^2", name, "^7: ", description); } }
260 BAN_COMMANDS(0, 0, "");
264 float BanCommand_macro_command(float argc, string command)
266 #define BAN_COMMAND(name, function, description) \
267 { if (name == strtolower(argv(0))) { function; return true; } }
269 BAN_COMMANDS(CMD_REQUEST_COMMAND, argc, command);
275 float BanCommand_macro_usage(float argc)
277 #define BAN_COMMAND(name, function, description) \
278 { if (name == strtolower(argv(1))) { function; return true; } }
280 BAN_COMMANDS(CMD_REQUEST_USAGE, argc, "");
286 void BanCommand_macro_write_aliases(float fh)
288 #define BAN_COMMAND(name, function, description) \
289 { if (strtolower(description) != "") { CMD_Write_Alias("qc_cmd_sv", name, description); } }
291 BAN_COMMANDS(0, 0, "");
295 float BanCommand(string command)
297 float argc = tokenize_console(command);
299 // Guide for working with argc arguments by example:
300 // argc: 1 - 2 - 3 - 4
301 // argv: 0 - 1 - 2 - 3
302 // cmd vote - master - login - password
304 if (BanCommand_macro_command(argc, command)) { // continue as usual and scan for normal commands
305 return true; // handled by one of the above GenericCommand_* functions