Make log entries formatting reloadable and configurable

This commit is contained in:
Salanto 2021-11-21 16:43:55 +01:00
parent 30b769b282
commit a3d89c352c
4 changed files with 113 additions and 12 deletions

View File

@ -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]"

View File

@ -381,6 +381,15 @@ class ConfigManager {
*/ */
static bool passwordCanContainUsername(); 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. * @brief Returns the duration before a client is considered AFK.
* *
@ -520,6 +529,11 @@ private:
*/ */
static QSettings* m_areas; static QSettings* m_areas;
/**
* @brief Stores all adjustable logstrings.
*/
static QSettings* m_logtext;
/** /**
* @brief Pointer to QElapsedTimer to track the uptime of the server. * @brief Pointer to QElapsedTimer to track the uptime of the server.
*/ */

View File

@ -22,6 +22,7 @@
QSettings* ConfigManager::m_settings = new QSettings("config/config.ini", QSettings::IniFormat); 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_discord = new QSettings("config/discord.ini", QSettings::IniFormat);
QSettings* ConfigManager::m_areas = new QSettings("config/areas.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(); ConfigManager::CommandSettings* ConfigManager::m_commands = new CommandSettings();
QElapsedTimer* ConfigManager::m_uptimeTimer = new QElapsedTimer; QElapsedTimer* ConfigManager::m_uptimeTimer = new QElapsedTimer;
QHash<QString,float>* ConfigManager::m_musicList = new QHash<QString,float>; QHash<QString,float>* ConfigManager::m_musicList = new QHash<QString,float>;
@ -239,6 +240,7 @@ void ConfigManager::reloadSettings()
{ {
m_settings->sync(); m_settings->sync();
m_discord->sync(); m_discord->sync();
m_logtext->sync();
} }
QStringList ConfigManager::loadConfigFile(const QString filename) QStringList ConfigManager::loadConfigFile(const QString filename)
@ -522,6 +524,11 @@ bool ConfigManager::passwordCanContainUsername()
return m_settings->value("Password/pass_can_contain_username", false).toBool(); 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() int ConfigManager::afkTimeout()
{ {
bool ok; bool ok;

View File

@ -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) 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 = QStringLiteral("[%1][%5][IC][%2(%3)][%4]%6\n") QString l_logEntry = QString(ConfigManager::LogText("ic") + "\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);
} }
@ -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) 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 = 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); .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);
} }
@ -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_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 = 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); .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);
} }
@ -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 // 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 = 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); .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 = 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); .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 = 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); .arg(l_time, f_area_name, f_char_name, f_ooc_name, f_args.at(0), f_ipid);
} }
else { 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); .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);
@ -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) 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 = QStringLiteral("[%1][%2][KICK][%3]\n") QString l_logEntry = QString(ConfigManager::LogText("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);
} }
@ -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) 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 = 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); .arg(l_time, f_moderator, f_target_ipid, f_duration);
updateAreaBuffer("SERVER",l_logEntry); 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) 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 = 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); .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);
@ -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) 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 = 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); .arg(l_time, f_ip_address, f_ipid, f_hwid);
updateAreaBuffer("SERVER",l_logEntry); updateAreaBuffer("SERVER",l_logEntry);
} }