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.
Account creation #
When a player attempts to log in, authenticateOrCreate
is called. There are two possible scenarios after confirming the player’s identity with the third party provider:
- If the player does not have an existing account,
onAccountCreate
is called and the returned account information is stored in the accounts database. After successful account creation,onAccountCreated
is called. ThenonAccountLogin
is called. - If the player does have an existing Pragma Engine account, only
onAccountLogin
is called.
onAccountCreate
must return aPragmaAccount
object to write an account to the database. If this function throws an exception or nothing is returned, then an account will not be made.
Account login #
After a player has been authenticated, onAccountLogin
is called. The player’s account information is sent as a parameter.
Account update #
When there is a request to update a player’s account information, onAccountUpdate
is called. Here you can add custom logic to filter display names or reject certain display names.
Account deletion #
When an operator deletes an account, onAccountDelete
is called. Pragma Engine removes all standard account information. You’ll need to remove any additional account data you have stored. After successful account deletion, onAccountDeleted
is called.
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. |
Update a player’s display name #
The AccountRpc.UpdateDisplayNameV1Request
endpoint can be used for players to update their display name. The default Account Plugin prevents players from modifying their display name.
To enable players to edit their display name, do not throw the PragmaException
from your custom Account Plugin. We recommend adding custom logic to restrict when players can update their display name.
override suspend fun updateDisplayName(
requestedDisplayName: String,
pragmaAccount: PragmaAccount
) {
pragmaAccount.setDisplayName(requestedDisplayName)
throw PragmaException(
PragmaError.AccountService_DisplayNameUpdateNotAllowed,
"Display name updating is not allowed"
)
}
For more information on how players can edit their display name, see the Social Player Portal page.
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. |
Create a custom Account Plugin #
To build off existing Account Plugin features, you’ll need to do the following:
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"