Thread: HTTP:X
View Single Post
JusTGo
Veteran Member
Join Date: Mar 2013
Old 09-14-2016 , 17:41   Re: HTTP:X
Reply With Quote #24

Quote:
Originally Posted by Freezo Begin View Post
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(sBuffer127"http://ip-api.com/json/%s"IP
    
    
g_ClientTrace[id] = HTTPX_Download(sBuffer_"Complete"); 


public 
client_disconnect(id

    
g_ClientTrace[id] = 
    idCount
--;


public 
Complete(DownloadIDError) { 
    if ( 
Error 
    { 
        
server_print("Something went wrong..."
        return; 
    } 
    
    
idCount++;
    
    new 
szName[32];
    
get_user_name(idCountszNamecharsmax(szName))
    

    
server_print("file download complete."
    
    new 
buffer[1024]; 
    
HTTPX_GetData(buffercharsmax(buffer)); 
    
    if(!
is_user_connected(idCount)) 
        return 
    
    new 
JsonHandle:jroot json_object() 
    new 
error_buffer[32
    
jroot json_loads(bufferJSON_REJECT_DUPLICATESerror_buffersizeof(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(datacountrysizeof(country)) 
    
    
data json_object_get(jroot"city"
    if(
data == INVALID_JSON
    { 
        
server_print("Coudln't find city."
        return 
    } 
    
json_string_value(datacitysizeof(city)) 
    
    
data json_object_get(jroot"isp"
    if(
data == INVALID_JSON
    { 
        
server_print("Coudln't find isp."
        return 
    } 
    
json_string_value(dataispsizeof(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.
__________________
JusTGo is offline