plugins/basebans/ban.sp
author David Anderson <danderson@mozilla.com>
Thu Aug 08 09:41:24 2013 -0700 (2013-08-08)
changeset 3977 fca2b54741ca
parent 3808 b5f4ea4d3736
child 4089 a4e4207da173
permissions -rw-r--r--
Refactor the JIT to use a newer, simpler macro assembler. (bug 5827, r=ann)
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basecommands
     5  * Functionality related to banning.
     6  *
     7  * SourceMod (C)2004-2008 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 PrepareBan(client, target, time, const String:reason[])
    35 {
    36 	new originalTarget = GetClientOfUserId(g_BanTargetUserId[client]);
    37 
    38 	if (originalTarget != target)
    39 	{
    40 		if (client == 0)
    41 		{
    42 			PrintToServer("[SM] %t", "Player no longer available");
    43 		}
    44 		else
    45 		{
    46 			PrintToChat(client, "[SM] %t", "Player no longer available");
    47 		}
    48 
    49 		return;
    50 	}
    51 
    52 	new String:name[32];
    53 	GetClientName(target, name, sizeof(name));
    54 
    55 	if (!time)
    56 	{
    57 		if (reason[0] == '\0')
    58 		{
    59 			ShowActivity(client, "%t", "Permabanned player", name);
    60 		} else {
    61 			ShowActivity(client, "%t", "Permabanned player reason", name, reason);
    62 		}
    63 	} else {
    64 		if (reason[0] == '\0')
    65 		{
    66 			ShowActivity(client, "%t", "Banned player", name, time);
    67 		} else {
    68 			ShowActivity(client, "%t", "Banned player reason", name, time, reason);
    69 		}
    70 	}
    71 
    72 	LogAction(client, target, "\"%L\" banned \"%L\" (minutes \"%d\") (reason \"%s\")", client, target, time, reason);
    73 
    74 	if (reason[0] == '\0')
    75 	{
    76 		BanClient(target, time, BANFLAG_AUTO, "Banned", "Banned", "sm_ban", client);
    77 	}
    78 	else
    79 	{
    80 		BanClient(target, time, BANFLAG_AUTO, reason, reason, "sm_ban", client);
    81 	}
    82 }
    83 
    84 DisplayBanTargetMenu(client)
    85 {
    86 	new Handle:menu = CreateMenu(MenuHandler_BanPlayerList);
    87 
    88 	decl String:title[100];
    89 	Format(title, sizeof(title), "%T:", "Ban player", client);
    90 	SetMenuTitle(menu, title);
    91 	SetMenuExitBackButton(menu, true);
    92 
    93 	AddTargetsToMenu2(menu, client, COMMAND_FILTER_NO_BOTS|COMMAND_FILTER_CONNECTED);
    94 
    95 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    96 }
    97 
    98 DisplayBanTimeMenu(client)
    99 {
   100 	new Handle:menu = CreateMenu(MenuHandler_BanTimeList);
   101 
   102 	decl String:title[100];
   103 	Format(title, sizeof(title), "%T: %N", "Ban player", client, g_BanTarget[client]);
   104 	SetMenuTitle(menu, title);
   105 	SetMenuExitBackButton(menu, true);
   106 
   107 	AddMenuItem(menu, "0", "Permanent");
   108 	AddMenuItem(menu, "10", "10 Minutes");
   109 	AddMenuItem(menu, "30", "30 Minutes");
   110 	AddMenuItem(menu, "60", "1 Hour");
   111 	AddMenuItem(menu, "240", "4 Hours");
   112 	AddMenuItem(menu, "1440", "1 Day");
   113 	AddMenuItem(menu, "10080", "1 Week");
   114 
   115 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
   116 }
   117 
   118 DisplayBanReasonMenu(client)
   119 {
   120 	new Handle:menu = CreateMenu(MenuHandler_BanReasonList);
   121 
   122 	decl String:title[100];
   123 	Format(title, sizeof(title), "%T: %N", "Ban reason", client, g_BanTarget[client]);
   124 	SetMenuTitle(menu, title);
   125 	SetMenuExitBackButton(menu, true);
   126 
   127 	/* :TODO: we should either remove this or make it configurable */
   128 
   129 	AddMenuItem(menu, "Abusive", "Abusive");
   130 	AddMenuItem(menu, "Racism", "Racism");
   131 	AddMenuItem(menu, "General cheating/exploits", "General cheating/exploits");
   132 	AddMenuItem(menu, "Wallhack", "Wallhack");
   133 	AddMenuItem(menu, "Aimbot", "Aimbot");
   134 	AddMenuItem(menu, "Speedhacking", "Speedhacking");
   135 	AddMenuItem(menu, "Mic spamming", "Mic spamming");
   136 	AddMenuItem(menu, "Admin disrespect", "Admin disrespect");
   137 	AddMenuItem(menu, "Camping", "Camping");
   138 	AddMenuItem(menu, "Team killing", "Team killing");
   139 	AddMenuItem(menu, "Unacceptable Spray", "Unacceptable Spray");
   140 	AddMenuItem(menu, "Breaking Server Rules", "Breaking Server Rules");
   141 	AddMenuItem(menu, "Other", "Other");
   142 
   143 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
   144 }
   145 
   146 public AdminMenu_Ban(Handle:topmenu,
   147 							  TopMenuAction:action,
   148 							  TopMenuObject:object_id,
   149 							  param,
   150 							  String:buffer[],
   151 							  maxlength)
   152 {
   153 	if (action == TopMenuAction_DisplayOption)
   154 	{
   155 		Format(buffer, maxlength, "%T", "Ban player", param);
   156 	}
   157 	else if (action == TopMenuAction_SelectOption)
   158 	{
   159 		DisplayBanTargetMenu(param);
   160 	}
   161 }
   162 
   163 public MenuHandler_BanReasonList(Handle:menu, MenuAction:action, param1, param2)
   164 {
   165 	if (action == MenuAction_End)
   166 	{
   167 		CloseHandle(menu);
   168 	}
   169 	else if (action == MenuAction_Cancel)
   170 	{
   171 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   172 		{
   173 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   174 		}
   175 	}
   176 	else if (action == MenuAction_Select)
   177 	{
   178 		decl String:info[64];
   179 
   180 		GetMenuItem(menu, param2, info, sizeof(info));
   181 
   182 		PrepareBan(param1, g_BanTarget[param1], g_BanTime[param1], info);
   183 	}
   184 }
   185 
   186 public MenuHandler_BanPlayerList(Handle:menu, MenuAction:action, param1, param2)
   187 {
   188 	if (action == MenuAction_End)
   189 	{
   190 		CloseHandle(menu);
   191 	}
   192 	else if (action == MenuAction_Cancel)
   193 	{
   194 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   195 		{
   196 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   197 		}
   198 	}
   199 	else if (action == MenuAction_Select)
   200 	{
   201 		decl String:info[32], String:name[32];
   202 		new userid, target;
   203 
   204 		GetMenuItem(menu, param2, info, sizeof(info), _, name, sizeof(name));
   205 		userid = StringToInt(info);
   206 
   207 		if ((target = GetClientOfUserId(userid)) == 0)
   208 		{
   209 			PrintToChat(param1, "[SM] %t", "Player no longer available");
   210 		}
   211 		else if (!CanUserTarget(param1, target))
   212 		{
   213 			PrintToChat(param1, "[SM] %t", "Unable to target");
   214 		}
   215 		else
   216 		{
   217 			g_BanTarget[param1] = target;
   218 			g_BanTargetUserId[param1] = userid;
   219 			DisplayBanTimeMenu(param1);
   220 		}
   221 	}
   222 }
   223 
   224 public MenuHandler_BanTimeList(Handle:menu, MenuAction:action, param1, param2)
   225 {
   226 	if (action == MenuAction_End)
   227 	{
   228 		CloseHandle(menu);
   229 	}
   230 	else if (action == MenuAction_Cancel)
   231 	{
   232 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   233 		{
   234 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   235 		}
   236 	}
   237 	else if (action == MenuAction_Select)
   238 	{
   239 		decl String:info[32];
   240 
   241 		GetMenuItem(menu, param2, info, sizeof(info));
   242 		g_BanTime[param1] = StringToInt(info);
   243 
   244 		DisplayBanReasonMenu(param1);
   245 	}
   246 }
   247 
   248 
   249 public Action:Command_Ban(client, args)
   250 {
   251 	if (args < 2)
   252 	{
   253 		ReplyToCommand(client, "[SM] Usage: sm_ban <#userid|name> <minutes|0> [reason]");
   254 		return Plugin_Handled;
   255 	}
   256 
   257 	decl len, next_len;
   258 	decl String:Arguments[256];
   259 	GetCmdArgString(Arguments, sizeof(Arguments));
   260 
   261 	decl String:arg[65];
   262 	len = BreakString(Arguments, arg, sizeof(arg));
   263 
   264 	new target = FindTarget(client, arg, true);
   265 	if (target == -1)
   266 	{
   267 		return Plugin_Handled;
   268 	}
   269 
   270 	decl String:s_time[12];
   271 	if ((next_len = BreakString(Arguments[len], s_time, sizeof(s_time))) != -1)
   272 	{
   273 		len += next_len;
   274 	}
   275 	else
   276 	{
   277 		len = 0;
   278 		Arguments[0] = '\0';
   279 	}
   280 
   281 	new time = StringToInt(s_time);
   282 
   283 	g_BanTargetUserId[client] = GetClientUserId(target);
   284 
   285 	PrepareBan(client, target, time, Arguments[len]);
   286 
   287 	return Plugin_Handled;
   288 }