From d193fe61be5e6915c9440d71c3512f20665dd464 Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Sat, 18 Nov 2023 18:05:26 -0800 Subject: [PATCH] Database working for ignores --- dChatServer/ChatIgnoreList.cpp | 14 ++++++++++++ dDatabase/GameDatabase/GameDatabase.h | 3 ++- dDatabase/GameDatabase/ITables/IIgnoreList.h | 20 +++++++++++++++++ dDatabase/GameDatabase/MySQL/MySQLDatabase.h | 3 +++ .../GameDatabase/MySQL/Tables/CMakeLists.txt | 1 + .../GameDatabase/MySQL/Tables/IgnoreList.cpp | 22 +++++++++++++++++++ migrations/dlu/13_ignore_list.sql | 6 +++++ 7 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 dDatabase/GameDatabase/ITables/IIgnoreList.h create mode 100644 dDatabase/GameDatabase/MySQL/Tables/IgnoreList.cpp create mode 100644 migrations/dlu/13_ignore_list.sql diff --git a/dChatServer/ChatIgnoreList.cpp b/dChatServer/ChatIgnoreList.cpp index bcb771e7..1eebb570 100644 --- a/dChatServer/ChatIgnoreList.cpp +++ b/dChatServer/ChatIgnoreList.cpp @@ -28,6 +28,18 @@ void ChatIgnoreList::GetIgnoreList(Packet* packet) { return; } + auto ignoreList = Database::Get()->GetIgnoreList(static_cast(playerId)); + if (ignoreList.empty()) { + LOG_DEBUG("Player %llu has no ignores", playerId); + return; + } + + for (auto& ignoredPlayer : ignoreList) { + receiver->ignoredPlayers.push_back(IgnoreData{ ignoredPlayer.id, ignoredPlayer.name }); + GeneralUtils::SetBit(receiver->ignoredPlayers.back().playerId, eObjectBits::CHARACTER); + GeneralUtils::SetBit(receiver->ignoredPlayers.back().playerId, eObjectBits::PERSISTENT); + } + CBITSTREAM; BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); bitStream.Write(receiver->playerID); @@ -102,6 +114,7 @@ void ChatIgnoreList::AddIgnore(Packet* packet) { bitStream.Write(IgnoreResponse::PLAYER_NOT_FOUND); } else { ignoredPlayerId = player->id; + Database::Get()->AddIgnore(static_cast(playerId), static_cast(ignoredPlayerId)); GeneralUtils::SetBit(ignoredPlayerId, eObjectBits::CHARACTER); GeneralUtils::SetBit(ignoredPlayerId, eObjectBits::PERSISTENT); @@ -146,6 +159,7 @@ void ChatIgnoreList::RemoveIgnore(Packet* packet) { return; } + Database::Get()->RemoveIgnore(static_cast(playerId), static_cast(toRemove->playerId)); receiver->ignoredPlayers.erase(toRemove, receiver->ignoredPlayers.end()); CBITSTREAM; BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER); diff --git a/dDatabase/GameDatabase/GameDatabase.h b/dDatabase/GameDatabase/GameDatabase.h index 7d8c7de9..a79bc8d4 100644 --- a/dDatabase/GameDatabase/GameDatabase.h +++ b/dDatabase/GameDatabase/GameDatabase.h @@ -21,6 +21,7 @@ #include "ICharInfo.h" #include "IAccounts.h" #include "IActivityLog.h" +#include "IIgnoreList.h" namespace sql { class Statement; @@ -38,7 +39,7 @@ class GameDatabase : public IMail, public ICommandLog, public IPlayerCheatDetections, public IBugReports, public IPropertyContents, public IProperty, public IPetNames, public ICharXml, public IMigrationHistory, public IUgc, public IFriends, public ICharInfo, - public IAccounts, public IActivityLog { + public IAccounts, public IActivityLog, public IIgnoreList { public: virtual ~GameDatabase() = default; // TODO: These should be made private. diff --git a/dDatabase/GameDatabase/ITables/IIgnoreList.h b/dDatabase/GameDatabase/ITables/IIgnoreList.h new file mode 100644 index 00000000..cf831203 --- /dev/null +++ b/dDatabase/GameDatabase/ITables/IIgnoreList.h @@ -0,0 +1,20 @@ +#ifndef __IIGNORELIST__H__ +#define __IIGNORELIST__H__ + +#include +#include +#include + +class IIgnoreList { +public: + struct Info { + std::string name; + uint32_t id; + }; + + virtual std::vector GetIgnoreList(const uint32_t playerId) = 0; + virtual void AddIgnore(const uint32_t playerId, const uint32_t ignoredPlayerId) = 0; + virtual void RemoveIgnore(const uint32_t playerId, const uint32_t ignoredPlayerId) = 0; +}; + +#endif //!__IIGNORELIST__H__ diff --git a/dDatabase/GameDatabase/MySQL/MySQLDatabase.h b/dDatabase/GameDatabase/MySQL/MySQLDatabase.h index bed79bb7..26bfd2d9 100644 --- a/dDatabase/GameDatabase/MySQL/MySQLDatabase.h +++ b/dDatabase/GameDatabase/MySQL/MySQLDatabase.h @@ -103,6 +103,9 @@ public: std::optional GetDonationTotal(const uint32_t activityId) override; std::optional IsPlaykeyActive(const int32_t playkeyId) override; std::vector GetUgcModels(const LWOOBJID& propertyId) override; + void AddIgnore(const uint32_t playerId, const uint32_t ignoredPlayerId) override; + void RemoveIgnore(const uint32_t playerId, const uint32_t ignoredPlayerId) override; + std::vector GetIgnoreList(const uint32_t playerId) override; private: // Generic query functions that can be used for any query. diff --git a/dDatabase/GameDatabase/MySQL/Tables/CMakeLists.txt b/dDatabase/GameDatabase/MySQL/Tables/CMakeLists.txt index e9593ba9..51b5d34a 100644 --- a/dDatabase/GameDatabase/MySQL/Tables/CMakeLists.txt +++ b/dDatabase/GameDatabase/MySQL/Tables/CMakeLists.txt @@ -6,6 +6,7 @@ set(DDATABASES_DATABASES_MYSQL_TABLES_SOURCES "CharXml.cpp" "CommandLog.cpp" "Friends.cpp" + "IgnoreList.cpp" "Leaderboard.cpp" "Mail.cpp" "MigrationHistory.cpp" diff --git a/dDatabase/GameDatabase/MySQL/Tables/IgnoreList.cpp b/dDatabase/GameDatabase/MySQL/Tables/IgnoreList.cpp new file mode 100644 index 00000000..ec90e341 --- /dev/null +++ b/dDatabase/GameDatabase/MySQL/Tables/IgnoreList.cpp @@ -0,0 +1,22 @@ +#include "MySQLDatabase.h" + +std::vector MySQLDatabase::GetIgnoreList(const uint32_t playerId) { + auto result = ExecuteSelect("SELECT ci.name AS name, il.ignored_player_id AS ignore_id FROM ignore_list AS il JOIN charinfo AS ci ON il.ignored_player_id = ci.id WHERE il.player_id = ?", playerId); + + std::vector ignoreList; + + ignoreList.reserve(result->rowsCount()); + while (result->next()) { + ignoreList.push_back(IIgnoreList::Info{ result->getString("name").c_str(), result->getUInt("ignore_id") }); + } + + return ignoreList; +} + +void MySQLDatabase::AddIgnore(const uint32_t playerId, const uint32_t ignoredPlayerId) { + ExecuteInsert("INSERT INTO ignore_list (player_id, ignored_player_id) VALUES (?, ?)", playerId, ignoredPlayerId); +} + +void MySQLDatabase::RemoveIgnore(const uint32_t playerId, const uint32_t ignoredPlayerId) { + ExecuteDelete("DELETE FROM ignore_list WHERE player_id = ? AND ignored_player_id = ?", playerId, ignoredPlayerId); +} diff --git a/migrations/dlu/13_ignore_list.sql b/migrations/dlu/13_ignore_list.sql new file mode 100644 index 00000000..2550beb5 --- /dev/null +++ b/migrations/dlu/13_ignore_list.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXISTS ignore_list ( + player_id BIGINT NOT NULL REFERENCES charinfo(id) ON DELETE CASCADE, + ignored_player_id BIGINT NOT NULL REFERENCES charinfo(id) ON DELETE CASCADE, + + PRIMARY KEY (player_id, ignored_player_id) +);