diff --git a/CMakeLists.txt b/CMakeLists.txt index a87bb373..842b80d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ set(PRJ_HEADERS include/TScopedTimer.h include/TServer.h include/VehicleData.h + include/Env.h ) # add all source files (.cpp) to this, except the one with main() set(PRJ_SOURCES @@ -70,6 +71,7 @@ set(PRJ_SOURCES src/TScopedTimer.cpp src/TServer.cpp src/VehicleData.cpp + src/Env.cpp ) find_package(Lua REQUIRED) diff --git a/include/Env.h b/include/Env.h new file mode 100644 index 00000000..030eeaee --- /dev/null +++ b/include/Env.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include +namespace Env { + +enum class Key { + // provider settings + PROVIDER_UPDATE_MESSAGE, +}; + +std::optional Get(Key key); + +std::string_view ToString(Key key); + +} diff --git a/src/Common.cpp b/src/Common.cpp index d68dcf18..dd66ae82 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -1,8 +1,10 @@ #include "Common.h" +#include "Env.h" #include "TConsole.h" #include #include +#include #include #include #include @@ -201,8 +203,11 @@ void Application::CheckForUpdates() { auto MyVersion = ServerVersion(); auto RemoteVersion = Version(VersionStrToInts(Response)); if (IsOutdated(MyVersion, RemoteVersion)) { - std::string RealVersionString = RemoteVersion.AsString(); - beammp_warn(std::string(ANSI_YELLOW_BOLD) + "NEW VERSION IS OUT! Please update to the new version (v" + RealVersionString + ") of the BeamMP-Server! Download it here: https://beammp.com/! For a guide on how to update, visit: https://wiki.beammp.com/en/home/server-maintenance#updating-the-server" + std::string(ANSI_RESET)); + std::string RealVersionString = std::string("v") + RemoteVersion.AsString(); + const std::string DefaultUpdateMsg = "NEW VERSION IS OUT! Please update to the new version ({}) of the BeamMP-Server! Download it here: https://beammp.com/! For a guide on how to update, visit: https://wiki.beammp.com/en/home/server-maintenance#updating-the-server"; + auto UpdateMsg = Env::Get(Env::Key::PROVIDER_UPDATE_MESSAGE).value_or(DefaultUpdateMsg); + UpdateMsg = fmt::vformat(std::string_view(UpdateMsg), fmt::make_format_args(RealVersionString)); + beammp_warnf("{}{}{}", ANSI_YELLOW_BOLD, UpdateMsg, ANSI_RESET); } else { if (FirstTime) { beammp_info("Server up-to-date!"); diff --git a/src/Env.cpp b/src/Env.cpp new file mode 100644 index 00000000..205b35b8 --- /dev/null +++ b/src/Env.cpp @@ -0,0 +1,20 @@ +#include "Env.h" +#include + +std::optional Env::Get(Env::Key key) { + auto StrKey = ToString(key); + auto Value = std::getenv(StrKey.data()); + if (!Value || std::string_view(Value).empty()) { + return std::nullopt; + } + return Value; +} + +std::string_view Env::ToString(Env::Key key) { + switch (key) { + case Key::PROVIDER_UPDATE_MESSAGE: + return "BEAMMP_PROVIDER_UPDATE_MESSAGE"; + break; + } + return ""; +}