Add custom configuration to a Player Data Subservice #
This guide will cover how to customize a Player Data Subservice by enhancing it with custom configuration. In the example below we’ll add a feature flag that could possibly be controlling whether a Player Data operation in a Player Data Subservice is enabled or not.
Setup #
Start with a clean build of your project.
./pragma build -s
Declare a ServiceExtensionConfig #
This declaration will create the schema required for your custom configuration.
class CustomPlayerDataConfig private constructor(type: BackendType) :
ServiceExtensionConfig<CustomPlayerDataConfig>(type) {
override val description = "Custom configuration for a Player Data Subservice"
var operationToggle by types.boolean("Feature toggle to allow operation. Defaults to false. ")
companion object : ConfigBackendModeFactory<CustomPlayerDataConfig> {
override fun getFor(type: BackendType): CustomPlayerDataConfig {
return CustomPlayerDataConfig(type).apply {
operationToggle = false
}
}
}
}
Declare a Player Data Subservice #
Besides being a PlayerDataSubservice
, we’ll need to have our Player Data Subservice also be a ServiceExtensionConfigHandler
of the CustomPlayerDataConfig
type. Here’s an example:
class DemoPlayerDataSubservice(
contentLibrary: PlayerDataContentLibrary
): PlayerDataSubService(contentLibrary), ServiceExtensionConfigHandler<CustomPlayerDataConfig> {
lateinit var config: CustomPlayerDataConfig
override fun onConfigChanged(serviceExtensionConfig: CustomPlayerDataConfig) {
config = serviceExtensionConfig
}
@PlayerDataOperation(sessionTypes = [SessionType.PLAYER])
fun customPlayerDataOperation(request: CustomPlayerDataRequest, context: Context): CustomPlayerDataResponse {
applicationRequire(config.operationToggle) {
UnauthorizedApplicationError.newBuilder()
.setReason("Operation not allowed (operationToggle config value set to false)")
.build()
}
return CustomPlayerDataResponse()
}
}
In the example above, CustomPlayerDataRequest
and CustomPlayerDataResponse
are just PlayerDataRequest
and PlayerDataResponse
without further customizations added to them.
class CustomPlayerDataRequest : PlayerDataRequest
class CustomPlayerDataResponse : PlayerDataResponse
In order to configure this Player Data Subservice, you would make use of the serviceExtensionConfigs
key in one of the yaml files that are loaded when pragma-engine starts up.
For example, in your local-dev.yml
file you would configure the DemoPlayerDataSubservice
Player Data Subservice as follows.
game:
core:
serviceConfigs:
pluginConfigs:
serviceExtensionConfigs:
DemoPlayerDataSubservice:
operationToggle: true