added query display on update

This commit is contained in:
jenz 2022-04-23 18:36:34 +02:00
parent 3fc37089bd
commit f04173482c

View File

@ -44,7 +44,7 @@ public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
char sQuery[512];
Format(sQuery, sizeof(sQuery), "CREATE TABLE if not exists `sb_bans_shortened` (`steam_id` varchar(64) NOT NULL, `ipv4` varchar(64) NOT NULL, PRIMARY KEY (`steam_id`,`ipv4`))");
g_hDatabase.Query(sql_insert_dummy, sQuery, _, DBPrio_High);
Format(sQuery, sizeof(sQuery), "CREATE TABLE if not exists `connect_restriction` (`country` varchar(64) DEFAULT NULL, `asn` varchar(128) DEFAULT NULL, `provider` varchar(128) DEFAULT NULL, `cooldown` datetime DEFAULT NULL, `steam_id` varchar(64) NOT NULL, `ipv4` varchar(64) NOT NULL, `inserted_on` datetime DEFAULT current_timestamp(), `modified_on` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`steam_id`,`ipv4`))");
Format(sQuery, sizeof(sQuery), "CREATE TABLE if not exists `connect_restriction` (`country` varchar(64) DEFAULT NULL, `asn` varchar(128) DEFAULT NULL, `provider` varchar(128) DEFAULT NULL, `cooldown` datetime DEFAULT NULL, `steam_id` varchar(64) NOT NULL, `ipv4` varchar(64) NOT NULL, `inserted_on` datetime DEFAULT current_timestamp(), `cooldown_query` varchar(1028) DEFAULT NULL, `modified_on` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`steam_id`,`ipv4`))");
g_hDatabase.Query(SQL_OnQueryCompleted, sQuery, _, DBPrio_High);
}
@ -137,12 +137,14 @@ public void SQL_insert(Database db, DBResultSet results, const char[] error, any
int client;
if ((client = GetClientFromSerial(data)) == 0)
return;
char sql_statement[512];
char sql_statement[1024];
char sIP[64];
char ip_subblock[8][8];
GetClientIP(client, sIP, sizeof(sIP));
ExplodeString(sIP, ".", ip_subblock, sizeof(ip_subblock), sizeof(ip_subblock[]));
Format(sql_statement, sizeof(sql_statement), "update connect_restriction cr1 inner join (select * from connect_restriction cr3 where cr3.asn = '%s' and cr3.provider = '%s' and cr3.country = '%s' and cr3.ipv4 like '%s.%s%s' and cr3.cooldown > CURDATE() order by cr3.inserted_on desc limit 1) as cr2 on cr1.asn = cr2.asn and cr1.provider = cr2.provider and cr1.country = cr2.country set cr1.cooldown = cr2.cooldown", g_asn[client], g_provider[client], g_country[client], ip_subblock[0], ip_subblock[1], "%");
Format(sql_statement, sizeof(sql_statement), "update connect_restriction cr1 inner join (select * from connect_restriction cr3 where cr3.asn = '%s' and cr3.provider = '%s' and cr3.country = '%s' and cr3.ipv4 like '%s.%s.%s%s' and cr3.cooldown > CURDATE() order by cr3.inserted_on desc limit 1) as cr2 on cr1.asn = cr2.asn and cr1.provider = cr2.provider and cr1.country = cr2.country set cr1.cooldown = cr2.cooldown", g_asn[client], g_provider[client], g_country[client], ip_subblock[0], ip_subblock[1], ip_subblock[2], "%");
Format(sql_statement, sizeof(sql_statement), "%s , cr1.cooldown_query = %s%s%s", sql_statement, "\"", sql_statement, "\"");
//LogMessage("sql_statement: %s", sql_statement);
delete results;
g_hDatabase.Query(SQL_update_restriction, sql_statement, GetClientSerial(client), DBPrio_High);
}
@ -163,7 +165,7 @@ public void SQL_update_restriction(Database db, DBResultSet results, const char[
GetClientIP(client, sIP, sizeof(sIP));
ExplodeString(sIP, ".", ip_subblock, sizeof(ip_subblock), sizeof(ip_subblock[]));
char sql_statement[512];
Format(sql_statement, sizeof(sql_statement), "select * from connect_restriction where asn = '%s' and provider = '%s' and country = '%s' and ipv4 like '%s.%s%s' and cooldown > CURDATE() order by inserted_on desc limit 1", g_asn[client], g_provider[client], g_country[client], ip_subblock[0], ip_subblock[1], "%");
Format(sql_statement, sizeof(sql_statement), "select * from connect_restriction where asn = '%s' and provider = '%s' and country = '%s' and ipv4 like '%s.%s.%s%s' and cooldown > CURDATE() order by inserted_on desc limit 1", g_asn[client], g_provider[client], g_country[client], ip_subblock[0], ip_subblock[1], ip_subblock[2], "%");
g_hDatabase.Query(sql_select_cooldown, sql_statement, GetClientSerial(client), DBPrio_High);
}
@ -181,7 +183,9 @@ public void sql_select_cooldown(Database db, DBResultSet results, const char[] e
{
char sIP[64];
GetClientIP(client, sIP, sizeof(sIP));
LogMessage("%L nosteamer got kicked for dynamic IP ban avoiding(IP: %s).", client, sIP);
char sAuthID[512];
GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), false);
LogMessage("%L | %s nosteamer got kicked for dynamic IP ban avoiding(IP: %s).", client, sAuthID, sIP);
KickClient(client, "If you believe this is undeserved write a forum post on https://www.unloze.com");
}
else
@ -250,7 +254,9 @@ public void sql_select_sb_bans(Database db, DBResultSet results, const char[] er
delete results;
char ip_subblock[8][8];
ExplodeString(s_client_ip, ".", ip_subblock, sizeof(ip_subblock), sizeof(ip_subblock[]));
Format(sql_statement, sizeof(sql_statement), "select cr1.* from connect_restriction cr1 inner join connect_restriction cr2 on cr1.asn = cr2.asn inner join sb_bans_shortened cr3 on cr1.steam_id = cr3.steam_id and cr1.ipv4 = cr3.ipv4 and cr1.provider = cr2.provider and cr1.country = cr2.country and cr2.ipv4 = '%s' and cr1.ipv4 like '%s.%s%s' limit 1", s_client_ip, ip_subblock[0], ip_subblock[1], "%");
Format(sql_statement, sizeof(sql_statement), "select cr1.* from connect_restriction cr1 inner join connect_restriction cr2 on cr1.asn = cr2.asn inner join sb_bans_shortened cr3 on cr1.steam_id = cr3.steam_id and cr1.ipv4 = cr3.ipv4 and cr1.provider = cr2.provider and cr1.country = cr2.country and cr2.ipv4 = '%s' and cr1.ipv4 like '%s.%s.%s%s' limit 1", s_client_ip, ip_subblock[0], ip_subblock[1], ip_subblock[2], "%");
char sAuthID[512];
GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), false);
g_hDatabase.Query(sql_select_banned, sql_statement, GetClientSerial(client), DBPrio_High);
}
@ -300,7 +306,9 @@ public void sql_update_cooldown(Database db, DBResultSet results, const char[] e
delete results;
char sIP[64];
GetClientIP(client, sIP, sizeof(sIP));
LogMessage("%L nosteamer got kicked for dynamic IP ban avoiding(IP: %s).", client, sIP);
char sAuthID[512];
GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), false);
LogMessage("%L | %s nosteamer got kicked for dynamic IP ban avoiding(IP: %s).", client, sAuthID, sIP);
KickClient(client, "If you believe this is undeserved write a forum post on https://www.unloze.com");
}
@ -329,11 +337,16 @@ public void sql_select_if_exists(Database db, DBResultSet results, const char[]
results.FetchString(2, s_provider, sizeof(s_provider));
results.FetchString(4, s_steam, sizeof(s_steam));
results.FetchString(5, s_ipv4, sizeof(s_ipv4));
Format(g_asn[client], sizeof(g_asn[]), s_asn);
Format(g_provider[client], sizeof(g_provider[]), s_provider);
Format(g_country[client], sizeof(g_country[]), s_country);
Format(sql_statement, sizeof(sql_statement), "insert into connect_restriction (country, asn, provider, steam_id, ipv4) values ('%s', '%s', '%s', '%s', '%s') ON DUPLICATE KEY UPDATE modified_on = now()", s_country, s_asn, s_provider, s_steam, s_ipv4);
g_hDatabase.Query(SQL_insert, sql_statement, GetClientSerial(client), DBPrio_High);
//we already have the infos on the IP address so we skip the https request
}
else
{
//we have not yet saved infos on the IP so we use the https request
char sRequest[256];
FormatEx(sRequest, sizeof(sRequest), "https://proxycheck.io/v2/%s?key=%s&asn=1", sAddress, APIKEY);
Handle hRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodGET, sRequest);