further fixes to queries and timers

This commit is contained in:
jenz 2023-04-30 19:57:25 +02:00
parent 004889f308
commit 275245d6ab
3 changed files with 115 additions and 69 deletions

View File

@ -251,8 +251,13 @@ public void CvarQueryFinished_SprayLifeTime(QueryCookie cookie, int client, ConV
g_iClientSprayLifetime[client] = iVal <= 0 ? 1 : iVal > 1000 ? 1000 : iVal;
}
public void select_sprays_to_hide(Handle hParent, Handle hChild, const char[] err, any client)
public void select_sprays_to_hide(Handle hParent, Handle hChild, const char[] err, int Serial)
{
int client;
if ((client = GetClientFromSerial(Serial)) == 0)
{
return;
}
if (!IsValidClient(client))
return;
@ -2374,7 +2379,7 @@ public Action Timer_UpdateHideSprays(Handle hTimer)
char sQuery[512];
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_Normal);
SQL_TQuery(g_hDatabase, select_sprays_to_hide, sQuery, GetClientSerial(client), DBPrio_Normal);
}
}
@ -2956,7 +2961,7 @@ void UpdatePlayerInfo(int client)
GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID));
Format(sQuery, sizeof(sQuery), "SELECT * FROM `spraymanager` WHERE `steamid` = '%s';", sSteamID);
SQL_TQuery(g_hDatabase, OnSQLCheckBanQuery, sQuery, client, DBPrio_Normal);
SQL_TQuery(g_hDatabase, OnSQLCheckBanQuery, sQuery, GetClientSerial(client), DBPrio_Normal);
}
void UpdateSprayHashInfo(int client)
@ -2970,7 +2975,7 @@ void UpdateSprayHashInfo(int client)
char sSprayQuery[128];
Format(sSprayQuery, sizeof(sSprayQuery), "SELECT * FROM `sprayblacklist` WHERE `sprayhash` = '%s';", g_sSprayHash[client]);
SQL_TQuery(g_hDatabase, OnSQLCheckSprayHashBanQuery, sSprayQuery, client, DBPrio_Normal);
SQL_TQuery(g_hDatabase, OnSQLCheckSprayHashBanQuery, sSprayQuery, GetClientSerial(client), DBPrio_Normal);
}
void UpdateNSFWInfo(int client)
@ -2984,7 +2989,7 @@ void UpdateNSFWInfo(int client)
char sSprayQuery[128];
Format(sSprayQuery, sizeof(sSprayQuery), "SELECT * FROM `spraynsfwlist` WHERE `sprayhash` = '%s';", g_sSprayHash[client]);
SQL_TQuery(g_hDatabase, OnSQLCheckNSFWSprayHashQuery, sSprayQuery, client);
SQL_TQuery(g_hDatabase, OnSQLCheckNSFWSprayHashQuery, sSprayQuery, GetClientSerial(client));
}
public void DummyCallback(Handle hOwner, Handle hChild, const char[] err, any data)
@ -2993,85 +2998,114 @@ public void DummyCallback(Handle hOwner, Handle hChild, const char[] err, any da
LogError("Query error. (%s)", err);
}
public void OnSQLCheckBanQuery(Handle hParent, Handle hChild, const char[] err, any client)
public void OnSQLCheckBanQuery(Handle hParent, Handle hChild, const char[] err, int Serial)
{
if (!IsValidClient(client))
return;
int client;
if ((client = GetClientFromSerial(Serial)) == 0)
{
return;
}
if (!IsValidClient(client))
return;
if (hChild == null)
{
LogError("An error occurred while querying the database for a user ban, retrying in 10 seconds. (%s)", err);
CreateTimer(10.0, RetryPlayerInfoUpdate, client);
if (hChild == null)
{
LogError("An error occurred while querying the database for a user ban, retrying in 10 seconds. (%s)", err);
CreateTimer(10.0, RetryPlayerInfoUpdate, GetClientSerial(client));
return;
}
return;
}
if (SQL_FetchRow(hChild))
{
g_bSprayBanned[client] = true;
g_iSprayUnbanTimestamp[client] = SQL_FetchInt(hChild, 2);
g_iSprayBanTimestamp[client] = SQL_FetchInt(hChild, 5);
if (SQL_FetchRow(hChild))
{
g_bSprayBanned[client] = true;
g_iSprayUnbanTimestamp[client] = SQL_FetchInt(hChild, 2);
g_iSprayBanTimestamp[client] = SQL_FetchInt(hChild, 5);
SQL_FetchString(hChild, 3, g_sBanIssuerSID[client], sizeof(g_sBanIssuerSID[]));
SQL_FetchString(hChild, 4, g_sBanIssuer[client], sizeof(g_sBanIssuer[]));
SQL_FetchString(hChild, 6, g_sBanReason[client], sizeof(g_sBanReason[]));
}
SQL_FetchString(hChild, 3, g_sBanIssuerSID[client], sizeof(g_sBanIssuerSID[]));
SQL_FetchString(hChild, 4, g_sBanIssuer[client], sizeof(g_sBanIssuer[]));
SQL_FetchString(hChild, 6, g_sBanReason[client], sizeof(g_sBanReason[]));
}
}
public void OnSQLCheckSprayHashBanQuery(Handle hParent, Handle hChild, const char[] err, any client)
public void OnSQLCheckSprayHashBanQuery(Handle hParent, Handle hChild, const char[] err, int Serial)
{
if (!IsValidClient(client))
return;
int client;
if ((client = GetClientFromSerial(Serial)) == 0)
{
return;
}
if (!IsValidClient(client))
return;
if (hChild == null)
{
LogError("An error occurred while querying the database for a spray ban, retrying in 10 seconds. (%s)", err);
CreateTimer(10.0, RetrySprayHashUpdate, client);
if (hChild == null)
{
LogError("An error occurred while querying the database for a spray ban, retrying in 10 seconds. (%s)", err);
CreateTimer(10.0, RetrySprayHashUpdate, GetClientSerial(client));
return;
}
return;
}
if (SQL_FetchRow(hChild))
g_bSprayHashBanned[client] = true;
if (SQL_FetchRow(hChild))
g_bSprayHashBanned[client] = true;
}
public void OnSQLCheckNSFWSprayHashQuery(Handle hParent, Handle hChild, const char[] err, any client)
public void OnSQLCheckNSFWSprayHashQuery(Handle hParent, Handle hChild, const char[] err, int Serial)
{
if (!IsValidClient(client))
return;
int client;
if ((client = GetClientFromSerial(Serial)) == 0)
{
return;
}
if (!IsValidClient(client))
return;
if (hChild == null)
{
LogError("An error occurred while querying the NSFW database for a spray, retrying in 10 seconds. (%s)", err);
CreateTimer(10.0, RetryNSFWSprayLookup, client);
if (hChild == null)
{
LogError("An error occurred while querying the NSFW database for a spray, retrying in 10 seconds. (%s)", err);
CreateTimer(10.0, RetryNSFWSprayLookup, GetClientSerial(client));
return;
}
return;
}
if (SQL_FetchRow(hChild))
{
g_bHasNSFWSpray[client] = true;
if (SQL_FetchRow(hChild))
{
g_bHasNSFWSpray[client] = true;
char sSetByAdmin[8];
SQL_FetchString(hChild, 2, sSetByAdmin, sizeof(sSetByAdmin));
char sSetByAdmin[8];
SQL_FetchString(hChild, 2, sSetByAdmin, sizeof(sSetByAdmin));
g_bMarkedNSFWByAdmin[client] = view_as<bool>(StringToInt(sSetByAdmin));
}
g_bMarkedNSFWByAdmin[client] = view_as<bool>(StringToInt(sSetByAdmin));
}
}
public Action RetryPlayerInfoUpdate(Handle hTimer, any client)
public Action RetryPlayerInfoUpdate(Handle hTimer, int Serial)
{
UpdatePlayerInfo(client);
int client;
if ((client = GetClientFromSerial(Serial)) == 0)
{
return;
}
UpdatePlayerInfo(client);
}
public Action RetrySprayHashUpdate(Handle hTimer, any client)
public Action RetrySprayHashUpdate(Handle hTimer, int Serial)
{
UpdateSprayHashInfo(client);
int client;
if ((client = GetClientFromSerial(Serial)) == 0)
{
return;
}
UpdateSprayHashInfo(client);
}
public Action RetryNSFWSprayLookup(Handle hTimer, any client)
public Action RetryNSFWSprayLookup(Handle hTimer, int Serial)
{
UpdateNSFWInfo(client);
int client;
if ((client = GetClientFromSerial(Serial)) == 0)
{
return;
}
UpdateNSFWInfo(client);
}
stock bool ForceSpray(int client, int target, bool bPlaySound=true)

