added query to check if IP and steamID combo alreayd present to reduce amount of http requests

This commit is contained in:
jenz 2022-04-10 20:02:14 +02:00
parent 69824f8eed
commit 42faa95ffa

View File

@ -298,6 +298,50 @@ public void sql_update_cooldown(Database db, DBResultSet results, const char[] e
KickClient(client, "If you believe this is undeserved write a forum post on https://www.unloze.com");
}
public void sql_select_if_exists(Database db, DBResultSet results, const char[] error, any data)
{
if(!db || strlen(error))
{
LogError("Query error: %s", error);
return;
}
int client;
if ((client = GetClientFromSerial(data)) == 0)
return;
char sAddress[16];
GetClientIP(client, sAddress, sizeof(sAddress));
if (results.RowCount && results.FetchRow())
{
char sql_statement[1024];
char s_country[64];
char s_asn[512];
char s_provider[64];
char s_steam[64];
char s_ipv4[64];
results.FetchString(0, s_country, sizeof(s_country));
results.FetchString(1, s_asn, sizeof(s_asn));
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(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);
}
else
{
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);
if (!hRequest ||
!SteamWorks_SetHTTPCallbacks(hRequest, OnTransferComplete) ||
!SteamWorks_SetHTTPRequestContextValue(hRequest, GetClientSerial(client)) ||
!SteamWorks_SendHTTPRequest(hRequest))
{
delete hRequest;
}
}
delete results;
}
public void resetClient(int client)
{
Format(g_asn[client], sizeof(g_asn[]), "");
@ -327,20 +371,13 @@ public void OnClientPostAdminCheck(int client)
resetClient(client);
char sAuthID[32];
GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), false);
char sIP[32];
GetClientIP(client, sIP, sizeof(sIP));
if (!SteamClientAuthenticated(sAuthID))
{
char sAddress[16];
GetClientIP(client, sAddress, sizeof(sAddress));
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);
if (!hRequest ||
!SteamWorks_SetHTTPCallbacks(hRequest, OnTransferComplete) ||
!SteamWorks_SetHTTPRequestContextValue(hRequest, GetClientSerial(client)) ||
!SteamWorks_SendHTTPRequest(hRequest))
{
delete hRequest;
}
char sql_statement[512];
Format(sql_statement, sizeof(sql_statement), "select * from connect_restriction where steam_id = '%s' and ipv4 = '%s'", sAuthID, sIP);
g_hDatabase.Query(sql_select_if_exists, sql_statement, GetClientSerial(client), DBPrio_High);
}
}