Up to this point, I’ve been using the Steam OSS with my dedicated server without issue. I’d simply get the ID of the server using Steam’s server browser, and use open Steam.[ID]
in the console of the client to connect to the server. I finally decided to implement some sort of basic matchmaking and to start I just want to connect to my server automatically. I start by creating a session on the server, then finding it on the client through a session search.
I create my session like this:
const IOnlineSessionPtr SessionInterface = Online::GetSessionInterface(GetWorld());
if (!SessionInterface.IsValid())
{
OnCreateSessionCompleteEvent.Broadcast(false);
return;
}
// settings passed in when createsession function is called.
LastSessionSettings = MakeShareable(new FOnlineSessionSettings());
LastSessionSettings->NumPrivateConnections = NumPrivateConnections; // 0
LastSessionSettings->NumPublicConnections = NumPublicConnections; // 16
LastSessionSettings->bAllowInvites = AllowInvites; // true
LastSessionSettings->bAllowJoinInProgress = AllowJoinInProgress; // true
LastSessionSettings->bAllowJoinViaPresence = AllowJoinViaPresence; // false
LastSessionSettings->bAllowJoinViaPresenceFriendsOnly = AllowJoinViaPresenceFriendsOnly; // false
LastSessionSettings->bIsDedicated = IsDedicatedServer; // true
LastSessionSettings->bUsesPresence = UsesPresence; // false
LastSessionSettings->bIsLANMatch = IsLANMatch; // false
LastSessionSettings->bShouldAdvertise = ShouldAdvertise; // true
LastSessionSettings->Set(SETTING_GAMEMODE, FString("DeathMatch"), EOnlineDataAdvertisementType::ViaOnlineService);
LastSessionSettings->Set(SETTING_MAPNAME, MapName, EOnlineDataAdvertisementType::ViaOnlineService);
LastSessionSettings->Set(SETTING_MATCHING_HOPPER, FString("Deathmatch"), EOnlineDataAdvertisementType::DontAdvertise);
LastSessionSettings->Set(SETTING_MATCHING_TIMEOUT, 120.f, EOnlineDataAdvertisementType::ViaOnlineService);
LastSessionSettings->Set(SETTING_SESSION_TEMPLATE_NAME, FString("GameSession"), EOnlineDataAdvertisementType::DontAdvertise);
CreateSessionCompleteDelegateHandle = SessionInterface->AddOnCreateSessionCompleteDelegate_Handle(CreateSessionCompleteDelegate);
if(!SessionInterface->CreateSession(0, NAME_GameSession, *LastSessionSettings))
{
UE_LOG(LogTemp, Warning, TEXT("Something went wrong while creating a session"));
SessionInterface->ClearOnCreateSessionCompleteDelegate_Handle(CreateSessionCompleteDelegateHandle);
OnCreateSessionCompleteEvent.Broadcast(false);
}
I search for my session like this:
const IOnlineSessionPtr SessionInterface = Online::GetSessionInterface(GetWorld());
if (!SessionInterface.IsValid())
{
OnFindSessionsCompleteEvent.Broadcast(TArray<FOnlineSessionSearchResult>(), false);
return;
}
UE_LOG(LogTemp, Warning, TEXT("Begin find sessions"));
FindSessionsCompleteDelegateHandle = SessionInterface->AddOnFindSessionsCompleteDelegate_Handle(FindSessionsCompleteDelegate);
// settings passed in when findsessions function is called.
LastSessionSearch = MakeShareable(new FOnlineSessionSearch());
LastSessionSearch->MaxSearchResults = MaxSearchResults; // 10000
LastSessionSearch->bIsLanQuery = IsLANQuery; // false
LastSessionSearch->QuerySettings.Set(SEARCH_DEDICATED_ONLY, true, EOnlineComparisonOp::Equals);
UE_LOG(LogTemp, Warning, TEXT("end session finding rules"));
const ULocalPlayer* localPlayer = GetWorld()->GetFirstLocalPlayerFromController();
if (!SessionInterface->FindSessions(*localPlayer->GetPreferredUniqueNetId(), LastSessionSearch.ToSharedRef()))
{
SessionInterface->ClearOnFindSessionsCompleteDelegate_Handle(FindSessionsCompleteDelegateHandle);
OnFindSessionsCompleteEvent.Broadcast(TArray<FOnlineSessionSearchResult>(), false);
}
I’m fairly certain that it’s working for the most part… At one point I accidentally had the client create the session, then also try to find and join one and it was indeed able to find and attempt to join itself (which failed because it was already in the session). When I search normally (with the server creating a session and the client searching for one), the client outputs the following logs:
LogOnlineSession: Warning: STEAM: Server response IP:[SomeoneElsesPublicIP]
LogOnlineSession: Warning: STEAM: Rules response [Rules from the other server that responded]
LogOnlineSession: Warning: STEAM: Failed to respond IP:[MyPublicIP]
Like I said before, I think the system is close to working, especially since I can join the server through the console, but I want to be able to search for it automatically. What am I doing wrong such that my server doesn’t properly respond like this other server that my client found? In my attempts to find an answer to this, the most I’ve seen is people suggesting that it’s probably a local firewall issue. I’ve gone as far as turning off the firewall on the windows pc that’s hosting the server to no avail. I’ve made sure to portforward both 7777 and 27015. I’m obviously missing something because others have been able to do this, but I just can’t figure it out and it’s been a pain in my backside for days now. Any help is greatly appreciated, thanks.