Updating Display Name with Steam #

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 and make 5-ext if it doesn’t already exist: make skip-tests build

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

  1. Create a new directory at 5-ext/ext/src/main/kotlin/ext/accounttutorial.
  2. Create a new Kotlin file in that directory called AccountTutorialSteamAccountPlugin.kt.
  3. 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"
        )
    }
}
Method overview

The onAccountCreate method defines the logic that executes when a player’s account is first created. It always needs to return a Pragma Account representing the player’s new account that will be created. This is how you define the player’s initial account parameters like their display name. If you want to customize how the player’s account is created you can do that in this method.

The onAccountLogin method defines the logic that executes when a player logs in. This is where we will insert the logic needed to update a Pragma Account display name when a player has updated their name on Steam. The next time the player logs into the Player Social backend, Pragma checks for any Steam display name changes. If the Steam display name is different from the player’s current display name, the Pragma Account display name will be updated with their new Steam name accordingly. The Pragma Account display name is only updated with the Steam display name when the player logs into the Social Player Portal or your game client with their Steam account using the Steam identity provider.

The following onAccountCreated, onAccountUpdate, updateDisplayName, onAccountDelete, and onAccountDeleted methods are other account events that you could add additional logic to but for the purpose of our implementation they can be left empty. These methods need to be included to adhere to the Account Plugin interface even if they are not being used.

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.

  1. Open 5-ext/config/local-dev.yml.
  2. 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.

Running via Make
Run make run to start the platform. Run this in a terminal with platform as the working directory.
Running in IntelliJ

From the IntelliJ toolbar in the upper right, ensure MainKt - LocalConfigured is selected, then click the play button.

If MainKt - LocalConfigured isn’t available, you will need to configure it. In the IntelliJ toolbar, click the dropdown next to the run button, then click Edit Configurations…. In the Run/Debug Configurations window that appears, expand Kotlin in the left hand side, then select MainKt - LocalConfigured. Click OK. Click the play button in the IntelliJ toolbar to start Pragma Engine.

Once the engine has started successfully, it prints the message [main] INFO main - Pragma server startup complete.

Update your display name #

The following are two options for testing:

Option 1: Testing with Steam
  1. Log in with Steam.
  2. Change your Steam display name.
  3. Log into your game client with Steam.
    • Your Pragma Account display name should be updated to your new Steam display name.
Option 2: Testing with the Social Operator Portal
  1. Log in with Steam as a player in your game client.
  2. Go to the Social Operator Portal and login as the Operator account test01.
  3. Search for the account you used to log into Steam.
  4. Change your display name through the Social Operator Portal.
  5. Log in to the game client with Steam again.
  6. Confirm your Pragma Account display name has changed back to match the Steam display name.