|
Veteran Member
|
09-14-2016
, 17:41
Re: HTTP:X
|
#24
|
Quote:
Originally Posted by Freezo Begin
JustGo,
PHP Code:
#include <amxmodx>
#include <httpx>
#include <json>
new g_ClientTrace[33]
new idCount;
public plugin_init() {
register_plugin("HTTP:X Searching chunks example", "2.0", "[ --{-@ ]");
}
public client_putinserver(id)
{
new sBuffer[128], IP[24]
get_user_ip(id,IP,charsmax(IP),1)
format(sBuffer, 127, "http://ip-api.com/json/%s", IP)
g_ClientTrace[id] = HTTPX_Download(sBuffer, _, "Complete");
}
public client_disconnect(id)
{
g_ClientTrace[id] = 0
idCount--;
}
public Complete(DownloadID, Error) {
if ( Error )
{
server_print("Something went wrong...")
return;
}
idCount++;
new szName[32];
get_user_name(idCount, szName, charsmax(szName))
server_print("file download complete.")
new buffer[1024];
HTTPX_GetData(buffer, charsmax(buffer));
if(!is_user_connected(idCount))
return
new JsonHandle:jroot = json_object()
new error_buffer[32]
jroot = json_loads(buffer, JSON_REJECT_DUPLICATES, error_buffer, sizeof(error_buffer))
if(jroot == INVALID_JSON)
{
server_print("Coudln't decode json.")
return
}
new JsonHandle:data = json_object()
new country[24],city[24],isp[24]
data = json_object_get(jroot, "country")
if(data == INVALID_JSON)
{
server_print("Coudln't find country.")
return
}
json_string_value(data, country, sizeof(country))
data = json_object_get(jroot, "city")
if(data == INVALID_JSON)
{
server_print("Coudln't find city.")
return
}
json_string_value(data, city, sizeof(city))
data = json_object_get(jroot, "isp")
if(data == INVALID_JSON)
{
server_print("Coudln't find isp.")
return
}
json_string_value(data, isp, sizeof(isp))
destroy_json(data)
destroy_json(jroot)
server_print("name: %s | country:%s | city:%s | isp:%s",szName,country,city,isp)
}
|
ty for try but i think that players can disconnect before they trigger client_putinserver ? also this isn't a solution if you try to get the data in the middle of game.
__________________
|
|
|
|