fix /bans

This commit is contained in:
scatterflower 2021-04-26 02:43:38 -05:00
parent 3403d45676
commit aba007a5fc
3 changed files with 13 additions and 11 deletions

View File

@ -126,6 +126,7 @@ public:
unsigned long time; //!< The time the ban was registered. unsigned long time; //!< The time the ban was registered.
QString reason; //!< The reason given for the ban by the moderator who registered it. QString reason; //!< The reason given for the ban by the moderator who registered it.
long long duration; //!< The duration of the ban, in seconds. long long duration; //!< The duration of the ban, in seconds.
int id; //!< The unique ID of the ban.
}; };
/** /**

View File

@ -178,12 +178,12 @@ void AOClient::cmdBans(int argc, QStringList argv)
if (ban.duration == -2) if (ban.duration == -2)
banned_until = "The heat death of the universe"; banned_until = "The heat death of the universe";
else else
banned_until = QDateTime::fromSecsSinceEpoch(ban.time).addSecs(ban.duration).toString("dd.MM.yyyy, hh:mm"); banned_until = QDateTime::fromSecsSinceEpoch(ban.time).addSecs(ban.duration).toString("MM/dd/yyyy, hh:mm");
recent_bans << "Ban ID: " + QString::number(server->db_manager->getBanID(ban.ipid)); recent_bans << "Ban ID: " + QString::number(ban.id);
recent_bans << "Affected IPID: " + ban.ipid; recent_bans << "Affected IPID: " + ban.ipid;
recent_bans << "Affected HDID: " + ban.hdid; recent_bans << "Affected HDID: " + ban.hdid;
recent_bans << "Reason for ban: " + ban.reason; 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 << "Ban lasts until: " + banned_until;
recent_bans << "-----"; recent_bans << "-----";
} }

View File

@ -126,7 +126,7 @@ long long DBManager::getBanDuration(QHostAddress ip)
int DBManager::getBanID(QString hdid) int DBManager::getBanID(QString hdid)
{ {
QSqlQuery query; 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.addBindValue(hdid);
query.exec(); query.exec();
if (query.first()) { if (query.first()) {
@ -141,7 +141,7 @@ int DBManager::getBanID(QString hdid)
int DBManager::getBanID(QHostAddress ip) int DBManager::getBanID(QHostAddress ip)
{ {
QSqlQuery query; 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.addBindValue(ip.toString());
query.exec(); query.exec();
if (query.first()) { if (query.first()) {
@ -161,12 +161,13 @@ QList<DBManager::BanInfo> DBManager::getRecentBans()
query.exec(); query.exec();
while (query.next()) { while (query.next()) {
BanInfo ban; BanInfo ban;
ban.ipid = query.value(0).toString(); ban.id = query.value(0).toInt();
ban.hdid = query.value(1).toString(); ban.ipid = query.value(1).toString();
ban.ip = QHostAddress(query.value(2).toString()); ban.hdid = query.value(2).toString();
ban.time = static_cast<unsigned long>(query.value(3).toULongLong()); ban.ip = QHostAddress(query.value(3).toString());
ban.reason = query.value(4).toString(); ban.time = static_cast<unsigned long>(query.value(4).toULongLong());
ban.duration = query.value(5).toLongLong(); ban.reason = query.value(5).toString();
ban.duration = query.value(6).toLongLong();
return_list.append(ban); return_list.append(ban);
} }
std::reverse(return_list.begin(), return_list.end()); std::reverse(return_list.begin(), return_list.end());