From 3fce3adb39e353c8c40bdfef669a962c1dec2b2f Mon Sep 17 00:00:00 2001 From: Kelsi Date: Tue, 10 Mar 2026 05:48:37 -0700 Subject: [PATCH] game: keep contacts_ in sync with SMSG_FRIEND_STATUS updates When a friend goes online, offline, or is added/removed, update the contacts_ vector in addition to friendsCache. This ensures the Friends tab in the Social window always reflects the current state without needing a full SMSG_CONTACT_LIST/SMSG_FRIEND_LIST refresh. --- src/game/game_handler.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/game/game_handler.cpp b/src/game/game_handler.cpp index 6e6e8d54..4c5d635e 100644 --- a/src/game/game_handler.cpp +++ b/src/game/game_handler.cpp @@ -16551,6 +16551,28 @@ void GameHandler::handleFriendStatus(network::Packet& packet) { friendsCache.erase(playerName); } + // Mirror into contacts_: update existing entry or add/remove as needed + if (data.status == 0) { // Removed from friends list + contacts_.erase(std::remove_if(contacts_.begin(), contacts_.end(), + [&](const ContactEntry& e){ return e.guid == data.guid; }), contacts_.end()); + } else { + auto cit = std::find_if(contacts_.begin(), contacts_.end(), + [&](const ContactEntry& e){ return e.guid == data.guid; }); + if (cit != contacts_.end()) { + if (!playerName.empty() && playerName != "Unknown") cit->name = playerName; + // status: 2=online→1, 3=offline→0, 1=added→1 (online on add) + if (data.status == 2) cit->status = 1; + else if (data.status == 3) cit->status = 0; + } else { + ContactEntry entry; + entry.guid = data.guid; + entry.name = playerName; + entry.flags = 0x1; // friend + entry.status = (data.status == 2) ? 1 : 0; + contacts_.push_back(std::move(entry)); + } + } + // Status messages switch (data.status) { case 0: