alliedmodders / amxmodx

AMX Mod X - Half-Life 1 Scripting and Administration
http://www.amxmodx.org/
489 stars 197 forks source link

Erroneous 127.0.0.1 get_user_ip #848

Open djearthquake opened 4 years ago

djearthquake commented 4 years ago

Occasionally Amxx shows real users as bots with 127.0.0.1 IP addresses.

MrCoala commented 4 years ago

client_connectex doesnt give me 127.0.0.1 as ip value. so i am retrieving the ip like that:

public client_connectex(id, const name[], const ip[], reason[128]) {
  g_szIP[id] = ""
  new szTMP[46]
    if (split_string(ip,":",szTMP,45) != -1)
    copy(g_szIP[id],45,szTMP)
  else
    copy(g_szIP[id],45,ip)
  return PLUGIN_CONTINUE
}

this works just fine on amxmodx v1.9.0.5. get_user_ip returns pretty often 127.0.0.1

i believe this is being caused in the moduleconfig.cpp where the ip will be set to 127.0.0.1 for bots. It seems that if the bot leaves and a player joins into that slot the ip 127.0.0.1 remains. Can you confirm that you run bots on your server?

djearthquake commented 4 years ago

Bots are sometimes used on server.

pizzahut2 commented 3 years ago

@Arkshine @dvander I think get_user_ip needs to be rewritten to retrieve the IP the same way as client_connectex. In the server log, people connect with a normal IP address, but get_user_ip sometimes returns 127.0.0.1. The probability of this to happen is approx. 4,7%.

Example with anonymised data, 2nd line is from a plugin which uses get_user_ip (with a 10s delay):

log:L 02/18/2021 - 11:07:27: "player name<1340><>" connected, address "111.222.33.44:27005" log:L 02/18/2021 - 11:07:37: [info];player name;STEAM_0:1:222222;127.0.0.1

Edit: Or, as Master and Coala mentioned, this is an issue with "moduleconfig.cpp" , function "ClientUserInfoChanged_Post". As the IP is set to 127.0.0.1 in there - meant for bots. The server does use bots, so probably this is causing the issue.

void ClientUserInfoChanged_Post( edict_t *pEntity, char *infobuffer ) {
    CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity);
    const char* name = INFOKEY_VALUE(infobuffer,"name");
    const char* oldname = STRING(pEntity->v.netname);

    if ( pPlayer->rank ){
        if ( strcmp(oldname,name) != 0 ) {
            if ((int)tfcstats_rank->value == 0)
                pPlayer->rank = g_rank.findEntryInRank( name, name );
            else
                pPlayer->rank->setName( name );
        }
    }
    else if ( pPlayer->IsBot() ) {
        pPlayer->Connect( "127.0.0.1" );
        pPlayer->PutInServer();
    }

    RETURN_META(MRES_IGNORED);
}
    inline bool IsBot(){
        const char* auth= (*g_engfuncs.pfnGetPlayerAuthId)(pEdict);
        return ( auth && !strcmp( auth , "BOT" ) );
    }
djearthquake commented 3 years ago

Trimming IsBot() as @pizzahut2 showed resolves this.

djearthquake commented 2 years ago

I've compiled a new release of Amxx. https://github.com/djearthquake/amxmodx/releases/tag/amxmodx-1.10-s Needless to say people have not been mistaken for loopback since.