From e33f47e83804ff6f0c09e0b5139215cb6ed019c3 Mon Sep 17 00:00:00 2001 From: Tixx <83774803+WiserTixx@users.noreply.github.com> Date: Thu, 18 Jun 2026 22:32:06 +0200 Subject: [PATCH] Add BEAMMP_MAX_CONCURRENT_CONNECTIONS env var --- include/Env.h | 1 + src/Env.cpp | 3 +++ src/TNetwork.cpp | 19 ++++++++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/Env.h b/include/Env.h index 93a38ba..78eed96 100644 --- a/include/Env.h +++ b/include/Env.h @@ -23,6 +23,7 @@ namespace Env { enum class Key { + MAX_CONCURRENT_CONNECTIONS, // provider settings PROVIDER_UPDATE_MESSAGE, PROVIDER_DISABLE_CONFIG, diff --git a/src/Env.cpp b/src/Env.cpp index 6d3d4d0..6c85aff 100644 --- a/src/Env.cpp +++ b/src/Env.cpp @@ -45,6 +45,9 @@ std::string_view Env::ToString(Env::Key key) { case Key::PROVIDER_IP_ENV: return "BEAMMP_PROVIDER_IP_ENV"; break; + case Key::MAX_CONCURRENT_CONNECTIONS: + return "BEAMMP_MAX_CONCURRENT_CONNECTIONS"; + break; } return ""; } diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 003c94b..3cf8b75 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -19,6 +19,7 @@ #include "TNetwork.h" #include "Client.h" #include "Common.h" +#include "Env.h" #include "LuaAPI.h" #include "TConnectionLimiter.h" #include "THeartbeatThread.h" @@ -45,8 +46,24 @@ typedef boost::asio::detail::socket_option::integer rcv_timeout_option; -static constexpr uint8_t MAX_CONCURRENT_CONNECTIONS = 10; 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(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 std::vector StringToVector(const std::string& Str) {