Compare commits

..

2 Commits

Author SHA1 Message Date
Tixx 176de6b5a5 Add BEAMMP_MAX_CONCURRENT_CONNECTIONS env var (#496)
By creating this pull request, I understand that code that is AI
generated or otherwise automatically generated may be rejected without
further discussion.
I declare that I fully understand all code I pushed into this PR, and
wrote all this code myself and own the rights to this code.
2026-06-27 21:29:10 +02:00
Tixx e33f47e838 Add BEAMMP_MAX_CONCURRENT_CONNECTIONS env var 2026-06-18 22:32:06 +02:00
15 changed files with 35 additions and 162 deletions
-2
View File
@@ -55,7 +55,6 @@ set(PRJ_HEADERS
include/ChronoWrapper.h include/ChronoWrapper.h
include/TConnectionLimiter.h include/TConnectionLimiter.h
include/TLuaResult.h include/TLuaResult.h
include/RegionHandler.h
) )
# add all source files (.cpp) to this, except the one with main() # add all source files (.cpp) to this, except the one with main()
set(PRJ_SOURCES set(PRJ_SOURCES
@@ -85,7 +84,6 @@ set(PRJ_SOURCES
src/ChronoWrapper.cpp src/ChronoWrapper.cpp
src/TConnectionLimiter.cpp src/TConnectionLimiter.cpp
src/TLuaResult.cpp src/TLuaResult.cpp
src/RegionHandler.cpp
) )
find_package(Lua REQUIRED) find_package(Lua REQUIRED)
+8 -6
View File
@@ -80,12 +80,16 @@ public:
static inline struct Settings Settings { }; static inline struct Settings Settings { };
static std::vector<std::string> GetBackendUrlsInOrder(); static std::vector<std::string> GetBackendUrlsInOrder() {
return {
"https://backend.beammp.com",
};
}
static std::string GetServerCheckUrl(); static std::string GetServerCheckUrl() { return "https://check.beammp.com"; }
static std::string GetBackendUrlForAuth(); static std::string GetBackendUrlForAuth() { return "https://auth.beammp.com"; }
static std::string GetBackendUrlForSocketIO(); static std::string GetBackendUrlForSocketIO() { return "https://backend.beammp.com"; }
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);
@@ -124,8 +128,6 @@ private:
static inline bool mShutdown { false }; static inline bool mShutdown { false };
static inline std::mutex mShutdownHandlersMutex {}; static inline std::mutex mShutdownHandlersMutex {};
static inline std::deque<TShutdownHandler> mShutdownHandlers {}; static inline std::deque<TShutdownHandler> mShutdownHandlers {};
static inline int mTLDIndex { 0 };
static inline std::vector<std::string> mValidTLDs {"beammp.com", "beammp.ru"};
static inline Version mVersion { 3, 9, 3 }; static inline Version mVersion { 3, 9, 3 };
}; };
+1
View File
@@ -23,6 +23,7 @@
namespace Env { namespace Env {
enum class Key { enum class Key {
MAX_CONCURRENT_CONNECTIONS,
// provider settings // provider settings
PROVIDER_UPDATE_MESSAGE, PROVIDER_UPDATE_MESSAGE,
PROVIDER_DISABLE_CONFIG, PROVIDER_DISABLE_CONFIG,
+2 -2
View File
@@ -39,8 +39,8 @@
namespace fs = std::filesystem; namespace fs = std::filesystem;
namespace Http { namespace Http {
std::string GET(std::string url, unsigned int* status = nullptr, const bool& redirect = true); std::string GET(const std::string& url, unsigned int* status = nullptr);
std::string POST(std::string url, const std::string& body, const std::string& ContentType, unsigned int* status = nullptr, const std::map<std::string, std::string>& headers = {}, const bool& redirect = true); std::string POST(const std::string& url, const std::string& body, const std::string& ContentType, unsigned int* status = nullptr, const std::map<std::string, std::string>& headers = {});
namespace Status { namespace Status {
std::string ToString(int code); std::string ToString(int code);
} }
-34
View File
@@ -1,34 +0,0 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <vector>
#include <string>
#include <array>
class RegionHandler final {
public:
RegionHandler() = delete;
static void TopLevelDomainFailed();
static std::string RegionToTopLevelDomain();
static std::string RedirectURL(const std::string &URL);
private:
static inline unsigned int mRegionIndex { 0 };
const static inline std::array<std::string, 2> mValidTLDs {"beammp.com", "beammp.ru"};
};
-1
View File
@@ -87,7 +87,6 @@ struct Settings {
General_Debug, General_Debug,
General_AllowGuests, General_AllowGuests,
General_InformationPacket, General_InformationPacket,
General_Region,
}; };
Sync<std::unordered_map<Key, SettingsTypeVariant>> SettingsMap; Sync<std::unordered_map<Key, SettingsTypeVariant>> SettingsMap;
-22
View File
@@ -35,7 +35,6 @@
#include "Compat.h" #include "Compat.h"
#include "CustomAssert.h" #include "CustomAssert.h"
#include "Http.h" #include "Http.h"
#include "RegionHandler.h"
void Application::RegisterShutdownHandler(const TShutdownHandler& Handler) { void Application::RegisterShutdownHandler(const TShutdownHandler& Handler) {
std::unique_lock Lock(mShutdownHandlersMutex); std::unique_lock Lock(mShutdownHandlersMutex);
@@ -74,27 +73,6 @@ std::string Application::ServerVersionString() {
return mVersion.AsString(); return mVersion.AsString();
} }
std::vector<std::string> Application::GetBackendUrlsInOrder() {
return {
"https://backend.beammp.com",
};
}
std::string Application::GetServerCheckUrl()
{
return "https://check.beammp.com";
}
std::string Application::GetBackendUrlForAuth()
{
return "https://auth.beammp.com";
}
std::string Application::GetBackendUrlForSocketIO()
{
return "https://backend.beammp.com";
}
std::array<uint8_t, 3> Application::VersionStrToInts(const std::string& str) { std::array<uint8_t, 3> Application::VersionStrToInts(const std::string& str) {
std::array<uint8_t, 3> Version; std::array<uint8_t, 3> Version;
std::stringstream ss(str); std::stringstream ss(str);
+3
View File
@@ -45,6 +45,9 @@ std::string_view Env::ToString(Env::Key key) {
case Key::PROVIDER_IP_ENV: case Key::PROVIDER_IP_ENV:
return "BEAMMP_PROVIDER_IP_ENV"; return "BEAMMP_PROVIDER_IP_ENV";
break; break;
case Key::MAX_CONCURRENT_CONNECTIONS:
return "BEAMMP_MAX_CONCURRENT_CONNECTIONS";
break;
} }
return ""; return "";
} }
+2 -11
View File
@@ -18,7 +18,6 @@
#include "Http.h" #include "Http.h"
#include "RegionHandler.h"
#include "Common.h" #include "Common.h"
#include "CustomAssert.h" #include "CustomAssert.h"
@@ -116,13 +115,10 @@ public:
} }
}; };
std::string Http::GET(std::string url, unsigned int* status, const bool& redirect) { std::string Http::GET(const std::string& url, unsigned int* status) {
std::string Ret; std::string Ret;
CurlLease Lease{}; CurlLease Lease{};
CURL* curl = Lease.GetHandle(); CURL* curl = Lease.GetHandle();
if (redirect) {
url = RegionHandler::RedirectURL(url);
}
if (curl) { if (curl) {
CURLcode res; CURLcode res;
char errbuf[CURL_ERROR_SIZE]; char errbuf[CURL_ERROR_SIZE];
@@ -146,7 +142,6 @@ std::string Http::GET(std::string url, unsigned int* status, const bool& redirec
if (res != CURLE_OK) { if (res != CURLE_OK) {
beammp_error("GET to " + url + " failed: " + std::string(curl_easy_strerror(res))); beammp_error("GET to " + url + " failed: " + std::string(curl_easy_strerror(res)));
beammp_error("Curl error: " + std::string(errbuf)); beammp_error("Curl error: " + std::string(errbuf));
RegionHandler::TopLevelDomainFailed();
return Http::ErrorString; return Http::ErrorString;
} }
@@ -161,13 +156,10 @@ std::string Http::GET(std::string url, unsigned int* status, const bool& redirec
return Ret; return Ret;
} }
std::string Http::POST(std::string url, const std::string& body, const std::string& ContentType, unsigned int* status, const std::map<std::string, std::string>& headers, const bool& redirect) { std::string Http::POST(const std::string& url, const std::string& body, const std::string& ContentType, unsigned int* status, const std::map<std::string, std::string>& headers) {
std::string Ret; std::string Ret;
CurlLease Lease{}; CurlLease Lease{};
CURL* curl = Lease.GetHandle(); CURL* curl = Lease.GetHandle();
if (redirect) {
url = RegionHandler::RedirectURL(url);
}
if (curl) { if (curl) {
CURLcode res; CURLcode res;
char errbuf[CURL_ERROR_SIZE]; char errbuf[CURL_ERROR_SIZE];
@@ -203,7 +195,6 @@ std::string Http::POST(std::string url, const std::string& body, const std::stri
if (res != CURLE_OK) { if (res != CURLE_OK) {
beammp_error("POST to " + url + " failed: " + std::string(curl_easy_strerror(res))); beammp_error("POST to " + url + " failed: " + std::string(curl_easy_strerror(res)));
beammp_error("Curl error: " + std::string(errbuf)); beammp_error("Curl error: " + std::string(errbuf));
RegionHandler::TopLevelDomainFailed();
return Http::ErrorString; return Http::ErrorString;
} }
-53
View File
@@ -1,53 +0,0 @@
// BeamMP, the BeamNG.drive multiplayer mod.
// Copyright (C) 2024 BeamMP Ltd., BeamMP team and contributors.
//
// BeamMP Ltd. can be contacted by electronic mail via contact@beammp.com.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "RegionHandler.h"
#include "Common.h"
#include <regex>
void RegionHandler::TopLevelDomainFailed()
{
static bool isDeveloperRegion = Application::Settings.getAsString(Settings::Key::General_Region) == "Developer";
if (!isDeveloperRegion) {
beammp_info("Top level domain of " + mValidTLDs[mRegionIndex % mValidTLDs.size()] + " didn't respond correctly , changing domain to " + mValidTLDs[(mRegionIndex + 1) % mValidTLDs.size()]);
}
mRegionIndex++;
}
std::string RegionHandler::RegionToTopLevelDomain()
{
static bool isDeveloperRegion = Application::Settings.getAsString(Settings::Key::General_Region) == "Developer";
if (isDeveloperRegion) {
return "beammp.dev";
}
return mValidTLDs[mRegionIndex % mValidTLDs.size()]; // Global
}
std::string RegionHandler::RedirectURL(const std::string &URL)
{
std::regex link_pattern(R"(^(https:\/\/.*)beammp\.com(\/.*)?$)");
std::smatch link_match;
if (std::regex_search(URL, link_match, link_pattern) && link_match.position() == 0) {
//TLD matched beammp.com
std::string before = link_match[1].str(); // "https://..." up to beammp
std::string after = link_match[2].matched ? link_match[2].str() : ""; // "/path" or ""
return before + RegionToTopLevelDomain() + after;
}
return URL; //if it didn't match, just return the unmodified URL
}
-2
View File
@@ -36,7 +36,6 @@ Settings::Settings() {
{ General_Debug, false }, { General_Debug, false },
{ General_AllowGuests, true }, { General_AllowGuests, true },
{ General_InformationPacket, true }, { General_InformationPacket, true },
{ General_Region, std::string("")},
{ Misc_ImScaredOfUpdates, true }, { Misc_ImScaredOfUpdates, true },
{ Misc_UpdateReminderTime, "30s" } { Misc_UpdateReminderTime, "30s" }
}; };
@@ -57,7 +56,6 @@ Settings::Settings() {
{ { "General", "Debug" }, { General_Debug, READ_WRITE } }, { { "General", "Debug" }, { General_Debug, READ_WRITE } },
{ { "General", "AllowGuests" }, { General_AllowGuests, READ_WRITE } }, { { "General", "AllowGuests" }, { General_AllowGuests, READ_WRITE } },
{ { "General", "InformationPacket" }, { General_InformationPacket, READ_WRITE } }, { { "General", "InformationPacket" }, { General_InformationPacket, READ_WRITE } },
{ { "General", "Region" }, { General_Region, READ_WRITE } },
{ { "Misc", "ImScaredOfUpdates" }, { Misc_ImScaredOfUpdates, READ_WRITE } }, { { "Misc", "ImScaredOfUpdates" }, { Misc_ImScaredOfUpdates, READ_WRITE } },
{ { "Misc", "UpdateReminderTime" }, { Misc_UpdateReminderTime, READ_WRITE } } { { "Misc", "UpdateReminderTime" }, { Misc_UpdateReminderTime, READ_WRITE } }
}; };
-13
View File
@@ -52,8 +52,6 @@ static constexpr std::string_view StrTags = "Tags";
static constexpr std::string_view EnvStrTags = "BEAMMP_TAGS"; static constexpr std::string_view EnvStrTags = "BEAMMP_TAGS";
static constexpr std::string_view StrResourceFolder = "ResourceFolder"; static constexpr std::string_view StrResourceFolder = "ResourceFolder";
static constexpr std::string_view EnvStrResourceFolder = "BEAMMP_RESOURCE_FOLDER"; static constexpr std::string_view EnvStrResourceFolder = "BEAMMP_RESOURCE_FOLDER";
static constexpr std::string_view StrRegion = "BackendRegion";
static constexpr std::string_view EnvStrRegion = "BEAMMP_BACKEND_REGION";
static constexpr std::string_view StrAuthKey = "AuthKey"; static constexpr std::string_view StrAuthKey = "AuthKey";
static constexpr std::string_view EnvStrAuthKey = "BEAMMP_AUTH_KEY"; static constexpr std::string_view EnvStrAuthKey = "BEAMMP_AUTH_KEY";
static constexpr std::string_view StrLogChat = "LogChat"; static constexpr std::string_view StrLogChat = "LogChat";
@@ -153,9 +151,6 @@ void TConfig::FlushToFile() {
data["General"][StrMap.data()] = Application::Settings.getAsString(Settings::Key::General_Map); data["General"][StrMap.data()] = Application::Settings.getAsString(Settings::Key::General_Map);
data["General"][StrDescription.data()] = Application::Settings.getAsString(Settings::Key::General_Description); data["General"][StrDescription.data()] = Application::Settings.getAsString(Settings::Key::General_Description);
data["General"][StrResourceFolder.data()] = Application::Settings.getAsString(Settings::Key::General_ResourceFolder); data["General"][StrResourceFolder.data()] = Application::Settings.getAsString(Settings::Key::General_ResourceFolder);
if (Application::Settings.getAsString(Settings::Key::General_Region) != "") {
data["General"][StrRegion.data()] = Application::Settings.getAsString(Settings::Key::General_Region);
}
// data["General"][StrPassword.data()] = Application::Settings.Password; // data["General"][StrPassword.data()] = Application::Settings.Password;
// SetComment(data["General"][StrPassword.data()].comments(), " Sets a password on this server, which restricts people from joining. To join, a player must enter this exact password. Leave empty ("") to disable the password."); // SetComment(data["General"][StrPassword.data()].comments(), " Sets a password on this server, which restricts people from joining. To join, a player must enter this exact password. Leave empty ("") to disable the password.");
// Misc // Misc
@@ -226,22 +221,16 @@ 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 {
@@ -281,7 +270,6 @@ void TConfig::ParseFromFile(std::string_view name) {
TryReadValue(data, "General", StrDescription, EnvStrDescription, Settings::Key::General_Description); TryReadValue(data, "General", StrDescription, EnvStrDescription, Settings::Key::General_Description);
TryReadValue(data, "General", StrTags, EnvStrTags, Settings::Key::General_Tags); TryReadValue(data, "General", StrTags, EnvStrTags, Settings::Key::General_Tags);
TryReadValue(data, "General", StrResourceFolder, EnvStrResourceFolder, Settings::Key::General_ResourceFolder); TryReadValue(data, "General", StrResourceFolder, EnvStrResourceFolder, Settings::Key::General_ResourceFolder);
TryReadValue(data, "General", StrRegion, EnvStrRegion, Settings::Key::General_Region);
TryReadValue(data, "General", StrAuthKey, EnvStrAuthKey, Settings::Key::General_AuthKey); TryReadValue(data, "General", StrAuthKey, EnvStrAuthKey, Settings::Key::General_AuthKey);
TryReadValue(data, "General", StrLogChat, EnvStrLogChat, Settings::Key::General_LogChat); TryReadValue(data, "General", StrLogChat, EnvStrLogChat, Settings::Key::General_LogChat);
TryReadValue(data, "General", StrAllowGuests, EnvStrAllowGuests, Settings::Key::General_AllowGuests); TryReadValue(data, "General", StrAllowGuests, EnvStrAllowGuests, Settings::Key::General_AllowGuests);
@@ -334,7 +322,6 @@ void TConfig::PrintDebug() {
beammp_debug(std::string(StrTags) + ": " + TagsAsPrettyArray()); beammp_debug(std::string(StrTags) + ": " + TagsAsPrettyArray());
beammp_debug(std::string(StrLogChat) + ": \"" + (Application::Settings.getAsBool(Settings::Key::General_LogChat) ? "true" : "false") + "\""); beammp_debug(std::string(StrLogChat) + ": \"" + (Application::Settings.getAsBool(Settings::Key::General_LogChat) ? "true" : "false") + "\"");
beammp_debug(std::string(StrResourceFolder) + ": \"" + Application::Settings.getAsString(Settings::Key::General_ResourceFolder) + "\""); beammp_debug(std::string(StrResourceFolder) + ": \"" + Application::Settings.getAsString(Settings::Key::General_ResourceFolder) + "\"");
beammp_debug(std::string(StrRegion) + ": \"" + Application::Settings.getAsString(Settings::Key::General_Region) + "\"");
beammp_debug(std::string(StrAllowGuests) + ": \"" + (Application::Settings.getAsBool(Settings::Key::General_AllowGuests) ? "true" : "false") + "\""); beammp_debug(std::string(StrAllowGuests) + ": \"" + (Application::Settings.getAsBool(Settings::Key::General_AllowGuests) ? "true" : "false") + "\"");
// special! // special!
beammp_debug("Key Length: " + std::to_string(Application::Settings.getAsString(Settings::Key::General_AuthKey).length()) + ""); beammp_debug("Key Length: " + std::to_string(Application::Settings.getAsString(Settings::Key::General_AuthKey).length()) + "");
-5
View File
@@ -25,7 +25,6 @@
#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,10 +297,6 @@ 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) {
RegionHandler::TopLevelDomainFailed();
T = Http::GET(Application::GetServerCheckUrl() + "/api/v2/beammp/" + std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port)), &status);
}
beammp_debugf("Status and response from Server Check API: {0}, {1}", status, T); beammp_debugf("Status and response from Server Check API: {0}, {1}", status, T);
+1 -5
View File
@@ -22,9 +22,9 @@
#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>
#include <sstream>
void THeartbeatThread::operator()() { void THeartbeatThread::operator()() {
RegisterThread("Heartbeat"); RegisterThread("Heartbeat");
@@ -63,10 +63,6 @@ void THeartbeatThread::operator()() {
bool Ok = false; bool Ok = false;
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) {
RegionHandler::TopLevelDomainFailed();
T = Http::POST(Url + Target, Body, "application/json", &ResponseCode, { { "api-v", "2" } });
}
if (!Application::Settings.getAsBool(Settings::Key::General_Private)) { if (!Application::Settings.getAsBool(Settings::Key::General_Private)) {
beammp_debug("Backend response was: `" + T + "`"); beammp_debug("Backend response was: `" + T + "`");
+18 -6
View File
@@ -19,8 +19,8 @@
#include "TNetwork.h" #include "TNetwork.h"
#include "Client.h" #include "Client.h"
#include "Common.h" #include "Common.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"
@@ -46,8 +46,24 @@
typedef boost::asio::detail::socket_option::integer<SOL_SOCKET, SO_RCVTIMEO> rcv_timeout_option; typedef boost::asio::detail::socket_option::integer<SOL_SOCKET, SO_RCVTIMEO> rcv_timeout_option;
static constexpr uint8_t MAX_CONCURRENT_CONNECTIONS = 10;
static constexpr uint8_t MAX_GLOBAL_CONNECTIONS = 128; static constexpr uint8_t MAX_GLOBAL_CONNECTIONS = 128;
static const uint8_t MAX_CONCURRENT_CONNECTIONS = []() -> uint8_t {
if (auto EnvVar = Env::Get(Env::Key::MAX_CONCURRENT_CONNECTIONS)) {
try {
beammp_debugf("BEAMMP_MAX_CONCURRENT_CONNECTIONS: {}", EnvVar.value());
if (const int value = std::stoi(std::string(EnvVar.value())); value > 0 && value <= MAX_GLOBAL_CONNECTIONS) {
beammp_debugf("BEAMMP_MAX_CONCURRENT_CONNECTIONS Parsed: {}", value);
return static_cast<uint8_t>(value);
}
beammp_warn("Env variable BEAMMP_MAX_CONCURRENT_CONNECTIONS is out of range, using default value.");
} catch (const std::exception&) {
beammp_warn("Error parsing Env variable BEAMMP_MAX_CONCURRENT_CONNECTIONS, using default value.");
}
}
return 10;
}();
static constexpr uint8_t READ_TIMEOUT_S = 10; // seconds static constexpr uint8_t READ_TIMEOUT_S = 10; // seconds
std::vector<uint8_t> StringToVector(const std::string& Str) { std::vector<uint8_t> StringToVector(const std::string& Str) {
@@ -441,10 +457,6 @@ 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) {
RegionHandler::TopLevelDomainFailed();
AuthResStr = Http::POST(Application::GetBackendUrlForAuth() + Target, AuthReq.dump(), "application/json", &ResponseCode);
}
} catch (const std::exception& e) { } catch (const std::exception& e) {
beammp_debugf("Invalid json sent by client, kicking: {}", e.what()); beammp_debugf("Invalid json sent by client, kicking: {}", e.what());