removed inner join, instead doing subquery

This commit is contained in:
jenz 2024-02-15 21:50:32 +01:00
parent d3b1a59885
commit 92096977d9

View File

@ -82,6 +82,7 @@ public void SQL_addEntry(int client)
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
g_dDatabase.Escape(sName, sEscapedName, size2 + 1);
GetClientIP(client, sIP, sizeof(sIP));
//Format(sQuery, sizeof(sQuery), "insert ignore into `ban_detector` (`steamid`, `ip`, `name`) SELECT '%s', '%s','%s'", sSID, sIP,sEscapedName);
Format(sQuery, sizeof(sQuery), "insert ignore into `ban_detector` (`steamid`, `ip`, `name`) SELECT '%s', '%s','%s'", sSID, sIP,sEscapedName);
g_dDatabase.Query(SQL_callback_insert_ignore, sQuery, GetClientSerial(client), DBPrio_Low);
}
@ -182,7 +183,8 @@ public Action SQL_Select_fingerprints(Handle hTimer, int Serial)
char sIP[MAX_NAME_LENGTH];
GetClientIP(client, sIP, sizeof(sIP));
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
Format(sQuery, sizeof(sQuery), "select fingerprint from ban_detector.ban_detector where steamid = '%s'", sSID);
//steamID is unique but fingerprint might occur multiple times.
Format(sQuery, sizeof(sQuery), "select steamid from ban_detector.ban_detector where fingerprint = (select fingerprint from ban_detector.ban_detector where steamid = '%s'", sSID);
//PrintToChatAll("sQuery: %s", sQuery);
g_dDatabase.Query(SQL_FindFingerPrints, sQuery, Serial, DBPrio_Low);
}
@ -211,35 +213,32 @@ public void SQL_FindFingerPrints(Database db, DBResultSet results, const char[]
//god knows how big this might need to be
char sQuery[4344];
Format(sQuery, sizeof(sQuery), "select sb.authid from unloze_sourceban.sb_bans where sb.authid in (");
//cant rely on IP cause several chinese players share VPN and end up with same IP despite clearly being different people.
Format(sQuery, sizeof(sQuery), "select sb.authid from ban_detector.ban_detector bd inner join unloze_sourceban.sb_bans sb on sb.authid = bd.steamid where fingerprint in (");
//now instead of fingerprint returns all steam IDs related to the specific fingerprint.
bool first = true;
//this is kinda obsolete now because it always just returns a single fingerprint. it was made for the intention of multiple fingerprints being returned.
//does not change that the IN clause still works, it will always just be a single element in the IN clause.
while (results.RowCount > 0 && results.FetchRow())
{
char fingerprint[1024];
results.FetchString(0, fingerprint, sizeof(fingerprint));
char[] sEscapedFingerPrint = new char[1024];
g_dDatabase.Escape(fingerprint, sEscapedFingerPrint, 1024);
char steamid[64];
results.FetchString(0, steamid, sizeof(steamid));
if (first)
{
Format(sEscapedFingerPrint, 1024, "'%s'", sEscapedFingerPrint);
StrCat(sQuery, sizeof(sQuery), steamid);
first = false;
}
else
{
Format(sEscapedFingerPrint, 1024, ",'%s'", sEscapedFingerPrint);
Format(steamid, sizeof(steamid), ",'%s'", steamid);
StrCat(sQuery, sizeof(sQuery), steamid);
}
StrCat(sQuery, sizeof(sQuery), sEscapedFingerPrint);
first = false;
}
StrCat(sQuery, sizeof(sQuery), ") and (RemoveType != 'U' or RemoveType is NULL) and (ends > UNIX_TIMESTAMP() + 3600 or ends = created) order by created desc limit 1");
//LogError("LOOK HERE: %s", sQuery);
delete results;
if (!first)
{
g_dDatabase.Query(sql_select_sb_bans, sQuery, Serial, DBPrio_Low);
}
delete results;
}
public void sql_select_sb_bans(Database db, DBResultSet results, const char[] error, int Serial)
@ -263,10 +262,11 @@ public void sql_select_sb_bans(Database db, DBResultSet results, const char[] er
return;
}
//if we get a result its a steam ID that still has an active ban. the steam ID that is banned is confirmed to have the same fingerprint as the connecting client.
if (results.RowCount && results.FetchRow())
{
char sSID[MAX_NAME_LENGTH];
results.FetchString(0, sSID, sizeof(sSID));
results.FetchString(0, sSID, sizeof(sSID));
Call_StartForward(g_hOnReportBanPostForward);
Call_PushCell(client);
Call_PushString(sSID);
@ -274,7 +274,8 @@ public void sql_select_sb_bans(Database db, DBResultSet results, const char[] er
//bans need to be over 1 hour long for getting detected
char message[1024];
Format(message, sizeof(message), "Ban avoiding (Jenz ban detector). SteamID avoiding ban: %s", sSID);
SBPP_BanPlayer(0, client, 0, message);
//instead of permaban now just banning the alt account for circa 3 months.
SBPP_BanPlayer(131487, client, 0, message);
}
delete results;
}