AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
|
11-29-2015
, 18:26
Re: Ban if no return in 5 minutes.
|
#70
|
This uses nvault to store all bans. The value/data of the vault entry is a timestamp of when the player was banned and the actual vault entry timestamp is when their ban expires. The vault is pruned on map change to delete all bans that have expired. Entries with a 0 timestamp never get pruned since they are considered permanent entries by nvault. Doing it this way allows you to determine when a player was banned, and when his ban will expire--it also allows for easy maintenance of the vault since it can be pruned to clear out expired bans. These bans are accurate to the second. I have not tested this at all, let me know if it works.
You can use nvault editor (see sig) to see any bans that exist in the vault. At this website you can convert a timestamp to time to see that it is setting the ban correctly: http://www.unixtimestamp.com/
PHP Code:
#include <amxmodx> #include <engine> #include <celltravtrie> #include <nvault>
new const Version[] = "0.5c";
#define MAX_PLAYERS 32
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 , g_Vault , g_IgnorePlayers , g_HasAuthorized;
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(); g_Vault = nvault_open( "BINR" ); }
public plugin_cfg() { nvault_prune( g_Vault , 0 , get_systime() ); }
public plugin_end() { call_think( g_Entity ); TravTrieDestroy( ttTrie ); nvault_close( g_Vault ); }
public client_authorized( id ) { new pdData[ PlayerData ] , iTrieKey , szKickMessage[ 60 ] , iReconnectMinutes , szBanTime[ 2 ] , iTS;
g_IgnorePlayers |= ( is_user_bot( id ) || is_user_hltv( id ) ? 1 : 0 ) << ( id & 31 ); g_HasAuthorized |= ( 1 << ( id & 31 ) ); if ( !( g_IgnorePlayers & ( 1 << ( id & 31 ) ) ) ) { get_user_authid( id , g_pdData[ id ][ AuthID ] , charsmax( g_pdData[][ AuthID ] ) ); if ( nvault_lookup( g_Vault , g_pdData[ id ][ AuthID ] , szBanTime , charsmax( szBanTime ) , iTS ) ) { if ( !iTS || ( get_systime() < iTS ) ) { message_begin( MSG_ONE , 2 , {0,0,0} , id ); write_string( "You are banned." ); message_end(); } else { nvault_remove( g_Vault , g_pdData[ id ][ AuthID ] ); } } else { 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 ( ( g_HasAuthorized & ( 1 << ( id & 31 ) ) ) && !( get_user_flags( id ) & ADMIN_IMMUNITY ) && !( g_IgnorePlayers & ( 1 << ( id & 31 ) ) ) ) { 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[] ) ); } g_IgnorePlayers &= ~( 1 << ( id & 31 ) ); g_HasAuthorized &= ~( 1 << ( id & 31 ) ); }
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[] ) { new szBanTime[ 11 ] , iBanMinutes; iBanMinutes = get_pcvar_num( g_pBanMinutes ); num_to_str( get_systime() , szBanTime , charsmax( szBanTime ) ); nvault_set( g_Vault , szAuthID , szBanTime ); nvault_touch( g_Vault , szAuthID , iBanMinutes ? get_systime() + ( iBanMinutes * 60 ) : 0 ); }
__________________
Last edited by Bugsy; 12-01-2015 at 23:17.
|
|