2014-10-31 05:25:23 +01:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
|
|
|
* =============================================================================
|
|
|
|
* SourceMod Basecommands
|
|
|
|
* Functionality related to banning.
|
|
|
|
*
|
|
|
|
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
|
|
|
|
* =============================================================================
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
2016-04-27 15:34:22 +02:00
|
|
|
void PrepareBan(int client, int target, int time, const char[] reason)
|
2014-10-31 05:25:23 +01:00
|
|
|
{
|
2016-04-27 15:34:22 +02:00
|
|
|
int originalTarget = GetClientOfUserId(g_BanTargetUserId[client]);
|
2014-10-31 05:25:23 +01:00
|
|
|
|
|
|
|
if (originalTarget != target)
|
|
|
|
{
|
|
|
|
if (client == 0)
|
|
|
|
{
|
|
|
|
PrintToServer("[SM] %t", "Player no longer available");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PrintToChat(client, "[SM] %t", "Player no longer available");
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-27 15:34:22 +02:00
|
|
|
char name[MAX_NAME_LENGTH];
|
2014-10-31 05:25:23 +01:00
|
|
|
GetClientName(target, name, sizeof(name));
|
|
|
|
|
|
|
|
if (!time)
|
|
|
|
{
|
|
|
|
if (reason[0] == '\0')
|
|
|
|
{
|
|
|
|
ShowActivity(client, "%t", "Permabanned player", name);
|
Update to sm_ban, sm_kick, & sm_map in chat with no args to display menu (#838)
This change makes it so /kick, /ban, and /map open the already created methods for displaying their menus when there are no args.
The reason for the feature is to take advantage of menus that already exist and to make the commands easier to use.
The client == 0 check prevents them from opening if it was ran via rcon, sm_rcon, or server command. Client auth is also checked because its a registered admin command.
Usage params will display if client == 0 and args < min
For example, a moderator wants to change a map, instead of running through the admin menu, they can instead type just /map to display available maps and choose one.
If a mod wants to quickly ban or kick someone without having to either run through the admin menu or type it out, they could then type the corresponding commands with no args to open the menus.
2018-09-04 01:41:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-31 05:25:23 +01:00
|
|
|
ShowActivity(client, "%t", "Permabanned player reason", name, reason);
|
|
|
|
}
|
Update to sm_ban, sm_kick, & sm_map in chat with no args to display menu (#838)
This change makes it so /kick, /ban, and /map open the already created methods for displaying their menus when there are no args.
The reason for the feature is to take advantage of menus that already exist and to make the commands easier to use.
The client == 0 check prevents them from opening if it was ran via rcon, sm_rcon, or server command. Client auth is also checked because its a registered admin command.
Usage params will display if client == 0 and args < min
For example, a moderator wants to change a map, instead of running through the admin menu, they can instead type just /map to display available maps and choose one.
If a mod wants to quickly ban or kick someone without having to either run through the admin menu or type it out, they could then type the corresponding commands with no args to open the menus.
2018-09-04 01:41:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-31 05:25:23 +01:00
|
|
|
if (reason[0] == '\0')
|
|
|
|
{
|
|
|
|
ShowActivity(client, "%t", "Banned player", name, time);
|
Update to sm_ban, sm_kick, & sm_map in chat with no args to display menu (#838)
This change makes it so /kick, /ban, and /map open the already created methods for displaying their menus when there are no args.
The reason for the feature is to take advantage of menus that already exist and to make the commands easier to use.
The client == 0 check prevents them from opening if it was ran via rcon, sm_rcon, or server command. Client auth is also checked because its a registered admin command.
Usage params will display if client == 0 and args < min
For example, a moderator wants to change a map, instead of running through the admin menu, they can instead type just /map to display available maps and choose one.
If a mod wants to quickly ban or kick someone without having to either run through the admin menu or type it out, they could then type the corresponding commands with no args to open the menus.
2018-09-04 01:41:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-31 05:25:23 +01:00
|
|
|
ShowActivity(client, "%t", "Banned player reason", name, time, reason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LogAction(client, target, "\"%L\" banned \"%L\" (minutes \"%d\") (reason \"%s\")", client, target, time, reason);
|
|
|
|
|
|
|
|
if (reason[0] == '\0')
|
|
|
|
{
|
|
|
|
BanClient(target, time, BANFLAG_AUTO, "Banned", "Banned", "sm_ban", client);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BanClient(target, time, BANFLAG_AUTO, reason, reason, "sm_ban", client);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-27 15:34:22 +02:00
|
|
|
void DisplayBanTargetMenu(int client)
|
2014-10-31 05:25:23 +01:00
|
|
|
{
|
2016-04-27 15:34:22 +02:00
|
|
|
Menu menu = new Menu(MenuHandler_BanPlayerList);
|
2014-10-31 05:25:23 +01:00
|
|
|
|
2016-04-27 15:34:22 +02:00
|
|
|
char title[100];
|
2014-10-31 05:25:23 +01:00
|
|
|
Format(title, sizeof(title), "%T:", "Ban player", client);
|
2014-11-16 01:30:45 +01:00
|
|
|
menu.SetTitle(title);
|
|
|
|
menu.ExitBackButton = true;
|
2014-10-31 05:25:23 +01:00
|
|
|
|
|
|
|
AddTargetsToMenu2(menu, client, COMMAND_FILTER_NO_BOTS|COMMAND_FILTER_CONNECTED);
|
|
|
|
|
2014-11-16 01:30:45 +01:00
|
|
|
menu.Display(client, MENU_TIME_FOREVER);
|
2014-10-31 05:25:23 +01:00
|
|
|
}
|
|
|
|
|
2016-04-27 15:34:22 +02:00
|
|
|
void DisplayBanTimeMenu(int client)
|
2014-10-31 05:25:23 +01:00
|
|
|
{
|
2016-04-27 15:34:22 +02:00
|
|
|
Menu menu = new Menu(MenuHandler_BanTimeList);
|
2014-10-31 05:25:23 +01:00
|
|
|
|
2016-04-27 15:34:22 +02:00
|
|
|
char title[100];
|
2014-10-31 05:25:23 +01:00
|
|
|
Format(title, sizeof(title), "%T: %N", "Ban player", client, g_BanTarget[client]);
|
2014-11-16 01:30:45 +01:00
|
|
|
menu.SetTitle(title);
|
|
|
|
menu.ExitBackButton = true;
|
|
|
|
|
|
|
|
menu.AddItem("0", "Permanent");
|
|
|
|
menu.AddItem("10", "10 Minutes");
|
|
|
|
menu.AddItem("30", "30 Minutes");
|
|
|
|
menu.AddItem("60", "1 Hour");
|
|
|
|
menu.AddItem("240", "4 Hours");
|
|
|
|
menu.AddItem("1440", "1 Day");
|
|
|
|
menu.AddItem("10080", "1 Week");
|
|
|
|
|
|
|
|
menu.Display(client, MENU_TIME_FOREVER);
|
2014-10-31 05:25:23 +01:00
|
|
|
}
|
|
|
|
|
2016-04-27 15:34:22 +02:00
|
|
|
void DisplayBanReasonMenu(int client)
|
2014-10-31 05:25:23 +01:00
|
|
|
{
|
2016-04-27 15:34:22 +02:00
|
|
|
Menu menu = new Menu(MenuHandler_BanReasonList);
|
2014-10-31 05:25:23 +01:00
|
|
|
|
2016-04-27 15:34:22 +02:00
|
|
|
char title[100];
|
2014-10-31 05:25:23 +01:00
|
|
|
Format(title, sizeof(title), "%T: %N", "Ban reason", client, g_BanTarget[client]);
|
2014-11-16 01:30:45 +01:00
|
|
|
menu.SetTitle(title);
|
|
|
|
menu.ExitBackButton = true;
|
2014-10-31 05:25:23 +01:00
|
|
|
|
|
|
|
//Add custom chat reason entry first
|
2014-11-16 01:30:45 +01:00
|
|
|
menu.AddItem("", "Custom reason (type in chat)");
|
2014-10-31 05:25:23 +01:00
|
|
|
|
|
|
|
//Loading configurable entries from the kv-file
|
2016-04-27 15:34:22 +02:00
|
|
|
char reasonName[100];
|
|
|
|
char reasonFull[255];
|
2014-10-31 05:25:23 +01:00
|
|
|
|
|
|
|
//Iterate through the kv-file
|
2014-10-31 04:55:02 +01:00
|
|
|
g_hKvBanReasons.GotoFirstSubKey(false);
|
2014-10-31 05:25:23 +01:00
|
|
|
do
|
|
|
|
{
|
2014-10-31 04:55:02 +01:00
|
|
|
g_hKvBanReasons.GetSectionName(reasonName, sizeof(reasonName));
|
|
|
|
g_hKvBanReasons.GetString(NULL_STRING, reasonFull, sizeof(reasonFull));
|
2014-10-31 05:25:23 +01:00
|
|
|
|
|
|
|
//Add entry
|
2014-11-16 01:30:45 +01:00
|
|
|
menu.AddItem(reasonFull, reasonName);
|
2014-10-31 05:25:23 +01:00
|
|
|
|
2014-10-31 04:55:02 +01:00
|
|
|
} while (g_hKvBanReasons.GotoNextKey(false));
|
2014-10-31 05:25:23 +01:00
|
|
|
|
|
|
|
//Reset kvHandle
|
2014-10-31 04:55:02 +01:00
|
|
|
g_hKvBanReasons.Rewind();
|
2014-10-31 05:25:23 +01:00
|
|
|
|
2014-11-16 01:30:45 +01:00
|
|
|
menu.Display(client, MENU_TIME_FOREVER);
|
2014-10-31 05:25:23 +01:00
|
|
|
}
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
public void AdminMenu_Ban(TopMenu topmenu,
|
2016-04-27 15:34:22 +02:00
|
|
|
TopMenuAction action,
|
|
|
|
TopMenuObject object_id,
|
|
|
|
int param,
|
|
|
|
char[] buffer,
|
|
|
|
int maxlength)
|
2014-10-31 05:25:23 +01:00
|
|
|
{
|
|
|
|
//Reset chat reason first
|
|
|
|
g_IsWaitingForChatReason[param] = false;
|
|
|
|
|
|
|
|
if (action == TopMenuAction_DisplayOption)
|
|
|
|
{
|
|
|
|
Format(buffer, maxlength, "%T", "Ban player", param);
|
|
|
|
}
|
|
|
|
else if (action == TopMenuAction_SelectOption)
|
|
|
|
{
|
|
|
|
DisplayBanTargetMenu(param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-27 15:34:22 +02:00
|
|
|
public int MenuHandler_BanReasonList(Menu menu, MenuAction action, int param1, int param2)
|
2014-10-31 05:25:23 +01:00
|
|
|
{
|
|
|
|
if (action == MenuAction_End)
|
|
|
|
{
|
2014-11-16 01:30:45 +01:00
|
|
|
delete menu;
|
2014-10-31 05:25:23 +01:00
|
|
|
}
|
|
|
|
else if (action == MenuAction_Cancel)
|
|
|
|
{
|
|
|
|
if (param2 == MenuCancel_ExitBack && hTopMenu)
|
|
|
|
{
|
|
|
|
hTopMenu.Display(param1, TopMenuPosition_LastCategory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (action == MenuAction_Select)
|
|
|
|
{
|
|
|
|
if(param2 == 0)
|
|
|
|
{
|
|
|
|
//Chat reason
|
|
|
|
g_IsWaitingForChatReason[param1] = true;
|
|
|
|
PrintToChat(param1, "[SM] %t", "Custom ban reason explanation", "sm_abortban");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-27 15:34:22 +02:00
|
|
|
char info[64];
|
2014-10-31 05:25:23 +01:00
|
|
|
|
2014-11-16 01:30:45 +01:00
|
|
|
menu.GetItem(param2, info, sizeof(info));
|
2014-10-31 05:25:23 +01:00
|
|
|
|
|
|
|
PrepareBan(param1, g_BanTarget[param1], g_BanTime[param1], info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-27 15:34:22 +02:00
|
|
|
public int MenuHandler_BanPlayerList(Menu menu, MenuAction action, int param1, int param2)
|
2014-10-31 05:25:23 +01:00
|
|
|
{
|
|
|
|
if (action == MenuAction_End)
|
|
|
|
{
|
2014-11-16 01:30:45 +01:00
|
|
|
delete menu;
|
2014-10-31 05:25:23 +01:00
|
|
|
}
|
|
|
|
else if (action == MenuAction_Cancel)
|
|
|
|
{
|
|
|
|
if (param2 == MenuCancel_ExitBack && hTopMenu)
|
|
|
|
{
|
|
|
|
hTopMenu.Display(param1, TopMenuPosition_LastCategory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (action == MenuAction_Select)
|
|
|
|
{
|
2016-04-27 15:34:22 +02:00
|
|
|
char info[32], name[32];
|
|
|
|
int userid, target;
|
2014-10-31 05:25:23 +01:00
|
|
|
|
2014-11-16 01:30:45 +01:00
|
|
|
menu.GetItem(param2, info, sizeof(info), _, name, sizeof(name));
|
2014-10-31 05:25:23 +01:00
|
|
|
userid = StringToInt(info);
|
|
|
|
|
|
|
|
if ((target = GetClientOfUserId(userid)) == 0)
|
|
|
|
{
|
|
|
|
PrintToChat(param1, "[SM] %t", "Player no longer available");
|
|
|
|
}
|
|
|
|
else if (!CanUserTarget(param1, target))
|
|
|
|
{
|
|
|
|
PrintToChat(param1, "[SM] %t", "Unable to target");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_BanTarget[param1] = target;
|
|
|
|
g_BanTargetUserId[param1] = userid;
|
|
|
|
DisplayBanTimeMenu(param1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-27 15:34:22 +02:00
|
|
|
public int MenuHandler_BanTimeList(Menu menu, MenuAction action, int param1, int param2)
|
2014-10-31 05:25:23 +01:00
|
|
|
{
|
|
|
|
if (action == MenuAction_End)
|
|
|
|
{
|
2014-11-16 01:30:45 +01:00
|
|
|
delete menu;
|
2014-10-31 05:25:23 +01:00
|
|
|
}
|
|
|
|
else if (action == MenuAction_Cancel)
|
|
|
|
{
|
|
|
|
if (param2 == MenuCancel_ExitBack && hTopMenu)
|
|
|
|
{
|
|
|
|
hTopMenu.Display(param1, TopMenuPosition_LastCategory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (action == MenuAction_Select)
|
|
|
|
{
|
2016-04-27 15:34:22 +02:00
|
|
|
char info[32];
|
2014-10-31 05:25:23 +01:00
|
|
|
|
2014-11-16 01:30:45 +01:00
|
|
|
menu.GetItem(param2, info, sizeof(info));
|
2014-10-31 05:25:23 +01:00
|
|
|
g_BanTime[param1] = StringToInt(info);
|
|
|
|
|
|
|
|
DisplayBanReasonMenu(param1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-27 15:34:22 +02:00
|
|
|
public Action Command_Ban(int client, int args)
|
2014-10-31 05:25:23 +01:00
|
|
|
{
|
|
|
|
if (args < 2)
|
|
|
|
{
|
Update to sm_ban, sm_kick, & sm_map in chat with no args to display menu (#838)
This change makes it so /kick, /ban, and /map open the already created methods for displaying their menus when there are no args.
The reason for the feature is to take advantage of menus that already exist and to make the commands easier to use.
The client == 0 check prevents them from opening if it was ran via rcon, sm_rcon, or server command. Client auth is also checked because its a registered admin command.
Usage params will display if client == 0 and args < min
For example, a moderator wants to change a map, instead of running through the admin menu, they can instead type just /map to display available maps and choose one.
If a mod wants to quickly ban or kick someone without having to either run through the admin menu or type it out, they could then type the corresponding commands with no args to open the menus.
2018-09-04 01:41:22 +02:00
|
|
|
if ((GetCmdReplySource() == SM_REPLY_TO_CHAT) && (client != 0) && (args == 0))
|
|
|
|
{
|
|
|
|
DisplayBanTargetMenu(client);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ReplyToCommand(client, "[SM] Usage: sm_ban <#userid|name> <minutes|0> [reason]");
|
|
|
|
}
|
|
|
|
|
2014-10-31 05:25:23 +01:00
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
2016-04-27 15:34:22 +02:00
|
|
|
int len, next_len;
|
|
|
|
char Arguments[256];
|
2014-10-31 05:25:23 +01:00
|
|
|
GetCmdArgString(Arguments, sizeof(Arguments));
|
|
|
|
|
2016-04-27 15:34:22 +02:00
|
|
|
char arg[65];
|
2014-10-31 05:25:23 +01:00
|
|
|
len = BreakString(Arguments, arg, sizeof(arg));
|
|
|
|
|
2016-04-27 15:34:22 +02:00
|
|
|
int target = FindTarget(client, arg, true);
|
2014-10-31 05:25:23 +01:00
|
|
|
if (target == -1)
|
|
|
|
{
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
2016-04-27 15:34:22 +02:00
|
|
|
char s_time[12];
|
2014-10-31 05:25:23 +01:00
|
|
|
if ((next_len = BreakString(Arguments[len], s_time, sizeof(s_time))) != -1)
|
|
|
|
{
|
|
|
|
len += next_len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len = 0;
|
|
|
|
Arguments[0] = '\0';
|
|
|
|
}
|
|
|
|
|
2016-04-27 15:34:22 +02:00
|
|
|
int time = StringToInt(s_time);
|
2014-10-31 05:25:23 +01:00
|
|
|
|
|
|
|
g_BanTargetUserId[client] = GetClientUserId(target);
|
|
|
|
|
|
|
|
PrepareBan(client, target, time, Arguments[len]);
|
|
|
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|