Raised This Month: $12 Target: $400
 3% 

[EXTENSION] System2 - Easy to use HTTP(S)/FTP Request API and useful system natives


Post New Thread Reply   
 
Thread Tools Display Modes
dordnung
Veteran Member
Join Date: Apr 2010
Old 01-27-2018 , 09:06   Re: [EXTENSION] System2 - Easy to use HTTP/FTP Request API and useful system natives
Reply With Quote #71

You can just do it like this:

PHP Code:
System2HTTPRequest request = new System2HTTPRequest(HttpResponseCallback"http://example.com"); 
request.SetData("data=myData"); 
request.POST(); 
This will produce the same request as the with the old syntax:
PHP Code:
System2_GetPage(HttpResponseCallback"http://example.com""data=myData"); 
__________________

Last edited by dordnung; 01-27-2018 at 09:12.
dordnung is offline
CamerDisco
AlliedModders Donor
Join Date: Aug 2015
Location: Poland
Old 01-27-2018 , 09:12   Re: [EXTENSION] System2 - Easy to use HTTP/FTP Request API and useful system natives
Reply With Quote #72

I mean Client UserID to callback and etc
__________________


Max-Play.pl - the best polish servers
CamerDisco is offline
dordnung
Veteran Member
Join Date: Apr 2010
Old 01-27-2018 , 09:14   Re: [EXTENSION] System2 - Easy to use HTTP/FTP Request API and useful system natives
Reply With Quote #73

Ah sorry, but this is easy, too:

PHP Code:
int userId 2;

System2HTTPRequest request = new System2HTTPRequest(HttpResponseCallback"http://example.com"); 
request.Any userId;
request.SetData("data=myData"); 
request.POST(); 
And in the response:

