diff --git a/include/aoclient.h b/include/aoclient.h index 1d663fe..48e9606 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -224,6 +224,7 @@ class AOClient : public QObject { void cmdGM(int argc, QStringList argv); void cmdMute(int argc, QStringList argv); void cmdUnmute(int argc, QStringList argv); + void cmdBans(int argc, QStringList argv); // Casing/RP void cmdPlay(int argc, QStringList argv); void cmdNeed(int argc, QStringList argv); @@ -315,7 +316,8 @@ class AOClient : public QObject { {"m", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdM}}, {"gm", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdGM}}, {"mute", {ACLFlags.value("MUTE"), 1, &AOClient::cmdMute}}, - {"unmute", {ACLFlags.value("MUTE"), 1, &AOClient::cmdUnmute}} + {"unmute", {ACLFlags.value("MUTE"), 1, &AOClient::cmdUnmute}}, + {"bans", {ACLFlags.value("BAN"), 0, &AOClient::cmdBans}} }; QString partial_packet; diff --git a/include/db_manager.h b/include/db_manager.h index d18b87a..a93b7a4 100644 --- a/include/db_manager.h +++ b/include/db_manager.h @@ -41,6 +41,16 @@ public: long long getBanDuration(QString hdid); long long getBanDuration(QHostAddress hdid); + struct BanInfo { + QString ipid; + QHostAddress ip; + QString hdid; + unsigned long time; + QString reason; + long long duration; + }; + QList getRecentBans(); + void addBan(QString ipid, QHostAddress ip, QString hdid, unsigned long time, QString reason, long long duration); bool createUser(QString username, QString salt, QString password, unsigned long long acl); diff --git a/src/commands.cpp b/src/commands.cpp index 033050b..3325a20 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -971,6 +971,22 @@ void AOClient::cmdUnmute(int argc, QStringList argv) server->getClientByID(uid)->is_muted = false; } +void AOClient::cmdBans(int argc, QStringList argv) +{ + QStringList recent_bans; + recent_bans << "Last 5 bans:"; + recent_bans << "-----"; + for (DBManager::BanInfo ban : server->db_manager->getRecentBans()) { + recent_bans << "Affected IPID: " + ban.ipid; + recent_bans << "Affected HDID: " + ban.hdid; + recent_bans << "Reason for ban: " + ban.reason; + recent_bans << "Date of ban: " + QDateTime::fromSecsSinceEpoch(ban.time).toString("dd.MM.yyyy, hh:mm"); + recent_bans << "Ban lasts until: " + QDateTime::fromSecsSinceEpoch(ban.time).addSecs(ban.duration).toString("dd.MM.yyyy, hh:mm"); + recent_bans << "-----"; + } + sendServerMessage(recent_bans.join("\n")); +} + QStringList AOClient::buildAreaList(int area_idx) { QStringList entries; diff --git a/src/db_manager.cpp b/src/db_manager.cpp index 6a0c0b7..e203fcc 100644 --- a/src/db_manager.cpp +++ b/src/db_manager.cpp @@ -122,6 +122,27 @@ long long DBManager::getBanDuration(QHostAddress ip) } } +QList DBManager::getRecentBans() +{ + QList return_list; + QSqlQuery query; + query.prepare("SELECT TOP(5) * FROM BANS ORDER BY TIME DESC"); + query.setForwardOnly(true); + query.exec(); + while (query.next()) { + BanInfo ban; + ban.ipid = query.value(0).toString(); + ban.hdid = query.value(1).toString(); + ban.ip = QHostAddress(query.value(2).toString()); + ban.time = static_cast(query.value(3).toULongLong()); + ban.reason = query.value(4).toString(); + ban.duration = query.value(5).toLongLong(); + return_list.append(ban); + } + std::reverse(return_list.begin(), return_list.end()); + return return_list; +} + void DBManager::addBan(QString ipid, QHostAddress ip, QString hdid, unsigned long time, QString reason, long long duration) { QSqlQuery query;