mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-02 07:45:26 +00:00
Move backend heartbeat to json
This commit is contained in:
parent
4abe9b8636
commit
54e31ce2ec
@ -25,6 +25,7 @@
|
|||||||
// #include "SocketIO.h"
|
// #include "SocketIO.h"
|
||||||
#include <rapidjson/document.h>
|
#include <rapidjson/document.h>
|
||||||
#include <rapidjson/rapidjson.h>
|
#include <rapidjson/rapidjson.h>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace json = rapidjson;
|
namespace json = rapidjson;
|
||||||
@ -65,7 +66,7 @@ void THeartbeatThread::operator()() {
|
|||||||
json::Document Doc;
|
json::Document Doc;
|
||||||
bool Ok = false;
|
bool Ok = false;
|
||||||
for (const auto& Url : Application::GetBackendUrlsInOrder()) {
|
for (const auto& Url : Application::GetBackendUrlsInOrder()) {
|
||||||
T = Http::POST(Url, 443, Target, Body, "application/x-www-form-urlencoded", &ResponseCode, { { "api-v", "2" } });
|
T = Http::POST(Url, 443, Target, Body, "application/json", &ResponseCode, { { "api-v", "2" } });
|
||||||
Doc.Parse(T.data(), T.size());
|
Doc.Parse(T.data(), T.size());
|
||||||
if (Doc.HasParseError() || !Doc.IsObject()) {
|
if (Doc.HasParseError() || !Doc.IsObject()) {
|
||||||
if (!Application::Settings.getAsBool(Settings::Key::General_Private)) {
|
if (!Application::Settings.getAsBool(Settings::Key::General_Private)) {
|
||||||
@ -138,26 +139,29 @@ void THeartbeatThread::operator()() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string THeartbeatThread::GenerateCall() {
|
std::string THeartbeatThread::GenerateCall() {
|
||||||
std::stringstream Ret;
|
nlohmann::json Ret = {
|
||||||
|
{"players", mServer.ClientCount()},
|
||||||
|
{"maxplayers", Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)},
|
||||||
|
{"port", Application::Settings.getAsInt(Settings::Key::General_Port)},
|
||||||
|
{"map", Application::Settings.getAsString(Settings::Key::General_Map)},
|
||||||
|
{"private", Application::Settings.getAsBool(Settings::Key::General_Private)},
|
||||||
|
{"version", Application::ServerVersionString()},
|
||||||
|
{"clientversion", Application::ClientMinimumVersion().AsString()},
|
||||||
|
{"name", Application::Settings.getAsString(Settings::Key::General_Name)},
|
||||||
|
{"tags", Application::Settings.getAsString(Settings::Key::General_Tags)},
|
||||||
|
{"guests", Application::Settings.getAsBool(Settings::Key::General_AllowGuests)},
|
||||||
|
{"modlist", mResourceManager.TrimmedList()},
|
||||||
|
{"modstotalsize", mResourceManager.MaxModSize()},
|
||||||
|
{"modstotal", mResourceManager.ModsLoaded()},
|
||||||
|
{"playerslist", GetPlayers()},
|
||||||
|
{"desc", Application::Settings.getAsString(Settings::Key::General_Description)}
|
||||||
|
};
|
||||||
|
|
||||||
Ret << "players=" << mServer.ClientCount()
|
lastCall = Ret.dump();
|
||||||
<< "&maxplayers=" << Application::Settings.getAsInt(Settings::Key::General_MaxPlayers)
|
|
||||||
<< "&port=" << Application::Settings.getAsInt(Settings::Key::General_Port)
|
Ret["uuid"] = Application::Settings.getAsString(Settings::Key::General_AuthKey);
|
||||||
<< "&map=" << Application::Settings.getAsString(Settings::Key::General_Map)
|
|
||||||
<< "&private=" << (Application::Settings.getAsBool(Settings::Key::General_Private) ? "true" : "false")
|
return Ret.dump();
|
||||||
<< "&version=" << Application::ServerVersionString()
|
|
||||||
<< "&clientversion=" << Application::ClientMinimumVersion().AsString()
|
|
||||||
<< "&name=" << Application::Settings.getAsString(Settings::Key::General_Name)
|
|
||||||
<< "&tags=" << Application::Settings.getAsString(Settings::Key::General_Tags)
|
|
||||||
<< "&guests=" << (Application::Settings.getAsBool(Settings::Key::General_AllowGuests) ? "true" : "false")
|
|
||||||
<< "&modlist=" << mResourceManager.TrimmedList()
|
|
||||||
<< "&modstotalsize=" << mResourceManager.MaxModSize()
|
|
||||||
<< "&modstotal=" << mResourceManager.ModsLoaded()
|
|
||||||
<< "&playerslist=" << GetPlayers()
|
|
||||||
<< "&desc=" << Application::Settings.getAsString(Settings::Key::General_Description);
|
|
||||||
lastCall = Ret.str();
|
|
||||||
Ret << "&uuid=" << Application::Settings.getAsString(Settings::Key::General_AuthKey);
|
|
||||||
return Ret.str();
|
|
||||||
}
|
}
|
||||||
THeartbeatThread::THeartbeatThread(TResourceManager& ResourceManager, TServer& Server)
|
THeartbeatThread::THeartbeatThread(TResourceManager& ResourceManager, TServer& Server)
|
||||||
: mResourceManager(ResourceManager)
|
: mResourceManager(ResourceManager)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user