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_BanTargetUserId[MAXPLAYERS+1];
 | 
				
			||||||
new g_BanTime[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"
 | 
					#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()
 | 
					public OnPluginStart()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	LoadTranslations("common.phrases");
 | 
						LoadTranslations("common.phrases");
 | 
				
			||||||
	LoadTranslations("basebans.phrases");
 | 
						LoadTranslations("basebans.phrases");
 | 
				
			||||||
 | 
						LoadTranslations("core.phrases");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	RegAdminCmd("sm_ban", Command_Ban, ADMFLAG_BAN, "sm_ban <#userid|name> <minutes|0> [reason]");
 | 
						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_unban", Command_Unban, ADMFLAG_UNBAN, "sm_unban <steamid|ip>");
 | 
				
			||||||
	RegAdminCmd("sm_addban", Command_AddBan, ADMFLAG_RCON, "sm_addban <time> <steamid> [reason]");
 | 
						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]");
 | 
						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 */
 | 
						/* Account for late loading */
 | 
				
			||||||
	new Handle:topmenu;
 | 
						new Handle:topmenu;
 | 
				
			||||||
	if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
 | 
						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)
 | 
					public OnAdminMenuReady(Handle:topmenu)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/* Block us from being called twice */
 | 
						/* Block us from being called twice */
 | 
				
			||||||
@ -295,3 +373,39 @@ public Action:Command_Unban(client, args)
 | 
				
			|||||||
	return Plugin_Handled;
 | 
						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;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -123,22 +123,28 @@ DisplayBanReasonMenu(client)
 | 
				
			|||||||
	Format(title, sizeof(title), "%T: %N", "Ban reason", client, g_BanTarget[client]);
 | 
						Format(title, sizeof(title), "%T: %N", "Ban reason", client, g_BanTarget[client]);
 | 
				
			||||||
	SetMenuTitle(menu, title);
 | 
						SetMenuTitle(menu, title);
 | 
				
			||||||
	SetMenuExitBackButton(menu, true);
 | 
						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");
 | 
						//Loading configurable entries from the kv-file
 | 
				
			||||||
	AddMenuItem(menu, "General cheating/exploits", "General cheating/exploits");
 | 
						decl String:reasonName[100];
 | 
				
			||||||
	AddMenuItem(menu, "Wallhack", "Wallhack");
 | 
						decl String:reasonFull[255];
 | 
				
			||||||
	AddMenuItem(menu, "Aimbot", "Aimbot");
 | 
						
 | 
				
			||||||
	AddMenuItem(menu, "Speedhacking", "Speedhacking");
 | 
						//Iterate through the kv-file
 | 
				
			||||||
	AddMenuItem(menu, "Mic spamming", "Mic spamming");
 | 
						KvGotoFirstSubKey(g_hKvBanReasons, false);
 | 
				
			||||||
	AddMenuItem(menu, "Admin disrespect", "Admin disrespect");
 | 
						do
 | 
				
			||||||
	AddMenuItem(menu, "Camping", "Camping");
 | 
						{
 | 
				
			||||||
	AddMenuItem(menu, "Team killing", "Team killing");
 | 
							KvGetSectionName(g_hKvBanReasons, reasonName, sizeof(reasonName));
 | 
				
			||||||
	AddMenuItem(menu, "Unacceptable Spray", "Unacceptable Spray");
 | 
							KvGetString(g_hKvBanReasons, NULL_STRING, reasonFull, sizeof(reasonFull));
 | 
				
			||||||
	AddMenuItem(menu, "Breaking Server Rules", "Breaking Server Rules");
 | 
							
 | 
				
			||||||
	AddMenuItem(menu, "Other", "Other");
 | 
							//Add entry
 | 
				
			||||||
 | 
							AddMenuItem(menu, reasonFull, reasonName);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
						} while (KvGotoNextKey(g_hKvBanReasons, false));
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						//Reset kvHandle
 | 
				
			||||||
 | 
						KvRewind(g_hKvBanReasons);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DisplayMenu(menu, client, MENU_TIME_FOREVER);
 | 
						DisplayMenu(menu, client, MENU_TIME_FOREVER);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -150,6 +156,9 @@ public AdminMenu_Ban(Handle:topmenu,
 | 
				
			|||||||
							  String:buffer[],
 | 
												  String:buffer[],
 | 
				
			||||||
							  maxlength)
 | 
												  maxlength)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						//Reset chat reason first
 | 
				
			||||||
 | 
						g_IsWaitingForChatReason[param] = false;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	if (action == TopMenuAction_DisplayOption)
 | 
						if (action == TopMenuAction_DisplayOption)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		Format(buffer, maxlength, "%T", "Ban player", param);
 | 
							Format(buffer, maxlength, "%T", "Ban player", param);
 | 
				
			||||||
@ -175,11 +184,20 @@ public MenuHandler_BanReasonList(Handle:menu, MenuAction:action, param1, param2)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	else if (action == MenuAction_Select)
 | 
						else if (action == MenuAction_Select)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		decl String:info[64];
 | 
							if(param2 == 0)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
		GetMenuItem(menu, param2, info, sizeof(info));
 | 
								//Chat reason
 | 
				
			||||||
 | 
								g_IsWaitingForChatReason[param1] = true;
 | 
				
			||||||
		PrepareBan(param1, g_BanTarget[param1], g_BanTime[param1], info);
 | 
								PrintToChat(param1, "[SM] %t", "Custom ban reason explanation", "sm_abortban");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								decl String:info[64];
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								GetMenuItem(menu, param2, info, sizeof(info));
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								PrepareBan(param1, g_BanTarget[param1], g_BanTime[param1], info);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -49,4 +49,20 @@
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		"en"			"You cannot ban that IP address."
 | 
							"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