End Sessions and Manage State
Properly ending player sessions and cleaning up multi user state is important for security and memory management, especially in games where players can log out, switch profiles, or leave the device.
How it Works
When a player logs out or you want to remove their session, you should end their session and remove their state from the SDK.
When the player leaves, but does not log out, you should set them to inactive but keep the cached session data. That way the player can pick the session up at a later time (until the token expires).
How to Sign Your Player Out
In situations when the player actively signs out/removes their profile from the device you need to end the LootLocker session and clear the cached state for that player. This will mean that they have to authenticate again if they decide to play again on the same device.
// The ulid that you want to end the session for
// In a multi user context it is vital to make sure that you're ending
// the session for the correct player.
string playerUlid = "player_ulid_here";
// Remember to provide the shouldClearLocalState parameter as true
// to clear the local state of the player.
bool bShouldClearLocalState = true;
LootLockerSDKManager.EndSession(endSessionResponse =>
{
if (endSessionResponse.success)
{
Log("Session ended successfully");
}
else
{
// Handle errors
Log("Failed to end session, local state not cleared: " + endSessionResponse.errorData);
}
}, bShouldClearLocalState, playerUlid);
How to Manually Clear Player State
In some situations you may want to manually and explicitly clear the local session. This can be for example when the session has expired with LootLocker, the user has finished moving an identity provider from one player to another, or simply because you want to clean up local data.
Note that as opposed to the End Session Example this makes no calls to the LootLocker systems. It simply removes all information stored locally about the player(s).
For a Specific Player
// The ulid that you want to clear data for
string playerUlid = "player_ulid_here";
LootLockerSDKManager.ClearCacheForPlayer(playerUlid);
For Everyone
Use this if you want a clean slate on the device. Use this during development to make sure you have a clean slate, or when resetting game settings etc.
LootLockerSDKManager.ClearAllPlayerCaches();
For Everyone Except a Specific Player
Use this for example when account linking has finished and the new session token should be the only active one on the device. Or when say a local hot seat session finishes and all visitor users should be removed from the device.
// The ulid that you want to keep data for
string playerUlid = "player_ulid_here";
LootLockerSDKManager.ClearAllPlayerCachesExceptForPlayer(playerUlid);
How to Manage Active vs Inactive Players
In situations where a player stops playing for now you will likely want to set them to inactive in the LootLocker SDK. This means that the session will not be used for requests unless specifically requested.
Note that this makes no calls to the LootLocker backend, and is a non destructive action. No data is lost or altered. It only designates if the specified player is considered active or not.
For a Specific Player
// The ulid of the player that you want to set to inactive
string playerUlid = "player_ulid_here";
LootLockerSDKManager.SetPlayerUlidToInactive(playerUlid);
For Everyone
LootLockerSDKManager.SetAllPlayersToInactive();
For Everyone Except a Specific Player
// The ulid that you want to keep active
string playerUlid = "player_ulid_here";
LootLockerSDKManager.SetAllPlayersToInactiveExceptForPlayer(playerUlid);
Last updated