Updating Display Name with Social Player Portal #
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 in the Social Player Portal. We’ll also go through how to add time throttling to limit how often a player can update their display name.
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 in the Social Player Portal.
Steps
- Create a new directory at
5-ext/ext/src/main/kotlin/ext/accounttutorial
. - Create a new Kotlin file in that directory called
AccountTutorialManualUpdateAccountPlugin.kt
. - Copy the following code into the
AccountTutorialManualUpdateAccountPlugin.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.PragmaAccount
import pragma.account.TimeSpanner
import pragma.auth.IdProviderAccount
import pragma.config.ConfigBackendModeFactory
import pragma.config.PluginConfig
import pragma.content.ContentDataNodeService
import pragma.plugins.ConfigurablePlugin
import pragma.services.Service
import pragma.settings.BackendType
@Suppress("unused")
class AccountTutorialManualUpdateAccountPlugin(
override val service: Service,
override val contentDataNodeService: ContentDataNodeService,
) : ConfigurablePlugin<AccountTutorialAccountPlugin.Config>, AccountPlugin {
class Config private constructor(type: BackendType) : PluginConfig<Config>(type) {
override val description = "Account plugin configuration."
var waitingPeriodInDays by types.long("The number of days between name changes.")
companion object : ConfigBackendModeFactory<Config> {
override fun getFor(type: BackendType): Config {
return Config(type).apply {
waitingPeriodInDays = 30L
}
}
}
}
private lateinit var config: Config
private val timeSpanner: TimeSpanner = TimeSpanner()
override suspend fun onAccountCreate(idProviderAccount: IdProviderAccount): PragmaAccount {
return PragmaAccount(idProviderAccount.displayName)
}
override suspend fun onAccountCreated(pragmaAccount: PragmaAccount) { }
override suspend fun onAccountLogin(pragmaAccount: PragmaAccount) { }
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) {
if (!timeSpanner.enoughTimeHasElapsedSince(pragmaAccount.getDisplayNameLastUpdated())) {
throw PragmaException(
PragmaError.AccountService_BadRequest,
"Players are only allowed to update display name every ${config.waitingPeriodInDays} days"
)
}
pragmaAccount.setDisplayName(requestedDisplayName)
}
override suspend fun onConfigChanged(config: Config) {
this.config = config
timeSpanner.setWaitingPeriodDays(this.config.waitingPeriodInDays)
}
}
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. Here we will configure the plugin to run in your local Pragma Engine
- Open
5-ext/config/local-dev.yml
. - Register the
AccountTutorialManualUpdateAccountPlugin
by ensuring the social section of the config file matches the following:
social:
pluginConfigs:
AccountService.accountPlugin:
class: "ext.accounttutorial.AccountTutorialManualUpdateAccountPlugin"
Optional config #
The Account Plugin contains a configurable config waitingPeriodInDays
that defaults to 30 days. This value can be overridden by setting the value in the config:
social:
pluginConfigs:
AccountService.accountPlugin:
class: "ext.accounttutorial.AccountTutorialManualUpdateAccountPlugin"
config:
waitingPeriodInDays: 10
3. Enable the Social Player Portal overlay #
Goal
Enable the overlay so that players can update their Pragma Account display name in the Social Player Portal.
Steps
Enable the Social Player Portal overlay to allow users to update their display name.
- Open
5-ext/portal/src/config/default.js
. - Under
player-social
addaccountTutorialPlayerExtension
.
module.exports = {
builds: {
'player-social': {
common: { 'app.extensions': ['accountTutorialPlayerExtension.js'] }
},
}
}
- In
5-ext/portal/src/extensions/
create a new file calledaccountTutorialPlayerExtension.js
. - Add the following code:
const { DisplayNameEdit } = pragma.ext.player.ui.components
export default {
swappableComponents: {
"Player.Account.Settings.DisplayName": DisplayNameEdit
},
};
4. Package Social Player Portal #
Goal
Update the Social Player Portal for players to see the update display name input box.
Steps
To package the Social Player Portal run the following command: make portal-package PROJECT=5-ext
Test the plugin #
In this section we’ll test if your Pragma Account display name updates when updated from the Social Player Portal.
Start Pragma Engine #
Run Pragma Engine via one of the following methods.
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: