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

i want to download a file for specific player is there is a way to have played index added to complete handler for now i m looping through all players to find the related player file:
PHP Code:
#include <amxmodx>
#include <httpx>
#include <json>

new g_ClientTrace[33]

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] = 0
}

public 
Complete(DownloadIDError) {
    if ( 
Error )
    {
        
server_print("Something went wrong...")
        return;
    }
    
    
server_print("file download complete.")
    
    new 
buffer[1024];
    
HTTPX_GetData(buffercharsmax(buffer));
    
    
server_print("Recived Data:%s",buffer)
    
    new 
id GetTracedClient(DownloadID)
    
    if(!
is_user_connected(id))
        return
    
    new 
szName[32]
    
get_user_name(idszNamecharsmax(szName))
    
    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)
}

GetTracedClient(DownloadID)
{
    new 
iPlayers32 ], iNumiTracedClient=0;
    
get_playersiPlayersiNum"ch" );
    for( 
0iNumi++ )
    {
        if(
g_ClientTrace[i] == DownloadID)
        {
            
TracedClient=g_ClientTrace[i]
            break
        }
    }
    
    return 
TracedClient

__________________
JusTGo is offline