Update on this issue. I can successfully have more than 2 players if we coordinate and click join at the same time. But if one player waits to join, then they can’t join anymore.
edit:
The host and first player can always join the game. But any players after that cannot join unless we coordinate and click join at the same time, then all players can join fine.
When I refresh my server list after a first player joins, the server is no longer found, even though my SessionSettings.NumPublicConnections is always > 2.
When 2 or more joining players can see the game on the server list and the first one joins, then (without refreshing) the 2nd player tries to join shortly afterwards, the Address returned by SessionInterface->GetResolvedConnectString(SessionName, Address) returns an empty string, which results in a failed attempt to join a game. When I use the Null Online Subsystem over LAN, things are working as expected. Does anyone have any ideas what I could be doing wrong?
edit 2:
void UBoiGameInstance::Host(FGameSettings Settings)
{
GameSettings = Settings;
GameSettings.bInitialized = true;
if (GameSettings.MaxPlayerCount < 1)
{
UE_LOG(LogTemp, Warning, TEXT("Invalid Player Count"));
return;
}
if (!SessionInterface.IsValid())
{
UE_LOG(LogTemp, Warning, TEXT("Invalid Session Interface"));
return;
}
FNamedOnlineSession* ExistingSession = SessionInterface->GetNamedSession(NAME_GameSession);
if (ExistingSession)
{
SessionInterface->DestroySession(NAME_GameSession);
}
else
{
CreateSession();
}
}
void UBoiGameInstance::CreateSession()
{
if (!SessionInterface.IsValid()) { return; }
FOnlineSessionSettings SessionSettings;
SessionSettings.NumPublicConnections = GameSettings.MaxPlayerCount;
SessionSettings.bShouldAdvertise = true;
SessionSettings.bAllowJoinInProgress = true;
SessionSettings.bIsDedicated = false;
SessionSettings.bIsLANMatch = (IOnlineSubsystem::Get()->GetSubsystemName() == "NULL");
SessionSettings.bUsesPresence = true;
SessionSettings.bAllowJoinViaPresence = true;
SessionSettings.Set(SERVER_NAME_SETTINGS_KEY, GameSettings.ServerName, EOnlineDataAdvertisementType::ViaOnlineServiceAndPing);
SessionInterface->CreateSession(0, NAME_GameSession, SessionSettings);
}
void UBoiGameInstance::OnCreateSessionComplete(FName SessionName, bool Success)
{
if (!Success)
{
UE_LOG(LogTemp, Warning, TEXT("Could not create session"));
return;
}
if (GEngine) { GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Green, TEXT("Hosting")); }
GetWorld()->ServerTravel("/Game/FPSBois/Maps/Lobby?listen");
}