plugins/basebans.sp
changeset 1423 e73b3563f254
child 1536 fe2146e4975d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/basebans.sp	Fri Sep 14 02:11:10 2007 +0000
     1.3 @@ -0,0 +1,284 @@
     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 +
    1.41 +public Plugin:myinfo =
    1.42 +{
    1.43 +	name = "Basic Ban Commands",
    1.44 +	author = "AlliedModders LLC",
    1.45 +	description = "Basic Banning Commands",
    1.46 +	version = SOURCEMOD_VERSION,
    1.47 +	url = "http://www.sourcemod.net/"
    1.48 +};
    1.49 +
    1.50 +public OnPluginStart()
    1.51 +{
    1.52 +	LoadTranslations("common.phrases");
    1.53 +
    1.54 +	RegAdminCmd("sm_ban", Command_Ban, ADMFLAG_BAN, "sm_ban <#userid|name> <minutes|0> [reason]");
    1.55 +	RegAdminCmd("sm_unban", Command_Unban, ADMFLAG_UNBAN, "sm_unban <steamid>");
    1.56 +	RegAdminCmd("sm_addban", Command_AddBan, ADMFLAG_RCON, "sm_addban <time> <steamid> [reason]");
    1.57 +	RegAdminCmd("sm_banip", Command_BanIp, ADMFLAG_BAN, "sm_banip <time> <ip|#userid|name> [reason]");
    1.58 +}
    1.59 +
    1.60 +public Action:Command_BanIp(client, args)
    1.61 +{
    1.62 +	if (args < 2)
    1.63 +	{
    1.64 +		ReplyToCommand(client, "[SM] Usage: sm_banip <time> <ip|#userid|name> [reason]");
    1.65 +		return Plugin_Handled;
    1.66 +	}
    1.67 +
    1.68 +	decl String:arg[50], String:time[20];
    1.69 +	GetCmdArg(1, time, sizeof(time));
    1.70 +	GetCmdArg(2, arg, sizeof(arg));
    1.71 +	
    1.72 +	if (StrEqual(arg, "0"))
    1.73 +	{
    1.74 +		ReplyToCommand(client, "[SM] %t", "Cannot ban that IP");
    1.75 +		return Plugin_Handled;
    1.76 +	}
    1.77 +	
    1.78 +	new clients[1];
    1.79 +	new numClients = SearchForClients(arg, clients, 1);
    1.80 +
    1.81 +	new bool:has_rcon;
    1.82 +	
    1.83 +	if (client == 0 || (client == 1 && !IsDedicatedServer()))
    1.84 +	{
    1.85 +		has_rcon = true;
    1.86 +	} else {
    1.87 +		new AdminId:id = GetUserAdmin(client);
    1.88 +		has_rcon = (id == INVALID_ADMIN_ID) ? false : GetAdminFlag(id, Admin_RCON);
    1.89 +	}
    1.90 +	
    1.91 +	new hit_client = -1;
    1.92 +	if (numClients == 1 
    1.93 +		&& !IsFakeClient(clients[0])
    1.94 +		&& (has_rcon || CanUserTarget(client, clients[0])))
    1.95 +	{
    1.96 +		GetClientIP(clients[0], arg, sizeof(arg));
    1.97 +		hit_client = clients[0];
    1.98 +	}
    1.99 +	
   1.100 +	if (hit_client == -1 && !has_rcon)
   1.101 +	{
   1.102 +		ReplyToCommand(client, "[SM] %t", "No Access");
   1.103 +		return Plugin_Handled;
   1.104 +	}
   1.105 +
   1.106 +	new minutes = StringToInt(time);
   1.107 +
   1.108 +	decl String:reason[128];
   1.109 +	if (args >= 3)
   1.110 +	{
   1.111 +		GetCmdArg(3, reason, sizeof(reason));
   1.112 +	}
   1.113 +
   1.114 +	LogAction(client, 
   1.115 +			  hit_client, 
   1.116 +			  "\"%L\" added ban (minutes \"%d\") (ip \"%s\") (reason \"%s\")", 
   1.117 +			  client, 
   1.118 +			  minutes, 
   1.119 +			  arg, 
   1.120 +			  reason);
   1.121 +	BanIdentity(arg, 
   1.122 +				minutes, 
   1.123 +				BANFLAG_IP, 
   1.124 +				reason, 
   1.125 +				"sm_banip", 
   1.126 +				client);
   1.127 +
   1.128 +	ReplyToCommand(client, "[SM] %t", "Ban added");
   1.129 +
   1.130 +	return Plugin_Handled;
   1.131 +}
   1.132 +
   1.133 +public Action:Command_AddBan(client, args)
   1.134 +{
   1.135 +	if (args < 2)
   1.136 +	{
   1.137 +		ReplyToCommand(client, "[SM] Usage: sm_addban <time> <steamid> [reason]");
   1.138 +		return Plugin_Handled;
   1.139 +	}
   1.140 +
   1.141 +	decl String:arg_string[256];
   1.142 +	new String:reason[128];
   1.143 +	new String:time[50];
   1.144 +	new String:authid[50];
   1.145 +
   1.146 +	GetCmdArgString(arg_string, sizeof(arg_string));
   1.147 +
   1.148 +	new len, total_len;
   1.149 +
   1.150 +	/* Get time */
   1.151 +	if ((len = BreakString(arg_string, time, sizeof(time))) == -1)
   1.152 +	{
   1.153 +		ReplyToCommand(client, "t[SM] Usage: sm_addban <time> <steamid> [reason]");
   1.154 +		return Plugin_Handled;
   1.155 +	}	
   1.156 +	total_len += len;
   1.157 +
   1.158 +	/* Get steamid */
   1.159 +	if ((len = BreakString(arg_string[total_len], authid, sizeof(authid))) != -1)
   1.160 +	{
   1.161 +		/* Get reason */
   1.162 +		total_len += len;
   1.163 +		BreakString(arg_string[total_len], reason, sizeof(reason));
   1.164 +	}
   1.165 +
   1.166 +	/* Verify steamid */
   1.167 +	if (strncmp(authid, "STEAM_0:", 8) != 0)
   1.168 +	{
   1.169 +		ReplyToCommand(client, "[SM] %t", "Invalid SteamID specified");
   1.170 +		return Plugin_Handled;
   1.171 +	}
   1.172 +
   1.173 +	new minutes = StringToInt(time);
   1.174 +
   1.175 +	LogAction(client, 
   1.176 +			  -1, 
   1.177 +			  "\"%L\" added ban (minutes \"%d\") (id \"%s\") (reason \"%s\")", 
   1.178 +			  client, 
   1.179 +			  minutes, 
   1.180 +			  authid, 
   1.181 +			  reason);
   1.182 +	BanIdentity(authid, 
   1.183 +				minutes, 
   1.184 +				BANFLAG_AUTHID, 
   1.185 +				reason, 
   1.186 +				"sm_addban", 
   1.187 +				client);
   1.188 +
   1.189 +	ReplyToCommand(client, "[SM] %t", "Ban added");
   1.190 +
   1.191 +	return Plugin_Handled;
   1.192 +}
   1.193 +
   1.194 +public Action:Command_Unban(client, args)
   1.195 +{
   1.196 +	if (args < 1)
   1.197 +	{
   1.198 +		ReplyToCommand(client, "[SM] Usage: sm_unban <steamid|ip>");
   1.199 +		return Plugin_Handled;
   1.200 +	}
   1.201 +
   1.202 +	decl String:arg[50];
   1.203 +	GetCmdArgString(arg, sizeof(arg));
   1.204 +
   1.205 +	ReplaceString(arg, sizeof(arg), "\"", "");	
   1.206 +
   1.207 +	new ban_flags;
   1.208 +	if (strncmp(arg, "STEAM_0:", 8) == 0)
   1.209 +	{
   1.210 +		ban_flags |= BANFLAG_AUTHID;
   1.211 +	}
   1.212 +	else
   1.213 +	{
   1.214 +		ban_flags |= BANFLAG_IP;
   1.215 +	}
   1.216 +
   1.217 +	LogAction(client, -1, "\"%L\" removed ban (filter \"%s\")", client, arg);
   1.218 +	RemoveBan(arg, ban_flags, "sm_unban", client);
   1.219 +
   1.220 +	ReplyToCommand(client, "[SM] %t", "Removed bans matching", arg);
   1.221 +
   1.222 +	return Plugin_Handled;
   1.223 +}
   1.224 +
   1.225 +public Action:Command_Ban(client, args)
   1.226 +{
   1.227 +	if (args < 2)
   1.228 +	{
   1.229 +		ReplyToCommand(client, "[SM] Usage: sm_ban <#userid|name> <minutes|0> [reason]");
   1.230 +		return Plugin_Handled;
   1.231 +	}
   1.232 +
   1.233 +	decl String:arg[65];
   1.234 +	GetCmdArg(1, arg, sizeof(arg));
   1.235 +
   1.236 +	new target = FindTarget(client, arg, true);
   1.237 +	if (target == -1)
   1.238 +	{
   1.239 +		return Plugin_Handled;
   1.240 +	}
   1.241 +
   1.242 +	decl String:s_time[12];
   1.243 +	GetCmdArg(2, s_time, sizeof(s_time));
   1.244 +
   1.245 +	new time = StringToInt(s_time);
   1.246 +
   1.247 +	decl String:reason[128];
   1.248 +	if (args >= 3)
   1.249 +	{
   1.250 +		GetCmdArg(3, reason, sizeof(reason));
   1.251 +	} else {
   1.252 +		reason[0] = '\0';
   1.253 +	}
   1.254 +
   1.255 +	decl String:authid[64];
   1.256 +	GetClientAuthString(target, authid, sizeof(authid));
   1.257 +	GetClientName(target, arg, sizeof(arg));
   1.258 +
   1.259 +	if (!time)
   1.260 +	{
   1.261 +		if (reason[0] == '\0')
   1.262 +		{
   1.263 +			ShowActivity(client, "%t", "Permabanned player", arg);
   1.264 +		} else {
   1.265 +			ShowActivity(client, "%t", "Permabanned player reason", arg, reason);
   1.266 +		}
   1.267 +	} else {
   1.268 +		if (reason[0] == '\0')
   1.269 +		{
   1.270 +			ShowActivity(client, "%t", "Banned player", arg, time);
   1.271 +		} else {
   1.272 +			ShowActivity(client, "%t", "Banned player reason", arg, time, reason);
   1.273 +		}
   1.274 +	}
   1.275 +
   1.276 +	LogAction(client, target, "\"%L\" banned \"%L\" (minutes \"%d\") (reason \"%s\")", client, target, time, reason);
   1.277 +
   1.278 +	if (reason[0] == '\0')
   1.279 +	{
   1.280 +		strcopy(reason, sizeof(reason), "Banned");
   1.281 +	}
   1.282 +
   1.283 +	BanClient(target, time, BANFLAG_AUTO, reason, reason, "sm_ban", client);
   1.284 +
   1.285 +	return Plugin_Handled;
   1.286 +}
   1.287 +