3 * =============================================================================
4 * SourceMod Basecommands
5 * Functionality related to banning.
7 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
8 * =============================================================================
10 * This program is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License, version 3.0, as published by the
12 * Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
22 * As a special exception, AlliedModders LLC gives you permission to link the
23 * code of this program (as well as its derivative works) to "Half-Life 2," the
24 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
25 * by the Valve Corporation. You must obey the GNU General Public License in
26 * all respects for all other code used. Additionally, AlliedModders LLC grants
27 * this exception to all derivative works. AlliedModders LLC defines further
28 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
29 * or <http://www.sourcemod.net/license.php>.
34 PrepareBan(client, target, time, const String:reason[])
36 new originalTarget = GetClientOfUserId(g_BanTargetUserId[client]);
38 if (originalTarget != target)
42 PrintToServer("[SM] %t", "Player no longer available");
46 PrintToChat(client, "[SM] %t", "Player no longer available");
53 GetClientName(target, name, sizeof(name));
57 if (reason[0] == '\0')
59 ShowActivity(client, "%t", "Permabanned player", name);
61 ShowActivity(client, "%t", "Permabanned player reason", name, reason);
64 if (reason[0] == '\0')
66 ShowActivity(client, "%t", "Banned player", name, time);
68 ShowActivity(client, "%t", "Banned player reason", name, time, reason);
72 LogAction(client, target, "\"%L\" banned \"%L\" (minutes \"%d\") (reason \"%s\")", client, target, time, reason);
74 if (reason[0] == '\0')
76 BanClient(target, time, BANFLAG_AUTO, "Banned", "Banned", "sm_ban", client);
80 BanClient(target, time, BANFLAG_AUTO, reason, reason, "sm_ban", client);
84 DisplayBanTargetMenu(client)
86 new Handle:menu = CreateMenu(MenuHandler_BanPlayerList);
88 decl String:title[100];
89 Format(title, sizeof(title), "%T:", "Ban player", client);
90 SetMenuTitle(menu, title);
91 SetMenuExitBackButton(menu, true);
93 AddTargetsToMenu2(menu, client, COMMAND_FILTER_NO_BOTS|COMMAND_FILTER_CONNECTED);
95 DisplayMenu(menu, client, MENU_TIME_FOREVER);
98 DisplayBanTimeMenu(client)
100 new Handle:menu = CreateMenu(MenuHandler_BanTimeList);
102 decl String:title[100];
103 Format(title, sizeof(title), "%T: %N", "Ban player", client, g_BanTarget[client]);
104 SetMenuTitle(menu, title);
105 SetMenuExitBackButton(menu, true);
107 AddMenuItem(menu, "0", "Permanent");
108 AddMenuItem(menu, "10", "10 Minutes");
109 AddMenuItem(menu, "30", "30 Minutes");
110 AddMenuItem(menu, "60", "1 Hour");
111 AddMenuItem(menu, "240", "4 Hours");
112 AddMenuItem(menu, "1440", "1 Day");
113 AddMenuItem(menu, "10080", "1 Week");
115 DisplayMenu(menu, client, MENU_TIME_FOREVER);
118 DisplayBanReasonMenu(client)
120 new Handle:menu = CreateMenu(MenuHandler_BanReasonList);
122 decl String:title[100];
123 Format(title, sizeof(title), "%T: %N", "Ban reason", client, g_BanTarget[client]);
124 SetMenuTitle(menu, title);
125 SetMenuExitBackButton(menu, true);
127 /* :TODO: we should either remove this or make it configurable */
129 AddMenuItem(menu, "Abusive", "Abusive");
130 AddMenuItem(menu, "Racism", "Racism");
131 AddMenuItem(menu, "General cheating/exploits", "General cheating/exploits");
132 AddMenuItem(menu, "Wallhack", "Wallhack");
133 AddMenuItem(menu, "Aimbot", "Aimbot");
134 AddMenuItem(menu, "Speedhacking", "Speedhacking");
135 AddMenuItem(menu, "Mic spamming", "Mic spamming");
136 AddMenuItem(menu, "Admin disrespect", "Admin disrespect");
137 AddMenuItem(menu, "Camping", "Camping");
138 AddMenuItem(menu, "Team killing", "Team killing");
139 AddMenuItem(menu, "Unacceptable Spray", "Unacceptable Spray");
140 AddMenuItem(menu, "Breaking Server Rules", "Breaking Server Rules");
141 AddMenuItem(menu, "Other", "Other");
143 DisplayMenu(menu, client, MENU_TIME_FOREVER);
146 public AdminMenu_Ban(Handle:topmenu,
147 TopMenuAction:action,
148 TopMenuObject:object_id,
153 if (action == TopMenuAction_DisplayOption)
155 Format(buffer, maxlength, "%T", "Ban player", param);
157 else if (action == TopMenuAction_SelectOption)
159 DisplayBanTargetMenu(param);
163 public MenuHandler_BanReasonList(Handle:menu, MenuAction:action, param1, param2)
165 if (action == MenuAction_End)
169 else if (action == MenuAction_Cancel)
171 if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
173 DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
176 else if (action == MenuAction_Select)
178 decl String:info[64];
180 GetMenuItem(menu, param2, info, sizeof(info));
182 PrepareBan(param1, g_BanTarget[param1], g_BanTime[param1], info);
186 public MenuHandler_BanPlayerList(Handle:menu, MenuAction:action, param1, param2)
188 if (action == MenuAction_End)
192 else if (action == MenuAction_Cancel)
194 if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
196 DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
199 else if (action == MenuAction_Select)
201 decl String:info[32], String:name[32];
204 GetMenuItem(menu, param2, info, sizeof(info), _, name, sizeof(name));
205 userid = StringToInt(info);
207 if ((target = GetClientOfUserId(userid)) == 0)
209 PrintToChat(param1, "[SM] %t", "Player no longer available");
211 else if (!CanUserTarget(param1, target))
213 PrintToChat(param1, "[SM] %t", "Unable to target");
217 g_BanTarget[param1] = target;
218 g_BanTargetUserId[param1] = userid;
219 DisplayBanTimeMenu(param1);
224 public MenuHandler_BanTimeList(Handle:menu, MenuAction:action, param1, param2)
226 if (action == MenuAction_End)
230 else if (action == MenuAction_Cancel)
232 if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
234 DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
237 else if (action == MenuAction_Select)
239 decl String:info[32];
241 GetMenuItem(menu, param2, info, sizeof(info));
242 g_BanTime[param1] = StringToInt(info);
244 DisplayBanReasonMenu(param1);
249 public Action:Command_Ban(client, args)
253 ReplyToCommand(client, "[SM] Usage: sm_ban <#userid|name> <minutes|0> [reason]");
254 return Plugin_Handled;
258 decl String:Arguments[256];
259 GetCmdArgString(Arguments, sizeof(Arguments));
262 len = BreakString(Arguments, arg, sizeof(arg));
264 new target = FindTarget(client, arg, true);
267 return Plugin_Handled;
270 decl String:s_time[12];
271 if ((next_len = BreakString(Arguments[len], s_time, sizeof(s_time))) != -1)
281 new time = StringToInt(s_time);
283 g_BanTargetUserId[client] = GetClientUserId(target);
285 PrepareBan(client, target, time, Arguments[len]);
287 return Plugin_Handled;