I need a working detection of country script
#1

this is what I tested so far and didn't work:

https://sampforum.blast.hk/showthread.php?tid=296171
https://sampforum.blast.hk/showthread.php?tid=32509
https://sampforum.blast.hk/showthread.php?tid=521843
Reply
#2

1. Have you made sure you had all the required files?
2. Have you used a string to store the name of the country, city, etc?
Please come with the code that you tried.
Reply
#3

Quote:
Originally Posted by XStormiest
View Post
1. Have you made sure you had all the required files?
2. Have you used a string to store the name of the country, city, etc?
Please come with the code that you tried.
Yes of course

I tried with 4 different includes none of them worked

geoip.inc
https://pastebin.com/B08XHjA2
geolocation.inc
https://pastebin.com/kzfD7y5g
lookup.inc
https://pastebin.com/xwf5mwyC
lookup2.inc
https://pastebin.com/ad2tkVTa
Reply
#4

I will give you an example for this one geolocation.inc, since it is the one I've been using and it works.
Code:
GetCountry(playerid)
{
    new country[32], message[128], name[24];
    GetPlayerName(playerid, name, sizeof(name));
    GetPlayerCountry(playerid, country, sizeof(country))
    format(message, sizeof(message), "%s is from the country %s",  name, country);
    return message; 
}
Reply
#5

Quote:
Originally Posted by XStormiest
View Post
I will give you an example for this one geolocation.inc, since it is the one I've been using and it works.
Code:
GetCountry(playerid)
{
    new country[32], message[128], name[24];
    GetPlayerName(playerid, name, sizeof(name));
    GetPlayerCountry(playerid, country, sizeof(country))
    format(message, sizeof(message), "%s is from the country %s",  name, country);
    return message; 
}
Yes, I'm currently using geolocation.inc and there is the same function


Code:
stock GetPlayerCountry(playerid, string3123[], const len = sizeof(string3123)) {
	new ip[24];
	GetPlayerIp(playerid, ip, sizeof(ip));

	GetIPCountry(ip, string3123, len);

	return true;
}
Reply
#6

Can you show us how you used it?
Reply
#7

You can try one of the PHP location tracker and get the response from it..

PS When you say, its not "working", what do you mean? Whats the issue?
Reply
#8

Quote:
Originally Posted by XStormiest
View Post
I will give you an example for this one geolocation.inc, since it is the one I've been using and it works.
Code:
GetCountry(playerid)
{
    new country[32], message[128], name[24];
    GetPlayerName(playerid, name, sizeof(name));
    GetPlayerCountry(playerid, country, sizeof(country))
    format(message, sizeof(message), "%s is from the country %s",  name, country);
    return message; 
}
Worked Thanks !!!

Code:
stock GetPlayerCountry(playerid)
{
    new string3123[32];
    new ip123[24];
    GetPlayerIp(playerid, ip123, sizeof(ip123));
    GetIPCountry(ip123, string3123, sizeof(string3123));
    return string3123; 
}
++REP
Reply
#9

Quote:
Originally Posted by GTLS
View Post
You can try one of the PHP location tracker and get the response from it..

PS When you say, its not "working", what do you mean? Whats the issue?
it was not working in general, im not advanced scripter but the problem was with the stock but geolocation include only importing only the database files stored in /scriptfiles

I was trying to make lookup include to work again but it seems the website(www.countryffs.com) is offline thats why not working ?

lookup include:
PHP Code:
//===[Misc]=====================================================================
#include <a_http>
#define GetPlayerHost(%1) LookupData[%1][Hostname]
#define GetPlayerISP(%1) LookupData[%1][ISP]
#define GetPlayerCountryCode(%1) LookupData[%1][Code]
#define GetPlayerCountryName(%1) LookupData[%1][Country]
#define GetPlayerCountryRegion(%1) LookupData[%1][Region]
#define IsProxyUser(%1) LookupData[%1][Proxy]
enum ldata
{
    
Hostname[60],
    
ISP[60],
    
Code[3],
    
Country[45],
    
Region[43],
    
Proxy
};
new
    
