Unreal Engine Module - Login with Steam - Use the Online Subsystem to log in with Steam
Unwrap The Subsystem
In the Module: Login with Device ID, you have set up a subsystem in the AuthEssentialsSubsystem_Starter
class for login with device ID. Since login with Steam has similar logic, you will reuse that subsystem. Let's recall some of the subsystem's functionalities.
If you open the
AuthEssentialsSubsystem_Starter
class CPP file located in/Source/AccelByteWars/TutorialModules/Access/AuthEssentials/AuthEssentialsSubsystem_Starter.cpp
, you will find the followingSetAuthCredentials()
function. You use this function to set up login credentials, including the login method, id/username, and token/password.void UAuthEssentialsSubsystem_Starter::SetAuthCredentials(const EAccelByteLoginType& LoginMethod, const FString& Id, const FString& Token)
{
Credentials.Type = (LoginMethod == EAccelByteLoginType::None) ? TEXT("") : FAccelByteUtilities::GetUEnumValueAsString(LoginMethod);
Credentials.Id = Id;
Credentials.Token = Token;
}After you set up the credentials, you can call the
Login()
function to start the login process. The credentials supplied through the aboveSetAuthCredentials()
method will be passed to the underlying login call made to the AccelByteOnlineSubsystem
.void UAuthEssentialsSubsystem_Starter::Login(const APlayerController* PC, const FAuthOnLoginCompleteDelegate& OnLoginComplete)
{
if (!ensure(IdentityInterface.IsValid()))
{
FString Message = TEXT("Cannot login. Identiy interface is not valid.");
UE_LOG_AUTH_ESSENTIALS(Warning, TEXT("%s"), *Message);
OnLoginComplete.ExecuteIfBound(false, *Message);
return;
}
// Get local user number
const ULocalPlayer* LocalPlayer = PC->GetLocalPlayer();
ensure(LocalPlayer != nullptr);
int32 LocalUserNum = LocalPlayer->GetControllerId();
// Perform login using IdentityInterface
IdentityInterface->AddOnLoginCompleteDelegate_Handle(LocalUserNum, FOnLoginCompleteDelegate::CreateUObject(this, &ThisClass::OnLoginComplete, OnLoginComplete));
IdentityInterface->Login(LocalUserNum, Credentials);
// Helper to logout the user when the game shutdown in PIE mode.
if (UAccelByteWarsGameInstance* ByteWarsGameInstance = Cast<UAccelByteWarsGameInstance>(GetGameInstance()); ensure(ByteWarsGameInstance))
{
ByteWarsGameInstance->OnGameInstanceShutdownDelegate.AddWeakLambda(this, [this, LocalUserNum]()
{
IdentityInterface->Logout(LocalUserNum);
UE_LOG_AUTH_ESSENTIALS(Warning, TEXT("Logging out local player %d"), LocalUserNum);
});
}
}In the Module: Login with Device ID, the above functions were utilized to implement login using device ID. Those same two functions will be used to log in with Steam in the next section.
Now, you can move to the next tutorial section to connect the UI you prepared earlier with the
AuthEssentialsSubsystem_Starter
subsystem.
Resources
- The files used in this tutorial section are available in the Byte Wars GitHub repository.