Add support for customizing ban reasons in basebans.sp (bug 5762, r=psychonic).
This commit is contained in:
		
							parent
							
								
									693c4024d6
								
							
						
					
					
						commit
						fd9e657196
					
				@ -52,18 +52,40 @@ new g_BanTarget[MAXPLAYERS+1];
 | 
			
		||||
new g_BanTargetUserId[MAXPLAYERS+1];
 | 
			
		||||
new g_BanTime[MAXPLAYERS+1];
 | 
			
		||||
 | 
			
		||||
new g_IsWaitingForChatReason[MAXPLAYERS+1];
 | 
			
		||||
new Handle:g_hKvBanReasons;
 | 
			
		||||
new String:g_BanReasonsPath[PLATFORM_MAX_PATH];
 | 
			
		||||
 | 
			
		||||
#include "basebans/ban.sp"
 | 
			
		||||
 | 
			
		||||
public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
 | 
			
		||||
{
 | 
			
		||||
	BuildPath(Path_SM, g_BanReasonsPath, sizeof(g_BanReasonsPath), "configs/banreasons.txt");
 | 
			
		||||
	if(LoadBanReasons())
 | 
			
		||||
	{
 | 
			
		||||
		return APLRes_Success;
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		Format(error, err_max, "Couldn't load file %s: See log for details.", g_BanReasonsPath);
 | 
			
		||||
		return APLRes_Failure;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public OnPluginStart()
 | 
			
		||||
{
 | 
			
		||||
	LoadTranslations("common.phrases");
 | 
			
		||||
	LoadTranslations("basebans.phrases");
 | 
			
		||||
	LoadTranslations("core.phrases");
 | 
			
		||||
 | 
			
		||||
	RegAdminCmd("sm_ban", Command_Ban, ADMFLAG_BAN, "sm_ban <#userid|name> <minutes|0> [reason]");
 | 
			
		||||
	RegAdminCmd("sm_unban", Command_Unban, ADMFLAG_UNBAN, "sm_unban <steamid|ip>");
 | 
			
		||||
	RegAdminCmd("sm_addban", Command_AddBan, ADMFLAG_RCON, "sm_addban <time> <steamid> [reason]");
 | 
			
		||||
	RegAdminCmd("sm_banip", Command_BanIp, ADMFLAG_BAN, "sm_banip <ip|#userid|name> <time> [reason]");
 | 
			
		||||
	
 | 
			
		||||
	//This to manage custom ban reason messages
 | 
			
		||||
	RegConsoleCmd("sm_abortban", Command_AbortBan, "sm_abortban");
 | 
			
		||||
	
 | 
			
		||||
	/* Account for late loading */
 | 
			
		||||
	new Handle:topmenu;
 | 
			
		||||
	if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
 | 
			
		||||
@ -72,6 +94,62 @@ public OnPluginStart()
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public OnPluginEnd()
 | 
			
		||||
{
 | 
			
		||||
	//Close kv-handle
 | 
			
		||||
	if(g_hKvBanReasons != INVALID_HANDLE)
 | 
			
		||||
	{
 | 
			
		||||
		CloseHandle(g_hKvBanReasons);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public OnMapStart()
 | 
			
		||||
{
 | 
			
		||||
	//(Re-)Load BanReasons
 | 
			
		||||
	if(g_hKvBanReasons != INVALID_HANDLE)
 | 
			
		||||
	{
 | 
			
		||||
		CloseHandle(g_hKvBanReasons);
 | 
			
		||||
	}
 | 
			
		||||
	if(!LoadBanReasons())
 | 
			
		||||
	{
 | 
			
		||||
		SetFailState("Error trying to load or parse %s: See logfile for details", g_BanReasonsPath);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public OnClientDisconnect(client)
 | 
			
		||||
{
 | 
			
		||||
	g_IsWaitingForChatReason[client] = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public bool:LoadBanReasons()
 | 
			
		||||
{
 | 
			
		||||
	g_hKvBanReasons = CreateKeyValues("banreasons");
 | 
			
		||||
	if(FileToKeyValues(g_hKvBanReasons, g_BanReasonsPath))
 | 
			
		||||
	{
 | 
			
		||||
		decl String:sectionName[255];
 | 
			
		||||
		if(!KvGetSectionName(g_hKvBanReasons, sectionName, sizeof(sectionName)))
 | 
			
		||||
		{
 | 
			
		||||
			LogMessage("Error in %s: File corrupt or in the wrong format", g_BanReasonsPath);
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		if(strcmp(sectionName, "banreasons") != 0)
 | 
			
		||||
		{
 | 
			
		||||
			LogMessage("Error in %s: Couldn't find 'banreasons'", g_BanReasonsPath);
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		//Reset kvHandle
 | 
			
		||||
		KvRewind(g_hKvBanReasons);
 | 
			
		||||
		
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		LogMessage("Error in %s: File not found, corrupt or in the wrong format", g_BanReasonsPath);
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public OnAdminMenuReady(Handle:topmenu)
 | 
			
		||||
{
 | 
			
		||||
	/* Block us from being called twice */
 | 
			
		||||
@ -295,3 +373,39 @@ public Action:Command_Unban(client, args)
 | 
			
		||||
	return Plugin_Handled;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public Action:Command_AbortBan(client, args)
 | 
			
		||||
{
 | 
			
		||||
	if(!CheckCommandAccess(client, "sm_ban", ADMFLAG_BAN))
 | 
			
		||||
	{
 | 
			
		||||
		ReplyToCommand(client, "[SM] %t", "No Access");
 | 
			
		||||
		return Plugin_Handled;
 | 
			
		||||
	}
 | 
			
		||||
	if(g_IsWaitingForChatReason[client])
 | 
			
		||||
	{
 | 
			
		||||
		g_IsWaitingForChatReason[client] = false;
 | 
			
		||||
		ReplyToCommand(client, "[SM] %t", "AbortBan applied successfully");
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		ReplyToCommand(client, "[SM] %t", "AbortBan not waiting for custom reason");
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	return Plugin_Handled;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public Action:OnClientSayCommand(client, const String:command[], const String:sArgs[])
 | 
			
		||||
{
 | 
			
		||||
	if(g_IsWaitingForChatReason[client])
 | 
			
		||||
	{
 | 
			
		||||
		g_IsWaitingForChatReason[client] = false;
 | 
			
		||||
		
 | 
			
		||||
		decl String:message[192];		
 | 
			
		||||
		GetCmdArgString(message, sizeof(message));
 | 
			
		||||
		StripQuotes(message);
 | 
			
		||||
		
 | 
			
		||||
		PrepareBan(client, g_BanTarget[client], g_BanTime[client], message);
 | 
			
		||||
		
 | 
			
		||||
		return Plugin_Handled;
 | 
			
		||||
	}
 | 
			
		||||
	return Plugin_Continue;
 | 
			
		||||
}
 | 
			
		||||
@ -124,21 +124,27 @@ DisplayBanReasonMenu(client)
 | 
			
		||||
	SetMenuTitle(menu, title);
 | 
			
		||||
	SetMenuExitBackButton(menu, true);
 | 
			
		||||
	
 | 
			
		||||
	/* :TODO: we should either remove this or make it configurable */
 | 
			
		||||
	//Add custom chat reason entry first
 | 
			
		||||
	AddMenuItem(menu, "", "Custom reason (type in chat)");
 | 
			
		||||
	
 | 
			
		||||
	AddMenuItem(menu, "Abusive", "Abusive");
 | 
			
		||||
	AddMenuItem(menu, "Racism", "Racism");
 | 
			
		||||
	AddMenuItem(menu, "General cheating/exploits", "General cheating/exploits");
 | 
			
		||||
	AddMenuItem(menu, "Wallhack", "Wallhack");
 | 
			
		||||
	AddMenuItem(menu, "Aimbot", "Aimbot");
 | 
			
		||||
	AddMenuItem(menu, "Speedhacking", "Speedhacking");
 | 
			
		||||
	AddMenuItem(menu, "Mic spamming", "Mic spamming");
 | 
			
		||||
	AddMenuItem(menu, "Admin disrespect", "Admin disrespect");
 | 
			
		||||
	AddMenuItem(menu, "Camping", "Camping");
 | 
			
		||||
	AddMenuItem(menu, "Team killing", "Team killing");
 | 
			
		||||
	AddMenuItem(menu, "Unacceptable Spray", "Unacceptable Spray");
 | 
			
		||||
	AddMenuItem(menu, "Breaking Server Rules", "Breaking Server Rules");
 | 
			
		||||
	AddMenuItem(menu, "Other", "Other");
 | 
			
		||||
	//Loading configurable entries from the kv-file
 | 
			
		||||
	decl String:reasonName[100];
 | 
			
		||||
	decl String:reasonFull[255];
 | 
			
		||||
	
 | 
			
		||||
	//Iterate through the kv-file
 | 
			
		||||
	KvGotoFirstSubKey(g_hKvBanReasons, false);
 | 
			
		||||
	do
 | 
			
		||||
	{
 | 
			
		||||
		KvGetSectionName(g_hKvBanReasons, reasonName, sizeof(reasonName));
 | 
			
		||||
		KvGetString(g_hKvBanReasons, NULL_STRING, reasonFull, sizeof(reasonFull));
 | 
			
		||||
		
 | 
			
		||||
		//Add entry
 | 
			
		||||
		AddMenuItem(menu, reasonFull, reasonName);
 | 
			
		||||
		
 | 
			
		||||
	} while (KvGotoNextKey(g_hKvBanReasons, false));
 | 
			
		||||
	
 | 
			
		||||
	//Reset kvHandle
 | 
			
		||||
	KvRewind(g_hKvBanReasons);
 | 
			
		||||
 | 
			
		||||
	DisplayMenu(menu, client, MENU_TIME_FOREVER);
 | 
			
		||||
}
 | 
			
		||||
@ -150,6 +156,9 @@ public AdminMenu_Ban(Handle:topmenu,
 | 
			
		||||
							  String:buffer[],
 | 
			
		||||
							  maxlength)
 | 
			
		||||
{
 | 
			
		||||
	//Reset chat reason first
 | 
			
		||||
	g_IsWaitingForChatReason[param] = false;
 | 
			
		||||
	
 | 
			
		||||
	if (action == TopMenuAction_DisplayOption)
 | 
			
		||||
	{
 | 
			
		||||
		Format(buffer, maxlength, "%T", "Ban player", param);
 | 
			
		||||
@ -174,6 +183,14 @@ public MenuHandler_BanReasonList(Handle:menu, MenuAction:action, param1, param2)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	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
 | 
			
		||||
		{
 | 
			
		||||
			decl String:info[64];
 | 
			
		||||
			
 | 
			
		||||
@ -181,6 +198,7 @@ public MenuHandler_BanReasonList(Handle:menu, MenuAction:action, param1, param2)
 | 
			
		||||
			
 | 
			
		||||
			PrepareBan(param1, g_BanTarget[param1], g_BanTime[param1], info);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public MenuHandler_BanPlayerList(Handle:menu, MenuAction:action, param1, param2)
 | 
			
		||||
 | 
			
		||||
@ -49,4 +49,20 @@
 | 
			
		||||
	{
 | 
			
		||||
		"en"			"You cannot ban that IP address."
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	"Custom ban reason explanation"
 | 
			
		||||
	{
 | 
			
		||||
		"#format"		"{1:s}"
 | 
			
		||||
		"en"			"Enter the reason as a chat message. Use {1} to abort this."
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	"AbortBan applied successfully"
 | 
			
		||||
	{
 | 
			
		||||
		"en"			"Ban aborted."
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	"AbortBan not waiting for custom reason"
 | 
			
		||||
	{
 | 
			
		||||
		"en"			"Not waiting for a ban reason to be typed in, no ban to abort."
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user