[SOLVED] DisconnectByServerLogic and Game closed error from OnJoinRoomFailed

I'm having a problem on the game I'm developing. When I try to put more than 4 players in the some room, some issues appear.
Basically when I try to log in the fifth player, I got this:


Disconnected because: DisconnectByServerLogic
UnityEngine.Debug:Log(Object, Object)
PhotonLobby:OnDisconnected(DisconnectCause) (at Assets/Scripts/PhotonLobby.cs:57)
Photon.Realtime.ConnectionCallbacksContainer:OnDisconnected(DisconnectCause) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3438)
Photon.Realtime.LoadBalancingClient:OnStatusChanged(StatusCode) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2557)
ExitGames.Client.Photon.<>c__DisplayClass105_0:b__0() (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PeerBase.cs:907)
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands() (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/EnetPeer.cs:431)
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands() (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PhotonPeer.cs:1596)
Photon.Pun.PhotonHandler:Dispatch() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:205)
Photon.Pun.PhotonHandler:FixedUpdate() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:139)

Couldn't entered the room because: User does not exist in this game
UnityEngine.Debug:Log(Object)
PhotonLobby:OnJoinRoomFailed(Int16, String) (at Assets/Scripts/PhotonLobby.cs:71)
Photon.Realtime.MatchMakingCallbacksContainer:OnJoinRoomFailed(Int16, String) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3525)
Photon.Realtime.LoadBalancingClient:CallbackRoomEnterFailed(OperationResponse) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2104)
Photon.Realtime.LoadBalancingClient:OnOperationResponse(OperationResponse) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2244)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(StreamBuffer) (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PeerBase.cs:620)
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands() (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/EnetPeer.cs:548)
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands() (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PhotonPeer.cs:1596)
Photon.Pun.PhotonHandler:Dispatch() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:205)
Photon.Pun.PhotonHandler:FixedUpdate() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:139)

RaiseEvent(202) failed. Your event is not being sent! Check if your are in a Room
UnityEngine.Debug:LogWarning(Object)
Photon.Pun.PhotonNetwork:RaiseEventInternal(Byte, Object, RaiseEventOptions, SendOptions) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:2213)
Photon.Pun.PhotonNetwork:SendInstantiate(InstantiateParameters, Boolean) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:2562)
Photon.Pun.PhotonNetwork:NetworkInstantiate(InstantiateParameters, Boolean, Boolean) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:2486)
Photon.Pun.PhotonNetwork:Instantiate(String, Vector3, Quaternion, Byte, Object[]) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:2336)
d__13:MoveNext() (at Assets/Scripts/PhotonLobby.cs:113)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

And then, after a while trying, I got this:

Couldn't entered the room because: Game closed
UnityEngine.Debug:Log(Object)
PhotonLobby:OnJoinRoomFailed(Int16, String) (at Assets/Scripts/PhotonLobby.cs:71)
Photon.Realtime.MatchMakingCallbacksContainer:OnJoinRoomFailed(Int16, String) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3525)
Photon.Realtime.LoadBalancingClient:CallbackRoomEnterFailed(OperationResponse) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2104)
Photon.Realtime.LoadBalancingClient:OnOperationResponse(OperationResponse) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2337)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(StreamBuffer) (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PeerBase.cs:620)
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands() (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/EnetPeer.cs:548)
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands() (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PhotonPeer.cs:1596)
Photon.Pun.PhotonHandler:Dispatch() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:205)
Photon.Pun.PhotonHandler:FixedUpdate() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:139)

This is the SupportLogger info when I'm trying:

[12.216] SupportLogger Rtt(variance): 55(7). Since receive: 1ms. Longest send: 1ms. Stats elapsed: 10sec.
Longest delta between Send: 116ms Dispatch: 251ms. Longest callback OnEv: 226=3ms OnResp: 230=7ms. Calls of Send: 199 Dispatch: 507. Ping min/max: 47/55
UnityEngine.Debug:Log(Object)
Photon.Realtime.SupportLogger:LogStats() (at Assets/Photon/PhotonRealtime/Code/SupportLogger.cs:185)

I don't know what to do and I really aprecciate if you guys could help me :smile:

