From 6f50cad76b76a5ec3bc1d803e6d9747497801589 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sat, 30 Dec 2023 11:30:48 +0100 Subject: [PATCH] add BEAMMP_PROVIDER_PORT_ENV to allow provider to change which ENV variable the port is fetched from --- include/Env.h | 1 + src/Env.cpp | 3 +++ src/TConfig.cpp | 6 +++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/Env.h b/include/Env.h index dc56353..749cb3e 100644 --- a/include/Env.h +++ b/include/Env.h @@ -26,6 +26,7 @@ enum class Key { // provider settings PROVIDER_UPDATE_MESSAGE, PROVIDER_DISABLE_CONFIG, + PROVIDER_PORT_ENV, }; std::optional Get(Key key); diff --git a/src/Env.cpp b/src/Env.cpp index 82037a0..a969de3 100644 --- a/src/Env.cpp +++ b/src/Env.cpp @@ -36,6 +36,9 @@ std::string_view Env::ToString(Env::Key key) { case Key::PROVIDER_DISABLE_CONFIG: return "BEAMMP_PROVIDER_DISABLE_CONFIG"; break; + case Key::PROVIDER_PORT_ENV: + return "BEAMMP_PROVIDER_PORT_ENV"; + break; } return ""; } diff --git a/src/TConfig.cpp b/src/TConfig.cpp index 543ada3..1223ec7 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -234,7 +234,11 @@ void TConfig::ParseFromFile(std::string_view name) { // GENERAL TryReadValue(data, "General", StrDebug, EnvStrDebug, Application::Settings.DebugModeEnabled); TryReadValue(data, "General", StrPrivate, EnvStrPrivate, Application::Settings.Private); - TryReadValue(data, "General", StrPort, EnvStrPort, Application::Settings.Port); + if (Env::Get(Env::Key::PROVIDER_PORT_ENV).has_value()) { + TryReadValue(data, "General", StrPort, Env::Get(Env::Key::PROVIDER_PORT_ENV).value(), Application::Settings.Port); + } else { + TryReadValue(data, "General", StrPort, EnvStrPort, Application::Settings.Port); + } TryReadValue(data, "General", StrMaxCars, EnvStrMaxCars, Application::Settings.MaxCars); TryReadValue(data, "General", StrMaxPlayers, EnvStrMaxPlayers, Application::Settings.MaxPlayers); TryReadValue(data, "General", StrMap, EnvStrMap, Application::Settings.MapName);