Implement log message creation

This commit is contained in:
Salanto 2021-08-24 23:25:39 +02:00
parent f2a4f2d3e3
commit 055ef2e6a4
2 changed files with 70 additions and 22 deletions

View File

@ -21,6 +21,7 @@
#include <QObject>
#include <QMap>
#include <QQueue>
#include <QDateTime>
#include "include/config_manager.h"
/**
@ -46,23 +47,26 @@ public slots:
/**
* @brief Adds an IC log entry to the area buffer and writes it to the respective log format.
*/
void logIC(const QString& f_charName, const QString& f_oocName, const QString& f_ipid, const QString& f_areaName);
void logIC(const QString& f_charName, const QString& f_oocName, const QString& f_ipid,
const QString& f_areaName, const QString &f_message);
/**
* @brief Adds an OOC log entry to the area buffer and writes it to the respective log format.
*/
void logOOC(const QString& f_charName, const QString& f_oocName, const QString& f_ipid, const QString& f_areaName);
void logOOC(const QString& f_charName, const QString& f_oocName, const QString& f_ipid,
const QString& f_areaName, const QString& f_message);
/**
* @brief Adds an login attempt to the area buffer and writes it to the respective log format.
*/
void logLogin(const QString& f_charName, const QString& f_oocName, const QString& f_moderatorName,
const QString& f_ipid, bool& f_sucees);
const QString& f_ipid, const QString &f_areaName, const bool& f_success);
/**
* @brief Adds a command usage to the area buffer and writes it to the respective log format.
*/
void logCMD(const QString& f_charName, const QString& f_oocName, const QString f_command, const QString f_Args);
void logCMD(const QString& f_charName, const QString &f_ipid, const QString& f_oocName, const QString f_command,
const QStringList f_args, const QString f_areaName);
/**
* @brief Adds a player kick to the area buffer and writes it to the respective log format.
@ -73,12 +77,12 @@ public slots:
* @brief Adds a player ban to the area buffer and writes it to the respective log format.
*/
void logBan(const QString& f_moderator, const QString& f_targetIPID, const QString& f_targetName, const QString f_targetOOCName,
const QDateTime& duration);
const QString &f_duration);
/**
* @brief Logs any connection attempt to the server, wether sucessful or not.
*/
void logConnectionAttempt(const QString &ip_address, const QString &ipid, const QString &hdid);
void logConnectionAttempt(const QString &f_ip_address, const QString &f_ipid, const QString &f_hdid);
private:
@ -87,7 +91,7 @@ private:
* @param Name of the area which buffer is modified.
* @param Formatted QString to be added into the buffer.
*/
void updateAreaBuffer(const QString& f_areaName, const QString& f_entry);
void updateAreaBuffer(const QString& f_areaName, const QString& f_logEntry);
/**
* @brief Returns the buffer of a respective area. Primarily used by the Discord Webhook.

View File

@ -23,51 +23,95 @@ ULogger::ULogger(QObject* parent) :
}
void ULogger::logIC(const QString& f_charName, const QString& f_oocName, const QString& f_ipid, const QString& f_areaName)
void ULogger::logIC(const QString& f_charName, const QString& f_oocName, const QString& f_ipid,
const QString& f_areaName, 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")
.arg(l_time, f_charName, f_oocName, f_ipid, f_areaName, f_message);
updateAreaBuffer(f_areaName,l_logEntry);
}
void ULogger::logOOC(const QString& f_charName, const QString& f_oocName, const QString& f_ipid, const QString& f_areaName)
void ULogger::logOOC(const QString& f_charName, const QString& f_oocName, const QString& f_ipid,
const QString& f_areaName, 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")
.arg(l_time, f_charName, f_oocName, f_ipid, f_areaName, f_message);
updateAreaBuffer(f_areaName,l_logEntry);
}
void ULogger::logLogin(const QString& f_charName, const QString& f_oocName, const QString& f_moderatorName,
const QString& f_ipid, bool& f_sucees)
const QString& f_ipid, const QString& f_areaName, const bool &f_success)
{
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_success = f_success ? "[SUCCESS]" + f_moderatorName : "[FAILED]" + f_moderatorName;
QString l_logEntry = QStringLiteral("[%1][LOGON][%2][%3][%4(%5)]")
.arg(l_time, l_success, f_ipid, f_charName, f_oocName);
updateAreaBuffer(f_areaName, l_logEntry);
}
void ULogger::logCMD(const QString& f_charName, const QString& f_oocName, const QString f_command, const QString f_Args)
void ULogger::logCMD(const QString& f_charName,const QString& f_ipid, const QString& f_oocName, const QString f_command,
const QStringList f_args, const QString f_areaName)
{
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEntry;
// 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)]")
.arg(l_time, f_areaName, f_charName, f_oocName, f_ipid);
}
else if (f_command == "rootpass") {
l_logEntry = QStringLiteral("[%1][%2][ROOTPASS][%5][%3(%4)]")
.arg(l_time, f_areaName, f_charName, f_oocName, f_ipid);
}
else if (f_command == "adduser" && !f_args.isEmpty()) {
l_logEntry = QStringLiteral("[%1][%2][USERADD][%6][%3(%4)]%5")
.arg(l_time, f_areaName, f_charName, f_oocName, f_args.at(0), f_ipid);
}
else {
l_logEntry = QStringLiteral("[%1][%2][CMD][%7][%3(%4)][%5]%6")
.arg(l_time, f_areaName, f_charName, f_oocName, f_command, f_args.join(" "), f_ipid);
}
updateAreaBuffer(f_areaName,l_logEntry);
}
void ULogger::logKick(const QString& f_moderator, const QString& f_targetIPID, const QString& f_targetName, const QString f_targetOOCName)
{
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEntry = QStringLiteral("[%1][KICK][%2][%3][%4(%5)]")
.arg(l_time, f_moderator, f_targetIPID, f_targetName, f_targetOOCName);
updateAreaBuffer("SERVER",l_logEntry);
}
void ULogger::logBan(const QString &f_moderator, const QString &f_targetIPID, const QString &f_targetName, const QString f_targetOOCName, const QDateTime &duration)
void ULogger::logBan(const QString &f_moderator, const QString &f_targetIPID, const QString &f_targetName, const QString f_targetOOCName, const QString &f_duration)
{
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEntry = QStringLiteral("[%1][BAN][%2][%3(%4)][%5][%6]")
.arg(l_time, f_moderator, f_targetName, f_targetOOCName, f_targetIPID, f_duration);
updateAreaBuffer("SERVER",l_logEntry);
}
void ULogger::logConnectionAttempt(const QString& ip_address, const QString& ipid, const QString& hdid)
void ULogger::logConnectionAttempt(const QString& f_ip_address, const QString& f_ipid, const QString& f_hdid)
{
QString l_time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
QString l_logEntry = QStringLiteral("[%1][CONNECT][%2][%3][%4]\n")
.arg(l_time, f_ip_address, f_ipid, f_hdid);
updateAreaBuffer("SERVER",l_logEntry);
}
void ULogger::updateAreaBuffer(const QString& f_areaName, const QString& f_entry)
void ULogger::updateAreaBuffer(const QString& f_areaName, const QString& f_logEntry)
{
QQueue<QString>l_buffer = m_bufferMap.value(f_areaName);
if (l_buffer.length() <= ConfigManager::logBuffer()) {
l_buffer.enqueue(f_entry);
l_buffer.enqueue(f_logEntry);
}
else {
l_buffer.dequeue();
l_buffer.enqueue(f_entry);
l_buffer.enqueue(f_logEntry);
}
m_bufferMap.insert(f_areaName, l_buffer);
}