plugins/basebans.sp
branchsourcemod-1.1.0
changeset 2283 03a67e41afbc
parent 1951 c7b4237fff50
child 2287 017a725c9d17
     1.1 --- a/plugins/basebans.sp	Fri Mar 28 06:21:34 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,294 +0,0 @@
     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-2007 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:reason[128];
   1.216 -	new String:time[50];
   1.217 -	new String:authid[50];
   1.218 -
   1.219 -	GetCmdArgString(arg_string, sizeof(arg_string));
   1.220 -
   1.221 -	new len, total_len;
   1.222 -
   1.223 -	/* Get time */
   1.224 -	if ((len = BreakString(arg_string, time, sizeof(time))) == -1)
   1.225 -	{
   1.226 -		ReplyToCommand(client, "t[SM] Usage: sm_addban <time> <steamid> [reason]");
   1.227 -		return Plugin_Handled;
   1.228 -	}	
   1.229 -	total_len += len;
   1.230 -
   1.231 -	/* Get steamid */
   1.232 -	if ((len = BreakString(arg_string[total_len], authid, sizeof(authid))) != -1)
   1.233 -	{
   1.234 -		/* Get reason */
   1.235 -		total_len += len;
   1.236 -		BreakString(arg_string[total_len], reason, sizeof(reason));
   1.237 -	}
   1.238 -
   1.239 -	/* Verify steamid */
   1.240 -	if (strncmp(authid, "STEAM_0:", 8) != 0)
   1.241 -	{
   1.242 -		ReplyToCommand(client, "[SM] %t", "Invalid SteamID specified");
   1.243 -		return Plugin_Handled;
   1.244 -	}
   1.245 -
   1.246 -	new minutes = StringToInt(time);
   1.247 -
   1.248 -	LogAction(client, 
   1.249 -			  -1, 
   1.250 -			  "\"%L\" added ban (minutes \"%d\") (id \"%s\") (reason \"%s\")", 
   1.251 -			  client, 
   1.252 -			  minutes, 
   1.253 -			  authid, 
   1.254 -			  reason);
   1.255 -	BanIdentity(authid, 
   1.256 -				minutes, 
   1.257 -				BANFLAG_AUTHID, 
   1.258 -				reason, 
   1.259 -				"sm_addban", 
   1.260 -				client);
   1.261 -
   1.262 -	ReplyToCommand(client, "[SM] %t", "Ban added");
   1.263 -
   1.264 -	return Plugin_Handled;
   1.265 -}
   1.266 -
   1.267 -public Action:Command_Unban(client, args)
   1.268 -{
   1.269 -	if (args < 1)
   1.270 -	{
   1.271 -		ReplyToCommand(client, "[SM] Usage: sm_unban <steamid|ip>");
   1.272 -		return Plugin_Handled;
   1.273 -	}
   1.274 -
   1.275 -	decl String:arg[50];
   1.276 -	GetCmdArgString(arg, sizeof(arg));
   1.277 -
   1.278 -	ReplaceString(arg, sizeof(arg), "\"", "");	
   1.279 -
   1.280 -	new ban_flags;
   1.281 -	if (strncmp(arg, "STEAM_0:", 8) == 0)
   1.282 -	{
   1.283 -		ban_flags |= BANFLAG_AUTHID;
   1.284 -	}
   1.285 -	else
   1.286 -	{
   1.287 -		ban_flags |= BANFLAG_IP;
   1.288 -	}
   1.289 -
   1.290 -	LogAction(client, -1, "\"%L\" removed ban (filter \"%s\")", client, arg);
   1.291 -	RemoveBan(arg, ban_flags, "sm_unban", client);
   1.292 -
   1.293 -	ReplyToCommand(client, "[SM] %t", "Removed bans matching", arg);
   1.294 -
   1.295 -	return Plugin_Handled;
   1.296 -}
   1.297 -