I’m learning how to search for lobbies in EOS using these lessons
I have an error
// Fill out your copyright notice in the Description page of Project Settings.
#include "EOS_GameInstance.h"
#include "OnlineSubsystem.h"
#include "Interfaces/OnlineIdentityInterface.h"
#include "Interfaces/OnlineSessionInterface.h"
#include "OnlineSessionSettings.h"
#include "Kismet/GameplayStatics.h"
void UEOS_GameInstance::Login()
{
if (IdentityPtr)
{
FOnlineAccountCredentials OnlineAccountCredentials;
OnlineAccountCredentials.Type = "accountportal";
OnlineAccountCredentials.Id = "";
OnlineAccountCredentials.Token = "";
IdentityPtr->Login(0, OnlineAccountCredentials);
}
}
void UEOS_GameInstance::CreateSession()
{
if (SessionPtr)
{
FOnlineSessionSettings SessionSettings;
SessionSettings.bAllowInvites = true;
SessionSettings.bIsDedicated = false;
SessionSettings.bIsLANMatch = false;
SessionSettings.bShouldAdvertise = true;
SessionSettings.bUseLobbiesIfAvailable = true;
SessionSettings.bUsesPresence = true;
SessionSettings.bAllowJoinInProgress = true;
SessionSettings.bAllowJoinViaPresence = true;
SessionSettings.NumPublicConnections = 10;
SessionSettings.Set(FName("LobbyName"), FString("MyFunLobby"), EOnlineDataAdvertisementType::ViaOnlineServiceAndPing);
SessionPtr->CreateSession(0, "FunSession", SessionSettings);
}
}
void UEOS_GameInstance::FindSession()
{
if (SessionPtr)
{
SessionSearch = MakeShareable(new FOnlineSessionSearch);
SessionSearch->bIsLanQuery = false;
SessionSearch->MaxSearchResults = 100;
SessionSearch->QuerySettings.Set(SEARCH_LOBBIES,true, EOnlineComparisonOp::Equals);
SessionPtr->FindSessions(0, SessionSearch.ToSharedRef());
}
}
void UEOS_GameInstance::Init()
{
Super::Init();
OnlineSubsystem = IOnlineSubsystem::Get();
IdentityPtr = OnlineSubsystem->GetIdentityInterface();
IdentityPtr->OnLoginCompleteDelegates->AddUObject(this, &UEOS_GameInstance::LoginCompleted);
SessionPtr = OnlineSubsystem->GetSessionInterface();
SessionPtr->OnCreateSessionCompleteDelegates.AddUObject(this, &UEOS_GameInstance::CreateSessionCompleted);
SessionPtr->OnFindSessionsCompleteDelegates.AddUObject(this, &UEOS_GameInstance::FindSessionCompleted);
}
void UEOS_GameInstance::LoginCompleted(int numOfPlayers, bool bWasSuccessful, const FUniqueNetId& UserId, const FString& Error)
{
if (bWasSuccessful)
{
UE_LOG(LogTemp, Warning, TEXT("Login on"))
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Login failed: %s"),* Error)
}
}
void UEOS_GameInstance::CreateSessionCompleted(FName Name, bool bWasSuccessful)
{
if (bWasSuccessful)
{
UE_LOG(LogTemp, Warning, TEXT("Session created"))
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Session create failure"))
}
if (!Gamelvl.IsValid())
{
Gamelvl.LoadSynchronous();
}
if (Gamelvl.IsValid())
{
const FName LevelName = FName(*FPackageName::ObjectPathToPackageName(Gamelvl.ToString()));
GetWorld()->ServerTravel(LevelName.ToString() + "?Listen");
}
}
void UEOS_GameInstance::FindSessionCompleted(bool bWasSuccessful)
{
if (bWasSuccessful)
{
for (const FOnlineSessionSearchResult& LobbyFound : SessionSearch->SearchResults)
{
UE_LOG(LogTemp, Warning, TEXT("Session found: %"),*LobbyFound.GetSessionIdStr());
}
}
}