Re: [req] blacklist ip
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;
}
|