Authenticating Users
Last updated
Last updated
Before we can do any sort of matchmaking, we need to login with the Online Subsystem first. Kronos features an automated user authentication process, so we do not need to do anything. Authentication is entirely handled by the KronosUserManager
class.
By default authentication will start automatically when the "Game Default Map" - set in your Project Settings - is opened.
You can override which map is considered as the game default map from the plugin's settings. This is useful if you want to have a dedicated "login" map.
The user will be authenticated every time when loading the game default map, even if authentication was completed before. We do this to confirm that the user didn't lose his login status while he was away (e.g. playing in a match).
During authentication the user will be logged in with the Online Subsystem. Different Online Subsystems require different inputs when logging in.
The Null Online Subsystem requires a login id. By default the plugin will use the local users' id so you do not have to do anything. Works out of the box.
To change the default login parameters, create a new blueprint from the KronosUserManager
class and override the GetLoginCredentials
function.
Now go to Project Settings -> Kronos Matchmaking and set the "User Manager Class" to your custom blueprint that you just created.
While authentication is in progress, a widget will be displayed showing the current auth state. During this time the user should be unable to interact with the game.
In case user authentication fails, the authentication widget will switch over to a failure screen displaying the error message to the user. From there the user can either retry authentication or quit the game.
Please refer to the Customizing The Auth Widget documentation page for more information about auth widget customization.
When authentication is complete, the OnEnterGame
event of the KronosOnlineSession
will be called. Think about this as passing the "login screen" of the game. You can display the main menu widget from here, add popups to the screen, or travel to a new map if needed.
You may want to have your authentication set up in a way that initially when the game loads, the user would have to press a key to enter the game. This is the "Press any key to continue" screen you've probably seen in a lot of games.
You can disable automatic user authentication in the plugin's settings. When disabled, the game has to call the AuthenticateUser
function of the KronosUserManager
manually.
The KronosOnlineSession
class has a convenient OnGameDefaultMapLoaded
event which you can use to handle user authentication. When the event is called, check if the user is currently authenticated and decide what to do. If the user is already authenticated, then he is returning from a match so you should authenticate to confirm his login status. If the user is not authenticated, then its the users first time loading the game which means you can wait for an input.
In case you want to allow a third party program or plugin to handle authentication instead of Kronos, go to Project Settings -> Kronos Matchmaking and enable "Authentication Is Passthrough". If this option is enabled, the user will not be logged in with the Online Subsystem during user authentication.
The plugin internally tracks whether the user was authenticated or not. This means that even if authentication is not handled by Kronos you will still have to call AuthenticateUser
to ensure that everything work correctly.