From 17c571811ac5012cf69306b4cf82c0a73adea491 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sun, 6 Feb 2022 21:37:51 +0100 Subject: [PATCH] Add config option to turn off chat logging When LogChat is disabled, using the `say` command in the console will trigger a "chat message sent!" reply, as UX feedback. --- include/Common.h | 1 + src/Common.cpp | 20 +++++++++++--------- src/TConfig.cpp | 5 +++++ src/TConsole.cpp | 3 +++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/include/Common.h b/include/Common.h index 9e0ee3e..930d329 100644 --- a/include/Common.h +++ b/include/Common.h @@ -49,6 +49,7 @@ public: bool DebugModeEnabled { false }; int Port { 30814 }; std::string CustomIP {}; + bool LogChat { true }; bool SendErrors { true }; bool SendErrorsMessageEnabled { true }; int HTTPServerPort { 8080 }; diff --git a/src/Common.cpp b/src/Common.cpp index a113f74..ac6319c 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -177,16 +177,18 @@ std::string Version::AsString() { } void LogChatMessage(const std::string& name, int id, const std::string& msg) { - std::stringstream ss; - ss << ThreadName(); - ss << "[CHAT] "; - if (id != -1) { - ss << "(" << id << ") <" << name << "> "; - } else { - ss << name << ""; + if (Application::Settings.LogChat) { + std::stringstream ss; + ss << ThreadName(); + ss << "[CHAT] "; + if (id != -1) { + ss << "(" << id << ") <" << name << "> "; + } else { + ss << name << ""; + } + ss << msg; + Application::Console().Write(ss.str()); } - ss << msg; - Application::Console().Write(ss.str()); } std::string GetPlatformAgnosticErrorString() { diff --git a/src/TConfig.cpp b/src/TConfig.cpp index f1c3126..54669eb 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -17,6 +17,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 StrLogChat = "LogChat"; static constexpr std::string_view StrSendErrors = "SendErrors"; static constexpr std::string_view StrSendErrorsMessageEnabled = "SendErrorsShowMessage"; static constexpr std::string_view StrHTTPServerEnabled = "HTTPServerEnabled"; @@ -62,6 +63,8 @@ void TConfig::FlushToFile() { 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"][StrLogChat.data()] = Application::Settings.LogChat; + SetComment(data["General"][StrLogChat.data()].comments(), " Whether to log chat messages in the console / log"); data["General"][StrDebug.data()] = Application::Settings.DebugModeEnabled; data["General"][StrPrivate.data()] = Application::Settings.Private; data["General"][StrPort.data()] = Application::Settings.Port; @@ -158,6 +161,7 @@ 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", StrLogChat, Application::Settings.LogChat); TryReadValue(data, "General", StrSendErrors, Application::Settings.SendErrors); TryReadValue(data, "General", StrSendErrorsMessageEnabled, Application::Settings.SendErrorsMessageEnabled); // HTTP @@ -198,6 +202,7 @@ void TConfig::PrintDebug() { beammp_debug(std::string(StrMap) + ": \"" + Application::Settings.MapName + "\""); beammp_debug(std::string(StrName) + ": \"" + Application::Settings.ServerName + "\""); beammp_debug(std::string(StrDescription) + ": \"" + Application::Settings.ServerDesc + "\""); + beammp_debug(std::string(StrLogChat) + ": \"" + (Application::Settings.LogChat ? "true" : "false") + "\""); beammp_debug(std::string(StrResourceFolder) + ": \"" + Application::Settings.Resource + "\""); beammp_debug(std::string(StrSSLKeyPath) + ": \"" + Application::Settings.SSLKeyPath + "\""); beammp_debug(std::string(StrSSLCertPath) + ": \"" + Application::Settings.SSLCertPath + "\""); diff --git a/src/TConsole.cpp b/src/TConsole.cpp index 3e41345..cf74c60 100644 --- a/src/TConsole.cpp +++ b/src/TConsole.cpp @@ -199,6 +199,9 @@ void TConsole::Command_Say(const std::string& cmd) { if (cmd.size() > 3) { auto Message = cmd.substr(4); LuaAPI::MP::SendChatMessage(-1, Message); + if (!Application::Settings.LogChat) { + Application::Console().WriteRaw("Chat message sent!"); + } } }