From de82caef335403767ffd50cac7f69e6ff2131c75 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Fri, 25 Mar 2022 13:33:03 +0100 Subject: [PATCH] Add HideUpdateMessages setting ("ImScaredOfUpdates") and periodic update reminders (every 5th heartbeat) --- include/Common.h | 1 + src/Common.cpp | 2 +- src/TConfig.cpp | 28 ++++++++++++++++++---------- src/THeartbeatThread.cpp | 5 +++++ 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/include/Common.h b/include/Common.h index 88e2732..5d224fb 100644 --- a/include/Common.h +++ b/include/Common.h @@ -54,6 +54,7 @@ public: bool SendErrorsMessageEnabled { true }; int HTTPServerPort { 8080 }; bool HTTPServerUseSSL { true }; + bool HideUpdateMessages { false }; [[nodiscard]] bool HasCustomIP() const { return !CustomIP.empty(); } }; diff --git a/src/Common.cpp b/src/Common.cpp index a113f74..99d0009 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -107,7 +107,7 @@ void Application::CheckForUpdates() { auto RemoteVersion = Version(VersionStrToInts(Response)); if (IsOutdated(MyVersion, RemoteVersion)) { std::string RealVersionString = RemoteVersion.AsString(); - beammp_warn(std::string(ANSI_YELLOW_BOLD) + "NEW VERSION OUT! There's a new version (v" + RealVersionString + ") of the BeamMP-Server available! For more info visit https://wiki.beammp.com/en/home/server-maintenance#updating-the-server." + std::string(ANSI_RESET)); + 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)); } else { beammp_info("Server up-to-date!"); } diff --git a/src/TConfig.cpp b/src/TConfig.cpp index f1c3126..1260cb7 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -17,12 +17,15 @@ static constexpr std::string_view StrName = "Name"; static constexpr std::string_view StrDescription = "Description"; static constexpr std::string_view StrResourceFolder = "ResourceFolder"; static constexpr std::string_view StrAuthKey = "AuthKey"; + +// Misc static constexpr std::string_view StrSendErrors = "SendErrors"; static constexpr std::string_view StrSendErrorsMessageEnabled = "SendErrorsShowMessage"; -static constexpr std::string_view StrHTTPServerEnabled = "HTTPServerEnabled"; -static constexpr std::string_view StrHTTPServerUseSSL = "UseSSL"; +static constexpr std::string_view StrHideUpdateMessages = "ImScaredOfUpdates"; // HTTP +static constexpr std::string_view StrHTTPServerEnabled = "HTTPServerEnabled"; +static constexpr std::string_view StrHTTPServerUseSSL = "UseSSL"; static constexpr std::string_view StrSSLKeyPath = "SSLKeyPath"; static constexpr std::string_view StrSSLCertPath = "SSLCertPath"; static constexpr std::string_view StrHTTPServerPort = "HTTPServerPort"; @@ -59,7 +62,6 @@ void SetComment(CommentsT& Comments, const std::string& Comment) { */ void TConfig::FlushToFile() { auto data = toml::parse(mConfigFileName); - data["General"] = toml::table(); data["General"][StrAuthKey.data()] = Application::Settings.Key; SetComment(data["General"][StrAuthKey.data()].comments(), " AuthKey has to be filled out in order to run the server"); data["General"][StrDebug.data()] = Application::Settings.DebugModeEnabled; @@ -71,10 +73,14 @@ void TConfig::FlushToFile() { data["General"][StrMap.data()] = Application::Settings.MapName; data["General"][StrDescription.data()] = Application::Settings.ServerDesc; data["General"][StrResourceFolder.data()] = Application::Settings.Resource; - data["General"][StrSendErrors.data()] = Application::Settings.SendErrors; - SetComment(data["General"][StrSendErrors.data()].comments(), " You can turn on/off the SendErrors message you get on startup here"); - data["General"][StrSendErrorsMessageEnabled.data()] = Application::Settings.SendErrorsMessageEnabled; - SetComment(data["General"][StrSendErrorsMessageEnabled.data()].comments(), " If SendErrors is `true`, the server will send helpful info about crashes and other issues back to the BeamMP developers. This info may include your config, who is on your server at the time of the error, and similar general information. This kind of data is vital in helping us diagnose and fix issues faster. This has no impact on server performance. You can opt-out of this system by setting this to `false`"); + // Misc + data["Misc"][StrHideUpdateMessages.data()] = Application::Settings.HideUpdateMessages; + SetComment(data["Misc"][StrHideUpdateMessages.data()].comments(), " Hides the periodic update message which notifies you of a new server version. You should really keep this on and always update as soon as possible. For more information visit https://wiki.beammp.com/en/home/server-maintenance#updating-the-server. An update message will always appear at startup regardless."); + data["Misc"][StrSendErrors.data()] = Application::Settings.SendErrors; + SetComment(data["Misc"][StrSendErrors.data()].comments(), " You can turn on/off the SendErrors message you get on startup here"); + data["Misc"][StrSendErrorsMessageEnabled.data()] = Application::Settings.SendErrorsMessageEnabled; + SetComment(data["Misc"][StrSendErrorsMessageEnabled.data()].comments(), " If SendErrors is `true`, the server will send helpful info about crashes and other issues back to the BeamMP developers. This info may include your config, who is on your server at the time of the error, and similar general information. This kind of data is vital in helping us diagnose and fix issues faster. This has no impact on server performance. You can opt-out of this system by setting this to `false`"); + // HTTP data["HTTP"][StrSSLKeyPath.data()] = Application::Settings.SSLKeyPath; data["HTTP"][StrSSLCertPath.data()] = Application::Settings.SSLCertPath; data["HTTP"][StrHTTPServerPort.data()] = Application::Settings.HTTPServerPort; @@ -82,7 +88,7 @@ void TConfig::FlushToFile() { SetComment(data["HTTP"][StrHTTPServerUseSSL.data()].comments(), " Recommended to keep enabled. With SSL the server will serve https and requires valid key and cert files"); data["HTTP"][StrHTTPServerEnabled.data()] = Application::Settings.HTTPServerEnabled; SetComment(data["HTTP"][StrHTTPServerEnabled.data()].comments(), " Enables the internal HTTP server"); - std::ofstream Stream(mConfigFileName); + std::ofstream Stream(mConfigFileName, std::ios::trunc | std::ios::out); Stream << data << std::flush; } @@ -158,8 +164,10 @@ void TConfig::ParseFromFile(std::string_view name) { TryReadValue(data, "General", StrDescription, Application::Settings.ServerDesc); TryReadValue(data, "General", StrResourceFolder, Application::Settings.Resource); TryReadValue(data, "General", StrAuthKey, Application::Settings.Key); - TryReadValue(data, "General", StrSendErrors, Application::Settings.SendErrors); - TryReadValue(data, "General", StrSendErrorsMessageEnabled, Application::Settings.SendErrorsMessageEnabled); + // Misc + TryReadValue(data, "Misc", StrSendErrors, Application::Settings.SendErrors); + TryReadValue(data, "Misc", StrHideUpdateMessages, Application::Settings.HideUpdateMessages); + TryReadValue(data, "Misc", StrSendErrorsMessageEnabled, Application::Settings.SendErrorsMessageEnabled); // HTTP TryReadValue(data, "HTTP", StrSSLKeyPath, Application::Settings.SSLKeyPath); TryReadValue(data, "HTTP", StrSSLCertPath, Application::Settings.SSLCertPath); diff --git a/src/THeartbeatThread.cpp b/src/THeartbeatThread.cpp index 42e7b36..d65380e 100644 --- a/src/THeartbeatThread.cpp +++ b/src/THeartbeatThread.cpp @@ -19,7 +19,9 @@ void THeartbeatThread::operator()() { static std::chrono::high_resolution_clock::time_point LastNormalUpdateTime = std::chrono::high_resolution_clock::now(); bool isAuth = false; + size_t UpdateReminderCounter = 0; while (!mShutdown) { + ++UpdateReminderCounter; Body = GenerateCall(); // a hot-change occurs when a setting has changed, to update the backend of that change. auto Now = std::chrono::high_resolution_clock::now(); @@ -128,6 +130,9 @@ void THeartbeatThread::operator()() { if (isAuth) { Application::SetSubsystemStatus("Heartbeat", Application::Status::Good); } + if (!Application::Settings.HideUpdateMessages && UpdateReminderCounter % 5) { + Application::CheckForUpdates(); + } } }