Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Photon PUN missing error handler?

Discussion in 'Multiplayer' started by Paulx774, Jul 8, 2021.

  1. Paulx774

    Paulx774

    Joined:
    Mar 18, 2021
    Posts:
    103
    When I call PhotonNetwork.ConnectUsingSettings method, Photon automatically calls OnConnectedToMaster method when it succeeds. I want to show an error message if a client can't connect to the master server, but I couldn't find any error handler.

    The same thing for the JoinLobby method as well. There's a method called OnJoinedLobby when it succeeds, but there is no error handler.

    There is, however, error handlers for CreateRoom and JoinRoom methods.

    How can I catch the errors for ConnectUsingSettings and JoinLobby?

    EDIT: Followup question: The error handlers return a code in short. Where can I find which code means what? Is there any lookup table?
     
    Last edited: Jul 8, 2021
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    When you connect, check the return value of ConnectUsingSettings(). If this returns false, there is (likely) an issue with the address (if you entered any).
    Check out the IConnectionCallbacks, too. If the connection is not working, the client calls OnDisconnected(DisconnectCause cause). If the authentication rejected your players, there will be a call to OnCustomAuthenticationFailed(string debugMessage). All other cases, should connect to the Master Server.

    JoinLobby has no error case. Lobbies are created on demand.

    You should use the callbacks. Those use enums.
    Which ones do you refer to? You may look into Photon.Realtime.ErrorCode.
     
    Paulx774 likes this.
  3. Paulx774

    Paulx774

    Joined:
    Mar 18, 2021
    Posts:
    103
    I'm actually using ConnectToRegion method. It returns true/false as well. So, it should be the same.

    The error handlers returning codes in short type are OnCreateRoomFailed and OnJoinRoomFailed methods. They are not enum type.

    Code (CSharp):
    1.         /// <summary>
    2.         /// Called when the server couldn't create a room (OpCreateRoom failed).
    3.         /// </summary>
    4.         /// <remarks>
    5.         /// The most common cause to fail creating a room, is when a title relies on fixed room-names and the room already exists.
    6.         /// </remarks>
    7.         /// <param name="returnCode">Operation ReturnCode from the server.</param>
    8.         /// <param name="message">Debug message for the error.</param>
    9.         public virtual void OnCreateRoomFailed(short returnCode, string message)
    10.         {
    11.         }
    12.  
    13.         /// <summary>
    14.         /// Called when a previous OpJoinRoom call failed on the server.
    15.         /// </summary>
    16.         /// <remarks>
    17.         /// The most common causes are that a room is full or does not exist (due to someone else being faster or closing the room).
    18.         /// </remarks>
    19.         /// <param name="returnCode">Operation ReturnCode from the server.</param>
    20.         /// <param name="message">Debug message for the error.</param>
    21.         public virtual void OnJoinRoomFailed(short returnCode, string message)
    22.         {
    23.         }
    I checked the Photon.Realtime.ErrorCode class and it has some const int variables. That should be it, I guess. Thank you for the answer.