From 51ea6d996d3603974f67cb9131fe9a4af82bb83c Mon Sep 17 00:00:00 2001 From: scatterflower Date: Mon, 26 Apr 2021 02:16:56 -0500 Subject: [PATCH 1/3] fix incorrect sql statement, and add config switch to skip authentication for testing --- akashi.pro | 3 +++ src/db_manager.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/akashi.pro b/akashi.pro index 8e995b4..822de90 100644 --- a/akashi.pro +++ b/akashi.pro @@ -26,6 +26,9 @@ RC_ICONS = resource/icon/akashi.ico # Enable this to print network messages tothe console #DEFINES += NET_DEBUG +# Enable this to skip all authentication checks +#DEFINES += SKIP_AUTH + SOURCES += src/advertiser.cpp \ src/aoclient.cpp \ src/aopacket.cpp \ diff --git a/src/db_manager.cpp b/src/db_manager.cpp index 861ec1a..f80b731 100644 --- a/src/db_manager.cpp +++ b/src/db_manager.cpp @@ -156,7 +156,7 @@ QList DBManager::getRecentBans() { QList return_list; QSqlQuery query; - query.prepare("SELECT TOP(5) * FROM BANS ORDER BY TIME DESC"); + query.prepare("SELECT * FROM BANS ORDER BY TIME DESC LIMIT 5"); query.setForwardOnly(true); query.exec(); while (query.next()) { From 3403d45676d13ca211967f7a811c5b95855b08d8 Mon Sep 17 00:00:00 2001 From: scatterflower Date: Mon, 26 Apr 2021 02:19:19 -0500 Subject: [PATCH 2/3] add auth skip --- src/aoclient.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/aoclient.cpp b/src/aoclient.cpp index 1fc9c92..39fc6cd 100644 --- a/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -311,6 +311,9 @@ void AOClient::sendServerBroadcast(QString message) bool AOClient::checkAuth(unsigned long long acl_mask) { +#ifdef SKIP_AUTH + return true; +#endif if (acl_mask != ACLFlags.value("NONE")) { if (acl_mask == ACLFlags.value("CM")) { AreaData* area = server->areas[current_area]; From aba007a5fc1288831361e5559177bdae20d1315e Mon Sep 17 00:00:00 2001 From: scatterflower Date: Mon, 26 Apr 2021 02:43:38 -0500 Subject: [PATCH 3/3] 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());