i am trying to run a LAN multiplayer testing session but it wont join session i am using two versions of same game on one PC running standalone is this wrong
void UGameInstance::Init()
{
if (IOnlineSubsystem* SubSystem = IOnlineSubsystem::Get())
{
SessionInterface = SubSystem->GetSessionInterface();
if (SessionInterface.IsValid())
{
//bind delegates
SessionInterface->OnCreateSessionCompleteDelegates.AddUObject(this, &UGameInstance::OnCreateSessionComplete);
SessionInterface->OnFindSessionsCompleteDelegates.AddUObject(this, &UGameInstance::OnFindSessionComplete);
SessionInterface->OnJoinSessionCompleteDelegates.AddUObject(this, &UGameInstance::OnJoinSessionComplete);
}
}
}
void UGameInstance::OnCreateSessionComplete(FName ServerName, bool Succeeded)
{
UE_LOG(LogTemp, Warning, TEXT("OnCreateSessionComplete, Succeeded: %d"), Succeeded);
if (Succeeded)
{
GetWorld()->ServerTravel("/Game/FirstPersonCPP/Maps/FirstPersonExampleMap?listen");
}
}
void UGameInstance::OnFindSessionComplete(bool Succeeded)
{
UE_LOG(LogTemp, Warning, TEXT("OnFindSessionComplete, Succeeded: %d"), Succeeded);
if (Succeeded)
{
TArray<FOnlineSessionSearchResult> SearchResults = SessionSearch->SearchResults;
UE_LOG(LogTemp, Warning, TEXT("SearchResults, Server Count: %d"), SearchResults.Num());
if (SearchResults.Num())
{
UE_LOG(LogTemp, Warning, TEXT("Joining Server"));
SessionInterface->JoinSession(0, "My Session", SearchResults[0]);
}
}
}
void UGameInstance::OnJoinSessionComplete(FName SessionName,
EOnJoinSessionCompleteResult::Type Result)
{
UE_LOG(LogTemp, Warning, TEXT("OnJoinSessionComplete"));
if (APlayerController* PController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
{
FString JoinAdress = "";
SessionInterface->GetResolvedConnectString(SessionName, JoinAdress);
if (JoinAdress != "")
PController->ClientTravel(JoinAdress, ETravelType::TRAVEL_Absolute);
}
}
void UGameInstance::CreateServer()
{
UE_LOG(LogTemp, Warning, TEXT("CreateServer"));
FOnlineSessionSettings SessionSettings;
SessionSettings.bAllowJoinInProgress = true;
SessionSettings.bIsDedicated = false;
SessionSettings.bIsLANMatch = true;
SessionSettings.bShouldAdvertise = true;
SessionSettings.NumPrivateConnections = 5;
SessionSettings.NumPublicConnections = 5;
SessionInterface->CreateSession(0, FName("My Session"), SessionSettings);
}
void UGameInstance::JoinServer()
{
UE_LOG(LogTemp, Warning, TEXT("JoinServer"));
SessionSearch = MakeShareable(new FOnlineSessionSearch());
SessionSearch->bIsLanQuery = true;
SessionSearch->MaxSearchResults = 10000;
SessionSearch->QuerySettings.Set(SEARCH_PRESENCE, true, EOnlineComparisonOp::Equals);
SessionInterface->FindSessions(0, SessionSearch.ToSharedRef());
}