SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 08/08/2019, 04:18 PM   #1
FinStar
Big Clucker
 
Join Date: Nov 2013
Location: Instead of nothing
Posts: 154
Reputation: 0
Default HTTP error

Hi.

What is wrong?

server_log.txt:

Code:
[17:44:13] index:  response:  data: 
[17:44:13] [debug] Run time error 5: "Invalid memory access"
[17:44:13] [debug] AMX backtrace:
[17:44:13] [debug] #0 002e89fc in _cntr_GetXMLData (string[]=@026ac984 "", tag[]=@01450e9c "host", output[]=@01450c90 "", &start=@026ec960 4, maxlength=60) at larp.pwn:39259
[17:44:13] [debug] #1 002e86f8 in public ProxyResponde (index=1, response=1, data[]=@026ac984 "") at larp.pwn:39242
Code:
_cntr_GetXMLData(string[], tag[], output[], &start, maxlength = sizeof(output))
{
	new end = start = (strfind(string, tag, true, start) + strlen(tag) + 1);

	while(string[end] != '<' && string[end] != '\0' && end - start < maxlength) // Error line ..
		end++;

	strmid(output, string, start, end, maxlength);
}
Code:
forward ProxyResponde(index, response, data[]);
public ProxyResponde(index, response, data[])
{
	printf("index: %d response: %d data: %s");
	new
		pos,
		proxy[2],
		vpn[2];
		
	_cntr_GetXMLData(data, "host", PlayerHost[index], pos, 60);		
	_cntr_GetXMLData(data, "proxy", proxy, pos, 2);	// Error line
	_cntr_GetXMLData(data, "vpn", vpn, pos, 2);	
	
	PlayerProxy[index] = strval(proxy);
	PlayerVPN[index] = strval(vpn);
	
	printf("host: %s proxy: %d vpn: %d", PlayerHost[index], PlayerProxy[index], PlayerVPN[index]);

    // Kick ..
 
    return 1;
}
Code:
new String[64];
			format(String, 64, "https://www.ipqualityscore.com/api/xml/ip/%s", ReturnIP(playerid));
			HTTP(playerid, HTTP_GET, String, "", "ProxyResponde");
FinStar is offline   Reply With Quote
Old 08/08/2019, 04:40 PM   #2
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 660
Reputation: 96
Default Re: HTTP error

Without a XML/JSON plugin, it is easier to extract them in Pawn with json (api) format.
pawn Code:
new bool: proxy, proxy_pos,
    bool: vpn, vpn_pos;

proxy_pos = strfind(data, "\"proxy\":");
vpn_pos = strfind(data, "\"vpn\":");

sscanf(data[proxy_pos + 8], "p<,>l{s[1]}", proxy);
sscanf(data[vpn_pos + 6], "p<,>l{s[1]}", vpn);

printf("proxy: %d, vpn: %d", proxy, vpn);

`host` is the IP you search for, no reason to extract it unless you meant ISP.
Calisthenics is offline   Reply With Quote
Old 08/08/2019, 04:45 PM   #3
FinStar
Big Clucker
 
Join Date: Nov 2013
Location: Instead of nothing
Posts: 154
Reputation: 0
Default Re: HTTP error

Okay, so that I can do the same with others, like host, country, region, ISP, ..

EDIT:

Yes, I mean ISP.
FinStar is offline   Reply With Quote
Old 08/08/2019, 05:21 PM   #4
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 660
Reputation: 96
Default Re: HTTP error

It is better to use a plugin if you want to extract many of them.

https://github.com/Southclaws/pawn-requests

pawn Code:
#include <a_samp>
#include <requests>

new RequestsClient: client;

main() {}

public OnGameModeInit()
{
    new ip[] = "x.x.x.x"; // change

    client = RequestsClient("http://ipqualityscore.com/", RequestHeaders());

    new path[75];
    format(path, sizeof (path), "api/json/ip/YOUR_API_KEY/%s?strictness=1", ip);

    RequestJSON(
        client,
        path,
        HTTP_METHOD_GET,
        "OnGetJson",
        .headers = RequestHeaders()
    );
    return 1;
}

forward OnGetJson(Request:id, E_HTTP_STATUS:status, Node:node);
public OnGetJson(Request:id, E_HTTP_STATUS:status, Node:node)
{
    new bool: proxy;
    JsonGetBool(node, "proxy", proxy);
   
    new bool: vpn;
    JsonGetBool(node, "vpn", vpn);
   
    new ISP[100];
    JsonGetString(node, "ISP", ISP);
   
    new country_code[3];
    JsonGetString(node, "country_code", country_code);
   
    new region[100];
    JsonGetString(node, "region", region);
   
    new city[100];
    JsonGetString(node, "city", city);

    printf("proxy: %d\n\
            vpn: %d\n\
            ISP: %s\n\
            country_code: %s\n\
            region: %s\n\
            city: %s"
,
            proxy,
            vpn,
            ISP,
            country_code,
            region,
            city);
}
Calisthenics 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
HTTP error qRazor Scripting Help 20 29/03/2019 06:57 PM
Error 301 with HTTP() djoudjou Scripting Help 4 21/01/2019 04:54 PM
[Ajuda] Error HTTP social PortuguÍs/Portuguese 1 24/07/2017 03:58 AM
HTTP Error Deduction Scripting Help 1 26/12/2012 02:28 AM
HTTP() callback won't fire, + server crash using HTTP() KoczkaHUN Bug Reports 6 14/12/2011 09:35 AM


All times are GMT. The time now is 09:38 AM.


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