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

This commit is contained in:
jenz 2022-06-18 21:39:13 +02:00
parent 208496a909
commit ecc3cad771

View File

@ -322,6 +322,17 @@ public void OnClientPostAdminCheck(int client)
g_bSkipDecalHook = false; 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) public void OnClientDisconnect(int client)
@ -342,6 +353,8 @@ public void OnClientDisconnect(int client)
g_bSkipDecalHook = true; g_bSkipDecalHook = true;
SprayClientDecalToAll(client, 0, ACTUAL_NULL_VECTOR); SprayClientDecalToAll(client, 0, ACTUAL_NULL_VECTOR);
g_bSkipDecalHook = false; g_bSkipDecalHook = false;
update_client_online(client, 0);
} }
ClearPlayerInfo(client); ClearPlayerInfo(client);
@ -2360,7 +2373,7 @@ public Action Timer_UpdateHideSprays(Handle hTimer)
} }
char sQuery[512]; 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); 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."); 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) public void OnSQLConnected(Handle hParent, Handle hChild, const char[] err, any data)
{ {
if (hChild == null) if (hChild == null)
@ -2524,6 +2544,7 @@ public void OnSQLConnected(Handle hParent, Handle hChild, const char[] err, any
if (!strncmp(sDriver, "my", 2, false)) if (!strncmp(sDriver, "my", 2, false))
{ {
update_all_clients_offline();
SQL_TQuery(g_hDatabase, DummyCallback, "SET NAMES \"UTF8\""); 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;"); 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;");