Thread: [Solved] Ban players if disconnect
View Single Post
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-05-2015 , 14:03   Re: Ban if no return in 5 minutes.
Reply With Quote #3

Not thoroughly tested. Use the attached CellTravTrie include as the original one has a warning when compiled due to the author not tagging a variable as a bool in TravTrieGetArrayEx().

Edit: Removed disconnect reason code.
PHP Code:
#include <amxmodx>
#include <engine>
#include <celltravtrie>

new const Version[] = "0.3";

const 
Float:EntityTimerInterval 10.0

enum _:PlayerData
{
    
AuthID34 ],
    
DisconnectTime
}

new 
TravTrie:ttTrie g_pdDataMAX_PLAYERS ][ PlayerData ];
new 
g_Entity g_pBanLeavers g_pReconnectMinutes g_pBanMinutes;

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" "60" );
    
    
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() + EntityTimerInterval ) );
    
    
ttTrie TravTrieCreate();
}

public 
plugin_end()
{
    
call_thinkg_Entity );
    
TravTrieDestroyttTrie );
}

public 
client_authorizedid )
{
    new 
pdDataPlayerData ] , iTrieKey szKickMessage60 ] , iReconnectMinutes;

    
get_user_authidid g_pdDataid ][ AuthID ] , charsmaxg_pdData[][ AuthID ] ) );

    
iTrieKey str_to_numg_pdDataid ][ AuthID ][ 10 ] );
    
    if ( 
TravTrieGetArrayExttTrie iTrieKey pdData sizeofpdData ) ) && pdDataDisconnectTime ] )
    {
        
iReconnectMinutes get_pcvar_numg_pReconnectMinutes );
        
        if ( 
get_pcvar_numg_pBanLeavers ) && ( ( get_systime() - pdDataDisconnectTime ] ) > ( iReconnectMinutes 60 ) ) )
        {
            
formatexszKickMessage charsmaxszKickMessage ) , "^nYou have been banned for %d minutes for not re-joining within %d minutes" get_pcvar_numg_pBanMinutes ) , iReconnectMinutes );     
            
message_beginMSG_ONE , {0,0,0} , id );     
            
write_stringszKickMessage );     
            
message_end();    
    
            
BanPlayerpdDataAuthID ] );
            
            
TravTrieDeleteKeyExttTrie iTrieKey );
        }
        else
        {
            
pdDataDisconnectTime ] = 0;
            
TravTrieSetArrayExttTrie iTrieKey pdData sizeofpdData ) );
        }
    }
}

public 
client_disconnectid )
{
    new 
szName33 ];
    
    if (!( 
get_user_flagsid ) & ADMIN_IMMUNITY ) )
    {
        
get_user_nameid szName charsmaxszName ) );
        
client_printprint_chat "* %s left - he has %d minutes to return or he will be banned for %d minutes." szName get_pcvar_numg_pReconnectMinutes ) , get_pcvar_numg_pBanMinutes ) );
        
        
g_pdDataid ][ DisconnectTime ] = get_systime();
        
TravTrieSetArrayExttTrie str_to_numg_pdDataid ][ AuthID ][ 10 ] ) , g_pdDataid ] , sizeofg_pdData[] ) );
    }
}

public 
EntityThinkiEntity )
{
    if( ( 
iEntity == g_Entity ) && get_pcvar_numg_pBanLeavers ) ) 
    {
        new 
travTrieIter:ttIterator pdDataPlayerData ] , iTimeLeft iReconnectMinutes iSysTime;
        
        
ttIterator GetTravTrieIteratorttTrie );
        
iTimeLeft get_timeleft();
        
iSysTime get_systime();
        
iReconnectMinutes get_pcvar_numg_pReconnectMinutes );
        
        while ( 
MoreTravTriettIterator ) )
        {
            
ReadTravTrieArrayttIterator pdData sizeofpdData ) );
            
            if ( ( 
iTimeLeft 30 ) || ( iSysTime pdDataDisconnectTime ] ) > ( iReconnectMinutes 60 ) )
            {
                
BanPlayerpdDataAuthID ] );
                
TravTrieDeleteKeyExttTrie str_to_numpdDataAuthID ][ 10 ] ) );
            }
        }
        
        
DestroyTravTrieIteratorttIterator );
        
        
entity_set_floatg_Entity EV_FL_nextthink , ( get_gametime() + EntityTimerInterval ) );
    }
}
 
public 
BanPlayer( const szAuthID[] )
{
     
server_cmd"banid %d %s" get_pcvar_numg_pBanMinutes ) , szAuthID );

Attached Files
File Type: inc celltravtrie.inc (9.2 KB, 231 views)
__________________

Last edited by Bugsy; 07-11-2015 at 08:55.
Bugsy is offline