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