plugins/basebans/ban.sp
branchrefac-jit
changeset 2168 c24a6fa957db
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/basebans/ban.sp	Sun Jul 06 04:49:55 2008 +0000
     1.3 @@ -0,0 +1,270 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod Basecommands
     1.8 + * Functionality related to banning.
     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 +PrepareBan(client, target, time, const String:reason[])
    1.38 +{
    1.39 +	decl String:authid[64], String:name[32];
    1.40 +	GetClientAuthString(target, authid, sizeof(authid));
    1.41 +	GetClientName(target, name, sizeof(name));
    1.42 +
    1.43 +	if (!time)
    1.44 +	{
    1.45 +		if (reason[0] == '\0')
    1.46 +		{
    1.47 +			ShowActivity(client, "%t", "Permabanned player", name);
    1.48 +		} else {
    1.49 +			ShowActivity(client, "%t", "Permabanned player reason", name, reason);
    1.50 +		}
    1.51 +	} else {
    1.52 +		if (reason[0] == '\0')
    1.53 +		{
    1.54 +			ShowActivity(client, "%t", "Banned player", name, time);
    1.55 +		} else {
    1.56 +			ShowActivity(client, "%t", "Banned player reason", name, time, reason);
    1.57 +		}
    1.58 +	}
    1.59 +
    1.60 +	LogAction(client, target, "\"%L\" banned \"%L\" (minutes \"%d\") (reason \"%s\")", client, target, time, reason);
    1.61 +
    1.62 +	if (reason[0] == '\0')
    1.63 +	{
    1.64 +		BanClient(target, time, BANFLAG_AUTO, "Banned", "Banned", "sm_ban", client);
    1.65 +	}
    1.66 +	else
    1.67 +	{
    1.68 +		BanClient(target, time, BANFLAG_AUTO, reason, reason, "sm_ban", client);
    1.69 +	}
    1.70 +}
    1.71 +
    1.72 +DisplayBanTargetMenu(client)
    1.73 +{
    1.74 +	new Handle:menu = CreateMenu(MenuHandler_BanPlayerList);
    1.75 +	
    1.76 +	decl String:title[100];
    1.77 +	Format(title, sizeof(title), "%T:", "Ban player", client);
    1.78 +	SetMenuTitle(menu, title);
    1.79 +	SetMenuExitBackButton(menu, true);
    1.80 +	
    1.81 +	AddTargetsToMenu2(menu, client, COMMAND_FILTER_NO_BOTS|COMMAND_FILTER_CONNECTED);
    1.82 +	
    1.83 +	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    1.84 +}
    1.85 +
    1.86 +DisplayBanTimeMenu(client)
    1.87 +{
    1.88 +	new Handle:menu = CreateMenu(MenuHandler_BanTimeList);
    1.89 +	
    1.90 +	decl String:title[100];
    1.91 +	Format(title, sizeof(title), "%T:", "Ban player", client);
    1.92 +	SetMenuTitle(menu, title);
    1.93 +	SetMenuExitBackButton(menu, true);
    1.94 +	
    1.95 +	AddMenuItem(menu, "0", "Permanent");
    1.96 +	AddMenuItem(menu, "10", "10 Minutes");
    1.97 +	AddMenuItem(menu, "30", "30 Minutes");
    1.98 +	AddMenuItem(menu, "60", "1 Hour");
    1.99 +	AddMenuItem(menu, "240", "4 Hours");
   1.100 +	AddMenuItem(menu, "1440", "1 Day");
   1.101 +	AddMenuItem(menu, "10080", "1 Week");
   1.102 +	
   1.103 +	DisplayMenu(menu, client, MENU_TIME_FOREVER);
   1.104 +}
   1.105 +
   1.106 +DisplayBanReasonMenu(client)
   1.107 +{
   1.108 +	new Handle:menu = CreateMenu(MenuHandler_BanReasonList);
   1.109 +	
   1.110 +	decl String:title[100];
   1.111 +	Format(title, sizeof(title), "%T:", "Ban reason", client);
   1.112 +	SetMenuTitle(menu, title);
   1.113 +	SetMenuExitBackButton(menu, true);
   1.114 +	
   1.115 +	/* :TODO: we should either remove this or make it configurable */
   1.116 +	
   1.117 +	AddMenuItem(menu, "Abusive", "Abusive");
   1.118 +	AddMenuItem(menu, "Racism", "Racism");
   1.119 +	AddMenuItem(menu, "General cheating/exploits", "General cheating/exploits");
   1.120 +	AddMenuItem(menu, "Wallhack", "Wallhack");
   1.121 +	AddMenuItem(menu, "Aimbot", "Aimbot");
   1.122 +	AddMenuItem(menu, "Speedhacking", "Speedhacking");
   1.123 +	AddMenuItem(menu, "Mic spamming", "Mic spamming");
   1.124 +	AddMenuItem(menu, "Admin disrepect", "Admin disrepect");
   1.125 +	AddMenuItem(menu, "Camping", "Camping");
   1.126 +	AddMenuItem(menu, "Team killing", "Team killing");
   1.127 +	AddMenuItem(menu, "Unacceptable Spray", "Unacceptable Spray");
   1.128 +	AddMenuItem(menu, "Breaking Server Rules", "Breaking Server Rules");
   1.129 +	AddMenuItem(menu, "Other", "Other");
   1.130 +	
   1.131 +	DisplayMenu(menu, client, MENU_TIME_FOREVER);
   1.132 +}
   1.133 +
   1.134 +public AdminMenu_Ban(Handle:topmenu, 
   1.135 +							  TopMenuAction:action,
   1.136 +							  TopMenuObject:object_id,
   1.137 +							  param,
   1.138 +							  String:buffer[],
   1.139 +							  maxlength)
   1.140 +{
   1.141 +	if (action == TopMenuAction_DisplayOption)
   1.142 +	{
   1.143 +		Format(buffer, maxlength, "%T", "Ban player", param);
   1.144 +	}
   1.145 +	else if (action == TopMenuAction_SelectOption)
   1.146 +	{
   1.147 +		DisplayBanTargetMenu(param);
   1.148 +	}
   1.149 +}
   1.150 +
   1.151 +public MenuHandler_BanReasonList(Handle:menu, MenuAction:action, param1, param2)
   1.152 +{
   1.153 +	if (action == MenuAction_End)
   1.154 +	{
   1.155 +		CloseHandle(menu);
   1.156 +	}
   1.157 +	else if (action == MenuAction_Cancel)
   1.158 +	{
   1.159 +		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   1.160 +		{
   1.161 +			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   1.162 +		}
   1.163 +	}
   1.164 +	else if (action == MenuAction_Select)
   1.165 +	{
   1.166 +		decl String:info[64];
   1.167 +		
   1.168 +		GetMenuItem(menu, param2, info, sizeof(info));
   1.169 +	
   1.170 +		PrepareBan(param1, g_BanTarget[param1], g_BanTime[param1], info);
   1.171 +	}
   1.172 +}
   1.173 +
   1.174 +public MenuHandler_BanPlayerList(Handle:menu, MenuAction:action, param1, param2)
   1.175 +{
   1.176 +	if (action == MenuAction_End)
   1.177 +	{
   1.178 +		CloseHandle(menu);
   1.179 +	}
   1.180 +	else if (action == MenuAction_Cancel)
   1.181 +	{
   1.182 +		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   1.183 +		{
   1.184 +			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   1.185 +		}
   1.186 +	}
   1.187 +	else if (action == MenuAction_Select)
   1.188 +	{
   1.189 +		decl String:info[32], String:name[32];
   1.190 +		new userid, target;
   1.191 +		
   1.192 +		GetMenuItem(menu, param2, info, sizeof(info), _, name, sizeof(name));
   1.193 +		userid = StringToInt(info);
   1.194 +
   1.195 +		if ((target = GetClientOfUserId(userid)) == 0)
   1.196 +		{
   1.197 +			PrintToChat(param1, "[SM] %t", "Player no longer available");
   1.198 +		}
   1.199 +		else if (!CanUserTarget(param1, target))
   1.200 +		{
   1.201 +			PrintToChat(param1, "[SM] %t", "Unable to target");
   1.202 +		}
   1.203 +		else
   1.204 +		{
   1.205 +			g_BanTarget[param1] = target;
   1.206 +			DisplayBanTimeMenu(param1);
   1.207 +		}
   1.208 +	}
   1.209 +}
   1.210 +
   1.211 +public MenuHandler_BanTimeList(Handle:menu, MenuAction:action, param1, param2)
   1.212 +{
   1.213 +	if (action == MenuAction_End)
   1.214 +	{
   1.215 +		CloseHandle(menu);
   1.216 +	}
   1.217 +	else if (action == MenuAction_Cancel)
   1.218 +	{
   1.219 +		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   1.220 +		{
   1.221 +			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   1.222 +		}
   1.223 +	}
   1.224 +	else if (action == MenuAction_Select)
   1.225 +	{
   1.226 +		decl String:info[32];
   1.227 +		
   1.228 +		GetMenuItem(menu, param2, info, sizeof(info));
   1.229 +		g_BanTime[param1] = StringToInt(info);
   1.230 +		
   1.231 +		DisplayBanReasonMenu(param1);
   1.232 +	}
   1.233 +}
   1.234 +
   1.235 +
   1.236 +public Action:Command_Ban(client, args)
   1.237 +{
   1.238 +	if (args < 2)
   1.239 +	{
   1.240 +		ReplyToCommand(client, "[SM] Usage: sm_ban <#userid|name> <minutes|0> [reason]");
   1.241 +		return Plugin_Handled;
   1.242 +	}
   1.243 +	
   1.244 +	decl len, next_len;
   1.245 +	decl String:Arguments[256];
   1.246 +	GetCmdArgString(Arguments, sizeof(Arguments));
   1.247 +
   1.248 +	decl String:arg[65];	
   1.249 +	len = BreakString(Arguments, arg, sizeof(arg));
   1.250 +
   1.251 +	new target = FindTarget(client, arg, true);
   1.252 +	if (target == -1)
   1.253 +	{
   1.254 +		return Plugin_Handled;
   1.255 +	}
   1.256 +
   1.257 +	decl String:s_time[12];
   1.258 +	if ((next_len = BreakString(Arguments[len], s_time, sizeof(s_time))) != -1)
   1.259 +	{
   1.260 +		len += next_len;
   1.261 +	}
   1.262 +	else
   1.263 +	{
   1.264 +		len = 0;
   1.265 +		Arguments[0] = '\0';
   1.266 +	}
   1.267 +
   1.268 +	new time = StringToInt(s_time);
   1.269 +
   1.270 +	PrepareBan(client, target, time, Arguments[len]);
   1.271 +
   1.272 +	return Plugin_Handled;
   1.273 +}