add modcall and IC logging
This commit is contained in:
parent
fde0c4b78f
commit
288e8ffa49
@ -30,6 +30,7 @@ SOURCES += src/advertiser.cpp \
|
|||||||
src/commands.cpp \
|
src/commands.cpp \
|
||||||
src/config_manager.cpp \
|
src/config_manager.cpp \
|
||||||
src/db_manager.cpp \
|
src/db_manager.cpp \
|
||||||
|
src/logger.cpp \
|
||||||
src/main.cpp \
|
src/main.cpp \
|
||||||
src/packets.cpp \
|
src/packets.cpp \
|
||||||
src/server.cpp \
|
src/server.cpp \
|
||||||
@ -43,6 +44,7 @@ HEADERS += include/advertiser.h \
|
|||||||
include/area_data.h \
|
include/area_data.h \
|
||||||
include/config_manager.h \
|
include/config_manager.h \
|
||||||
include/db_manager.h \
|
include/db_manager.h \
|
||||||
|
include/logger.h \
|
||||||
include/server.h \
|
include/server.h \
|
||||||
include/ws_client.h \
|
include/ws_client.h \
|
||||||
include/ws_proxy.h
|
include/ws_proxy.h
|
||||||
|
@ -16,4 +16,5 @@ server_name=An Unnamed Server
|
|||||||
webao_enable=true
|
webao_enable=true
|
||||||
webao_port=27017
|
webao_port=27017
|
||||||
auth=simple
|
auth=simple
|
||||||
modpass=changeme
|
modpass=changeme
|
||||||
|
logbuffer=500
|
@ -51,6 +51,7 @@ class AOClient : public QObject {
|
|||||||
bool authenticated = false;
|
bool authenticated = false;
|
||||||
QString moderator_name = "";
|
QString moderator_name = "";
|
||||||
QString ooc_name = "";
|
QString ooc_name = "";
|
||||||
|
Server* server;
|
||||||
|
|
||||||
QMap<QString, unsigned long long> ACLFlags {
|
QMap<QString, unsigned long long> ACLFlags {
|
||||||
{"NONE", 0ULL},
|
{"NONE", 0ULL},
|
||||||
@ -69,7 +70,6 @@ class AOClient : public QObject {
|
|||||||
void sendPacket(QString header);
|
void sendPacket(QString header);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Server* server;
|
|
||||||
QTcpSocket* socket;
|
QTcpSocket* socket;
|
||||||
|
|
||||||
enum ARUPType {
|
enum ARUPType {
|
||||||
@ -104,6 +104,7 @@ class AOClient : public QObject {
|
|||||||
void pktWtCe(AreaData* area, int argc, QStringList argv, AOPacket packet);
|
void pktWtCe(AreaData* area, int argc, QStringList argv, AOPacket packet);
|
||||||
void pktHpBar(AreaData* area, int argc, QStringList argv, AOPacket packet);
|
void pktHpBar(AreaData* area, int argc, QStringList argv, AOPacket packet);
|
||||||
void pktWebSocketIp(AreaData* area, int argc, QStringList argv, AOPacket packet);
|
void pktWebSocketIp(AreaData* area, int argc, QStringList argv, AOPacket packet);
|
||||||
|
void pktModCall(AreaData* area, int argc, QStringList argv, AOPacket packet);
|
||||||
|
|
||||||
// Packet helper functions
|
// Packet helper functions
|
||||||
AOPacket validateIcPacket(AOPacket packet);
|
AOPacket validateIcPacket(AOPacket packet);
|
||||||
@ -133,7 +134,8 @@ class AOClient : public QObject {
|
|||||||
{"MC", {ACLFlags.value("NONE"), 2, &AOClient::pktChangeMusic}},
|
{"MC", {ACLFlags.value("NONE"), 2, &AOClient::pktChangeMusic}},
|
||||||
{"RT", {ACLFlags.value("NONE"), 1, &AOClient::pktWtCe}},
|
{"RT", {ACLFlags.value("NONE"), 1, &AOClient::pktWtCe}},
|
||||||
{"HP", {ACLFlags.value("NONE"), 2, &AOClient::pktHpBar}},
|
{"HP", {ACLFlags.value("NONE"), 2, &AOClient::pktHpBar}},
|
||||||
{"WSIP", {ACLFlags.value("NONE"), 1, &AOClient::pktWebSocketIp}}
|
{"WSIP", {ACLFlags.value("NONE"), 1, &AOClient::pktWebSocketIp}},
|
||||||
|
{"ZZ", {ACLFlags.value("NONE"), 0, &AOClient::pktModCall}}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Commands
|
// Commands
|
||||||
|
@ -18,11 +18,14 @@
|
|||||||
#ifndef AREA_DATA_H
|
#ifndef AREA_DATA_H
|
||||||
#define AREA_DATA_H
|
#define AREA_DATA_H
|
||||||
|
|
||||||
|
#include "include/logger.h"
|
||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
class Logger;
|
||||||
class AreaData {
|
class AreaData {
|
||||||
public:
|
public:
|
||||||
AreaData(QStringList p_characters, QString p_name, int p_index);
|
AreaData(QStringList p_characters, QString p_name, int p_index);
|
||||||
@ -34,15 +37,14 @@ class AreaData {
|
|||||||
QString status;
|
QString status;
|
||||||
QString current_cm;
|
QString current_cm;
|
||||||
bool locked;
|
bool locked;
|
||||||
|
|
||||||
QString background;
|
QString background;
|
||||||
bool showname_allowed;
|
bool showname_allowed;
|
||||||
bool locking_allowed;
|
bool locking_allowed;
|
||||||
bool iniswap_allowed;
|
bool iniswap_allowed;
|
||||||
bool bg_locked;
|
bool bg_locked;
|
||||||
|
|
||||||
int def_hp;
|
int def_hp;
|
||||||
int pro_hp;
|
int pro_hp;
|
||||||
|
Logger* logger;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // AREA_DATA_H
|
#endif // AREA_DATA_H
|
||||||
|
46
include/logger.h
Normal file
46
include/logger.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
//////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// akashi - a server for Attorney Online 2 //
|
||||||
|
// Copyright (C) 2020 scatterflower //
|
||||||
|
// //
|
||||||
|
// This program is free software: you can redistribute it and/or modify //
|
||||||
|
// it under the terms of the GNU Affero General Public License as //
|
||||||
|
// published by the Free Software Foundation, either version 3 of the //
|
||||||
|
// License, or (at your option) any later version. //
|
||||||
|
// //
|
||||||
|
// This program is distributed in the hope that it will be useful, //
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||||
|
// GNU Affero General Public License for more details. //
|
||||||
|
// //
|
||||||
|
// You should have received a copy of the GNU Affero General Public License //
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifndef LOGGER_H
|
||||||
|
#define LOGGER_H
|
||||||
|
|
||||||
|
#include "include/aoclient.h"
|
||||||
|
#include "include/aopacket.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QString>
|
||||||
|
#include <QQueue>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
|
class AOClient;
|
||||||
|
class Logger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Logger(int p_max_length);
|
||||||
|
|
||||||
|
void logIC(AOClient* client, AOPacket* packet);
|
||||||
|
void flush();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void addEntry(QString entry);
|
||||||
|
|
||||||
|
int max_length;
|
||||||
|
QQueue<QString> buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LOGGER_H
|
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
class AOClient;
|
class AOClient;
|
||||||
class DBManager;
|
class DBManager;
|
||||||
|
class AreaData;
|
||||||
|
|
||||||
class Server : public QObject {
|
class Server : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -70,7 +70,7 @@ void AOClient::clientDisconnected()
|
|||||||
|
|
||||||
void AOClient::handlePacket(AOPacket packet)
|
void AOClient::handlePacket(AOPacket packet)
|
||||||
{
|
{
|
||||||
qDebug() << "Received packet:" << packet.header << ":" << packet.contents << "args length:" << packet.contents.length();
|
// qDebug() << "Received packet:" << packet.header << ":" << packet.contents << "args length:" << packet.contents.length();
|
||||||
AreaData* area = server->areas[current_area];
|
AreaData* area = server->areas[current_area];
|
||||||
PacketInfo info = packets.value(packet.header, {false, 0, &AOClient::pktDefault});
|
PacketInfo info = packets.value(packet.header, {false, 0, &AOClient::pktDefault});
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ void AOClient::fullArup() {
|
|||||||
|
|
||||||
void AOClient::sendPacket(AOPacket packet)
|
void AOClient::sendPacket(AOPacket packet)
|
||||||
{
|
{
|
||||||
qDebug() << "Sent packet:" << packet.header << ":" << packet.contents;
|
// qDebug() << "Sent packet:" << packet.header << ":" << packet.contents;
|
||||||
socket->write(packet.toUtf8());
|
socket->write(packet.toUtf8());
|
||||||
socket->flush();
|
socket->flush();
|
||||||
}
|
}
|
||||||
|
@ -35,4 +35,10 @@ AreaData::AreaData(QStringList characters, QString p_name, int p_index)
|
|||||||
def_hp = 10;
|
def_hp = 10;
|
||||||
pro_hp = 10;
|
pro_hp = 10;
|
||||||
bg_locked = false;
|
bg_locked = false;
|
||||||
|
QSettings config_ini("config/config.ini", QSettings::IniFormat);
|
||||||
|
config_ini.beginGroup("Options");
|
||||||
|
int log_size = config_ini.value("logbuffer", 50).toInt();
|
||||||
|
if (log_size == 0)
|
||||||
|
log_size = 500;
|
||||||
|
logger = new Logger(log_size);
|
||||||
}
|
}
|
||||||
|
62
src/logger.cpp
Normal file
62
src/logger.cpp
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
//////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// akashi - a server for Attorney Online 2 //
|
||||||
|
// Copyright (C) 2020 scatterflower //
|
||||||
|
// //
|
||||||
|
// This program is free software: you can redistribute it and/or modify //
|
||||||
|
// it under the terms of the GNU Affero General Public License as //
|
||||||
|
// published by the Free Software Foundation, either version 3 of the //
|
||||||
|
// License, or (at your option) any later version. //
|
||||||
|
// //
|
||||||
|
// This program is distributed in the hope that it will be useful, //
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||||
|
// GNU Affero General Public License for more details. //
|
||||||
|
// //
|
||||||
|
// You should have received a copy of the GNU Affero General Public License //
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#include "include/logger.h"
|
||||||
|
|
||||||
|
Logger::Logger(int p_max_length)
|
||||||
|
{
|
||||||
|
max_length = p_max_length;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::logIC(AOClient *client, AOPacket *packet)
|
||||||
|
{
|
||||||
|
QString time = QDateTime::currentDateTime().toString("ddd MMMM d yyyy | hh:mm:ss");
|
||||||
|
QString area_name = client->server->area_names.value(client->current_area);
|
||||||
|
QString char_name = client->current_char;
|
||||||
|
QString ipid = client->getIpid();
|
||||||
|
QString message = packet->contents[4];
|
||||||
|
|
||||||
|
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::addEntry(QString entry)
|
||||||
|
{
|
||||||
|
if (buffer.length() < max_length) {
|
||||||
|
buffer.enqueue(entry);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
buffer.dequeue();
|
||||||
|
buffer.enqueue(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::flush()
|
||||||
|
{
|
||||||
|
QFile logfile("config/server.log");
|
||||||
|
if (logfile.open(QIODevice::WriteOnly | QIODevice::Append)) {
|
||||||
|
QTextStream file_stream(&logfile);
|
||||||
|
while (!buffer.isEmpty())
|
||||||
|
file_stream << buffer.dequeue();
|
||||||
|
}
|
||||||
|
logfile.close();
|
||||||
|
}
|
@ -145,6 +145,7 @@ void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket pa
|
|||||||
if (validated_packet.header == "INVALID")
|
if (validated_packet.header == "INVALID")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
area->logger->logIC(this, &validated_packet);
|
||||||
server->broadcast(validated_packet, current_area);
|
server->broadcast(validated_packet, current_area);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,6 +235,15 @@ void AOClient::pktWebSocketIp(AreaData* area, int argc, QStringList argv, AOPack
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AOClient::pktModCall(AreaData *area, int argc, QStringList argv, AOPacket packet)
|
||||||
|
{
|
||||||
|
for (AOClient* client : server->clients) {
|
||||||
|
if (client->authenticated)
|
||||||
|
client->sendPacket(packet);
|
||||||
|
}
|
||||||
|
area->logger->flush();
|
||||||
|
}
|
||||||
|
|
||||||
AOPacket AOClient::validateIcPacket(AOPacket packet)
|
AOPacket AOClient::validateIcPacket(AOPacket packet)
|
||||||
{
|
{
|
||||||
// Welcome to the super cursed server-side IC chat validation hell
|
// Welcome to the super cursed server-side IC chat validation hell
|
||||||
|
Loading…
Reference in New Issue
Block a user