-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
1edc80a
commit 27ef14f
Showing
17 changed files
with
260 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.