Game Instance Reference #
Game Instance service SDK #
The Pragma SDK provides methods that developers can use to facilitate game instance processes, such as connecting more players or ending the game. The SDK includes methods for Game Instance service implementation through the GameInstanceApi
and the MatchApi
, depending on whether the call comes from the player client or game server, respectively. The tables below contains a list of all the methods relevant to the Game Instance service.
Game Instance API (player client) SDK methods #
Call | description | |
---|---|---|
Initialize | Initializes the client’s party API state and synchronizes its party state with the platform’s party state. Must be called prior to using other functionality on the API. | |
ForceSync | Forcibly synchronizes the player client’s game instance data with the game instance information in the Pragma Engine backend | |
Update | Requests game instance data updates | |
DeclineReconnect | Signals that the player is declining to reconnect to the game instance after disconnecting | |
GetGameInstanceCache | Gets the player’s game instance cache |
Match API (game server) SDK methods #
Call | description | |
---|---|---|
RequestStartGame | Requests the game start data for a game instance. Use this method when Pragma does not manage your game server capacity. | |
ConnectPlayers | Connects the initial players for a game instance | |
ConnectMorePlayers | Connects more players for a game instance | |
VerifyPlayer | Uses player connection token to verify that connecting players are not misrepresenting their Pragma identity | |
UpdateGameInstance | Requests game instance data updates | |
RemovePlayers | Removes players from a game instance and processes player game results. Does not end the game instance. | |
EndGame | Request that a game instance end. Does note automatically end the game instance. | |
EnterMatchmaking | Enters a game instance into matchmaking to accept additional players | |
LeaveMatchmaking | Removes a game instance from matchmaking | |
SetRichPresence | Sets a player’s rich presence based on server-side options (such as “in party”) |
The SDK calls invoke various Game Instance Plugin methods through Game Instance service RPCs.
Game Instance service plugins #
The Pragma game instance plugins allow developers to implement custom game instance functionality. Pragma provides the following customizable game instance plugins:
GameInstancePlugin #
The Game Instance Plugin can be used to define custom interactions throughout the lifecycle of a game instance.
method | description |
---|---|
buildExtGameStart | Use to prepare any custom data to provide to the game server when the game server has been allocated to a game |
buildExtGameServerPlayer | Use to prepare any custom data to send to the game server when a player is joining a game |
buildExtAddedToGame | Use to prepare any custom data to send to the player client when they are joining a game |
handlePlayerUpdateRequest | Called when receiving a player request to update a game instance |
handleBackendUpdateRequest | Called when receiving a backend request to update a game instance |
onRemovePlayers | Called when players are removed from the game. Use to prepare any custom data to send to the removed players. |
onEndGame | Called when players are removed from the game. Use to prepare any custom data to send to the removed players. |
Pragma provides a default GameInstancePlugin
implementation, DefaultGameInstancePlugin
, that returns the default ext payloads.
GameServerProviderPlugin #
The Game Server Provider Plugin can be used to route a game instance to a host game server. This plugin accepts an ExtAllocateGameServer
.
method | description |
---|---|
startAllocationForGameInstance | Use to integrate with your game server provider in order to allocate a game server for this game instance. If using the Pragma Fleet service, use this method to prepare custom data needed to determine a server pool for the game instance. |
Pragma provides the following GameServerProviderPlugin
implementations:
DefaultGameServerProviderPlugin
: placeholder implementation for environments that are not yet allocating gamer servers. Replace this implementation as soon as you are ready to allocate actual game servers.LocalProcessGameServerProviderPlugin
: aids in developing a game server on a local machine. Using this plugin can make your local development more similar to your non-local environments.LocalProcessGameServerProviderPlugin
is configured in the local-dev.yml file as the default game server provider plugin.FleetGameServerProviderPlugin
: aids in allocating game servers when using the Pragma Fleet service
GameInstanceMatchmakingPlugin #
The Game Instance Matchmaking Plugin can be used to define custom interactions for a game instance and its players when entering matchmaking.
method | description |
---|---|
buildExtMatchmakingKey | Use to declare any custom data about the matchmaking queue that the game instance is going to enter |
buildExtMatchmakingGameInstance | Use to declare any custom data about the game instance that needs to be sent to the Matchmaking service for use in matchPartiesWithGame() |
buildExtMatchmakingGameParty | Use to declare any custom data about the party in the game that needs to be sent to the Matchmaking service for use in matchPartiesWithGame() |
buildExtMatchmakingGamePlayer | Use to declare any custom data about the players in the game that needs to be sent to the Matchmaking service for use in matchPartiesWithGame() |
Pragma provides a default GameInstanceMatchmakingPlugin
implementation, DefaultGameInstanceMatchmakingPlugin
, that returns the default ext payloads.
Game Instance interfaces #
There are three main interfaces within the Game Instance service: GameInstance
, GameParty
, and GamePlayer
. These interfaces represent game instances and their parties and players.
GameInstance #
The GameInstance
interface represents a running game instance, and includes details about the parties, players, and a custom-defined payload of extra game information that will be used to create the game instance.
property | description |
---|---|
id | Unique GameInstanceId of the game instance |
parties | List of parties in the game instance |
players | List of players in the game instance |
removedPlayers | List of players previously removed from the game instance |
gameServerVersion | Game server version the game instance is running within |
gameServerZone | Game server zone the game instance is using |
inMatchmaking | Boolean value indicating whether the GameInstance is currently enrolled within matchmaking to find more players |
gameServerAllocationStatus | Allocation status of a game server for the game instance (NOT_STARTED , IN_PROGRESS , COMPLETE , or FAILED ) |
ext | The ExtGameInstance created during matchmaking in the NewGameInstance |
method | description |
---|---|
allocateGameServer() | Starts the process of allocating a game server for this game instance |
end() | Ends the game instance. Game instances are not ended until this method is called. |
GameParty #
The GameParty
interface represents a party within a game instance.
property | description |
---|---|
id | Unique party ID |
players | List of players in the game instance |
ext | The ExtGameParty set by the NewGameInstance and GameInstanceUpdate . Used to store unique data for a party in a game instance. |
GamePlayers #
The GamePlayer
interface represents a player within a game instance.
property | description |
---|---|
playerId | Unique player ID |
socialId | Unique social ID |
displayName | Player’s public display name |
partyId | Party ID for the party the player belongs to |
teamNumber | Player’s assigned team number |
ext | The ExtGamePlayer created during matchmaking in the NewGameInstance or GameInstanceUpdate . Used to store unique data for a player in a game instance. |
Data classes #
GameStart #
GameStart
represents data sent to the game server when a game server is allocated for a game instance.
property | description |
---|---|
gameInstanceId | Unique game instance ID |
playersAndExts | List of GamePlayer and ExtGameServerPlayer |
ext | The ExtGameStart used to store custom data to send to the game server |
PartnerClientTokens #
The PartnerClientTokens
class contains data for partner client tokens that the game server should use when authenticating to Pragma.
property | description |
---|---|
gameToken | Partner client token to use when authenticating to Pragma game backend |
socialToken | Partner client token to use when authenticating to Pragma social backend |
Configuration #
The GameInstanceServiceConfig
configuration block provides a place to define default values for the Party service. The following configuration values are available:
config | description |
---|---|
gameReadyTimeoutMillis | Time, in milliseconds, to wait for a game server to send a connect players request before releasing the players attached to the game instance |
enableKeepAlive | Enables the keep alive interval, which specifies the interval within which a game server needs to send a keep alive request. If the game server does not send a request within this interval, the the game instance will be released from the service. |
keepAliveIntervalMillis | Interval, in milliseconds, to wait between keep alive requests. This value will be ignored if enableKeepAlive is false . |
keepAliveMissesLimit | Number of keep alive request the game server can miss before releasing the game instance from the service. This value will be ignored if enableKeepAlive is false. |
reconnect | Determines the player client behavior when recovering from an unexpected disconnect during a game |
enableExtraCreateGameInstanceTimers | Enables additional timing metrics to diagnose performance issues within the CreateGameInstanceV1 endpoint |
enableStaleGameInstanceExpiration | Enables the absolute timeout that will release a game from the service after a specific amount of time has elapsed. Defaults to true . |
staleGameInstanceExpirationMinutes | Time, in minutes, to wait before releasing a game instance. A 0 or negative values means games will never timeout. This value will be ignored if enableStaleGameInstanceExpiration is false . |
Extension data #
You can use Extension Data (exts
) to pass custom information between different Pragma components for the duration of the game instance. Fields in the various exts
can be stored on the engine, or forwarded to plugins, game servers, and player clients through other exts
. Using exts
to define when and how certain data travels between two components allows you to control each component’s access to certain data. See Game Instance Tasks for sample implementation.
The following table lists the ext
payloads relevant to game instance information.
ext | description | Example data |
---|---|---|
ExtAllocateGameServer | Data to assist in game server allocation. Populated by GameServerProviderPlugin.startAllocationForGameInstance() and used in the Pragma Fleet service to determine which server pool to assign for the game instance. | |
ExtRemovePlayersRequest | Game instance data sent from the game server to the Game Instance Plugin’s onRemovePlayers() method when a group of players are removed from a game instance. | game time elapsed at removal time |
ExtRemovePlayer | Player data passed from the game server to the Game Instance Plugin’s onRemovePlayers() method via the playerToRemove list when a player is removed from a game instance. | player’s progress on current mission |
ExtRemovedFromGame | Player data populated by the Game Instance Plugin’s onRemovePlayers() method and sent to the removed player client in the OnRemovedFromGame notification when the player is removed from a game instance | rewards delta |
ExtEndGameRequest | Game instance data sent from the game server to the Game Instance Plugin’s onEndGame() method when a game instance ends | game metrics |
ExtPlayerGameResult | Player data passed from the game server to the Game Instance Plugin’s onEndGame() method via the PlayerGameResult list when a game instance ends | completed missions, points gained |
ExtGameEnded | Player data populated by the Game Instance Plugin’s onEndGame() method and sent to the player in the OnGameEnded notification when a game instance ends. Players previously removed from the game instance can still receive this information. | rewards delta |
ExtAddedToGame | Game instance data populated by the Game Instance Plugin’s buildExtAddedToGame() method and sent to the player client in the OnAddedToGame notification when the player is added to a game | team color, current game score |
ExtGameInstance | Game instance data populated by the Matchmaking Plugin’s matchParties() method and sent to the Game Instance Service when a new game instance is created. This data will be used when creating the new game instance and persists on the engine for the duration of the game instance. | max game instance duration, game mode, map |
ExtGameParty | Party data populated and passed to the Game Instance service when the Matchmaking service creates a NewGameInstance or GameInstanceUpdate . The data persists on the engine for the duration of the party’s time in the game instance and can be updated during subsequent plugin calls. | custom party data |
ExtGamePlayer | Player data populated and passed to the Game Instance service when the Matchmaking service creates a NewGameInstance or GameInstanceUpdate . The data persists on the engine for the duration of the player’s time in the game instance and can be updated during subsequent plugin calls. | Steam ID |
ExtGameStart | Game instance data provided to the game server starting the game. When the game server is allocated for a game instance, it calls getGameStartDataV1() , which invokes the Game Instance Plugin’s buildExtGameStart() method. This ext could include data sent to the Game Instance service in the ExtGameParty payload. | game instance duration |
ExtGameServerPlayer | Player data provided to the game server by the Game Instance service. When the game server is allocated for a game instance, it calls getGameStartDataV1() , which invokes the Game Instance Plugin’s buildExtGameServerPlayer() method for each player in the game instance. This ext could include data sent to the Game Instance service in the ExtGamePlayer payload. | Steam ID |
ExtPlayerConnectionDetails | Connection details populated by the game server and used when a game instance is ready for players to join. Players receive the connect details in the OnHostConnectionDetailsReceived notification. | game server zone/region |
ExtBackendUpdateRequest | Payload sent via the game server’s UpdateGameInstance() SDK method defining what updates to make to a game instance | advance the current game phase |
ExtPlayerUpdateRequest | Payload populated by player clients defining what updates to make to a game instance | connection details in peer-to-peer setups |
Events #
There are several game instance-related events that player clients and game servers can listen to. The following tables contain bindable events relevant to the Game Instance service, along with associated descriptions of when the event is triggered.
Player client events #
The following events are handled by the player client.
Event | Trigger | Data returned |
---|---|---|
OnAddedToGameInstance | The player has been added to a game instance. Will be followed with OnHostConnectionDetailsReceived when the game server is ready. | GameInstance |
OnFailedToAllocateGameInstance | Game instance allocation fails due to game server issues after matchmaking succeeds | N/A |
OnHostConnectionDetailsReceived | The game server starts a game instance and is available for parties to connect | GameInstance |
OnRemovedFromGameInstance | The game server has removed the player from the game | game instance ID, ExtRemovedFromGame |
OnGameInstanceEnded | The game has ended | Game instance ID, ExtGameEnded |
OnGameInstanceTerminated | A game instance is forcibly terminated because it’s no longer communicating with the engine | game instance ID, termination reason (UNSPECIFIED , KEEP_ALIVE_FAILED , or ABSOLUTE_TIMEOUT_ELAPSED ) |
OnGameInstanceUpdated | A game instance is updated due to player client request | GameInstance |
Game server events #
The following events are handled by the game server.
Event | Trigger | Data returned |
---|---|---|
OnGameStart | Game instance data is retrieved using the provided game instance ID | GameStart |
OnGameStartFailed | An error occurs when attempting to retrieve game instance data with the provided game instance ID | Pragma error |
OnKeepAliveFailed | The platform fails to process a keep alive request | game instance ID, Pragma error |
OnAddPlayers | The platform sends new players to the game server to add to the game instance. Upon receiving, the game server should invoke ConnectMorePlayers with prepared details for the provided new players for the provided game instance id. | game instance ID, list of Game players |
OnGameInstanceEnteredMatchmaking | The given active game instance enters matchmaking | game instance ID |
OnGameInstanceLeftMatchmaking | The given active game instance leaves matchmaking | game instance ID |
OnPlayerDeclinedReconnect | A player declines to reconnect to the game they were in. Includes the game instance ID and player ID respectively. | game instance ID, player ID |
Errors #
- GameInstanceService_GameServerAlreadyAllocated
- GameInstanceService_CapacityRequestFailed
- GameInstanceService_UnknownGameInstanceId
- GameInstanceService_PlayerNotInGameInstance
- GameInstanceService_GameInstanceAlreadyInMatchmaking
- GameInstanceService_MissingPlayerConnectionDetails
- GameInstanceService_CannotDeclineReconnect
- GameInstanceService_FailedToUpdateMatchmakingGameInstancePlayers
- GameInstanceService_FailedToLeaveMatchmaking
- GameInstanceService_GameInstanceNotInMatchmaking
- GameInstanceService_FailedToUpdateMatchmakingGameInstance