new const PLUGIN[ ] = "Country On Name"
new const VERSION[ ] = "1.0.1";
new const AUTHOR[ ] = "Bboy Grun";
new const g_unknow[ ] = "[??]";
new const g_lan[ ] = "[LAN]";
new const g_privateAddress[ ][ ] = { "10.0", "172.16", "192.168", "loopback" };
#define WITHOUT_PORT 1
#include < amxmodx >
#include < geoip >
new g_country[ 33 ][ 6 ];
new g_pCvar_botTag, g_pCvar_lanTag;
public plugin_init( )
{
register_plugin( PLUGIN, VERSION, AUTHOR );
set_pcvar_string( register_cvar( "country_on_name", VERSION, FCVAR_SERVER | FCVAR_SPONLY ), VERSION );
g_pCvar_botTag = register_cvar( "bot_tag", "0" );
g_pCvar_lanTag = register_cvar( "lan_tag", "0" );
}
public client_putinserver( id )
{
new ip[ 16 ], country[ 3 ];
get_user_ip( id, ip, charsmax( ip ), WITHOUT_PORT ); // Get player IP
if( geoip_code2_ex( ip, country ) )
{
format( g_country[ id ], charsmax( g_country[ ] ), "[%s]", country ); // Player country detected
}
else
{
if( is_user_bot( id ) ) // player is a bot, let's set a special tag
{
switch( get_pcvar_num( g_pCvar_botTag ) )
{
case 0: // Show [??]
{
g_country[ id ] = g_unknow;
}
case 1: // Show [BOT]
{
g_country[ id ] = "[BOT]";
}
case 2: // Show [LAN]
{
g_country[ id ] = g_lan;
}
}
}
else
{
if( get_pcvar_num( g_pCvar_lanTag ) ) // check for lan ?
{
new i;
for( i = 3; i > -1; i -- )
{
if( contain( ip, g_privateAddress[ i ] ) > -1 )
{
g_country[ id ] = g_lan;
break;
}
}
if( i == -1 )
{
g_country[ id ] = g_unknow;
}
}
else
{
g_country[ id ] = g_unknow;
}
}
}
}
public client_disconnect( id )
{
g_country[ id ][ 0 ] = EOS;
}
public client_infochanged( id )
{
if( g_country[ id ][ 0 ] )
{
new name[ 32 ];
get_user_info( id, "name", name, charsmax( name ) );
for( new i = 0; i <= 4; i ++ )
{
if( name[ i ] != g_country[ id ][ i ] && g_country[ id ][ i ] )
{
format( name, charsmax( name ), "%s %s", g_country[ id ], name );
set_user_info( id, "name", name );
return PLUGIN_HANDLED;
}
}
}
return PLUGIN_CONTINUE;
}