Skip to content

Latest commit

 

History

History
123 lines (81 loc) · 6.15 KB

create-match-lobby.md

File metadata and controls

123 lines (81 loc) · 6.15 KB

Create a Match Lobby

Index

Summary

This sample demonstrates how to implement the Match Lobbies feature. A Match Lobby is an entity that allows a set of players to be matched and to play together.

This implementation uses the Shared Group Data feature, a data entity shared between a small group of players, where the game state and players' data will be stored during the match.

The Match Lobby data is also stored in a Cosmos DB instance, allowing players to list and join to any available lobby.

As PlayFab's documentation states, Shared Group Data should not be used by groups larger than a dozen or so players, at most.

Prerequisites

Before configuring this project, first ensure the following prerequisites have been completed:

Architecture

This is the current Architecture we're using for implementing the Match Lobby feature:


High-level architecture


Implementation

The implementation of the Match Lobby creation feature has the following steps:


Match Lobby Creation


Unity Game: Starts the creation process

The Unity Game is the first layer involved. Here is where the Match Lobby creation process starts with the player interaction, which triggers the execution of the CreateSharedGroup Azure Function.

The requests to the CreateSharedGroup are sent from the SharedGroupDataHandler which uses the ExecuteFunction method from the PlayFab SDK.

The same logic is used to call the CreateMatchLobby function.

PlayFab Title: Integration with Azure Functions

PlayFab allows the integration with Azure Functions working as an intermediary between the Unity game and the Azure Function.

In this sample, PlayFab receives the requests to execute the Azure Functions with the names CreateSharedGroup and CreateMatchLobby.

Azure Function App: CreateSharedGroup function

The CreateSharedGroup function creates the Shared Group Data (SGD) where the game data will be stored, with the TicTacToeSharedGroupData model structure:

  • The Game Status: It contains the status of the board at each movement, the current player, and the winner.
  • The Match: It contains the Identifier of the P1, and P2.
  • The Match Lobby: It contains the MatchLobbyId, that works also as its name, and the current availability.

This function is responsible for:

  • Creates the Shared Group Data in PlayFab
  • Adds the player who has triggered the function as a member of the group
  • Updates the SGD's SharedGroupId and Match attributes. The SharedGroupId is updated with the ID return by PlayFab in the SGD creation, meanwhile the Match is updated in its PlayerOnId attribute with the ID of the player who has triggered the function.

Azure Function App: CreateMatchLobby function

The Azure Function CreateMatchLobby is responsible for updating the Shared Group Data with the Match Lobby and storing it in Cosmos DB.

We perform this update with a request to the [UpdateSharedGroupData][ms-updatesharedgroupdata-doc] endpoint specifying the SharedGroupId and the Match Lobby's data to update.

Finally, the TicTacToeSharedGroupData is returned to the Game which starts the Start Match process.