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/