Skip to content

Commit

Permalink
fix: friends not updating and using incorrect world (#1724)
Browse files Browse the repository at this point in the history
* fix: friends not updating and using incorrect world

* use better reset logic

* actual fix for real
  • Loading branch information
EmosewaMC authored Jan 7, 2025
1 parent 7599a2e commit 23551d4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
54 changes: 26 additions & 28 deletions dChatServer/ChatPacketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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);

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);
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;

//Now check if they're online:
const auto& fr = Game::playerContainer.GetPlayerData(fd.friendID);

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:
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:
Expand Down
3 changes: 3 additions & 0 deletions dChatServer/PlayerContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions dChatServer/PlayerContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct PlayerData {
std::vector<IgnoreData> ignoredPlayers;
eGameMasterLevel gmLevel = static_cast<eGameMasterLevel>(0); // CIVILLIAN
bool isFTP = false;
bool isLogin = false;
};

struct TeamData {
Expand Down

0 comments on commit 23551d4

Please sign in to comment.