Add cookies for sm_hide (#311)

This commit is contained in:
shavitush 2016-11-16 22:22:23 +02:00
parent fc45e60ba0
commit a9cf7a32f3
No known key found for this signature in database
GPG Key ID: 0A298F154527B9A4

View File

@ -23,6 +23,7 @@
#include <sdktools>
#include <sdkhooks>
#include <dynamic>
#include <clientprefs>
#undef REQUIRE_EXTENSIONS
#include <dhooks>
@ -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<bool>(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);