csgo-plugins/UNLOZE_BanDetector/scripting/UNLOZE_BanDetector.sp
2020-03-25 20:09:12 +02:00

189 lines
7.2 KiB
SourcePawn

//====================================================================================================
//
// Name: i3D.net Ban Detector.
// Author: zaCade
// Description: Detect potential ban evasions.
//
//====================================================================================================
#undef REQUIRE_PLUGIN
#include <sourcemod>
#include <sourcebans>
#include <SteamWorks>
new G_iParentAuthID[MAXPLAYERS+1];
new G_iClientAuthID[MAXPLAYERS+1];
new bool:G_bSourcebansAvailable;
new Handle:G_hDatabase;
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Plugin:myinfo =
{
name = "UNLOZE Ban Detector",
author = "zaCade",
description = "Detect potential ban evasions",
version = "1.0",
};
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public OnPluginStart()
{
SQL_TConnect(SQL_OnConnected, "sourcebans");
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public OnAllPluginsLoaded()
{
if (LibraryExists("sourcebans"))
G_bSourcebansAvailable = true;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public OnLibraryAdded(const String:name[])
{
if (StrEqual("sourcebans", name))
G_bSourcebansAvailable = true;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public OnLibraryRemoved(const String:name[])
{
if (StrEqual("sourcebans", name))
G_bSourcebansAvailable = false;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public OnClientConnected(client)
{
G_iParentAuthID[client] = -1;
G_iClientAuthID[client] = -1;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public OnClientDisconnect(client)
{
G_iParentAuthID[client] = -1;
G_iClientAuthID[client] = -1;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public OnClientPostAdminCheck(client)
{
if (G_bSourcebansAvailable && !IsFakeClient(client))
{
if (G_iParentAuthID[client] != -1 && G_iClientAuthID[client] != -1)
CheckBans_SteamID(client, G_iParentAuthID[client], G_iClientAuthID[client]);
CheckBans_IPAdress(client);
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public SteamWorks_OnValidateClient(parentAuthID, clientAuthID)
{
if (G_bSourcebansAvailable && parentAuthID != clientAuthID)
{
for (new client = 1; client <= MaxClients; client++)
{
if (IsClientConnected(client) && GetSteamAccountID(client) == clientAuthID)
{
if (!IsClientInGame(client))
{
G_iParentAuthID[client] = parentAuthID;
G_iClientAuthID[client] = clientAuthID;
break;
}
else
{
CheckBans_SteamID(client, parentAuthID, clientAuthID);
break;
}
}
}
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public CheckBans_SteamID(client, parentAuthID, clientAuthID)
{
new String:authid[32];
Format(authid, sizeof(authid), "STEAM_0:%d:%d", (parentAuthID & 1), (parentAuthID >> 1));
new String:query[512];
Format(query, sizeof(query), "SELECT * FROM sb_bans WHERE authid = '%s' AND ((length = 0 OR ends > UNIX_TIMESTAMP()) AND removetype IS NULL)", authid);
// Format(query, sizeof(query), "SELECT * FROM sb_bans WHERE authid = '%s' AND ((ends > '%d' AND length != '0') OR length = '0')", authid, GetTime());
LogMessage("[BanDetector] Checking family sharing user %L (AUTH: %s, PAUTH: %d, CAUTH: %d)", client, authid, parentAuthID, clientAuthID);
if (G_hDatabase != INVALID_HANDLE)
SQL_TQuery(G_hDatabase, SQL_OnCheckClientSteamID, query, client);
else
LogMessage("[BanDetector] Unable to check user %L (No database)", client);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public CheckBans_IPAdress(client)
{
new String:adress[32];
GetClientIP(client, adress, sizeof(adress));
new String:query[512];
Format(query, sizeof(query), "SELECT * FROM sb_bans WHERE ip = '%s' AND ((length = 0 OR ends > UNIX_TIMESTAMP()) AND removetype IS NULL AND (aid != 0 OR reason != 'Ban evasion (IP)')", adress);
// Format(query, sizeof(query), "SELECT * FROM sb_bans WHERE ip = '%s' AND ((ends > '%d' AND length != '0') OR length = '0') AND ((reason != 'Ban evasion (IP)' AND aid = '0') OR aid != '0')", adress, GetTime());
LogMessage("[BanDetector] Checking user %L (IP: %s)", client, adress);
if (G_hDatabase != INVALID_HANDLE)
SQL_TQuery(G_hDatabase, SQL_OnCheckClientIP, query, client);
else
LogMessage("[BanDetector] Unable to check user %L (No database)", client);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public SQL_OnConnected(Handle:owner, Handle:handle, const String:error[], any:data)
{
if (handle != INVALID_HANDLE)
G_hDatabase = handle;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public SQL_OnCheckClientSteamID(Handle:owner, Handle:handle, const String:error[], any:client)
{
if (handle != INVALID_HANDLE && SQL_FetchRow(handle))
SBBanPlayer(0, client, 0, "Ban evasion (FS)");
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public SQL_OnCheckClientIP(Handle:owner, Handle:handle, const String:error[], any:client)
{
if (handle != INVALID_HANDLE && SQL_FetchRow(handle))
SBBanPlayer(0, client, 0, "Ban evasion (IP)");
}