plugins/basevotes/voteban.sp
author Nicholas Hastings <skamonkey@gmail.com>
Mon May 13 15:33:55 2013 -0400 (2013-05-13)
changeset 3914 ec79ea87c2e7
parent 3808 b5f4ea4d3736
permissions -rw-r--r--
One more dota build fix.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basevotes Plugin
     5  * Provides ban functionality
     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 DisplayVoteBanMenu(client, target)
    35 {
    36 	g_voteClient[VOTE_CLIENTID] = target;
    37 	g_voteClient[VOTE_USERID] = GetClientUserId(target);
    38 
    39 	GetClientName(target, g_voteInfo[VOTE_NAME], sizeof(g_voteInfo[]));
    40 	GetClientIP(target, g_voteInfo[VOTE_IP], sizeof(g_voteInfo[]));
    41 
    42 	LogAction(client, target, "\"%L\" initiated a ban vote against \"%L\"", client, target);
    43 	ShowActivity2(client, "[SM] ", "%t", "Initiated Vote Ban", g_voteInfo[VOTE_NAME]);
    44 
    45 	g_voteType = voteType:ban;
    46 	
    47 	g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
    48 	SetMenuTitle(g_hVoteMenu, "Voteban Player");
    49 	AddMenuItem(g_hVoteMenu, VOTE_YES, "Yes");
    50 	AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
    51 	SetMenuExitButton(g_hVoteMenu, false);
    52 	VoteMenuToAll(g_hVoteMenu, 20);
    53 }
    54 
    55 DisplayBanTargetMenu(client)
    56 {
    57 	new Handle:menu = CreateMenu(MenuHandler_Ban);
    58 	
    59 	decl String:title[100];
    60 	Format(title, sizeof(title), "%T:", "Ban vote", client);
    61 	SetMenuTitle(menu, title);
    62 	SetMenuExitBackButton(menu, true);
    63 	
    64 	AddTargetsToMenu(menu, client, false, false);
    65 	
    66 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    67 }
    68 
    69 public AdminMenu_VoteBan(Handle:topmenu, 
    70 							  TopMenuAction:action,
    71 							  TopMenuObject:object_id,
    72 							  param,
    73 							  String:buffer[],
    74 							  maxlength)
    75 {
    76 	if (action == TopMenuAction_DisplayOption)
    77 	{
    78 		Format(buffer, maxlength, "%T", "Ban vote", param);
    79 	}
    80 	else if (action == TopMenuAction_SelectOption)
    81 	{
    82 		DisplayBanTargetMenu(param);
    83 	}
    84 	else if (action == TopMenuAction_DrawOption)
    85 	{	
    86 		/* disable this option if a vote is already running */
    87 		buffer[0] = !IsNewVoteAllowed() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT;
    88 	}
    89 }
    90 
    91 public MenuHandler_Ban(Handle:menu, MenuAction:action, param1, param2)
    92 {
    93 	if (action == MenuAction_End)
    94 	{
    95 		CloseHandle(menu);
    96 	}
    97 	else if (action == MenuAction_Cancel)
    98 	{
    99 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   100 		{
   101 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   102 		}
   103 	}
   104 	else if (action == MenuAction_Select)
   105 	{
   106 		decl String:info[32], String:name[32];
   107 		new userid, target;
   108 		
   109 		GetMenuItem(menu, param2, info, sizeof(info), _, name, sizeof(name));
   110 		userid = StringToInt(info);
   111 
   112 		if ((target = GetClientOfUserId(userid)) == 0)
   113 		{
   114 			PrintToChat(param1, "[SM] %t", "Player no longer available");
   115 		}
   116 		else if (!CanUserTarget(param1, target))
   117 		{
   118 			PrintToChat(param1, "[SM] %t", "Unable to target");
   119 		}
   120 		else
   121 		{
   122 			g_voteArg[0] = '\0';
   123 			DisplayVoteBanMenu(param1, target);
   124 		}
   125 	}
   126 }
   127 
   128 public Action:Command_Voteban(client, args)
   129 {
   130 	if (args < 1)
   131 	{
   132 		ReplyToCommand(client, "[SM] Usage: sm_voteban <player> [reason]");
   133 		return Plugin_Handled;	
   134 	}
   135 	
   136 	if (IsVoteInProgress())
   137 	{
   138 		ReplyToCommand(client, "[SM] %t", "Vote in Progress");
   139 		return Plugin_Handled;
   140 	}	
   141 	
   142 	if (!TestVoteDelay(client))
   143 	{
   144 		return Plugin_Handled;
   145 	}
   146 	
   147 	decl String:text[256], String:arg[64];
   148 	GetCmdArgString(text, sizeof(text));
   149 	
   150 	new len = BreakString(text, arg, sizeof(arg));
   151 	
   152 	if (len != -1)
   153 	{
   154 		strcopy(g_voteArg, sizeof(g_voteArg), text[len]);
   155 	}
   156 	else
   157 	{
   158 		g_voteArg[0] = '\0';
   159 	}
   160 	
   161 	decl String:target_name[MAX_TARGET_LENGTH];
   162 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   163 	
   164 	if ((target_count = ProcessTargetString(
   165 			arg,
   166 			client,
   167 			target_list,
   168 			MAXPLAYERS,
   169 			COMMAND_FILTER_NO_MULTI|COMMAND_FILTER_NO_BOTS,
   170 			target_name,
   171 			sizeof(target_name),
   172 			tn_is_ml)) <= 0)
   173 	{
   174 		ReplyToTargetError(client, target_count);
   175 		return Plugin_Handled;
   176 	}
   177 
   178 	DisplayVoteBanMenu(client, target_list[0]);
   179 	
   180 	return Plugin_Handled;
   181 }