alliedmodders / amxmodx

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

GeoIP not working at all in latest 1.9 #653

Closed OciXCrom closed 4 years ago

OciXCrom commented 5 years ago

Detected here - https://forums.alliedmods.net/showthread.php?t=297952&page=10

I used this test plugin:

#include <amxmodx>
#include <geoip>

public plugin_init()
{
    register_plugin("GeoIP Test", "1.0", "OciXCrom")
    register_srvcmd("geoip_test", "GeoIP_Test")
}

public GeoIP_Test(id)
{
    new szTemp[45], szIP[32]
    read_argv(1, szIP, charsmax(szIP))

    if(!szIP[0])
    {
        server_print("Please enter a valid IP address.")
        return PLUGIN_HANDLED
    }

    server_print("~~~ AMXX Version %s ~~~", AMXX_VERSION_STR)

    geoip_country(szIP, szTemp, charsmax(szTemp))
    server_print("Country: %s", szTemp)

    geoip_country_ex(szIP, szTemp, charsmax(szTemp))
    server_print("Country [ex]: %s", szTemp)

    geoip_city(szIP, szTemp, charsmax(szTemp))
    server_print("City: %s", szTemp)

    return PLUGIN_HANDLED
}

Results from 1.8.2 and latest 1.9 dev-build using my current IP address (77.29.18.129):

~~~ AMXX Version 1.9.0.5235 ~~~
Country: error
Country [ex]: 
City:

~~~ AMXX Version 1.8.2 ~~~
Country: Macedonia
Country [ex]: Macedonia
City:

Also notice how geoip_country and geoip_country_ex give a different value when they can't detect the country. This can be a problem in some cases.

In addition, I didn't manage to get the city in neither version, testing with different IP addresses from different countries.

WPMGPRoSToTeMa commented 5 years ago

Also notice how geoip_country and geoip_country_ex give a different value when they can't detect the country. This can be a problem in some cases.

You can check return value of geoip_country_ex call: @return The result length on successful lookup, 0 otherwise.

OciXCrom commented 5 years ago

I usually do checks like that by doing if(szCountry[0]) because the country is already stored in some global variable. This check won't give the same result on both functions. Not a big deal, but I think it would be better if they both did the same thing on failure.

Arkshine commented 5 years ago

geoip_country is deprecated, you should not use it.

To test an IP you can also use the command geoip dump <ip>. Will check if the last updates did something wrong.

Arkshine commented 5 years ago

@OciXCrom Try to download the latest version of the database. It might be possible that the file you have is corrupted or the structure has changed a little and doesn't work well with the latest lib version. It worked for me it would seem.

OciXCrom commented 5 years ago

I tried using the original GeoIP that comes with the AMXX 1.9 package - it didn't work.

I tried replacing the GeoIP files from this thread and it didn't work either.

Typing geoip dump <ip> in a clean 1.9 installation did nothing. Even writing only geoip doesn't print out any information in the console. It's like the module isn't even installed. The command doesn't exist in 1.8.2 either.

However, downloading GeoIP from the above link and putting it in 1.8.2 adds the command and it works. Doing the same in 1.9 adds the command, but it says Either look up failed or no found results.

Arkshine commented 5 years ago

This is not what I'm asking.

I'm asking you to download the latest GeoIP database.

Either: http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz or http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz

Use the AMXX 1.9 GeoIP module with the latest GeoIP database.

OciXCrom commented 5 years ago

Yup, downloading the two files fixed both of the problems. I assume they should be included in the AMXX package by default.

Arkshine commented 5 years ago

You don't need both. The country version is the basic and provided by default. The city is not included by default because much larger as size. But you will need this file if you want to use the city-related natives.

The database should be automatically updated each month (if a build is triggered of course).

OciXCrom commented 5 years ago

The GeoLite2-Country.mmdb file was updated 4 years ago, if that's what you meant. Anyways, this is a problem for all people who use the latest 1.9, not only for me.

Arkshine commented 5 years ago

It's because you did not update the database from AMXX 1.9. When a build is triggered, if the current saved database is older than one month, it will download and include the latest version. You can check the date. I'm referring to #524.

That's said, it looks like you need a build from this year. I've no idea why. I hope the issue is not how the buildbot downloads the file and would corrupt it somehow.

djearthquake commented 5 years ago

The reason geoip is not working is it was packed wrong in 1.9. Download a good copy from https://dev.maxmind.com/geoip/geoip2/geolite2. It was packed as filetype (application/x-tar) and should be Binary (application/octet-stream). Another way is to uncompress the packed version but why when you can get a clean copy?

Arkshine commented 5 years ago

Makes sense: https://github.com/alliedmodders/amxmodx/pull/524/files#diff-c2a5b25b903e6036e1dc98654263b0cfR77

It's originally a copy-paste from SourceMod, but they're still using the old format which is only .gz and not tar.gz. Oopsie.

abdobiskra commented 2 years ago

This is not what I'm asking.

I'm asking you to download the latest GeoIP database.

Either: http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz or http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz

Use the AMXX 1.9 GeoIP module with the latest GeoIP database.

Hi, link is dead?

0Ky commented 9 months ago

I'm having the same issue as https://github.com/alliedmodders/amxmodx/issues/653#issuecomment-451956607 running on Half-Life 11:26:46 Dec 11 2023 (9909) with AMXX and GeoIP v1.9.0.5294. Also, the links @Arkshine provided in https://github.com/alliedmodders/amxmodx/issues/653#issuecomment-451964753 are dead, the URLs require a (free) license key for access.