make update message adjustable by provider

This commit is contained in:
Lion Kortlepel 2023-12-29 01:10:24 +01:00 committed by Lion
parent b0f5976121
commit c6aa7776fc
4 changed files with 45 additions and 2 deletions

View File

@ -48,6 +48,7 @@ set(PRJ_HEADERS
include/TScopedTimer.h include/TScopedTimer.h
include/TServer.h include/TServer.h
include/VehicleData.h include/VehicleData.h
include/Env.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
@ -70,6 +71,7 @@ set(PRJ_SOURCES
src/TScopedTimer.cpp src/TScopedTimer.cpp
src/TServer.cpp src/TServer.cpp
src/VehicleData.cpp src/VehicleData.cpp
src/Env.cpp
) )
find_package(Lua REQUIRED) find_package(Lua REQUIRED)

16
include/Env.h Normal file
View File

@ -0,0 +1,16 @@
#pragma once
#include <optional>
#include <string>
namespace Env {
enum class Key {
// provider settings
PROVIDER_UPDATE_MESSAGE,
};
std::optional<std::string> Get(Key key);
std::string_view ToString(Key key);
}

View File

@ -1,8 +1,10 @@
#include "Common.h" #include "Common.h"
#include "Env.h"
#include "TConsole.h" #include "TConsole.h"
#include <array> #include <array>
#include <charconv> #include <charconv>
#include <fmt/core.h>
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <regex> #include <regex>
@ -201,8 +203,11 @@ void Application::CheckForUpdates() {
auto MyVersion = ServerVersion(); auto MyVersion = ServerVersion();
auto RemoteVersion = Version(VersionStrToInts(Response)); auto RemoteVersion = Version(VersionStrToInts(Response));
if (IsOutdated(MyVersion, RemoteVersion)) { if (IsOutdated(MyVersion, RemoteVersion)) {
std::string RealVersionString = RemoteVersion.AsString(); std::string RealVersionString = std::string("v") + 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)); 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 { } else {
if (FirstTime) { if (FirstTime) {
beammp_info("Server up-to-date!"); beammp_info("Server up-to-date!");

20
src/Env.cpp Normal file
View File

@ -0,0 +1,20 @@
#include "Env.h"
#include <optional>
std::optional<std::string> 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 "";
}