Comments

  • Bubuzam
    Bubuzam
    edited October 2019
    This is the code of my connection:

    using System.Collections;
    using UnityEngine;
    using Photon.Pun;
    using Photon.Realtime;
    using Photon.Voice.PUN;
    #if PLATFORM_ANDROID
    using UnityEngine.Android;
    #endif
    
    public class PhotonLobby : MonoBehaviourPunCallbacks
    {
        public static PhotonLobby lobby;
        public bool OfflineMode;
    
    
        
        public GameObject Avatar;
       
    
        GameObject go;
    
    
        private void Awake() {        
            lobby = this; //Creates Singleton
    
    
    #if PLATFORM_ANDROID
            if (!Permission.HasUserAuthorizedPermission(Permission.Microphone))
            {
                Permission.RequestUserPermission(Permission.Microphone);
                
            }
    #endif
    
        }
        void Start()
        {
            if (OfflineMode) PhotonNetwork.OfflineMode = true;
            if (!OfflineMode) PhotonNetwork.ConnectUsingSettings();
            var temp = PhotonVoiceNetwork.Instance.VoiceClient;
        }
    
    
    
        public override void OnConnectedToMaster(){
            Debug.Log("Player has connected to the Photon master server");
            CreateRoom();
        }
    
        public override void OnDisconnected (DisconnectCause cause)
        {
            Debug.Log("Disconnected because: " + cause.ToString(),this);
            if ((DisconnectCause.ClientTimeout == cause) || (DisconnectCause.ExceptionOnConnect == cause)) PhotonNetwork.ReconnectAndRejoin();
            else if (DisconnectCause.DisconnectByServerLogic == cause) PhotonNetwork.ReconnectAndRejoin();
        }
    
        public override void OnCreateRoomFailed(short returnCode, string message)
        {
            Debug.Log("Failed creating the room. Now trying to enter Sala3926");
            PhotonNetwork.JoinRoom("Sala3926"); 
        }
    
        public override void OnJoinRoomFailed(short returnCode, string message)
        {
            Debug.Log("Couldn't entered the room because: "+message);
        }
    
        void CreateRoom()
        {        
            int RoomName = 3926;
            RoomOptions roomOps = new RoomOptions(){IsVisible=true,IsOpen=true,MaxPlayers=20,PlayerTtl = 0,EmptyRoomTtl = 60000};
            TypedLobby lobby= new TypedLobby();
            PhotonNetwork.CreateRoom("Sala" + RoomName, roomOps,lobby);
            Debug.Log("The room: Sala"+ RoomName + " was created");
        }
    
    
        public override void OnPlayerEnteredRoom(Player newPlayer)
        {
            Debug.Log("A Player entered on the room");
        }
        
        public override void OnJoinedRoom(){
            Debug.Log("OnJoinedRoom() called by PUN. Now this client is in a room. From here on, your game would be running. For reference, all callbacks are listed in enum: PhotonNetworkingMessage");      
            StartCoroutine(WaitToConnect());   
        }
    
        IEnumerator WaitToConnect()
        {
            yield return new WaitForSeconds(2);
            Vector3 posicao = new Vector3(0, 1.75f, 0);
    
    
    #if UNITY_ANDROID
            if (!Permission.HasUserAuthorizedPermission(Permission.Microphone))
            {
                Application.Quit(1);
            }
    #endif
    
            go = PhotonNetwork.Instantiate(Avatar.name, posicao, Quaternion.identity, 0);
        }
    
        public virtual void OnFailedToConnectToPhoton(DisconnectCause cause)
        {
            Debug.LogError("Cause: " + cause);
        }
    }
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @Bubuzam,

    Thank you for choosing Photon!

    What PUN 2 version you use?
    Do you connect to Photon Cloud or self-hosted Photon Server?
    What protocol do you use?

    Do you send too many events or too much data on join?
    I don't see that in the code you shared but maybe in another script?

    And closing the room, maybe you do it on another script?
    room.IsOpen = false

    Also, I see that you first try to create a room then if it exists you try to join it. I think you could make use of JoinOrCreateRoom method.

    Anyway, other than answering those questions, you could take a look at "Analyzing Disconnects".
  • Bubuzam
    Bubuzam
    edited October 2019
    Thanks for answering me, JohnTube :)

    My version is Pun: 2.15 Photon lib: 4.1.2.18
    Connection through Photon Cloud and I use default Protocol: Udp

    room.IsOpen = false

    I only discover this command some days ago, when I was trying to fix this problem, so I'm sure that it doesn't exist in my code. I'm guessing that the room is being closed for some security reason because the player is trying to go into the room but these Disconnections ByServerLogic are happening instead

    Also, I see that you first try to create a room then if it exists you try to join it. I think you could make use of JoinOrCreateRoom method.

    I used to use this command, but I separated in Create e Join for debugging this error

    Anyway, other than answering those questions, you could take a look at "Analyzing Disconnects".

    I read It already and It helped me with others disconnecting problems, but not with this one :disappointed:
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited October 2019
    Hi @Bubuzam,

    Send an email to developer@photonengine.com with your AppId and AppVersion and Region.
    Plus minimal repro steps and link to this forum thread.
  • Bubuzam
    Bubuzam
    edited October 2019
    Thanks JohnTube, I just found out the problem when I was defining the minimal programming steps to reproduce the error.
    One of my scripts was calling constantly a RPC. So I just rewrite it to call the RPC only on changes, fixing the problem. Problably it was calling around 100msgs/s per player and when I was joining with 5 players, it was exceeding the maximum from the server and it was closing the room. SOLVED