Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make update message adjustable by provider #239

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -70,6 +71,7 @@ set(PRJ_SOURCES
src/TScopedTimer.cpp
src/TServer.cpp
src/VehicleData.cpp
src/Env.cpp
)

find_package(Lua REQUIRED)
Expand Down
16 changes: 16 additions & 0 deletions include/Env.h
Original file line number Diff line number Diff line change
@@ -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);

}
9 changes: 7 additions & 2 deletions src/Common.cpp
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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!");
Expand Down
20 changes: 20 additions & 0 deletions src/Env.cpp
Original file line number Diff line number Diff line change
@@ -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