3 #include <common/command/_mod.qh>
4 #include <common/state.qh>
5 #include <common/stats.qh>
6 #include <common/util.qh>
7 #include <common/weapons/_all.qh>
8 #include <server/command/banning.qh>
9 #include <server/command/common.qh>
10 #include <server/ipban.qh>
11 #include <server/player.qh>
13 // =====================================================
14 // Banning and kicking command code, written by Samual
15 // Last updated: December 29th, 2011
16 // =====================================================
18 void BanCommand_ban(int request, int 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_INFOF("Incorrect parameters for ^2%s^7", argv(0));
42 case CMD_REQUEST_USAGE:
44 LOG_HELP("Usage:^3 sv_cmd ban <address> [<bantime>] [<reason>]");
45 LOG_HELP(" <address> is the IP address or range of the player to ban,");
46 LOG_HELP(" <bantime> is the amount of time that the ban is active (default if not provided),");
47 LOG_HELP(" and <reason> is the string to label the ban with as reason for banning.");
48 LOG_HELP("See also: ^2banlist, kickban, unban^7");
54 void BanCommand_banlist(int request)
58 case CMD_REQUEST_COMMAND:
65 case CMD_REQUEST_USAGE:
67 LOG_HELP("Usage:^3 sv_cmd banlist");
68 LOG_HELP(" No arguments required.");
69 LOG_HELP("See also: ^2ban, kickban, unban^7");
75 void BanCommand_kickban(int request, int 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)), ".");
108 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
109 case CMD_REQUEST_USAGE:
111 LOG_HELP("Usage:^3 sv_cmd kickban <client> [<bantime>] [<masksize>] [<reason>]");
112 LOG_HELP(" <client> is the entity number or name of the player to ban,");
113 LOG_HELP(" <bantime> is the amount of time that the ban is active (default if not provided),");
114 LOG_HELP(" <masksize> is the range of the IP address (1-thru-4, default if not provided),");
115 LOG_HELP(" and <reason> is the string to label the ban with as reason for banning.");
116 LOG_HELP("See also: ^2ban, banlist, unban^7");
122 void BanCommand_mute(int request, int argc, string command)
126 case CMD_REQUEST_COMMAND:
130 entity client = GetIndexedEntity(argc, 1);
131 float accepted = VerifyClientEntity(client, true, false);
136 if(!PlayerInIPList(client, autocvar_g_muteban_list))
137 theid = cons(theid, client.netaddress);
138 if(!PlayerInIDList(client, autocvar_g_muteban_list))
139 theid = cons(theid, client.crypto_idfp);
140 CS(client).muted = true;
141 LOG_INFO(strcat("Mute-banning player ", GetCallerName(client), " (", argv(1), ")."));
142 cvar_set("g_muteban_list", cons(autocvar_g_muteban_list, theid));
148 LOG_INFO("mute: ", GetClientErrorString(accepted, argv(1)), ".");
154 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
155 case CMD_REQUEST_USAGE:
157 LOG_HELP("Usage:^3 sv_cmd mute <client>");
158 LOG_HELP(" <client> is the entity number or name of the player to mute.");
159 LOG_HELP("See also: ^2unmute, g_muteban_list^7");
165 void BanCommand_playban(int request, int argc, string command)
169 case CMD_REQUEST_COMMAND:
173 entity client = GetIndexedEntity(argc, 1);
174 float accepted = VerifyClientEntity(client, true, false);
179 if(!PlayerInIPList(client, autocvar_g_playban_list))
180 theid = cons(theid, client.netaddress);
181 if(!PlayerInIDList(client, autocvar_g_playban_list))
182 theid = cons(theid, client.crypto_idfp);
184 LOG_INFO(strcat("Play-banning player ", GetCallerName(client), " (", argv(1), ")."));
185 PutObserverInServer(client, true, true);
186 cvar_set("g_playban_list", cons(autocvar_g_playban_list, theid));
192 LOG_INFO("playban: ", GetClientErrorString(accepted, argv(1)), ".");
198 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
199 case CMD_REQUEST_USAGE:
201 LOG_HELP("Usage:^3 sv_cmd playban <client>");
202 LOG_HELP(" <client> is the entity number or name of the player to ban being forced to spectate permanently,");
203 LOG_HELP("See also: ^2g_playban_list, unplayban^7");
209 void BanCommand_unban(int request, int argc)
213 case CMD_REQUEST_COMMAND:
217 float tmp_number = -1;
220 if (substring(argv(1), 0, 1) == "#")
222 tmp_string = substring(argv(1), 1, -1);
224 if (tmp_string != "") // is it all one token? like #1
225 tmp_number = stof(tmp_string);
226 else if (argc > 2) // no, it's two tokens? # 1
227 tmp_number = stof(argv(2));
228 else tmp_number = -1;
230 else // maybe it's ONLY a number?
232 tmp_number = stof(argv(1));
234 if ((tmp_number == 0) && (argv(1) != "0")) tmp_number = -1; }
238 Ban_Delete(tmp_number);
245 case CMD_REQUEST_USAGE:
247 LOG_HELP("Usage:^3 sv_cmd unban <banid>");
248 LOG_HELP(" Where <banid> is the ID of the ban of which to remove.");
249 LOG_HELP("See also: ^2ban, banlist, kickban^7");
255 void BanCommand_unmute(int request, int argc)
259 case CMD_REQUEST_COMMAND:
263 entity client = GetIndexedEntity(argc, 1);
264 float accepted = VerifyClientEntity(client, true, false);
265 string original_arg = argv(1);
269 string tmp_string = "";
270 FOREACH_WORD(autocvar_g_muteban_list, it != client.netaddress,
272 if(client.crypto_idfp && it == substring(client.crypto_idfp, 0, strlen(it)))
274 tmp_string = cons(tmp_string, it);
277 cvar_set("g_muteban_list", tmp_string);
278 LOG_INFO(strcat("Unmuting player ", GetCallerName(client), " (", original_arg, ")."));
279 CS(client).muted = false;
285 LOG_INFO("unmute: ", GetClientErrorString(accepted, argv(1)), ".");
291 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
292 case CMD_REQUEST_USAGE:
294 LOG_HELP("Usage:^3 sv_cmd unmute <client>");
295 LOG_HELP(" <client> is the entity number or name of the player to unmute.");
296 LOG_HELP("See also: ^2mute, g_muteban_list^7");
302 void BanCommand_unplayban(int request, int argc)
306 case CMD_REQUEST_COMMAND:
310 entity client = GetIndexedEntity(argc, 1);
311 float accepted = VerifyClientEntity(client, true, false);
312 string original_arg = argv(1);
316 string tmp_string = "";
317 FOREACH_WORD(autocvar_g_playban_list, it != client.netaddress,
319 if(client.crypto_idfp && it == substring(client.crypto_idfp, 0, strlen(it)))
321 tmp_string = cons(tmp_string, it);
324 cvar_set("g_playban_list", tmp_string);
325 LOG_INFO(strcat("Releasing forced to spectate player ", GetCallerName(client), " (", original_arg, ")."));
331 LOG_INFO("unplayban: ", GetClientErrorString(accepted, argv(1)), ".");
337 case CMD_REQUEST_USAGE:
339 LOG_HELP("Usage:^3 sv_cmd unplayban <banid>");
340 LOG_HELP(" Where <banid> is the ID of the forced to spectate ban of which to remove.");
341 LOG_HELP("See also: ^2playban, g_playban_list^7");
347 void BanCommand_unvoteban(int request, int argc)
351 case CMD_REQUEST_COMMAND:
355 entity client = GetIndexedEntity(argc, 1);
356 float accepted = VerifyClientEntity(client, true, false);
357 string original_arg = argv(1);
361 string tmp_string = "";
362 FOREACH_WORD(autocvar_g_voteban_list, it != client.netaddress,
364 if(client.crypto_idfp && it == substring(client.crypto_idfp, 0, strlen(it)))
366 tmp_string = cons(tmp_string, it);
369 cvar_set("g_voteban_list", tmp_string);
370 LOG_INFO(strcat("Unvote-banning player ", GetCallerName(client), " (", original_arg, ")."));
376 LOG_INFO("unvoteban: ", GetClientErrorString(accepted, argv(1)), ".");
382 case CMD_REQUEST_USAGE:
384 LOG_HELP("Usage:^3 sv_cmd unvoteban <banid>");
385 LOG_HELP(" Where <banid> is the ID of the ban from voting of which to remove.");
386 LOG_HELP("See also: ^2voteban, g_voteban_list^7");
392 void BanCommand_voteban(int request, int argc, string command)
396 case CMD_REQUEST_COMMAND:
400 entity client = GetIndexedEntity(argc, 1);
401 float accepted = VerifyClientEntity(client, true, false);
406 if(!PlayerInIPList(client, autocvar_g_voteban_list))
407 theid = cons(theid, client.netaddress);
408 if(!PlayerInIDList(client, autocvar_g_voteban_list))
409 theid = cons(theid, client.crypto_idfp);
411 LOG_INFO(strcat("Vote-banning player ", GetCallerName(client), " (", argv(1), ")."));
412 cvar_set("g_voteban_list", cons(autocvar_g_voteban_list, theid));
418 LOG_INFO("voteban: ", GetClientErrorString(accepted, argv(1)), ".");
424 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
425 case CMD_REQUEST_USAGE:
427 LOG_HELP("Usage:^3 sv_cmd voteban <client>");
428 LOG_HELP(" <client> is the entity number or name of the player to ban from voting,");
429 LOG_HELP("See also: ^2g_voteban_list, unvoteban^7");
435 /* use this when creating a new command, making sure to place it in alphabetical order... also,
436 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
437 void BanCommand_(int request)
441 case CMD_REQUEST_COMMAND:
448 case CMD_REQUEST_USAGE:
450 LOG_HELP("Usage:^3 sv_cmd ");
451 LOG_HELP(" No arguments required.");
459 // ==================================
460 // Macro system for server commands
461 // ==================================
463 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
464 #define BAN_COMMANDS(request, arguments, command) \
465 BAN_COMMAND("ban", BanCommand_ban(request, arguments, command), "Ban an IP address or a range of addresses (like 1.2.3)") \
466 BAN_COMMAND("banlist", BanCommand_banlist(request), "List all existing bans") \
467 BAN_COMMAND("kickban", BanCommand_kickban(request, arguments, command), "Disconnect a client and ban it at the same time") \
468 BAN_COMMAND("mute", BanCommand_mute(request, arguments, command), "Disallow a client from talking by muting them") \
469 BAN_COMMAND("playban", BanCommand_playban(request, arguments, command), "Force to spectate a client permanently") \
470 BAN_COMMAND("unban", BanCommand_unban(request, arguments), "Remove an existing ban") \
471 BAN_COMMAND("unmute", BanCommand_unmute(request, arguments), "Unmute a client") \
472 BAN_COMMAND("unvoteban", BanCommand_unvoteban(request, arguments), "Remove an existing voting ban") \
473 BAN_COMMAND("unplayban", BanCommand_unplayban(request, arguments), "Remove an existing forced to spectate ban") \
474 BAN_COMMAND("voteban", BanCommand_voteban(request, arguments, command), "Disallow a client from voting") \
477 void BanCommand_macro_help()
479 #define BAN_COMMAND(name, function, description) \
480 { if (strtolower(description) != "") { LOG_INFO(" ^2", name, "^7: ", description); } }
482 BAN_COMMANDS(0, 0, "");
486 float BanCommand_macro_command(int argc, string command)
488 #define BAN_COMMAND(name, function, description) \
489 { if (name == strtolower(argv(0))) { function; return true; } }
491 BAN_COMMANDS(CMD_REQUEST_COMMAND, argc, command);
497 float BanCommand_macro_usage(int argc)
499 #define BAN_COMMAND(name, function, description) \
500 { if (name == strtolower(argv(1))) { function; return true; } }
502 BAN_COMMANDS(CMD_REQUEST_USAGE, argc, "");
508 void BanCommand_macro_write_aliases(float fh)
510 #define BAN_COMMAND(name, function, description) \
511 { if (strtolower(description) != "") { CMD_Write_Alias("qc_cmd_sv", name, description); } }
513 BAN_COMMANDS(0, 0, "");
517 float BanCommand(string command)
519 int argc = tokenize_console(command);
521 // Guide for working with argc arguments by example:
522 // argc: 1 - 2 - 3 - 4
523 // argv: 0 - 1 - 2 - 3
524 // cmd vote - master - login - password
526 if (BanCommand_macro_command(argc, command)) // continue as usual and scan for normal commands
527 return true; // handled by one of the above GenericCommand_* functions