bool AGameSession::TravelToSession(int32 ControllerId, FName InSessionName)
{
	UWorld* World = GetWorld();

	FString URL;
	if (UOnlineEngineInterface::Get()->GetResolvedConnectString(World, InSessionName, URL))
	{
		APlayerController* PC = UGameplayStatics::GetPlayerController(World, ControllerId);
		if (PC)
		{
			PC->ClientTravel(URL, TRAVEL_Absolute);
			return true;
		}
	}
	else
	{
		UE_LOG(LogGameSession, Warning, TEXT("Failed to resolve session connect string for %s"), *InSessionName.ToString());
	}

	return false;
}
/**
 * Delegate fired when the joining process for an online session has completed
 *
 * @param SessionName the name of the session this callback is for
 * @param bWasSuccessful true if the async action completed without error, false if there was an error
 */
void UOnlineSessionClient::OnJoinSessionComplete(FName SessionName, EOnJoinSessionCompleteResult::Type Result)
{
	UE_LOG(LogOnline, Verbose, TEXT("OnJoinSessionComplete %s bSuccess: %d"), *SessionName.ToString(), static_cast<int32>(Result));
	SessionInt->ClearOnJoinSessionCompleteDelegate(OnJoinSessionCompleteDelegate);

	if (Result == EOnJoinSessionCompleteResult::Success)
	{
		FString URL;
		if (SessionInt->GetResolvedConnectString(SessionName, URL))
		{
			APlayerController* PC = GetPlayerController();
			if (PC)
			{
				if (bIsFromInvite)
				{
					URL += TEXT("?bIsFromInvite");
					bIsFromInvite = false;
				}
				PC->ClientTravel(URL, TRAVEL_Absolute);
			}
		}
		else
		{
			UE_LOG(LogOnline, Warning, TEXT("Failed to join session %s"), *SessionName.ToString());
		}
	}
}
void UNetGameInstance::OnCompleted(FName SessionName, EOnJoinSessionCompleteResult::Type Result)
{
	
	
	APlayerController* PC = GetWorld()->GetFirstPlayerController();
	
	FFrame::KismetExecutionMessage(TEXT("Yeeee Join succesful"), ELogVerbosity::Warning);

	
	auto Sessions = Online::GetSessionInterface();
	if (Sessions.IsValid())
	{
		Sessions->ClearOnJoinSessionCompleteDelegate(Delegate);

		if (Result == EOnJoinSessionCompleteResult::Success)
		{
			// Client travel to the server
			FString ConnectString;
			if (Sessions->GetResolvedConnectString(GameSessionName, ConnectString) && PC->IsValidLowLevel())
			{
				//UE_LOG(Network, Log, TEXT("Join session: traveling to %s"), *ConnectString);
					
				PC->ClientTravel(ConnectString, TRAVEL_Absolute);
					
				return;
			}
		}
	}
	

	
}
APlayerController* AGameModeBase::ProcessClientTravel(FString& FURL, FGuid NextMapGuid, bool bSeamless, bool bAbsolute)
{
	// We call PreClientTravel directly on any local PlayerPawns (ie listen server)
	APlayerController* LocalPlayerController = nullptr;
	for (FConstPlayerControllerIterator Iterator = GetWorld()->GetPlayerControllerIterator(); Iterator; ++Iterator)
	{
		APlayerController* PlayerController = *Iterator;
		if (Cast<UNetConnection>(PlayerController->Player) != nullptr)
		{
			// Remote player
			PlayerController->ClientTravel(FURL, TRAVEL_Relative, bSeamless, NextMapGuid);
		}
		else
		{
			// Local player
			LocalPlayerController = PlayerController;
			PlayerController->PreClientTravel(FURL, bAbsolute ? TRAVEL_Absolute : TRAVEL_Relative, bSeamless);
		}
	}

	return LocalPlayerController;
}