redid query so its smaller by just inner joining sourcebans
This commit is contained in:
parent
a88daaf583
commit
d5b9191521
@ -12,7 +12,6 @@
|
||||
|
||||
int validate_state [MAXPLAYERS + 1];
|
||||
Database g_dDatabase;
|
||||
Database g_hDatabase_sourceban;
|
||||
Handle g_hOnReportBanPostForward;
|
||||
bool g_bReportedClientBanAvoiding[MAXPLAYERS + 1];
|
||||
|
||||
@ -75,17 +74,6 @@ public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
|
||||
g_dDatabase = db;
|
||||
}
|
||||
|
||||
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 Serial)
|
||||
{
|
||||
if(!db || strlen(error))
|
||||
@ -107,7 +95,7 @@ public void SQL_UpdateEntry(Database db, DBResultSet results, const char[] error
|
||||
char sIP[MAX_NAME_LENGTH];
|
||||
GetClientIP(client, sIP, sizeof(sIP));
|
||||
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
|
||||
Format(sQuery, sizeof(sQuery), "SELECT bd.fingerprint FROM `ban_detector` bd inner join `ban_detector_steamids` bds on bd.ID = bds.ID where bds.steamid = '%s' or bd.ip = '%s'", sSID, sIP);
|
||||
Format(sQuery, sizeof(sQuery), "SELECT distinct (bd.fingerprint) FROM `ban_detector` bd inner join `ban_detector_steamids` bds on bd.ID = bds.ID where bds.steamid = '%s' or bd.ip = '%s'", sSID, sIP);
|
||||
//PrintToChatAll("sQuery: %s", sQuery);
|
||||
g_dDatabase.Query(SQL_FindFingerPrints, sQuery, GetClientSerial(client), DBPrio_Low);
|
||||
}
|
||||
@ -134,9 +122,9 @@ public void SQL_FindFingerPrints(Database db, DBResultSet results, const char[]
|
||||
return;
|
||||
}
|
||||
|
||||
//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 (");
|
||||
//god knows how big this might need to be
|
||||
char sQuery[4344];
|
||||
Format(sQuery, sizeof(sQuery), "select sb.authid, sb.ip from ban_detector.ban_detector bd inner join ban_detector.ban_detector_steamids bds on bd.ID = bds.ID inner join unloze_sourceban.sb_bans sb on sb.authid = bds.steamid or sb.ip = bd.ip where fingerprint in (");
|
||||
bool first = true;
|
||||
while (results.RowCount > 0 && results.FetchRow())
|
||||
{
|
||||
@ -155,64 +143,12 @@ public void SQL_FindFingerPrints(Database db, DBResultSet results, const char[]
|
||||
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;
|
||||
}
|
||||
|
||||
public void SQL_checkSourcebans(Database db, DBResultSet results, const char[] error, int Serial)
|
||||
{
|
||||
if (!db || strlen(error))
|
||||
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);
|
||||
if (!first)
|
||||
{
|
||||
delete results;
|
||||
LogError("Database error: %s", error);
|
||||
return;
|
||||
g_dDatabase.Query(sql_select_sb_bans, sQuery, GetClientSerial(client), DBPrio_Low);
|
||||
}
|
||||
|
||||
int client;
|
||||
if ((client = GetClientFromSerial(Serial)) == 0)
|
||||
{
|
||||
delete results;
|
||||
return;
|
||||
}
|
||||
if (!IsValidClient(client))
|
||||
{
|
||||
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));
|
||||
if (first)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@ -221,7 +157,7 @@ public void sql_select_sb_bans(Database db, DBResultSet results, const char[] er
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
delete results;
|
||||
LogError("Database error: %s", error);
|
||||
LogError("Database error 2: %s", error);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -281,11 +217,6 @@ public void OnMapStart()
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "jenz_ban_detector");
|
||||
}
|
||||
|
||||
if (!g_hDatabase_sourceban)
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect_sb, "sourcebans");
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClientDisconnect(int client)
|
||||
|
Loading…
Reference in New Issue
Block a user