George480 / geolite

GeoLite2 for San Andreas Multiplayer
MIT License
8 stars 4 forks source link

GeoLite (SQLite)

It is based on the free product GeoLite2 by MaxMind.

I was updating the country database every month for MySQL and decided to update the GeoIp databases by Whitetiger's include as many people requested. It turned out I was unable to, the way the databases were structured. I converted my version to SQLite and started comparing the two includes with geolite.inc being victorious. But this was to be expected with not only the good database structure and the use of indexes but also the appropriate queries to avoid range scans. Even though latest database provide more data than last year, it did not affect the performance in any way.

The past days, I managed to import Autonomous System (AS) and City databases with the original databases having big flows.

The above issue arose another problem related to time zones.

I initially posted these changes and improvements in Whitetiger's thread but due to their absence, I decided to create a new thread. I was also unaware if Whitetiger would accept the changes, nor how the updates would be done.

Installation

Repository: https://github.com/George480/geolite

Releases: https://github.com/George480/geolite/releases

Include: https://raw.githubusercontent.com/George480/geolite/master/geolite.inc

Save as geolite.inc into pawno\include folder. Include in your code and begin using the library:

#include <geolite>

Place the database you want to use into scriptfiles folder.

Functions

IP-Based Functions:

GetIpAutonomousSystem(const geolite_ip[], geolite_dest[], geolite_len = sizeof (geolite_dest))
GetIpCountry(const geolite_ip[], geolite_dest[], geolite_len = sizeof (geolite_dest))
GetIpCity(const geolite_ip[], geolite_dest[], geolite_len = sizeof (geolite_dest))
GetIpUTC(const geolite_ip[], geolite_dest[], geolite_len = sizeof (geolite_dest))
IsIpProxy(const geolite_ip[])

Player-Based Functions:

GetPlayerAutonomousSystem(playerid, geolite_dest[], geolite_len = sizeof (geolite_dest))
GetPlayerCountry(playerid, geolite_dest[], geolite_len = sizeof (geolite_dest))
GetPlayerCity(playerid, geolite_dest[], geolite_len = sizeof (geolite_dest))
GetPlayerUTC(playerid, geolite_dest[], geolite_len = sizeof (geolite_dest))
IsPlayerUsingProxy(playerid)

Usage

#include <a_samp>
#include <sscanf2>
#include <geolite>

main() {}

public OnPlayerConnect(playerid)
{
    new player_name[MAX_PLAYER_NAME], player_country[MAX_COUNTRY_LENGTH], connection_text[80];

    GetPlayerName(playerid, player_name, MAX_PLAYER_NAME);
    GetPlayerCountry(playerid, player_country, MAX_COUNTRY_LENGTH);

    format(connection_text, sizeof (connection_text), "%s joined from %s", player_name, player_country);
    SendClientMessageToAll(0xFFFF00FF, connection_text);
    return 1;
}

Extra Notes

127.0.0.1 is given as "Unknown" because it is a private IP.

Country, City and ASN databases will be updated every first Wednesday of every month.

It opens the databases on startup according to which database exists in scriptfiles folder, therefore if you prefer to use the Country database only, place maxmind_country.db into scriptfiles folder and not the other two databases.

It only detects public proxies and not VPNs.

A MySQL version would require non-threaded queries to keep the same usage of functions. If you have any suggestion, please inform me.

Constants:

#define MAX_AUTONOMOUS_SYSTEM_LENGTH    95
#define MAX_COUNTRY_LENGTH              45
#define MAX_CITY_LENGTH                 109
#define MAX_UTC_LENGTH                  7

Requirements

sscanf: https://github.com/maddinat0r/sscanf/releases

Credits