View File

@ -161,13 +161,20 @@ public void sql_select_hiding_unavailable_maps(int client)
GetClientAuthId(client, AuthId_Steam2, steam_auth, sizeof(steam_auth));
//we have way too many dbs, just adding this to unloze_race_timer
Format(query, sizeof(query), "SELECT is_ignoring FROM `mapchooser_hide_unavailable` where steam_auth = '%s'", steam_auth);
g_dDatabase.Query(SQL_OnQueryCompleted_ignoring, query, client);
g_dDatabase.Query(SQL_OnQueryCompleted_ignoring, query, GetClientSerial(client));
}
public void SQL_OnQueryCompleted_ignoring(Database db, DBResultSet results, const char[] error, int client)
public void SQL_OnQueryCompleted_ignoring(Database db, DBResultSet results, const char[] error, int Serial)
{
if (!db)
{
delete results;
return;
}
int client;
if ((client = GetClientFromSerial(Serial)) == 0)
{
delete results;
return;
}
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
@ -180,6 +187,7 @@ public void SQL_OnQueryCompleted_ignoring(Database db, DBResultSet results, cons
g_bClientsIgnoring[client] = true;
}
}
delete results;
}
public void sql_insert_update_hiding_unavailable(int client)
@ -216,15 +224,16 @@ public void sql_insert_update_hiding_unavailable(int client)
public void SQL_FinishedQuery(Database db, DBResultSet results, const char[] error, DataPack data)
{
if (!db || strlen(error))
{
char sQuery[256];
ResetPack(data);
data.ReadString(sQuery, sizeof(sQuery));
LogError("Query error 3: %s", error);
LogError("actual query: %s", sQuery);
}
delete data;
if (!db || strlen(error))
{
char sQuery[256];
ResetPack(data);
data.ReadString(sQuery, sizeof(sQuery));
LogError("Query error 3: %s", error);
LogError("actual query: %s", sQuery);
}
delete results;
delete data;
}
public void OnClientDisconnect(int client)

View File

@ -238,7 +238,10 @@ public void OnMapStart()
//----------------------------------------------------------------------------------------------------
public void OnConfigsExecuted()
{
Database.Connect(SQL_OnDatabaseConnect, "season");
if (!g_hDatabase)
{
Database.Connect(SQL_OnDatabaseConnect, "season");
}
}
//----------------------------------------------------------------------------------------------------