diff --git a/_entWatch4/scripting/entWatch-restrictions.sp b/_entWatch4/scripting/entWatch-restrictions.sp index 1b6e7382..ebbf6670 100644 --- a/_entWatch4/scripting/entWatch-restrictions.sp +++ b/_entWatch4/scripting/entWatch-restrictions.sp @@ -20,14 +20,20 @@ Handle g_hFwd_OnClientUnrestricted; /* COOKIES */ Handle g_hCookie_RestrictIssued; -Handle g_hCookie_RestrictLength; Handle g_hCookie_RestrictExpire; +Handle g_hCookie_RestrictLength; + +/* BOOLEANS */ +bool g_bRestrictedTemp[MAXPLAYERS+1]; /* INTERGERS */ int g_iRestrictIssued[MAXPLAYERS+1]; int g_iRestrictLength[MAXPLAYERS+1]; int g_iRestrictExpire[MAXPLAYERS+1]; +/* STRINGMAPS */ +StringMap g_hTrie_Storage; + //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- @@ -64,8 +70,10 @@ public void OnPluginStart() g_hFwd_OnClientUnrestricted = CreateGlobalForward("EW_OnClientUnrestricted", ET_Ignore, Param_Cell, Param_Cell); g_hCookie_RestrictIssued = RegClientCookie("EW_RestrictIssued", "", CookieAccess_Private); - g_hCookie_RestrictLength = RegClientCookie("EW_RestrictLength", "", CookieAccess_Private); g_hCookie_RestrictExpire = RegClientCookie("EW_RestrictExpire", "", CookieAccess_Private); + g_hCookie_RestrictLength = RegClientCookie("EW_RestrictLength", "", CookieAccess_Private); + + g_hTrie_Storage = new StringMap(); RegAdminCmd("sm_eban", Command_ClientRestrict, ADMFLAG_BAN); RegAdminCmd("sm_eunban", Command_ClientUnrestrict, ADMFLAG_UNBAN); @@ -73,14 +81,37 @@ public void OnPluginStart() RegConsoleCmd("sm_restrictions", Command_DisplayRestrictions); } +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnMapStart() +{ + g_hTrie_Storage.Clear(); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnClientPutInServer(int client) +{ + char sAddress[32]; + GetClientIP(client, sAddress, sizeof(sAddress)); + + bool bRestrictedTemp; + if (g_hTrie_Storage.GetValue(sAddress, bRestrictedTemp)) + { + g_bRestrictedTemp[client] = bRestrictedTemp; + } +} + //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public void OnClientCookiesCached(int client) { g_iRestrictIssued[client] = GetClientCookieInt(client, g_hCookie_RestrictIssued); - g_iRestrictLength[client] = GetClientCookieInt(client, g_hCookie_RestrictLength); g_iRestrictExpire[client] = GetClientCookieInt(client, g_hCookie_RestrictExpire); + g_iRestrictLength[client] = GetClientCookieInt(client, g_hCookie_RestrictLength); } //---------------------------------------------------------------------------------------------------- @@ -88,9 +119,18 @@ public void OnClientCookiesCached(int client) //---------------------------------------------------------------------------------------------------- public void OnClientDisconnect(int client) { + if (g_bRestrictedTemp[client]) + { + char sAddress[32]; + GetClientIP(client, sAddress, sizeof(sAddress)); + + g_hTrie_Storage.SetArray(sAddress, g_bRestrictedTemp[client], true); + } + + g_bRestrictedTemp[client] = false; g_iRestrictIssued[client] = 0; - g_iRestrictLength[client] = 0; g_iRestrictExpire[client] = 0; + g_iRestrictLength[client] = 0; } //---------------------------------------------------------------------------------------------------- @@ -104,28 +144,38 @@ public Action Command_ClientRestrict(int client, int args) return Plugin_Handled; } - char sTarget[32]; - char sLength[32]; - GetCmdArg(1, sTarget, sizeof(sTarget)); - GetCmdArg(2, sLength, sizeof(sLength)); + char sArguments[2][32]; + GetCmdArg(1, sArguments[0], sizeof(sArguments[])); + GetCmdArg(2, sArguments[1], sizeof(sArguments[])); int target; - if ((target = FindTarget(client, sTarget, true)) == -1) + if ((target = FindTarget(client, sArguments[0], true)) == -1) return Plugin_Handled; - int length = StringToInt(sLength); - - if (ClientRestrict(client, target, length)) + if (GetCmdArgs() >= 2) { - if (length) + int length = StringToInt(sArguments[1]); + + if (ClientRestrict(client, target, length)) { - CPrintToChatAll("\x07%s[entWatch] \x07%s%N\x07%s restricted \x07%s%N\x07%s for \x07%s%d\x07%s minutes.", "E01B5D", "EDEDED", client, "F16767", "EDEDED", target, "F16767", "EDEDED", length, "F16767"); - LogAction(client, target, "%L restricted %L for %d minutes.", client, target, length); + if (length) + { + CPrintToChatAll("\x07%s[entWatch] \x07%s%N\x07%s restricted \x07%s%N\x07%s for \x07%s%d\x07%s minutes.", "E01B5D", "EDEDED", client, "F16767", "EDEDED", target, "F16767", "EDEDED", length, "F16767"); + LogAction(client, target, "%L restricted %L for %d minutes.", client, target, length); + } + else + { + CPrintToChatAll("\x07%s[entWatch] \x07%s%N\x07%s restricted \x07%s%N\x07%s permanently.", "E01B5D", "EDEDED", client, "F16767", "EDEDED", target, "F16767"); + LogAction(client, target, "%L restricted %L permanently.", client, target); + } } - else + } + else + { + if (ClientRestrict(client, target, -1)) { - CPrintToChatAll("\x07%s[entWatch] \x07%s%N\x07%s restricted \x07%s%N\x07%s permanently.", "E01B5D", "EDEDED", client, "F16767", "EDEDED", target, "F16767"); - LogAction(client, target, "%L restricted %L permanently.", client, target); + CPrintToChatAll("\x07%s[entWatch] \x07%s%N\x07%s restricted \x07%s%N\x07%s temporarily.", "E01B5D", "EDEDED", client, "F16767", "EDEDED", target, "F16767"); + LogAction(client, target, "%L restricted %L temporarily.", client, target); } } @@ -143,11 +193,11 @@ public Action Command_ClientUnrestrict(int client, int args) return Plugin_Handled; } - char sTarget[32]; - GetCmdArg(1, sTarget, sizeof(sTarget)); + char sArguments[1][32]; + GetCmdArg(1, sArguments[0], sizeof(sArguments[])); int target; - if ((target = FindTarget(client, sTarget, true)) == -1) + if ((target = FindTarget(client, sArguments[0], true)) == -1) return Plugin_Handled; if (ClientUnrestrict(client, target)) @@ -215,17 +265,32 @@ stock bool ClientRestrict(int client, int target, int length) if (!Client_IsValid(client) || !Client_IsValid(target) || !AreClientCookiesCached(target) || ClientRestricted(target)) return false; - int issued = GetTime(); - int second = length * 60; - int expire = issued + second; + if (length == -1) + { + g_bRestrictedTemp[target] = true; + } + else if (length == 0) + { + g_bRestrictedTemp[target] = false; + g_iRestrictIssued[target] = GetTime(); + g_iRestrictExpire[target] = 0; + g_iRestrictLength[target] = 0; - g_iRestrictIssued[target] = issued; - g_iRestrictLength[target] = length; - g_iRestrictExpire[target] = expire; + SetClientCookieInt(target, g_hCookie_RestrictIssued, GetTime()); + SetClientCookieInt(target, g_hCookie_RestrictExpire, 0); + SetClientCookieInt(target, g_hCookie_RestrictLength, 0); + } + else + { + g_bRestrictedTemp[target] = false; + g_iRestrictIssued[target] = GetTime(); + g_iRestrictExpire[target] = GetTime() + (length * 60); + g_iRestrictLength[target] = length; - SetClientCookieInt(target, g_hCookie_RestrictIssued, issued); - SetClientCookieInt(target, g_hCookie_RestrictLength, length); - SetClientCookieInt(target, g_hCookie_RestrictExpire, expire); + SetClientCookieInt(target, g_hCookie_RestrictIssued, GetTime()); + SetClientCookieInt(target, g_hCookie_RestrictExpire, GetTime() + (length * 60)); + SetClientCookieInt(target, g_hCookie_RestrictLength, length); + } Call_StartForward(g_hFwd_OnClientRestricted); Call_PushCell(client); @@ -244,13 +309,14 @@ stock bool ClientUnrestrict(int client, int target) if (!Client_IsValid(client) || !Client_IsValid(target) || !AreClientCookiesCached(target) || !ClientRestricted(target)) return false; + g_bRestrictedTemp[target] = false; g_iRestrictIssued[target] = 0; - g_iRestrictLength[target] = 0; g_iRestrictExpire[target] = 0; + g_iRestrictLength[target] = 0; SetClientCookieInt(target, g_hCookie_RestrictIssued, 0); - SetClientCookieInt(target, g_hCookie_RestrictLength, 0); SetClientCookieInt(target, g_hCookie_RestrictExpire, 0); + SetClientCookieInt(target, g_hCookie_RestrictLength, 0); Call_StartForward(g_hFwd_OnClientUnrestricted); Call_PushCell(client); @@ -272,12 +338,16 @@ stock bool ClientRestricted(int client) if (!AreClientCookiesCached(client)) return true; - //Permanent restriction.. - if (g_iRestrictExpire[client] && g_iRestrictLength[client] == 0) + //Temporary restriction. + if (g_bRestrictedTemp[client]) return true; - //Limited restriction.. - if (g_iRestrictExpire[client] && g_iRestrictExpire[client] >= GetTime()) + //Permanent restriction. + if (g_iRestrictIssued[client] && g_iRestrictLength[client] == 0) + return true; + + //Normal restriction. + if (g_iRestrictIssued[client] && g_iRestrictExpire[client] >= GetTime()) return true; return false;