added sql check on connection if the player has an active ban

This commit is contained in:
jenz 2023-02-03 01:44:45 +01:00
parent 9f60bbbaa4
commit 532c3212ce

View File

@ -11,6 +11,7 @@
int validate_state [MAXPLAYERS + 1];
Database g_dDatabase;
Database g_hDatabase_sourceban;
public Plugin myinfo =
{
@ -53,7 +54,7 @@ public void SQL_checkEntries(int client)
Format(sQuery, sizeof(sQuery), "UPDATE `ban_detector` SET steamid='%s', name='%s' WHERE ip='%s'; ", sSID, sEscapedName, sIP);
//PrintToChatAll("sQuery: %s", sQuery);
g_dDatabase.Query(SQL_UpdateEntry, sQuery, _, DBPrio_High);
g_dDatabase.Query(SQL_UpdateEntry, sQuery, client, DBPrio_High);
}
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
@ -66,13 +67,120 @@ public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
g_dDatabase = db;
}
public void SQL_UpdateEntry(Database db, DBResultSet results, const char[] error, any data)
public void SQL_OnDatabaseConnect_sb(Database db, const char[] error, any data)
{
if(!db || strlen(error))
{
LogError("Database error: %s", error);
return;
}
g_hDatabase_sourceban = db;
}
public void SQL_UpdateEntry(Database db, DBResultSet results, const char[] error, int client)
{
if(!db || strlen(error))
{
LogError("Database error: %s", error);
return;
}
if (IsValidClient(client))
{
char sQuery[g_dLength];
char sSID[MAX_NAME_LENGTH];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
Format(sQuery, sizeof(sQuery), "SELECT fingerprint FROM `ban_detector` where steamid = '%s' and detected_on_sourceban is NULL limit 1", sSID);
//PrintToChatAll("sQuery: %s", sQuery);
g_dDatabase.Query(SQL_FindFingerPrints, sQuery, client, DBPrio_High);
}
delete results;
}
public void SQL_FindFingerPrints(Database db, DBResultSet results, const char[] error, int client)
{
if (!db || strlen(error))
{
LogError("Database error: %s", error);
return;
}
char fingerprint[1024];
if (results.RowCount && results.FetchRow())
{
results.FetchString(0, fingerprint, sizeof(fingerprint));
char sQuery[1024];
char[] sEscapedFingerPrint = new char[1024];
g_dDatabase.Escape(fingerprint, sEscapedFingerPrint, 1024);
Format(sQuery, sizeof(sQuery), "select steamid, ip from ban_detector where fingerprint = '%s'", sEscapedFingerPrint);
//PrintToChatAll("sQuery: %s", sQuery);
g_dDatabase.Query(SQL_checkSourcebans, sQuery, client, DBPrio_High);
}
delete results;
}
public void SQL_checkSourcebans(Database db, DBResultSet results, const char[] error, int client)
{
if (!db || strlen(error))
{
LogError("Database error: %s", error);
return;
}
while (results.RowCount > 0 && results.FetchRow())
{
char sSID[MAX_NAME_LENGTH];
char sIP[MAX_NAME_LENGTH];
results.FetchString(0, sSID, sizeof(sSID));
results.FetchString(1, sIP, sizeof(sIP));
char sql_statement[512];
// + 3600 for one hour to accomdate timezone difference
Format(sql_statement, sizeof(sql_statement), "select authid, ip from sb_bans where (ip = '%s' or authid = '%s') and (RemoveType != 'U' or RemoveType is NULL) and (ends > UNIX_TIMESTAMP() + 3600 or ends = created) order by created desc limit 1", sIP, sSID);
g_hDatabase_sourceban.Query(sql_select_sb_bans, sql_statement, client, DBPrio_High);
}
delete results;
}
public void sql_select_sb_bans(Database db, DBResultSet results, const char[] error, int client)
{
if (!db || strlen(error))
{
LogError("Database error: %s", error);
return;
}
if (!IsValidClient(client))
{
delete results;
return;
}
if (results.RowCount && results.FetchRow())
{
char sSID[MAX_NAME_LENGTH];
char sSIDClient[MAX_NAME_LENGTH];
GetClientAuthId(client, AuthId_Steam2, sSIDClient, sizeof(sSIDClient));
char sIP[MAX_NAME_LENGTH];
results.FetchString(0, sSID, sizeof(sSID));
results.FetchString(1, sIP, sizeof(sIP));
char sql_statement[512];
Format(sql_statement, sizeof(sql_statement), "UPDATE `ban_detector` SET detected_on_sourceban = '%s' where steamid = '%s'", sSID, sSIDClient);
if (strlen(sSID) == 0)
{
Format(sql_statement, sizeof(sql_statement), "UPDATE `ban_detector` SET detected_on_sourceban = '%s' where steamid = '%s'", sIP, sSIDClient);
}
g_dDatabase.Query(SQL_UpdateLogged, sql_statement, _, DBPrio_High);
}
delete results;
}
public void SQL_UpdateLogged(Database db, DBResultSet results, const char[] error, any data)
{
if (!db || strlen(error))
{
LogError("Database error: %s", error);
return;
}
delete results;
}
public Action start_checks(Handle hTimer)
@ -83,12 +191,19 @@ public Action start_checks(Handle hTimer)
}
else
{
for (int i = 0; i < MaxClients; i++)
if (!g_hDatabase_sourceban)
{
if (IsValidClient(i) && validate_state[i] == 0)
Database.Connect(SQL_OnDatabaseConnect_sb, "sourcebans");
}
else
{
for (int i = 0; i < MaxClients; i++)
{
validate_state[i] = -1;
SQL_checkEntries(i);
if (IsValidClient(i) && validate_state[i] == 0)
{
validate_state[i] = -1;
SQL_checkEntries(i);
}
}
}
}