Just when I thought OnlineSubsystemEOS can’t get any worse with half of the interface methods not implemented, someone decided to implement FindFriendSession (“only for lobbies”).
He did a good search which is working (I suppose) and finding lobbies. Then this man calls a delegate with 1 parameter: whether the search was successful or not.
Thank you, this is a very important information indeed. How do I access the search results though? And why TriggerOnFindFriendSessionCompleteDelegates couldn’t be called?
Correct code:
bool FOnlineSessionEOS::FindFriendSession(int32 LocalUserNum, const FUniqueNetId& Friend)
{
bool bResult = false;
// So far there is only a lobby implementation for this
// We create the search handle
EOS_HLobbySearch LobbySearchHandle;
EOS_Lobby_CreateLobbySearchOptions CreateLobbySearchOptions = { 0 };
CreateLobbySearchOptions.ApiVersion = EOS_LOBBY_CREATELOBBYSEARCH_API_LATEST;
CreateLobbySearchOptions.MaxResults = EOS_SESSIONS_MAX_SEARCH_RESULTS;
EOS_EResult CreateLobbySearchResult = EOS_Lobby_CreateLobbySearch(LobbyHandle, &CreateLobbySearchOptions, &LobbySearchHandle);
if (CreateLobbySearchResult == EOS_EResult::EOS_Success)
{
const FUniqueNetIdEOS& FriendEOSId = FUniqueNetIdEOS::Cast(Friend);
// Set the user we wan to use to find lobbies
EOS_LobbySearch_SetTargetUserIdOptions SetTargetUserIdOptions = { 0 };
SetTargetUserIdOptions.ApiVersion = EOS_LOBBYSEARCH_SETTARGETUSERID_API_LATEST;
SetTargetUserIdOptions.TargetUserId = FriendEOSId.GetProductUserId();
// TODO: Using this as a search parameter only works if we use the owner's id (search for lobbies we're already in). Pending API fix so it works with other users too.
EOS_LobbySearch_SetTargetUserId(LobbySearchHandle, &SetTargetUserIdOptions);
// Then perform the search
CurrentSessionSearch = MakeShareable(new FOnlineSessionSearch());
CurrentSessionSearch->SearchState = EOnlineAsyncTaskState::InProgress;
StartLobbySearch(LocalUserNum, LobbySearchHandle, CurrentSessionSearch.ToSharedRef(), FOnSingleSessionResultCompleteDelegate::CreateLambda([this](int32 LocalUserNum, bool bWasSuccessful, const FOnlineSessionSearchResult& EOSResult)
{
TriggerOnFindFriendSessionCompleteDelegates(LocalUserNum, bWasSuccessful, {EOSResult});
}));
bResult = true;
}
else
{
UE_LOG_ONLINE_SESSION(Warning, TEXT("[FOnlineSessionEOS::FindFriendSession] CreateLobbySearch not successful. Finished with EOS_EResult %s"), ANSI_TO_TCHAR(EOS_EResult_ToString(CreateLobbySearchResult)));
EOSSubsystem->ExecuteNextTick([this, LocalUserNum]()
{
TriggerOnFindFriendSessionCompleteDelegates(LocalUserNum, false, {});
});
}
return bResult;
};