mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-07 16:26:04 +00:00
Refactor all references to settings to use new Settings type
Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
This commit is contained in:
@@ -33,8 +33,6 @@
|
||||
#include "CustomAssert.h"
|
||||
#include "Http.h"
|
||||
|
||||
Application::TSettings Application::Settings = {};
|
||||
|
||||
void Application::RegisterShutdownHandler(const TShutdownHandler& Handler) {
|
||||
std::unique_lock Lock(mShutdownHandlersMutex);
|
||||
if (Handler) {
|
||||
@@ -256,7 +254,7 @@ static std::mutex ThreadNameMapMutex {};
|
||||
|
||||
std::string ThreadName(bool DebugModeOverride) {
|
||||
auto Lock = std::unique_lock(ThreadNameMapMutex);
|
||||
if (DebugModeOverride || Application::Settings.DebugModeEnabled) {
|
||||
if (DebugModeOverride || Application::Settings.getAsBool(Settings::Key::General_Debug)) {
|
||||
auto id = std::this_thread::get_id();
|
||||
if (threadNameMap.find(id) != threadNameMap.end()) {
|
||||
// found
|
||||
@@ -268,21 +266,21 @@ std::string ThreadName(bool DebugModeOverride) {
|
||||
|
||||
TEST_CASE("ThreadName") {
|
||||
RegisterThread("MyThread");
|
||||
auto OrigDebug = Application::Settings.DebugModeEnabled;
|
||||
auto OrigDebug = Application::Settings.getAsBool(Settings::Key::General_Debug);
|
||||
|
||||
// ThreadName adds a space at the end, legacy but we need it still
|
||||
SUBCASE("Debug mode enabled") {
|
||||
Application::Settings.DebugModeEnabled = true;
|
||||
Application::Settings.set(Settings::Key::General_Debug, true);
|
||||
CHECK(ThreadName(true) == "MyThread ");
|
||||
CHECK(ThreadName(false) == "MyThread ");
|
||||
}
|
||||
SUBCASE("Debug mode disabled") {
|
||||
Application::Settings.DebugModeEnabled = false;
|
||||
Application::Settings.set(Settings::Key::General_Debug, false);
|
||||
CHECK(ThreadName(true) == "MyThread ");
|
||||
CHECK(ThreadName(false) == "");
|
||||
}
|
||||
// cleanup
|
||||
Application::Settings.DebugModeEnabled = OrigDebug;
|
||||
Application::Settings.set(Settings::Key::General_Debug, OrigDebug);
|
||||
}
|
||||
|
||||
void RegisterThread(const std::string& str) {
|
||||
@@ -296,7 +294,7 @@ void RegisterThread(const std::string& str) {
|
||||
#elif defined(BEAMMP_FREEBSD)
|
||||
ThreadId = std::to_string(getpid());
|
||||
#endif
|
||||
if (Application::Settings.DebugModeEnabled) {
|
||||
if (Application::Settings.getAsBool(Settings::Key::General_Debug)) {
|
||||
std::ofstream ThreadFile(".Threads.log", std::ios::app);
|
||||
ThreadFile << ("Thread \"" + str + "\" is TID " + ThreadId) << std::endl;
|
||||
}
|
||||
@@ -329,7 +327,7 @@ TEST_CASE("Version::AsString") {
|
||||
}
|
||||
|
||||
void LogChatMessage(const std::string& name, int id, const std::string& msg) {
|
||||
if (Application::Settings.LogChat) {
|
||||
if (Application::Settings.getAsBool(Settings::Key::General_LogChat)) {
|
||||
std::stringstream ss;
|
||||
ss << ThreadName();
|
||||
ss << "[CHAT] ";
|
||||
|
||||
Reference in New Issue
Block a user