Updating Display Name with Steam #
This tutorial uses Pragma Engine 0.4.0.
In this section, we’ll create a custom Account Plugin that updates a player’s Pragma Account display name when a player updates their display name on Steam.
Prerequisites: You’ll need to have authenticated with Steam. See tutorials Unreal: Authenticate with Steam or Unity: Authenticate with Steam for details.
Get started #
Run the following command in the terminal from the platform directory to build the engine: ./pragma build all --skipTests
1. Create a custom Account Plugin #
Goal
Create a custom Account Plugin with logic to update a player’s Pragma Account display name when they update their name on Steam.
Steps
- Create a new directory at
5-ext/ext/src/main/kotlin/ext/accounttutorial
. - Create a new Kotlin file in that directory called
AccountTutorialSteamAccountPlugin.kt
. - Copy the following code into the
AccountTutorialSteamAccountPlugin.kt
file. This defines a class that implements the Account Plugin interface:
package ext.accounttutorial
import pragma.PragmaError
import pragma.PragmaException
import pragma.account.AccountPlugin
import pragma.account.AccountRpc
import pragma.account.PragmaAccount
import pragma.auth.IdProviderAccount
import pragma.content.ContentDataNodeService
import pragma.services.Service
@Suppress("unused")
class AccountTutorialSteamAccountPlugin(
val service: Service,
val contentDataNodeService: ContentDataNodeService,
) : AccountPlugin {
override suspend fun onAccountCreate(idProviderAccount: IdProviderAccount): PragmaAccount {
return PragmaAccount(idProviderAccount.displayName)
}
override suspend fun onAccountCreated(pragmaAccount: PragmaAccount) { }
override suspend fun onAccountLogin(pragmaAccount: PragmaAccount) {
val steamIdProvider =
pragmaAccount.getSocialIdentity()?.providerAccounts?.find {
it.idProvider == AccountRpc.IdProvider.STEAM_VALUE
}
if (steamIdProvider != null && steamIdProvider.displayName !=
pragmaAccount.getDisplayName()) {
pragmaAccount.setDisplayName(steamIdProvider.displayName)
}
}
override suspend fun onAccountUpdate(pragmaAccount: PragmaAccount) { }
override suspend fun onAccountDelete(pragmaAccount: PragmaAccount) { }
override suspend fun onAccountDeleted(pragmaAccount: PragmaAccount) { }
override suspend fun updateDisplayName(requestedDisplayName: String, pragmaAccount: PragmaAccount) {
/**
* We are disabling the ability for players to manually update their display name
*/
throw PragmaException(
PragmaError.AccountService_DisplayNameUpdateNotAllowed,
"Display name updating is not allowed"
)
}
}
After saving the new file, run the following command in the terminal from the platform directory to build the platform: ./pragma build --skipTests
2. Configure the plugin #
Goal
Register your custom Account Plugin in Pragma Engine.
Steps
Plugins must be configured in YAML configuration files before they can be utilized by Pragma Engine. We’ll configure the plugin to run in your local Pragma Engine.
- Open
5-ext/config/local-dev.yml
. - Register the
AccountTutorialSteamAccountPlugin
by ensuring the social section of the config file matches the following:
social:
pluginConfigs:
AccountService.accountPlugin:
class: "ext.accounttutorial.AccountTutorialSteamAccountPlugin"
Test the plugin #
In this section we’ll test if your Account Plugin updates your Pragma Account display name when you change your name on Steam.
Start Pragma Engine #
Run Pragma Engine via one of the following methods.
Once the engine has started successfully, it prints the message INFO main - Pragma server startup complete
.
Update your display name #
You’ll need to have completed either the Unreal: Authenticate with Steam or Unity: Authenticate with Steam tutorial.
The following are two options for testing: