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