diff --git a/configs/sm_limit_ban_duration.ini b/configs/sm_limit_ban_duration.ini new file mode 100644 index 0000000..4c3084e --- /dev/null +++ b/configs/sm_limit_ban_duration.ini @@ -0,0 +1,175 @@ +"Limit_Ban_Durations" +{ + //-=-=-=-=-=-=-=-=-=-=-=-=-= + //"#_of_minutes" + //{ + // "override" "Limit_Ban_Duration" + // "flags" "flag1,flag2,flag3" + // "display" "X Minutes/Hours/Seconds/Years/Months/Jiggawatts" + //} + //-=-=-=-=-=-=-=-=-=-=-=-=-= + //- #_of_minutes is the maximum value for that rank. If you give an admin access to "5", they can ban up to 5 minutes, but no more. + // + //- "0" seconds indicates a permanent punishment. Only one "0" entry will be considered. + // + //- Both "override" and "flags" definitions are necessary when restricting a specific duration. Using one without the other will result in undesired behavior. + // - You're not required to use the "override" or even have Overrides set up on your server, but the definition is necessary for the method being used. + // - When in doubt, just use an override of "Limit_Ban_Duration". Set it and forget it the saying goes! + // - "flags" are checked when the user does not have access to the provided "override", so a bogus override allows for just flag usage. + // - When specifying multiple flags, users must possess all flags to access the specific duration. + // - For example, "flags" "a,b,c" will require the user possess all three flags. + // + //- An "override" and "flags" definition of "" will result in no restriction being placed upon that length. + // - Do not do silly things such as block off "5" minutes yet allow "15" minutes; the plugin will durations arrange times from low to high and assumes you're not an idiot. + // + //- The "display" parameter is displayed to clients when accessing the ban parameter is a modified ban plugin. + //-=-=-=-=-=-=-=-=-=-=-=-=-= + + "5" + { + "override" "" + "flags" "" + + "display" "5 Minutes" + } + "10" + { + "override" "" + "flags" "" + + "display" "10 Minutes" + } + "15" + { + "override" "" + "flags" "" + + "display" "15 Minutes" + } + "30" + { + "override" "" + "flags" "" + + "display" "30 Minutes" + } + "45" + { + "override" "" + "flags" "" + + "display" "45 Minutes" + } + "60" + { + "override" "" + "flags" "" + + "display" "60 Minutes" + } + "120" + { + "override" "" + "flags" "" + + "display" "2 Hours" + } + "180" + { + "override" "" + "flags" "" + + "display" "3 Hours" + } + "360" + { + "override" "" + "flags" "" + + "display" "6 Hours" + } + "720" + { + "override" "" + "flags" "" + + "display" "12 Hours" + } + "1440" + { + "override" "" + "flags" "" + + "display" "24 Hours" + } + "2880" + { + "override" "" + "flags" "" + + "display" "2 Days" + } + "4320" + { + "override" "" + "flags" "" + + "display" "3 Days" + } + "5760" + { + "override" "" + "flags" "" + + "display" "4 Days" + } + "7200" + { + "override" "" + "flags" "" + + "display" "5 Days" + } + "8640" + { + "override" "" + "flags" "" + + "display" "6 Days" + } + "10080" + { + "override" "" + "flags" "" + + "display" "7 Days" + } + "20160" + { + "override" "" + "flags" "" + + "display" "2 Weeks" + } + "30240" + { + "override" "" + "flags" "" + + "display" "3 Weeks" + } + "40320" + { + "override" "" + "flags" "" + + "display" "4 Weeks" + } + "0" + { + "override" "" + "flags" "" + + "display" "Permanent" + } +} \ No newline at end of file diff --git a/plugins/lbd_basebans.smx b/plugins/lbd_basebans.smx new file mode 100644 index 0000000..5e4b4d4 Binary files /dev/null and b/plugins/lbd_basebans.smx differ diff --git a/plugins/lbd_sbpp_main.smx b/plugins/lbd_sbpp_main.smx new file mode 100644 index 0000000..3f0e474 Binary files /dev/null and b/plugins/lbd_sbpp_main.smx differ diff --git a/plugins/sm_limit_ban_duration.smx b/plugins/sm_limit_ban_duration.smx new file mode 100644 index 0000000..606c2e9 Binary files /dev/null and b/plugins/sm_limit_ban_duration.smx differ diff --git a/scripting/include/sm_limit_ban_duration.inc b/scripting/include/sm_limit_ban_duration.inc new file mode 100644 index 0000000..a224c98 --- /dev/null +++ b/scripting/include/sm_limit_ban_duration.inc @@ -0,0 +1,65 @@ +#if defined _limit_ban_included + #endinput +#endif +#define _limit_ban_included + +#define MAX_BAN_DURATIONS 32 + +/********************************************************* + * Returns the current number of defined ban lengths. + * + * @return The number of ban lengths defined. + *********************************************************/ +native LimitBan_GetSize(); + +/********************************************************* + * Returns permission for a specified ban length index. + * + * @param index The specific index to retrieve permission for. + * @param client The client to check access for. + * + * @return True if the client has access; False if disabled or no access. + *********************************************************/ +native LimitBan_GetAccess(index, client); + +/********************************************************* + * Provides access to the word form of defined ban lengths. + * + * @param index The specific index to retrieve the display for. + * @param string The string to store the index's display in. + * + * @return True if successful; false if disabled or no display set. + *********************************************************/ +native LimitBan_GetDisplay(index, String:buffer[]); + +/********************************************************* + * Returns the number of minutes for a specified ban length index. + * + * @return Number of minutes; -1 if disabled. + *********************************************************/ +native LimitBan_GetLength(index); + +/* + * Do not edit below this line! + */ + +public SharedPlugin:__pl_limit_ban = +{ + name = "sm_limit_ban_duration", + file = "sm_limit_ban_duration.smx", +#if defined REQUIRE_PLUGIN + required = 1, +#else + required = 0, +#endif +}; + +#if !defined REQUIRE_PLUGIN +public __pl_limit_ban_SetNTVOptional() +{ + MarkNativeAsOptional("LimitBan_GetSize"); + MarkNativeAsOptional("LimitBan_GetAccess"); + MarkNativeAsOptional("LimitBan_GetDisplay"); + MarkNativeAsOptional("LimitBan_GetLength"); +} +#endif \ No newline at end of file diff --git a/scripting/lbd_basebans.sp b/scripting/lbd_basebans.sp index 80ff6bb..f6a1a1b 100644 --- a/scripting/lbd_basebans.sp +++ b/scripting/lbd_basebans.sp @@ -36,6 +36,7 @@ #include #undef REQUIRE_PLUGIN #include +#include #pragma newdecls required @@ -43,13 +44,14 @@ public Plugin myinfo = { name = "Basic Ban Commands", author = "AlliedModders LLC", - description = "Basic Banning Commands", + description = "Basic Banning Commands, with optional Limit Ban Duration support.", version = SOURCEMOD_VERSION, url = "http://www.sourcemod.net/" }; TopMenu hTopMenu; +bool g_bLimitBan; int g_BanTarget[MAXPLAYERS+1]; int g_BanTargetUserId[MAXPLAYERS+1]; int g_BanTime[MAXPLAYERS+1]; @@ -86,9 +88,33 @@ public void OnPluginStart() } } -public void OnMapStart() + +public void OnLibraryRemoved(const char [] name) { - //(Re-)Load BanReasons + if(StrEqual(name, "sm_limit_ban_duration")) + g_bLimitBan = false; +} + +public void OnLibraryAdded(const char [] name) +{ + if(StrEqual(name, "sm_limit_ban_duration")) + g_bLimitBan = true; +} + +public void OnConfigsExecuted() +{ + char _sPath[PLATFORM_MAX_PATH]; + BuildPath(Path_SM, _sPath, sizeof(_sPath), "plugins/basebans.smx"); + if(FileExists(_sPath)) + { + char _sNewPath[PLATFORM_MAX_PATH]; + BuildPath(Path_SM, _sNewPath, sizeof(_sNewPath), "plugins/disabled/basebans.smx"); + ServerCommand("sm plugins unload basebans"); + if(FileExists(_sNewPath)) + DeleteFile(_sNewPath); + RenameFile(_sNewPath, _sPath); + LogMessage("plugins/basebans.smx was unloaded and moved to plugins/disabled/basebans.smx"); + } LoadBanReasons(); } @@ -299,6 +325,13 @@ public Action Command_AddBan(int client, int args) return Plugin_Handled; } + AdminId tid = FindAdminByIdentity("steam", authid); + if (client && !CanAdminTarget(GetUserAdmin(client), tid)) + { + ReplyToCommand(client, "[SM] %t", "No Access"); + return Plugin_Handled; + } + int minutes = StringToInt(time); LogAction(client, @@ -381,4 +414,4 @@ public Action OnClientSayCommand(int client, const char[] command, const char[] } return Plugin_Continue; -} +} \ No newline at end of file diff --git a/scripting/lbd_sbpp_main.sp b/scripting/lbd_sbpp_main.sp index f14fc0f..9b70388 100644 --- a/scripting/lbd_sbpp_main.sp +++ b/scripting/lbd_sbpp_main.sp @@ -31,6 +31,7 @@ #undef REQUIRE_PLUGIN #include #tryinclude +#include #define SB_VERSION "1.6.2++" #define SBR_VERSION "1.6.2" @@ -67,6 +68,7 @@ new State:ConfigState; new Handle:ConfigParser; new Handle:hTopMenu = INVALID_HANDLE; +bool g_bLimitBan; new const String:Prefix[] = "[SourceBans++] "; @@ -133,8 +135,8 @@ new Handle:g_hFwd_OnBanAdded; public Plugin:myinfo = { - name = "SourceBans++: Main Plugin", - author = "SourceBans Development Team, SourceBans++ Dev Team", + name = "(LBD) SourceBans++: Main Plugin", + author = "SourceBans Development Team, SourceBans++ Dev Team, with optional Limit Ban Duration support.", description = "Advanced ban management for the Source engine", version = SBR_VERSION, url = "https://sbpp.github.io" @@ -241,18 +243,30 @@ public OnPluginStart() #endif } -#if defined _updater_included -public OnLibraryAdded(const String:name[]) +public void OnLibraryAdded(const char[] name) { +#if defined _updater_included if (StrEqual(name, "updater")) { Updater_AddPlugin(UPDATE_URL); } -} #endif + + if(StrEqual(name, "sm_limit_ban_duration")){ + g_bLimitBan = true; + } +} + +public void OnLibraryRemoved(const char[] name) +{ + if(StrEqual(name, "sm_limit_ban_duration")){ + g_bLimitBan = false; + } +} public OnAllPluginsLoaded() { + g_bLimitBan = LibraryExists("sm_limit_ban_duration"); new Handle:topmenu; #if defined DEBUG LogToFile(logFile, "OnAllPluginsLoaded()"); @@ -278,6 +292,18 @@ public OnConfigsExecuted() RenameFile(newfilename, filename); LogToFile(logFile, "plugins/basebans.smx was unloaded and moved to plugins/disabled/basebans.smx"); } + + BuildPath(Path_SM, filename, sizeof(filename), "plugins/sbpp_main.smx"); + if(FileExists(filename)) + { + char newfilename[PLATFORM_MAX_PATH]; + BuildPath(Path_SM, newfilename, sizeof(newfilename), "plugins/disabled/sbpp_main.smx"); + ServerCommand("sm plugins unload sbpp_main"); + if(FileExists(newfilename)) + DeleteFile(newfilename); + RenameFile(newfilename, filename); + LogToFile(logFile, "plugins/sbpp_main.smx was unloaded and moved to plugins/disabled/sbpp_main.smx"); + } } public OnMapStart() @@ -955,22 +981,50 @@ stock DisplayBanTimeMenu(client) LogToFile(logFile, "DisplayBanTimeMenu()"); #endif - new Handle:menu = CreateMenu(MenuHandler_BanTimeList); + new Handle:menu; + if(g_bLimitBan && LimitBan_GetSize() > 0){ + menu = CreateMenu(MenuHandler_BanTimeList, MenuAction_Select | MenuAction_Cancel | MenuAction_DrawItem); + } else { + menu = CreateMenu(MenuHandler_BanTimeList, MenuAction_Select | MenuAction_Cancel | MenuAction_DrawItem); + } decl String:title[100]; Format(title, sizeof(title), "%T:", "Ban player", client); //Format(title, sizeof(title), "Ban player", client); SetMenuTitle(menu, title); SetMenuExitBackButton(menu, true); - - if (CheckCommandAccess(client, "sm_unban", ADMFLAG_UNBAN | ADMFLAG_ROOT)) - AddMenuItem(menu, "0", "Permanent"); - AddMenuItem(menu, "10", "10 Minutes"); - AddMenuItem(menu, "30", "30 Minutes"); - AddMenuItem(menu, "60", "1 Hour"); - AddMenuItem(menu, "240", "4 Hours"); - AddMenuItem(menu, "1440", "1 Day"); - AddMenuItem(menu, "10080", "1 Week"); + + if(g_bLimitBan && LimitBan_GetSize() > 0) + { + char _sDisplay[64]; + char _sLength[32]; + for(int i = 0; i <= LimitBan_GetSize(); i++) + { + if(LimitBan_GetAccess(i, client)) + { + int _iLength = LimitBan_GetLength(i); + IntToString(_iLength, _sLength, sizeof(_sLength)); + LimitBan_GetDisplay(i, _sDisplay); + AddMenuItem(menu, _sLength, _sDisplay); + } + } + + if(LimitBan_GetAccess(-1, client) && CheckCommandAccess(client, "sm_unban", ADMFLAG_UNBAN|ADMFLAG_ROOT)) + { + LimitBan_GetDisplay(-1, _sDisplay); + AddMenuItem(menu, "0", _sDisplay); + } + } else { + if (CheckCommandAccess(client, "sm_unban", ADMFLAG_UNBAN | ADMFLAG_ROOT)){ + AddMenuItem(menu, "0", "Permanent"); + AddMenuItem(menu, "10", "10 Minutes"); + AddMenuItem(menu, "30", "30 Minutes"); + AddMenuItem(menu, "60", "1 Hour"); + AddMenuItem(menu, "240", "4 Hours"); + AddMenuItem(menu, "1440", "1 Day"); + AddMenuItem(menu, "10080", "1 Week"); + } + } DisplayMenu(menu, client, MENU_TIME_FOREVER); } diff --git a/scripting/sm_limit_ban_duration.sp b/scripting/sm_limit_ban_duration.sp new file mode 100644 index 0000000..0f34065 --- /dev/null +++ b/scripting/sm_limit_ban_duration.sp @@ -0,0 +1,425 @@ +/* + Revision 1.0.2 + -=-=-=-=-=-=- + Added an option for -1 index parameter in natives, which will reference the perma ban entry. + Updated LBD_Basebans & LBD_Sourcebans to have support for perma ban options. + + Notice: + -=-=-=-=-=-=- + Requires sm_limit_ban_duration to recompile. +*/ + +#pragma semicolon 1 +#include +#include +#undef REQUIRE_PLUGIN +#tryinclude + +#if !defined _sourcebans_included + native SBBanPlayer(client, target, time, String:reason[]); +#endif + +#define PLUGIN_VERSION "1.0.2" + +new Handle:g_hEnabled = INVALID_HANDLE; +new Handle:g_hReduce = INVALID_HANDLE; +new Handle:g_hMaximum = INVALID_HANDLE; + +new bool:g_bDurationRestricted[MAX_BAN_DURATIONS], bool:g_bPermRestricted; +new g_iDurationLength[MAX_BAN_DURATIONS]; +new g_iDurationTotalFlags[MAX_BAN_DURATIONS], g_iPermTotalFlags; +new g_iDurationFlags[MAX_BAN_DURATIONS][24], g_iPermFlags[24]; +new String:g_sDurationOverride[MAX_BAN_DURATIONS][32], String:g_sPermOverride[32]; +new String:g_sDurationDisplay[MAX_BAN_DURATIONS][64], String:g_sPermDisplay[64]; + +new bool:g_bEnabled, bool:g_bReduce, bool:g_bPermanent, bool:g_bMaximum, bool:g_bSourceBans; +new g_iLastChange, g_iNumTimes; +new String:g_sPrefixPlugin[64]; + +public Plugin:myinfo = +{ + name = "Limit Ban Duration", + author = "Twisted|Panda", + description = "Provides functionality for creating restrictions on ban lengths.", + version = PLUGIN_VERSION, + url = "http://ominousgaming.com" +}; + +public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max) +{ + RegPluginLibrary("sm_limit_ban_duration"); + + CreateNative("LimitBan_GetSize", Native_GetSize); + CreateNative("LimitBan_GetAccess", Native_GetAccess); + CreateNative("LimitBan_GetDisplay", Native_GetDisplay); + CreateNative("LimitBan_GetLength", Native_GetLength); + return APLRes_Success; +} + +public Native_GetSize(Handle:hPlugin, iNumParams) +{ + return g_bEnabled ? g_iNumTimes : 0; +} + +public Native_GetAccess(Handle:hPlugin, iNumParams) +{ + if(!g_bEnabled) + return false; + + new index = GetNativeCell(1); + new client = GetNativeCell(2); + + return (index == -1) ? Bool_CheckFlagsPerm(client) : Bool_CheckFlags(client, index); +} + +public Native_GetDisplay(Handle:hPlugin, iNumParams) +{ + if(!g_bEnabled) + return false; + + new result = -1; + new index = GetNativeCell(1); + if(index == -1) + result = SetNativeString(2, g_sPermDisplay, sizeof(g_sPermDisplay), false); + else + { + decl String:_sTemp[64]; + strcopy(_sTemp, sizeof(_sTemp), g_sDurationDisplay[index]); + result = SetNativeString(2, _sTemp, sizeof(_sTemp), false); + } + + return (result == SP_ERROR_NONE) ? true : false; +} + +public Native_GetLength(Handle:hPlugin, iNumParams) +{ + if(!g_bEnabled) + return -1; + + new index = GetNativeCell(1); + return (index == -1) ? 0 : g_iDurationLength[index]; +} + +public OnAllPluginsLoaded() +{ + g_bSourceBans = LibraryExists("sourcebans"); +} + +public OnLibraryRemoved(const String:name[]) +{ + if(StrEqual(name, "sourcebans")) + g_bSourceBans = false; +} + +public OnLibraryAdded(const String:name[]) +{ + if(StrEqual(name, "sourcebans")) + g_bSourceBans = true; +} + +public OnPluginStart() +{ + LoadTranslations("common.phrases"); + LoadTranslations("sm_limit_ban_duration.phrases"); + + CreateConVar("sm_limit_ban_duration_version", PLUGIN_VERSION, "Limit Ban Duration: Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD); + + g_hEnabled = CreateConVar("sm_limit_ban_duration_enabled", "1", "Enables/disables all features of this plugin.", FCVAR_NONE, true, 0.0, true, 1.0); + HookConVarChange(g_hEnabled, OnSettingsChange); + g_hReduce = CreateConVar("sm_limit_ban_duration_reduce", "1", "If enabled, the plugin will lower ban lengths if an admin doesn't have access to their specified length to a length they do possess.", FCVAR_NONE, true, 0.0, true, 1.0); + HookConVarChange(g_hReduce, OnSettingsChange); + g_hMaximum = CreateConVar("sm_limit_ban_duration_maximum", "1", "If enabled, the highest entry defined in the plugins configuration file will be the highest amount any admin can ban for.", FCVAR_NONE, true, 0.0, true, 1.0); + HookConVarChange(g_hMaximum, OnSettingsChange); + AutoExecConfig(true, "sm_limit_ban_duration"); + + AddCommandListener(Command_Ban, "sm_ban"); + + g_bEnabled = GetConVarBool(g_hEnabled); + g_bReduce = GetConVarBool(g_hReduce); + g_bMaximum = GetConVarBool(g_hMaximum); +} + +public OnSettingsChange(Handle:cvar, const String:oldvalue[], const String:newvalue[]) +{ + if(cvar == g_hEnabled) + g_bEnabled = StringToInt(newvalue) ? true : false; + else if(cvar == g_hReduce) + g_bReduce = StringToInt(newvalue) ? true : false; + else if(cvar == g_hMaximum) + g_bMaximum = StringToInt(newvalue) ? true : false; +} + +public OnMapStart() +{ + if(g_bEnabled) + { + Void_LoadTimes(); + } +} + +public OnConfigsExecuted() +{ + if(g_bEnabled) + { + Format(g_sPrefixPlugin, sizeof(g_sPrefixPlugin), "%T", "Prefix_Plugin", LANG_SERVER); + } +} + +public Action:Command_Ban(client, const String:command[], argc) +{ + if(g_bEnabled && g_iNumTimes && (!client || CheckCommandAccess(client, "sm_ban", ADMFLAG_BAN))) + { + if(argc < 2) + return Plugin_Continue; + + decl String:_sTime[32]; + GetCmdArg(2, _sTime, sizeof(_sTime)); + new _iLength = StrEqual(_sTime, "") ? -1 : StringToInt(_sTime); + if(_iLength <= -1) + return Plugin_Continue; + + if(!_iLength) + { + if(!g_bPermanent || !g_bPermRestricted || Bool_CheckFlagsPerm(client)) + return Plugin_Continue; + + new _iPosition = -1; + for(new i = g_iNumTimes; i >= 0; i--) + { + if(Bool_CheckFlags(client, i)) + { + _iPosition = i; + break; + } + } + + if(_iPosition == -1) + ReplyToCommand(client, "%s%t", g_sPrefixPlugin, "Phrase_No_Access"); + else + { + if(g_bReduce) + { + decl String:_sBuffer[256]; + GetCmdArgString(_sBuffer, sizeof(_sBuffer)); + if(Bool_IssueBan(client, _iPosition, _sBuffer)) + ReplyToCommand(client, "%s%t", g_sPrefixPlugin, "Phrase_Reduced_Perm_Length", g_iDurationLength[_iPosition]); + } + else + ReplyToCommand(client, "%s%t", g_sPrefixPlugin, "Phrase_Illegal_Ban_Perm", g_iDurationLength[_iPosition]); + } + + return Plugin_Stop; + } + + new _iPosition; + for(new i = g_iNumTimes; i >= 0; i--) + if((_iLength >= g_iDurationLength[i] || i == 0) && (i == g_iNumTimes || _iLength <= g_iDurationLength[i + 1])) + _iPosition = i; + + if(!_iPosition && _iLength < g_iDurationLength[_iPosition]) + { + if(Bool_CheckFlags(client, _iPosition)) + return Plugin_Continue; + + ReplyToCommand(client, "%s%t", g_sPrefixPlugin, "Phrase_No_Access"); + return Plugin_Stop; + } + else if(_iPosition == g_iNumTimes) + { + if(Bool_CheckFlags(client, _iPosition)) + { + if(g_bMaximum) + { + if(g_bReduce) + { + decl String:_sBuffer[256]; + GetCmdArgString(_sBuffer, sizeof(_sBuffer)); + if(Bool_IssueBan(client, _iPosition, _sBuffer)) + ReplyToCommand(client, "%s%t", g_sPrefixPlugin, "Phrase_Reduced_Ban_Length", g_iDurationLength[_iPosition]); + } + else + ReplyToCommand(client, "%s%t", g_sPrefixPlugin, "Phrase_Illegal_Ban_Length", g_iDurationLength[_iPosition]); + + return Plugin_Stop; + } + + return Plugin_Continue; + } + } + + if(_iLength == g_iDurationLength[_iPosition] && Bool_CheckFlags(client, _iPosition)) + return Plugin_Continue; + else if(Bool_CheckFlags(client, (_iPosition + 1))) + return Plugin_Continue; + else + { + for(new i = _iPosition; i >= -1; i--) + { + if(i == -1) + break; + + if(Bool_CheckFlags(client, i)) + { + _iPosition = i; + break; + } + } + + if(_iPosition == -1) + ReplyToCommand(client, "%s%t", g_sPrefixPlugin, "Phrase_No_Access"); + else + { + if(g_bReduce) + { + decl String:_sBuffer[256]; + GetCmdArgString(_sBuffer, sizeof(_sBuffer)); + if(Bool_IssueBan(client, _iPosition, _sBuffer)) + ReplyToCommand(client, "%s%t", g_sPrefixPlugin, "Phrase_Reduced_Ban_Length", _iLength, g_iDurationLength[_iPosition]); + } + else + ReplyToCommand(client, "%s%t", g_sPrefixPlugin, "Phrase_Illegal_Ban_Length", g_iDurationLength[_iPosition]); + } + } + + return Plugin_Stop; + } + + return Plugin_Continue; +} + +bool:Bool_CheckFlagsPerm(client) +{ + if(!client || !g_bPermRestricted) + return true; + + new _iTotal; + for(new i = 0; i < g_iPermTotalFlags; i++) + { + if(CheckCommandAccess(client, g_sPermOverride, g_iPermFlags[i])) + _iTotal++; + else + break; + } + + return (_iTotal == g_iPermTotalFlags) ? true : false; +} + +bool:Bool_CheckFlags(client, index) +{ + if(!client || !g_bDurationRestricted[index]) + return true; + + new _iTotal; + for(new i = 0; i < g_iDurationTotalFlags[index]; i++) + { + if(CheckCommandAccess(client, g_sDurationOverride[index], g_iDurationFlags[index][i])) + _iTotal++; + else + break; + } + + return (_iTotal == g_iDurationTotalFlags[index]) ? true : false; +} + +Bool_IssueBan(client, index, const String:buffer[]) +{ + decl String:_sBuffer[192]; + new _iLength = BreakString(buffer, _sBuffer, sizeof(_sBuffer)); + new _iTarget = FindTarget(client, _sBuffer, true); + if(_iTarget == -1) + return false; + _iLength += BreakString(buffer[_iLength], _sBuffer, sizeof(_sBuffer)); + strcopy(_sBuffer, sizeof(_sBuffer), buffer[_iLength]); + if(g_bSourceBans) + SBBanPlayer(client, _iTarget, g_iDurationLength[index], _sBuffer); + else + BanClient(_iTarget, g_iDurationLength[index], BANFLAG_AUTO, _sBuffer); + return true; +} + +Void_LoadTimes() +{ + decl String:_sPath[PLATFORM_MAX_PATH]; + BuildPath(Path_SM, _sPath, PLATFORM_MAX_PATH, "configs/sm_limit_ban_duration.ini"); + + new _iCurrent = GetFileTime(_sPath, FileTime_LastChange); + if(_iCurrent < g_iLastChange) + return; + else + g_iLastChange = _iCurrent; + + g_iNumTimes = 0; + g_bPermanent = false; + new Handle:_hKV = CreateKeyValues("Limit_Ban_Durations"); + decl String:_sDisplay[MAX_BAN_DURATIONS][64], String:_sTemp[32], String:_sBuffer[24][3], String:_sOverrides[MAX_BAN_DURATIONS][32]; + new bool:_bDuration[MAX_BAN_DURATIONS], _iLength[MAX_BAN_DURATIONS], _iFlags[MAX_BAN_DURATIONS][24], _iTotalFlags[MAX_BAN_DURATIONS]; + if(FileToKeyValues(_hKV, _sPath)) + { + KvGotoFirstSubKey(_hKV); + do + { + KvGetSectionName(_hKV, _sTemp, sizeof(_sTemp)); + new _iTemp = StringToInt(_sTemp); + + if(_iTemp == 0) + { + g_bPermanent = true; + + KvGetString(_hKV, "flags", _sTemp, sizeof(_sTemp)); + g_iPermTotalFlags = StrEqual(_sTemp, "") ? 0 : ExplodeString(_sTemp, ",", _sBuffer, 24, 3); + for(new i = 0; i < g_iPermTotalFlags; i++) + g_iPermFlags[i] = ReadFlagString(_sBuffer[i]); + KvGetString(_hKV, "override", g_sPermOverride, sizeof(g_sPermOverride)); + g_bPermRestricted = (!g_iPermTotalFlags && StrEqual(g_sPermOverride, "")) ? false : true; + KvGetString(_hKV, "display", g_sPermDisplay, sizeof(g_sPermDisplay)); + } + else + { + _iLength[g_iNumTimes] = _iTemp; + + KvGetString(_hKV, "flags", _sTemp, sizeof(_sTemp)); + _iTotalFlags[g_iNumTimes] = StrEqual(_sTemp, "") ? 0 : ExplodeString(_sTemp, ",", _sBuffer, 24, 3); + for(new i = 0; i < _iTotalFlags[g_iNumTimes]; i++) + _iFlags[g_iNumTimes][i] = ReadFlagString(_sBuffer[i]); + KvGetString(_hKV, "override", _sOverrides[g_iNumTimes], sizeof(_sOverrides[])); + _bDuration[g_iNumTimes] = (!_iTotalFlags[g_iNumTimes] && StrEqual(_sOverrides[g_iNumTimes], "")) ? false : true; + KvGetString(_hKV, "display", _sDisplay[g_iNumTimes], sizeof(_sDisplay[])); + g_iNumTimes++; + } + } + while (KvGotoNextKey(_hKV)); + } + else + SetFailState("Limit Ban Durations: configs/sm_limit_ban_duration.ini is missing or invalid!"); + + if(g_iNumTimes) + g_iNumTimes--; + + new _iCurrentHigh, _iTotalSorted = g_iNumTimes; + for(new i = 0; i <= g_iNumTimes; i++) + { + _iCurrentHigh = -1; + new _iCurrentIndex; + for(new j = 0; j <= g_iNumTimes; j++) + { + if(_iLength[j] != -1 && _iLength[j] > _iCurrentHigh) + { + _iCurrentIndex = j; + _iCurrentHigh = _iLength[j]; + } + } + + g_bDurationRestricted[_iTotalSorted] = _bDuration[_iCurrentIndex]; + g_iDurationLength[_iTotalSorted] = _iLength[_iCurrentIndex]; + g_iDurationTotalFlags[_iTotalSorted] = _iTotalFlags[_iCurrentIndex]; + for(new j = 0; j < g_iDurationTotalFlags[_iTotalSorted]; j++) + g_iDurationFlags[_iTotalSorted][j] = _iFlags[_iCurrentIndex][j]; + strcopy(g_sDurationOverride[_iTotalSorted], sizeof(g_sDurationOverride[]), _sOverrides[_iCurrentIndex]); + strcopy(g_sDurationDisplay[_iTotalSorted], sizeof(g_sDurationDisplay[]), _sDisplay[_iCurrentIndex]); + + _iLength[_iCurrentIndex] = -1; + _iTotalSorted--; + } + + CloseHandle(_hKV); +} \ No newline at end of file diff --git a/translations/sm_limit_ban_duration.phrases.txt b/translations/sm_limit_ban_duration.phrases.txt new file mode 100644 index 0000000..f9b122f --- /dev/null +++ b/translations/sm_limit_ban_duration.phrases.txt @@ -0,0 +1,35 @@ +"Phrases" +{ + //==================================================================== + "Prefix_Plugin" + { + "#format" "" + "en" "[SM] " + } + //==================================================================== + "Phrase_No_Access" + { + "#format" "" + "en" "You do not have access to this command!" + } + "Phrase_Illegal_Ban_Length" + { + "#format" "{1:d}" + "en" "You do not have permission to issue bans for more than {1} minutes!" + } + "Phrase_Illegal_Ban_Perm" + { + "#format" "" + "en" "You do not have permission to issue permanent bans!" + } + "Phrase_Reduced_Perm_Length" + { + "#format" "{1:d}" + "en" "You cannot issue permanent bans! Your ban length was automatically lowered to {1} minutes." + } + "Phrase_Reduced_Ban_Length" + { + "#format" "{1:d}" + "en" "You cannot ban for more than {1} minutes! Your ban length was automatically lowered." + } +} \ No newline at end of file