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");
52 decl String:authid[64], String:name[32];
53 GetClientAuthString(target, authid, sizeof(authid));
54 GetClientName(target, name, sizeof(name));
58 if (reason[0] == '\0')
60 ShowActivity(client, "%t", "Permabanned player", name);
62 ShowActivity(client, "%t", "Permabanned player reason", name, reason);
65 if (reason[0] == '\0')
67 ShowActivity(client, "%t", "Banned player", name, time);
69 ShowActivity(client, "%t", "Banned player reason", name, time, reason);
73 LogAction(client, target, "\"%L\" banned \"%L\" (minutes \"%d\") (reason \"%s\")", client, target, time, reason);
75 if (reason[0] == '\0')
77 BanClient(target, time, BANFLAG_AUTO, "Banned", "Banned", "sm_ban", client);
81 BanClient(target, time, BANFLAG_AUTO, reason, reason, "sm_ban", client);
85 DisplayBanTargetMenu(client)
87 new Handle:menu = CreateMenu(MenuHandler_BanPlayerList);
89 decl String:title[100];
90 Format(title, sizeof(title), "%T:", "Ban player", client);
91 SetMenuTitle(menu, title);
92 SetMenuExitBackButton(menu, true);
94 AddTargetsToMenu2(menu, client, COMMAND_FILTER_NO_BOTS|COMMAND_FILTER_CONNECTED);
96 DisplayMenu(menu, client, MENU_TIME_FOREVER);
99 DisplayBanTimeMenu(client)
101 new Handle:menu = CreateMenu(MenuHandler_BanTimeList);
103 decl String:title[100];
104 Format(title, sizeof(title), "%T: %N", "Ban player", client, g_BanTarget[client]);
105 SetMenuTitle(menu, title);
106 SetMenuExitBackButton(menu, true);
108 AddMenuItem(menu, "0", "Permanent");
109 AddMenuItem(menu, "10", "10 Minutes");
110 AddMenuItem(menu, "30", "30 Minutes");
111 AddMenuItem(menu, "60", "1 Hour");
112 AddMenuItem(menu, "240", "4 Hours");
113 AddMenuItem(menu, "1440", "1 Day");
114 AddMenuItem(menu, "10080", "1 Week");
116 DisplayMenu(menu, client, MENU_TIME_FOREVER);
119 DisplayBanReasonMenu(client)
121 new Handle:menu = CreateMenu(MenuHandler_BanReasonList);
123 decl String:title[100];
124 Format(title, sizeof(title), "%T: %N", "Ban reason", client, g_BanTarget[client]);
125 SetMenuTitle(menu, title);
126 SetMenuExitBackButton(menu, true);
128 /* :TODO: we should either remove this or make it configurable */
130 AddMenuItem(menu, "Abusive", "Abusive");
131 AddMenuItem(menu, "Racism", "Racism");
132 AddMenuItem(menu, "General cheating/exploits", "General cheating/exploits");
133 AddMenuItem(menu, "Wallhack", "Wallhack");
134 AddMenuItem(menu, "Aimbot", "Aimbot");
135 AddMenuItem(menu, "Speedhacking", "Speedhacking");
136 AddMenuItem(menu, "Mic spamming", "Mic spamming");
137 AddMenuItem(menu, "Admin disrepect", "Admin disrepect");
138 AddMenuItem(menu, "Camping", "Camping");
139 AddMenuItem(menu, "Team killing", "Team killing");
140 AddMenuItem(menu, "Unacceptable Spray", "Unacceptable Spray");
141 AddMenuItem(menu, "Breaking Server Rules", "Breaking Server Rules");
142 AddMenuItem(menu, "Other", "Other");
144 DisplayMenu(menu, client, MENU_TIME_FOREVER);
147 public AdminMenu_Ban(Handle:topmenu,
148 TopMenuAction:action,
149 TopMenuObject:object_id,
154 if (action == TopMenuAction_DisplayOption)
156 Format(buffer, maxlength, "%T", "Ban player", param);
158 else if (action == TopMenuAction_SelectOption)
160 DisplayBanTargetMenu(param);
164 public MenuHandler_BanReasonList(Handle:menu, MenuAction:action, param1, param2)
166 if (action == MenuAction_End)
170 else if (action == MenuAction_Cancel)
172 if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
174 DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
177 else if (action == MenuAction_Select)
179 decl String:info[64];
181 GetMenuItem(menu, param2, info, sizeof(info));
183 PrepareBan(param1, g_BanTarget[param1], g_BanTime[param1], info);
187 public MenuHandler_BanPlayerList(Handle:menu, MenuAction:action, param1, param2)
189 if (action == MenuAction_End)
193 else if (action == MenuAction_Cancel)
195 if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
197 DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
200 else if (action == MenuAction_Select)
202 decl String:info[32], String:name[32];
205 GetMenuItem(menu, param2, info, sizeof(info), _, name, sizeof(name));
206 userid = StringToInt(info);
208 if ((target = GetClientOfUserId(userid)) == 0)
210 PrintToChat(param1, "[SM] %t", "Player no longer available");
212 else if (!CanUserTarget(param1, target))
214 PrintToChat(param1, "[SM] %t", "Unable to target");
218 g_BanTarget[param1] = target;
219 g_BanTargetUserId[param1] = userid;
220 DisplayBanTimeMenu(param1);
225 public MenuHandler_BanTimeList(Handle:menu, MenuAction:action, param1, param2)
227 if (action == MenuAction_End)
231 else if (action == MenuAction_Cancel)
233 if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
235 DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
238 else if (action == MenuAction_Select)
240 decl String:info[32];
242 GetMenuItem(menu, param2, info, sizeof(info));
243 g_BanTime[param1] = StringToInt(info);
245 DisplayBanReasonMenu(param1);
250 public Action:Command_Ban(client, args)
254 ReplyToCommand(client, "[SM] Usage: sm_ban <#userid|name> <minutes|0> [reason]");
255 return Plugin_Handled;
259 decl String:Arguments[256];
260 GetCmdArgString(Arguments, sizeof(Arguments));
263 len = BreakString(Arguments, arg, sizeof(arg));
265 new target = FindTarget(client, arg, true);
268 return Plugin_Handled;
271 decl String:s_time[12];
272 if ((next_len = BreakString(Arguments[len], s_time, sizeof(s_time))) != -1)
282 new time = StringToInt(s_time);
284 g_BanTargetUserId[client] = GetClientUserId(target);
286 PrepareBan(client, target, time, Arguments[len]);
288 return Plugin_Handled;