Skip to content

Commit

Permalink
Client list support (#365)
Browse files Browse the repository at this point in the history
* Boilerplate structure for playerlist

* Change id, character and area to private with get/set

* WIP push

* Restructured the project entirely

* Implemented player list

* Build against project-akashi.pro

* Updated coverage location

* Copy gcov files from the proper path

* Update coverage to copy files

* Coverage update.

* Update main.yml

* Disabled coverage for the time being

* Reworked player list implementation, ...

* Reworked player list implementation
  * No longer rely on JSON
* Introduced moderation packets: ban, kick
  * A kick is a duration of 0
  * A ban is a duration between -1 (permanent) and anything above 0
* Packet ZZ has been modified and now include a client id field for client-specific reports
* Ban duration is now explicit.

* Tweak to ban duration calculation

* Resolve failing ZZ test

---------

Co-authored-by: Salanto <[email protected]>
  • Loading branch information
TrickyLeifa and Salanto authored Jul 14, 2024
1 parent 1edc80a commit 27ef14f
Show file tree
Hide file tree
Showing 17 changed files with 260 additions and 188 deletions.
6 changes: 4 additions & 2 deletions core.pro
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ SOURCES += \
src/config_manager.cpp \
src/db_manager.cpp \
src/discord.cpp \
src/packet/packet_pr.cpp \
src/packets.cpp \
src/playerstateobserver.cpp \
src/server.cpp \
Expand All @@ -68,10 +69,10 @@ SOURCES += \
src/packet/packet_de.cpp \
src/packet/packet_ee.cpp \
src/packet/packet_hp.cpp \
src/packet/packet_ma.cpp \
src/packet/packet_mc.cpp \
src/packet/packet_ms.cpp \
src/packet/packet_pe.cpp \
src/packet/packet_pl.cpp \
src/packet/packet_pw.cpp \
src/packet/packet_rc.cpp \
src/packet/packet_rd.cpp \
Expand All @@ -92,6 +93,7 @@ HEADERS += src/aoclient.h \
src/data_types.h \
src/db_manager.h \
src/discord.h \
src/packet/packet_pr.h \
src/playerstateobserver.h \
src/server.h \
src/typedefs.h \
Expand All @@ -113,10 +115,10 @@ HEADERS += src/aoclient.h \
src/packet/packet_de.h \
src/packet/packet_ee.h \
src/packet/packet_hp.h \
src/packet/packet_ma.h \
src/packet/packet_mc.h \
src/packet/packet_ms.h \
src/packet/packet_pe.h \
src/packet/packet_pl.h \
src/packet/packet_pw.h \
src/packet/packet_rc.h \
src/packet/packet_rd.h \
Expand Down
2 changes: 1 addition & 1 deletion src/commands/moderation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void AOClient::cmdBan(int argc, QStringList argv)
l_ban_duration = QDateTime::fromSecsSinceEpoch(l_ban.time).addSecs(l_ban.duration).toString("MM/dd/yyyy, hh:mm");
}
else {
l_ban_duration = "The heat death of the universe.";
l_ban_duration = "Permanently.";
}
int l_ban_id = server->getDatabaseManager()->getBanID(l_ban.ip);
l_client->sendPacket("KB", {l_ban.reason + "\nID: " + QString::number(l_ban_id) + "\nUntil: " + l_ban_duration});
Expand Down
9 changes: 6 additions & 3 deletions src/network/aopacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
#include "packet/packet_hi.h"
#include "packet/packet_hp.h"
#include "packet/packet_id.h"
#include "packet/packet_ma.h"
#include "packet/packet_mc.h"
#include "packet/packet_ms.h"
#include "packet/packet_pe.h"
#include "packet/packet_pl.h"
#include "packet/packet_pr.h"
#include "packet/packet_pw.h"
#include "packet/packet_rc.h"
#include "packet/packet_rd.h"
Expand All @@ -46,6 +47,8 @@ AOPacket::AOPacket(QStringList p_contents) :
{
}

AOPacket::~AOPacket() {}

const QStringList AOPacket::getContent()
{
return m_content;
Expand Down Expand Up @@ -132,8 +135,8 @@ void AOPacket::registerPackets()
PacketFactory::registerClass<PacketRM>("RM");
PacketFactory::registerClass<PacketRT>("RT");
PacketFactory::registerClass<PacketSetcase>("SETCASE");
PacketFactory::registerClass<PacketMA>("MA");
PacketFactory::registerClass<PacketZZ>("ZZ");
PacketFactory::registerClass<PacketPL>("PL");
PacketFactory::registerClass<PacketPLU>("PLU");
PacketFactory::registerClass<PacketPR>("PR");
PacketFactory::registerClass<PacketPU>("PU");
}
2 changes: 1 addition & 1 deletion src/network/aopacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AOPacket
/**
* @brief Destructor for the AOPacket
*/
~AOPacket(){};
virtual ~AOPacket();

