mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-07-13 18:24:16 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dad469f800 | |||
| c3012fcee7 | |||
| 7250137935 | |||
| fa3cf9f5a7 | |||
| eed8326deb | |||
| 90c3aac0bc | |||
| 7a25377d4e | |||
| f4900189c0 |
+20
-65
@@ -3,12 +3,8 @@
|
|||||||
#include "Client.h"
|
#include "Client.h"
|
||||||
#include "Http.h"
|
#include "Http.h"
|
||||||
//#include "SocketIO.h"
|
//#include "SocketIO.h"
|
||||||
#include <rapidjson/document.h>
|
|
||||||
#include <rapidjson/rapidjson.h>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace json = rapidjson;
|
|
||||||
|
|
||||||
void THeartbeatThread::operator()() {
|
void THeartbeatThread::operator()() {
|
||||||
RegisterThread("Heartbeat");
|
RegisterThread("Heartbeat");
|
||||||
std::string Body;
|
std::string Body;
|
||||||
@@ -45,83 +41,42 @@ void THeartbeatThread::operator()() {
|
|||||||
{ { "response-body", T },
|
{ { "response-body", T },
|
||||||
{ "request-body", Body } });
|
{ "request-body", Body } });
|
||||||
Sentry.SetTransaction(transaction);
|
Sentry.SetTransaction(transaction);
|
||||||
|
trace("sending log to sentry: " + std::to_string(status) + " for " + transaction);
|
||||||
Sentry.Log(SentryLevel::Error, "default", Http::Status::ToString(status) + " (" + std::to_string(status) + ")");
|
Sentry.Log(SentryLevel::Error, "default", Http::Status::ToString(status) + " (" + std::to_string(status) + ")");
|
||||||
};
|
};
|
||||||
|
|
||||||
auto Target = "/heartbeat";
|
auto Target = "/heartbeat";
|
||||||
int ResponseCode = -1;
|
int ResponseCode = -1;
|
||||||
const std::vector<std::string> Urls = {
|
T = Http::POST(Application::GetBackendHostname(), Target, {}, Body, false, &ResponseCode);
|
||||||
Application::GetBackendHostname(),
|
|
||||||
Application::GetBackup1Hostname(),
|
|
||||||
Application::GetBackup2Hostname(),
|
|
||||||
};
|
|
||||||
|
|
||||||
json::Document Doc;
|
if ((T.substr(0, 2) != "20" && ResponseCode != 200) || ResponseCode != 200) {
|
||||||
bool Ok = false;
|
trace("got " + T + " from backend");
|
||||||
for (const auto& Url : Urls) {
|
SentryReportError(Application::GetBackendHostname() + Target, ResponseCode);
|
||||||
T = Http::POST(Url, Target, { { "api-v", "2" } }, Body, false, &ResponseCode);
|
|
||||||
trace(T);
|
|
||||||
Doc.Parse(T.data(), T.size());
|
|
||||||
if (Doc.HasParseError() || !Doc.IsObject()) {
|
|
||||||
error("Backend response failed to parse as valid json");
|
|
||||||
debug("Response was: `" + T + "`");
|
|
||||||
Sentry.SetContext("JSON Response", { { "reponse", T } });
|
|
||||||
SentryReportError(Url + Target, ResponseCode);
|
|
||||||
} else if (ResponseCode != 200) {
|
|
||||||
SentryReportError(Url + Target, ResponseCode);
|
|
||||||
} else {
|
|
||||||
// all ok
|
|
||||||
Ok = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
}
|
T = Http::POST(Application::GetBackup1Hostname(), Target, {}, Body, false, &ResponseCode);
|
||||||
std::string Status {};
|
if ((T.substr(0, 2) != "20" && ResponseCode != 200) || ResponseCode != 200) {
|
||||||
std::string Code {};
|
SentryReportError(Application::GetBackup1Hostname() + Target, ResponseCode);
|
||||||
std::string Message {};
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
const auto StatusKey = "status";
|
T = Http::POST(Application::GetBackup2Hostname(), Target, {}, Body, false, &ResponseCode);
|
||||||
const auto CodeKey = "code";
|
if ((T.substr(0, 2) != "20" && ResponseCode != 200) || ResponseCode != 200) {
|
||||||
const auto MessageKey = "msg";
|
warn("Backend system refused server! Server will not show in the public server list.");
|
||||||
|
isAuth = false;
|
||||||
if (Ok) {
|
SentryReportError(Application::GetBackup2Hostname() + Target, ResponseCode);
|
||||||
if (Doc.HasMember(StatusKey) && Doc[StatusKey].IsString()) {
|
}
|
||||||
Status = Doc[StatusKey].GetString();
|
|
||||||
} else {
|
|
||||||
Sentry.SetContext("JSON Response", { { StatusKey, "invalid string / missing" } });
|
|
||||||
Ok = false;
|
|
||||||
}
|
|
||||||
if (Doc.HasMember(CodeKey) && Doc[CodeKey].IsString()) {
|
|
||||||
Code = Doc[CodeKey].GetString();
|
|
||||||
} else {
|
|
||||||
Sentry.SetContext("JSON Response", { { CodeKey, "invalid string / missing" } });
|
|
||||||
Ok = false;
|
|
||||||
}
|
|
||||||
if (Doc.HasMember(MessageKey) && Doc[MessageKey].IsString()) {
|
|
||||||
Message = Doc[MessageKey].GetString();
|
|
||||||
} else {
|
|
||||||
Sentry.SetContext("JSON Response", { { MessageKey, "invalid string / missing" } });
|
|
||||||
Ok = false;
|
|
||||||
}
|
|
||||||
if (!Ok) {
|
|
||||||
error("Missing/invalid json members in backend response");
|
|
||||||
Sentry.LogError("Missing/invalid json members in backend response", __FILE__, std::to_string(__LINE__));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ok && !isAuth) {
|
if (!isAuth) {
|
||||||
if (Status == "2000") {
|
if (T == "2000") {
|
||||||
info(("Authenticated!"));
|
info(("Authenticated!"));
|
||||||
isAuth = true;
|
isAuth = true;
|
||||||
} else if (Status == "200") {
|
} else if (T == "200") {
|
||||||
info(("Resumed authenticated session!"));
|
info(("Resumed authenticated session!"));
|
||||||
isAuth = true;
|
isAuth = true;
|
||||||
} else {
|
|
||||||
if (Message.empty()) {
|
|
||||||
Message = "Backend didn't provide a reason";
|
|
||||||
}
|
|
||||||
error("Backend REFUSED the auth key. " + Message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SocketIO::Get().SetAuthenticated(isAuth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,16 +54,6 @@ int main(int argc, char** argv) try {
|
|||||||
Application::Console().InitializeLuaConsole(LuaEngine);
|
Application::Console().InitializeLuaConsole(LuaEngine);
|
||||||
Application::CheckForUpdates();
|
Application::CheckForUpdates();
|
||||||
|
|
||||||
Sentry.LogError("test error", __FILE__, std::to_string(__LINE__));
|
|
||||||
|
|
||||||
error("goodbye, crashing now");
|
|
||||||
volatile int* a = nullptr;
|
|
||||||
// oh boy
|
|
||||||
*a = -0;
|
|
||||||
a[318008]++;
|
|
||||||
// bye now
|
|
||||||
abort();
|
|
||||||
|
|
||||||
// TODO: replace
|
// TODO: replace
|
||||||
while (!Shutdown) {
|
while (!Shutdown) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
|
|||||||
Reference in New Issue
Block a user