summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarkus Mittendrein <git@maxmitti.tk>2015-11-10 21:48:29 +0100
committerMarkus Mittendrein <git@maxmitti.tk>2015-11-10 21:48:29 +0100
commite4ccb9c3e8baae8632d52ec7158f64eabc2b4d76 (patch)
treee3917f7036eacf720940e52337961b56022c6047 /src
parent7ceb033275b40e72142db6395aa4fc5c5f669cd3 (diff)
downloadmanager-e4ccb9c3e8baae8632d52ec7158f64eabc2b4d76.tar.gz
manager-e4ccb9c3e8baae8632d52ec7158f64eabc2b4d76.zip
Add logging
Diffstat (limited to 'src')
-rw-r--r--src/CRSMConfig.hpp12
-rw-r--r--src/CRSMLogging.cpp192
-rw-r--r--src/CRSMLogging.hpp42
-rw-r--r--src/CrServerManager.pro6
-rw-r--r--src/crsm.cpp146
-rw-r--r--src/crsm.hpp6
6 files changed, 366 insertions, 38 deletions
diff --git a/src/CRSMConfig.hpp b/src/CRSMConfig.hpp
index 921e56e..3b43b6c 100644
--- a/src/CRSMConfig.hpp
+++ b/src/CRSMConfig.hpp
@@ -16,6 +16,12 @@ public:
} CRSM;
struct {
+ String Folder = "CrServerManager.logs";
+ String MainLog = "CRSM.log";
+ String TimestampFormat = "dd.MM.yyyy [hh:mm:ss] ";
+ } Logging;
+
+ struct {
struct {
String Arguments = "/fullscreen /lobby:300 /nosignup Objects.c4d";
String Config = "config";
@@ -101,6 +107,12 @@ public:
+ ConfigVal(Logging.Folder),
+ ConfigVal(Logging.MainLog),
+ ConfigVal(Logging.TimestampFormat),
+
+
+
ConfigVal(Clonk.Server.Arguments),
ConfigVal(Clonk.Server.Config),
ConfigVal(Clonk.Server.Executable),
diff --git a/src/CRSMLogging.cpp b/src/CRSMLogging.cpp
new file mode 100644
index 0000000..ca1badd
--- /dev/null
+++ b/src/CRSMLogging.cpp
@@ -0,0 +1,192 @@
+#include "CRSMLogging.hpp"
+#include "crsm.hpp"
+
+#include <QDateTime>
+#include <QDir>
+
+CRSMLogging::CRSMLogging()
+{
+
+}
+
+QString CRSMLogging::setLogFolder(const QString &folder)
+{
+ logFolder = folder;
+ QDir logDir(logFolder);
+ if(!logDir.mkpath(folder))
+ {
+ return "Warning: Could not create Logging.Folder.\n";
+ }
+
+ if(!mainLogName.isEmpty())
+ {
+ setMainLog(mainLogName);
+ }
+
+ foreach(QFile* file, logFiles)
+ {
+ file->close();
+ delete file;
+ }
+ logFiles.clear();
+
+ if(!QDir(logFolder + cmdLogsFolder).exists() && !logDir.mkdir(cmdLogsFolder))
+ {
+ return "Warning: Could not create Folder for command-logs.\n";
+ }
+
+ if(!QDir(logFolder + ircLogsFolder).exists() && !logDir.mkdir(ircLogsFolder))
+ {
+ return "Warning: Could not create Folder for irc-logs.\n";
+ }
+
+ if(!QDir(logFolder + modLogsFolder).exists() && !logDir.mkdir(modLogsFolder))
+ {
+ return "Warning: Could not create Folder for moderator-logs.\n";
+ }
+
+ if(!QDir(logFolder + userLogsFolder).exists() && !logDir.mkdir(userLogsFolder))
+ {
+ return "Warning: Could not create Folder for user-logs.\n";
+ }
+
+ return "";
+}
+
+QString CRSMLogging::setMainLog(const QString &fileName)
+{
+ mainLogName = fileName;
+ mainLog.close();
+ mainLog.setFileName(logFolder + fileName);
+ if(!mainLog.open(QFile::WriteOnly | QFile::Append | QFile::Unbuffered))
+ {
+ return "Warning: Could not open MainLog-file for writing: " + mainLog.errorString() + "\n";
+ }
+ return "";
+}
+
+void CRSMLogging::setTimestampFormat(const QString &format)
+{
+ timestampFormat = format;
+}
+
+void CRSMLogging::log(const QString &message, const QString logFile)
+{
+ QFile* file = (logFile.isEmpty()) ? &mainLog : logFiles.value(logFile, nullptr);
+ if(file == nullptr)
+ {
+ file = logFiles[logFile] = new QFile;
+ file->setFileName(logFolder + logFile);
+ file->open(QFile::WriteOnly | QFile::Append | QFile::Unbuffered);
+ }
+ if(file->isOpen())
+ {
+ file->write(QDateTime::currentDateTime().toString(timestampFormat).toUtf8());
+ file->write(message.toUtf8());
+ }
+}
+
+void CRSMLogging::clonkUserLog(const QString &message, const ClientInfo &client, bool action, bool command, bool response)
+{
+ if(action)
+ {
+ log("Action: " + message + "\n", userLogsFolder + client.toString());
+ }
+ else if(command)
+ {
+ log("Command: " + message + "\n", userLogsFolder + client.toString());
+ }
+ else if(response)
+ {
+ log("Response: " + message + "\n", userLogsFolder + client.toString());
+ }
+ else
+ {
+ log("Message: " + message + "\n", userLogsFolder + client.toString());
+ }
+}
+
+void CRSMLogging::modLog(const QString &message, const ClientInfo &client, const QString &modName, bool response)
+{
+ if(response)
+ {
+ log("Response: " + client.toString(true) + " " + message + "\n", modLogsFolder + modName);
+ }
+ else
+ {
+ log("Command: " + client.toString(true) + " " + message + "\n", modLogsFolder + modName);
+ }
+}
+
+void CRSMLogging::commandLog(const QString &message, const ClientInfo &client, bool response)
+{
+ if(response)
+ {
+ log("Response: " + message.trimmed() + "\n", cmdLogsFolder + client.toString());
+ }
+ else
+ {
+ log("Command: " + message + "\n", cmdLogsFolder + client.toString());
+ }
+ if(client.interface == Clonk)
+ {
+ clonkUserLog(message, client, false, true, response);
+ }
+ else if(client.interface == IRC)
+ {
+ ircUserLog(message.trimmed(), client, false, response ? "¡Response!" : "¿Command?", false, false);
+ }
+}
+
+void CRSMLogging::ircLog(const QString& message, const QString &nick, bool query, QString channel, bool action, bool notice, bool response)
+{
+ if(query)
+ {
+ if(notice)
+ {
+ log("Notice: " + message + "\n", ircLogsFolder + nick);
+ }
+ else if(action)
+ {
+ log("Action: " + message + "\n", ircLogsFolder + nick);
+ }
+ else if(response)
+ {
+ log("Response: " + message + "\n", ircLogsFolder + nick);
+ }
+ else
+ {
+ log("Message: " + message + "\n", ircLogsFolder + nick);
+ }
+ }
+ else
+ {
+ log(formatIrcNick(nick, true, "", action, notice) + " " + message + "\n", ircLogsFolder + channel);
+ }
+}
+
+void CRSMLogging::ircUserLog(const QString &message, const ClientInfo &client, bool query, const QString& channel, bool action, bool notice)
+{
+ log(formatIrcNick(client.nick, query, channel, action, notice) + " " + message + "\n", userLogsFolder + client.toString());
+}
+
+void CRSMLogging::clonkChatLog(const QString &message)
+{
+ log(message + "\n", clonkChatLogFile);
+}
+
+void CRSMLogging::clonkLog(const QString &message)
+{
+ log(message + "\n", clonkLogFile);
+}
+
+void CRSMLogging::scenLog(const ScenarioSettings &scen)
+{
+ log(scen.name + (scen.league ? " league" : " no league") + " by " + scen.wishClient.toString() + "\n", scensLogFile);
+}
+
+QString CRSMLogging::formatIrcNick(const QString &nick, bool noChannel, const QString &channel, bool action, bool notice)
+{
+ return (notice ? "-" : (action ? "*" : "<")) + (noChannel ? "" : channel + ":") + nick + (notice ? "-" : (action ? "*" : ">"));
+}
+
diff --git a/src/CRSMLogging.hpp b/src/CRSMLogging.hpp
new file mode 100644
index 0000000..7f30b3e
--- /dev/null
+++ b/src/CRSMLogging.hpp
@@ -0,0 +1,42 @@
+#pragma once
+
+#include <QFile>
+#include <QMap>
+#include <QString>
+
+#include "ClientInfo.hpp"
+
+class ScenarioSettings;
+
+class CRSMLogging
+{
+ QString logFolder;
+ QString mainLogName;
+ QString timestampFormat;
+ QFile mainLog;
+ QMap<QString, QFile*> logFiles;
+
+ const char* cmdLogsFolder = "cmd/";
+ const char* ircLogsFolder = "irc/";
+ const char* modLogsFolder = "mod/";
+ const char* userLogsFolder = "usr/";
+ const char* clonkLogFile = "clonk";
+ const char* clonkChatLogFile = "clonk.chat";
+ const char* scensLogFile = "scenarios";
+public:
+ CRSMLogging();
+
+ QString setLogFolder(const QString& folder);
+ QString setMainLog(const QString& fileName);
+ void setTimestampFormat(const QString& format);
+ void log(const QString& message, const QString logFile = "");
+ void clonkUserLog(const QString& message, const ClientInfo& client, bool action, bool command = false, bool response = false);
+ void modLog(const QString& message, const ClientInfo& client, const QString& modName, bool response);
+ void commandLog(const QString& message, const ClientInfo& client, bool response);
+ void ircLog(const QString& message, const QString &nick, bool query = false, QString channel = "", bool action = false, bool notice = false, bool response = false);
+ void ircUserLog(const QString& message, const ClientInfo &client, bool query, const QString &channel, bool action, bool notice);
+ void clonkChatLog(const QString& message);
+ void clonkLog(const QString& message);
+ void scenLog(const ScenarioSettings& scen);
+ QString formatIrcNick(const QString& nick, bool noChannel, const QString& channel, bool action, bool notice);
+};
diff --git a/src/CrServerManager.pro b/src/CrServerManager.pro
index 4c27668..57d5f3b 100644
--- a/src/CrServerManager.pro
+++ b/src/CrServerManager.pro
@@ -23,7 +23,8 @@ SOURCES += main.cpp \
ConfigBase.cpp \
Util.cpp \
CRSMStats.cpp \
- CRSMPackCompatibility.cpp
+ CRSMPackCompatibility.cpp \
+ CRSMLogging.cpp
HEADERS += \
CmdFunctionRef.hpp \
@@ -34,7 +35,8 @@ HEADERS += \
ConfigBase.hpp \
Util.hpp \
CRSMStats.hpp \
- CRSMPackCompatibility.hpp
+ CRSMPackCompatibility.hpp \
+ CRSMLogging.hpp
equals(QT_ARCH, "x86_64"):linux-*: DEFINES += Q_OS_LINUX64
QMAKE_CXXFLAGS *= -std=c++11 -Wall -Wextra -Werror -Wunused
diff --git a/src/crsm.cpp b/src/crsm.cpp
index a4ccbfa..92ee2e4 100644
--- a/src/crsm.cpp
+++ b/src/crsm.cpp
@@ -15,8 +15,6 @@ CRSM::CRSM(QObject *parent) :
{
qsrand(QDateTime::currentMSecsSinceEpoch());
codec = QTextCodec::codecForName("Windows-1252");
- qout = new QTextStream(stdout, QIODevice::WriteOnly | QIODevice::Unbuffered);
- qout->setCodec(QTextCodec::codecForName("UTF-8"));
outputBuffer.setFileName(MGMT_BUFFER_FILENAME);
outputBuffer.open(QFile::WriteOnly | QFile::Unbuffered);
@@ -75,10 +73,6 @@ CRSM::CRSM(QObject *parent) :
afkAdminTimer.setSingleShot(true);
connect(&afkAdminTimer, SIGNAL(timeout()), this, SLOT(afkAdminTimeout()));
- QFile *reallog = new QFile(Config.Auto.Volatile.Clonk.Directory + "CRSM.log");
- reallog->open(QIODevice::Append | QIODevice::Text);
- logstream.setDevice(reallog);
-
ok = true;
}
@@ -117,24 +111,24 @@ void CRSM::readServerOutput()
if(what.isEmpty())
return;
- logstream << what.trimmed() << endl;
-
if(Config.IRC.Use)
{
foreach(const QString &mess, what.split("\n", QString::SkipEmptyParts))
foreach(const QString &mod, ircModIOList)
{
- connection->sendCommand(IrcCommand::createNotice(mod, mess));
+ sendIrcMessage(mess, mod, false, true);
}
}
out(what.trimmed() + "\n");
if(!timeRemover.exactMatch(what))
return;
what = timeRemover.cap(2).trimmed();
+ Log.clonkLog(what);
static QRegExp userexp("^\\s*(\\*?)\\s*<(.*)\\|(\\d+)\\|([^>]*)>\\s+(.*)$");
if(userexp.exactMatch(what))
{
+ Log.clonkChatLog(what);
bool isMeMessage = (userexp.cap(1) == "*");
QString user = userexp.cap(4);
QString pcName = userexp.cap(2);
@@ -142,6 +136,7 @@ void CRSM::readServerOutput()
if(pcName != Config.Auto.Volatile.Clonk.ServerPCName)
{
ClientInfo& info = getClientInfo(pcName, cuid, user);
+ Log.clonkUserLog(what, info, isMeMessage);
if(info == Session.Clonk.Admin)
{
checkActivity(Session.Clonk.Admin);
@@ -164,12 +159,12 @@ void CRSM::readServerOutput()
}
else if(Session.IRC.UseIngameChat)
{
- connection->sendCommand(IrcCommand::createMessage(Config.IRC.IngameChannel, "[Clonk]<" + user + "> " + msg));
+ sendIrcMessage("[Clonk]<" + user + "> " + msg, Config.IRC.IngameChannel, false, false);
}
}
else if(Session.IRC.UseIngameChat)
{
- connection->sendCommand(IrcCommand::createCtcpAction(Config.IRC.IngameChannel, "[Clonk] " + user + " " + msg));
+ sendIrcMessage("[Clonk] " + user + " " + msg, Config.IRC.IngameChannel, true, false);
}
}
}
@@ -188,7 +183,7 @@ void CRSM::readServerOutput()
timer->start(1000);
if(Session.IRC.UseIngameChat)
{
- connection->sendCommand(IrcCommand::createMessage(Config.IRC.IngameChannel, "[Clonk] " + info.toString() + " verbunden."));
+ sendIrcMessage("[Clonk] " + info.toString() + " verbunden.", Config.IRC.IngameChannel, false, false);
}
}
}
@@ -246,7 +241,7 @@ void CRSM::readServerOutput()
if(Session.IRC.UseIngameChat)
{
- connection->sendCommand(IrcCommand::createMessage(Config.IRC.IngameChannel, "[Clonk] " + info.toString() + " entfernt" + leaveExp.cap(2)));
+ sendIrcMessage("[Clonk] " + info.toString() + " entfernt" + leaveExp.cap(2), Config.IRC.IngameChannel, false, false);
}
if(info == Session.Clonk.Admin)
@@ -300,10 +295,10 @@ void CRSM::readServerOutput()
out(gameRegisterFailMessage.arg(reason));
if(Config.IRC.Use)
{
- connection->sendCommand(IrcCommand::createMessage(Config.IRC.Channel, gameRegisterFailMessage.arg(reason)));
+ sendIrcMessage(gameRegisterFailMessage.arg(reason), Config.IRC.Channel, false, false);
if(Config.IRC.UseIngameChat)
{
- connection->sendCommand(IrcCommand::createMessage(Config.IRC.IngameChannel, gameRegisterFailMessage.arg(reason)));
+ sendIrcMessage(gameRegisterFailMessage.arg(reason), Config.IRC.IngameChannel, false, false);
}
}
}
@@ -367,16 +362,15 @@ void CRSM::scenarioFinished()
void CRSM::ircMessageReceived(IrcMessage *message)
{
- if(message->isOwn())
- return;
if(message->type() == IrcMessage::Notice)
{
+ IrcNoticeMessage* noticeMessage = (IrcNoticeMessage*)message;
if(message->nick() == "NickServ")
{
QStringList split = message->parameters().at(1).split(' ', QString::SkipEmptyParts);
- if(((IrcNoticeMessage*)message)->content().contains("nickname is registered"))
+ if(noticeMessage->content().contains("nickname is registered"))
{
- connection->sendCommand(IrcCommand::createMessage("NickServ", "IDENTIFY " + Config.IRC.Nick + " " + Config.IRC.Password));
+ sendIrcMessage("IDENTIFY " + Config.IRC.Nick + " " + Config.IRC.Password, "NickServ", false, false);
}
else if(split.first() == "STATUS")
{
@@ -393,11 +387,22 @@ void CRSM::ircMessageReceived(IrcMessage *message)
}
}
}
+ Log.ircLog(noticeMessage->content(), noticeMessage->nick(), noticeMessage->isPrivate(), noticeMessage->target(), false, true);
+ if(!message->isOwn())
+ {
+ Log.ircUserLog(noticeMessage->content(), ClientInfo::ircClient(noticeMessage->nick(), noticeMessage->target()), noticeMessage->isPrivate(), noticeMessage->target(), false, true);
+ }
}
else if(message->type() == IrcMessage::Private)
{
IrcPrivateMessage* privMessage = (IrcPrivateMessage*)message;
QString target = privMessage->target();
+ Log.ircLog(privMessage->content(), privMessage->nick(), privMessage->isPrivate(), privMessage->target(), privMessage->isAction(), false);
+ if(message->isOwn())
+ {
+ return;
+ }
+ Log.ircUserLog(privMessage->content(), ClientInfo::ircClient(privMessage->nick(), privMessage->target()), privMessage->isPrivate(), privMessage->target(), privMessage->isAction(), false);
if(target == connection->nickName())
target = message->nick();
QString mess = privMessage->content();
@@ -464,11 +469,15 @@ void CRSM::ircMessageReceived(IrcMessage *message)
}
}
}
+ else if(message->isOwn())
+ {
+ return;
+ }
else if(message->type() == IrcMessage::Join)
{
IrcJoinMessage* joinMessage = (IrcJoinMessage*) message;
QString joinChannel = joinMessage->channel();
- connection->sendCommand(IrcCommand::createMessage(joinChannel, "Hallo " + message->nick() + "!"));
+ sendIrcMessage("Hallo " + message->nick() + "!", joinChannel, false, false);
if(joinChannel == Config.IRC.IngameChannel && Session.IRC.UseIngameChat)
{
writeToServer("[IRC] " + message->nick() + " hat den Channel betreten." + "\n");
@@ -683,6 +692,7 @@ void CRSM::startScen(const ScenarioSettings &scen, QStringList argList)
processManager->setWorkingDirectory(Config.Auto.Volatile.Clonk.Directory);
out(Packs.linkScenarioPacks(filename));
processManager->start(Config.Clonk.Server.Executable, argList);
+ Log.scenLog(scen);
}
void CRSM::readConfig()
@@ -769,7 +779,7 @@ void CRSM::listC4Folders()
}
}
}
- out(QString(3, '\b') + ": Finished\n");
+ out("Finished\n");
}
void CRSM::cleanUp()
@@ -1049,7 +1059,7 @@ void CRSM::informModsAboutAliasWish()
{
foreach(const QString& mod, ircMods)
{
- connection->sendCommand(IrcCommand::createNotice(mod, "Ein neuer Aliaswunsch ist verfügbar. Insgesamt verfügbar: " + QString::number(Config.Auto.Hosting.AliasWishes.size())));
+ sendIrcMessage("Ein neuer Aliaswunsch ist verfügbar. Insgesamt verfügbar: " + QString::number(Config.Auto.Hosting.AliasWishes.size()), mod, false, true);
}
}
@@ -1057,13 +1067,13 @@ void CRSM::editAliasWishes()
{
if(Config.Auto.Hosting.AliasWishes.isEmpty())
{
- connection->sendCommand(IrcCommand::createMessage(aliasWishEditor, "Keine Aliaswünsche " + (currentAliasWish == "" ? QString("") : QString("mehr ")) + "vorhanden."));
+ sendIrcMessage("Keine Aliaswünsche " + (currentAliasWish == "" ? QString("") : QString("mehr ")) + "vorhanden.", aliasWishEditor, false, false);
stopAliasWishEditing();
}
else
{
currentAliasWish = Config.Auto.Hosting.AliasWishes.firstKey();
- connection->sendCommand(IrcCommand::createMessage(aliasWishEditor, currentAliasWish + " = " + Config.Auto.Hosting.AliasWishes[currentAliasWish] + " [Ja|Nein|Stop]"));
+ sendIrcMessage(currentAliasWish + " = " + Config.Auto.Hosting.AliasWishes[currentAliasWish] + " [Ja|Nein|Stop]", aliasWishEditor, false, false);
}
}
@@ -1080,13 +1090,13 @@ void CRSM::editAliasWishes(const QString &message)
}
else if(message.toLower() == "s" || message.toLower() == "stop")
{
- connection->sendCommand(IrcCommand::createMessage(aliasWishEditor, "Aliaswunsch-Bearbeitung gestoppt."));
+ sendIrcMessage("Aliaswunsch-Bearbeitung gestoppt.", aliasWishEditor, false, false);
stopAliasWishEditing();
return;
}
else
{
- connection->sendCommand(IrcCommand::createMessage(aliasWishEditor, "\"" + message + "\" ist keine Antwortmöglichkeit. Antwortmöglichkeiten: [Ja|Nein|Stop]"));
+ sendIrcMessage("\"" + message + "\" ist keine Antwortmöglichkeit. Antwortmöglichkeiten: [Ja|Nein|Stop]", aliasWishEditor, false, false);
}
editAliasWishes();
}
@@ -1245,6 +1255,7 @@ CmdFunctionRef* CRSM::findCommand(QStringList&& cmd, ClientInterface interface,
bool CRSM::cmd(const QString& cmd, const ClientInfo &client)
{
+ Log.commandLog(cmd, client, false);
CmdFunctionRef* cmdPtr;
QString realCmd = cmd;
if((cmdPtr = findCommand(cmd, client.interface, realCmd)) != nullptr)
@@ -1439,11 +1450,11 @@ void CRSM::respond(const ClientInfo &client, const QString &message, const Respo
{
case RespondType::Normal:
case RespondType::Private:
- connection->sendCommand(IrcCommand::createMessage(type == Normal ? client.target : client.nick, line));
+ sendIrcMessage(line, type == Normal ? client.target : client.nick, false, false);
break;
case RespondType::Notice:
case RespondType::PrivateNotice:
- connection->sendCommand(IrcCommand::createNotice(type == Notice ? client.target : client.nick, line));
+ sendIrcMessage(line, type == Notice ? client.target : client.nick, false, true);
break;
}
}
@@ -1454,12 +1465,17 @@ void CRSM::respond(const ClientInfo &client, const QString &message, const Respo
case Auto: //just to avoid the compiler warning
break;
}
+ Log.commandLog(message, client, true);
+ if(clientUserType(client) == Moderator)
+ {
+ Log.modLog(message, client, clientModName(client), true);
+ }
}
void CRSM::ircCheckUserStatus(const ClientInfo &requester, const ClientInfo &subject, IrcCheckCallback callback)
{
ircStatusFifos[subject.nick].append(qMakePair<ClientInfo, IrcCheckCallback>(requester, callback));
- connection->sendCommand(IrcCommand::createMessage("NickServ", "STATUS " + subject.nick));
+ sendIrcMessage("STATUS " + subject.nick, "NickServ", false, false);
}
void CRSM::setIngameAdmin(const ClientInfo &client, const QString& newAdmin)
@@ -1515,8 +1531,11 @@ void CRSM::setIngameAdmin(const ClientInfo &client, const QString& newAdmin)
void CRSM::out(const QString &text)
{
- *qout << text;
- qout->flush();
+ if(text.isEmpty())
+ {
+ return;
+ }
+ Log.log(text);
if(managementConnections.size() == 0)
{
outputBuffer.write(text.toUtf8());
@@ -1628,7 +1647,7 @@ void CRSM::afkAdminTimeout()
writeToServer("Der Rundenadmin war zu lange AFK und wurde freigegeben.\n");
if(Session.IRC.UseIngameChat)
{
- connection->sendCommand(IrcCommand::createMessage(Config.IRC.IngameChannel, "Der Rundenadmin war zu lange AFK und wurde freigegeben.\n"));
+ sendIrcMessage("Der Rundenadmin war zu lange AFK und wurde freigegeben.\n", Config.IRC.IngameChannel, false, false);
}
Session.AfkAdmin = false;
}
@@ -1661,6 +1680,7 @@ void CRSM::applyConfig()
afkAdminTimer.setInterval(Config.Hosting.AfkAdminTime * 1000);
Config.CRSM.ListFolder = QDir(Config.CRSM.ListFolder).absolutePath() + QDir::separator();
+ Config.Logging.Folder = QDir(Config.Logging.Folder).absolutePath() + QDir::separator();
if(!QDir(Config.CRSM.ListFolder).exists())
{
@@ -1739,6 +1759,10 @@ void CRSM::applyConfig()
Session.IRC.UseIngameChat = false;
}
+ out(Log.setLogFolder(Config.Logging.Folder));
+ out(Log.setMainLog(Config.Logging.MainLog));
+ Log.setTimestampFormat(Config.Logging.TimestampFormat);
+
setupCmds();
out(Stats.read(Config.CRSM.StatsFile));
out(Packs.read(Config.CRSM.PacksFile, Config.Auto.Volatile.Clonk.Directory));
@@ -1753,6 +1777,11 @@ QString CRSM::scenarioFileName(QString name)
CmdResult CRSM::callCommand(const CmdFunctionRef &func, const QString &args, const ClientInfo &client, UserType userType)
{
+ if(userType == Moderator)
+ {
+
+ Log.modLog(func.name + " " + args, client, clientModName(client), false);
+ }
CmdResult ret = (this->*func.func)(func.name, args, client, userType);
Stats.AddCommandResult(client, func.name, ret);
return ret;
@@ -1850,6 +1879,55 @@ void CRSM::substituteCommandAlias(QString &command)
}
}
+QString CRSM::clientModName(const ClientInfo &client)
+{
+ if(client.interface == IRC)
+ {
+ return Config.IRC.Moderators.value(client.nick);
+ }
+ else if(client.interface == Clonk)
+ {
+ return Config.Clonk.Chat.Moderators.value(client.CUID);
+ }
+ else if(client.interface == Management)
+ {
+ return client.management.name;
+ }
+ else
+ {
+ return "";
+ }
+}
+
+void CRSM::sendIrcMessage(const QString& message, const QString& target, bool action, bool notice)
+{
+ bool query = !isChannelName(target);
+ Log.ircLog(message, (query ? target : connection->nickName()), query, target, action, notice, query);
+ /*if(cmd->type() == IrcCommand::Message || cmd->type() == IrcCommand::CtcpAction)
+ {
+ IrcPrivateMessage* messageCmd = (IrcPrivateMessage*)cmd;
+ Log.ircLog(messageCmd->content(), connection->nickName(), !isChannelName(messageCmd->parameter(0)), messageCmd->parameter(0), cmd->type() == IrcCommand::CtcpAction, false);
+ }
+ else if(cmd->type() == IrcCommand::Notice)
+ {
+ IrcNoticeMessage* noticeCmd = (IrcNoticeMessage*)cmd;
+ Log.ircLog(noticeCmd->content(), connection->nickName(), !isChannelName(noticeCmd->parameter(0)), noticeCmd->parameter(0), false, true);
+ }
+ connection->sendCommand(cmd);*/
+ if(action)
+ {
+ connection->sendCommand(IrcCommand::createCtcpAction(target, message));
+ }
+ else if(notice)
+ {
+ connection->sendCommand(IrcCommand::createNotice(target, message));
+ }
+ else
+ {
+ connection->sendCommand(IrcCommand::createMessage(target, message));
+ }
+}
+
CMD_FUNCTION_IMPL(help)
bool longHelp = (args == "long");
if(args.isEmpty() || longHelp)
@@ -2611,7 +2689,7 @@ CMD_FUNCTION_IMPL(ircSay)
}
else
{
- connection->sendCommand(IrcCommand::createMessage(target, message));
+ sendIrcMessage(message, target, false, false);
}
}
return Success;
@@ -2862,7 +2940,7 @@ IRC_CHECK_CALLBACK_IMPL(ircSayQuery)
{
foreach(const QString& message, ircSayQueryFifos[subject.nick])
{
- connection->sendCommand(IrcCommand::createMessage(subject.nick, message));
+ sendIrcMessage(message, subject.nick, false, false);
}
}
ircSayQueryFifos[subject.nick].clear();
diff --git a/src/crsm.hpp b/src/crsm.hpp
index 5130578..0e352f5 100644
--- a/src/crsm.hpp
+++ b/src/crsm.hpp
@@ -24,6 +24,7 @@
#include "CRSMConfig.hpp"
#include "CRSMStats.hpp"
#include "CRSMPackCompatibility.hpp"
+#include "CRSMLogging.hpp"
#define CONFIG_FILE_NAME "CrServerManager.conf"
#define SESSION_FILE_NAME "CrServerManager.session"
@@ -195,6 +196,7 @@ private:
CRSMSession Session;
CRSMStats Stats;
CRSMPackCompatibility Packs;
+ CRSMLogging Log;
QList<ScenarioSettings> userlist;
QList<ScenarioSettings> autolist;
@@ -208,13 +210,11 @@ private:
QString aliasWishEditor = "";
QString currentAliasWish = "";
int current;
- QTextStream *qout;
bool finish;
IrcConnection *connection = 0;
bool autoHost = true;
QSignalMapper greetMapper;
QFile *logfile;
- QTextStream logstream;
QTextCodec *codec;
QStringList ircModIOList;
QList<ClientInfo> ircModWatchList;
@@ -292,6 +292,8 @@ private:
bool isChannelName(const QString& name);
void removeCommandSuffixes(QString& command);
void substituteCommandAlias(QString& command);
+ QString clientModName(const ClientInfo& client);
+ void sendIrcMessage(const QString& message, const QString& target, bool action, bool notice);
CMD_FUNCTION(help);
CMD_FUNCTION(passToClonk);