PHP Code:
void HttpResponseCallback(bool success, const char[] errorSystem2HTTPRequest requestSystem2HTTPResponse responseHTTPRequestMethod method) { 
    if (
success) { 
        
PrintToServer("UserID is: %d"request.Any); 
    }

__________________

Last edited by dordnung; 01-27-2018 at 09:16.
dordnung is offline
CamerDisco
AlliedModders Donor
Join Date: Aug 2015
Location: Poland
Old 01-27-2018 , 10:07   Re: [EXTENSION] System2 - Easy to use HTTP/FTP Request API and useful system natives
Reply With Quote #74

Oh thanks
__________________


Max-Play.pl - the best polish servers
CamerDisco is offline
lugui
Senior Member
Join Date: Feb 2016
Location: GetClientAbsOrigin();
Old 02-12-2018 , 12:45   Re: [EXTENSION] System2 - Easy to use HTTP/FTP Request API and useful system natives
Reply With Quote #75

Apparently, if you do a lot of requests using this extension, the server crashes.

I created a plugin that periodicaly makes requests to a server. after some time running, the plugin simply stops requesting and if there are players / a player joins the server, the server crashes and I get this error from sourcemod:

[SM] Unable to create db threader (error unknown)
lugui is offline
dordnung
Veteran Member
Join Date: Apr 2010
Old 02-12-2018 , 12:56   Re: [EXTENSION] System2 - Easy to use HTTP/FTP Request API and useful system natives
Reply With Quote #76

Thanks for this hint.
Do you have any sample code for reproduce this? This would help me.
__________________
dordnung is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 02-12-2018 , 15:01   Re: [EXTENSION] System2 - Easy to use HTTP/FTP Request API and useful system natives
Reply With Quote #77

Quote:
Originally Posted by lugui View Post
Apparently, if you do a lot of requests using this extension, the server crashes.

I created a plugin that periodicaly makes requests to a server. after some time running, the plugin simply stops requesting and if there are players / a player joins the server, the server crashes and I get this error from sourcemod:

[SM] Unable to create db threader (error unknown)
You're running out of OS threads, and this extension creates a new thread for almost every operation which isn't really best practice.

What SM version are you using? What OS?
__________________
asherkin is offline
dordnung
Veteran Member
Join Date: Apr 2010
Old 02-12-2018 , 15:10   Re: [EXTENSION] System2 - Easy to use HTTP/FTP Request API and useful system natives
Reply With Quote #78

Then the question is, how often "periodicaly" is.
I've added a request in OnGameFrame and never got more then 30 threads, which shouldn't be a problem for any OS
__________________

Last edited by dordnung; 02-12-2018 at 15:36.
dordnung is offline
lugui
Senior Member
Join Date: Feb 2016
Location: GetClientAbsOrigin();
Old 02-12-2018 , 16:01   Re: [EXTENSION] System2 - Easy to use HTTP/FTP Request API and useful system natives
Reply With Quote #79

I wrote a simpler version of my plugin that just does the request.

Code:
#pragma semicolon 1

#define DEBUG

/* Stock Includes */
#include <sourcemod>
#include <sdktools>
#include <string>

/* Extra includes */
#include <system2>
#include <test>

char etag[40];
char lastModified[40];

System2HTTPRequest httpRequest;

public void OnMapStart()
{
	//initial header data
	lastModified = GetGmtDate();
	etag = "0";
	Longpoll();
}

void Longpoll()
{
	//the web server does not reply if nothing has changed sinse the last poll
	
	//this one will just aways get a response isntantly.
	httpRequest = new System2HTTPRequest(OnHTTPSRequestEnd, "https://lugui.in/fdlapi/Debug.php");
	
	//Long poll URL. Only works if there is something new on /pub
	//httpRequest = new System2HTTPRequest(OnHTTPSRequestEnd, "https://lugui.in/sub");
	
	httpRequest.SetHeader("If-Modified-Since", lastModified);
	httpRequest.SetHeader("If-None-Match", etag);
	httpRequest.Timeout = 60;
	httpRequest.GET();
}

 //The request always executes this function, even if it was unsuccessful
public void OnHTTPSRequestEnd(bool success, const char[] error, System2HTTPRequest request, System2HTTPResponse response, HTTPRequestMethod method)
{
	if(success) {
			char res[30];
			
			response.GetContent(res, response.ContentLength + 1);
			
			char dbfile[30];
			response.GetContent(dbfile, response.ContentLength + 1);
			
			LogToFile("addons/sourcemod/logs/FDMLog.log", "Received: %s", res);
			response.GetHeader("Etag", etag, sizeof(etag));
			response.GetHeader("Last-Modified", lastModified, sizeof(lastModified));
			
	}
	Longpoll();
}


//generates GMT Date and compensates for timezones.
//only needed if polling at /sub
char GetGmtDate()
{
	int timestamp = GetTime();
	
	//fix timezones
	char offsetstr[10];
	FormatTime(offsetstr, sizeof(offsetstr), "%z", timestamp);
	timestamp -= (StringToInt(offsetstr) / 100) * 3600;
	
	//build sring
	char GMTTime[40];
	FormatTime(GMTTime, sizeof(GMTTime), "%a, %d %h %Y %H:%M:%S GMT", timestamp);
	
	return GMTTime;
}
Basicaly, it long polls my server, waiting for a response (the date part is required for other reseons).
After a request, this plugin will log the response and start the poll again.
In this script, the request starts instantly after it ends, but it doesn't matter. if I insert a delay, the server will crash anyway with the same problem.

SO: Ubuntu 16.04
SM: 1.8.0.5982

Here is my server conole while I running this code.

Code:
//some time running the plugin..
L 02/12/2018 - 18:54:54: [debug.smx] Received: TestMsg.1518468894
L 02/12/2018 - 18:54:55: [debug.smx] Received: TestMsg.1518468895
L 02/12/2018 - 18:54:55: [debug.smx] Received: TestMsg.1518468895
L 02/12/2018 - 18:54:55: [debug.smx] Received: TestMsg.1518468895
L 02/12/2018 - 18:54:56: [debug.smx] Received: TestMsg.1518468895
L 02/12/2018 - 18:54:56: [debug.smx] Received: TestMsg.1518468896
L 02/12/2018 - 18:54:56: [debug.smx] Received: TestMsg.1518468896
L 02/12/2018 - 18:54:57: [debug.smx] Received: TestMsg.1518468897
L 02/12/2018 - 18:54:57: [debug.smx] Received: TestMsg.1518468897    <---- The plugin stopped here
Lugui: test
L 02/12/2018 - 18:55:05: "Lugui<3><[U:1:88621772]><Red>" say "test"
sm plugins reload debug
[SM] Plugin debug.smx reloaded successfully.
L 02/12/2018 - 18:55:44: [debug.smx] Received: TestMsg.1518468943 <--- worked only once
sm plugins reload debug
[SM] Plugin debug.smx reloaded successfully.
L 02/12/2018 - 18:56:14: "Lugui<3><[U:1:88621772]><Red>" disconnected (reason "Disconnect by user.") <-- I retryed to the server
Dropped Lugui from server (Disconnect by user.)
Server is hibernating
L 02/12/2018 - 18:56:14: "Lugui<4><[U:1:88621772]><>" connected, address "192.168.15.13:27005"
Client "Lugui" connected (192.168.15.13:27005).
Server waking up from hibernation
L 02/12/2018 - 18:56:14: "Lugui<4><[U:1:88621772]><>" STEAM USERID validated
L 02/12/2018 - 18:56:15: [SM] Unable to create db threader (error unknown)
L 02/12/2018 - 18:56:19: "Lugui<4><[U:1:88621772]><unknown>" spawned as "undefined"
sL 02/12/2018 - 18:56:19: "Lugui<4><[U:1:88621772]><>" entered the game
status
hostname: LUGUI - BRASIL || PRIVADO
version : 4294355/24 4294355 secure
udp/ip  : 192.168.15.12:26090  (public ip: 186.214.76.64)
steamid : [A:1:4211181574:9628] (90113348703717382)
account : not logged in  (No account specified)
map     : cp_sunshine at: 0 x, 0 y, 0 z
tags    : cp,increased_maxplayers,nocrits
sourcetv:  port 27027, delay 120.0s
players : 1 humans, 1 bots (33 max)
edicts  : 769 used of 2048 max
# userid name                uniqueid            connected ping loss state  adr
#      2 "LBR-TV"            BOT                                     active
#      4 "Lugui"             [U:1:88621772]      00:06       56   75 active 192.168.15.13:27005
L 02/12/2018 - 18:56:24: "Lugui<4><[U:1:88621772]><Unassigned>" joined team "Red"
L 02/12/2018 - 18:56:25: "Lugui<4><[U:1:88621772]><Red>" changed role to "pyro"
L 02/12/2018 - 18:56:25: "Lugui<4><[U:1:88621772]><Red>" spawned as "pyro"
L 02/12/2018 - 18:56:25: "Lugui<4><[U:1:88621772]><Red>" spawned as "pyro"
sm plugins reload debug
[SM] Plugin debug.smx reloaded successfully.
Out of memory or address space.  Texture quality setting may be too high.
Out of memory or address space.  Texture quality setting may be too high.

L 02/12/2018 - 18:56:32: Engine error: Out of memory or address space.  Texture quality setting may be too high.

Setting breakpad minidump AppID = 232251
Segmentation fault (core dumped)
Add "-debug" to the ./srcds_run command line to generate a debug.log to help with solving this problem
Seg Fev 12 18:56:32 -02 2018: Server restart in 10 seconds

if you want to talk about it or if you need help to make tests, add me on steam: http://steamcommunity.com/id/lugui1998/

Last edited by lugui; 02-12-2018 at 16:08.
lugui is offline
dordnung
Veteran Member
Join Date: Apr 2010
Old 02-12-2018 , 16:12   Re: [EXTENSION] System2 - Easy to use HTTP/FTP Request API and useful system natives
Reply With Quote #80

The only thing i can see is, that you forget to delete the request after using it:

so after

PHP Code:
httpRequest.GET(); 
you have to add:

PHP Code:
delete httpRequest
This could be the reason why you get a "Out of memory or address space"
__________________

Last edited by dordnung; 02-12-2018 at 16:16.
dordnung is offline
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

Forum Jump


All times are GMT -4. The time now is 20:09.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode