Fix unexpected type for backend region

This commit is contained in:
SaltySnail
2026-07-04 19:38:07 +02:00
parent 569d46769a
commit 75d844d5a6
5 changed files with 12 additions and 5 deletions
-2
View File
@@ -86,8 +86,6 @@ public:
static std::string GetBackendUrlForAuth(); static std::string GetBackendUrlForAuth();
static std::string GetBackendUrlForSocketIO(); static std::string GetBackendUrlForSocketIO();
static void TopLevelDomainFailed(bool failed);
static std::string RegionToTopLevelDomain(const std::string region);
static void CheckForUpdates(); static void CheckForUpdates();
static std::array<uint8_t, 3> VersionStrToInts(const std::string& str); static std::array<uint8_t, 3> VersionStrToInts(const std::string& str);
static bool IsOutdated(const Version& Current, const Version& Newest); static bool IsOutdated(const Version& Current, const Version& Newest);
+6
View File
@@ -226,16 +226,22 @@ void TConfig::TryReadValue(toml::value& Table, const std::string& Category, cons
if constexpr (std::is_same_v<T, std::string>) { if constexpr (std::is_same_v<T, std::string>) {
if (Table[Category.c_str()][Key.data()].is_string()) if (Table[Category.c_str()][Key.data()].is_string())
Application::Settings.set(key, Table[Category.c_str()][Key.data()].as_string()); Application::Settings.set(key, Table[Category.c_str()][Key.data()].as_string());
else if (Table[Category.c_str()][Key.data()].is_empty())
beammp_debugf("Value '{}.{}' is empty", Category, Key);
else else
beammp_warnf("Value '{}.{}' has unexpected type, expected type 'string'", Category, Key); beammp_warnf("Value '{}.{}' has unexpected type, expected type 'string'", Category, Key);
} else if constexpr (std::is_same_v<T, int>) { } else if constexpr (std::is_same_v<T, int>) {
if (Table[Category.c_str()][Key.data()].is_integer()) if (Table[Category.c_str()][Key.data()].is_integer())
Application::Settings.set(key, int(Table[Category.c_str()][Key.data()].as_integer())); Application::Settings.set(key, int(Table[Category.c_str()][Key.data()].as_integer()));
else if (Table[Category.c_str()][Key.data()].is_empty())
beammp_debugf("Value '{}.{}' is empty", Category, Key);
else else
beammp_warnf("Value '{}.{}' has unexpected type, expected type 'integer'", Category, Key); beammp_warnf("Value '{}.{}' has unexpected type, expected type 'integer'", Category, Key);
} else if constexpr (std::is_same_v<T, bool>) { } else if constexpr (std::is_same_v<T, bool>) {
if (Table[Category.c_str()][Key.data()].is_boolean()) if (Table[Category.c_str()][Key.data()].is_boolean())
Application::Settings.set(key, Table[Category.c_str()][Key.data()].as_boolean()); Application::Settings.set(key, Table[Category.c_str()][Key.data()].as_boolean());
else if (Table[Category.c_str()][Key.data()].is_empty())
beammp_debugf("Value '{}.{}' is empty", Category, Key);
else else
beammp_warnf("Value '{}.{}' has unexpected type, expected type 'boolean'", Category, Key); beammp_warnf("Value '{}.{}' has unexpected type, expected type 'boolean'", Category, Key);
} else { } else {
+2 -1
View File
@@ -25,6 +25,7 @@
#include "Http.h" #include "Http.h"
#include "LuaAPI.h" #include "LuaAPI.h"
#include "TLuaEngine.h" #include "TLuaEngine.h"
#include "RegionHandler.h"
#include <ctime> #include <ctime>
#include <lua.hpp> #include <lua.hpp>
@@ -298,7 +299,7 @@ void TConsole::Command_NetTest(const std::string& cmd, const std::vector<std::st
std::string T = Http::GET( std::string T = Http::GET(
Application::GetServerCheckUrl() + "/api/v2/beammp/" + std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port)), &status); Application::GetServerCheckUrl() + "/api/v2/beammp/" + std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port)), &status);
if (T == Http::ErrorString || status != 200) { if (T == Http::ErrorString || status != 200) {
Application::TopLevelDomainFailed(); RegionHandler::TopLevelDomainFailed();
T = Http::GET(Application::GetServerCheckUrl() + "/api/v2/beammp/" + std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port)), &status); T = Http::GET(Application::GetServerCheckUrl() + "/api/v2/beammp/" + std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port)), &status);
} }
+2 -1
View File
@@ -22,6 +22,7 @@
#include "Client.h" #include "Client.h"
#include "Common.h" #include "Common.h"
#include "Http.h" #include "Http.h"
#include "RegionHandler.h"
// #include "SocketIO.h" // #include "SocketIO.h"
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@@ -63,7 +64,7 @@ void THeartbeatThread::operator()() {
for (const auto& Url : Application::GetBackendUrlsInOrder()) { for (const auto& Url : Application::GetBackendUrlsInOrder()) {
T = Http::POST(Url + Target, Body, "application/json", &ResponseCode, { { "api-v", "2" } }); T = Http::POST(Url + Target, Body, "application/json", &ResponseCode, { { "api-v", "2" } });
if (T == Http::ErrorString || ResponseCode != 200) { if (T == Http::ErrorString || ResponseCode != 200) {
Application::TopLevelDomainFailed(); RegionHandler::TopLevelDomainFailed();
T = Http::POST(Url + Target, Body, "application/json", &ResponseCode, { { "api-v", "2" } }); T = Http::POST(Url + Target, Body, "application/json", &ResponseCode, { { "api-v", "2" } });
} }
+2 -1
View File
@@ -21,6 +21,7 @@
#include "Common.h" #include "Common.h"
#include "Env.h" #include "Env.h"
#include "LuaAPI.h" #include "LuaAPI.h"
#include "RegionHandler.h"
#include "TConnectionLimiter.h" #include "TConnectionLimiter.h"
#include "THeartbeatThread.h" #include "THeartbeatThread.h"
#include "TLuaEngine.h" #include "TLuaEngine.h"
@@ -458,7 +459,7 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
unsigned int ResponseCode = 0; unsigned int ResponseCode = 0;
AuthResStr = Http::POST(Application::GetBackendUrlForAuth() + Target, AuthReq.dump(), "application/json", &ResponseCode); AuthResStr = Http::POST(Application::GetBackendUrlForAuth() + Target, AuthReq.dump(), "application/json", &ResponseCode);
if (AuthResStr == Http::ErrorString || ResponseCode != 200) { if (AuthResStr == Http::ErrorString || ResponseCode != 200) {
Application::TopLevelDomainFailed(); RegionHandler::TopLevelDomainFailed();
AuthResStr = Http::POST(Application::GetBackendUrlForAuth() + Target, AuthReq.dump(), "application/json", &ResponseCode); AuthResStr = Http::POST(Application::GetBackendUrlForAuth() + Target, AuthReq.dump(), "application/json", &ResponseCode);
} }