LookupData[MAX_PLAYERS][ldata],
    
PlayerSession[MAX_PLAYERS],
    
Retry[MAX_PLAYERS];
forward OnLookupResponse(sessionidresponsedata[]);
forward OnLookupComplete(playerid);
//===[Callbacks]================================================================
public OnPlayerConnect(playerid)
{
    
cleardata(LookupData[playerid][Hostname]);
    
cleardata(LookupData[playerid][ISP]);
    
cleardata(LookupData[playerid][Code]);
    
cleardata(LookupData[playerid][Country]);
    
cleardata(LookupData[playerid][Region]);
    
LookupData[playerid][Proxy] = 0;
    
Retry[playerid] = 0;
    
PlayerSession[playerid] = 0;
    
LookupPlayerIP(playerid);
    return 
CallLocalFunction("Lookup_OnPlayerConnect""i"playerid);
}
public 
OnLookupResponse(sessionidresponsedata[])
{
    new 
xml[5][2],
    
playerid GetPlayerFromSession(sessionid);
    if(
playerid == -1) return 1;
    if(
response != 200)
    {
    if(
Retry[playerid] == 0)
    {
    
Retry[playerid] = 1;
    
LookupPlayerIP(playerid);
    }
    return 
1;
    }
    
xml[0][0] = strfind(data,     "<host>"true);
    
xml[0][1] = strfind(data,    "</host>"true);
    
xml[1][0] = strfind(data,      "<isp>"true);
    
xml[1][1] = strfind(data,     "</isp>"true);
    
xml[2][0] = strfind(data,     "<code>"true);
    
xml[2][1] = strfind(data,    "</code>"true);
    
xml[3][0] = strfind(data,  "<country>"true);
    
xml[3][1] = strfind(data"</country>"true);
    
xml[4][0] = strfind(data,   "<region>"true);
    
xml[4][1] = strfind(data,  "</region>"true);
    
strmidex(LookupData[playerid][Hostname], data,  xml[0][0], xml[0][1], 60);
    
strmidex(LookupData[playerid][ISP],      data,  xml[1][0], xml[1][1], 60);
    
strmidex(LookupData[playerid][Code],     data,  xml[2][0], xml[2][1],  3);
    
strmidex(LookupData[playerid][Country],  data,  xml[3][0], xml[3][1], 40);
    
strmidex(LookupData[playerid][Region],   data,  xml[4][0], xml[4][1], 40);
    
LookupData[playerid][Proxy] = strval(data[strfind(data"<proxy>"true) + 7]);
    
CallLocalFunction("OnLookupComplete""i"playerid);
    return 
1;
}
//===[Functions]================================================================
stock LookupPlayerIP(playerid)
{
    if(!
IsPlayerNPC(playerid))
    {
    new 
ip[16], lQuery[60];
    static
    
SessionIndex;
    
SessionIndex++;
    
PlayerSession[playerid] = SessionIndex;
    
GetPlayerIp(playeridipsizeof(ip));
    
format(lQuerysizeof(lQuery), "www.countryffs.com/api.php?ip=%s"ip);
    
HTTP(SessionIndexHTTP_GETlQuery"""OnLookupResponse");
    }
}
stock GetPlayerFromSession(sessionid)
{
    for(new 
0MAX_PLAYERSi++)
    {
    if(
IsPlayerConnected(i) && PlayerSession[i] == sessionid)
    return 
i;
    }
    return -
1;
}
stock DisplayLookupData(playeridtargetid)
{
    new 
lstr[300], boxname[40];
    
GetPlayerIp(targetidboxnamesizeof(boxname));
    
format(boxnamesizeof(boxname), "IP Lookup: %s"boxname);
    
format(lstrsizeof(lstr),
    
"Hostname: %s\n\
    ISP: %s\n\
    Country: %s (%s)\n\
    State/Region: %s"
,
    
LookupData[targetid][Hostname],
    
LookupData[targetid][ISP],
    
LookupData[targetid][Country],
    
LookupData[targetid][Code],
    
LookupData[targetid][Region]);
    
ShowPlayerDialog(playerid30000DIALOG_STYLE_MSGBOXboxnamelstr"Close""");
}
stock strmidex(dest[], const src[],  startendmaxlength=sizeof dest)
{
    if(
end start 1)
    
strmid(destsrc,  startendmaxlength);
}
stock cleardata(src[])
{
    
src[0] = '?';
    new 
1;
    while(
src[c] != '\0')
    {
    
src[c] = '\0';
    
c++;
    }
}
//===[Hooking]==================================================================
#if defined _ALS_OnPlayerConnect
#undef OnPlayerConnect
#else
#define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect Lookup_OnPlayerConnect
forward Lookup_OnPlayerConnect(playerid); 
Reply
#10

This whole thing can be done so much easier:

pawn Code:
//Get IP and send that data:
new string[45];
GetPlayerIp(playerid, string, 16);
format(string, sizeof(string), "ip-api.com/csv/%s?fields=3", string);
HTTP(playerid, HTTP_GET, string, "", "OnLookupIP");

//Retrieve the data:
foward OnLookupIP(index, response_code, data[]);
public OnLookupIP(index, response_code, data[]) //Not checking if response was OK (200) here
{
    new Country[64], cCode[2];
    sscanf(data, "p<,>s[64]s[2]", Country, cCode);
    //Now you know the country (Country) and country code (cCode) of "index" (index = playerid)
}
http://ip-api.com/csv/IP_HERE?fields=3 returns nothing but: Country,Country_Code. If you just need the country name, use ?fields=1. Then you won't even need sscanf and you can just use "data".

NOTE: HTTP() is threaded. So if you want to retrieve the country before doing anything else (such as checking if the player is registered) you should use this under OnPlayerConnect as the very first thing, and proceed once the data comes in at OnLookupIP().

EDIT:
If you want to fetch all data like in the post above, you should use ip-api.com/csv/IP_HERE (without ?fields=x)
This returns (if success):
Code:
success,COUNTRY_NAME,COUNTRY_CODE(2 chars),REGION_CODE(2 chars),REGION_NAME,CITY,LAT,LON,TIMEZONE,ISP,ORG,AS,QUERY(which is the IP)
If it failed (eg. by using a local IP):
Code:
fail,message,query
'message' in such a case would be "private range" or "reserved range" if you're connecting as localhost (127.0.0.1)


Since the /csv/ returns the data seperated by comma's you won't need multiple kind of functions to fetch the data, you can simply use sscanf. Example:
pawn Code:
//Get IP and send that data:
new string[37];
GetPlayerIp(playerid, string, 16);
format(string, sizeof(string), "ip-api.com/csv/%s", string);
HTTP(playerid, HTTP_GET, string, "", "OnLookupIP");

foward OnLookupIP(index, response_code, data[]);
public OnLookupIP(index, response_code, data[])
{
    new success[8], Country[64], cCode[2], rCode[2], Region[64], City[64], Float:gps_lat, Float:gps_lon, timezone[64], IspName[64], IspOrg[64], AS[10];
    sscanf(data, "p<,>s[8]s[64]s[2]s[2]s[64]s[64]ffs[64]s[64]s[64]s[10]", success, Country, cCode, rCode, Region, City, gps_lat, gps_lon, timezone, IspName, IspOrg, AS);
}
If success is "fail", use "Country" to get the message error.
Note how I by default used array sizes of 64 cells. No idea what maximum names can be for regions, ISP, cities etc. Might wanna tweak it a bit if it turns out they're too small or too big.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)