1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/plugins/basevotes/voteban.sp Sun Mar 30 07:00:22 2008 +0000
1.3 @@ -0,0 +1,182 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * =============================================================================
1.7 + * SourceMod Basevotes Plugin
1.8 + * Provides ban functionality
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: admin-flatfile.sp 1438 2007-09-16 03:45:06Z dvander $
1.35 + */
1.36 +
1.37 +DisplayVoteBanMenu(client, target)
1.38 +{
1.39 + g_voteClient[VOTE_CLIENTID] = target;
1.40 + g_voteClient[VOTE_USERID] = GetClientUserId(target);
1.41 +
1.42 + GetClientName(target, g_voteInfo[VOTE_NAME], sizeof(g_voteInfo[]));
1.43 + GetClientAuthString(target, g_voteInfo[VOTE_AUTHID], sizeof(g_voteInfo[]));
1.44 + GetClientIP(target, g_voteInfo[VOTE_IP], sizeof(g_voteInfo[]));
1.45 +
1.46 + LogAction(client, target, "\"%L\" initiated a ban vote against \"%L\"", client, target);
1.47 + ShowActivity2(client, "[SM] ", "%t", "Initiated Vote Ban", g_voteInfo[VOTE_NAME]);
1.48 +
1.49 + g_voteType = voteType:ban;
1.50 +
1.51 + g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
1.52 + SetMenuTitle(g_hVoteMenu, "Voteban Player");
1.53 + AddMenuItem(g_hVoteMenu, VOTE_YES, "Yes");
1.54 + AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
1.55 + SetMenuExitButton(g_hVoteMenu, false);
1.56 + VoteMenuToAll(g_hVoteMenu, 20);
1.57 +}
1.58 +
1.59 +DisplayBanTargetMenu(client)
1.60 +{
1.61 + new Handle:menu = CreateMenu(MenuHandler_Ban);
1.62 +
1.63 + decl String:title[100];
1.64 + Format(title, sizeof(title), "%T:", "Ban vote", client);
1.65 + SetMenuTitle(menu, title);
1.66 + SetMenuExitBackButton(menu, true);
1.67 +
1.68 + AddTargetsToMenu(menu, client, false, false);
1.69 +
1.70 + DisplayMenu(menu, client, MENU_TIME_FOREVER);
1.71 +}
1.72 +
1.73 +public AdminMenu_VoteBan(Handle:topmenu,
1.74 + TopMenuAction:action,
1.75 + TopMenuObject:object_id,
1.76 + param,
1.77 + String:buffer[],
1.78 + maxlength)
1.79 +{
1.80 + if (action == TopMenuAction_DisplayOption)
1.81 + {
1.82 + Format(buffer, maxlength, "%T", "Ban vote", param);
1.83 + }
1.84 + else if (action == TopMenuAction_SelectOption)
1.85 + {
1.86 + DisplayBanTargetMenu(param);
1.87 + }
1.88 + else if (action == TopMenuAction_DrawOption)
1.89 + {
1.90 + /* disable this option if a vote is already running */
1.91 + buffer[0] = !IsNewVoteAllowed() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT;
1.92 + }
1.93 +}
1.94 +
1.95 +public MenuHandler_Ban(Handle:menu, MenuAction:action, param1, param2)
1.96 +{
1.97 + if (action == MenuAction_End)
1.98 + {
1.99 + CloseHandle(menu);
1.100 + }
1.101 + else if (action == MenuAction_Cancel)
1.102 + {
1.103 + if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
1.104 + {
1.105 + DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
1.106 + }
1.107 + }
1.108 + else if (action == MenuAction_Select)
1.109 + {
1.110 + decl String:info[32], String:name[32];
1.111 + new userid, target;
1.112 +
1.113 + GetMenuItem(menu, param2, info, sizeof(info), _, name, sizeof(name));
1.114 + userid = StringToInt(info);
1.115 +
1.116 + if ((target = GetClientOfUserId(userid)) == 0)
1.117 + {
1.118 + PrintToChat(param1, "[SM] %t", "Player no longer available");
1.119 + }
1.120 + else if (!CanUserTarget(param1, target))
1.121 + {
1.122 + PrintToChat(param1, "[SM] %t", "Unable to target");
1.123 + }
1.124 + else
1.125 + {
1.126 + g_voteArg[0] = '\0';
1.127 + DisplayVoteBanMenu(param1, target);
1.128 + }
1.129 + }
1.130 +}
1.131 +
1.132 +public Action:Command_Voteban(client, args)
1.133 +{
1.134 + if (args < 1)
1.135 + {
1.136 + ReplyToCommand(client, "[SM] Usage: sm_voteban <player> [reason]");
1.137 + return Plugin_Handled;
1.138 + }
1.139 +
1.140 + if (IsVoteInProgress())
1.141 + {
1.142 + ReplyToCommand(client, "[SM] %t", "Vote in Progress");
1.143 + return Plugin_Handled;
1.144 + }
1.145 +
1.146 + if (!TestVoteDelay(client))
1.147 + {
1.148 + return Plugin_Handled;
1.149 + }
1.150 +
1.151 + decl String:text[256], String:arg[64];
1.152 + GetCmdArgString(text, sizeof(text));
1.153 +
1.154 + new len = BreakString(text, arg, sizeof(arg));
1.155 +
1.156 + if (len != -1)
1.157 + {
1.158 + strcopy(g_voteArg, sizeof(g_voteArg), text[len]);
1.159 + }
1.160 + else
1.161 + {
1.162 + g_voteArg[0] = '\0';
1.163 + }
1.164 +
1.165 + decl String:target_name[MAX_TARGET_LENGTH];
1.166 + decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
1.167 +
1.168 + if ((target_count = ProcessTargetString(
1.169 + arg,
1.170 + client,
1.171 + target_list,
1.172 + MAXPLAYERS,
1.173 + COMMAND_FILTER_NO_MULTI|COMMAND_FILTER_NO_BOTS,
1.174 + target_name,
1.175 + sizeof(target_name),
1.176 + tn_is_ml)) <= 0)
1.177 + {
1.178 + ReplyToTargetError(client, target_count);
1.179 + return Plugin_Handled;
1.180 + }
1.181 +
1.182 + DisplayVoteBanMenu(client, target_list[0]);
1.183 +
1.184 + return Plugin_Handled;
1.185 +}