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
{
AuthID[ 34 ],
DisconnectTime
}
new TravTrie:ttTrie , g_pdData[ MAX_PLAYERS + 1 ][ 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_string( g_Entity , EV_SZ_classname , "binr_entity" );
register_think( "binr_entity" , "EntityThink" );
entity_set_float( g_Entity , EV_FL_nextthink , ( get_gametime() + EntityTimerInterval ) );
ttTrie = TravTrieCreate();
}
public plugin_end()
{
call_think( g_Entity );
TravTrieDestroy( ttTrie );
}
public client_authorized( id )
{
new pdData[ PlayerData ] , iTrieKey , szKickMessage[ 60 ] , iReconnectMinutes;
get_user_authid( id , g_pdData[ id ][ AuthID ] , charsmax( g_pdData[][ AuthID ] ) );
iTrieKey = str_to_num( g_pdData[ id ][ AuthID ][ 10 ] );
if ( TravTrieGetArrayEx( ttTrie , iTrieKey , pdData , sizeof( pdData ) ) && pdData[ DisconnectTime ] )
{
iReconnectMinutes = get_pcvar_num( g_pReconnectMinutes );
if ( get_pcvar_num( g_pBanLeavers ) && ( ( get_systime() - pdData[ DisconnectTime ] ) > ( iReconnectMinutes * 60 ) ) )
{
formatex( szKickMessage , charsmax( szKickMessage ) , "^nYou have been banned for %d minutes for not re-joining within %d minutes" , get_pcvar_num( g_pBanMinutes ) , iReconnectMinutes );
message_begin( MSG_ONE , 2 , {0,0,0} , id );
write_string( szKickMessage );
message_end();
BanPlayer( pdData[ AuthID ] );
TravTrieDeleteKeyEx( ttTrie , iTrieKey );
}
else
{
pdData[ DisconnectTime ] = 0;
TravTrieSetArrayEx( ttTrie , iTrieKey , pdData , sizeof( pdData ) );
}
}
}
public client_disconnect( id )
{
new szName[ 33 ];
if (!( get_user_flags( id ) & ADMIN_IMMUNITY ) )
{
get_user_name( id , szName , charsmax( szName ) );
client_print( 0 , print_chat , "* %s left - he has %d minutes to return or he will be banned for %d minutes." , szName , get_pcvar_num( g_pReconnectMinutes ) , get_pcvar_num( g_pBanMinutes ) );
g_pdData[ id ][ DisconnectTime ] = get_systime();
TravTrieSetArrayEx( ttTrie , str_to_num( g_pdData[ id ][ AuthID ][ 10 ] ) , g_pdData[ id ] , sizeof( g_pdData[] ) );
}
}
public EntityThink( iEntity )
{
if( ( iEntity == g_Entity ) && get_pcvar_num( g_pBanLeavers ) )
{
new travTrieIter:ttIterator , pdData[ PlayerData ] , iTimeLeft , iReconnectMinutes , iSysTime;
ttIterator = GetTravTrieIterator( ttTrie );
iTimeLeft = get_timeleft();
iSysTime = get_systime();
iReconnectMinutes = get_pcvar_num( g_pReconnectMinutes );
while ( MoreTravTrie( ttIterator ) )
{
ReadTravTrieArray( ttIterator , pdData , sizeof( pdData ) );
if ( ( iTimeLeft < 30 ) || ( iSysTime - pdData[ DisconnectTime ] ) > ( iReconnectMinutes * 60 ) )
{
BanPlayer( pdData[ AuthID ] );
TravTrieDeleteKeyEx( ttTrie , str_to_num( pdData[ AuthID ][ 10 ] ) );
}
}
DestroyTravTrieIterator( ttIterator );
entity_set_float( g_Entity , EV_FL_nextthink , ( get_gametime() + EntityTimerInterval ) );
}
}
public BanPlayer( const szAuthID[] )
{
server_cmd( "banid %d %s" , get_pcvar_num( g_pBanMinutes ) , szAuthID );
}