mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-08-16 16:26:26 +00:00
make update message adjustable by provider
This commit is contained in:
parent
b0f5976121
commit
c6aa7776fc
@ -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)
|
||||
|
16
include/Env.h
Normal file
16
include/Env.h
Normal 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);
|
||||
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
#include "Common.h"
|
||||
|
||||
#include "Env.h"
|
||||
#include "TConsole.h"
|
||||
#include <array>
|
||||
#include <charconv>
|
||||
#include <fmt/core.h>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <regex>
|
||||
@ -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!");
|
||||
|
20
src/Env.cpp
Normal file
20
src/Env.cpp
Normal 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 "";
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user