/** * Find an online session * * @param UserId user that initiated the request * @param SessionName name of session this search will generate * @param bIsLAN are we searching LAN matches * @param bIsPresence are we searching presence sessions */ void URadeGameInstance::FindSessions(TSharedPtr<const FUniqueNetId> UserId, FName SessionName, bool bIsLAN, bool bIsPresence) { // Get the OnlineSubsystem we want to work with IOnlineSubsystem* OnlineSub = IOnlineSubsystem::Get(); if (OnlineSub) { bIsSearchingSession = true; // Get the SessionInterface from our OnlineSubsystem IOnlineSessionPtr Sessions = OnlineSub->GetSessionInterface(); if (Sessions.IsValid() && UserId.IsValid()) { /* Fill in all the SearchSettings, like if we are searching for a LAN game and how many results we want to have! */ SessionSearch = MakeShareable(new FOnlineSessionSearch()); SessionSearch->bIsLanQuery = bIsLAN; SessionSearch->MaxSearchResults = 20; SessionSearch->PingBucketSize = 50; // We only want to set this Query Setting if "bIsPresence" is true if (bIsPresence) { SessionSearch->QuerySettings.Set(SEARCH_PRESENCE, bIsPresence, EOnlineComparisonOp::Equals); } TSharedRef<FOnlineSessionSearch> SearchSettingsRef = SessionSearch.ToSharedRef(); // Set the Delegate to the Delegate Handle of the FindSession function OnFindSessionsCompleteDelegateHandle = Sessions->AddOnFindSessionsCompleteDelegate_Handle(OnFindSessionsCompleteDelegate); // Finally call the SessionInterface function. The Delegate gets called once this is finished Sessions->FindSessions(*UserId, SearchSettingsRef); } } else { // If something goes wrong, just call the Delegate Function directly with "false". OnFindSessionsComplete(false); } }
bool UQosEvaluator::FindQosServersByRegion(int32 RegionIdx, FOnQosSearchComplete InCompletionDelegate) { bool bSuccess = false; if (Datacenters.IsValidIndex(RegionIdx)) { FQosRegionInfo& Datacenter = Datacenters[RegionIdx]; Datacenter.Reset(); IOnlineSubsystem* OnlineSub = Online::GetSubsystem(GetWorld()); if (OnlineSub) { IOnlineSessionPtr SessionInt = OnlineSub->GetSessionInterface(); if (SessionInt.IsValid()) { if (!Datacenter.Region.RegionId.IsEmpty()) { const TSharedRef<FOnlineSessionSearch> QosSearchParams = MakeShareable(new FOnlineSessionSearchQos()); QosSearchParams->QuerySettings.Set(SETTING_REGION, Datacenter.Region.RegionId, EOnlineComparisonOp::Equals); QosSearchQuery = QosSearchParams; FOnFindSessionsCompleteDelegate OnFindDatacentersCompleteDelegate = FOnFindSessionsCompleteDelegate::CreateUObject(this, &ThisClass::OnFindQosServersByRegionComplete, RegionIdx, InCompletionDelegate); OnFindDatacentersCompleteDelegateHandle = SessionInt->AddOnFindSessionsCompleteDelegate_Handle(OnFindDatacentersCompleteDelegate); SessionInt->FindSessions(ControllerId, QosSearchParams); } else { OnFindQosServersByRegionComplete(false, RegionIdx, InCompletionDelegate); } bSuccess = true; } } } return bSuccess; }