This document is about: SERVER 5
SWITCH TO

App and Lobby Stats

Photon servers can broadcast application and lobby statistics to clients. You can make use of this data to implement a complex custom matchmaking system. You can also brag about these statistics in your game to show how popular it is. :]

Application Statistics

When connected to a Photon master server, a Photon client receives applications statistics. Regardless of whether the client is joined to a lobby or not, it will receive AppStats events. Application statistics are per region.

The applications statistics are:

  • Number of live rooms:

    C#

    loadBalancingClient.RoomsCount
    

    C++

    Client::getCountGamesRunning()
    
  • Number of players not joined to rooms:

    C#

    loadBalancingClient.PlayersOnMasterCount
    

    C++

    Client::getCountPlayersOnline() - Client::getCountPlayersIngame()
    
  • Number of players inside rooms:

    C#

    loadBalancingClient.PlayersInRoomsCount
    

    C++

    Client::getCountPlayersIngame()
    
  • Total number of connected players:

    C#

    loadBalancingClient.PlayersOnMasterCount + loadBalancingClient.PlayersInRoomsCount
    

    C++

    Client::getCountPlayersOnline()
    

    AppStats event is sent to client every five seconds.

    In the native C++ SDK, the Listener class provides a callback every time to know that the statistics' getters are updated:

    C++

    virtual void onAppStatsUpdate(void) {}
    

Lobby Statistics

Lobby statistics can be useful if a game uses multiple lobbies and you want to show the activity.

Per typed lobby (name + type) you can get information about:

  • Number of live rooms
  • Total number of players joined to the lobby or joined to the lobby's rooms

Automatically Get Lobby Statistics

Lobby statistics events are sent as soon as the client is authenticated to a master server. Then they are sent every minute. Lobby statistics events are disabled by default.

  • C#

    Before connecting, to enable lobby statistics:

    C#

    loadBalancingClient.EnableLobbyStatistics = true;
    

    Get the statistics from the ILobbyCallbacks.OnLobbyStatisticsUpdate callback which could be useful to update your UI.

  • C++

    To enable lobby statistics, one has to pass true for parameter autoLobbyStats to the constructor of class Client:

    C++

    Client(LoadBalancing::Listener& listener, const Common::JString& applicationID, const Common::JString& appVersion, nByte connectionProtocol=Photon::ConnectionProtocol::DEFAULT, bool autoLobbyStats=false, nByte regionSelectionMode=RegionSelectionMode::DEFAULT);
    

    The Listener class provides the following optional callback whenever a lobby stats event arrives (when enabled):

    C++

    virtual void onLobbyStatsUpdate(const Common::JVector<LobbyStatsResponse>& lobbyStats) {}
    

Explicitly Get Lobby Statistics

You can explicitly request lobby statistics using an operation call when not joined to a room:

  • C#

    This is currently not implemented.

  • C++

    C++

    Client::opLobbyStats()
    

    The Listener class provides the following optional callback when the response arrives:

    C++

    virtual void onLobbyStatsResponse(const Common::JVector<LobbyStatsResponse>& lobbyStats) {}
    

Photon Server Configuration

You can configure how often LobbyStats event is sent to clients. To do so, change the value of "LobbyStatsPublishInterval" inside the configuration file of the Photon master server application. The unit used is seconds.

XML

<Photon.LoadBalancing.MasterServer.MasterServerSettings>
    <setting name="LobbyStatsPublishInterval" serializeAs="String">
        <value>120</value>
    </setting>
</Photon.LoadBalancing.MasterServer.MasterServerSettings>

There is also an optional setting to limit the number of statistics returned by the server. To do so, change the value of "LobbyStatsLimit" inside the configuration file of the Photon master server application. If not configured or set to zero no limit will by applied. Any other positive integer will set the maximum allowed number of lobbies.

XML

<Photon.LoadBalancing.MasterServer.MasterServerSettings>
    <setting name="LobbyStatsLimit" serializeAs="String">
        <value>0</value>
    </setting>
</Photon.LoadBalancing.MasterServer.MasterServerSettings>
Back to top