mirror of
https://github.com/SantaSpeen/BeamMP-Server.git
synced 2026-06-17 06:50:53 +00:00
fixed debug output, server exit hang, crashes
This commit is contained in:
+3
-3
@@ -87,7 +87,7 @@ void LoadConfig(std::ifstream& IFS){
|
||||
if(index-1 < 11){
|
||||
error(Sec("Outdated/Incorrect config please remove it server will close in 5 secs"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
exit(0);
|
||||
_Exit(0);
|
||||
}
|
||||
IFS.close();
|
||||
IFS.open(Sec("Server.cfg"));
|
||||
@@ -122,7 +122,7 @@ void Default(){
|
||||
GenerateConfig();
|
||||
warn(Sec("You are required to input the AuthKey"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
exit(0);
|
||||
_Exit(0);
|
||||
}
|
||||
void DebugData(){
|
||||
debug(std::string(Sec("Debug : ")) + (Debug?"true":"false"));
|
||||
@@ -145,7 +145,7 @@ void InitConfig(){
|
||||
if(Key.empty()){
|
||||
error(Sec("No AuthKey was found"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
exit(0);
|
||||
_Exit(0);
|
||||
}
|
||||
if(Debug)DebugData();
|
||||
}
|
||||
|
||||
+16
-4
@@ -8,6 +8,7 @@
|
||||
#include "Logger.h"
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <future>
|
||||
|
||||
void WebsocketInit();
|
||||
std::string GetPlayers(){
|
||||
@@ -29,6 +30,18 @@ std::string GenerateCall(){
|
||||
+"&playerslist="+GetPlayers()+"&desc="+ServerDesc;
|
||||
return ret;
|
||||
}
|
||||
std::string RunPromise(const std::string& IP, const std::string& R) {
|
||||
std::packaged_task<std::string()> task([&]() { return PostHTTP(IP,R); });
|
||||
std::future<std::string> f1 = task.get_future();
|
||||
std::thread t(std::move(task));
|
||||
t.detach();
|
||||
auto status = f1.wait_for(std::chrono::seconds(10));
|
||||
if (status != std::future_status::timeout)return f1.get();
|
||||
error(Sec("Backend system Timeout please try again later"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
_Exit(0);
|
||||
}
|
||||
|
||||
void Heartbeat(){
|
||||
DebugPrintTID();
|
||||
std::string R,T;
|
||||
@@ -37,17 +50,16 @@ void Heartbeat(){
|
||||
R = GenerateCall();
|
||||
if(!CustomIP.empty())R+="&ip="+CustomIP;
|
||||
std::string link = Sec("https://beammp.com/heartbeatv2");
|
||||
T = PostHTTP(link,R);
|
||||
|
||||
T = RunPromise(link,R);
|
||||
if(T.find_first_not_of(Sec("20")) != std::string::npos){
|
||||
//Backend system refused server startup!
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
std::string Backup = Sec("https://backup1.beammp.com/heartbeatv2");
|
||||
T = PostHTTP(Backup,R);
|
||||
T = RunPromise(Backup,R);
|
||||
if(T.find_first_not_of(Sec("20")) != std::string::npos) {
|
||||
error(Sec("Backend system refused server! Check your AuthKey"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
exit(-1);
|
||||
_Exit(-1);
|
||||
}
|
||||
}
|
||||
//Server Authenticated
|
||||
|
||||
Reference in New Issue
Block a user