[Include] Ip Locator Adds Callback OnRetrieveIpLocation(playerid, country[], city[])
#1

Ip Locator 1.1
What does it do?

Quite simple, it adds a callback that gets called just after a player connects. The players country and city are sent to a the callback as two strings. The data is retrieved from this site http://www.hostip.info/

When a player connects a HTTP get request is sent with the players ip to the site above, when the site responds OnRetrieveIpLocation will be called. (after everything in OnPlayerConnect)


Example FS
pawn Код:
#define FILTERSCRIPT

#include <a_samp>
#include <iploc>

public OnFilterScriptInit()
{
    return 1;
}

public OnRetrieveIpLocation(playerid, country[])
{

    new
        szStr[ 64 ];

    GetPlayerName( playerid, szStr, MAX_PLAYER_NAME );

    format( szStr, sizeof( szStr ), "<SERVER> Welcome %s to the server. From %s", szStr, country );

    SendClientMessageToAll( -1, szStr );

}

public OnPlayerConnect( playerid )
{
    return 1;
}
NOTE: If an ip isn't stored on that site it's country will be "Private country" (this happens with localhost too). I could also add lat/lon but i thought that would be pretty pointless.

If anyone spots any bugs please point them out and ill try fix em.

UPDATE 1.1
  • Code re-written much more efficient and should hopefully work on linux.
  • Callback no longer has city argument, it was too inaccurate on all free sites i could find.
Download: http://dl.dropbox.com/u/76608104/iploc1.1.inc

Alternative:
If this isn't what your after try slices plugin free GeoIp filterscript.
Slices plugin free GeoIp: https://sampforum.blast.hk/showthread.php?tid=190699
Reply
#2

Pretty nice man, like it. Short but useful. 5/5
Reply
#3

Nice, ... i will try it tomorrow, if works perfectlly, i will use it !
Reply
#4

this is nice and this will be may be more accurate
A Question:
Can i use it to retrieve info customly e.g.
a command /getloc <playerid> and get his ip in command and use it some how ? or it works only in OnPlayerConnect?
i mean if there be stock or something will make this more cool :/
EDIT: i trying it now , but its no working O.o
Reply
#5

Nice way do detect and quite fast. Good job.
Reply
#6

Nice! Good Job nice and clean!
Reply
#7

Quote:
Originally Posted by Niko_boy
Посмотреть сообщение
this is nice and this will be may be more accurate
A Question:
Can i use it to retrieve info customly e.g.
a command /getloc <playerid> and get his ip in command and use it some how ? or it works only in OnPlayerConnect?
i mean if there be stock or something will make this more cool :/
EDIT: i trying it now , but its no working O.o
It returns "private country" if you connect from your localhost. ie if you connect to your home-hosted server. Next update i will get it to display "Local host" in that case.

You could also make that command yourself with the callback provided, just store the country/city in an array, and have a function return it. (or just use the var in the command)

If i added a function to get the players country, people would more than likely use it in OnPlayerConnect and it wouldn't work. I thought a callback would be the simplest way. If there was a way for me to get the HTTP response instantly i would have added more funcs.

Thanks all for positive feedback.
Reply
#8

