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>.
38 public Plugin:myinfo =
40 name = "Basic Ban Commands",
41 author = "AlliedModders LLC",
42 description = "Basic Banning Commands",
43 version = SOURCEMOD_VERSION,
44 url = "http://www.sourcemod.net/"
47 public OnPluginStart()
49 LoadTranslations("common.phrases");
51 RegAdminCmd("sm_ban", Command_Ban, ADMFLAG_BAN, "sm_ban <#userid|name> <minutes|0> [reason]");
52 RegAdminCmd("sm_unban", Command_Unban, ADMFLAG_UNBAN, "sm_unban <steamid>");
53 RegAdminCmd("sm_addban", Command_AddBan, ADMFLAG_RCON, "sm_addban <time> <steamid> [reason]");
54 RegAdminCmd("sm_banip", Command_BanIp, ADMFLAG_BAN, "sm_banip <time> <ip|#userid|name> [reason]");
57 public Action:Command_BanIp(client, args)
61 ReplyToCommand(client, "[SM] Usage: sm_banip <time> <ip|#userid|name> [reason]");
62 return Plugin_Handled;
65 decl String:arg[50], String:time[20];
66 GetCmdArg(1, time, sizeof(time));
67 GetCmdArg(2, arg, sizeof(arg));
69 if (StrEqual(arg, "0"))
71 ReplyToCommand(client, "[SM] %t", "Cannot ban that IP");
72 return Plugin_Handled;
76 new numClients = SearchForClients(arg, clients, 1);
80 if (client == 0 || (client == 1 && !IsDedicatedServer()))
84 new AdminId:id = GetUserAdmin(client);
85 has_rcon = (id == INVALID_ADMIN_ID) ? false : GetAdminFlag(id, Admin_RCON);
90 && !IsFakeClient(clients[0])
91 && (has_rcon || CanUserTarget(client, clients[0])))
93 GetClientIP(clients[0], arg, sizeof(arg));
94 hit_client = clients[0];
97 if (hit_client == -1 && !has_rcon)
99 ReplyToCommand(client, "[SM] %t", "No Access");
100 return Plugin_Handled;
103 new minutes = StringToInt(time);
105 decl String:reason[128];
108 GetCmdArg(3, reason, sizeof(reason));
113 "\"%L\" added ban (minutes \"%d\") (ip \"%s\") (reason \"%s\")",
125 ReplyToCommand(client, "[SM] %t", "Ban added");
127 return Plugin_Handled;
130 public Action:Command_AddBan(client, args)
134 ReplyToCommand(client, "[SM] Usage: sm_addban <time> <steamid> [reason]");
135 return Plugin_Handled;
138 decl String:arg_string[256];
139 new String:reason[128];
141 new String:authid[50];
143 GetCmdArgString(arg_string, sizeof(arg_string));
148 if ((len = BreakString(arg_string, time, sizeof(time))) == -1)
150 ReplyToCommand(client, "t[SM] Usage: sm_addban <time> <steamid> [reason]");
151 return Plugin_Handled;
156 if ((len = BreakString(arg_string[total_len], authid, sizeof(authid))) != -1)
160 BreakString(arg_string[total_len], reason, sizeof(reason));
164 if (strncmp(authid, "STEAM_0:", 8) != 0)
166 ReplyToCommand(client, "[SM] %t", "Invalid SteamID specified");
167 return Plugin_Handled;
170 new minutes = StringToInt(time);
174 "\"%L\" added ban (minutes \"%d\") (id \"%s\") (reason \"%s\")",
186 ReplyToCommand(client, "[SM] %t", "Ban added");
188 return Plugin_Handled;
191 public Action:Command_Unban(client, args)
195 ReplyToCommand(client, "[SM] Usage: sm_unban <steamid|ip>");
196 return Plugin_Handled;
200 GetCmdArgString(arg, sizeof(arg));
202 ReplaceString(arg, sizeof(arg), "\"", "");
205 if (strncmp(arg, "STEAM_0:", 8) == 0)
207 ban_flags |= BANFLAG_AUTHID;
211 ban_flags |= BANFLAG_IP;
214 LogAction(client, -1, "\"%L\" removed ban (filter \"%s\")", client, arg);
215 RemoveBan(arg, ban_flags, "sm_unban", client);
217 ReplyToCommand(client, "[SM] %t", "Removed bans matching", arg);
219 return Plugin_Handled;
222 public Action:Command_Ban(client, args)
226 ReplyToCommand(client, "[SM] Usage: sm_ban <#userid|name> <minutes|0> [reason]");
227 return Plugin_Handled;
231 GetCmdArg(1, arg, sizeof(arg));
233 new target = FindTarget(client, arg, true);
236 return Plugin_Handled;
239 decl String:s_time[12];
240 GetCmdArg(2, s_time, sizeof(s_time));
242 new time = StringToInt(s_time);
244 decl String:reason[128];
247 GetCmdArg(3, reason, sizeof(reason));
252 decl String:authid[64];
253 GetClientAuthString(target, authid, sizeof(authid));
254 GetClientName(target, arg, sizeof(arg));
258 if (reason[0] == '\0')
260 ShowActivity(client, "%t", "Permabanned player", arg);
262 ShowActivity(client, "%t", "Permabanned player reason", arg, reason);
265 if (reason[0] == '\0')
267 ShowActivity(client, "%t", "Banned player", arg, time);
269 ShowActivity(client, "%t", "Banned player reason", arg, time, reason);
273 LogAction(client, target, "\"%L\" banned \"%L\" (minutes \"%d\") (reason \"%s\")", client, target, time, reason);
275 if (reason[0] == '\0')
277 strcopy(reason, sizeof(reason), "Banned");
280 BanClient(target, time, BANFLAG_AUTO, reason, reason, "sm_ban", client);
282 return Plugin_Handled;