2018-03-24 17:20:48 +01:00
# pragma semicolon 1
# include <sourcemod>
# include <basecomm>
# include <connect>
# pragma newdecls required
2018-03-26 21:44:05 +02:00
/* CONVARS */
2019-03-05 19:23:37 +01:00
ConVar g_hCvar_BlockSpoof ;
2018-03-26 21:44:05 +02:00
ConVar g_hCvar_BlockAdmin ;
ConVar g_hCvar_BlockVoice ;
2018-07-20 15:52:46 +02:00
2018-09-09 01:48:11 +02:00
/* DATABASE */
2019-03-05 19:23:37 +01:00
Database g_hDatabase ;
2018-09-09 01:48:11 +02:00
2018-03-24 17:20:48 +01:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Plugin myinfo =
{
2019-03-05 19:23:37 +01:00
name = " NoSteamManager_Connect " ,
author = " zaCade + Neon " ,
2018-03-24 17:20:48 +01:00
description = " Manage No-Steam clients, denying admin access, ect. " ,
2019-03-05 19:23:37 +01:00
version = " 2.0.0 "
2018-03-24 17:20:48 +01:00
} ;
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnPluginStart ( )
{
2019-03-05 19:23:37 +01:00
g_hCvar_BlockSpoof = CreateConVar ( " sm_nosteam_block_spoof " , " 1 " , " Kick nosteamers that use authenticated steamids. " , FCVAR_NONE , true , 0.0 , true , 1.0 ) ;
2018-03-27 16:42:12 +02:00
g_hCvar_BlockAdmin = CreateConVar ( " sm_nosteam_block_admin " , " 1 " , " Should people marked as nosteam be blocked from admin? " , FCVAR_NONE , true , 0.0 , true , 1.0 ) ;
g_hCvar_BlockVoice = CreateConVar ( " sm_nosteam_block_voice " , " 1 " , " Should people marked as nosteam be blocked from voice? " , FCVAR_NONE , true , 0.0 , true , 1.0 ) ;
2018-03-26 21:44:05 +02:00
2018-03-24 17:20:48 +01:00
AddMultiTargetFilter ( " @steam " , Filter_Steam , " Steam Players " , false ) ;
AddMultiTargetFilter ( " @nosteam " , Filter_NoSteam , " No-Steam Players " , false ) ;
RegConsoleCmd ( " sm_nosteam " , Command_DisplaySteamStats , " Shows the number of Steam and No-Steam players " ) ;
RegConsoleCmd ( " sm_steam " , Command_DisplaySteamStats , " Shows the number of Steam and No-Steam players " ) ;
2018-03-26 21:44:05 +02:00
AutoExecConfig ( ) ;
2019-03-05 19:23:37 +01:00
}
2018-09-09 01:48:11 +02:00
2019-03-05 19:23:37 +01:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnConfigsExecuted ( )
{
if ( ! g_hCvar_BlockSpoof . BoolValue )
return ;
2018-09-09 19:16:30 +02:00
2019-03-05 19:23:37 +01:00
Database . Connect ( SQL_OnDatabaseConnect , " NoSteamManager " ) ;
2018-03-24 17:20:48 +01:00
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnPluginEnd ( )
{
RemoveMultiTargetFilter ( " @steam " , Filter_Steam ) ;
RemoveMultiTargetFilter ( " @nosteam " , Filter_NoSteam ) ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action Command_DisplaySteamStats ( int client , int args )
{
char aBuf [ 1024 ] ;
char aBuf2 [ MAX_NAME_LENGTH ] ;
for ( int i = 1 ; i < = MaxClients ; i + + )
{
if ( IsClientInGame ( i ) & & ! IsFakeClient ( i ) )
{
2019-03-05 19:23:37 +01:00
char sAuthID [ 32 ] ;
GetClientAuthId ( i , AuthId_Steam2 , sAuthID , sizeof ( sAuthID ) ) ;
2018-03-24 17:20:48 +01:00
2019-03-05 19:23:37 +01:00
if ( ! SteamClientAuthenticated ( sAuthID ) )
2018-03-24 17:20:48 +01:00
{
GetClientName ( i , aBuf2 , sizeof ( aBuf2 ) ) ;
StrCat ( aBuf , sizeof ( aBuf ) , aBuf2 ) ;
StrCat ( aBuf , sizeof ( aBuf ) , " , " ) ;
}
}
}
if ( strlen ( aBuf ) )
{
aBuf [ strlen ( aBuf ) - 2 ] = 0 ;
ReplyToCommand ( client , " [SM] No-Steam clients online: %s " , aBuf ) ;
}
else
ReplyToCommand ( client , " [SM] No-Steam clients online: none " ) ;
return Plugin_Handled ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public bool Filter_Steam ( const char [ ] sPattern , Handle hClients )
{
for ( int i = 1 ; i < = MaxClients ; i + + )
{
if ( IsClientInGame ( i ) & & ! IsFakeClient ( i ) )
{
2019-03-05 19:23:37 +01:00
char sAuthID [ 32 ] ;
GetClientAuthId ( i , AuthId_Steam2 , sAuthID , sizeof ( sAuthID ) ) ;
2018-03-24 17:20:48 +01:00
2019-03-05 19:23:37 +01:00
if ( SteamClientAuthenticated ( sAuthID ) )
2018-03-24 17:20:48 +01:00
PushArrayCell ( hClients , i ) ;
}
}
return true ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public bool Filter_NoSteam ( const char [ ] sPattern , Handle hClients )
{
for ( int i = 1 ; i < = MaxClients ; i + + )
{
if ( IsClientInGame ( i ) & & ! IsFakeClient ( i ) )
{
2019-03-05 19:23:37 +01:00
char sAuthID [ 32 ] ;
GetClientAuthId ( i , AuthId_Steam2 , sAuthID , sizeof ( sAuthID ) ) ;
2018-03-24 17:20:48 +01:00
2019-03-05 19:23:37 +01:00
if ( ! SteamClientAuthenticated ( sAuthID ) )
2018-03-24 17:20:48 +01:00
PushArrayCell ( hClients , i ) ;
}
}
return true ;
}
2019-03-05 19:23:37 +01:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientAuthorized ( int client , const char [ ] sAuthID )
{
if ( ! g_hCvar_BlockSpoof . BoolValue | | ! g_hDatabase )
return ;
if ( IsFakeClient ( client ) | | IsClientSourceTV ( client ) )
return ;
char sQuery [ 512 ] ;
Format ( sQuery , sizeof ( sQuery ) , " SELECT * FROM connections WHERE auth='%s' " , sAuthID ) ;
g_hDatabase . Query ( SQL_OnQueryCompleted , sQuery , GetClientSerial ( client ) , DBPrio_Low ) ;
}
2018-03-24 17:20:48 +01:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action OnClientPreAdminCheck ( int client )
{
2018-07-15 23:38:20 +02:00
if ( ! g_hCvar_BlockAdmin . BoolValue )
2018-03-26 21:44:05 +02:00
return Plugin_Continue ;
2018-07-15 23:38:20 +02:00
if ( IsFakeClient ( client ) | | IsClientSourceTV ( client ) )
2018-03-24 17:20:48 +01:00
return Plugin_Continue ;
2019-03-05 19:23:37 +01:00
char sAuthID [ 32 ] ;
GetClientAuthId ( client , AuthId_Steam2 , sAuthID , sizeof ( sAuthID ) ) ;
2018-03-24 17:20:48 +01:00
2019-03-05 19:23:37 +01:00
if ( ! SteamClientAuthenticated ( sAuthID ) )
2018-03-24 17:20:48 +01:00
{
LogMessage ( " %L was not authenticated with steam, denying admin. " , client ) ;
NotifyPostAdminCheck ( client ) ;
return Plugin_Handled ;
}
2019-03-05 19:23:37 +01:00
else return Plugin_Continue ;
2018-03-24 17:20:48 +01:00
}
2018-03-24 17:22:05 +01:00
//----------------------------------------------------------------------------------------------------
2018-03-24 17:20:48 +01:00
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientPostAdminCheck ( int client )
{
2018-07-15 23:38:20 +02:00
if ( ! g_hCvar_BlockVoice . BoolValue )
2018-03-26 21:44:05 +02:00
return ;
2018-07-15 23:38:20 +02:00
if ( IsFakeClient ( client ) | | IsClientSourceTV ( client ) )
2018-03-24 17:20:48 +01:00
return ;
2019-03-05 19:23:37 +01:00
char sAuthID [ 32 ] ;
GetClientAuthId ( client , AuthId_Steam2 , sAuthID , sizeof ( sAuthID ) ) ;
2018-03-24 17:20:48 +01:00
2019-03-05 19:23:37 +01:00
if ( ! SteamClientAuthenticated ( sAuthID ) )
2018-03-24 17:20:48 +01:00
{
LogMessage ( " %L was not authenticated with steam, muting client. " , client ) ;
BaseComm_SetClientMute ( client , true ) ;
2018-09-09 01:48:11 +02:00
return ;
}
}
2018-03-24 17:20:48 +01:00
2018-09-09 01:48:11 +02:00
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
2019-03-05 19:23:37 +01:00
public void SQL_OnDatabaseConnect ( Database db , const char [ ] error , any data )
2018-09-09 01:48:11 +02:00
{
2019-03-05 19:23:37 +01:00
if ( ! db | | strlen ( error ) )
{
2019-03-08 17:04:26 +01:00
LogError ( " Database error: %s " , error ) ;
2018-03-24 17:20:48 +01:00
return ;
2019-03-05 19:23:37 +01:00
}
g_hDatabase = db ;
char sQuery [ 512 ] ;
2019-03-08 17:04:26 +01:00
Format ( sQuery , sizeof ( sQuery ) , " CREATE TABLE IF NOT EXISTS connections (`auth` varchar(32), `address` varchar(16), PRIMARY KEY (`auth`)) " ) ;
2018-09-09 01:48:11 +02:00
2019-03-05 19:23:37 +01:00
g_hDatabase . Query ( SQL_OnQueryCompleted , sQuery , _ , DBPrio_High ) ;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void SQL_OnQueryCompleted ( Database db , DBResultSet results , const char [ ] error , any data )
{
if ( ! db | | strlen ( error ) )
2018-09-09 01:48:11 +02:00
{
2019-03-08 17:04:26 +01:00
LogError ( " Query error: %s " , error ) ;
2019-03-05 19:23:37 +01:00
return ;
}
int client ;
if ( ( client = GetClientFromSerial ( data ) ) = = 0 )
return ;
2018-09-09 19:16:30 +02:00
2019-03-05 19:23:37 +01:00
char sAuthID [ 32 ] ;
GetClientAuthId ( client , AuthId_Steam2 , sAuthID , sizeof ( sAuthID ) ) ;
2018-09-09 19:16:30 +02:00
2019-03-05 19:23:37 +01:00
char sAddress [ 16 ] ;
GetClientIP ( client , sAddress , sizeof ( sAddress ) ) ;
2018-09-10 15:07:00 +02:00
2019-03-05 19:23:37 +01:00
if ( results . RowCount & & results . FetchRow ( ) )
{
int iFieldNum ;
char sResultAddress [ 16 ] ;
2018-09-10 15:07:00 +02:00
2019-03-05 19:23:37 +01:00
results . FieldNameToNum ( " address " , iFieldNum ) ;
results . FetchString ( iFieldNum , sResultAddress , sizeof ( sResultAddress ) ) ;
delete results ;
if ( ! SteamClientAuthenticated ( sAuthID ) )
2018-09-10 15:07:00 +02:00
{
2019-03-05 19:23:37 +01:00
if ( StrEqual ( sAddress , sResultAddress , false ) )
{
LogMessage ( " %L tried to join with a legitimate steamid while not authenticated with steam. Allowing connection, IPs match. (Known: %s) " , client , sAddress ) ;
}
else
{
LogMessage ( " %L tried to join with a legitimate steamid while not authenticated with steam. Refusing connection, IPs dont match. (Known: %s | Current: %s) " , client , sResultAddress , sAddress ) ;
KickClient ( client , " Trying to join with a legitimate steamid while not authenticated with steam. " ) ;
return ;
}
2018-09-10 15:07:00 +02:00
}
}
2019-03-05 19:23:37 +01:00
char sQuery [ 512 ] ;
Format ( sQuery , sizeof ( sQuery ) , " INSERT INTO connections (auth, address) VALUES ('%s', '%s') ON DUPLICATE KEY UPDATE address='%s'; " , sAuthID , sAddress , sAddress ) ;
g_hDatabase . Query ( SQL_OnQueryCompleted , sQuery , _ , DBPrio_Low ) ;
2018-09-10 15:07:00 +02:00
}