diff --git a/dChatServer/ChatIgnoreList.cpp b/dChatServer/ChatIgnoreList.cpp index 1eebb570..d97c4536 100644 --- a/dChatServer/ChatIgnoreList.cpp +++ b/dChatServer/ChatIgnoreList.cpp @@ -28,6 +28,11 @@ void ChatIgnoreList::GetIgnoreList(Packet* packet) { return; } + if (!receiver->ignoredPlayers.empty()) { + LOG_DEBUG("Player %llu already has an ignore list", playerId); + return; + } + auto ignoreList = Database::Get()->GetIgnoreList(static_cast(playerId)); if (ignoreList.empty()) { LOG_DEBUG("Player %llu has no ignores", playerId); @@ -104,25 +109,31 @@ void ChatIgnoreList::AddIgnore(Packet* packet) { bitStream.Write(IgnoreResponse::ALREADY_IGNORED); } else { + // Get the playerId falling back to query if not online auto* playerData = Game::playerContainer.GetPlayerData(toIgnoreStr); if (!playerData) { // Fall back to query auto player = Database::Get()->GetCharacterInfo(toIgnoreStr); if (!player || player->name != toIgnoreStr) { LOG_DEBUG("Player %s not found", toIgnoreStr.c_str()); - - 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); - - receiver->ignoredPlayers.push_back(IgnoreData{ ignoredPlayerId, toIgnoreStr }); - LOG_DEBUG("Player %llu is ignoring %s", playerId, toIgnoreStr.c_str()); - - bitStream.Write(IgnoreResponse::SUCCESS); } + } else { + ignoredPlayerId = playerData->playerID; + } + + if (ignoredPlayerId != LWOOBJID_EMPTY) { + Database::Get()->AddIgnore(static_cast(playerId), static_cast(ignoredPlayerId)); + GeneralUtils::SetBit(ignoredPlayerId, eObjectBits::CHARACTER); + GeneralUtils::SetBit(ignoredPlayerId, eObjectBits::PERSISTENT); + + receiver->ignoredPlayers.push_back(IgnoreData{ ignoredPlayerId, toIgnoreStr }); + LOG_DEBUG("Player %llu is ignoring %s", playerId, toIgnoreStr.c_str()); + + bitStream.Write(IgnoreResponse::SUCCESS); + } else { + bitStream.Write(IgnoreResponse::PLAYER_NOT_FOUND); } } diff --git a/dDatabase/GameDatabase/MySQL/Tables/IgnoreList.cpp b/dDatabase/GameDatabase/MySQL/Tables/IgnoreList.cpp index ec90e341..283df324 100644 --- a/dDatabase/GameDatabase/MySQL/Tables/IgnoreList.cpp +++ b/dDatabase/GameDatabase/MySQL/Tables/IgnoreList.cpp @@ -14,7 +14,7 @@ std::vector MySQLDatabase::GetIgnoreList(const uint32_t playe } void MySQLDatabase::AddIgnore(const uint32_t playerId, const uint32_t ignoredPlayerId) { - ExecuteInsert("INSERT INTO ignore_list (player_id, ignored_player_id) VALUES (?, ?)", playerId, ignoredPlayerId); + ExecuteInsert("INSERT IGNORE INTO ignore_list (player_id, ignored_player_id) VALUES (?, ?)", playerId, ignoredPlayerId); } void MySQLDatabase::RemoveIgnore(const uint32_t playerId, const uint32_t ignoredPlayerId) {