Setting PhotonNetwork.CurrentRoom.MaxPlayers causes DisconnectByServerLogic

Options

Hey there,

I've recently noticed that a part of my code that had been working for several months seemed to stop working. After narrowing it down, it appeared to be a bug within PUN (or Photon Realtime), so I created a new minimal project to reproduce the error.


The error is as follows:

Server 92.38.155.179:5056 sent disconnect. PeerId: 24039 RTT/Variance:37/10 reason byte: 1 peerConnectionState: Connected

UnityEngine.Debug:Log (object)

Photon.Realtime.LoadBalancingClient:DebugReturn (ExitGames.Client.Photon.DebugLevel,string) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2581)

ExitGames.Client.Photon.EnetPeer:ExecuteCommand (ExitGames.Client.Photon.NCommand) (at C:/Dev/photon-sdk-dotnet/PhotonDotNet/EnetPeer.cs:1665)

ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands () (at C:/Dev/photon-sdk-dotnet/PhotonDotNet/EnetPeer.cs:438)

ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands () (at C:/Dev/photon-sdk-dotnet/PhotonDotNet/PhotonPeer.cs:1771)

Photon.Pun.PhotonHandler:Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:226)

Photon.Pun.PhotonHandler:FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:145)


This happens a few seconds after trying to set PhotonNetwork.CurrentRoom.MaxPlayers = 0;

The class I'm using to recreate the error looks like this (this is the only code in this project):


using UnityEngine;

using Photon.Pun;

using Photon.Realtime;


public class Manager : MonoBehaviourPunCallbacks

{

   void Start()

   {

      Debug.Log("Connecting...");

      PhotonNetwork.ConnectUsingSettings();

   }


   public override void OnConnectedToMaster()

   {

      base.OnConnectedToMaster();

      Debug.Log("Connected to master, joining room...");

      PhotonNetwork.CreateRoom("testRoom");

   }


   public override void OnJoinedRoom()

   {

      base.OnJoinedRoom();

      Debug.Log("Joined room");

      PhotonNetwork.CurrentRoom.MaxPlayers = 0;

   }


   public override void OnDisconnected(DisconnectCause cause)

   {

      base.OnDisconnected(cause);

      Debug.Log($"Disconnected: {cause}");

   }

}


Note: This only happens when trying to set the rooms MaxPlayers, not any other room property like IsVisible or EmptyRoomTtl. The bug is reproducible with Unity 2022.2.1 and 2022.2.12.


Thanks in advance!

Answers

  • Tobias
    Options

    Thanks for the report and repro. I could use that to confirm.

    We'll have to discuss this here to figure out if this is by design. Overall, we changed the 20 CCU apps to not be able to use more than 20 players max in a room. But 0 should possibly just equal 20 players max in this case.

  • BlackThunder
    Options

    After some more testing I figured out that, indeed, the disconnect only occurs when setting MaxPlayers to something over 20 (or 0, which i guess translates to 255 internally since its a byte).

    However, I seem to have stumbled to upon another bug, as setting MaxPlayers to exactly 20 prevents OpSetPropertiesOfRoom() from being called (according to the network logs), any value between 1 and 20 works fine.

    Until the issue is resolved I will set MaxPlayers to 19 instead of 0 while operating with the free version of PUN in our development environment.

    Thanks for your help!

  • Tobias
    Options

    I can not reproduce the issue with setting Room.MaxPlayers = 20 in an AppId with the 20 CCU free plan. For me, that works fine.

    In PUN you should normally not go over 16 players, unless you made us aware of what you do. PUN is not extremely clever at reducing the needed bandwidth when updating a lot of players. Please contact us: developer@photonengine.com.