Triggering build.
3 * =============================================================================
4 * SourceMod Basic Commands Plugin
5 * Implements basic admin commands.
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>.
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_BanTargetUserId[MAXPLAYERS+1];
53 new g_BanTime[MAXPLAYERS+1];
55 #include "basebans/ban.sp"
57 public OnPluginStart()
59 LoadTranslations("common.phrases");
60 LoadTranslations("basebans.phrases");
62 RegAdminCmd("sm_ban", Command_Ban, ADMFLAG_BAN, "sm_ban <#userid|name> <minutes|0> [reason]");
63 RegAdminCmd("sm_unban", Command_Unban, ADMFLAG_UNBAN, "sm_unban <steamid|ip>");
64 RegAdminCmd("sm_addban", Command_AddBan, ADMFLAG_RCON, "sm_addban <time> <steamid> [reason]");
65 RegAdminCmd("sm_banip", Command_BanIp, ADMFLAG_BAN, "sm_banip <ip|#userid|name> <time> [reason]");
67 /* Account for late loading */
69 if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
71 OnAdminMenuReady(topmenu);
75 public OnAdminMenuReady(Handle:topmenu)
77 /* Block us from being called twice */
78 if (topmenu == hTopMenu)
86 /* Find the "Player Commands" category */
87 new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
89 if (player_commands != INVALID_TOPMENUOBJECT)
91 AddToTopMenu(hTopMenu,
102 public Action:Command_BanIp(client, args)
106 ReplyToCommand(client, "[SM] Usage: sm_banip <ip|#userid|name> <time> [reason]");
107 return Plugin_Handled;
111 decl String:Arguments[256];
112 decl String:arg[50], String:time[20];
114 GetCmdArgString(Arguments, sizeof(Arguments));
115 len = BreakString(Arguments, arg, sizeof(arg));
117 if ((next_len = BreakString(Arguments[len], time, sizeof(time))) != -1)
127 if (StrEqual(arg, "0"))
129 ReplyToCommand(client, "[SM] %t", "Cannot ban that IP");
130 return Plugin_Handled;
133 decl String:target_name[MAX_TARGET_LENGTH];
134 decl target_list[1], bool:tn_is_ml;
135 new found_client = -1;
137 if (ProcessTargetString(
142 COMMAND_FILTER_CONNECTED|COMMAND_FILTER_NO_MULTI,
147 found_client = target_list[0];
152 if (client == 0 || (client == 1 && !IsDedicatedServer()))
158 new AdminId:id = GetUserAdmin(client);
159 has_rcon = (id == INVALID_ADMIN_ID) ? false : GetAdminFlag(id, Admin_RCON);
163 if (found_client != -1
164 && !IsFakeClient(found_client)
165 && (has_rcon || CanUserTarget(client, found_client)))
167 GetClientIP(found_client, arg, sizeof(arg));
168 hit_client = found_client;
171 if (hit_client == -1 && !has_rcon)
173 ReplyToCommand(client, "[SM] %t", "No Access");
174 return Plugin_Handled;
177 new minutes = StringToInt(time);
181 "\"%L\" added ban (minutes \"%d\") (ip \"%s\") (reason \"%s\")",
187 ReplyToCommand(client, "[SM] %t", "Ban added");
196 if (hit_client != -1)
198 KickClient(hit_client, "Banned: %s", Arguments[len]);
201 return Plugin_Handled;
204 public Action:Command_AddBan(client, args)
208 ReplyToCommand(client, "[SM] Usage: sm_addban <time> <steamid> [reason]");
209 return Plugin_Handled;
212 decl String:arg_string[256];
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, "[SM] Usage: sm_addban <time> <steamid> [reason]");
224 return Plugin_Handled;
229 if ((len = BreakString(arg_string[total_len], authid, sizeof(authid))) != -1)
236 arg_string[0] = '\0';
240 if (strncmp(authid, "STEAM_", 6) != 0 || authid[7] != ':')
242 ReplyToCommand(client, "[SM] %t", "Invalid SteamID specified");
243 return Plugin_Handled;
246 new minutes = StringToInt(time);
250 "\"%L\" added ban (minutes \"%d\") (id \"%s\") (reason \"%s\")",
254 arg_string[total_len]);
258 arg_string[total_len],
262 ReplyToCommand(client, "[SM] %t", "Ban added");
264 return Plugin_Handled;
267 public Action:Command_Unban(client, args)
271 ReplyToCommand(client, "[SM] Usage: sm_unban <steamid|ip>");
272 return Plugin_Handled;
276 GetCmdArgString(arg, sizeof(arg));
278 ReplaceString(arg, sizeof(arg), "\"", "");
281 if (strncmp(arg, "STEAM_", 6) == 0 && arg[7] == ':')
283 ban_flags |= BANFLAG_AUTHID;
287 ban_flags |= BANFLAG_IP;
290 LogAction(client, -1, "\"%L\" removed ban (filter \"%s\")", client, arg);
291 RemoveBan(arg, ban_flags, "sm_unban", client);
293 ReplyToCommand(client, "[SM] %t", "Removed bans matching", arg);
295 return Plugin_Handled;