some logging improvements
This commit is contained in:
parent
0a29665927
commit
73381f97ef
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "include/aoclient.h"
|
#include "include/aoclient.h"
|
||||||
#include "include/aopacket.h"
|
#include "include/aopacket.h"
|
||||||
|
#include "include/area_data.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@ -28,21 +29,26 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
||||||
class AOClient;
|
class AOClient;
|
||||||
|
class AreaData;
|
||||||
class Logger
|
class Logger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Logger(int p_max_length);
|
Logger(int p_max_length, AreaData* p_area);
|
||||||
|
|
||||||
void logIC(AOClient* client, AOPacket* packet);
|
void logIC(AOClient* client, AOPacket* packet);
|
||||||
void logOOC(AOClient* client, AOPacket* packet);
|
void logOOC(AOClient* client, AOPacket* packet);
|
||||||
void logModcall(AOClient* client, AOPacket* packet);
|
void logModcall(AOClient* client, AOPacket* packet);
|
||||||
|
void logCmd(AOClient* client, AOPacket* packet, QString cmd, QStringList args);
|
||||||
|
void logLogin(AOClient* client, bool success, QString modname);
|
||||||
void flush();
|
void flush();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString buildEntry(AOClient* client, QString type, QString message);
|
||||||
void addEntry(QString entry);
|
void addEntry(QString entry);
|
||||||
|
|
||||||
int max_length;
|
int max_length;
|
||||||
QQueue<QString> buffer;
|
QQueue<QString> buffer;
|
||||||
|
AreaData* area;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOGGER_H
|
#endif // LOGGER_H
|
||||||
|
@ -40,5 +40,5 @@ AreaData::AreaData(QStringList characters, QString p_name, int p_index)
|
|||||||
int log_size = config_ini.value("logbuffer", 50).toInt();
|
int log_size = config_ini.value("logbuffer", 50).toInt();
|
||||||
if (log_size == 0)
|
if (log_size == 0)
|
||||||
log_size = 500;
|
log_size = 500;
|
||||||
logger = new Logger(log_size);
|
logger = new Logger(log_size, this);
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,8 @@ void AOClient::cmdLogin(int argc, QStringList argv)
|
|||||||
authenticated = true;
|
authenticated = true;
|
||||||
} else {
|
} else {
|
||||||
sendServerMessage("Incorrect password.");
|
sendServerMessage("Incorrect password.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
server->areas.value(current_area)->logger->logLogin(this, authenticated, "moderator");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
@ -57,11 +57,13 @@ void AOClient::cmdLogin(int argc, QStringList argv)
|
|||||||
if (server->db_manager->authenticate(username, password)) {
|
if (server->db_manager->authenticate(username, password)) {
|
||||||
moderator_name = username;
|
moderator_name = username;
|
||||||
authenticated = true;
|
authenticated = true;
|
||||||
sendServerMessage("Logged in as " + username);
|
sendServerMessage("Logged in as a moderator.");
|
||||||
|
sendServerMessage("Welcome, " + username);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sendServerMessage("Incorrect password.");
|
sendServerMessage("Incorrect password.");
|
||||||
}
|
}
|
||||||
|
server->areas.value(current_area)->logger->logLogin(this, authenticated, username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,63 +17,68 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////
|
||||||
#include "include/logger.h"
|
#include "include/logger.h"
|
||||||
|
|
||||||
Logger::Logger(int p_max_length)
|
Logger::Logger(int p_max_length, AreaData* p_area)
|
||||||
{
|
{
|
||||||
|
area = p_area;
|
||||||
max_length = p_max_length;
|
max_length = p_max_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::logIC(AOClient *client, AOPacket *packet)
|
void Logger::logIC(AOClient *client, AOPacket *packet)
|
||||||
{
|
{
|
||||||
// TODO: copy pasted code
|
|
||||||
QString time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
|
|
||||||
QString area_name = client->getServer()->area_names.value(client->current_area);
|
|
||||||
QString char_name = client->current_char;
|
|
||||||
QString ipid = client->getIpid();
|
|
||||||
QString message = packet->contents[4];
|
QString message = packet->contents[4];
|
||||||
|
addEntry(buildEntry(client, "IC", message));
|
||||||
QString log_entry = QStringLiteral("[%1][%2][IC] %3(%4): %5\n")
|
|
||||||
.arg(time)
|
|
||||||
.arg(area_name)
|
|
||||||
.arg(char_name)
|
|
||||||
.arg(ipid)
|
|
||||||
.arg(message);
|
|
||||||
addEntry(log_entry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::logOOC(AOClient* client, AOPacket* packet)
|
void Logger::logOOC(AOClient* client, AOPacket* packet)
|
||||||
{
|
{
|
||||||
// TODO: copy pasted code
|
|
||||||
QString time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
|
|
||||||
QString area_name = client->getServer()->area_names.value(client->current_area);
|
|
||||||
QString char_name = client->current_char;
|
|
||||||
QString ipid = client->getIpid();
|
|
||||||
QString message = packet->contents[1];
|
QString message = packet->contents[1];
|
||||||
|
addEntry(buildEntry(client, "OOC", message));
|
||||||
QString log_entry = QStringLiteral("[%1][%2][OOC] %3(%4): %5\n")
|
|
||||||
.arg(time)
|
|
||||||
.arg(area_name)
|
|
||||||
.arg(char_name)
|
|
||||||
.arg(ipid)
|
|
||||||
.arg(message);
|
|
||||||
addEntry(log_entry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::logModcall(AOClient* client, AOPacket* packet)
|
void Logger::logModcall(AOClient* client, AOPacket* packet)
|
||||||
{
|
{
|
||||||
// TODO: copy pasted code
|
QString message = packet->contents[0];
|
||||||
|
addEntry(buildEntry(client, "MODCALL", message));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::logCmd(AOClient *client, AOPacket *packet, QString cmd, QStringList args)
|
||||||
|
{
|
||||||
|
// Some commands contain sensitive data, like passwords
|
||||||
|
// These must be filtered out
|
||||||
|
if (cmd == "login") {
|
||||||
|
addEntry(buildEntry(client, "LOGIN", "Attempted login"));
|
||||||
|
}
|
||||||
|
else if (cmd == "rootpass") {
|
||||||
|
addEntry(buildEntry(client, "USERS", "Root password created"));
|
||||||
|
}
|
||||||
|
else if (cmd == "adduser") {
|
||||||
|
addEntry(buildEntry(client, "USERS", "Added user " + args[0]));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
logOOC(client, packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::logLogin(AOClient *client, bool success, QString modname)
|
||||||
|
{
|
||||||
|
QString message = success ? "Logged in as " + modname : "Failed to log in as " + modname;
|
||||||
|
addEntry(buildEntry(client, "LOGIN", message));
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Logger::buildEntry(AOClient *client, QString type, QString message)
|
||||||
|
{
|
||||||
QString time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
|
QString time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
|
||||||
QString area_name = client->getServer()->area_names.value(client->current_area);
|
QString area_name = area->name;
|
||||||
QString char_name = client->current_char;
|
QString char_name = client->current_char;
|
||||||
QString ipid = client->getIpid();
|
QString ipid = client->getIpid();
|
||||||
QString message = packet->contents[0];
|
|
||||||
|
|
||||||
QString log_entry = QStringLiteral("[%1][%2][MODCALL] %3(%4): %5\n")
|
QString log_entry = QStringLiteral("[%1][%2][%6] %3(%4): %5\n")
|
||||||
.arg(time)
|
.arg(time)
|
||||||
.arg(area_name)
|
.arg(area_name)
|
||||||
.arg(char_name)
|
.arg(char_name)
|
||||||
.arg(ipid)
|
.arg(ipid)
|
||||||
.arg(message);
|
.arg(message)
|
||||||
addEntry(log_entry);
|
.arg(type);
|
||||||
|
return log_entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::addEntry(QString entry)
|
void Logger::addEntry(QString entry)
|
||||||
@ -89,6 +94,9 @@ void Logger::addEntry(QString entry)
|
|||||||
|
|
||||||
void Logger::flush()
|
void Logger::flush()
|
||||||
{
|
{
|
||||||
|
// raiden suggested this, but idk if i want to use it
|
||||||
|
// QString time = QDateTime::currentDateTime().toString("ddd mm/dd/yy hh:mm:ss");
|
||||||
|
// QString filename = QStringLiteral("reports/%1/%2.log").arg(area->name).arg(time);
|
||||||
QFile logfile("config/server.log");
|
QFile logfile("config/server.log");
|
||||||
if (logfile.open(QIODevice::WriteOnly | QIODevice::Append)) {
|
if (logfile.open(QIODevice::WriteOnly | QIODevice::Append)) {
|
||||||
QTextStream file_stream(&logfile);
|
QTextStream file_stream(&logfile);
|
||||||
|
@ -159,14 +159,15 @@ void AOClient::pktOocChat(AreaData* area, int argc, QStringList argv, AOPacket p
|
|||||||
command = command.right(command.length() - 1);
|
command = command.right(command.length() - 1);
|
||||||
cmd_argv.removeFirst();
|
cmd_argv.removeFirst();
|
||||||
int cmd_argc = cmd_argv.length();
|
int cmd_argc = cmd_argv.length();
|
||||||
|
area->logger->logCmd(this, &packet, command, cmd_argv);
|
||||||
handleCommand(command, cmd_argc, cmd_argv);
|
handleCommand(command, cmd_argc, cmd_argv);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO: zalgo strip
|
// TODO: zalgo strip
|
||||||
server->broadcast(packet, current_area);
|
server->broadcast(packet, current_area);
|
||||||
}
|
|
||||||
area->logger->logOOC(this, &packet);
|
area->logger->logOOC(this, &packet);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AOClient::pktPing(AreaData* area, int argc, QStringList argv, AOPacket packet)
|
void AOClient::pktPing(AreaData* area, int argc, QStringList argv, AOPacket packet)
|
||||||
{
|
{
|
||||||
|
@ -110,8 +110,7 @@ void Server::clientConnected()
|
|||||||
});
|
});
|
||||||
connect(socket, &QTcpSocket::readyRead, client, &AOClient::clientData);
|
connect(socket, &QTcpSocket::readyRead, client, &AOClient::clientData);
|
||||||
|
|
||||||
AOPacket decryptor(
|
AOPacket decryptor("decryptor", {"NOENCRYPT"}); // This is the infamous workaround for
|
||||||
"decryptor", {"NOENCRYPT"}); // This is the infamous workaround for
|
|
||||||
// tsuserver4. It should disable fantacrypt
|
// tsuserver4. It should disable fantacrypt
|
||||||
// completely in any client 2.4.3 or newer
|
// completely in any client 2.4.3 or newer
|
||||||
client->sendPacket(decryptor);
|
client->sendPacket(decryptor);
|
||||||
|
Loading…
Reference in New Issue
Block a user