Exemple #1
0
void URadeGameInstance::OnJoinSessionComplete(FName SessionName, EOnJoinSessionCompleteResult::Type Result)
{
	// Get the OnlineSubsystem we want to work with
	IOnlineSubsystem* OnlineSub = IOnlineSubsystem::Get();
	if (OnlineSub)
	{
		// Get SessionInterface from the OnlineSubsystem
		IOnlineSessionPtr Sessions = OnlineSub->GetSessionInterface();

		if (Sessions.IsValid())
		{
			// Clear the Delegate again
			Sessions->ClearOnJoinSessionCompleteDelegate_Handle(OnJoinSessionCompleteDelegateHandle);

			// Get the first local PlayerController, so we can call "ClientTravel" to get to the Server Map
			// This is something the Blueprint Node "Join Session" does automatically!
			APlayerController * const PlayerController = GetFirstLocalPlayerController();

			// We need a FString to use ClientTravel and we can let the SessionInterface contruct such a
			// String for us by giving him the SessionName and an empty String. We want to do this, because
			// Every OnlineSubsystem uses different TravelURLs
			FString TravelURL;

			if (PlayerController && Sessions->GetResolvedConnectString(SessionName, TravelURL))
			{
				// Finally call the ClienTravel. If you want, you could print the TravelURL to see
				// how it really looks like
				PlayerController->ClientTravel(TravelURL, ETravelType::TRAVEL_Absolute);
			}
		}
	}
}
void UtrnetDemoGameInstance::OnJoinSessionComplete(FName SessionName, EOnJoinSessionCompleteResult::Type Result)
{
    isLoading_ = false;
	GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("OnJoinSessionComplete %s, %d"), *SessionName.ToString(), static_cast<int32>(Result)));

    // Get SessionInterface from the OnlineSubsystem
    IOnlineSessionPtr Sessions = GetSession();

    if (!Sessions.IsValid())
    {
        return;
    }
    // Clear the Delegate again
    Sessions->ClearOnJoinSessionCompleteDelegate_Handle(OnJoinSessionCompleteDelegateHandle);

    // Get the first local PlayerController, so we can call "ClientTravel" to get to the Server Map
    // This is something the Blueprint Node "Join Session" does automatically!
    APlayerController * const PlayerController = GetFirstLocalPlayerController();

    // We need a FString to use ClientTravel and we can let the SessionInterface contruct such a
    // String for us by giving him the SessionName and an empty String. We want to do this, because
    // Every OnlineSubsystem uses different TravelURLs
    FString TravelURL;

    if (PlayerController && Sessions->GetResolvedConnectString(SessionName, TravelURL))
    {
        // Finally call the ClienTravel. If you want, you could print the TravelURL to see
        // how it really looks like
        PlayerController->ClientTravel(TravelURL, ETravelType::TRAVEL_Absolute);
    }
}