/**
* @brief Returns the current content of the packet
Expand Down
2 changes: 1 addition & 1 deletion src/packet/packet_hi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void PacketHI::handlePacket(AreaData *area, AOClient &client) const
ban_duration = QDateTime::fromSecsSinceEpoch(ban.second.time).addSecs(ban.second.duration).toString("MM/dd/yyyy, hh:mm");
}
else {
ban_duration = "The heat death of the universe.";
ban_duration = "Permanently.";
}
client.sendPacket("BD", {"Reason: " + ban.second.reason + "\nBan ID: " + QString::number(ban.second.id) + "\nUntil: " + ban_duration});
client.m_socket->close();
Expand Down
115 changes: 115 additions & 0 deletions src/packet/packet_ma.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include "packet_ma.h"

#include "config_manager.h"
#include "db_manager.h"
#include "server.h"

PacketMA::PacketMA(QStringList &contents) :
AOPacket(contents)
{
}

PacketInfo PacketMA::getPacketInfo() const
{
PacketInfo info{
.acl_permission = ACLRole::Permission::NONE,
.min_args = 3,
.header = "MA"};
return info;
}

void PacketMA::handlePacket(AreaData *area, AOClient &client) const
{
if (!client.m_authenticated) {
client.sendServerMessage("You are not logged in!");
return;
}

int client_id = m_content.at(0).toInt();
int duration = qMax(m_content.at(1).toInt(), -1);
QString reason = m_content.at(2);

bool is_kick = duration == 0;
if (is_kick) {
if (!client.checkPermission(ACLRole::KICK)) {
client.sendServerMessage("You do not have permission to kick users.");
return;
}
}
else {
if (!client.checkPermission(ACLRole::BAN)) {
client.sendServerMessage("You do not have permission to ban users.");
return;
}
}

AOClient *target = client.getServer()->getClientByID(client_id);
if (target == nullptr) {
client.sendServerMessage("User not found.");
return;
}

QString moderator_name;
if (ConfigManager::authType() == DataTypes::AuthType::ADVANCED) {
moderator_name = client.m_moderator_name;
}
else {
moderator_name = "Moderator";
}

QList<AOClient *> clients = client.getServer()->getClientsByIpid(target->m_ipid);
if (is_kick) {
for (AOClient *subclient : clients) {
subclient->sendPacket("KK", {reason});
subclient->m_socket->close();
}

Q_EMIT client.logKick(moderator_name, target->m_ipid, reason);

client.sendServerMessage("Kicked " + QString::number(clients.size()) + " client(s) with ipid " + target->m_ipid + " for reason: " + reason);
}
else {
DBManager::BanInfo ban;

ban.ip = target->m_remote_ip;
ban.ipid = target->m_ipid;
ban.moderator = moderator_name;
ban.reason = reason;
ban.time = QDateTime::currentDateTime().toSecsSinceEpoch();

QString timestamp;
if (duration == -1) {
ban.duration = -2;
timestamp = "permanently";
}
else {
ban.duration = duration * 60;
timestamp = QDateTime::fromSecsSinceEpoch(ban.time).addSecs(ban.duration).toString("MM/dd/yyyy, hh:mm");
}

for (AOClient *subclient : clients) {
ban.hdid = subclient->m_hwid;

client.getServer()->getDatabaseManager()->addBan(ban);

subclient->sendPacket("KB", {reason});
subclient->m_socket->close();
}

if (ban.duration == -2) {
timestamp = "permanently";
}
else {
timestamp = QString::number(ban.time + ban.duration);
}

Q_EMIT client.logBan(moderator_name, target->m_ipid, timestamp, reason);

client.sendServerMessage("Banned " + QString::number(clients.size()) + " client(s) with ipid " + target->m_ipid + " for reason: " + reason);

int ban_id = client.getServer()->getDatabaseManager()->getBanID(ban.ip);
if (ConfigManager::discordBanWebhookEnabled()) {
Q_EMIT client.getServer()->banWebhookRequest(ban.ipid, ban.moderator, timestamp, ban.reason, ban_id);
}
}
}
11 changes: 11 additions & 0 deletions src/packet/packet_ma.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "network/aopacket.h"

class PacketMA : public AOPacket
{
public:
PacketMA(QStringList &contents);
virtual PacketInfo getPacketInfo() const;
virtual void handlePacket(AreaData *area, AOClient &client) const;
};
88 changes: 0 additions & 88 deletions src/packet/packet_pl.cpp

This file was deleted.

59 changes: 0 additions & 59 deletions src/packet/packet_pl.h

This file was deleted.

Loading

0 comments on commit 27ef14f

Please sign in to comment.