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
{
pdAuthID[ 34 ],
pdDisconnectTime,
pdConnectTime
}
new g_pdData[ MAX_PLAYERS + 1 ][ PlayerData ] , g_BanQueue[ BanQueueSize ][ 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_prune( g_Vault , 0 , get_systime() );
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() + EntityInterval ) );
}
public plugin_end()
{
SaveQueue();
call_think( g_Entity );
nvault_close( g_Vault );
}
public client_authorized( id )
{
new iTimeStamp , szKickMessage[ 96 ] , szFlags[ 26 ];
get_pcvar_string( g_pImmunityFlags , szFlags , charsmax( szFlags ) );
g_IgnorePlayers |= ( is_user_bot( id ) || is_user_hltv( id ) || ( get_user_flags( id ) & read_flags( szFlags ) ) ? 1 : 0 ) << ( id & 31 ) ;
if ( !( g_IgnorePlayers & ( 1 << ( id & 31 ) ) ) )
{
get_user_authid( id , g_pdData[ id ][ pdAuthID ] , charsmax( g_pdData[][ pdAuthID ] ) );
if ( nvault_lookup( g_Vault , g_pdData[ id ][ pdAuthID ] , "" , 0 , iTimeStamp ) )
{
if ( iTimeStamp > get_systime() )
{
formatex( szKickMessage , charsmax( szKickMessage ) , "^nBanned 7 days. YOU LEFT LIVE MIX. Come back in %d minutes" , ( get_systime() - iTimeStamp ) / 60 );
message_begin( MSG_ONE , 2 , {0,0,0} , id );
write_string( szKickMessage );
message_end();
}
else
{
nvault_remove( g_Vault , g_pdData[ id ][ pdAuthID ] );
}
}
else
{
RemoveFromBanQueue( id );
}
}
g_pdData[ id ][ pdConnectTime ] = get_systime();
g_HasAuthorized |= ( 1 << ( id & 31 ) );
}
public client_disconnect( id )
{
if ( !( g_IgnorePlayers & ( 1 << ( id & 31 ) ) ) && ( g_HasAuthorized & ( 1 << ( id & 31 ) ) ) && get_pcvar_num( g_pBanLeavers ) && ( ( get_systime() - g_pdData[ id ][ pdConnectTime ] ) >= 60 ) )
{
if ( !AddToBanQueue( id ) )
set_fail_state( "Ban If No Return: Need to increase queue size." );
}
g_IgnorePlayers &= ~( 1 << ( id & 31 ) );
g_HasAuthorized &= ~( 1 << ( id & 31 ) );
}
public EntityThink( iEntity )
{
if( iEntity == g_Entity )
{
SetBansInQueue();
entity_set_float( g_Entity , EV_FL_nextthink , ( get_gametime() + EntityInterval ) );
}
}
bool:AddToBanQueue( id , DisconnectTime=0 )
{
new bool:bSuccess;
for (new iFindSlot = 0 ; iFindSlot < BanQueueSize ; iFindSlot++ )
{
if ( g_BanQueue[ iFindSlot ][ pdAuthID ][ 0 ] == EOS )
{
copy( g_BanQueue[ iFindSlot ][ pdAuthID ] , charsmax( g_BanQueue[][ pdAuthID ] ) , g_pdData[ id ][ pdAuthID ] );
g_BanQueue[ iFindSlot ][ pdDisconnectTime ] = DisconnectTime ? DisconnectTime : get_systime();
bSuccess = true;
break;
}
}
return bSuccess;
}
RemoveFromBanQueue( id )
{
for ( new iFindSlot = 0 ; iFindSlot < BanQueueSize ; iFindSlot++ )
{
if ( equal( g_BanQueue[ iFindSlot ][ pdAuthID ] , g_pdData[ id ][ pdAuthID ] ) )
{
g_BanQueue[ iFindSlot ][ pdAuthID ][ 0 ] = EOS;
g_BanQueue[ iFindSlot ][ pdDisconnectTime ] = 0;
break;
}
}
}
SetBansInQueue()
{
new iBanTime;
for ( new iFindSlot = 0 ; iFindSlot < BanQueueSize ; iFindSlot++ )
{
if ( g_BanQueue[ iFindSlot ][ pdAuthID ][ 0 ] )
{
if ( ( get_systime() - g_BanQueue[ iFindSlot ][ pdDisconnectTime ] ) >= ( get_pcvar_num( g_pReconnectMinutes ) * MinuteSeconds ) )
{
nvault_set( g_Vault , g_BanQueue[ iFindSlot ][ pdAuthID ] , "1" );
nvault_touch( g_Vault , g_BanQueue[ iFindSlot ][ pdAuthID ] , ( iBanTime = get_pcvar_num( g_pBanMinutes ) ) == 0 ? 0 : get_systime() + ( iBanTime * MinuteSeconds ) );
g_BanQueue[ iFindSlot ][ pdAuthID ][ 0 ] = EOS;
g_BanQueue[ iFindSlot ][ pdDisconnectTime ] = 0;
}
}
}
}
LoadQueue()
{
new iVault , pData[ _:PlayerData ] , iPos , iCount , iItems , iTimeStamp , szKey[ 9 ];
if ( ( iVault = nvault_util_open( "ban_if_no_return" ) ) )
{
iCount = nvault_util_count( iVault );
for ( new iEntry = 0 ; iEntry < iCount ; iEntry++ )
{
iPos = nvault_util_read_array( iVault , iPos , szKey , charsmax( szKey ) , pData , sizeof( pData ) , iItems , iTimeStamp );
if ( equal( szKey , "BanQueue" ) )
{
copy( g_pdData[ 0 ][ pdAuthID ] , sizeof( g_pdData[][ pdAuthID ] ) , pData[ _:pdAuthID ] );
g_pdData[ 0 ][ pdDisconnectTime ] = pData[ _:pdDisconnectTime ];
AddToBanQueue( 0 , g_pdData[ 0 ][ pdDisconnectTime ] );
}
}
}
}
SaveQueue()
{
new szKey[ 12 ] , iSlotIndex , pData[ _:PlayerData ];
copy( szKey , charsmax( szKey ) , "BanQueue" );
for ( new iSlot = 0 ; iSlot < BanQueueSize ; iSlot++ )
{
if ( g_BanQueue[ iSlot ][ pdDisconnectTime ] )
{
copy( pData[ _:pdAuthID ] , charsmax( pData[ pdAuthID ] ) , g_BanQueue[ iSlot ][ pdAuthID ] );
pData[ _:pdDisconnectTime ] = g_BanQueue[ iSlot ][ pdDisconnectTime ];
num_to_str( iSlotIndex++ , szKey[ 8 ] , charsmax( szKey ) - 8 );
nvault_set_array( g_Vault , szKey , pData , sizeof( pData ) );
nvault_touch( g_Vault , szKey , 1 );
}
}
}