diff --git a/core/include/logger/u_logger.h b/core/include/logger/u_logger.h index 9d756cb..5d1ec7c 100644 --- a/core/include/logger/u_logger.h +++ b/core/include/logger/u_logger.h @@ -96,6 +96,11 @@ public slots: */ void logConnectionAttempt(const QString& f_ip_address, const QString& f_ipid, const QString& f_hwid); + /** + * @brief Loads template strings for the logger. + */ + void loadLogtext(); + private: /** @@ -121,6 +126,26 @@ private: * @brief Pointer to full writer. Handles single messages in one file. */ WriterFull* writerFull; + + /** + * @brief Table that contains template strings for text-based logger format. + * @details To keep ConfigManager cleaner the logstrings are loaded from an inifile by name. + * This has the problem of lacking defaults that work for all when the file is missing. + * This QMap contains all default values and overwrites them on logger construction. + */ + QHashm_logtext { + {"ic", "[%1][%5][IC][%2(%3)][%4]%6"}, + {"ooc", "[%1][%5][OOC][%2(%3)][%4]%6"}, + {"login", "[%1][LOGIN][%2][%3][%4(%5)]"}, + {"cmdlogin", "[%1][%2][LOGIN][%5][%3(%4)]"}, + {"cmdrootpass", "[%1][%2][ROOTPASS][%5][%3(%4)]"}, + {"cmdadduser", "[%1][%2][USERADD][%6][%3(%4)]%5"}, + {"cmd", "[%1][%2][CMD][%7][%3(%4)]/%5 %6"}, + {"kick", "[%1][%2][KICK][%3]"}, + {"ban", "[%1][%2][BAN][%3][%4]"}, + {"modcall", "[%1][%2][MODCALL][%5][%3(%4)]"}, + {"connect", "[%1][CONNECT][%2][%3][%4]"} + }; }; #endif //U_LOGGER_H diff --git a/core/include/server.h b/core/include/server.h index 26bccbf..7afbb61 100644 --- a/core/include/server.h +++ b/core/include/server.h @@ -264,6 +264,12 @@ class Server : public QObject { bool can_send_ic_messages = true; public slots: + + /** + * @brief Convenience class to call a reload of available configuraiton elements. + */ + void reloadSettings(); + /** * @brief Handles a new connection. * diff --git a/core/src/commands/moderation.cpp b/core/src/commands/moderation.cpp index 45c41d3..26f9b8c 100644 --- a/core/src/commands/moderation.cpp +++ b/core/src/commands/moderation.cpp @@ -469,12 +469,8 @@ void AOClient::cmdReload(int argc, QStringList argv) Q_UNUSED(argc); Q_UNUSED(argv); - ConfigManager::reloadSettings(); - emit server->reloadRequest(ConfigManager::serverName(), ConfigManager::serverDescription()); - server->updateHTTPAdvertiserConfig(); - server->handleDiscordIntegration(); - server->m_music_list = ConfigManager::musiclist(); - server->m_ipban_list = ConfigManager::iprangeBans(); + //Todo: Make this a signal when splitting AOClient and Server. + server->reloadSettings(); sendServerMessage("Reloaded configurations"); } diff --git a/core/src/logger/u_logger.cpp b/core/src/logger/u_logger.cpp index 13b6a0c..358f515 100644 --- a/core/src/logger/u_logger.cpp +++ b/core/src/logger/u_logger.cpp @@ -29,6 +29,7 @@ ULogger::ULogger(QObject* parent) : writerFull = new WriterFull; break; } + loadLogtext(); } ULogger::~ULogger() @@ -48,7 +49,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 = QString(ConfigManager::LogText("ic") + "\n").arg(l_time, f_char_name, f_ooc_name, f_ipid, f_area_name, f_message); + QString l_logEntry = QString(m_logtext.value("ic") + "\n").arg(l_time, f_char_name, f_ooc_name, f_ipid, f_area_name, f_message); updateAreaBuffer(f_area_name,l_logEntry); } @@ -56,7 +57,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 = QString(ConfigManager::LogText("ooc") + "\n") + QString l_logEntry = QString(m_logtext.value("ooc") + "\n") .arg(l_time, f_char_name, f_ooc_name, f_ipid, f_area_name, f_message); updateAreaBuffer(f_area_name,l_logEntry); } @@ -66,7 +67,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 = QString(ConfigManager::LogText("login") + "\n") + QString l_logEntry = QString(m_logtext.value("login") + "\n") .arg(l_time, l_success, f_ipid, f_char_name, f_ooc_name); updateAreaBuffer(f_area_name, l_logEntry); } @@ -79,19 +80,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 = QString(ConfigManager::LogText("cmdlogin") + "\n") + l_logEntry = QString(m_logtext.value("cmdlogin") + "\n") .arg(l_time, f_area_name, f_char_name, f_ooc_name, f_ipid); } else if (f_command == "rootpass") { - l_logEntry = QString(ConfigManager::LogText("cmdrootpass") + "\n") + l_logEntry = QString(m_logtext.value("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 = QString(ConfigManager::LogText("adduser") + "\n") + l_logEntry = QString(m_logtext.value("adduser") + "\n") .arg(l_time, f_area_name, f_char_name, f_ooc_name, f_args.at(0), f_ipid); } else { - l_logEntry = QString(ConfigManager::LogText("cmd") + "\n") + l_logEntry = QString(m_logtext.value("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); @@ -100,7 +101,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 = QString(ConfigManager::LogText("kick") + "\n") + QString l_logEntry = QString(m_logtext.value("kick") + "\n") .arg(l_time, f_moderator, f_target_ipid); updateAreaBuffer("SERVER",l_logEntry); } @@ -108,7 +109,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 = QString(ConfigManager::LogText("ban") + "\n") + QString l_logEntry = QString(m_logtext.value("ban") + "\n") .arg(l_time, f_moderator, f_target_ipid, f_duration); updateAreaBuffer("SERVER",l_logEntry); } @@ -116,7 +117,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 = QString(ConfigManager::LogText("modcall") + "\n") + QString l_logEvent = QString(m_logtext.value("modcall") + "\n") .arg(l_time, f_area_name, f_char_name, f_ooc_name, f_ipid); updateAreaBuffer(f_area_name, l_logEvent); @@ -128,11 +129,22 @@ 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 = QString(ConfigManager::LogText("connect") + "\n") + QString l_logEntry = QString(m_logtext.value("connect") + "\n") .arg(l_time, f_ip_address, f_ipid, f_hwid); updateAreaBuffer("SERVER",l_logEntry); } +void ULogger::loadLogtext() +{ + //All of this to prevent one single clazy warning from appearing. + for (auto iterator = m_logtext.keyBegin(), end = m_logtext.keyEnd(); iterator != end; ++iterator){ + QString l_tempstring = ConfigManager::LogText(iterator.operator*()); + if (!l_tempstring.isEmpty()) { + m_logtext[iterator.operator*()] = l_tempstring; + } + } +} + void ULogger::updateAreaBuffer(const QString& f_area_name, const QString& f_log_entry) { QQueuel_buffer = m_bufferMap.value(f_area_name); diff --git a/core/src/server.cpp b/core/src/server.cpp index 1f1c53f..e70246d 100644 --- a/core/src/server.cpp +++ b/core/src/server.cpp @@ -228,6 +228,17 @@ QHostAddress Server::parseToIPv4(QHostAddress f_remote_ip) return l_remote_ip; } +void Server::reloadSettings() +{ + ConfigManager::reloadSettings(); + emit reloadRequest(ConfigManager::serverName(), ConfigManager::serverDescription()); + updateHTTPAdvertiserConfig(); + handleDiscordIntegration(); + logger->loadLogtext(); + m_music_list = ConfigManager::musiclist(); + m_ipban_list = ConfigManager::iprangeBans(); +} + void Server::broadcast(AOPacket packet, int area_index) { for (AOClient* client : qAsConst(m_clients)) {