From aba007a5fc1288831361e5559177bdae20d1315e Mon Sep 17 00:00:00 2001 From: scatterflower Date: Mon, 26 Apr 2021 02:43:38 -0500 Subject: [PATCH] fix /bans --- include/db_manager.h | 1 + src/commands/moderation.cpp | 6 +++--- src/db_manager.cpp | 17 +++++++++-------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/db_manager.h b/include/db_manager.h index b696dfe..8d1d525 100644 --- a/include/db_manager.h +++ b/include/db_manager.h @@ -126,6 +126,7 @@ public: unsigned long time; //!< The time the ban was registered. QString reason; //!< The reason given for the ban by the moderator who registered it. long long duration; //!< The duration of the ban, in seconds. + int id; //!< The unique ID of the ban. }; /** diff --git a/src/commands/moderation.cpp b/src/commands/moderation.cpp index e0fc24a..0d0bb19 100644 --- a/src/commands/moderation.cpp +++ b/src/commands/moderation.cpp @@ -178,12 +178,12 @@ void AOClient::cmdBans(int argc, QStringList argv) if (ban.duration == -2) banned_until = "The heat death of the universe"; else - banned_until = QDateTime::fromSecsSinceEpoch(ban.time).addSecs(ban.duration).toString("dd.MM.yyyy, hh:mm"); - recent_bans << "Ban ID: " + QString::number(server->db_manager->getBanID(ban.ipid)); + banned_until = QDateTime::fromSecsSinceEpoch(ban.time).addSecs(ban.duration).toString("MM/dd/yyyy, hh:mm"); + recent_bans << "Ban ID: " + QString::number(ban.id); 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 << "Date of ban: " + QDateTime::fromSecsSinceEpoch(ban.time).toString("MM/dd/yyyy, hh:mm"); recent_bans << "Ban lasts until: " + banned_until; recent_bans << "-----"; } diff --git a/src/db_manager.cpp b/src/db_manager.cpp index f80b731..a0eafaf 100644 --- a/src/db_manager.cpp +++ b/src/db_manager.cpp @@ -126,7 +126,7 @@ long long DBManager::getBanDuration(QHostAddress ip) int DBManager::getBanID(QString hdid) { QSqlQuery query; - query.prepare("SELECT ID FROM BANS WHERE HDID = ?"); + query.prepare("SELECT ID FROM BANS WHERE HDID = ? ORDER BY TIME DESC"); query.addBindValue(hdid); query.exec(); if (query.first()) { @@ -141,7 +141,7 @@ int DBManager::getBanID(QString hdid) int DBManager::getBanID(QHostAddress ip) { QSqlQuery query; - query.prepare("SELECT ID FROM BANS WHERE IP = ?"); + query.prepare("SELECT ID FROM BANS WHERE IP = ? ORDER BY TIME DESC"); query.addBindValue(ip.toString()); query.exec(); if (query.first()) { @@ -161,12 +161,13 @@ QList DBManager::getRecentBans() 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(); + ban.id = query.value(0).toInt(); + ban.ipid = query.value(1).toString(); + ban.hdid = query.value(2).toString(); + ban.ip = QHostAddress(query.value(3).toString()); + ban.time = static_cast(query.value(4).toULongLong()); + ban.reason = query.value(5).toString(); + ban.duration = query.value(6).toLongLong(); return_list.append(ban); } std::reverse(return_list.begin(), return_list.end());