Skip to content

XBOX-CSM/PlayFabMatchHistoryExtension

Repository files navigation

PlayFabMatchHistoryExtension

The goal of this Project is to showcase how Azure PlayFab can be extended by a scaleable Match History with Azure. We wanted to make sure to integrate with Azure PlayFab as much as possible to feed into the built-in PlayFab Analytics solution.

We only implemented a limited set of queryable statistics, as every game has its very own stats that are interesting to them. Our reference implementation should cover most of these use cases.

This extension is intended as a Proof of Concept and not intended for production use.

Prerequisites

Development Prerequisites

Deploying

PlayFab

  • Get your Title ID (from the Game Studio dashboard or from the GameManager)
  • Get a developer secret key: Create Developer Secret Key
  • Copy it to later use it in an environment variable or as parameter to Terraform

Terraform

You can either choose to set the PlayFab Title Id and Developer Secret as environment variables (recommended, see below), or you can choose not to do so, and instead provide the secret when calling terraform plan or terraform apply, respectively.

Environment Variables

These are optional, but if you do not set them, you will be prompted by Terraform for their values.

Name Description
TF_VAR_pf_title_id A PlayFab Title ID to authenticate against
TF_VAR_pf_developer_secret A PlayFab Developer Secret for the above Title

Init Terraform:

Before initializing, set up a copy of example.backend.config.tf, and configure an existing storage account and container to be used for Terraform state management.

Then, init:

terraform init -backend-config='.\config\backend.local.config.tf'

Apply

terraform apply

Architecture

Architecture Diagram

We use custom PlayFab Player events that are generated by the "GameServerMock" project which is simulating a game server that submits match finished events for Players that participated in the session.

This means that we are expecting the game server to publish one "player_finished_match" event for every player that attended at the end of a match.

We are aware, that integrating this into a C++ / UE / Unity server will require outbound HTTPS connection towards PlayFab. We used the PlayFabSDK but you could build a optimized versions of the web requests that we used.

Getting Events into Azure

The next step is to register a Queue triggered Azure function that takes our custom event and writes it into our Data store. We decided to use CosmosDb as the serverless SKU enables simple testing and scale abilty. As partition key we are using the PlayFab Master Player Id, which gives every Player their own partition. When looking for the History of a Player this partition schema makes sense and enables us to scale. Be aware that this might need optimization for high throughput players that are attracting more than ~20k history request a second.

Deliver the Data to the client

The PublicAPI function project is used to authenticate every request to make sure that only authenticated PlayFab users can query it. Now we only need to query our CosmosDb for the match data of a player and return it.

Have a look at the Swagger UI by navigating to the deployed function app and using the api/swagger/ui endpoint, e.g.

https://pfmatchhistory-publicapi-function.azurewebsites.net/api/swagger/ui

About

An Azure PlayFab Match History reference implementation.

Topics

Resources

License

Stars

Watchers

Forks