plugins/basebans.sp
author Matt Woodrow <pred@alliedmods.net>
Sat Oct 13 04:43:42 2007 +0000 (2007-10-13)
changeset 1536 fe2146e4975d
parent 1423 e73b3563f254
child 1593 402899e19a44
permissions -rw-r--r--
Coded menus for most base plugins
     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 #undef REQUIRE_PLUGIN
    38 #include <adminmenu>
    39 
    40 public Plugin:myinfo =
    41 {
    42 	name = "Basic Ban Commands",
    43 	author = "AlliedModders LLC",
    44 	description = "Basic Banning Commands",
    45 	version = SOURCEMOD_VERSION,
    46 	url = "http://www.sourcemod.net/"
    47 };
    48 
    49 new Handle:hTopMenu = INVALID_HANDLE;
    50 
    51 new g_BanTarget[MAXPLAYERS+1];
    52 new g_BanTime[MAXPLAYERS+1];
    53 
    54 #include "basebans/ban.sp"
    55 
    56 public OnPluginStart()
    57 {
    58 	LoadTranslations("common.phrases");
    59 
    60 	RegAdminCmd("sm_ban", Command_Ban, ADMFLAG_BAN, "sm_ban <#userid|name> <minutes|0> [reason]");
    61 	RegAdminCmd("sm_unban", Command_Unban, ADMFLAG_UNBAN, "sm_unban <steamid>");
    62 	RegAdminCmd("sm_addban", Command_AddBan, ADMFLAG_RCON, "sm_addban <time> <steamid> [reason]");
    63 	RegAdminCmd("sm_banip", Command_BanIp, ADMFLAG_BAN, "sm_banip <time> <ip|#userid|name> [reason]");
    64 	
    65 	/* Account for late loading */
    66 	new Handle:topmenu;
    67 	if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
    68 	{
    69 		OnAdminMenuReady(topmenu);
    70 	}
    71 }
    72 
    73 public OnAdminMenuReady(Handle:topmenu)
    74 {
    75 	/* Block us from being called twice */
    76 	if (topmenu == hTopMenu)
    77 	{
    78 		return;
    79 	}
    80 	
    81 	/* Save the Handle */
    82 	hTopMenu = topmenu;
    83 	
    84 	/* Find the "Player Commands" category */
    85 	new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
    86 
    87 	if (player_commands != INVALID_TOPMENUOBJECT)
    88 	{
    89 		AddToTopMenu(hTopMenu,
    90 			"Ban Player",
    91 			TopMenuObject_Item,
    92 			AdminMenu_Ban,
    93 			player_commands,
    94 			"sm_ban",
    95 			ADMFLAG_BAN);
    96 			
    97 	}
    98 }
    99 
   100 public Action:Command_BanIp(client, args)
   101 {
   102 	if (args < 2)
   103 	{
   104 		ReplyToCommand(client, "[SM] Usage: sm_banip <time> <ip|#userid|name> [reason]");
   105 		return Plugin_Handled;
   106 	}
   107 
   108 	decl String:arg[50], String:time[20];
   109 	GetCmdArg(1, time, sizeof(time));
   110 	GetCmdArg(2, arg, sizeof(arg));
   111 	
   112 	if (StrEqual(arg, "0"))
   113 	{
   114 		ReplyToCommand(client, "[SM] %t", "Cannot ban that IP");
   115 		return Plugin_Handled;
   116 	}
   117 	
   118 	new clients[1];
   119 	new numClients = SearchForClients(arg, clients, 1);
   120 
   121 	new bool:has_rcon;
   122 	
   123 	if (client == 0 || (client == 1 && !IsDedicatedServer()))
   124 	{
   125 		has_rcon = true;
   126 	} else {
   127 		new AdminId:id = GetUserAdmin(client);
   128 		has_rcon = (id == INVALID_ADMIN_ID) ? false : GetAdminFlag(id, Admin_RCON);
   129 	}
   130 	
   131 	new hit_client = -1;
   132 	if (numClients == 1 
   133 		&& !IsFakeClient(clients[0])
   134 		&& (has_rcon || CanUserTarget(client, clients[0])))
   135 	{
   136 		GetClientIP(clients[0], arg, sizeof(arg));
   137 		hit_client = clients[0];
   138 	}
   139 	
   140 	if (hit_client == -1 && !has_rcon)
   141 	{
   142 		ReplyToCommand(client, "[SM] %t", "No Access");
   143 		return Plugin_Handled;
   144 	}
   145 
   146 	new minutes = StringToInt(time);
   147 
   148 	decl String:reason[128];
   149 	if (args >= 3)
   150 	{
   151 		GetCmdArg(3, reason, sizeof(reason));
   152 	}
   153 
   154 	LogAction(client, 
   155 			  hit_client, 
   156 			  "\"%L\" added ban (minutes \"%d\") (ip \"%s\") (reason \"%s\")", 
   157 			  client, 
   158 			  minutes, 
   159 			  arg, 
   160 			  reason);
   161 	BanIdentity(arg, 
   162 				minutes, 
   163 				BANFLAG_IP, 
   164 				reason, 
   165 				"sm_banip", 
   166 				client);
   167 
   168 	ReplyToCommand(client, "[SM] %t", "Ban added");
   169 
   170 	return Plugin_Handled;
   171 }
   172 
   173 public Action:Command_AddBan(client, args)
   174 {
   175 	if (args < 2)
   176 	{
   177 		ReplyToCommand(client, "[SM] Usage: sm_addban <time> <steamid> [reason]");
   178 		return Plugin_Handled;
   179 	}
   180 
   181 	decl String:arg_string[256];
   182 	new String:reason[128];
   183 	new String:time[50];
   184 	new String:authid[50];
   185 
   186 	GetCmdArgString(arg_string, sizeof(arg_string));
   187 
   188 	new len, total_len;
   189 
   190 	/* Get time */
   191 	if ((len = BreakString(arg_string, time, sizeof(time))) == -1)
   192 	{
   193 		ReplyToCommand(client, "t[SM] Usage: sm_addban <time> <steamid> [reason]");
   194 		return Plugin_Handled;
   195 	}	
   196 	total_len += len;
   197 
   198 	/* Get steamid */
   199 	if ((len = BreakString(arg_string[total_len], authid, sizeof(authid))) != -1)
   200 	{
   201 		/* Get reason */
   202 		total_len += len;
   203 		BreakString(arg_string[total_len], reason, sizeof(reason));
   204 	}
   205 
   206 	/* Verify steamid */
   207 	if (strncmp(authid, "STEAM_0:", 8) != 0)
   208 	{
   209 		ReplyToCommand(client, "[SM] %t", "Invalid SteamID specified");
   210 		return Plugin_Handled;
   211 	}
   212 
   213 	new minutes = StringToInt(time);
   214 
   215 	LogAction(client, 
   216 			  -1, 
   217 			  "\"%L\" added ban (minutes \"%d\") (id \"%s\") (reason \"%s\")", 
   218 			  client, 
   219 			  minutes, 
   220 			  authid, 
   221 			  reason);
   222 	BanIdentity(authid, 
   223 				minutes, 
   224 				BANFLAG_AUTHID, 
   225 				reason, 
   226 				"sm_addban", 
   227 				client);
   228 
   229 	ReplyToCommand(client, "[SM] %t", "Ban added");
   230 
   231 	return Plugin_Handled;
   232 }
   233 
   234 public Action:Command_Unban(client, args)
   235 {
   236 	if (args < 1)
   237 	{
   238 		ReplyToCommand(client, "[SM] Usage: sm_unban <steamid|ip>");
   239 		return Plugin_Handled;
   240 	}
   241 
   242 	decl String:arg[50];
   243 	GetCmdArgString(arg, sizeof(arg));
   244 
   245 	ReplaceString(arg, sizeof(arg), "\"", "");	
   246 
   247 	new ban_flags;
   248 	if (strncmp(arg, "STEAM_0:", 8) == 0)
   249 	{
   250 		ban_flags |= BANFLAG_AUTHID;
   251 	}
   252 	else
   253 	{
   254 		ban_flags |= BANFLAG_IP;
   255 	}
   256 
   257 	LogAction(client, -1, "\"%L\" removed ban (filter \"%s\")", client, arg);
   258 	RemoveBan(arg, ban_flags, "sm_unban", client);
   259 
   260 	ReplyToCommand(client, "[SM] %t", "Removed bans matching", arg);
   261 
   262 	return Plugin_Handled;
   263 }
   264