1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/plugins/basebans.sp Sun Mar 30 07:00:22 2008 +0000
1.3 @@ -0,0 +1,296 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * =============================================================================
1.7 + * SourceMod Basic Commands Plugin
1.8 + * Implements basic admin commands.
1.9 + *
1.10 + * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
1.11 + * =============================================================================
1.12 + *
1.13 + * This program is free software; you can redistribute it and/or modify it under
1.14 + * the terms of the GNU General Public License, version 3.0, as published by the
1.15 + * Free Software Foundation.
1.16 + *
1.17 + * This program is distributed in the hope that it will be useful, but WITHOUT
1.18 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.19 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.20 + * details.
1.21 + *
1.22 + * You should have received a copy of the GNU General Public License along with
1.23 + * this program. If not, see <http://www.gnu.org/licenses/>.
1.24 + *
1.25 + * As a special exception, AlliedModders LLC gives you permission to link the
1.26 + * code of this program (as well as its derivative works) to "Half-Life 2," the
1.27 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.28 + * by the Valve Corporation. You must obey the GNU General Public License in
1.29 + * all respects for all other code used. Additionally, AlliedModders LLC grants
1.30 + * this exception to all derivative works. AlliedModders LLC defines further
1.31 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.32 + * or <http://www.sourcemod.net/license.php>.
1.33 + *
1.34 + * Version: $Id$
1.35 + */
1.36 +
1.37 +#pragma semicolon 1
1.38 +
1.39 +#include <sourcemod>
1.40 +#undef REQUIRE_PLUGIN
1.41 +#include <adminmenu>
1.42 +
1.43 +public Plugin:myinfo =
1.44 +{
1.45 + name = "Basic Ban Commands",
1.46 + author = "AlliedModders LLC",
1.47 + description = "Basic Banning Commands",
1.48 + version = SOURCEMOD_VERSION,
1.49 + url = "http://www.sourcemod.net/"
1.50 +};
1.51 +
1.52 +new Handle:hTopMenu = INVALID_HANDLE;
1.53 +
1.54 +new g_BanTarget[MAXPLAYERS+1];
1.55 +new g_BanTime[MAXPLAYERS+1];
1.56 +
1.57 +#include "basebans/ban.sp"
1.58 +
1.59 +public OnPluginStart()
1.60 +{
1.61 + LoadTranslations("common.phrases");
1.62 + LoadTranslations("basebans.phrases");
1.63 +
1.64 + RegAdminCmd("sm_ban", Command_Ban, ADMFLAG_BAN, "sm_ban <#userid|name> <minutes|0> [reason]");
1.65 + RegAdminCmd("sm_unban", Command_Unban, ADMFLAG_UNBAN, "sm_unban <steamid>");
1.66 + RegAdminCmd("sm_addban", Command_AddBan, ADMFLAG_RCON, "sm_addban <time> <steamid> [reason]");
1.67 + RegAdminCmd("sm_banip", Command_BanIp, ADMFLAG_BAN, "sm_banip <time> <ip|#userid|name> [reason]");
1.68 +
1.69 + /* Account for late loading */
1.70 + new Handle:topmenu;
1.71 + if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
1.72 + {
1.73 + OnAdminMenuReady(topmenu);
1.74 + }
1.75 +}
1.76 +
1.77 +public OnAdminMenuReady(Handle:topmenu)
1.78 +{
1.79 + /* Block us from being called twice */
1.80 + if (topmenu == hTopMenu)
1.81 + {
1.82 + return;
1.83 + }
1.84 +
1.85 + /* Save the Handle */
1.86 + hTopMenu = topmenu;
1.87 +
1.88 + /* Find the "Player Commands" category */
1.89 + new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
1.90 +
1.91 + if (player_commands != INVALID_TOPMENUOBJECT)
1.92 + {
1.93 + AddToTopMenu(hTopMenu,
1.94 + "sm_ban",
1.95 + TopMenuObject_Item,
1.96 + AdminMenu_Ban,
1.97 + player_commands,
1.98 + "sm_ban",
1.99 + ADMFLAG_BAN);
1.100 +
1.101 + }
1.102 +}
1.103 +
1.104 +public Action:Command_BanIp(client, args)
1.105 +{
1.106 + if (args < 2)
1.107 + {
1.108 + ReplyToCommand(client, "[SM] Usage: sm_banip <time> <ip|#userid|name> [reason]");
1.109 + return Plugin_Handled;
1.110 + }
1.111 +
1.112 + decl len, next_len;
1.113 + decl String:Arguments[256];
1.114 + decl String:arg[50], String:time[20];
1.115 +
1.116 + GetCmdArgString(Arguments, sizeof(Arguments));
1.117 + len = BreakString(Arguments, arg, sizeof(arg));
1.118 +
1.119 + if ((next_len = BreakString(Arguments[len], time, sizeof(time))) != -1)
1.120 + {
1.121 + len += next_len;
1.122 + }
1.123 + else
1.124 + {
1.125 + len = 0;
1.126 + Arguments[0] = '\0';
1.127 + }
1.128 +
1.129 + if (StrEqual(arg, "0"))
1.130 + {
1.131 + ReplyToCommand(client, "[SM] %t", "Cannot ban that IP");
1.132 + return Plugin_Handled;
1.133 + }
1.134 +
1.135 + decl String:target_name[MAX_TARGET_LENGTH];
1.136 + decl target_list[1], bool:tn_is_ml;
1.137 + new found_client = -1;
1.138 +
1.139 + if (ProcessTargetString(
1.140 + arg,
1.141 + client,
1.142 + target_list,
1.143 + 1,
1.144 + COMMAND_FILTER_CONNECTED|COMMAND_FILTER_NO_MULTI,
1.145 + target_name,
1.146 + sizeof(target_name),
1.147 + tn_is_ml) > 0)
1.148 + {
1.149 + found_client = target_list[0];
1.150 + }
1.151 +
1.152 + new bool:has_rcon;
1.153 +
1.154 + if (client == 0 || (client == 1 && !IsDedicatedServer()))
1.155 + {
1.156 + has_rcon = true;
1.157 + }
1.158 + else
1.159 + {
1.160 + new AdminId:id = GetUserAdmin(client);
1.161 + has_rcon = (id == INVALID_ADMIN_ID) ? false : GetAdminFlag(id, Admin_RCON);
1.162 + }
1.163 +
1.164 + new hit_client = -1;
1.165 + if (found_client != -1
1.166 + && !IsFakeClient(found_client)
1.167 + && (has_rcon || CanUserTarget(client, found_client)))
1.168 + {
1.169 + GetClientIP(found_client, arg, sizeof(arg));
1.170 + hit_client = found_client;
1.171 + }
1.172 +
1.173 + if (hit_client == -1 && !has_rcon)
1.174 + {
1.175 + ReplyToCommand(client, "[SM] %t", "No Access");
1.176 + return Plugin_Handled;
1.177 + }
1.178 +
1.179 + new minutes = StringToInt(time);
1.180 +
1.181 + LogAction(client,
1.182 + hit_client,
1.183 + "\"%L\" added ban (minutes \"%d\") (ip \"%s\") (reason \"%s\")",
1.184 + client,
1.185 + minutes,
1.186 + arg,
1.187 + Arguments[len]);
1.188 +
1.189 + ReplyToCommand(client, "[SM] %t", "Ban added");
1.190 +
1.191 + BanIdentity(arg,
1.192 + minutes,
1.193 + BANFLAG_IP,
1.194 + Arguments[len],
1.195 + "sm_banip",
1.196 + client);
1.197 +
1.198 + if (hit_client != -1)
1.199 + {
1.200 + KickClient(hit_client, "Banned: %s", Arguments[len]);
1.201 + }
1.202 +
1.203 + return Plugin_Handled;
1.204 +}
1.205 +
1.206 +public Action:Command_AddBan(client, args)
1.207 +{
1.208 + if (args < 2)
1.209 + {
1.210 + ReplyToCommand(client, "[SM] Usage: sm_addban <time> <steamid> [reason]");
1.211 + return Plugin_Handled;
1.212 + }
1.213 +
1.214 + decl String:arg_string[256];
1.215 + new String:time[50];
1.216 + new String:authid[50];
1.217 +
1.218 + GetCmdArgString(arg_string, sizeof(arg_string));
1.219 +
1.220 + new len, total_len;
1.221 +
1.222 + /* Get time */
1.223 + if ((len = BreakString(arg_string, time, sizeof(time))) == -1)
1.224 + {
1.225 + ReplyToCommand(client, "t[SM] Usage: sm_addban <time> <steamid> [reason]");
1.226 + return Plugin_Handled;
1.227 + }
1.228 + total_len += len;
1.229 +
1.230 + /* Get steamid */
1.231 + if ((len = BreakString(arg_string[total_len], authid, sizeof(authid))) != -1)
1.232 + {
1.233 + total_len += len;
1.234 + }
1.235 + else
1.236 + {
1.237 + total_len = 0;
1.238 + arg_string[0] = '\0';
1.239 + }
1.240 +
1.241 + /* Verify steamid */
1.242 + if (strncmp(authid, "STEAM_0:", 8) != 0)
1.243 + {
1.244 + ReplyToCommand(client, "[SM] %t", "Invalid SteamID specified");
1.245 + return Plugin_Handled;
1.246 + }
1.247 +
1.248 + new minutes = StringToInt(time);
1.249 +
1.250 + LogAction(client,
1.251 + -1,
1.252 + "\"%L\" added ban (minutes \"%d\") (id \"%s\") (reason \"%s\")",
1.253 + client,
1.254 + minutes,
1.255 + authid,
1.256 + arg_string[total_len]);
1.257 + BanIdentity(authid,
1.258 + minutes,
1.259 + BANFLAG_AUTHID,
1.260 + arg_string[total_len],
1.261 + "sm_addban",
1.262 + client);
1.263 +
1.264 + ReplyToCommand(client, "[SM] %t", "Ban added");
1.265 +
1.266 + return Plugin_Handled;
1.267 +}
1.268 +
1.269 +public Action:Command_Unban(client, args)
1.270 +{
1.271 + if (args < 1)
1.272 + {
1.273 + ReplyToCommand(client, "[SM] Usage: sm_unban <steamid|ip>");
1.274 + return Plugin_Handled;
1.275 + }
1.276 +
1.277 + decl String:arg[50];
1.278 + GetCmdArgString(arg, sizeof(arg));
1.279 +
1.280 + ReplaceString(arg, sizeof(arg), "\"", "");
1.281 +
1.282 + new ban_flags;
1.283 + if (strncmp(arg, "STEAM_0:", 8) == 0)
1.284 + {
1.285 + ban_flags |= BANFLAG_AUTHID;
1.286 + }
1.287 + else
1.288 + {
1.289 + ban_flags |= BANFLAG_IP;
1.290 + }
1.291 +
1.292 + LogAction(client, -1, "\"%L\" removed ban (filter \"%s\")", client, arg);
1.293 + RemoveBan(arg, ban_flags, "sm_unban", client);
1.294 +
1.295 + ReplyToCommand(client, "[SM] %t", "Removed bans matching", arg);
1.296 +
1.297 + return Plugin_Handled;
1.298 +}
1.299 +