Connect To Elympics
By default, ElympicsLobbyClient
authenticates you as a guest player (ClientSecret). If you want to use Web3 login, you should disable this option by setting authenticateOnAwakeWith
to AuthType.None
in ElympicsLobbyClient
's Inspector. Then be sure to use the ConnectToElympicsAsync
method.
The ElympicsLobbyClient.Instance.ConnectToElympicsAsync
method is used to establish a connection to the Elympics platform. This process involves authenticating the user and setting up the necessary environment for the game.
This method accepts an instance of ConnectionData
as its only argument.
Depending on which fields are filled in ConnectionData
, different outcomes can be expected:
- If the
AuthFromCacheData
field is not null, you will be logged in using provided cached authentication details and remaining fields will be ignored. It is also a way to provide external authentication, like when using PlayPad. - The
AuthType
field determines the type of authentication to be used.AuthType.ClientSecret
means the guest authentication. - The
Region
field specifies the location of the server you will connect to. Providing only theRegion
field and leaving other fields blank results in changing the region and reconnecting to the WebSocket using the same authentication data.
Important things to keep in mind when using ConnectToElympicsAsync
:
- The default region is
warsaw
. - This is an asynchronous method. After calling it, you should prevent the user from starting a match or fetching leaderboards until the connection is established.
- You should not call this method if the user is already authenticated, unless you have a specific reason (like choosing a closer region).
- It is recommended to use the
Start
method instead ofAwake
for connecting to Elympics systems to ensure that all components are fully initialized before attempting to authenticate.
Checking authentication and connection status
Elympics SDK separates the authentication status from the connection status. The connection status (ElympicsLobbyClient.Instance.WebSocketSession.IsConnected
) informs us about the connection to the WebSocket. The authentication status (ElympicsLobbyClient.Instance.IsAuthenticated
) provides information about the available AuthData
which is used not only to authenticate the player within the WebSocket-based communication, but also in HTTP requests to Elympics systems.
AuthData
The AuthData
structure stored in ElympicsLobbyClient.Instance.AuthData
provides information about the user's authentication status in Elympics. It contains the following properties:
UserId
- a unique identifier of the userJwtToken
- an authorization token associated with the user's sessionAuthType
- the type of authentication used currently by the user
Sign Out
If needed, you can sign out the user by calling the ElympicsLobbyClient.Instance.SignOut
method.
It is important to do so beforehand if you want to change the authentication method.