2 #include <common/state.qh>
3 #include <common/command/_mod.qh>
8 #include "../player.qh"
11 #include <common/util.qh>
13 // =====================================================
14 // Banning and kicking command code, written by Samual
15 // Last updated: December 29th, 2011
16 // =====================================================
18 void BanCommand_ban(float request, float argc, string command)
22 case CMD_REQUEST_COMMAND:
27 float reason_arg, bantime;
32 GET_BAN_ARG(bantime, autocvar_g_ban_default_bantime);
33 GET_BAN_REASON(reason, "No reason provided");
35 Ban_Insert(ip, bantime, reason, 1);
41 LOG_INFO("Incorrect parameters for ^2ban^7\n");
42 case CMD_REQUEST_USAGE:
44 LOG_INFO("\nUsage:^3 sv_cmd ban address [bantime] [reason]\n");
45 LOG_INFO(" 'address' is the IP address or range of the player to ban,\n");
46 LOG_INFO(" 'bantime' is the amount of time that the ban is active (default if not provided),\n");
47 LOG_INFO(" and 'reason' is the string to label the ban with as reason for banning.\n");
48 LOG_INFO("See also: ^2banlist, kickban, unban^7\n");
54 void BanCommand_banlist(float request)
58 case CMD_REQUEST_COMMAND:
65 case CMD_REQUEST_USAGE:
67 LOG_INFO("\nUsage:^3 sv_cmd banlist\n");
68 LOG_INFO(" No arguments required.\n");
69 LOG_INFO("See also: ^2ban, kickban, unban^7\n");
75 void BanCommand_kickban(float request, float argc, string command)
79 case CMD_REQUEST_COMMAND:
83 entity client = GetIndexedEntity(argc, 1);
84 float accepted = VerifyKickableEntity(client);
85 float reason_arg, bantime, masksize;
90 reason_arg = next_token;
92 GET_BAN_ARG(bantime, autocvar_g_ban_default_bantime);
93 GET_BAN_ARG(masksize, autocvar_g_ban_default_masksize);
94 GET_BAN_REASON(reason, "No reason provided");
96 Ban_KickBanClient(client, bantime, masksize, reason);
102 LOG_INFO("kickban: ", GetClientErrorString(accepted, argv(1)), ".\n");
108 LOG_INFO("Incorrect parameters for ^2kickban^7\n");
109 case CMD_REQUEST_USAGE:
111 LOG_INFO("\nUsage:^3 sv_cmd kickban client [bantime] [masksize] [reason]\n");
112 LOG_INFO(" 'client' is the entity number or name of the player to ban,\n");
113 LOG_INFO(" 'bantime' is the amount of time that the ban is active (default if not provided),\n");
114 LOG_INFO(" 'masksize' is the range of the IP address (1-thru-4, default if not provided),\n");
115 LOG_INFO(" and 'reason' is the string to label the ban with as reason for banning.\n");
116 LOG_INFO("See also: ^2ban, banlist, unban^7\n");
122 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
126 case CMD_REQUEST_COMMAND:
130 entity client = GetFilteredEntity(argv(1));
131 float accepted = VerifyClientEntity(client, true, false);
135 CS(client).muted = true;
140 LOG_INFO("mute: ", GetClientErrorString(accepted, argv(1)), ".\n");
146 LOG_INFO("Incorrect parameters for ^2mute^7\n");
147 case CMD_REQUEST_USAGE:
149 LOG_INFO("\nUsage:^3 sv_cmd mute client\n");
150 LOG_INFO(" 'client' is the entity number or name of the player to mute.\n");
151 LOG_INFO("See also: ^2unmute^7\n");
157 void BanCommand_unban(float request, float argc)
161 case CMD_REQUEST_COMMAND:
165 float tmp_number = -1;
168 if (substring(argv(1), 0, 1) == "#")
170 tmp_string = substring(argv(1), 1, -1);
172 if (tmp_string != "") // is it all one token? like #1
173 tmp_number = stof(tmp_string);
174 else if (argc > 2) // no, it's two tokens? # 1
175 tmp_number = stof(argv(2));
176 else tmp_number = -1;
178 else // maybe it's ONLY a number?
180 tmp_number = stof(argv(1));
182 if ((tmp_number == 0) && (argv(1) != "0")) tmp_number = -1; }
186 Ban_Delete(tmp_number);
193 case CMD_REQUEST_USAGE:
195 LOG_INFO("\nUsage:^3 sv_cmd unban banid\n");
196 LOG_INFO(" Where 'banid' is the ID of the ban of which to remove.\n");
197 LOG_INFO("See also: ^2ban, banlist, kickban^7\n");
203 void BanCommand_unmute(float request, float argc)
207 case CMD_REQUEST_COMMAND:
211 entity client = GetFilteredEntity(argv(1));
212 float accepted = VerifyClientEntity(client, true, false);
216 CS(client).muted = false;
221 LOG_INFO("unmute: ", GetClientErrorString(accepted, argv(1)), ".\n");
227 LOG_INFO("Incorrect parameters for ^2mute^7\n");
228 case CMD_REQUEST_USAGE:
230 LOG_INFO("\nUsage:^3 sv_cmd unmute client\n");
231 LOG_INFO(" 'client' is the entity number or name of the player to unmute.\n");
232 LOG_INFO("See also: ^2mute^7\n");
238 /* use this when creating a new command, making sure to place it in alphabetical order... also,
239 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
240 void BanCommand_(float request)
244 case CMD_REQUEST_COMMAND:
251 case CMD_REQUEST_USAGE:
253 print("\nUsage:^3 sv_cmd \n");
254 print(" No arguments required.\n");
262 // ==================================
263 // Macro system for server commands
264 // ==================================
266 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
267 #define BAN_COMMANDS(request, arguments, command) \
268 BAN_COMMAND("ban", BanCommand_ban(request, arguments, command), "Ban an IP address or a range of addresses (like 1.2.3)") \
269 BAN_COMMAND("banlist", BanCommand_banlist(request), "List all existing bans") \
270 BAN_COMMAND("kickban", BanCommand_kickban(request, arguments, command), "Disconnect a client and ban it at the same time") \
271 BAN_COMMAND("mute", BanCommand_mute(request, arguments, command), "Disallow a client from talking by muting them") \
272 BAN_COMMAND("unban", BanCommand_unban(request, arguments), "Remove an existing ban") \
273 BAN_COMMAND("unmute", BanCommand_unmute(request, arguments), "Unmute a client") \
276 void BanCommand_macro_help()
278 #define BAN_COMMAND(name, function, description) \
279 { if (strtolower(description) != "") { LOG_INFO(" ^2", name, "^7: ", description, "\n"); } }
281 BAN_COMMANDS(0, 0, "");
285 float BanCommand_macro_command(float argc, string command)
287 #define BAN_COMMAND(name, function, description) \
288 { if (name == strtolower(argv(0))) { function; return true; } }
290 BAN_COMMANDS(CMD_REQUEST_COMMAND, argc, command);
296 float BanCommand_macro_usage(float argc)
298 #define BAN_COMMAND(name, function, description) \
299 { if (name == strtolower(argv(1))) { function; return true; } }
301 BAN_COMMANDS(CMD_REQUEST_USAGE, argc, "");
307 void BanCommand_macro_write_aliases(float fh)
309 #define BAN_COMMAND(name, function, description) \
310 { if (strtolower(description) != "") { CMD_Write_Alias("qc_cmd_sv", name, description); } }
312 BAN_COMMANDS(0, 0, "");
316 float BanCommand(string command)
318 float argc = tokenize_console(command);
320 // Guide for working with argc arguments by example:
321 // argc: 1 - 2 - 3 - 4
322 // argv: 0 - 1 - 2 - 3
323 // cmd vote - master - login - password
325 if (BanCommand_macro_command(argc, command)) // continue as usual and scan for normal commands
326 return true; // handled by one of the above GenericCommand_* functions