Merge pull request #329 from AwesomeAim/ban-message
Improve Post-Ban Ban Message
This commit is contained in:
		
						commit
						03063be3ba
					
				| @ -59,6 +59,21 @@ class DBManager : public QObject | ||||
|      */ | ||||
|     ~DBManager(); | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief Details about a ban. | ||||
|      */ | ||||
|     struct BanInfo | ||||
|     { | ||||
|         QString ipid;       //!< The banned user's IPID.
 | ||||
|         QHostAddress ip;    //!< The banned user's IP.
 | ||||
|         QString hdid;       //!< The banned user's hardware ID.
 | ||||
|         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.
 | ||||
|         QString moderator;  //!< The moderator who issued the ban.
 | ||||
|     }; | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief Checks if there is a record in the Bans table with the given IPID. | ||||
|      * | ||||
| @ -68,7 +83,7 @@ class DBManager : public QObject | ||||
|      * * First, a `bool` that is true if the query could return at least one such record. | ||||
|      * * Then, a `QString` that is the reason for the ban. | ||||
|      */ | ||||
|     QPair<bool, QString> isIPBanned(QString ipid); | ||||
|     QPair<bool, BanInfo> isIPBanned(QString ipid); | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief Checks if there is a record in the Bans table with the given hardware ID. | ||||
| @ -79,7 +94,7 @@ class DBManager : public QObject | ||||
|      * * First, a `bool` that is true if the query could return at least one such record. | ||||
|      * * Then, a `QString` that is the reason for the ban. | ||||
|      */ | ||||
|     QPair<bool, QString> isHDIDBanned(QString hdid); | ||||
|     QPair<bool, BanInfo> isHDIDBanned(QString hdid); | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief Gets the ID number of a given ban. | ||||
| @ -96,21 +111,6 @@ class DBManager : public QObject | ||||
|      */ | ||||
|     int getBanID(QString hdid); | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief Details about a ban. | ||||
|      */ | ||||
|     struct BanInfo | ||||
|     { | ||||
|         QString ipid;       //!< The banned user's IPID.
 | ||||
|         QHostAddress ip;    //!< The banned user's IP.
 | ||||
|         QString hdid;       //!< The banned user's hardware ID.
 | ||||
|         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.
 | ||||
|         QString moderator;  //!< The moderator who issued the ban.
 | ||||
|     }; | ||||
| 
 | ||||
