From 136133dde21c077a1e5d41a79f404b0918673223 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Wed, 8 Jan 2025 20:44:55 -0800 Subject: [PATCH] fix: friends (#1726) * fix * Update ChatPacketHandler.cpp --- dChatServer/ChatPacketHandler.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/dChatServer/ChatPacketHandler.cpp b/dChatServer/ChatPacketHandler.cpp index ead39a84..d01d65fd 100644 --- a/dChatServer/ChatPacketHandler.cpp +++ b/dChatServer/ChatPacketHandler.cpp @@ -103,7 +103,8 @@ void ChatPacketHandler::HandleFriendRequest(Packet* packet) { return; }; - auto& requestee = Game::playerContainer.GetPlayerDataMutable(playerName); + // Intentional copy + PlayerData requestee = Game::playerContainer.GetPlayerData(playerName); // Check if player is online first if (isBestFriendRequest && !requestee) { @@ -188,19 +189,24 @@ void ChatPacketHandler::HandleFriendRequest(Packet* packet) { Database::Get()->SetBestFriendStatus(requestorPlayerID, requestee.playerID, bestFriendStatus); // Sent the best friend update here if the value is 3 if (bestFriendStatus == 3U) { - requestee.countOfBestFriends += 1; - requestor.countOfBestFriends += 1; if (requestee.sysAddr != UNASSIGNED_SYSTEM_ADDRESS) SendFriendResponse(requestee, requestor, eAddFriendResponseType::ACCEPTED, false, true); if (requestor.sysAddr != UNASSIGNED_SYSTEM_ADDRESS) SendFriendResponse(requestor, requestee, eAddFriendResponseType::ACCEPTED, false, true); + for (auto& friendData : requestor.friends) { if (friendData.friendID == requestee.playerID) { friendData.isBestFriend = true; } } - for (auto& friendData : requestee.friends) { - if (friendData.friendID == requestor.playerID) { - friendData.isBestFriend = true; + requestor.countOfBestFriends += 1; + + auto& toModify = Game::playerContainer.GetPlayerDataMutable(playerName); + if (toModify) { + for (auto& friendData : toModify.friends) { + if (friendData.friendID == requestor.playerID) { + friendData.isBestFriend = true; + } } + toModify.countOfBestFriends += 1; } } }