Thread: [Solved] Ban players if disconnect
View Single Post
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-01-2019 , 20:08   Re: Ban players if disconnect
Reply With Quote #164

Untested
PHP Code:

#include <amxmodx> 
#include <engine> 
#include <nvault_util> 
#include <nvault_array> 

new const Version[] = "1.3"

#define MAX_PLAYERS 32 

const BanQueueSize 30
const 
Float:EntityInterval 1.0
const 
MinuteSeconds 60

enum PlayerData 

    
pdAuthID34 ], 
    
pdDisconnectTime
    
pdConnectTime


new 
g_pdDataMAX_PLAYERS ][ PlayerData ] , g_BanQueueBanQueueSize ][ PlayerData ]; 
new 
g_IgnorePlayers g_HasAuthorized g_Entity g_Vault
new 
g_pBanLeavers g_pReconnectMinutes g_pBanMinutes g_pImmunityFlags

public 
plugin_init()  

    
register_plugin"Ban If No Return" Version "bugsy" ); 
    
    
g_pBanLeavers register_cvar"binr_enabled" "1" ); 
    
g_pReconnectMinutes register_cvar"binr_reconnectmin" "5" ); 
    
g_pBanMinutes register_cvar"binr_banmins" "8500" ); 
    
g_pImmunityFlags register_cvar"binr_immunityflags" "a" ); 
    
    
LoadQueue(); 
    
    
g_Vault nvault_open"ban_if_no_return" ); 
    
nvault_pruneg_Vault get_systime() ); 
    
    
g_Entity create_entity"info_target" ); 
    
entity_set_stringg_Entity EV_SZ_classname "binr_entity" ); 
    
register_think"binr_entity" "EntityThink" ); 
    
entity_set_floatg_Entity EV_FL_nextthink , ( get_gametime() + EntityInterval ) ); 


public 
plugin_end() 

    
SaveQueue(); 
    
    
call_thinkg_Entity ); 
    
nvault_closeg_Vault ); 


public 
client_authorizedid )  

    new 
iTimeStamp szKickMessage96 ] , szFlags26 ]; 
    
    
get_pcvar_stringg_pImmunityFlags szFlags charsmaxszFlags ) ); 
    
g_IgnorePlayers |= ( is_user_botid ) || is_user_hltvid )  || ( get_user_flagsid ) & read_flagsszFlags ) ) ? ) << ( id 31 ) ; 
    
    if ( !( 
g_IgnorePlayers & ( << ( id 31 ) ) ) ) 
    { 
        
get_user_authidid g_pdDataid ][ pdAuthID ] , charsmaxg_pdData[][ pdAuthID ] ) ); 
        
        if ( 
nvault_lookupg_Vault g_pdDataid ][ pdAuthID ] , "" iTimeStamp ) ) 
        { 
            if ( 
iTimeStamp get_systime() ) 
            { 
                
formatexszKickMessage charsmaxszKickMessage ) , "^nBanned 7 days. YOU LEFT LIVE MIX. Come back in %d minutes" , ( get_systime() - iTimeStamp ) / 60  );    
                
message_beginMSG_ONE , {0,0,0} , id );      
                
write_stringszKickMessage );      
                
message_end();  
            } 
            else 
            { 
                
nvault_removeg_Vault g_pdDataid ][ pdAuthID ] ); 
            } 
        } 
        else 
        { 
            
RemoveFromBanQueueid ); 
        } 
    } 
    
    
g_pdDataid ][ pdConnectTime ] = get_systime();
    
g_HasAuthorized |= ( << ( id 31 ) ); 


public 
client_disconnectid )  

    if ( !( 
g_IgnorePlayers & ( << ( id 31 ) ) ) && ( g_HasAuthorized & ( << ( id 31 ) ) ) && get_pcvar_numg_pBanLeavers ) && ( ( get_systime() - g_pdDataid ][ pdConnectTime ] ) >= 60 ) ) 
    { 
        if ( !
AddToBanQueueid ) ) 
            
set_fail_state"Ban If No Return: Need to increase queue size." ); 
    } 
    
    
g_IgnorePlayers &= ~( << ( id 31 ) ); 
    
g_HasAuthorized &= ~( << ( id 31 ) ); 


