plugins/basecommands/kick.sp
author David Anderson <dvander@alliedmods.net>
Fri Dec 14 05:54:36 2007 +0000 (2007-12-14)
changeset 1791 38e83ea09a24
parent 1789 55172f6df9a4
child 1947 e73a1e51833b
permissions -rw-r--r--
fixed amb1282 - elev1.wav is cstrike only
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basecommands Plugin
     5  * Provides kick functionality
     6  *
     7  * SourceMod (C)2004-2007 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 PerformKick(client, target, const String:reason[])
    35 {
    36 	LogAction(client, target, "\"%L\" kicked \"%L\" (reason \"%s\")", client, target, reason);
    37 
    38 	if (reason[0] == '\0')
    39 	{
    40 		KickClient(target, "%t", "Kicked by admin");
    41 	}
    42 	else
    43 	{
    44 		KickClient(target, "%s", reason);
    45 	}
    46 }
    47 
    48 DisplayKickMenu(client)
    49 {
    50 	new Handle:menu = CreateMenu(MenuHandler_Kick);
    51 	
    52 	decl String:title[100];
    53 	Format(title, sizeof(title), "%T:", "Kick player", client);
    54 	SetMenuTitle(menu, title);
    55 	SetMenuExitBackButton(menu, true);
    56 	
    57 	AddTargetsToMenu(menu, client, false, false);
    58 	
    59 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    60 }
    61 
    62 public AdminMenu_Kick(Handle:topmenu, 
    63 					  TopMenuAction:action,
    64 					  TopMenuObject:object_id,
    65 					  param,
    66 					  String:buffer[],
    67 					  maxlength)
    68 {
    69 	if (action == TopMenuAction_DisplayOption)
    70 	{
    71 		Format(buffer, maxlength, "%T", "Kick player", param);
    72 	}
    73 	else if (action == TopMenuAction_SelectOption)
    74 	{
    75 		DisplayKickMenu(param);
    76 	}
    77 }
    78 
    79 public MenuHandler_Kick(Handle:menu, MenuAction:action, param1, param2)
    80 {
    81 	if (action == MenuAction_End)
    82 	{
    83 		CloseHandle(menu);
    84 	}
    85 	else if (action == MenuAction_Cancel)
    86 	{
    87 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
    88 		{
    89 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
    90 		}
    91 	}
    92 	else if (action == MenuAction_Select)
    93 	{
    94 		decl String:info[32];
    95 		new userid, target;
    96 		
    97 		GetMenuItem(menu, param2, info, sizeof(info));
    98 		userid = StringToInt(info);
    99 
   100 		if ((target = GetClientOfUserId(userid)) == 0)
   101 		{
   102 			PrintToChat(param1, "[SM] %t", "Player no longer available");
   103 		}
   104 		else if (!CanUserTarget(param1, target))
   105 		{
   106 			PrintToChat(param1, "[SM] %t", "Unable to target");
   107 		}
   108 		else
   109 		{
   110 			decl String:name[MAX_NAME_LENGTH];
   111 			GetClientName(target, name, sizeof(name));
   112 			ShowActivity2(param1, "[SM] ", "%t", "Kicked target", "_s", name);
   113 			PerformKick(param1, target, "");
   114 		}
   115 		
   116 		/* Re-draw the menu if they're still valid */
   117 		if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
   118 		{
   119 			DisplayKickMenu(param1);
   120 		}
   121 	}
   122 }
   123 
   124 public Action:Command_Kick(client, args)
   125 {
   126 	if (args < 1)
   127 	{
   128 		ReplyToCommand(client, "[SM] Usage: sm_kick <#userid|name> [reason]");
   129 		return Plugin_Handled;
   130 	}
   131 
   132 	decl String:Arguments[256];
   133 	GetCmdArgString(Arguments, sizeof(Arguments));
   134 
   135 	decl String:arg[65];
   136 	new len = BreakString(Arguments, arg, sizeof(arg));
   137 	
   138 	if (len == -1)
   139 	{
   140 		/* Safely null terminate */
   141 		len = 0;
   142 		Arguments[0] = '\0';
   143 	}
   144 
   145 	decl String:target_name[MAX_TARGET_LENGTH];
   146 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   147 	
   148 	if ((target_count = ProcessTargetString(
   149 			arg,
   150 			client, 
   151 			target_list, 
   152 			MAXPLAYERS, 
   153 			COMMAND_FILTER_CONNECTED,
   154 			target_name,
   155 			sizeof(target_name),
   156 			tn_is_ml)) > 0)
   157 	{
   158 		if (tn_is_ml)
   159 		{
   160 			ShowActivity2(client, "[SM] ", "%t", "Kicked target", target_name);
   161 		}
   162 		else
   163 		{
   164 			ShowActivity2(client, "[SM] ", "%t", "Kicked target", "_s", target_name);
   165 		}
   166 		
   167 		new kick_self = 0;
   168 		
   169 		for (new i = 0; i < target_count; i++)
   170 		{
   171 			/* Kick everyone else first */
   172 			if (target_list[i] == client)
   173 			{
   174 				kick_self = client;
   175 			}
   176 			else
   177 			{
   178 				PerformKick(client, target_list[i], Arguments[len]);
   179 			}
   180 		}
   181 		
   182 		if (kick_self)
   183 		{
   184 			PerformKick(client, client, Arguments[len]);
   185 		}
   186 	}
   187 	else
   188 	{
   189 		ReplyToTargetError(client, target_count);
   190 	}
   191 
   192 	return Plugin_Handled;
   193 }