replacing while loops with concatting

This commit is contained in:
jenz 2023-06-20 23:47:39 +02:00
parent 168bcf5b4e
commit cc96bb56a4

View File

@ -133,21 +133,31 @@ public void SQL_FindFingerPrints(Database db, DBResultSet results, const char[]
delete results;
return;
}
char fingerprint[1024];
//god knows how big this might be
char sQuery[6144];
Format(sQuery, sizeof(sQuery), "select steamid, ip from ban_detector bd inner join ban_detector_steamids bds on bd.ID = bds.ID where fingerprint in (");
bool first = true;
while (results.RowCount > 0 && results.FetchRow())
{
char fingerprint[1024];
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 bd inner join ban_detector_steamids bds on bd.ID = bds.ID where fingerprint = '%s'", sEscapedFingerPrint);
//PrintToChatAll("sQuery: %s", sQuery);
g_dDatabase.Query(SQL_checkSourcebans, sQuery, GetClientSerial(client), DBPrio_Low);
if (IsValidClient(client) && g_bReportedClientBanAvoiding[client])
if (first)
{
break;
Format(sEscapedFingerPrint, 1024, "'%s'", sEscapedFingerPrint);
}
else
{
Format(sEscapedFingerPrint, 1024, ",'%s'", sEscapedFingerPrint);
}
StrCat(sQuery, sizeof(sQuery), sEscapedFingerPrint);
first = false;
}
StrCat(sQuery, sizeof(sQuery), ")");
//LogError("LOOK HERE: %s", sQuery);
g_dDatabase.Query(SQL_checkSourcebans, sQuery, GetClientSerial(client), DBPrio_Low);
delete results;
}
@ -171,23 +181,38 @@ public void SQL_checkSourcebans(Database db, DBResultSet results, const char[] e
delete results;
return;
}
//god knows how big it needs to be.
char sql_statement[6144];
char sql_extra[2048];
bool first = true;
Format(sql_statement, sizeof(sql_statement), "select authid, ip from sb_bans where ((ip in (");
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];
//PrintToChatAll(sSID);
//PrintToChatAll(sIP);
// + 3600 for one hour to accomdate timezone difference
Format(sql_statement, sizeof(sql_statement), "select authid, ip from sb_bans where ((ip = '%s' and ip is not null and ip != '') or (authid = '%s' and authid is not null and authid =! '')) 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, GetClientSerial(client), DBPrio_Low);
if (IsValidClient(client) && g_bReportedClientBanAvoiding[client])
if (first)
{
break;
Format(sSID, MAX_NAME_LENGTH, "'%s'", sSID);
Format(sIP, MAX_NAME_LENGTH, "'%s'", sIP);
}
else
{
Format(sSID, MAX_NAME_LENGTH, ",'%s'", sSID);
Format(sIP, MAX_NAME_LENGTH, ",'%s'", sIP);
}
StrCat(sql_statement, sizeof(sql_statement), sIP);
StrCat(sql_extra, sizeof(sql_extra), sSID);
first = false;
}
StrCat(sql_statement, sizeof(sql_statement), ") and ip is not null and ip != '') or (authid in (");
StrCat(sql_statement, sizeof(sql_statement), sql_extra);
// + 3600 for one hour to accomdate timezone difference
StrCat(sql_statement, sizeof(sql_statement), ") and authid is not null and authid =! '')) and (RemoveType != 'U' or RemoveType is NULL) and (ends > UNIX_TIMESTAMP() + 3600 or ends = created) order by created desc limit 1");
//LogError("LOOK HERE 2: %s", sql_statement);
g_hDatabase_sourceban.Query(sql_select_sb_bans, sql_statement, GetClientSerial(client), DBPrio_Low);
delete results;
}