This document is about: SERVER 4
SWITCH TO

Room Persistence Guide

This guide explains how to persist Photon rooms data on a web server.

Concept

Although by nature Photon applications are synchronous, they can be extended to support asynchronous behaviour.

Photon webhooks can be enabled and configured in a way it lets players leave and rejoin rooms seamlessly without losing game data.

It is also possible to enable joining rooms asynchronously via friend invitations.

In Photon, game data is called room state. The room state is composed of:

  • Room options
  • Room Properties
  • Actors List
  • Event cache
  • Interest Groups

In order to resume a left game, room state should be reconstructed.
That is why, the most simple way of persisting data in Photon is to save the room state as is.

Saving Room State

To save a room state, the following webhooks settings are required:

  • BaseUrl should be an available URL.
  • IsPersistent = true.
  • PathClose should be a valid working path.

When you create rooms, these conditions need to be met:

  • RoomOptions.PlayerTTL == -1 or RoomOptions.PlayerTTL > RoomOptions.EmptyRoomTTL.
  • RoomOptions.CheckUserOnJoin = true.

When players want to leave a room without abandoning you should call Disconnect() or OpLeave(true).

The room state will be sent in PathClose webhook and you will need to save it from your web server.

Loading Room State

To load a room state, the following webhooks settings are required:

  • BaseUrl should be an available URL.
  • IsPersistent = true.
  • PathCreate should be a valid working path.

To rejoin a room you should call:

C#

loadBalancingClient.OpReJoinRoom(savedRoomName);

If your game includes challenges and invitations you should keep AsyncJoin enabled (by default).
This way you can join rooms normally by name:

C#

loadBalancingClient.OpJoinRoom(roomName);

From web server you need to return the previously saved room state in the webhook response.

CheatSheet

IsPersistent PathCreate PathClose RoomOptions Comment
true valid path valid path PlayerTTL == -1
0 <= EmptyRoomTTL
Inactive players can never timeout.
Room state will always be sent unless all actors explicitly leave for good and the room stays empty for EmptyRoomTTL ms.
* * * EmptyRoomTTL >= PlayerTTL
PlayerTTL >= 0
Room state will never be sent in PathClose webhook.
true valid path valid path PlayerTTL > EmptyRoomTTL
EmptyRoomTTL >= 0
The room can only be loaded within PlayerTTL - EmptyRoomTTL ms after saving it.
false * * * Persistence disabled. Room state will never be sent in PathClose webhook.
* empty or invalid path * * Persistence disabled. Room state cannot be loaded using PathCreate webhook.
* * empty or invalid path * Persistence disabled. Room state cannot be sent in PathClose webhook.
Back to top