Thread: [DELETED]
View Single Post
raizo11
BANNED
Join Date: Dec 2013
Location: https://t.me/pump_upp
Old 01-17-2019 , 12:33   Re: [req] blacklist ip
Reply With Quote #8

Code:
#include <amxmodx>
#include <amxmisc>

new Trie:g_BlockIp;
new g_File[ 64 ];

new const Message[] = "Ip Blocked";

public plugin_init() 
{
    new szData[ 35 ];
    
    g_BlockIp = TrieCreate();
    
    copy( g_File[ get_localinfo( "amxx_configsdir" , g_File , charsmax( g_File ) ) ] , charsmax( g_File ) , "/IpWhiteLits.ini" );
    
    new f = fopen( g_File , "rt" );
    
    while( !feof( f ) )
    {
        fgets( f , szData , charsmax( szData ) );
     
        trim( szData );
        
        if( !szData[0] || szData[0] == ';' || szData[0] == '/' && szData[1] == '/' ) 
            continue;
            
        TrieSetCell( g_BlockIp , szData , 1 );
    }
    
    fclose( f );
    
    register_concmd( "amx_blockip" , "Add_User_Ip" , ADMIN_KICK , "<IP> - Add User IP to list" );
}

public client_connect( id )
{
    new szIP[ 32 ];
    
    get_user_ip(id, szIP, charsmax(szIP), 1);

    if ( TrieKeyExists( g_BlockIp , szIP[ contain( szIP, "" ) + 1 ]) )
    {
        message_begin( MSG_ONE, SVC_DISCONNECT, .player = id );
        write_string( Message );
        message_end();
    }
    else
    {
        //nothing
    }
}

public Add_User_Ip( id , level , cid )
{
    if ( !cmd_access( id , level , cid , 2 ) )
        return PLUGIN_HANDLED;
        
    new szIP[ 32 ];

    if ( read_argv( 1 , szIP , charsmax( szIP ) ) )
    {
        if ( !TrieKeyExists( g_BlockIp , szIP ) )
        {
            TrieSetCell( g_BlockIp , szIP , 1 );
            write_file( g_File , szIP );
            console_print( id , "* Added IP ^"%s^" to list." , szIP );
        }
        else
        {
            console_print( id , "* IP ^"%s^" already exists in list." , szIP );
        }
    }
    
    return PLUGIN_HANDLED;
}
raizo11 is offline
Send a message via ICQ to raizo11 Send a message via AIM to raizo11 Send a message via MSN to raizo11 Send a message via Yahoo to raizo11 Send a message via Skype™ to raizo11