SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 18/05/2020, 02:55 PM   #1
NeXTGoD
Banned
 
Join Date: Jul 2018
Posts: 118
Reputation: 9
Default I need a working detection of country script

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

https://forum.sa-mp.com/showthread.php?t=296171
https://forum.sa-mp.com/showthread.php?t=32509
https://forum.sa-mp.com/showthread.php?t=521843
NeXTGoD is offline   Reply With Quote
Old 18/05/2020, 04:51 PM   #2
XStormiest
Gangsta
 
Join Date: Jun 2012
Location: Continent: Europe, Country: Romania, City: Buzau
Posts: 558
Reputation: 46
Default Re: I need a working detection of country script

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.
__________________
XStormiest is offline   Reply With Quote
Old 18/05/2020, 05:54 PM   #3
NeXTGoD
Banned
 
Join Date: Jul 2018
Posts: 118
Reputation: 9
Default Re: I need a working detection of country script

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
NeXTGoD is offline   Reply With Quote
Old 18/05/2020, 06:05 PM   #4
XStormiest
Gangsta
 
Join Date: Jun 2012
Location: Continent: Europe, Country: Romania, City: Buzau
Posts: 558
Reputation: 46
Default Re: I need a working detection of country script

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; 
}
__________________
XStormiest is offline   Reply With Quote
Old 19/05/2020, 12:17 PM   #5
NeXTGoD
Banned
 
Join Date: Jul 2018
Posts: 118
Reputation: 9
Default Re: I need a working detection of country script

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;
}
NeXTGoD is offline   Reply With Quote
Old 19/05/2020, 12:34 PM   #6
Fairuz
Huge Clucker
 
Fairuz's Avatar
 
Join Date: Sep 2015
Location: Indonesia
Posts: 455
Reputation: 64
Default Re: I need a working detection of country script

Can you show us how you used it?
__________________
Los Santos based Cops and Robbers with many features.
209.58.183.101:7777
Fairuz is online now   Reply With Quote
Old 19/05/2020, 01:01 PM   #7
GTLS
High-roller
 
GTLS's Avatar
 
Join Date: Aug 2014
Location: India
Posts: 1,072
Reputation: 119
Default Re: I need a working detection of country script

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?
__________________

I don't help for rep. I help cuz I was helped in the past.


Retired from SAMP Scene. Might open SAMP Forums once in a while.

Some treats for ya. Click em
Basic House System
Simple Speedo
Base Login/Register Script

GTLS is offline   Reply With Quote
Old 19/05/2020, 01:11 PM   #8
NeXTGoD
Banned
 
Join Date: Jul 2018
Posts: 118
Reputation: 9
Default Re: I need a working detection of country script

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
NeXTGoD is offline   Reply With Quote
Old 19/05/2020, 05:18 PM   #9
NeXTGoD
Banned
 
Join Date: Jul 2018
Posts: 118
Reputation: 9
Default Re: I need a working detection of country script

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); 
NeXTGoD is offline   Reply With Quote
Old 20/05/2020, 04:55 PM   #10
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,712
Reputation: 1671
Default Re: I need a working detection of country script

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.
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#8009

Last edited by Kwarde; 21/05/2020 at 12:35 PM.
Kwarde is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I want gamemode script for my country khadeptrai Scripting Help 1 02/10/2018 05:06 AM
Leg hit bodypart detection not working. Dokins Scripting Help 1 15/02/2015 11:36 PM
Working on my script need help KingyKings Scripting Help 3 30/11/2011 04:31 PM
How to make country detection on connect? NiXeL Help Archive 4 21/06/2010 10:36 AM
[FilterScript] [FS] Short and simple teleport dialog from country to country bartje01 Filterscripts 2 18/03/2010 01:31 PM


All times are GMT. The time now is 11:11 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.