Merge pull request #217 from Salanto/logstringer-loading-nonesense

Fix non-functional logger with older config folders.
This commit is contained in:
Rosemary Witchaven 2021-12-16 23:55:03 -06:00 committed by GitHub
commit f26613af6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 17 deletions

View File

@ -96,6 +96,11 @@ public slots:
*/ */
void logConnectionAttempt(const QString& f_ip_address, const QString& f_ipid, const QString& f_hwid); 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: private:
/** /**
@ -121,6 +126,26 @@ private:
* @brief Pointer to full writer. Handles single messages in one file. * @brief Pointer to full writer. Handles single messages in one file.
*/ */
WriterFull* writerFull; 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.
*/
QHash<QString,QString>m_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 #endif //U_LOGGER_H

View File

@ -264,6 +264,12 @@ class Server : public QObject {
bool can_send_ic_messages = true; bool can_send_ic_messages = true;
public slots: public slots:
/**
* @brief Convenience class to call a reload of available configuraiton elements.
*/
void reloadSettings();
/** /**
* @brief Handles a new connection. * @brief Handles a new connection.
* *

View File

@ -469,12 +469,8 @@ void AOClient::cmdReload(int argc, QStringList argv)
Q_UNUSED(argc); Q_UNUSED(argc);
Q_UNUSED(argv); Q_UNUSED(argv);
ConfigManager::reloadSettings(); //Todo: Make this a signal when splitting AOClient and Server.
emit server->reloadRequest(ConfigManager::serverName(), ConfigManager::serverDescription()); server->reloadSettings();
server->updateHTTPAdvertiserConfig();
server->handleDiscordIntegration();
server->m_music_list = ConfigManager::musiclist();
server->m_ipban_list = ConfigManager::iprangeBans();
sendServerMessage("Reloaded configurations"); sendServerMessage("Reloaded configurations");
} }

View File

@ -29,6 +29,7 @@ ULogger::ULogger(QObject* parent) :
writerFull = new WriterFull; writerFull = new WriterFull;
break; break;
} }
loadLogtext();
} }
ULogger::~ULogger() 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) const QString& f_area_name, const QString& f_message)
{ {
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss"); 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); 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) const QString& f_area_name, const QString& f_message)
{ {
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss"); 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); .arg(l_time, f_char_name, f_ooc_name, f_ipid, f_area_name, f_message);
updateAreaBuffer(f_area_name,l_logEntry); 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_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_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); .arg(l_time, l_success, f_ipid, f_char_name, f_ooc_name);
updateAreaBuffer(f_area_name, l_logEntry); 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 // Some commands contain sensitive data, like passwords
// These must be filtered out // These must be filtered out
if (f_command == "login") { 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); .arg(l_time, f_area_name, f_char_name, f_ooc_name, f_ipid);
} }
else if (f_command == "rootpass") { 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); .arg(l_time, f_area_name, f_char_name, f_ooc_name, f_ipid);
} }
else if (f_command == "adduser" && !f_args.isEmpty()) { 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); .arg(l_time, f_area_name, f_char_name, f_ooc_name, f_args.at(0), f_ipid);
} }
else { 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); .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); 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) 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_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); .arg(l_time, f_moderator, f_target_ipid);
updateAreaBuffer("SERVER",l_logEntry); 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) 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_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); .arg(l_time, f_moderator, f_target_ipid, f_duration);
updateAreaBuffer("SERVER",l_logEntry); 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) 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_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); .arg(l_time, f_area_name, f_char_name, f_ooc_name, f_ipid);
updateAreaBuffer(f_area_name, l_logEvent); 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) 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_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); .arg(l_time, f_ip_address, f_ipid, f_hwid);
updateAreaBuffer("SERVER",l_logEntry); 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) void ULogger::updateAreaBuffer(const QString& f_area_name, const QString& f_log_entry)
{ {
QQueue<QString>l_buffer = m_bufferMap.value(f_area_name); QQueue<QString>l_buffer = m_bufferMap.value(f_area_name);

View File

@ -228,6 +228,17 @@ QHostAddress Server::parseToIPv4(QHostAddress f_remote_ip)
return l_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) void Server::broadcast(AOPacket packet, int area_index)
{ {
for (AOClient* client : qAsConst(m_clients)) { for (AOClient* client : qAsConst(m_clients)) {