From ecc3cad7716ac2518b46d3da248b8729adcc07f4 Mon Sep 17 00:00:00 2001 From: jenz Date: Sat, 18 Jun 2022 21:39:13 +0200 Subject: [PATCH] added boolean column set on player connect/disconnect. Also resets on DB Connection. Ensures to only fetch rows for hiding sprays of clients who are ingame too --- SprayManager/scripting/SprayManager.sp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/SprayManager/scripting/SprayManager.sp b/SprayManager/scripting/SprayManager.sp index ac8d215c..15023584 100644 --- a/SprayManager/scripting/SprayManager.sp +++ b/SprayManager/scripting/SprayManager.sp @@ -322,6 +322,17 @@ public void OnClientPostAdminCheck(int client) g_bSkipDecalHook = false; } } + update_client_online(client, 1); +} + +public void update_client_online(int client, int is_online) +{ + char sAuthID[32]; + GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), false); + + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "UPDATE `sprayhidemanage` SET `is_online` = %i WHERE `steamidtarget` = '%s';", is_online, sAuthID); + SQL_TQuery(g_hDatabase, DummyCallback, sQuery); } public void OnClientDisconnect(int client) @@ -342,6 +353,8 @@ public void OnClientDisconnect(int client) g_bSkipDecalHook = true; SprayClientDecalToAll(client, 0, ACTUAL_NULL_VECTOR); g_bSkipDecalHook = false; + + update_client_online(client, 0); } ClearPlayerInfo(client); @@ -2360,7 +2373,7 @@ public Action Timer_UpdateHideSprays(Handle hTimer) } char sQuery[512]; - Format(sQuery, sizeof(sQuery), "SELECT `steamidtarget` FROM `sprayhidemanage` WHERE `steamidhider` = '%s';", sAuthID); + Format(sQuery, sizeof(sQuery), "SELECT `steamidtarget` FROM `sprayhidemanage` WHERE `steamidhider` = '%s' and `is_online` = 1;", sAuthID); SQL_TQuery(g_hDatabase, select_sprays_to_hide, sQuery, client, DBPrio_High); } } @@ -2508,6 +2521,13 @@ void InitializeSQL() SetFailState("Could not find \"spraymanager\" entry in databases.cfg."); } +public void update_all_clients_offline() +{ + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "UPDATE `sprayhidemanage` SET `is_online` = 0;"); + SQL_TQuery(g_hDatabase, DummyCallback, sQuery); +} + public void OnSQLConnected(Handle hParent, Handle hChild, const char[] err, any data) { if (hChild == null) @@ -2524,6 +2544,7 @@ public void OnSQLConnected(Handle hParent, Handle hChild, const char[] err, any if (!strncmp(sDriver, "my", 2, false)) { + update_all_clients_offline(); SQL_TQuery(g_hDatabase, DummyCallback, "SET NAMES \"UTF8\""); SQL_TQuery(g_hDatabase, OnSQLTableCreated, "CREATE TABLE IF NOT EXISTS `spraymanager` (`steamid` VARCHAR(32) NOT NULL, `name` VARCHAR(32) NOT NULL, `unbantime` INT, `issuersteamid` VARCHAR(32), `issuername` VARCHAR(32) NOT NULL, `issuedtime` INT, `issuedreason` VARCHAR(64) NOT NULL, PRIMARY KEY(steamid)) CHARACTER SET utf8 COLLATE utf8_general_ci;");