|     /**
 | ||||
|      * @brief Gets the last five bans made on the server. | ||||
|      * | ||||
|  | ||||
| @ -44,48 +44,60 @@ DBManager::DBManager() : | ||||
|         updateDB(db_version); | ||||
| } | ||||
| 
 | ||||
| QPair<bool, QString> DBManager::isIPBanned(QString ipid) | ||||
| QPair<bool, DBManager::BanInfo> DBManager::isIPBanned(QString ipid) | ||||
| { | ||||
|     QSqlQuery query; | ||||
|     query.prepare("SELECT TIME,REASON,DURATION FROM BANS WHERE IPID = ? ORDER BY TIME DESC"); | ||||
|     query.prepare("SELECT * FROM BANS WHERE IPID = ? ORDER BY TIME DESC"); | ||||
|     query.addBindValue(ipid); | ||||
|     query.exec(); | ||||
|     BanInfo ban; | ||||
|     if (query.first()) { | ||||
|         long long ban_time = query.value(0).toLongLong(); | ||||
|         QString reason = query.value(1).toString(); | ||||
|         long long duration = query.value(2).toLongLong(); | ||||
|         if (duration == -2) | ||||
|             return {true, reason}; | ||||
|         long long current_time = QDateTime::currentDateTime().toSecsSinceEpoch(); | ||||
|         if (ban_time + duration > current_time) | ||||
|             return {true, reason}; | ||||
|         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<unsigned long>(query.value(4).toULongLong()); | ||||
|         ban.reason = query.value(5).toString(); | ||||
|         ban.duration = query.value(6).toLongLong(); | ||||
|         ban.moderator = query.value(7).toString(); | ||||
|         if (ban.duration == -2) | ||||
|             return {true, ban}; | ||||
|         unsigned long current_time = QDateTime::currentDateTime().toSecsSinceEpoch(); | ||||
|         if (ban.time + ban.duration > current_time) | ||||
|             return {true, ban}; | ||||
|         else | ||||
|             return {false, nullptr}; | ||||
|             return {false, ban}; | ||||
|     } | ||||
|     else | ||||
|         return {false, nullptr}; | ||||
|         return {false, ban}; | ||||
| } | ||||
| 
 | ||||
| QPair<bool, QString> DBManager::isHDIDBanned(QString hdid) | ||||
| QPair<bool, DBManager::BanInfo> DBManager::isHDIDBanned(QString hdid) | ||||
| { | ||||
|     QSqlQuery query; | ||||
|     query.prepare("SELECT TIME,REASON,DURATION FROM BANS WHERE HDID = ? ORDER BY TIME DESC"); | ||||
|     query.prepare("SELECT * FROM BANS WHERE HDID = ? ORDER BY TIME DESC"); | ||||
|     query.addBindValue(hdid); | ||||
|     query.exec(); | ||||
|     BanInfo ban; | ||||
|     if (query.first()) { | ||||
|         long long ban_time = query.value(0).toLongLong(); | ||||
|         QString reason = query.value(1).toString(); | ||||
|         long long duration = query.value(2).toLongLong(); | ||||
|         if (duration == -2) | ||||
|             return {true, reason}; | ||||
|         long long current_time = QDateTime::currentDateTime().toSecsSinceEpoch(); | ||||
|         if (ban_time + duration > current_time) | ||||
|             return {true, reason}; | ||||
|         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<unsigned long>(query.value(4).toULongLong()); | ||||
|         ban.reason = query.value(5).toString(); | ||||
|         ban.duration = query.value(6).toLongLong(); | ||||
|         ban.moderator = query.value(7).toString(); | ||||
|         if (ban.duration == -2) | ||||
|             return {true, ban}; | ||||
|         unsigned long current_time = QDateTime::currentDateTime().toSecsSinceEpoch(); | ||||
|         if (ban.time + ban.duration > current_time) | ||||
|             return {true, ban}; | ||||
|         else | ||||
|             return {false, nullptr}; | ||||
|             return {false, ban}; | ||||
|     } | ||||
|     else | ||||
|         return {false, nullptr}; | ||||
|         return {false, ban}; | ||||
| } | ||||
| 
 | ||||
| int DBManager::getBanID(QString hdid) | ||||
|  | ||||
| @ -35,7 +35,14 @@ void PacketHI::handlePacket(AreaData *area, AOClient &client) const | ||||
|     emit client.getServer()->logConnectionAttempt(client.m_remote_ip.toString(), client.m_ipid, client.m_hwid); | ||||
|     auto ban = client.getServer()->getDatabaseManager()->isHDIDBanned(client.m_hwid); | ||||
|     if (ban.first) { | ||||
|         client.sendPacket("BD", {ban.second + "\nBan ID: " + QString::number(client.getServer()->getDatabaseManager()->getBanID(client.m_hwid))}); | ||||
|         QString ban_duration; | ||||
|         if (!(ban.second.duration == -2)) { | ||||
|             ban_duration = QDateTime::fromSecsSinceEpoch(ban.second.time).addSecs(ban.second.duration).toString("MM/dd/yyyy, hh:mm"); | ||||
|         } | ||||
|         else { | ||||
|             ban_duration = "The heat death of the universe."; | ||||
|         } | ||||
|         client.sendPacket("BD", {"Reason: " + ban.second.reason + "\nBan ID: " + QString::number(ban.second.id) + "\nUntil: " + ban_duration}); | ||||
|         client.m_socket->close(); | ||||
|         return; | ||||
|     } | ||||
|  | ||||
| @ -194,8 +194,14 @@ void Server::clientConnected() | ||||
|         is_at_multiclient_limit = true; | ||||
| 
 | ||||
|     if (is_banned) { | ||||
|         QString reason = ban.second; | ||||
|         AOPacket *ban_reason = PacketFactory::createPacket("BD", {reason}); | ||||
|         QString ban_duration; | ||||
|         if (!(ban.second.duration == -2)) { | ||||
|             ban_duration = QDateTime::fromSecsSinceEpoch(ban.second.time).addSecs(ban.second.duration).toString("MM/dd/yyyy, hh:mm"); | ||||
|         } | ||||
|         else { | ||||
|             ban_duration = "The heat death of the universe."; | ||||
|         } | ||||
|         AOPacket *ban_reason = PacketFactory::createPacket("BD", {"Reason: " + ban.second.reason + "\nBan ID: " + QString::number(ban.second.id) + "\nUntil: " + ban_duration}); | ||||
|         socket->write(ban_reason->toUtf8()); | ||||
|     } | ||||
|     if (is_banned || is_at_multiclient_limit) { | ||||
| @ -275,8 +281,14 @@ void Server::ws_clientConnected() | ||||
|         is_at_multiclient_limit = true; | ||||
| 
 | ||||
|     if (is_banned) { | ||||
|         QString reason = ban.second; | ||||
|         AOPacket *ban_reason = PacketFactory::createPacket("BD", {reason}); | ||||
|         QString ban_duration; | ||||
|         if (!(ban.second.duration == -2)) { | ||||
|             ban_duration = QDateTime::fromSecsSinceEpoch(ban.second.time).addSecs(ban.second.duration).toString("MM/dd/yyyy, hh:mm"); | ||||
|         } | ||||
|         else { | ||||
|             ban_duration = "The heat death of the universe."; | ||||
|         } | ||||
|         AOPacket *ban_reason = PacketFactory::createPacket("BD", {"Reason: " + ban.second.reason + "\nBan ID: " + QString::number(ban.second.id) + "\nUntil: " + ban_duration}); | ||||
|         socket->sendTextMessage(ban_reason->toUtf8()); | ||||
|     } | ||||
|     if (is_banned || is_at_multiclient_limit) { | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 stonedDiscord
						stonedDiscord