EpicGames / EOS-Getting-Started

MIT License
110 stars 62 forks source link

Add a second call to ReadFriendsList() #15

Closed arousta closed 10 months ago

arousta commented 10 months ago

Observe that after the second call the GetFriends() won't return the list of friends.

The bug is here in the FUserManagerEOS::AddFriend() function:

    // Add this friend as a remote player if we haven't already (this will grab user info)
    if (!UniqueNetIdToAttributeAccessMap.Contains(FriendNetId))
    {
        AddRemotePlayer(LocalUserNum, EpicAccountId, FriendRef);
    }

The UniqueNetIdToAttributeAccessMap basically contains the cached information of friends which is populated during the first call to the ReadFriendsList().

During the second call, here we skip calling the AddRemotePlayer() function to avoid making unnecessary requests for obtainig the friends info which we already have in our cache.

However the problem is that we've forgotten to set the friend info using our cached values in the else block. The fix would be to move a piece of code from the FUserManagerEOS::ReadUserInfo() to here:

    // Add this friend as a remote player if we haven't already (this will grab user info)
    if (!UniqueNetIdToAttributeAccessMap.Contains(FriendNetId))
    {
        AddRemotePlayer(LocalUserNum, EpicAccountId, FriendRef);
    }
        else
        {
        // set user info from the cached info
            IAttributeAccessInterfaceRef AttributeAccessRef = UniqueNetIdToAttributeAccessMap[FriendNetId];
            FOnlineFriendEOSPtr FriendPtr = LocalUser.FriendsList->GetByNetId(FriendNetId);
            FriendPtr->UpdateInternalAttributes(AttributeAccessRef->GetInternalAttributes());
        }