public 
EntityThinkiEntity 

    if( 
iEntity == g_Entity )  
    { 
        
SetBansInQueue();                         
        
entity_set_floatg_Entity EV_FL_nextthink , ( get_gametime() + EntityInterval ) ); 
    } 


bool:AddToBanQueueid DisconnectTime=

    new 
bool:bSuccess
    
    for (new 
iFindSlot iFindSlot BanQueueSize iFindSlot++ ) 
    { 
        if ( 
g_BanQueueiFindSlot ][ pdAuthID ][ ] == EOS 
        { 
            
copyg_BanQueueiFindSlot ][ pdAuthID ] , charsmaxg_BanQueue[][ pdAuthID ] ) , g_pdDataid ][ pdAuthID ] ); 
            
g_BanQueueiFindSlot ][ pdDisconnectTime ] = DisconnectTime DisconnectTime get_systime(); 
            
bSuccess true
            break; 
        } 
    } 
    
    return 
bSuccess


RemoveFromBanQueueid 

    for ( new 
iFindSlot iFindSlot BanQueueSize iFindSlot++ ) 
    { 
        if ( 
equalg_BanQueueiFindSlot ][ pdAuthID ] , g_pdDataid ][ pdAuthID ] ) ) 
        { 
            
g_BanQueueiFindSlot ][ pdAuthID ][ ] = EOS
            
g_BanQueueiFindSlot ][ pdDisconnectTime ] = 0
            break; 
        } 
    } 


SetBansInQueue() 

    new 
iBanTime
    
    for ( new 
iFindSlot iFindSlot BanQueueSize iFindSlot++ ) 
    { 
        if ( 
g_BanQueueiFindSlot ][ pdAuthID ][ ] ) 
        { 
            if ( ( 
get_systime() - g_BanQueueiFindSlot ][ pdDisconnectTime ] ) >= ( get_pcvar_numg_pReconnectMinutes ) * MinuteSeconds ) ) 
            { 
                
nvault_setg_Vault g_BanQueueiFindSlot ][ pdAuthID ] , "1" ); 
                
nvault_touchg_Vault g_BanQueueiFindSlot ][ pdAuthID ] , ( iBanTime get_pcvar_numg_pBanMinutes ) ) == get_systime() +  ( iBanTime MinuteSeconds ) ); 
            
                
g_BanQueueiFindSlot ][ pdAuthID ][ ] = EOS
                
g_BanQueueiFindSlot ][ pdDisconnectTime ] = 0
            } 
        } 
    } 


LoadQueue() 

    new 
iVault pData_:PlayerData ] , iPos iCount iItems iTimeStamp szKey]; 
    
    if ( ( 
iVault nvault_util_open"ban_if_no_return" ) ) ) 
    { 
        
iCount nvault_util_countiVault ); 
        
        for ( new 
iEntry iEntry iCount iEntry++ ) 
        { 
            
iPos nvault_util_read_arrayiVault iPos szKey charsmaxszKey ) , pData sizeofpData ) , iItems iTimeStamp ); 
            
            if ( 
equalszKey "BanQueue" ) ) 
            { 
                
copyg_pdData][ pdAuthID ] , sizeofg_pdData[][ pdAuthID ] ) , pData_:pdAuthID ] ); 
                
g_pdData][ pdDisconnectTime ] = pData_:pdDisconnectTime ]; 
                
AddToBanQueueg_pdData][ pdDisconnectTime ] ); 
            } 
        } 
    } 


SaveQueue() 

    new 
szKey12 ] , iSlotIndex pData_:PlayerData ]; 
    
    
copyszKey charsmaxszKey ) , "BanQueue" ); 
    
    for ( new 
iSlot iSlot BanQueueSize iSlot++ ) 
    { 
        if ( 
g_BanQueueiSlot ][ pdDisconnectTime ] ) 
        { 
            
copypData_:pdAuthID ] , charsmaxpDatapdAuthID ] ) , g_BanQueueiSlot ][ pdAuthID ] ); 
            
pData_:pdDisconnectTime ] = g_BanQueueiSlot ][ pdDisconnectTime ]; 
            
            
num_to_striSlotIndex++ , szKey] , charsmaxszKey ) - ); 
            
nvault_set_arrayg_Vault szKey pData sizeofpData ) ); 
            
nvault_touchg_Vault szKey ); 
        } 
    } 

__________________
Bugsy is offline