fix: friends (#1726)

* fix

* Update ChatPacketHandler.cpp
This commit is contained in:
David Markowitz 2025-01-08 20:44:55 -08:00 committed by GitHub
parent 23551d4ed8
commit 136133dde2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -103,7 +103,8 @@ void ChatPacketHandler::HandleFriendRequest(Packet* packet) {
return; return;
}; };
auto& requestee = Game::playerContainer.GetPlayerDataMutable(playerName); // Intentional copy
PlayerData requestee = Game::playerContainer.GetPlayerData(playerName);
// Check if player is online first // Check if player is online first
if (isBestFriendRequest && !requestee) { if (isBestFriendRequest && !requestee) {
@ -188,20 +189,25 @@ void ChatPacketHandler::HandleFriendRequest(Packet* packet) {
Database::Get()->SetBestFriendStatus(requestorPlayerID, requestee.playerID, bestFriendStatus); Database::Get()->SetBestFriendStatus(requestorPlayerID, requestee.playerID, bestFriendStatus);
// Sent the best friend update here if the value is 3 // Sent the best friend update here if the value is 3
if (bestFriendStatus == 3U) { if (bestFriendStatus == 3U) {
requestee.countOfBestFriends += 1;
requestor.countOfBestFriends += 1;
if (requestee.sysAddr != UNASSIGNED_SYSTEM_ADDRESS) SendFriendResponse(requestee, requestor, eAddFriendResponseType::ACCEPTED, false, true); 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); if (requestor.sysAddr != UNASSIGNED_SYSTEM_ADDRESS) SendFriendResponse(requestor, requestee, eAddFriendResponseType::ACCEPTED, false, true);
for (auto& friendData : requestor.friends) { for (auto& friendData : requestor.friends) {
if (friendData.friendID == requestee.playerID) { if (friendData.friendID == requestee.playerID) {
friendData.isBestFriend = true; friendData.isBestFriend = true;
} }
} }
for (auto& friendData : requestee.friends) { requestor.countOfBestFriends += 1;
auto& toModify = Game::playerContainer.GetPlayerDataMutable(playerName);
if (toModify) {
for (auto& friendData : toModify.friends) {
if (friendData.friendID == requestor.playerID) { if (friendData.friendID == requestor.playerID) {
friendData.isBestFriend = true; friendData.isBestFriend = true;
} }
} }
toModify.countOfBestFriends += 1;
}
} }
} }
} else { } else {