From 6a9a9ee612462694204e1413d97cfb93139ca6a9 Mon Sep 17 00:00:00 2001 From: DoganGFL Date: Thu, 6 Dec 2018 20:55:19 +0100 Subject: [PATCH] add cookies to save sm_hide_lennies --- AntiLenny/scripting/AntiLenny.sp | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/AntiLenny/scripting/AntiLenny.sp b/AntiLenny/scripting/AntiLenny.sp index da1cf88e..18165692 100644 --- a/AntiLenny/scripting/AntiLenny.sp +++ b/AntiLenny/scripting/AntiLenny.sp @@ -6,8 +6,11 @@ #include #include #include +#include bool g_bHideLennies[MAXPLAYERS + 1] = { false, ... }; +bool g_bHideLenniesHooked = false; +Handle g_hCookieHideLennies = null; char g_cLennies[23][] = {"( ͡° ͜ʖ ͡°)", "͜ʖ", "(° ͜ʖ °)", "( ͝͠°͜ل͝͠°)", "( ͡° ͜ ͡°)", "( ͡°╭͜ʖ╮͡° )", "( ͠° ͜ʖ ͡°)", "( ° ͜ʖ °)", "(╯°□°)╯", "_(ツ)_", "_ツ_", "( ̿°̿ ͜ل͜ ̿°̿ )", "( ͡", "( ͠", "( ͝", "( °", "(͡", "ಠ_ಠ", "͡°", "°͡", "ʖ", "͡", "͜"}; @@ -23,6 +26,8 @@ public Plugin myinfo = public void OnPluginStart() { RegConsoleCmd("sm_hide_lennies", HideLennies, "Toggle blocking Lennies"); + + g_hCookieHideLennies = RegClientCookie("lennies_blocked", "are lennies blocked", CookieAccess_Protected); } public Action CCC_OnChatMessage(int client, int author, const char[] message) @@ -45,19 +50,56 @@ public Action CCC_OnChatMessage(int client, int author, const char[] message) public Action HideLennies(int client, int args) { g_bHideLennies[client] = !g_bHideLennies[client]; + CheckHideLenniesHooks(); if(g_bHideLennies[client]) { ReplyToCommand(client, "You blocked Lennies"); + SetClientCookie(client, g_hCookieHideLennies, "1"); } else { ReplyToCommand(client, "You unblocked Lennies"); + SetClientCookie(client, g_hCookieHideLennies, ""); } return Plugin_Handled; } +public void OnClientCookiesCached(int client) +{ + char sBuffer[2]; + + GetClientCookie(client, g_hCookieHideLennies, sBuffer, sizeof(sBuffer)); + + if(sBuffer[0] != '\0') + { + g_bHideLennies[client] = true; + g_bHideLenniesHooked = true; + } + else + { + g_bHideLennies[client] = false; + } +} + public void OnClientDisconnect(int client) { g_bHideLennies[client] = false; + CheckHideLenniesHooks(); +} + +public void CheckHideLenniesHooks() +{ + bool bShouldHook = false; + + for(int i = 1; i <= MaxClients; i++) + { + if(g_bHideLennies[i]) + { + bShouldHook = true; + break; + } + } + + g_bHideLenniesHooked = bShouldHook; } \ No newline at end of file