3 * =============================================================================
4 * SourceMod Basecommands Plugin
5 * Provides kick functionality
7 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
8 * =============================================================================
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.
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
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/>.
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>.
34 PerformKick(client, target, const String:reason[])
36 LogAction(client, target, "\"%L\" kicked \"%L\" (reason \"%s\")", client, target, reason);
38 if (reason[0] == '\0')
40 KickClient(target, "%t", "Kicked by admin");
44 KickClient(target, "%s", reason);
48 DisplayKickMenu(client)
50 new Handle:menu = CreateMenu(MenuHandler_Kick);
52 decl String:title[100];
53 Format(title, sizeof(title), "%T:", "Kick player", client);
54 SetMenuTitle(menu, title);
55 SetMenuExitBackButton(menu, true);
57 AddTargetsToMenu(menu, client, false, false);
59 DisplayMenu(menu, client, MENU_TIME_FOREVER);
62 public AdminMenu_Kick(Handle:topmenu,
64 TopMenuObject:object_id,
69 if (action == TopMenuAction_DisplayOption)
71 Format(buffer, maxlength, "%T", "Kick player", param);
73 else if (action == TopMenuAction_SelectOption)
75 DisplayKickMenu(param);
79 public MenuHandler_Kick(Handle:menu, MenuAction:action, param1, param2)
81 if (action == MenuAction_End)
85 else if (action == MenuAction_Cancel)
87 if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
89 DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
92 else if (action == MenuAction_Select)
97 GetMenuItem(menu, param2, info, sizeof(info));
98 userid = StringToInt(info);
100 if ((target = GetClientOfUserId(userid)) == 0)
102 PrintToChat(param1, "[SM] %t", "Player no longer available");
104 else if (!CanUserTarget(param1, target))
106 PrintToChat(param1, "[SM] %t", "Unable to target");
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, "");
116 /* Re-draw the menu if they're still valid */
117 if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
119 DisplayKickMenu(param1);
124 public Action:Command_Kick(client, args)
128 ReplyToCommand(client, "[SM] Usage: sm_kick <#userid|name> [reason]");
129 return Plugin_Handled;
132 decl String:Arguments[256];
133 GetCmdArgString(Arguments, sizeof(Arguments));
136 new len = BreakString(Arguments, arg, sizeof(arg));
140 /* Safely null terminate */
145 decl String:target_name[MAX_TARGET_LENGTH];
146 decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
148 if ((target_count = ProcessTargetString(
153 COMMAND_FILTER_CONNECTED,
160 ShowActivity2(client, "[SM] ", "%t", "Kicked target", target_name);
164 ShowActivity2(client, "[SM] ", "%t", "Kicked target", "_s", target_name);
169 for (new i = 0; i < target_count; i++)
171 /* Kick everyone else first */
172 if (target_list[i] == client)
178 PerformKick(client, target_list[i], Arguments[len]);
184 PerformKick(client, client, Arguments[len]);
189 ReplyToTargetError(client, target_count);
192 return Plugin_Handled;