From a9cf7a32f34801c9d6c7b5160201ce4ecefc9daa Mon Sep 17 00:00:00 2001 From: shavitush Date: Wed, 16 Nov 2016 22:22:23 +0200 Subject: [PATCH] Add cookies for sm_hide (#311) --- scripting/shavit-misc.sp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/scripting/shavit-misc.sp b/scripting/shavit-misc.sp index 59f027e8..071a7729 100644 --- a/scripting/shavit-misc.sp +++ b/scripting/shavit-misc.sp @@ -23,6 +23,7 @@ #include #include #include +#include #undef REQUIRE_EXTENSIONS #include @@ -53,6 +54,9 @@ char gS_CurrentMap[192]; ConVar gCV_Hostname = null; ConVar gCV_Hostport = null; +// cookies +Handle gH_HideCookie = null; + // cvars ConVar gCV_GodMode = null; ConVar gCV_PreSpeed = null; @@ -149,6 +153,7 @@ public void OnPluginStart() // hide RegConsoleCmd("sm_hide", Command_Hide, "Toggle players' hiding."); RegConsoleCmd("sm_unhide", Command_Hide, "Toggle players' hiding."); + gH_HideCookie = RegClientCookie("shavit_hide", "Hide settings", CookieAccess_Protected); // tpto RegConsoleCmd("sm_tpto", Command_Teleport, "Teleport to another player. Usage: sm_tpto [target]"); @@ -271,11 +276,33 @@ public void OnPluginStart() if(IsValidClient(i)) { OnClientPutInServer(i); + + if(AreClientCookiesCached(i)) + { + OnClientCookiesCached(i); + } } } } } +public void OnClientCookiesCached(int client) +{ + char[] sHideSetting = new char[8]; + GetClientCookie(client, gH_HideCookie, sHideSetting, 8); + + if(strlen(sHideSetting) == 0) + { + SetClientCookie(client, gH_HideCookie, "0"); + gB_Hide[client] = false; + } + + else + { + gB_Hide[client] = view_as(StringToInt(sHideSetting)); + } +} + public void Shavit_OnStyleConfigLoaded(int styles) { if(styles == -1) @@ -665,7 +692,10 @@ public Action OnPlayerRunCmd(int client, int &buttons) public void OnClientPutInServer(int client) { - gB_Hide[client] = false; + if(!AreClientCookiesCached(client)) + { + gB_Hide[client] = false; + } SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage); SDKHook(client, SDKHook_SetTransmit, OnSetTransmit);