Hi, I’m just trying to connect the server and the client via steam online subsystem. the problem is the client can not find any sessions and won’t join to the serve of course. The game works on Lan connection but not on steam. Here is the code
void URevolgyGameInstance::Init()
{
Super::Init();
IOnlineSubsystem* Subsystem = IOnlineSubsystem::Get();
if(Subsystem)
{
// subsystem has the session interface
SessionInterface = Subsystem->GetSessionInterface();
if (SessionInterface.IsValid())
{
// if the session interface is valid, subscribe (create and join to the server delegates to it)
SessionInterface->OnCreateSessionCompleteDelegates.AddUObject(this, &URevolgyGameInstance::OnCreateSessionComplete);
SessionInterface->OnFindSessionsCompleteDelegates.AddUObject(this, &URevolgyGameInstance::OnFindSessionsComplete);
SessionInterface->OnJoinSessionCompleteDelegates.AddUObject(this, &URevolgyGameInstance::OnJoinSessionComplete);
}
}
}
void URevolgyGameInstance::CreateServer()
{
// create session settings
UE_LOG(LogTemp, Warning, TEXT("CreateServer"))
FOnlineSessionSettings SessionSettings;
SessionSettings.bAllowJoinInProgress = true;
SessionSettings.bIsDedicated = false;
SessionSettings.bIsLANMatch = (IOnlineSubsystem::Get()->GetSubsystemName() == "NULL");
SessionSettings.bShouldAdvertise = true;
SessionSettings.bUsesPresence = true;
SessionSettings.NumPublicConnections = 5;
// use session interface to create session
// tries to create a server with these settings
SessionInterface->CreateSession(0, FName("Revolgy Test Session"), SessionSettings);
}
void URevolgyGameInstance::JoinServer()
{
SessionSearch = MakeShareable(new FOnlineSessionSearch());
if (!SessionSearch.IsValid())
{
UE_LOG(LogTemp, Error, TEXT("Session Search smart pointer is nullptr"))
PrintString("Session Search smart pointer is nullptr", FColor::Green);
return;
}
SessionSearch->bIsLanQuery = (IOnlineSubsystem::Get()->GetSubsystemName() == "NULL");
SessionSearch->MaxSearchResults = 10000;
SessionSearch->QuerySettings.Set("SEARCH_PRESENCE", true, EOnlineComparisonOp::Equals);
// tries to find all the available sessions and store it in an array in SessionSearch
SessionInterface->FindSessions(0, SessionSearch.ToSharedRef());
}
void URevolgyGameInstance::OnCreateSessionComplete(FName SessionName, bool bWasSuccessful)
{
// if creation of server was successful, travel the server player to the map
if (bWasSuccessful)
{
UE_LOG(LogTemp, Warning, TEXT("OnCreateSessionCompleted::Session is created successfully"))
PrintString("OnCreateSessionCompleted::Session is created successfully", FColor::Green);
GetWorld()->ServerTravel("/Game/ThirdPerson/Maps/ThirdPersonMap?listen");
}
}
void URevolgyGameInstance::OnFindSessionsComplete(bool bWasSuccessful)
{
if (bWasSuccessful)
{
UE_LOG(LogTemp, Warning, TEXT("OnFindSessionsComplete::Session search completed without any problems"))
PrintString("OnFindSessionsComplete::Session search completed without any problems", FColor::Green);
TArray<FOnlineSessionSearchResult> SearchResults = SessionSearch->SearchResults;
// if found any sessions
if (SearchResults.Num() > 0)
{
UE_LOG(LogTemp, Warning, TEXT("Number of sessions found :: %d"), SearchResults.Num())
PrintString(FString::Printf(TEXT("Number of sessions found :: %d"), SearchResults.Num()), FColor::Red);
//PrintString(FString::Printf("Name of sessions found :: %s", SearchResults[0]), FColor::Red);
SessionInterface->JoinSession(0, FName("Revolgy Test Session"), SearchResults[0]);
}
}
}
void URevolgyGameInstance::OnJoinSessionComplete(FName SessionName, EOnJoinSessionCompleteResult::Type JoinResult)
{
// send the client to the approprieta map
APlayerController* PC = UGameplayStatics::GetPlayerController(GetWorld(), 0);
if (PC)
{
UE_LOG(LogTemp, Warning, TEXT("PC Found!"))
FString outJoinAdress = "";
SessionInterface->GetResolvedConnectString(SessionName, outJoinAdress);
if (!outJoinAdress.IsEmpty())
{
PC->ClientTravel(outJoinAdress, ETravelType::TRAVEL_Absolute);
}
}
}
and my .ini file settings for steam:
[/Script/Engine.GameEngine]
+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver")
[OnlineSubsystem]
DefaultPlatformService=Steam
[OnlineSubsystemSteam]
bEnabled=true
SteamAppId=480
SteamDevAppId=480
GameServerQueryPort=27015
; If using Sessions
bInitServerOnClient=true
[/Script/OnlineSubsystemSteam.SteamNetDriver]
NetConnectionClassName="OnlineSubsystemSteam.SteamNetConnection"
what can be the problem?