Quote:
Originally Posted by iggy1
Посмотреть сообщение
Thanks all for positive feedback.
Welcome.
Quote:
Originally Posted by iggy1
Посмотреть сообщение
It returns "private country" if you connect from your localhost. ie if you connect to your home-hosted server. Next update i will get it to display "Local host" in that case.
But ^
it must say Private COuntry , but it isnt doing so O.o ?
nor it called the Function... OnRetrieveIpLocation
.. i tried to debug where it is CallLocalFunction("onretrieve.. and debug also showed no results .. ?
wtabout that ?
Reply
#9

I'll just check it again now, i'm quite sure it was working when i posted it. I will edit this post.

EDIT: It works for me, check your server log for the http response.

pawn Код:
#include <a_samp>
#include <iploc>

public OnRetrieveIpLocation(playerid, country[], city[])
{

    printf("playerid %d, joined from country %s, city %s", playerid, country, city);

}

main()
{
    print("\n----------------------------------");
    print("The most blank GM in the world!!!");
    print("----------------------------------\n");
}


public OnGameModeInit()
{
    return 1;
}
server_log:
Код:
[17:37:41] playerid 0, joined from country private country, city private address
Reply
#10

Nop nothing in there :/

Quote:

[21:55:27] OnGameo
[21:55:27]
--------------------------------------
[21:55:27] Iggys Ip Locator Loaded.
[21:55:27] --------------------------------------

[21:55:27]
----------------------------------
[21:55:27] Running LVDM ~MoneyGrub

[21:55:27] Coded By
[21:55:27] Jax
[21:55:27] ----------------------------------

[21:55:27] Number of vehicle models: 48
[21:55:40] Incoming connection: 192.168.1.3:59081
[21:55:40] [join] Niko_boy has joined the server (0:192.168.1.3)
[22:02:34] [part] Niko_boy has left the server (0:1)

and i use code u posted in ur first post no message is send + as i said earleir the Fucntion isnt gettign called.
aight i g2g atm :. i will get back to thread and try the script tommorow again :
Reply
#11

Run the GM i posted above, connect then dissconnect and post server_log please.

It's strange because every time i test it works. Maybe post your code?
Reply
#12

lol wtf i tried today and it worked xD
Thank You.
Also tried it on a host but its Showing my City as Banglore but my ISP is Hosted in New Delhi
i mean city differnece is there..
+ i tried to check my ISP again on thsi website http://www.ip-adress.com/ip_tracer/ its showing correct i.e. Delhi
so can that part be fixed i mean by using a better Ip Tracker website in website or something

and plz make those functions to get Info of custom playerid apart from only in OnPlayerConnect :/
Reply
#13

Hmm.. where have I seen this before?
Reply
#14

Quote:
Originally Posted by Niko_boy
View Post
lol wtf i tried today and it worked xD
Thank You.
Also tried it on a host but its Showing my City as Banglore but my ISP is Hosted in New Delhi
i mean city differnece is there..
It seems that site is a bit shite! I will look for another. I could use Geoip like slices

The hostip_response callback in the include is quite in-efficient (not too bad though) i will change that with next update.

@ slice did you mean yours or another?
Reply
#15

thought this was an include not a FS?
Reply
#16

very nice man
Reply
#17

Hmm looks nice. Must ... test ... this !

EDIT: fuck Doesn't work (on Linux)
Reply
#18

Quote:
Originally Posted by Michael@Belgium
View Post
Hmm looks nice. Must ... test ... this !

EDIT: fuck Doesn't work (on Linux)
Are you a linux guy? Any idea why it wont work on linux?

I think it might have something to do with the data returned from the HTTP call. If it uses carriage return or not IDK. (i dont even know if that would stop it from working)

Also does it print anything in server_log? It should print an error if the HTTP request fails. (or something else goes wrong)

If anyone has any ideas please let me know.

I will test it on linux in a day or two haven't got time to install ATM and need to free a lot of space on my HDD.

I will be removing the "city" argument because of how inaccurate it is. On all the sites i have looked at none that are free are accurate. (only payed services are)
Reply
#19

Quote:
Originally Posted by iggy1
View Post
Are you a linux guy? Any idea why it wont work on linux?

I think it might have something to do with the data returned from the HTTP call. If it uses carriage return or not IDK. (i dont even know if that would stop it from working)

Also does it print anything in server_log? It should print an error if the HTTP request fails. (or something else goes wrong)

If anyone has any ideas please let me know.

I will test it on linux in a day or two haven't got time to install ATM and need to free a lot of space on my HDD.

I will be removing the "city" argument because of how inaccurate it is. On all the sites i have looked at none that are free are accurate. (only payed services are)
Well ye i am a sort of Linux guy, my 2 servers are hosted on Linux OS. And it doesn't print anything in the server_log. When a player connect he immediatly crashes (because it get called on ONPlayerConnect())
Reply
#20

@Michael@Belgium Thanks for the report i never thought i'd need to test on linux TBH.

I will re-write it now.

Is it just the player who crashes or the server?

EDIT: Re-written should work fine now. I never did find the bug but i have made the code a lot smaller and more efficient. I don't see any reason why this wouldn't work on linux.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)