1 // =====================================================
2 // Banning and kicking command code, written by Samual
3 // Last updated: December 29th, 2011
4 // =====================================================
6 void BanCommand_ban(float request, float argc, string command)
10 case CMD_REQUEST_COMMAND:
15 float reason_arg, bantime;
20 GET_BAN_ARG(bantime, autocvar_g_ban_default_bantime);
21 GET_BAN_REASON(reason, "No reason provided");
23 Ban_Insert(ip, bantime, reason, 1);
29 print("Incorrect parameters for ^2ban^7\n");
30 case CMD_REQUEST_USAGE:
32 print("\nUsage:^3 sv_cmd ban address [bantime] [reason]\n");
33 print(" 'address' is the IP address or range of the player to ban,\n");
34 print(" 'bantime' is the amount of time that the ban is active (default if not provided),\n");
35 print(" and 'reason' is the string to label the ban with as reason for banning.\n");
36 print("See also: ^2banlist, kickban, unban^7\n");
42 void BanCommand_banlist(float request)
46 case CMD_REQUEST_COMMAND:
53 case CMD_REQUEST_USAGE:
55 print("\nUsage:^3 sv_cmd banlist\n");
56 print(" No arguments required.\n");
57 print("See also: ^2ban, kickban, unban^7\n");
63 void BanCommand_kickban(float request, float argc, string command)
67 case CMD_REQUEST_COMMAND:
71 entity client = GetIndexedEntity(argc, 1);
72 float accepted = VerifyClientEntity(client, TRUE, FALSE);
73 float reason_arg, bantime, masksize;
78 reason_arg = next_token;
80 GET_BAN_ARG(bantime, autocvar_g_ban_default_bantime);
81 GET_BAN_ARG(masksize, autocvar_g_ban_default_masksize);
82 GET_BAN_REASON(reason, "No reason provided");
84 Ban_KickBanClient(client, bantime, masksize, reason);
90 print("kickban: ", GetClientErrorString(accepted, argv(1)), ".\n");
96 print("Incorrect parameters for ^2kickban^7\n");
97 case CMD_REQUEST_USAGE:
99 print("\nUsage:^3 sv_cmd kickban client [bantime] [masksize] [reason]\n");
100 print(" 'client' is the entity number or name of the player to ban,\n");
101 print(" 'bantime' is the amount of time that the ban is active (default if not provided),\n");
102 print(" 'masksize' is the range of the IP address (1-thru-4, default if not provided),\n");
103 print(" and 'reason' is the string to label the ban with as reason for banning.\n");
104 print("See also: ^2ban, banlist, unban^7\n");
110 void BanCommand_unban(float request, float argc)
114 case CMD_REQUEST_COMMAND:
118 float tmp_number = -1;
121 if(substring(argv(1), 0, 1) == "#")
123 tmp_string = substring(argv(1), 1, -1);
125 if(tmp_string != "") // is it all one token? like #1
127 tmp_number = stof(tmp_string);
129 else if(argc > 2) // no, it's two tokens? # 1
131 tmp_number = stof(argv(2));
136 else // maybe it's ONLY a number?
138 tmp_number = stof(argv(1));
140 if((tmp_number == 0) && (argv(1) != "0"))
146 Ban_Delete(tmp_number);
153 case CMD_REQUEST_USAGE:
155 print("\nUsage:^3 sv_cmd unban banid\n");
156 print(" Where 'banid' is the ID of the ban of which to remove.\n");
157 print("See also: ^2ban, banlist, kickban^7\n");
163 /* use this when creating a new command, making sure to place it in alphabetical order... also,
164 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
165 void BanCommand_(float request)
169 case CMD_REQUEST_COMMAND:
176 case CMD_REQUEST_USAGE:
178 print("\nUsage:^3 sv_cmd \n");
179 print(" No arguments required.\n");
187 // ==================================
188 // Macro system for server commands
189 // ==================================
191 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
192 // but for 0.5 compat, we need "bans" here as it was replaced... REMOVE IT AFTER 0.6 RELEASE!!!!
193 #define BAN_COMMANDS(request,arguments,command) \
194 BAN_COMMAND("ban", BanCommand_ban(request, arguments, command), "Ban an IP address or a range of addresses (like 1.2.3)") \
195 BAN_COMMAND("banlist", BanCommand_banlist(request), "List all existing bans") \
196 BAN_COMMAND("bans", BanCommand_banlist(request), "") \
197 BAN_COMMAND("kickban", BanCommand_kickban(request, arguments, command), "Disconnect a client and ban it at the same time") \
198 BAN_COMMAND("unban", BanCommand_unban(request, arguments), "Remove an existing ban") \
201 void BanCommand_macro_help()
203 #define BAN_COMMAND(name,function,description) \
204 { if(strtolower(description) != "") { print(" ^2", name, "^7: ", description, "\n"); } }
206 BAN_COMMANDS(0, 0, "")
212 float BanCommand_macro_command(float argc, string command)
214 #define BAN_COMMAND(name,function,description) \
215 { if(name == strtolower(argv(0))) { function; return TRUE; } }
217 BAN_COMMANDS(CMD_REQUEST_COMMAND, argc, command)
223 float BanCommand_macro_usage(float argc)
225 #define BAN_COMMAND(name,function,description) \
226 { if(name == strtolower(argv(1))) { function; return TRUE; } }
228 BAN_COMMANDS(CMD_REQUEST_USAGE, argc, "")
234 void BanCommand_macro_write_aliases(float fh)
236 #define BAN_COMMAND(name,function,description) \
237 { if(strtolower(description) != "") { CMD_Write_Alias("qc_cmd_sv", name, description); } }
239 BAN_COMMANDS(0, 0, "")
245 float BanCommand(string command)
247 float argc = tokenize_console(command);
249 // Guide for working with argc arguments by example:
250 // argc: 1 - 2 - 3 - 4
251 // argv: 0 - 1 - 2 - 3
252 // cmd vote - master - login - password
254 if(BanCommand_macro_command(argc, command)) // continue as usual and scan for normal commands
256 return TRUE; // handled by one of the above GenericCommand_* functions