3 * =============================================================================
4 * SourceMod Basic Commands Plugin
5 * Implements basic admin commands.
7 * SourceMod (C)2004-2007 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>.
40 public Plugin:myinfo =
42 name = "Basic Ban Commands",
43 author = "AlliedModders LLC",
44 description = "Basic Banning Commands",
45 version = SOURCEMOD_VERSION,
46 url = "http://www.sourcemod.net/"
49 new Handle:hTopMenu = INVALID_HANDLE;
51 new g_BanTarget[MAXPLAYERS+1];
52 new g_BanTime[MAXPLAYERS+1];
54 #include "basebans/ban.sp"
56 public OnPluginStart()
58 LoadTranslations("common.phrases");
59 LoadTranslations("basebans.phrases");
61 RegAdminCmd("sm_ban", Command_Ban, ADMFLAG_BAN, "sm_ban <#userid|name> <minutes|0> [reason]");
62 RegAdminCmd("sm_unban", Command_Unban, ADMFLAG_UNBAN, "sm_unban <steamid>");
63 RegAdminCmd("sm_addban", Command_AddBan, ADMFLAG_RCON, "sm_addban <time> <steamid> [reason]");
64 RegAdminCmd("sm_banip", Command_BanIp, ADMFLAG_BAN, "sm_banip <time> <ip|#userid|name> [reason]");
66 /* Account for late loading */
68 if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
70 OnAdminMenuReady(topmenu);
74 public OnAdminMenuReady(Handle:topmenu)
76 /* Block us from being called twice */
77 if (topmenu == hTopMenu)
85 /* Find the "Player Commands" category */
86 new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
88 if (player_commands != INVALID_TOPMENUOBJECT)
90 AddToTopMenu(hTopMenu,
101 public Action:Command_BanIp(client, args)
105 ReplyToCommand(client, "[SM] Usage: sm_banip <time> <ip|#userid|name> [reason]");
106 return Plugin_Handled;
110 decl String:Arguments[256];
111 decl String:arg[50], String:time[20];
113 GetCmdArgString(Arguments, sizeof(Arguments));
114 len = BreakString(Arguments, arg, sizeof(arg));
116 if ((next_len = BreakString(Arguments[len], time, sizeof(time))) != -1)
126 if (StrEqual(arg, "0"))
128 ReplyToCommand(client, "[SM] %t", "Cannot ban that IP");
129 return Plugin_Handled;
132 decl String:target_name[MAX_TARGET_LENGTH];
133 decl target_list[1], bool:tn_is_ml;
134 new found_client = -1;
136 if (ProcessTargetString(
141 COMMAND_FILTER_CONNECTED|COMMAND_FILTER_NO_MULTI,
146 found_client = target_list[0];
151 if (client == 0 || (client == 1 && !IsDedicatedServer()))
157 new AdminId:id = GetUserAdmin(client);
158 has_rcon = (id == INVALID_ADMIN_ID) ? false : GetAdminFlag(id, Admin_RCON);
162 if (found_client != -1
163 && !IsFakeClient(found_client)
164 && (has_rcon || CanUserTarget(client, found_client)))
166 GetClientIP(found_client, arg, sizeof(arg));
167 hit_client = found_client;
170 if (hit_client == -1 && !has_rcon)
172 ReplyToCommand(client, "[SM] %t", "No Access");
173 return Plugin_Handled;
176 new minutes = StringToInt(time);
180 "\"%L\" added ban (minutes \"%d\") (ip \"%s\") (reason \"%s\")",
186 ReplyToCommand(client, "[SM] %t", "Ban added");
195 if (hit_client != -1)
197 KickClient(hit_client, "Banned: %s", Arguments[len]);
200 return Plugin_Handled;
203 public Action:Command_AddBan(client, args)
207 ReplyToCommand(client, "[SM] Usage: sm_addban <time> <steamid> [reason]");
208 return Plugin_Handled;
211 decl String:arg_string[256];
212 new String:reason[128];
214 new String:authid[50];
216 GetCmdArgString(arg_string, sizeof(arg_string));
221 if ((len = BreakString(arg_string, time, sizeof(time))) == -1)
223 ReplyToCommand(client, "t[SM] Usage: sm_addban <time> <steamid> [reason]");
224 return Plugin_Handled;
229 if ((len = BreakString(arg_string[total_len], authid, sizeof(authid))) != -1)
233 BreakString(arg_string[total_len], reason, sizeof(reason));
237 if (strncmp(authid, "STEAM_0:", 8) != 0)
239 ReplyToCommand(client, "[SM] %t", "Invalid SteamID specified");
240 return Plugin_Handled;
243 new minutes = StringToInt(time);
247 "\"%L\" added ban (minutes \"%d\") (id \"%s\") (reason \"%s\")",
259 ReplyToCommand(client, "[SM] %t", "Ban added");
261 return Plugin_Handled;
264 public Action:Command_Unban(client, args)
268 ReplyToCommand(client, "[SM] Usage: sm_unban <steamid|ip>");
269 return Plugin_Handled;
273 GetCmdArgString(arg, sizeof(arg));
275 ReplaceString(arg, sizeof(arg), "\"", "");
278 if (strncmp(arg, "STEAM_0:", 8) == 0)
280 ban_flags |= BANFLAG_AUTHID;
284 ban_flags |= BANFLAG_IP;
287 LogAction(client, -1, "\"%L\" removed ban (filter \"%s\")", client, arg);
288 RemoveBan(arg, ban_flags, "sm_unban", client);
290 ReplyToCommand(client, "[SM] %t", "Removed bans matching", arg);
292 return Plugin_Handled;