Liberty Unleashed

Scripting => Scripting Discussion => Topic started by: Vortrex on December 22, 2011, 06:43:22 pm

Title: IP to Country (GeoIP)
Post by: Vortrex on December 22, 2011, 06:43:22 pm
I've never worked with any C language, so I don't know how to build modules for LU, so I decided to take another route to getting a country name from an IP address. Currently, I am using a custom PHP socket server that listens on a certain port for incoming connections and data from already established connections.

As of now, the socket listens for something like "GEOIP 127.0.0.1". This server will send the name of the country back to the socket, which could be used to display a user's country on player join or something.

Anybody who is interested in using this, feel free. I am making this service public for all, so you can translate an IP to a country name in your script.

Here is a Squirrel snippet to help (if you need it):
Code: [Select]
function GeoIPProcess(socket,data)
{
LAST_COUNTRY <- data;
}

function onScriptLoad()
{
GeoIPSocket <- NewSocket("GeoIPProcess");
GeoIPSocket.Connect( "206.217.206.245", 2302 );
LAST_COUNTRY <- "";
}

function onPlayerConnect(player)
{
GeoIPSocket.Send("GEOIP " + player.IP);
}

function onPlayerJoin(player)
{
Message(player.Name + " has joined the server from " + LAST_COUNTRY,Colour(255,255,255));
}
Title: Re: IP to Country (GeoIP)
Post by: Thijn on December 23, 2011, 01:20:18 pm
First of all, even though you have no experience in making a Module, this is totally the wrong way to do it.
PHP wasn't made for a server listener, You can better parse an already existing site that gives you the country.
That squirrel snippet is wrongly made too. If 2 players join at the same time, and one request is faster then other one, the country names can be switched. Use arrays and player IDs for this.
Title: Re: IP to Country (GeoIP)
Post by: VetalYA on December 24, 2011, 12:38:49 am
I find everything that you said is  correct, but do not be so angry, it's only initial release :)
Title: Re: IP to Country (GeoIP)
Post by: SugarD on December 24, 2011, 04:35:20 am
Jeez Thijn, why are you so upset? D:
Title: Re: IP to Country (GeoIP)
Post by: Thijn on December 24, 2011, 03:27:07 pm
I wasn't upset, Its just my honest opinion..
Title: Re: IP to Country (GeoIP)
Post by: SugarD on December 24, 2011, 05:43:32 pm
I wasn't upset, Its just my honest opinion..
Your opinion became slightly irritated then D: