Federated Game Server¶
Game Server Federation allows you to integrate with 3rd Party Game Server Orchestrator (such as Hathora or Agones) as well as running arbitrary server-authoritative code before a lobby goes into a match.
The interface you implement looks like this:
There are two Federation Calls to this function: Matchmaking Match Found and Provision Game Server for Lobby.
Matchmaking Match Found¶
This is an Out-of-Band call that happens as part of the Matchmaking flow:
- Add the
IFederatedGameServer
federation to your microservice with a particular Federated Id. - Set up that Federated Id in any
UBeamGameTypeContent
'sfederation
field. - Use the
UBeamMatchmakingSubsystem
'sTryJoinQueue
operation passing along thatUBeamGameTypeContent
's id to join the queue. - Once a match is made, the
CreateGameServer
federated function will be invoked with a Lobby structure containing all of the players matched together. - This function can then do one or more of the following things:
- Use a 3rd Party API to provision a game server, wait for it to spin up and add the connection information to the
ServerInfo
return object. - Pre-fetch data associated from each player from Stats, Inventory or Storage Objects and add that data into the
ServerInfo
return object.
- Use a 3rd Party API to provision a game server, wait for it to spin up and add the connection information to the
- The returned
ServerInfo
object gets merged into the Lobby's global and player data. - The client SDK receives a notification from Beamable that a match is ready and invoke the
UBeamMatchmakingSubsystem
'sOnMatchReady
callback for the match ticket.
You can check out our Hathora Demo for more information on how to implement the actual CreateGameServer
function.
Working Locally¶
Because this is an Out-of-Band call, you'll need to set a content-id filter for which queues you want your locally running microservice to handle when its running.
You can do this via the Federation tab of the Microservice window or by using the following commands:
# Gets the current content filter for the this Service, FederationType and Federation Id.
dotnet beam federation local-settings get IFederatedGameServer --beamo-id MyService --fed-id myid
# Sets the content ids filter for the IFederatedGameServer
dotnet beam federation local-settings set IFederatedGameServer --beamo-id HathoraDemo --fed-id hathora --content-ids game_types.my_queue
Provision Game Server for Lobby¶
Certain games allow players to create custom lobbies manually. If those games also require invoking the federation endpoint to provision a server or run some arbitrary code, they can do so via the following steps:
- Add the
IFederatedGameServer
federation to your microservice with a particular Federated Id. - Set up that Federated Id in any
UBeamGameTypeContent
'sfederation
field. - Create a Lobby with the
UBeamGameTypeContent
's id.- Closed/Open lobbies both work with federation.
- Players will join the lobby and eventually become ready.
- Most custom lobby implementations use
UBeamLobbySubsystem
'sUpdatePlayerTags
function to update each individual player's ready state.
- Most custom lobby implementations use
- Once all players are ready, the lobby host can invoke the
UBeamLobbySubsystem
'sProvisionGameServerForLobby
function. - This function requests that the configured federation on the
UBeamGameTypeContent
'sCreateGameServer
implementation.This function can then do one or more of the following things:- Use a 3rd Party API to provision a game server, wait for it to spin up and add the connection information to the
ServerInfo
return object. - Pre-fetch data associated from each player from Stats, Inventory or Storage Objects and add that data into the
ServerInfo
return object.
- Use a 3rd Party API to provision a game server, wait for it to spin up and add the connection information to the
- Once that function returns, it'll trigger
UBeamLobbyState
'sOnLobbyUpdated
callback for the lobby each particular player is in.- You can check if the connection information you generated inside
CreateGameServer
is within the lobby's global properties (ULobby::Data
) and use that to connect all players to the newly created game server instance.
- You can check if the connection information you generated inside
While we don't have a sample showcasing this exact case, you can still learn a lot about this from our Hathora Demo sample.