From 23551d4ed8cc53ac0835a85ce871b2e529979ee9 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Mon, 6 Jan 2025 18:25:51 -0800 Subject: [PATCH] fix: friends not updating and using incorrect world (#1724) * fix: friends not updating and using incorrect world * use better reset logic * actual fix for real --- dChatServer/ChatPacketHandler.cpp | 46 +++++++++++++++---------------- dChatServer/PlayerContainer.cpp | 3 ++ dChatServer/PlayerContainer.h | 1 + 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/dChatServer/ChatPacketHandler.cpp b/dChatServer/ChatPacketHandler.cpp index 40901440..ead39a84 100644 --- a/dChatServer/ChatPacketHandler.cpp +++ b/dChatServer/ChatPacketHandler.cpp @@ -29,35 +29,33 @@ void ChatPacketHandler::HandleFriendlistRequest(Packet* packet) { auto& player = Game::playerContainer.GetPlayerDataMutable(playerID); if (!player) return; - if (player.friends.empty()) { - auto friendsList = Database::Get()->GetFriendsList(playerID); - for (const auto& friendData : friendsList) { - FriendData fd; - fd.isFTP = false; // not a thing in DLU - fd.friendID = friendData.friendID; - GeneralUtils::SetBit(fd.friendID, eObjectBits::PERSISTENT); - GeneralUtils::SetBit(fd.friendID, eObjectBits::CHARACTER); + auto friendsList = Database::Get()->GetFriendsList(playerID); + for (const auto& friendData : friendsList) { + FriendData fd; + fd.isFTP = false; // not a thing in DLU + fd.friendID = friendData.friendID; + GeneralUtils::SetBit(fd.friendID, eObjectBits::PERSISTENT); + GeneralUtils::SetBit(fd.friendID, eObjectBits::CHARACTER); - fd.isBestFriend = friendData.isBestFriend; //0 = friends, 1 = left_requested, 2 = right_requested, 3 = both_accepted - are now bffs - if (fd.isBestFriend) player.countOfBestFriends += 1; - fd.friendName = friendData.friendName; + fd.isBestFriend = friendData.isBestFriend; //0 = friends, 1 = left_requested, 2 = right_requested, 3 = both_accepted - are now bffs + if (fd.isBestFriend) player.countOfBestFriends += 1; + fd.friendName = friendData.friendName; - //Now check if they're online: - const auto& fr = Game::playerContainer.GetPlayerData(fd.friendID); + //Now check if they're online: + const auto& fr = Game::playerContainer.GetPlayerData(fd.friendID); - if (fr) { - fd.isOnline = true; - fd.zoneID = fr.zoneID; + if (fr) { + fd.isOnline = true; + fd.zoneID = fr.zoneID; - //Since this friend is online, we need to update them on the fact that we've just logged in: - SendFriendUpdate(fr, player, 1, fd.isBestFriend); - } else { - fd.isOnline = false; - fd.zoneID = LWOZONEID(); - } - - player.friends.push_back(fd); + //Since this friend is online, we need to update them on the fact that we've just logged in: + if (player.isLogin) SendFriendUpdate(fr, player, 1, fd.isBestFriend); + } else { + fd.isOnline = false; + fd.zoneID = LWOZONEID(); } + + player.friends.push_back(fd); } //Now, we need to send the friendlist to the server they came from: diff --git a/dChatServer/PlayerContainer.cpp b/dChatServer/PlayerContainer.cpp index 6e2fd6f8..9dbce529 100644 --- a/dChatServer/PlayerContainer.cpp +++ b/dChatServer/PlayerContainer.cpp @@ -32,7 +32,10 @@ void PlayerContainer::InsertPlayer(Packet* packet) { return; } + auto isLogin = !m_Players.contains(playerId); auto& data = m_Players[playerId]; + data = PlayerData(); + data.isLogin = isLogin; data.playerID = playerId; uint32_t len; diff --git a/dChatServer/PlayerContainer.h b/dChatServer/PlayerContainer.h index c888de08..bccb19e3 100644 --- a/dChatServer/PlayerContainer.h +++ b/dChatServer/PlayerContainer.h @@ -46,6 +46,7 @@ struct PlayerData { std::vector ignoredPlayers; eGameMasterLevel gmLevel = static_cast(0); // CIVILLIAN bool isFTP = false; + bool isLogin = false; }; struct TeamData {