Пример #1
0
void UtrnetDemoGameInstance::OnFindSessionsComplete(bool bWasSuccessful)
{
    isLoading_ = false;
	GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("OFindSessionsComplete bSuccess: %d"), bWasSuccessful));

    // Get SessionInterface of the OnlineSubsystem
    IOnlineSessionPtr Sessions = GetSession();
    
    if (!Sessions.IsValid())
    {
        return;
    }
    // Clear the Delegate handle, since we finished this call
    Sessions->ClearOnFindSessionsCompleteDelegate_Handle(OnFindSessionsCompleteDelegateHandle);

    // Just debugging the Number of Search results. Can be displayed in UMG or something later on
    GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("Num Search Results: %d"), SessionSearch->SearchResults.Num()));

    // If we have found at least 1 session, we just going to debug them. You could add them to a list of UMG Widgets, like it is done in the BP version!
    if (SessionSearch->SearchResults.Num() > 0)
    {
        // "SessionSearch->SearchResults" is an Array that contains all the information. You can access the Session in this and get a lot of information.
        // This can be customized later on with your own classes to add more information that can be set and displayed
        for (int32 SearchIdx = 0; SearchIdx < SessionSearch->SearchResults.Num(); SearchIdx++)
        {
            // OwningUserName is just the SessionName for now. I guess you can create your own Host Settings class and GameSession Class and add a proper GameServer Name here.
            // This is something you can't do in Blueprint for example!
            GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("Session Number: %d | Sessionname: %s "), SearchIdx + 1, *(SessionSearch->SearchResults[SearchIdx].Session.OwningUserName)));
        }
    }
}
Пример #2
0
/**
*	Delegate fired when a session search query has completed
*
*	@param bWasSuccessful true if the async action completed without error, false if there was an error
*/
void URadeGameInstance::OnFindSessionsComplete(bool bWasSuccessful)
{
	// Start Session Search
	bIsSearchingSession = false;

	// Get OnlineSubsystem we want to work with
	IOnlineSubsystem* const OnlineSub = IOnlineSubsystem::Get();
	if (OnlineSub)
	{
		// Get SessionInterface of the OnlineSubsystem
		IOnlineSessionPtr Sessions = OnlineSub->GetSessionInterface();
		if (Sessions.IsValid())
		{
			// Clear the Delegate handle, since we finished this call
			Sessions->ClearOnFindSessionsCompleteDelegate_Handle(OnFindSessionsCompleteDelegateHandle);
		}
	}

	UpdateSessionList();
}
Пример #3
0
void UQosEvaluator::OnFindQosServersByRegionComplete(bool bWasSuccessful, int32 RegionIdx, FOnQosSearchComplete InCompletionDelegate)
{
    IOnlineSubsystem* OnlineSub = Online::GetSubsystem(GetWorld());
    if (OnlineSub)
    {
        IOnlineSessionPtr SessionInt = OnlineSub->GetSessionInterface();
        if (SessionInt.IsValid())
        {
            SessionInt->ClearOnFindSessionsCompleteDelegate_Handle(OnFindDatacentersCompleteDelegateHandle);
        }
    }

    if (!bCancelOperation)
    {
        FQosRegionInfo& Datacenter = Datacenters[RegionIdx];
        Datacenter.Result = bWasSuccessful ? EQosCompletionResult::Success : EQosCompletionResult::Failure;

        // Copy the search results for later evaluation
        Datacenter.SearchResults = QosSearchQuery->SearchResults;
        QosSearchQuery = nullptr;

        int32 NextRegionIdx = GetNextRegionId(RegionIdx);
        if (Datacenters.IsValidIndex(NextRegionIdx))
        {
            TWeakObjectPtr<UQosEvaluator> WeakThisCap(this);
            GetWorldTimerManager().SetTimerForNextTick(FTimerDelegate::CreateLambda([InCompletionDelegate, NextRegionIdx, WeakThisCap]()
            {
                if (WeakThisCap.IsValid())
                {
                    auto StrongThis = WeakThisCap.Get();
                    // Move to the next region results
                    if (!StrongThis->FindQosServersByRegion(NextRegionIdx, InCompletionDelegate))
                    {
                        // Failed to start
                        StrongThis->GetWorldTimerManager().SetTimerForNextTick(FTimerDelegate::CreateLambda([InCompletionDelegate, WeakThisCap]()
                        {
                            if (WeakThisCap.IsValid())
                            {
                                auto StrongThis1 = WeakThisCap.Get();
                                StrongThis1->FinalizeDatacenterResult(InCompletionDelegate, EQosCompletionResult::Failure, TArray<FQosRegionInfo>());
                            }
                        }));
                    }
                }
            }));
        }
        else
        {
            // Evaluate search results for all regions next tick
            FOnQosPingEvalComplete CompletionDelegate = FOnQosPingEvalComplete::CreateUObject(this, &ThisClass::OnEvaluateForDatacenterComplete, InCompletionDelegate);

            TWeakObjectPtr<UQosEvaluator> WeakThisCap(this);
            GetWorldTimerManager().SetTimerForNextTick(FTimerDelegate::CreateLambda([CompletionDelegate, WeakThisCap]()
            {
                if (WeakThisCap.IsValid())
                {
                    auto StrongThis = WeakThisCap.Get();
                    StrongThis->bInProgress = false;
                    StrongThis->StartServerPing(CompletionDelegate);
                }
            }));
        }
    }
    else
    {
        QosSearchQuery = nullptr;

        // Mark all remaining datacenters as canceled
        for (int32 Idx = RegionIdx; Idx < Datacenters.Num(); Idx++)
        {
            Datacenters[Idx].Result = EQosCompletionResult::Canceled;
        }

        FinalizeDatacenterResult(InCompletionDelegate, EQosCompletionResult::Canceled, Datacenters);
    }
}