plugins/basebans.sp
author Borja Ferrer <faluco@alliedmods.net>
Fri Sep 28 20:13:42 2007 +0000 (2007-09-28)
changeset 1499 e55ac4555a2b
parent 1423 e73b3563f254
child 1536 fe2146e4975d
permissions -rw-r--r--
synced linux build
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basic Commands Plugin
     5  * Implements basic admin commands.
     6  *
     7  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     8  * =============================================================================
     9  *
    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.
    13  * 
    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
    17  * details.
    18  *
    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/>.
    21  *
    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>.
    30  *
    31  * Version: $Id$
    32  */
    33 
    34 #pragma semicolon 1
    35 
    36 #include <sourcemod>
    37 
    38 public Plugin:myinfo =
    39 {
    40 	name = "Basic Ban Commands",
    41 	author = "AlliedModders LLC",
    42 	description = "Basic Banning Commands",
    43 	version = SOURCEMOD_VERSION,
    44 	url = "http://www.sourcemod.net/"
    45 };
    46 
    47 public OnPluginStart()
    48 {
    49 	LoadTranslations("common.phrases");
    50 
    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]");
    55 }
    56 
    57 public Action:Command_BanIp(client, args)
    58 {
    59 	if (args < 2)
    60 	{
    61 		ReplyToCommand(client, "[SM] Usage: sm_banip <time> <ip|#userid|name> [reason]");
    62 		return Plugin_Handled;
    63 	}
    64 
    65 	decl String:arg[50], String:time[20];
    66 	GetCmdArg(1, time, sizeof(time));
    67 	GetCmdArg(2, arg, sizeof(arg));
    68 	
    69 	if (StrEqual(arg, "0"))
    70 	{
    71 		ReplyToCommand(client, "[SM] %t", "Cannot ban that IP");
    72 		return Plugin_Handled;
    73 	}
    74 	
    75 	new clients[1];
    76 	new numClients = SearchForClients(arg, clients, 1);
    77 
    78 	new bool:has_rcon;
    79 	
    80 	if (client == 0 || (client == 1 && !IsDedicatedServer()))
    81 	{
    82 		has_rcon = true;
    83 	} else {
    84 		new AdminId:id = GetUserAdmin(client);
    85 		has_rcon = (id == INVALID_ADMIN_ID) ? false : GetAdminFlag(id, Admin_RCON);
    86 	}
    87 	
    88 	new hit_client = -1;
    89 	if (numClients == 1 
    90 		&& !IsFakeClient(clients[0])
    91 		&& (has_rcon || CanUserTarget(client, clients[0])))
    92 	{
    93 		GetClientIP(clients[0], arg, sizeof(arg));
    94 		hit_client = clients[0];
    95 	}
    96 	
    97 	if (hit_client == -1 && !has_rcon)
    98 	{
    99 		ReplyToCommand(client, "[SM] %t", "No Access");
   100 		return Plugin_Handled;
   101 	}
   102 
   103 	new minutes = StringToInt(time);
   104 
   105 	decl String:reason[128];
   106 	if (args >= 3)
   107 	{
   108 		GetCmdArg(3, reason, sizeof(reason));
   109 	}
   110 
   111 	LogAction(client, 
   112 			  hit_client, 
   113 			  "\"%L\" added ban (minutes \"%d\") (ip \"%s\") (reason \"%s\")", 
   114 			  client, 
   115 			  minutes, 
   116 			  arg, 
   117 			  reason);
   118 	BanIdentity(arg, 
   119 				minutes, 
   120 				BANFLAG_IP, 
   121 				reason, 
   122 				"sm_banip", 
   123 				client);
   124 
   125 	ReplyToCommand(client, "[SM] %t", "Ban added");
   126 
   127 	return Plugin_Handled;
   128 }
   129 
   130 public Action:Command_AddBan(client, args)
   131 {
   132 	if (args < 2)
   133 	{
   134 		ReplyToCommand(client, "[SM] Usage: sm_addban <time> <steamid> [reason]");
   135 		return Plugin_Handled;
   136 	}
   137 
   138 	decl String:arg_string[256];
   139 	new String:reason[128];
   140 	new String:time[50];
   141 	new String:authid[50];
   142 
   143 	GetCmdArgString(arg_string, sizeof(arg_string));
   144 
   145 	new len, total_len;
   146 
   147 	/* Get time */
   148 	if ((len = BreakString(arg_string, time, sizeof(time))) == -1)
   149 	{
   150 		ReplyToCommand(client, "t[SM] Usage: sm_addban <time> <steamid> [reason]");
   151 		return Plugin_Handled;
   152 	}	
   153 	total_len += len;
   154 
   155 	/* Get steamid */
   156 	if ((len = BreakString(arg_string[total_len], authid, sizeof(authid))) != -1)
   157 	{
   158 		/* Get reason */
   159 		total_len += len;
   160 		BreakString(arg_string[total_len], reason, sizeof(reason));
   161 	}
   162 
   163 	/* Verify steamid */
   164 	if (strncmp(authid, "STEAM_0:", 8) != 0)
   165 	{
   166 		ReplyToCommand(client, "[SM] %t", "Invalid SteamID specified");
   167 		return Plugin_Handled;
   168 	}
   169 
   170 	new minutes = StringToInt(time);
   171 
   172 	LogAction(client, 
   173 			  -1, 
   174 			  "\"%L\" added ban (minutes \"%d\") (id \"%s\") (reason \"%s\")", 
   175 			  client, 
   176 			  minutes, 
   177 			  authid, 
   178 			  reason);
   179 	BanIdentity(authid, 
   180 				minutes, 
   181 				BANFLAG_AUTHID, 
   182 				reason, 
   183 				"sm_addban", 
   184 				client);
   185 
   186 	ReplyToCommand(client, "[SM] %t", "Ban added");
   187 
   188 	return Plugin_Handled;
   189 }
   190 
   191 public Action:Command_Unban(client, args)
   192 {
   193 	if (args < 1)
   194 	{
   195 		ReplyToCommand(client, "[SM] Usage: sm_unban <steamid|ip>");
   196 		return Plugin_Handled;
   197 	}
   198 
   199 	decl String:arg[50];
   200 	GetCmdArgString(arg, sizeof(arg));
   201 
   202 	ReplaceString(arg, sizeof(arg), "\"", "");	
   203 
   204 	new ban_flags;
   205 	if (strncmp(arg, "STEAM_0:", 8) == 0)
   206 	{
   207 		ban_flags |= BANFLAG_AUTHID;
   208 	}
   209 	else
   210 	{
   211 		ban_flags |= BANFLAG_IP;
   212 	}
   213 
   214 	LogAction(client, -1, "\"%L\" removed ban (filter \"%s\")", client, arg);
   215 	RemoveBan(arg, ban_flags, "sm_unban", client);
   216 
   217 	ReplyToCommand(client, "[SM] %t", "Removed bans matching", arg);
   218 
   219 	return Plugin_Handled;
   220 }
   221 
   222 public Action:Command_Ban(client, args)
   223 {
   224 	if (args < 2)
   225 	{
   226 		ReplyToCommand(client, "[SM] Usage: sm_ban <#userid|name> <minutes|0> [reason]");
   227 		return Plugin_Handled;
   228 	}
   229 
   230 	decl String:arg[65];
   231 	GetCmdArg(1, arg, sizeof(arg));
   232 
   233 	new target = FindTarget(client, arg, true);
   234 	if (target == -1)
   235 	{
   236 		return Plugin_Handled;
   237 	}
   238 
   239 	decl String:s_time[12];
   240 	GetCmdArg(2, s_time, sizeof(s_time));
   241 
   242 	new time = StringToInt(s_time);
   243 
   244 	decl String:reason[128];
   245 	if (args >= 3)
   246 	{
   247 		GetCmdArg(3, reason, sizeof(reason));
   248 	} else {
   249 		reason[0] = '\0';
   250 	}
   251 
   252 	decl String:authid[64];
   253 	GetClientAuthString(target, authid, sizeof(authid));
   254 	GetClientName(target, arg, sizeof(arg));
   255 
   256 	if (!time)
   257 	{
   258 		if (reason[0] == '\0')
   259 		{
   260 			ShowActivity(client, "%t", "Permabanned player", arg);
   261 		} else {
   262 			ShowActivity(client, "%t", "Permabanned player reason", arg, reason);
   263 		}
   264 	} else {
   265 		if (reason[0] == '\0')
   266 		{
   267 			ShowActivity(client, "%t", "Banned player", arg, time);
   268 		} else {
   269 			ShowActivity(client, "%t", "Banned player reason", arg, time, reason);
   270 		}
   271 	}
   272 
   273 	LogAction(client, target, "\"%L\" banned \"%L\" (minutes \"%d\") (reason \"%s\")", client, target, time, reason);
   274 
   275 	if (reason[0] == '\0')
   276 	{
   277 		strcopy(reason, sizeof(reason), "Banned");
   278 	}
   279 
   280 	BanClient(target, time, BANFLAG_AUTO, reason, reason, "sm_ban", client);
   281 
   282 	return Plugin_Handled;
   283 }
   284