From a3d89c352cc3a31ccdd8d8e48b7bea456acb9f23 Mon Sep 17 00:00:00 2001 From: Salanto <62221668+Salanto@users.noreply.github.com> Date: Sun, 21 Nov 2021 16:43:55 +0100 Subject: [PATCH] Make log entries formatting reloadable and configurable --- bin/config_sample/text/logtext.ini | 81 ++++++++++++++++++++++++++++++ core/include/config_manager.h | 14 ++++++ core/src/config_manager.cpp | 7 +++ core/src/logger/u_logger.cpp | 23 ++++----- 4 files changed, 113 insertions(+), 12 deletions(-) create mode 100644 bin/config_sample/text/logtext.ini diff --git a/bin/config_sample/text/logtext.ini b/bin/config_sample/text/logtext.ini new file mode 100644 index 0000000..1fa40ba --- /dev/null +++ b/bin/config_sample/text/logtext.ini @@ -0,0 +1,81 @@ +[LogConfiguration] +; This file controls how the log entires look. Editing these can cause logs to become nonfunctional, so be careful. +; Each logtype will mention what data is available and what their formatter is. + +; %1 = Event Time +; %2 = Character Name +; %3 = Out-Of-Courtroom Name +; %4 = Client IPID +; %5 = Area Name +; %6 = Message +ic="[%1][%5][IC][%2(%3)][%4]%6" + +; %1 = Event Time +; %2 = Character Name +; %3 = Out-Of-Courtroom Name +; %4 = Client IPID +; %5 = Area Name +; %6 = Message +ooc="[%1][%5][OOC][%2(%3)][%4]%6" + +; %1 = Event Time +; %2 = Success/Fail +; %3 = Client IPID +; %4 = Character Name +; %5 = Out-Of-Courtroom Name +login="[%1][LOGIN][%2][%3][%4(%5)]" + +; %1 = Event Time +; %2 = Area Name +; %3 = Character Name +; %4 = Out-Of-Courtroom Name +; %5 = Client IPID +cmdlogin="[%1][%2][LOGIN][%5][%3(%4)]" + +; %1 = Event Time +; %2 = Area Name +; %3 = Character Name +; %4 = Out-Of-Courtroom Name +; %5 = Client IPID +cmdrootpass="[%1][%2][ROOTPASS][%5][%3(%4)]" + +; %1 = Event Time +; %2 = Area Name +; %3 = Character Name +; %4 = Out-Of-Courtroom Name +; %5 = Username +; %6 = Client IPID +cmdadduser="[%1][%2][USERADD][%6][%3(%4)]%5" + +; %1 = Event Time +; %2 = Area Name +; %3 = Character Name +; %4 = Out-Of-Courtroom Name +; %5 = Command Name +; %6 = Command Arguments +; %7 = Client IPID +cmd="[%1][%2][CMD][%7][%3(%4)]/%5 %6" + +; %1 = Event Time +; %2 = Moderator Name +; %3 = Kicked Client IPID +kick="[%1][%2][KICK][%3]" + +; %1 = Event Time +; %2 = Moderator name +; %3 = Banned Client IPID +; %4 = Ban Duration +ban="[%1][%2][BAN][%3][%4]" + +; %1 = Event Time +; %2 = Area Name +; %3 = Character Name +; %4 = Out-Of-Courtroom Name +; %5 = Client IPID +modcall="[%1][%2][MODCALL][%5][%3(%4)]" + +; %1 = Event Time +; %2 = IP Address +; %3 = Client IPID +; %4 = Client HWID +connect="[%1][CONNECT][%2][%3][%4]" \ No newline at end of file diff --git a/core/include/config_manager.h b/core/include/config_manager.h index 74e80bc..451d9f1 100644 --- a/core/include/config_manager.h +++ b/core/include/config_manager.h @@ -381,6 +381,15 @@ class ConfigManager { */ static bool passwordCanContainUsername(); + /** + * @brief Returns the logstring for the specified logtype. + * + * @param Name of the logstring we want. + * + * @return See short description. + */ + static QString LogText(QString f_logtype); + /** * @brief Returns the duration before a client is considered AFK. * @@ -520,6 +529,11 @@ private: */ static QSettings* m_areas; + /** + * @brief Stores all adjustable logstrings. + */ + static QSettings* m_logtext; + /** * @brief Pointer to QElapsedTimer to track the uptime of the server. */ diff --git a/core/src/config_manager.cpp b/core/src/config_manager.cpp index 2a2b180..4945dfd 100644 --- a/core/src/config_manager.cpp +++ b/core/src/config_manager.cpp @@ -22,6 +22,7 @@ QSettings* ConfigManager::m_settings = new QSettings("config/config.ini", QSettings::IniFormat); QSettings* ConfigManager::m_discord = new QSettings("config/discord.ini", QSettings::IniFormat); QSettings* ConfigManager::m_areas = new QSettings("config/areas.ini", QSettings::IniFormat); +QSettings* ConfigManager::m_logtext = new QSettings("config/text/logtext.ini", QSettings::IniFormat); ConfigManager::CommandSettings* ConfigManager::m_commands = new CommandSettings(); QElapsedTimer* ConfigManager::m_uptimeTimer = new QElapsedTimer; QHash* ConfigManager::m_musicList = new QHash; @@ -239,6 +240,7 @@ void ConfigManager::reloadSettings() { m_settings->sync(); m_discord->sync(); + m_logtext->sync(); } QStringList ConfigManager::loadConfigFile(const QString filename) @@ -522,6 +524,11 @@ bool ConfigManager::passwordCanContainUsername() return m_settings->value("Password/pass_can_contain_username", false).toBool(); } +QString ConfigManager::LogText(QString f_logtype) +{ + return m_logtext->value("LogConfiguration/" + f_logtype,"").toString(); +} + int ConfigManager::afkTimeout() { bool ok; diff --git a/core/src/logger/u_logger.cpp b/core/src/logger/u_logger.cpp index d4960d0..13b6a0c 100644 --- a/core/src/logger/u_logger.cpp +++ b/core/src/logger/u_logger.cpp @@ -48,8 +48,7 @@ void ULogger::logIC(const QString& f_char_name, const QString& f_ooc_name, const const QString& f_area_name, const QString& f_message) { QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss"); - QString l_logEntry = QStringLiteral("[%1][%5][IC][%2(%3)][%4]%6\n") - .arg(l_time, f_char_name, f_ooc_name, f_ipid, f_area_name, f_message); + QString l_logEntry = QString(ConfigManager::LogText("ic") + "\n").arg(l_time, f_char_name, f_ooc_name, f_ipid, f_area_name, f_message); updateAreaBuffer(f_area_name,l_logEntry); } @@ -57,7 +56,7 @@ void ULogger::logOOC(const QString& f_char_name, const QString& f_ooc_name, cons const QString& f_area_name, const QString& f_message) { QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss"); - QString l_logEntry = QStringLiteral("[%1][%5][OOC][%2(%3)][%4]%6\n") + QString l_logEntry = QString(ConfigManager::LogText("ooc") + "\n") .arg(l_time, f_char_name, f_ooc_name, f_ipid, f_area_name, f_message); updateAreaBuffer(f_area_name,l_logEntry); } @@ -67,7 +66,7 @@ void ULogger::logLogin(const QString& f_char_name, const QString& f_ooc_name, co { QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss"); QString l_success = f_success ? "SUCCESS][" + f_moderator_name : "FAILED][" + f_moderator_name; - QString l_logEntry = QStringLiteral("[%1][LOGIN][%2][%3][%4(%5)]\n") + QString l_logEntry = QString(ConfigManager::LogText("login") + "\n") .arg(l_time, l_success, f_ipid, f_char_name, f_ooc_name); updateAreaBuffer(f_area_name, l_logEntry); } @@ -80,19 +79,19 @@ void ULogger::logCMD(const QString& f_char_name,const QString& f_ipid, const QSt // Some commands contain sensitive data, like passwords // These must be filtered out if (f_command == "login") { - l_logEntry = QStringLiteral("[%1][%2][LOGIN][%5][%3(%4)]\n") + l_logEntry = QString(ConfigManager::LogText("cmdlogin") + "\n") .arg(l_time, f_area_name, f_char_name, f_ooc_name, f_ipid); } else if (f_command == "rootpass") { - l_logEntry = QStringLiteral("[%1][%2][ROOTPASS][%5][%3(%4)]\n") + l_logEntry = QString(ConfigManager::LogText("cmdrootpass") + "\n") .arg(l_time, f_area_name, f_char_name, f_ooc_name, f_ipid); } else if (f_command == "adduser" && !f_args.isEmpty()) { - l_logEntry = QStringLiteral("[%1][%2][USERADD][%6][%3(%4)]%5\n") + l_logEntry = QString(ConfigManager::LogText("adduser") + "\n") .arg(l_time, f_area_name, f_char_name, f_ooc_name, f_args.at(0), f_ipid); } else { - l_logEntry = QStringLiteral("[%1][%2][CMD][%7][%3(%4)]/%5 %6\n") + l_logEntry = QString(ConfigManager::LogText("cmd") + "\n") .arg(l_time, f_area_name, f_char_name, f_ooc_name, f_command, f_args.join(" "), f_ipid); } updateAreaBuffer(f_area_name,l_logEntry); @@ -101,7 +100,7 @@ void ULogger::logCMD(const QString& f_char_name,const QString& f_ipid, const QSt void ULogger::logKick(const QString& f_moderator, const QString& f_target_ipid) { QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss"); - QString l_logEntry = QStringLiteral("[%1][%2][KICK][%3]\n") + QString l_logEntry = QString(ConfigManager::LogText("kick") + "\n") .arg(l_time, f_moderator, f_target_ipid); updateAreaBuffer("SERVER",l_logEntry); } @@ -109,7 +108,7 @@ void ULogger::logKick(const QString& f_moderator, const QString& f_target_ipid) void ULogger::logBan(const QString &f_moderator, const QString &f_target_ipid, const QString &f_duration) { QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss"); - QString l_logEntry = QStringLiteral("[%1][%2][BAN][%3][%4]\n") + QString l_logEntry = QString(ConfigManager::LogText("ban") + "\n") .arg(l_time, f_moderator, f_target_ipid, f_duration); updateAreaBuffer("SERVER",l_logEntry); } @@ -117,7 +116,7 @@ void ULogger::logBan(const QString &f_moderator, const QString &f_target_ipid, c void ULogger::logModcall(const QString &f_char_name, const QString &f_ipid, const QString &f_ooc_name, const QString &f_area_name) { QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss"); - QString l_logEvent = QStringLiteral("[%1][%2][MODCALL][%5][%3(%4)]\n") + QString l_logEvent = QString(ConfigManager::LogText("modcall") + "\n") .arg(l_time, f_area_name, f_char_name, f_ooc_name, f_ipid); updateAreaBuffer(f_area_name, l_logEvent); @@ -129,7 +128,7 @@ void ULogger::logModcall(const QString &f_char_name, const QString &f_ipid, cons void ULogger::logConnectionAttempt(const QString& f_ip_address, const QString& f_ipid, const QString& f_hwid) { QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss"); - QString l_logEntry = QStringLiteral("[%1][CONNECT][%2][%3][%4]\n") + QString l_logEntry = QString(ConfigManager::LogText("connect") + "\n") .arg(l_time, f_ip_address, f_ipid, f_hwid); updateAreaBuffer("SERVER",l_logEntry); }