2018-07-23 22:40:46 +02:00
//====================================================================================================
//
// Name: i3D.net Ban Detector.
// Author: zaCade
// Description: Detect potential ban evasions.
//
//====================================================================================================
# undef REQUIRE_PLUGIN
# include <sourcemod>
2021-04-30 13:53:55 +02:00
# include <sourcebanspp>
2018-07-23 22:40:46 +02:00
# 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 ] ;
2021-04-30 14:04:42 +02:00
Format ( query , sizeof ( query ) , " SELECT * FROM sb_bans WHERE authid = '%s' AND ((length = 0 OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL) " , authid ) ;
2018-07-23 22:40:46 +02:00
// 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 ] ;
2021-04-30 14:04:42 +02:00
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 ) ;
2018-07-23 22:40:46 +02:00
// 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 )
{
2021-12-02 00:49:10 +01:00
//SBPP_BanPlayer(0, client, 0, "Ban evasion (FS)");
2018-07-23 22:40:46 +02:00
if ( handle ! = INVALID_HANDLE & & SQL_FetchRow ( handle ) )
2021-12-02 00:49:10 +01:00
KickClient ( client , " Ban evasion (FS) " ) ;
2018-07-23 22:40:46 +02:00
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public SQL_OnCheckClientIP ( Handle : owner , Handle : handle , const String : error [ ] , any : client )
{
2021-12-02 00:49:10 +01:00
//SBPP_BanPlayer(0, client, 0, "Ban evasion (IP)");
2018-07-23 22:40:46 +02:00
if ( handle ! = INVALID_HANDLE & & SQL_FetchRow ( handle ) )
2021-12-02 00:49:10 +01:00
KickClient ( client , " Ban evasion (IP) " ) ;
2021-04-30 13:53:55 +02:00
}