Account Plugin #
The Account Plugin can be used to add custom behavior during the account lifecycle. The following are methods to manage account data:
Method | Description |
---|---|
onAccountCreate | Called before an account has been created. |
onAccountCreated | Called after account creation. |
onAccountLogin | Called after an account has signed in. |
onAccountUpdate | Called when account information has changed. |
onAccountDelete | Called before an account is deleted. |
onAccountDeleted | Called after account deletion. |
Flow Overview #
In this section we’ll demonstrate the Account Plugin’s flow by going through an example use case. Consider a scenario where a player creates an account for an early development game.
onAccountCreate
: Creates an account following specified requirements.
onAccountCreated
: Triggers after an account has been successfully created.
onAccountLogin
: Allows or prevents players to log in based on restrictions.
onAccountUpdate
: Makes updates to player account information following specified requirements.
onAccountDelete
: Pragma Engine removes all standard player information. You’ll need to remove any additional stored custom player data.
onAccountDeleted
: Triggers after an account has been successfully deleted.
Create an account #
The onAccountCreate
function is called after account authentication, but before creation of a Pragma Social account. When onAccountCreate
returns a PragmaAccount
object, an account is created. Account creation can be prevented by throwing an exception.
The IdProviderAccount
data class is unique account information from an identity provider:
Property | Type | Description |
---|---|---|
idProvider | AccountRPC.IdProvider | The type of the identity provider (Steam, Epic, unsafe). See Identity Providers for more information. |
accountId | String | User ID from the identity provider. |
displayName | String | The player’s registered account name from the identity provider. |
discriminator | String | Unique digits added to the end of usernames to identify the player’s account. |
Pragma Account Object #
The PragmaAccount
is a mutable object that represents the current state of the player’s account information. Any changes made on the PragmaAccount
object are saved.
All get
requests are lazy loaded.
Method | Description |
---|---|
getSocialIdentity | Retrieve all account information. This includes data on account ID, display name, list of game identities, and identity providers. |
getDisplayName | Retrieve the player’s registered account name. |
getTags | Retrieve all player tags associated with the player’s account. |
getGroups | Retrieve all player groups associated with the player’s account. |
setDisplayName | Set a new display name for the player’s Pragma account. |
addTag | Add a tag to the player’s account. |
addGroup | Adds a player to a group by the group’s unique ID. |
removeTag | Remove a tag from the player’s account by the tag’s unique ID. |
removeGroup | Remove a player from a group by the group’s unique ID. |
Implement the Account Plugin #
To build your custom Account Plugin, you’ll need to implement the AccountPlugin
interface:
class DemoAccountPlugin(
val service: Service,
val contentDataNodeService: ContentDataNodeService
) : AccountPlugin {}
Configure the Account Plugin #
To enable your custom Account Plugin, you’ll need to add this config in your yaml
:
social:
pluginConfigs:
AccountService.accountPlugin:
class: "demo.account.DemoAccountPlugin"