From 11e94e91a7ccbe151ca4340ea55feee9dc77aa84 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 9 Sep 2021 10:43:29 +0300 Subject: [PATCH 01/22] Update Changelog.md to reflect latest changes in recent merge from #44 --- Changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Changelog.md b/Changelog.md index 60e0daa..7a5832d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,7 @@ +# v2.3.1 + +- CHANGED join/sync timeout to 20 minutes, players wont drop if loading takes >5 mins + # v2.3.0 - ADDED version check - the server will now let you know when a new release is out From 0f9f81e9fa9c19d687765fcd53359b8e55b29aa8 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 9 Sep 2021 11:17:13 +0300 Subject: [PATCH 02/22] Http: Add cloudflare 5XX status code strings --- src/Http.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Http.cpp b/src/Http.cpp index 3ac754c..f9e452a 100644 --- a/src/Http.cpp +++ b/src/Http.cpp @@ -82,7 +82,7 @@ std::string Http::GET(const std::string& host, int port, const std::string& targ if (status) { *status = res.base().result_int(); } - + // ignore ec // If we get here then the connection is closed gracefully @@ -270,12 +270,22 @@ static std::map Map = { { 508, "Loop Detected" }, { 510, "Not Extended" }, { 511, "Network Authentication Required" }, + // cloudflare status codes + { 520, "(CDN) Web Server Returns An Unknown Error" }, + { 521, "(CDN) Web Server Is Down" }, + { 522, "(CDN) Connection Timed Out" }, + { 523, "(CDN) Origin Is Unreachable" }, + { 524, "(CDN) A Timeout Occurred" }, + { 525, "(CDN) SSL Handshake Failed" }, + { 526, "(CDN) Invalid SSL Certificate" }, + { 527, "(CDN) Railgun Listener To Origin Error" }, + { 530, "(CDN) 1XXX Internal Error" }, }; std::string Http::Status::ToString(int code) { if (Map.find(code) != Map.end()) { return Map.at(code); } else { - return "Unassigned"; + return std::to_string(code); } } From a5145916503cf295cccb514e4d2ffc589238462f Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 9 Sep 2021 11:37:56 +0300 Subject: [PATCH 03/22] Main: Add Ctrl+C handler for windows --- CMakeLists.txt | 3 +- Changelog.md | 4 +++ include/SignalHandling.h | 68 ++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 43 ++++++------------------- 4 files changed, 83 insertions(+), 35 deletions(-) create mode 100644 include/SignalHandling.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f9f672..a072d12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,8 @@ add_executable(BeamMP-Server include/Http.h src/Http.cpp include/TSentry.h src/TSentry.cpp include/TPPSMonitor.h src/TPPSMonitor.cpp - include/TNetwork.h src/TNetwork.cpp) + include/TNetwork.h src/TNetwork.cpp + include/SignalHandling.h) target_compile_definitions(BeamMP-Server PRIVATE SECRET_SENTRY_URL="${BEAMMP_SECRET_SENTRY_URL}") diff --git a/Changelog.md b/Changelog.md index 7a5832d..b4cd153 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,7 @@ +# v2.3.2 + +- ADDED Ctrl+C and closing the console causing a graceful shutdown + # v2.3.1 - CHANGED join/sync timeout to 20 minutes, players wont drop if loading takes >5 mins diff --git a/include/SignalHandling.h b/include/SignalHandling.h new file mode 100644 index 0000000..8f3dc93 --- /dev/null +++ b/include/SignalHandling.h @@ -0,0 +1,68 @@ +#pragma once + +#include "Common.h" + +#ifdef __unix +#include +static void UnixSignalHandler(int sig) { + switch (sig) { + case SIGPIPE: + warn("ignoring SIGPIPE"); + break; + case SIGTERM: + info("gracefully shutting down via SIGTERM"); + Application::GracefullyShutdown(); + break; + case SIGINT: + info("gracefully shutting down via SIGINT"); + Application::GracefullyShutdown(); + break; + default: + debug("unhandled signal: " + std::to_string(sig)); + break; + } +} +#endif // __unix + +#ifdef WIN32 +#include +// return TRUE if handled, FALSE if not +BOOL WINAPI Win32CtrlC_Handler(DWORD CtrlType) { + switch (CtrlType) { + case CTRL_C_EVENT: + info("gracefully shutting down via CTRL+C"); + Application::GracefullyShutdown(); + return TRUE; + case CTRL_BREAK_EVENT: + info("gracefully shutting down via CTRL+BREAK"); + Application::GracefullyShutdown(); + return TRUE; + case CTRL_CLOSE_EVENT: + info("gracefully shutting down via close"); + Application::GracefullyShutdown(); + return TRUE; + } + // we dont care for any others like CTRL_LOGOFF_EVENT and CTRL_SHUTDOWN_EVENT + return FALSE; +} +#endif // WIN32 + +// clang-format off +static void SetupSignalHandlers() { + // signal handlers for unix + #ifdef __unix + trace("registering handlers for SIGINT, SIGTERM, SIGPIPE"); + signal(SIGPIPE, UnixSignalHandler); + signal(SIGTERM, UnixSignalHandler); + #ifndef DEBUG + signal(SIGINT, UnixSignalHandler); + #endif // DEBUG + #endif // __unix + + // signal handlers for win32 + #ifdef WIN32 + trace("registering handlers for CTRL_*_EVENTs"); + SetConsoleCtrlHandler(Win32CtrlC_Handler, TRUE); + #endif // WIN32 +} +// clang-format on diff --git a/src/main.cpp b/src/main.cpp index 5e0aeaa..53d4a4c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,49 +10,20 @@ #include "TPPSMonitor.h" #include "TResourceManager.h" #include "TServer.h" +#include "SignalHandling.h" +#include #include -#ifdef __unix -#include - -void UnixSignalHandler(int sig) { - switch (sig) { - case SIGPIPE: - warn("ignoring SIGPIPE"); - break; - case SIGTERM: - info("gracefully shutting down via SIGTERM"); - Application::GracefullyShutdown(); - break; - case SIGINT: - info("gracefully shutting down via SIGINT"); - Application::GracefullyShutdown(); - break; - default: - debug("unhandled signal: " + std::to_string(sig)); - break; - } -} -#endif // __unix - // this is provided by the build system, leave empty for source builds // global, yes, this is ugly, no, it cant be done another way TSentry Sentry {}; -#include - int main(int argc, char** argv) try { -#ifdef __unix - trace("registering handlers for SIGINT, SIGTERM, SIGPIPE"); - signal(SIGPIPE, UnixSignalHandler); - signal(SIGTERM, UnixSignalHandler); -#ifndef DEBUG - signal(SIGINT, UnixSignalHandler); -#endif // DEBUG -#endif // __unix setlocale(LC_ALL, "C"); + SetupSignalHandlers(); + bool Shutdown = false; Application::RegisterShutdownHandler([&Shutdown] { Shutdown = true; }); @@ -61,7 +32,10 @@ int main(int argc, char** argv) try { if (Config.Failed()) { info("Closing in 10 seconds"); - std::this_thread::sleep_for(std::chrono::seconds(10)); + // loop to make it possible to ctrl+c instead + for (size_t i = 0; i < 20; ++i) { + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + } return 1; } @@ -88,3 +62,4 @@ int main(int argc, char** argv) try { error(e.what()); Sentry.LogException(e, _file_basename, _line); } + From d43ee4b7b6b5a5b851b0b3f465380a90d7e4c95f Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 9 Sep 2021 11:42:48 +0300 Subject: [PATCH 04/22] Bump version to 2.3.2 --- include/Common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Common.h b/include/Common.h index 6b6466a..64e0585 100644 --- a/include/Common.h +++ b/include/Common.h @@ -54,7 +54,7 @@ public: // Causes all threads to finish up and exit gracefull gracefully static void GracefullyShutdown(); static TConsole& Console() { return *mConsole; } - static std::string ServerVersion() { return "2.3.1"; } + static std::string ServerVersion() { return "2.3.2"; } static std::string ClientVersion() { return "2.0"; } static std::string PPS() { return mPPS; } static void SetPPS(const std::string& NewPPS) { mPPS = NewPPS; } From b055fd8bda92b764eecdddcea89770a0dec382a1 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 9 Sep 2021 11:58:58 +0300 Subject: [PATCH 05/22] GracefullyShutdown: Add "subsystem x/y shutting down" message Remove old "X shutting down", "X shut down" messages, they were bad and confusing --- src/Common.cpp | 15 ++++++++++++--- src/THeartbeatThread.cpp | 2 -- src/TLuaEngine.cpp | 2 -- src/TNetwork.cpp | 4 ---- src/TPPSMonitor.cpp | 2 -- src/main.cpp | 3 ++- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Common.cpp b/src/Common.cpp index 3fe52bf..f7875c6 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -22,11 +22,20 @@ void Application::RegisterShutdownHandler(const TShutdownHandler& Handler) { } } +static bool AlreadyShuttingDown = false; void Application::GracefullyShutdown() { - info("please wait while all subsystems are shutting down..."); + if (AlreadyShuttingDown) { + info("already shutting down"); + return; + } else { + AlreadyShuttingDown = true; + } + trace("waiting for lock release"); std::unique_lock Lock(mShutdownHandlersMutex); - for (auto& Handler : mShutdownHandlers) { - Handler(); + info("please wait while all subsystems are shutting down..."); + for (size_t i = 0; i < mShutdownHandlers.size(); ++i) { + info("Subsystem " + std::to_string(i + 1) + "/" + std::to_string(mShutdownHandlers.size()) + " shutting down"); + mShutdownHandlers[i](); } } diff --git a/src/THeartbeatThread.cpp b/src/THeartbeatThread.cpp index d650966..cbd5eb7 100644 --- a/src/THeartbeatThread.cpp +++ b/src/THeartbeatThread.cpp @@ -107,10 +107,8 @@ THeartbeatThread::THeartbeatThread(TResourceManager& ResourceManager, TServer& S , mServer(Server) { Application::RegisterShutdownHandler([&] { if (mThread.joinable()) { - debug("shutting down Heartbeat"); mShutdown = true; mThread.join(); - debug("shut down Heartbeat"); } }); Start(); diff --git a/src/TLuaEngine.cpp b/src/TLuaEngine.cpp index 0ec1b07..d1300e5 100644 --- a/src/TLuaEngine.cpp +++ b/src/TLuaEngine.cpp @@ -23,10 +23,8 @@ TLuaEngine::TLuaEngine(TServer& Server, TNetwork& Network) FolderList(Path, false); mPath = Path; Application::RegisterShutdownHandler([&] {if (mThread.joinable()) { - debug("shutting down LuaEngine"); mShutdown = true; mThread.join(); - debug("shut down LuaEngine"); } }); Start(); } diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index d0972f3..3ed0c93 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -20,18 +20,14 @@ TNetwork::TNetwork(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& R }); Application::RegisterShutdownHandler([&] { if (mUDPThread.joinable()) { - debug("shutting down TCPServer"); mShutdown = true; mUDPThread.detach(); - debug("shut down TCPServer"); } }); Application::RegisterShutdownHandler([&] { if (mTCPThread.joinable()) { - debug("shutting down TCPServer"); mShutdown = true; mTCPThread.detach(); - debug("shut down TCPServer"); } }); mTCPThread = std::thread(&TNetwork::TCPServerMain, this); diff --git a/src/TPPSMonitor.cpp b/src/TPPSMonitor.cpp index 129ab04..c544628 100644 --- a/src/TPPSMonitor.cpp +++ b/src/TPPSMonitor.cpp @@ -7,10 +7,8 @@ TPPSMonitor::TPPSMonitor(TServer& Server) Application::SetPPS("-"); Application::RegisterShutdownHandler([&] { if (mThread.joinable()) { - debug("shutting down PPSMonitor"); mShutdown = true; mThread.join(); - debug("shut down PPSMonitor"); } }); Start(); diff --git a/src/main.cpp b/src/main.cpp index 53d4a4c..9f5b339 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,8 +56,9 @@ int main(int argc, char** argv) try { // TODO: replace while (!Shutdown) { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); } + info("Shutdown."); } catch (const std::exception& e) { error(e.what()); Sentry.LogException(e, _file_basename, _line); From 3cd94380e2ed7ea3b4f73fa770d04f25893fafe4 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 9 Sep 2021 12:09:18 +0300 Subject: [PATCH 06/22] Changelog: Add recent additions --- Changelog.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index b4cd153..221f19e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,9 @@ # v2.3.2 -- ADDED Ctrl+C and closing the console causing a graceful shutdown +- ADDED Ctrl+C causes a graceful shutdown on windows (did already on linux) +- ADDED more meaningful shutdown messages +- ADDED even better backend connection error reporting +- # v2.3.1 From ffac000cd23fe26d920e88700e359c0c02e1649c Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 9 Sep 2021 17:22:03 +0300 Subject: [PATCH 07/22] Config: Add basic opt-out for Sentry --- Changelog.md | 2 +- include/Common.h | 4 +++- src/TConfig.cpp | 18 ++++++++++++++++++ src/TSentry.cpp | 9 +++++++-- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index 221f19e..8fbb87e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,7 +3,7 @@ - ADDED Ctrl+C causes a graceful shutdown on windows (did already on linux) - ADDED more meaningful shutdown messages - ADDED even better backend connection error reporting -- +- ADDED `SendErrors` config in `ServerConfig.toml` to opt-out of error reporting # v2.3.1 diff --git a/include/Common.h b/include/Common.h index 64e0585..3897bbb 100644 --- a/include/Common.h +++ b/include/Common.h @@ -30,7 +30,8 @@ public: , Private(false) , MaxCars(1) , DebugModeEnabled(false) - , Port(30814) { } + , Port(30814) + , SendErrors(true) { } std::string ServerName; std::string ServerDesc; std::string Resource; @@ -42,6 +43,7 @@ public: bool DebugModeEnabled; int Port; std::string CustomIP; + bool SendErrors; [[nodiscard]] bool HasCustomIP() const { return !CustomIP.empty(); } }; using TShutdownHandler = std::function; diff --git a/src/TConfig.cpp b/src/TConfig.cpp index d2a0696..5132a66 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -18,6 +18,7 @@ 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"; +static constexpr std::string_view StrSendErrors = "SendErrors"; TConfig::TConfig() { if (!fs::exists(ConfigFileName) || !fs::is_regular_file(ConfigFileName)) { @@ -32,6 +33,13 @@ TConfig::TConfig() { } } +void WriteSendErrors(const std::string& name) { + std::ofstream CfgFile { name, std::ios::out | std::ios::app }; + CfgFile << "# 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 data. You can opt-out of this system by setting this to `false`." + << std::endl + << StrSendErrors << " = true" << std::endl; +} + void TConfig::CreateConfigFile(std::string_view name) { // build from old config Server.cfg @@ -59,6 +67,7 @@ void TConfig::CreateConfigFile(std::string_view name) { { StrDescription, Application::Settings.ServerDesc }, { StrResourceFolder, Application::Settings.Resource }, { StrAuthKey, Application::Settings.Key }, + //{ StrSendErrors, Application::Settings.SendErrors }, } } }, @@ -72,6 +81,8 @@ void TConfig::CreateConfigFile(std::string_view name) { ofs << tbl << '\n'; error("There was no \"" + std::string(ConfigFileName) + "\" file (this is normal for the first time running the server), so one was generated for you. It was automatically filled with the settings from your Server.cfg, if you have one. Please open ServerConfig.toml and ensure your AuthKey and other settings are filled in and correct, then restart the server. The old Server.cfg file will no longer be used and causes a warning if it exists from now on."); mFailed = true; + ofs.close(); + WriteSendErrors(std::string(name)); } else { error("Couldn't create " + std::string(name) + ". Check permissions, try again, and contact support if it continues not to work."); mFailed = true; @@ -132,6 +143,13 @@ void TConfig::ParseFromFile(std::string_view name) { } else { throw std::runtime_error(std::string(StrAuthKey)); } + // added later, so behaves differently + if (auto val = GeneralTable[StrSendErrors].value(); val.has_value()) { + Application::Settings.SendErrors = val.value(); + } else { + // dont throw, instead write it into the file and use default + WriteSendErrors(std::string(name)); + } } catch (const std::exception& err) { error("Error parsing config file value: " + std::string(err.what())); mFailed = true; diff --git a/src/TSentry.cpp b/src/TSentry.cpp index fd8069f..d09df92 100644 --- a/src/TSentry.cpp +++ b/src/TSentry.cpp @@ -34,9 +34,14 @@ TSentry::~TSentry() { void TSentry::PrintWelcome() { if (mValid) { - info("Sentry started"); + if (!Application::Settings.SendErrors) { + mValid = false; + info("Opted out of error reporting (SendErrors), Sentry disabled."); + } else { + info("Sentry started! Reporting errors automatically. You can opt-out of this in the ServerConfig."); + } } else { - info("Sentry disabled in unofficial build"); + info("Sentry disabled in unofficial build. Automatic error reporting disabled."); } } From b1664bb184618ce1d72290ac8e17f9da5d99bedc Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Fri, 10 Sep 2021 13:24:15 +0300 Subject: [PATCH 08/22] Application: Perform hard-shutdown after 3 Ctrl+C's --- src/Common.cpp | 11 +++++++++-- src/main.cpp | 3 +-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Common.cpp b/src/Common.cpp index f7875c6..478cc8f 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -22,10 +22,17 @@ void Application::RegisterShutdownHandler(const TShutdownHandler& Handler) { } } -static bool AlreadyShuttingDown = false; void Application::GracefullyShutdown() { + static bool AlreadyShuttingDown = false; + static uint8_t ShutdownAttempts = 0; if (AlreadyShuttingDown) { - info("already shutting down"); + ++ShutdownAttempts; + // hard shutdown at 2 additional tries + if (ShutdownAttempts == 2) { + info("hard shutdown forced by multiple shutdown requests"); + exit(0); + } + info("already shutting down!"); return; } else { AlreadyShuttingDown = true; diff --git a/src/main.cpp b/src/main.cpp index 9f5b339..01a77ae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,7 @@ #include "Common.h" #include "CustomAssert.h" #include "Http.h" +#include "SignalHandling.h" #include "TConfig.h" #include "THeartbeatThread.h" #include "TLuaEngine.h" @@ -10,7 +11,6 @@ #include "TPPSMonitor.h" #include "TResourceManager.h" #include "TServer.h" -#include "SignalHandling.h" #include #include @@ -63,4 +63,3 @@ int main(int argc, char** argv) try { error(e.what()); Sentry.LogException(e, _file_basename, _line); } - From 30624c77a2190f74e76e5aac1adb7e6cccb47a2c Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Fri, 10 Sep 2021 13:24:46 +0300 Subject: [PATCH 09/22] Update commandline; reset terminal before exit --- include/commandline | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/commandline b/include/commandline index c34703d..4931aa8 160000 --- a/include/commandline +++ b/include/commandline @@ -1 +1 @@ -Subproject commit c34703df11ca00b7c4b04478bc566bd9744ac858 +Subproject commit 4931aa89c1b400732394d8b8523974ed09f427dc From a2f92b57914ffa7c7de89694ce672e49a6f807ec Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Fri, 10 Sep 2021 13:43:50 +0300 Subject: [PATCH 10/22] Update changelog, use std::exit instead of exit --- Changelog.md | 2 ++ src/Common.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 8fbb87e..2390760 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,8 @@ - ADDED more meaningful shutdown messages - ADDED even better backend connection error reporting - ADDED `SendErrors` config in `ServerConfig.toml` to opt-out of error reporting +- ADDED hard-shutdown if Ctrl+C pressed 3 times +- FIXED issue with shells like bash being unusable after server exit # v2.3.1 diff --git a/src/Common.cpp b/src/Common.cpp index 478cc8f..e4689bc 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -30,7 +30,7 @@ void Application::GracefullyShutdown() { // hard shutdown at 2 additional tries if (ShutdownAttempts == 2) { info("hard shutdown forced by multiple shutdown requests"); - exit(0); + std::exit(0); } info("already shutting down!"); return; From 38b934bc0f5047a7723be0bdd0ac4e4bcd0f2a17 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Fri, 10 Sep 2021 13:53:14 +0300 Subject: [PATCH 11/22] Move signal handling into its own translation unit to limit overlap --- CMakeLists.txt | 2 +- include/SignalHandling.h | 67 +--------------------------------------- src/SignalHandling.cpp | 65 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 67 deletions(-) create mode 100644 src/SignalHandling.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a072d12..362aebb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,7 @@ add_executable(BeamMP-Server include/TSentry.h src/TSentry.cpp include/TPPSMonitor.h src/TPPSMonitor.cpp include/TNetwork.h src/TNetwork.cpp - include/SignalHandling.h) + include/SignalHandling.h src/SignalHandling.cpp) target_compile_definitions(BeamMP-Server PRIVATE SECRET_SENTRY_URL="${BEAMMP_SECRET_SENTRY_URL}") diff --git a/include/SignalHandling.h b/include/SignalHandling.h index 8f3dc93..e945d37 100644 --- a/include/SignalHandling.h +++ b/include/SignalHandling.h @@ -1,68 +1,3 @@ #pragma once -#include "Common.h" - -#ifdef __unix -#include -static void UnixSignalHandler(int sig) { - switch (sig) { - case SIGPIPE: - warn("ignoring SIGPIPE"); - break; - case SIGTERM: - info("gracefully shutting down via SIGTERM"); - Application::GracefullyShutdown(); - break; - case SIGINT: - info("gracefully shutting down via SIGINT"); - Application::GracefullyShutdown(); - break; - default: - debug("unhandled signal: " + std::to_string(sig)); - break; - } -} -#endif // __unix - -#ifdef WIN32 -#include -// return TRUE if handled, FALSE if not -BOOL WINAPI Win32CtrlC_Handler(DWORD CtrlType) { - switch (CtrlType) { - case CTRL_C_EVENT: - info("gracefully shutting down via CTRL+C"); - Application::GracefullyShutdown(); - return TRUE; - case CTRL_BREAK_EVENT: - info("gracefully shutting down via CTRL+BREAK"); - Application::GracefullyShutdown(); - return TRUE; - case CTRL_CLOSE_EVENT: - info("gracefully shutting down via close"); - Application::GracefullyShutdown(); - return TRUE; - } - // we dont care for any others like CTRL_LOGOFF_EVENT and CTRL_SHUTDOWN_EVENT - return FALSE; -} -#endif // WIN32 - -// clang-format off -static void SetupSignalHandlers() { - // signal handlers for unix - #ifdef __unix - trace("registering handlers for SIGINT, SIGTERM, SIGPIPE"); - signal(SIGPIPE, UnixSignalHandler); - signal(SIGTERM, UnixSignalHandler); - #ifndef DEBUG - signal(SIGINT, UnixSignalHandler); - #endif // DEBUG - #endif // __unix - - // signal handlers for win32 - #ifdef WIN32 - trace("registering handlers for CTRL_*_EVENTs"); - SetConsoleCtrlHandler(Win32CtrlC_Handler, TRUE); - #endif // WIN32 -} -// clang-format on +void SetupSignalHandlers(); diff --git a/src/SignalHandling.cpp b/src/SignalHandling.cpp new file mode 100644 index 0000000..3325871 --- /dev/null +++ b/src/SignalHandling.cpp @@ -0,0 +1,65 @@ +#include "SignalHandling.h" +#include "Common.h" + +#ifdef __unix +#include +static void UnixSignalHandler(int sig) { + switch (sig) { + case SIGPIPE: + warn("ignoring SIGPIPE"); + break; + case SIGTERM: + info("gracefully shutting down via SIGTERM"); + Application::GracefullyShutdown(); + break; + case SIGINT: + info("gracefully shutting down via SIGINT"); + Application::GracefullyShutdown(); + break; + default: + debug("unhandled signal: " + std::to_string(sig)); + break; + } +} +#endif // __unix + +#ifdef WIN32 +#include +// return TRUE if handled, FALSE if not +BOOL WINAPI Win32CtrlC_Handler(DWORD CtrlType) { + switch (CtrlType) { + case CTRL_C_EVENT: + info("gracefully shutting down via CTRL+C"); + Application::GracefullyShutdown(); + return TRUE; + case CTRL_BREAK_EVENT: + info("gracefully shutting down via CTRL+BREAK"); + Application::GracefullyShutdown(); + return TRUE; + case CTRL_CLOSE_EVENT: + info("gracefully shutting down via close"); + Application::GracefullyShutdown(); + return TRUE; + } + // we dont care for any others like CTRL_LOGOFF_EVENT and CTRL_SHUTDOWN_EVENT + return FALSE; +} +#endif // WIN32 + +void SetupSignalHandlers() { + // signal handlers for unix#include +#ifdef __unix + trace("registering handlers for SIGINT, SIGTERM, SIGPIPE"); + signal(SIGPIPE, UnixSignalHandler); + signal(SIGTERM, UnixSignalHandler); +#ifndef DEBUG + signal(SIGINT, UnixSignalHandler); +#endif // DEBUG +#endif // __unix + + // signal handlers for win32 +#ifdef WIN32 + trace("registering handlers for CTRL_*_EVENTs"); + SetConsoleCtrlHandler(Win32CtrlC_Handler, TRUE); +#endif // WIN32 +} From 6542be09ee7619fcf05d9eb8d0f2c2a2ecb880e6 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Fri, 10 Sep 2021 15:53:08 +0300 Subject: [PATCH 12/22] Clarify what sentry sends, add a way to turn off the warning --- include/Common.h | 4 +++- src/TConfig.cpp | 11 ++++++++++- src/TSentry.cpp | 18 +++++++++++++++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/include/Common.h b/include/Common.h index 3897bbb..99c39bf 100644 --- a/include/Common.h +++ b/include/Common.h @@ -31,7 +31,8 @@ public: , MaxCars(1) , DebugModeEnabled(false) , Port(30814) - , SendErrors(true) { } + , SendErrors(true) + , SendErrorsMessageEnabled(true) { } std::string ServerName; std::string ServerDesc; std::string Resource; @@ -44,6 +45,7 @@ public: int Port; std::string CustomIP; bool SendErrors; + bool SendErrorsMessageEnabled; [[nodiscard]] bool HasCustomIP() const { return !CustomIP.empty(); } }; using TShutdownHandler = std::function; diff --git a/src/TConfig.cpp b/src/TConfig.cpp index 5132a66..fa3bb5d 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -19,6 +19,7 @@ static constexpr std::string_view StrDescription = "Description"; static constexpr std::string_view StrResourceFolder = "ResourceFolder"; static constexpr std::string_view StrAuthKey = "AuthKey"; static constexpr std::string_view StrSendErrors = "SendErrors"; +static constexpr std::string_view StrSendErrorsMessageEnabled = "SendErrorsShowMessage"; TConfig::TConfig() { if (!fs::exists(ConfigFileName) || !fs::is_regular_file(ConfigFileName)) { @@ -35,7 +36,9 @@ TConfig::TConfig() { void WriteSendErrors(const std::string& name) { std::ofstream CfgFile { name, std::ios::out | std::ios::app }; - CfgFile << "# 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 data. You can opt-out of this system by setting this to `false`." + CfgFile << "# You can turn on/off the SendErrors message you get on startup here" << std::endl + << StrSendErrorsMessageEnabled << " = true" << std::endl + << "# 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`." << std::endl << StrSendErrors << " = true" << std::endl; } @@ -150,6 +153,12 @@ void TConfig::ParseFromFile(std::string_view name) { // dont throw, instead write it into the file and use default WriteSendErrors(std::string(name)); } + if (auto val = GeneralTable[StrSendErrorsMessageEnabled].value(); val.has_value()) { + Application::Settings.SendErrorsMessageEnabled = val.value(); + } else { + // no idea what to do here, ignore...? + // this entire toml parser sucks and is replaced in the upcoming lua. + } } catch (const std::exception& err) { error("Error parsing config file value: " + std::string(err.what())); mFailed = true; diff --git a/src/TSentry.cpp b/src/TSentry.cpp index d09df92..ab20e31 100644 --- a/src/TSentry.cpp +++ b/src/TSentry.cpp @@ -36,12 +36,24 @@ void TSentry::PrintWelcome() { if (mValid) { if (!Application::Settings.SendErrors) { mValid = false; - info("Opted out of error reporting (SendErrors), Sentry disabled."); + if (Application::Settings.SendErrorsMessageEnabled) { + info("Opted out of error reporting (SendErrors), Sentry disabled."); + } else { + info("Sentry disabled"); + } } else { - info("Sentry started! Reporting errors automatically. You can opt-out of this in the ServerConfig."); + if (Application::Settings.SendErrorsMessageEnabled) { + info("Sentry started! Reporting errors automatically. This sends data to the developers in case of errors and crashes. You can learn more, turn this message off or opt-out of this in the ServerConfig.toml."); + } else { + info("Sentry started"); + } } } else { - info("Sentry disabled in unofficial build. Automatic error reporting disabled."); + if (Application::Settings.SendErrorsMessageEnabled) { + info("Sentry disabled in unofficial build. Automatic error reporting disabled."); + } else { + info("Sentry disabled in unofficial build"); + } } } From 3fc397814ce9f1f7d0db8c1ac755fadd4acc5cd2 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Fri, 10 Sep 2021 16:37:46 +0300 Subject: [PATCH 13/22] Move update check to after initialization (since its blocking) --- src/Common.cpp | 2 +- src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Common.cpp b/src/Common.cpp index e4689bc..0313190 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -81,7 +81,7 @@ void Application::CheckForUpdates() { std::string RealVersionString = std::to_string(RemoteVersion[0]) + "."; RealVersionString += std::to_string(RemoteVersion[1]) + "."; RealVersionString += std::to_string(RemoteVersion[2]); - warn(std::string(ANSI_YELLOW_BOLD) + "NEW VERSION OUT! There's a new version (v" + RealVersionString + ") of the BeamMP-Server available! For info on how to update your server, visit https://wiki.beammp.com/en/home/server-maintenance#updating-the-server." + std::string(ANSI_RESET)); + 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)); } else { info("Server up-to-date!"); } diff --git a/src/main.cpp b/src/main.cpp index 01a77ae..27cafee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,7 +45,6 @@ int main(int argc, char** argv) try { Sentry.SetupUser(); Sentry.PrintWelcome(); - Application::CheckForUpdates(); TResourceManager ResourceManager; TPPSMonitor PPSMonitor(Server); THeartbeatThread Heartbeat(ResourceManager, Server); @@ -53,6 +52,7 @@ int main(int argc, char** argv) try { TLuaEngine LuaEngine(Server, Network); PPSMonitor.SetNetwork(Network); Application::Console().InitializeLuaConsole(LuaEngine); + Application::CheckForUpdates(); // TODO: replace while (!Shutdown) { From 80aebcb9a7cb1303e44f0c3e990a3d7967aac282 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sat, 11 Sep 2021 11:43:43 +0300 Subject: [PATCH 14/22] Actions: prerelease by default --- .github/workflows/release-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index eab5ede..3392448 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -24,7 +24,7 @@ jobs: tag_name: ${{ github.ref }} release_name: ${{ github.ref }} draft: false - prerelease: false + prerelease: true body: | Files included in this release: - `BeamMP-Server.exe` is the windows build From c70ada292699846b7137ae1d44dbfb9601d97e04 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Tue, 14 Sep 2021 12:15:05 +0200 Subject: [PATCH 15/22] Config: private by default --- Changelog.md | 4 ++++ include/Common.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 2390760..f4df1f1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,7 @@ +# v2.3.3 + +- CHANGED servers to be private by default + # v2.3.2 - ADDED Ctrl+C causes a graceful shutdown on windows (did already on linux) diff --git a/include/Common.h b/include/Common.h index 99c39bf..dd03108 100644 --- a/include/Common.h +++ b/include/Common.h @@ -27,7 +27,7 @@ public: , Resource("Resources") , MapName("/levels/gridmap_v2/info.json") , MaxPlayers(10) - , Private(false) + , Private(true) , MaxCars(1) , DebugModeEnabled(false) , Port(30814) From f632606d764a2d84296ea61aa05220401fe0b0c4 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Tue, 14 Sep 2021 12:18:31 +0200 Subject: [PATCH 16/22] Heartbeat: Dont report 200 + INVALID_KEY to Sentry --- src/THeartbeatThread.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/THeartbeatThread.cpp b/src/THeartbeatThread.cpp index cbd5eb7..030fe8e 100644 --- a/src/THeartbeatThread.cpp +++ b/src/THeartbeatThread.cpp @@ -52,16 +52,16 @@ void THeartbeatThread::operator()() { int ResponseCode = -1; T = Http::POST(Application::GetBackendHostname(), Target, {}, Body, false, &ResponseCode); - if (T.substr(0, 2) != "20" || ResponseCode != 200) { + if ((T.substr(0, 2) != "20" && ResponseCode != 200) || ResponseCode != 200) { trace("got " + T + " from backend"); SentryReportError(Application::GetBackendHostname() + Target, ResponseCode); std::this_thread::sleep_for(std::chrono::milliseconds(500)); T = Http::POST(Application::GetBackup1Hostname(), Target, {}, Body, false, &ResponseCode); - if (T.substr(0, 2) != "20" || ResponseCode != 200) { + if ((T.substr(0, 2) != "20" && ResponseCode != 200) || ResponseCode != 200) { SentryReportError(Application::GetBackup1Hostname() + Target, ResponseCode); std::this_thread::sleep_for(std::chrono::milliseconds(500)); T = Http::POST(Application::GetBackup2Hostname(), Target, {}, Body, false, &ResponseCode); - if (T.substr(0, 2) != "20" || ResponseCode != 200) { + if ((T.substr(0, 2) != "20" && ResponseCode != 200) || ResponseCode != 200) { warn("Backend system refused server! Server will not show in the public server list."); isAuth = false; SentryReportError(Application::GetBackup2Hostname() + Target, ResponseCode); From 6883c96d332dca6a1da5bae0450b9eeee6e2d09f Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Tue, 14 Sep 2021 12:32:30 +0200 Subject: [PATCH 17/22] Http: Add Sentry error breadcrumbs on internal https POST errors --- src/Http.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Http.cpp b/src/Http.cpp index f9e452a..309b55d 100644 --- a/src/Http.cpp +++ b/src/Http.cpp @@ -127,6 +127,7 @@ std::string Http::POST(const std::string& host, const std::string& target, const bool ok = try_connect_with_protocol(tcp::v4()); if (!ok) { Application::Console().Write("[ERROR] failed to resolve or connect in POST " + host + target); + Sentry.AddErrorBreadcrumb("failed to resolve or connect to " + host + target, __FILE__, std::to_string(__LINE__)); // FIXME: this is ugly. return "-1"; } //} @@ -202,6 +203,7 @@ std::string Http::POST(const std::string& host, const std::string& target, const } catch (const std::exception& e) { Application::Console().Write(e.what()); + Sentry.AddErrorBreadcrumb(e.what(), __FILE__, std::to_string(__LINE__)); // FIXME: this is ugly. return "-1"; } } From 15704abf6ccfbaab85c2f689360608cb0cd42ac2 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Tue, 14 Sep 2021 12:34:28 +0200 Subject: [PATCH 18/22] Http, Heartbeat: Process status < 0 differently, report as "Invalid Response Code" --- src/Http.cpp | 1 + src/THeartbeatThread.cpp | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Http.cpp b/src/Http.cpp index 309b55d..cb06cab 100644 --- a/src/Http.cpp +++ b/src/Http.cpp @@ -210,6 +210,7 @@ std::string Http::POST(const std::string& host, const std::string& target, const // RFC 2616, RFC 7231 static std::map Map = { + { -1, "Invalid Response Code"}, { 100, "Continue" }, { 101, "Switching Protocols" }, { 102, "Processing" }, diff --git a/src/THeartbeatThread.cpp b/src/THeartbeatThread.cpp index 030fe8e..4a854e8 100644 --- a/src/THeartbeatThread.cpp +++ b/src/THeartbeatThread.cpp @@ -36,9 +36,6 @@ void THeartbeatThread::operator()() { Body += "&pps=" + Application::PPS(); auto SentryReportError = [&](const std::string& transaction, int status) { - if (status < 0) { - status = 0; - } auto Lock = Sentry.CreateExclusiveContext(); Sentry.SetContext("heartbeat", { { "response-body", T }, From 57d0eb735e667a980c43417a9d6d00b4f951236b Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Tue, 14 Sep 2021 12:52:19 +0200 Subject: [PATCH 19/22] Add cryptography header for the future --- include/Cryptography.h | 113 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 include/Cryptography.h diff --git a/include/Cryptography.h b/include/Cryptography.h new file mode 100644 index 0000000..d1ff235 --- /dev/null +++ b/include/Cryptography.h @@ -0,0 +1,113 @@ +// Copyright Anonymous275 8/11/2020 + +#pragma once +#include +#include +#include + +namespace Crypto { + +constexpr auto time = __TIME__; +constexpr auto seed = static_cast(time[7]) + static_cast(time[6]) * 10 + static_cast(time[4]) * 60 + static_cast(time[3]) * 600 + static_cast(time[1]) * 3600 + static_cast(time[0]) * 36000; + +// 1988, Stephen Park and Keith Miller +// "Random Number Generators: Good Ones Are Hard To Find", considered as "minimal standard" +// Park-Miller 31 bit pseudo-random number generator, implemented with G. Carta's optimisation: +// with 32-bit math and without division + +template +struct RandomGenerator { +private: + static constexpr unsigned a = 16807; // 7^5 + static constexpr unsigned m = 2147483647; // 2^31 - 1 + + static constexpr unsigned s = RandomGenerator::value; + static constexpr unsigned lo = a * (s & 0xFFFFu); // Multiply lower 16 bits by 16807 + static constexpr unsigned hi = a * (s >> 16u); // Multiply higher 16 bits by 16807 + static constexpr unsigned lo2 = lo + ((hi & 0x7FFFu) << 16u); // Combine lower 15 bits of hi with lo's upper bits + static constexpr unsigned hi2 = hi >> 15u; // Discard lower 15 bits of hi + static constexpr unsigned lo3 = lo2 + hi; + +public: + static constexpr unsigned max = m; + static constexpr unsigned value = lo3 > m ? lo3 - m : lo3; +}; + +template <> +struct RandomGenerator<0> { + static constexpr unsigned value = seed; +}; + +template +struct RandomInt { + static constexpr auto value = RandomGenerator::value % M; +}; + +template +struct RandomChar { + static const char value = static_cast(1 + RandomInt::value); +}; + +template +struct XorString { +private: + const char _key; + std::array _encrypted; + + constexpr Char enc(Char c) const { + return c ^ _key; + } + + Char dec(Char c) const { + return c ^ _key; + } + +public: + template + constexpr XorString(const Char* str, std::index_sequence) + : _key(RandomChar::value) + , _encrypted { enc(str[Is])... } { } + + decltype(auto) decrypt() { + for (size_t i = 0; i < N; ++i) { + _encrypted[i] = dec(_encrypted[i]); + } + _encrypted[N] = '\0'; + return _encrypted.data(); + } +}; + +static auto w_printf = [](const char* fmt, ...) { + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +}; + +static auto w_printf_s = [](const char* fmt, ...) { + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +}; + +static auto w_sprintf_s = [](char* buf, size_t buf_size, const char* fmt, ...) { + va_list args; + va_start(args, fmt); + vsprintf(buf, fmt, args); + va_end(args); +}; + +static auto w_sprintf_s_ret = [](char* buf, size_t buf_size, const char* fmt, ...) { + int ret; + va_list args; + va_start(args, fmt); + ret = vsprintf(buf, fmt, args); + va_end(args); + return ret; +}; + +#define XOR_C(s) [] { constexpr XorCompileTime::XorString< sizeof(s)/sizeof(char) - 1, __COUNTER__, char > expr( s, std::make_index_sequence< sizeof(s)/sizeof(char) - 1>() ); return expr; }().decrypt() +#define XOR_W(s) [] { constexpr XorCompileTime::XorString< sizeof(s)/sizeof(wchar_t) - 1, __COUNTER__, wchar_t > expr( s, std::make_index_sequence< sizeof(s)/sizeof(wchar_t) - 1>() ); return expr; }().decrypt() + +} From fa19ba08e3787b2e5eb0fda2e796578edbcfb852 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Tue, 14 Sep 2021 13:03:27 +0200 Subject: [PATCH 20/22] Sentry: Properly store DSN --- include/Common.h | 5 +++++ include/Cryptography.h | 9 +++++---- include/TConsole.h | 1 + src/TSentry.cpp | 11 +++-------- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/Common.h b/include/Common.h index dd03108..de7aee1 100644 --- a/include/Common.h +++ b/include/Common.h @@ -87,6 +87,7 @@ void RegisterThread(const std::string& str); #define KB 1024 #define MB (KB * 1024) +#define SSU_UNRAW SECRET_SENTRY_URL #define _file_basename std::filesystem::path(__FILE__).filename().string() #define _line std::to_string(__LINE__) @@ -112,9 +113,11 @@ void RegisterThread(const std::string& str); #else #define _this_location (ThreadName() + _file_basename + ":" + _line + " ") #endif +#define SU_RAW SSU_UNRAW #else // !defined(DEBUG) +#define SU_RAW RAWIFY(SSU_UNRAW) #define _this_location (ThreadName()) #endif // defined(DEBUG) @@ -150,3 +153,5 @@ void LogChatMessage(const std::string& name, int id, const std::string& msg); #define Biggest 30000 std::string Comp(std::string Data); std::string DeComp(std::string Compressed); + +#define S_DSN SU_RAW diff --git a/include/Cryptography.h b/include/Cryptography.h index d1ff235..5d710a0 100644 --- a/include/Cryptography.h +++ b/include/Cryptography.h @@ -49,7 +49,7 @@ struct RandomChar { }; template -struct XorString { +struct MangleString { private: const char _key; std::array _encrypted; @@ -64,7 +64,7 @@ private: public: template - constexpr XorString(const Char* str, std::index_sequence) + constexpr MangleString(const Char* str, std::index_sequence) : _key(RandomChar::value) , _encrypted { enc(str[Is])... } { } @@ -107,7 +107,8 @@ static auto w_sprintf_s_ret = [](char* buf, size_t buf_size, const char* fmt, .. return ret; }; -#define XOR_C(s) [] { constexpr XorCompileTime::XorString< sizeof(s)/sizeof(char) - 1, __COUNTER__, char > expr( s, std::make_index_sequence< sizeof(s)/sizeof(char) - 1>() ); return expr; }().decrypt() -#define XOR_W(s) [] { constexpr XorCompileTime::XorString< sizeof(s)/sizeof(wchar_t) - 1, __COUNTER__, wchar_t > expr( s, std::make_index_sequence< sizeof(s)/sizeof(wchar_t) - 1>() ); return expr; }().decrypt() +#define XOR_C(s) [] { constexpr Crypto::MangleString< sizeof(s)/sizeof(char) - 1, __COUNTER__, char > expr( s, std::make_index_sequence< sizeof(s)/sizeof(char) - 1>() ); return expr; }().decrypt() +#define XOR_W(s) [] { constexpr Crypto::MangleString< sizeof(s)/sizeof(wchar_t) - 1, __COUNTER__, wchar_t > expr( s, std::make_index_sequence< sizeof(s)/sizeof(wchar_t) - 1>() ); return expr; }().decrypt() +#define RAWIFY(s) XOR_C(s) } diff --git a/include/TConsole.h b/include/TConsole.h index fcaca26..7fd3c92 100644 --- a/include/TConsole.h +++ b/include/TConsole.h @@ -2,6 +2,7 @@ #include "commandline/commandline.h" #include "TLuaFile.h" +#include "Cryptography.h" #include #include diff --git a/src/TSentry.cpp b/src/TSentry.cpp index ab20e31..f95911e 100644 --- a/src/TSentry.cpp +++ b/src/TSentry.cpp @@ -1,22 +1,17 @@ #include "TSentry.h" #include "Common.h" +#include #include #include -// compile-time length of a string/array -template -constexpr size_t ConstexprLength(char const (&)[N]) { - return N - 1; -} - TSentry::TSentry() { - if constexpr (ConstexprLength(SECRET_SENTRY_URL) == 0) { + if (std::strlen(S_DSN) == 0) { mValid = false; } else { mValid = true; sentry_options_t* options = sentry_options_new(); - sentry_options_set_dsn(options, SECRET_SENTRY_URL); + sentry_options_set_dsn(options, S_DSN); sentry_options_set_debug(options, false); // needs to always be false sentry_options_set_symbolize_stacktraces(options, true); auto ReleaseString = "BeamMP-Server@" + Application::ServerVersion(); From 3837e101e207e0bc130927a1ea121547011f8ac7 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Tue, 14 Sep 2021 13:38:00 +0200 Subject: [PATCH 21/22] CMake: Use gzipped debug info on linux --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 362aebb..0bb0d26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ if (WIN32) elseif (UNIX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -static-libstdc++") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -s -fno-builtin") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -gz -fno-builtin") if (SANITIZE) message(STATUS "sanitize is ON") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLanAGS} -fsanitize=undefined,thread") From 2355327c2130ecb86ee82bd1ba2ac9dac5d1c882 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Tue, 14 Sep 2021 14:38:18 +0200 Subject: [PATCH 22/22] CMake: Fix typo in SANITIZE codepath --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bb0d26..a775eea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,7 @@ elseif (UNIX) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -gz -fno-builtin") if (SANITIZE) message(STATUS "sanitize is ON") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLanAGS} -fsanitize=undefined,thread") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined,thread") endif (SANITIZE) endif ()