updated several things
This commit is contained in:
@@ -10,10 +10,8 @@
|
||||
#include <cstrike>
|
||||
#include <sdktools>
|
||||
|
||||
int validate_state [MAXPLAYERS + 1];
|
||||
Database g_dDatabase;
|
||||
Handle g_hOnReportBanPostForward;
|
||||
bool g_bReportedClientBanAvoiding[MAXPLAYERS + 1];
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
@@ -37,15 +35,33 @@ public void OnPluginStart()
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "jenz_ban_detector");
|
||||
}
|
||||
for (int i = 0; i < MaxClients; i++)
|
||||
}
|
||||
|
||||
public void OnMapStart()
|
||||
{
|
||||
if (!g_dDatabase)
|
||||
{
|
||||
if (IsValidClient(i))
|
||||
{
|
||||
validate_state[i] = 0;
|
||||
g_bReportedClientBanAvoiding[i] = false;
|
||||
}
|
||||
Database.Connect(SQL_OnDatabaseConnect, "jenz_ban_detector");
|
||||
}
|
||||
}
|
||||
|
||||
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
|
||||
{
|
||||
if(!db || strlen(error))
|
||||
{
|
||||
LogError("Database error: %s", error);
|
||||
return;
|
||||
}
|
||||
g_dDatabase = db;
|
||||
}
|
||||
|
||||
public void OnClientPostAdminCheck(int client)
|
||||
{
|
||||
if (!IsFakeClient(client) && !IsClientSourceTV(client))
|
||||
{
|
||||
SQL_addEntry(client);
|
||||
CreateTimer(15.0, SQL_Select_fingerprints, GetClientSerial(client));
|
||||
}
|
||||
CreateTimer(10.0, start_checks, _, TIMER_REPEAT);
|
||||
}
|
||||
|
||||
public void SQL_addEntry(int client)
|
||||
@@ -60,20 +76,10 @@ 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 into `ban_detector_steamids` (`steamid`, `name`, `ID`) SELECT '%s', '%s', bd.ID from `ban_detector` bd where bd.ip = '%s' and not exists (select bds.ID from `ban_detector_steamids` bds where bds.ID = bd.ID and bds.steamid = '%s')", sSID, sEscapedName, sIP, sSID);
|
||||
Format(sQuery, sizeof(sQuery), "insert ignore into `ban_detector` (`steamid`, `ip`, `name`) SELECT '%s', '%s','%s'", sSID, sIP,sEscapedName);
|
||||
g_dDatabase.Query(SQL_UpdateEntry, sQuery, GetClientSerial(client), DBPrio_Low);
|
||||
}
|
||||
|
||||
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
|
||||
{
|
||||
if(!db || strlen(error))
|
||||
{
|
||||
LogError("Database error: %s", error);
|
||||
return;
|
||||
}
|
||||
g_dDatabase = db;
|
||||
}
|
||||
|
||||
public void SQL_UpdateEntry(Database db, DBResultSet results, const char[] error, int Serial)
|
||||
{
|
||||
if(!db || strlen(error))
|
||||
@@ -89,17 +95,45 @@ public void SQL_UpdateEntry(Database db, DBResultSet results, const char[] error
|
||||
return;
|
||||
}
|
||||
if (IsValidClient(client))
|
||||
{
|
||||
char sQuery[g_dLength];
|
||||
char sSID[MAX_NAME_LENGTH];
|
||||
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
|
||||
Format(sQuery, sizeof(sQuery), "UPDATE ban_detector SET last_connect = now() where steamid = '%s'", sSID);
|
||||
g_dDatabase.Query(SQL_update_last_connect, sQuery, GetClientSerial(client), DBPrio_Low);
|
||||
}
|
||||
delete results;
|
||||
}
|
||||
|
||||
public void SQL_update_last_connect(Database db, DBResultSet results, const char[] error, int Serial)
|
||||
{
|
||||
if(!db || strlen(error))
|
||||
{
|
||||
LogError("Database error: %s", error);
|
||||
delete results;
|
||||
return;
|
||||
}
|
||||
delete results;
|
||||
}
|
||||
|
||||
public Action SQL_Select_fingerprints(Handle hTimer, int Serial)
|
||||
{
|
||||
int client;
|
||||
if ((client = GetClientFromSerial(Serial)) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsValidClient(client))
|
||||
{
|
||||
char sQuery[g_dLength];
|
||||
char sSID[MAX_NAME_LENGTH];
|
||||
char sIP[MAX_NAME_LENGTH];
|
||||
GetClientIP(client, sIP, sizeof(sIP));
|
||||
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
|
||||
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);
|
||||
Format(sQuery, sizeof(sQuery), "select fingerprint from ban_detector.ban_detector where steamid = '%s'", sSID);
|
||||
//PrintToChatAll("sQuery: %s", sQuery);
|
||||
g_dDatabase.Query(SQL_FindFingerPrints, sQuery, GetClientSerial(client), DBPrio_Low);
|
||||
}
|
||||
delete results;
|
||||
}
|
||||
|
||||
public void SQL_FindFingerPrints(Database db, DBResultSet results, const char[] error, int Serial)
|
||||
@@ -124,7 +158,8 @@ 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, 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 (");
|
||||
//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 (");
|
||||
bool first = true;
|
||||
while (results.RowCount > 0 && results.FetchRow())
|
||||
{
|
||||
@@ -173,90 +208,25 @@ public void sql_select_sb_bans(Database db, DBResultSet results, const char[] er
|
||||
return;
|
||||
}
|
||||
|
||||
if (results.RowCount && results.FetchRow() && IsValidClient(client) && !g_bReportedClientBanAvoiding[client])
|
||||
if (results.RowCount && results.FetchRow() && IsValidClient(client))
|
||||
{
|
||||
g_bReportedClientBanAvoiding[client] = true;
|
||||
char sSID[MAX_NAME_LENGTH];
|
||||
char sIP[MAX_NAME_LENGTH];
|
||||
results.FetchString(0, sSID, sizeof(sSID));
|
||||
results.FetchString(1, sIP, sizeof(sIP));
|
||||
Call_StartForward(g_hOnReportBanPostForward);
|
||||
Call_PushCell(client);
|
||||
if (strlen(sSID) == 0)
|
||||
{
|
||||
// use IP instead if no steamID
|
||||
Call_PushString(sIP);
|
||||
}
|
||||
else
|
||||
{
|
||||
//found steamID
|
||||
Call_PushString(sSID);
|
||||
}
|
||||
Call_PushString(sSID);
|
||||
Call_Finish();
|
||||
//bans need to be over 1 hour long for getting detected
|
||||
if (strlen(sSID) == 0)
|
||||
{
|
||||
SBPP_BanPlayer(0, client, 0, "Ban avoiding (Jenz ban detector). Same IP avoiding ban.");
|
||||
}
|
||||
else
|
||||
{
|
||||
char message[1024];
|
||||
Format(message, sizeof(message), "Ban avoiding (Jenz ban detector). SteamID avoiding ban: %s", sSID);
|
||||
SBPP_BanPlayer(0, client, 0, message);
|
||||
}
|
||||
char message[1024];
|
||||
Format(message, sizeof(message), "Ban avoiding (Jenz ban detector). SteamID avoiding ban: %s", sSID);
|
||||
SBPP_BanPlayer(0, client, 0, message);
|
||||
}
|
||||
delete results;
|
||||
}
|
||||
|
||||
public Action start_checks(Handle hTimer)
|
||||
{
|
||||
for (int i = 0; i < MaxClients; i++)
|
||||
{
|
||||
if (IsValidClient(i) && validate_state[i] == 0)
|
||||
{
|
||||
validate_state[i] = -1;
|
||||
SQL_addEntry(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMapStart()
|
||||
{
|
||||
if (!g_dDatabase)
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "jenz_ban_detector");
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClientDisconnect(int client)
|
||||
{
|
||||
validate_state[client] = -1;
|
||||
g_bReportedClientBanAvoiding[client] = false;
|
||||
}
|
||||
|
||||
public void OnClientPostAdminCheck(int client)
|
||||
{
|
||||
validate_state[client] = -1;
|
||||
CreateTimer(10.0, make_db_entry, GetClientSerial(client));
|
||||
g_bReportedClientBanAvoiding[client] = false;
|
||||
}
|
||||
|
||||
public Action make_db_entry(Handle hTimer, int Serial)
|
||||
{
|
||||
int client;
|
||||
if ((client = GetClientFromSerial(Serial)) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsValidClient(client))
|
||||
{
|
||||
validate_state[client] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
stock bool IsValidClient(int client)
|
||||
{
|
||||
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && !IsFakeClient(client))
|
||||
return true;
|
||||
return false;
|
||||
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && !IsFakeClient(client))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user