Questions about ReconnectAndRejoin

Our app logic is

JoinRoom -> OnJoinedRoom->PhotonNetwork.Instantiate


Now we add the TTL logic using PlayerTTL and ReconnectAndRejoin, we set the PlayerTTL to 60000,we simulate the environment by shutting down the wifi and reopen it.The rejoin logic is as follows:

judge the network is connected -> call ReconnectAndRejoin->OnJoinedRoom->PhotonNetwork.Instantiate

Using the above logic, every time one new player is created ,and the cached player on photon server is also Instantiated locally.

So what is the correct way to use ReconnectAndRejoin?our purpose is that the cached player and local player should be one player after reconnectandrejoin.

Comments

  • harlan
    harlan
    edited August 2019
    hello @JohnTube

    we did some investigations and now know that when using ReconnectAndRejoin, PhotonNetwork.Instantiate should not be used locally and the player data is restored from photon server.But now has other two questions,
    • i moved to other position after I was born in the room, after ReconnectAndRejoin, the position cannot be restored and I am in where I was born again, so how to restore my position?I saw a post said that it can use SetCustomProperties to save the positions, but I think it is a waste for network traffic.
    • How to know the IsInactive value changed when some other player disconnect from photon server.I already did some tests, and found that OnPlayerPropertiesUpdate is not called at all, and OnPlayerLeftRoom is called two times ,a little strange,, maybe it is called the first time when other player disconnect from server, and second time when the player TTL is overdue??
    Please help me if you have time, thanks.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @harlan,

    I'm glad you found out that Instiantiate calls are cached events and the server sends those automatically to newly/late joiners or rejoiners.
    But now has another question, i moved to other position after I was born in the room, after ReconnectAndRejoin, the position cannot be restored and I am in where I was born again, does PUN support this?
    I don't think so. PhotonView synchronization events are not cached so you would need to find a solution for this yourself.
  • harlan
    harlan
    edited August 2019
    Thanks @JohnTube

    Please see my second question above, thank you.
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited November 2019
    OnPlayerLeftRoom is called two times ,a little strange,, maybe it is called the first time when other player disconnect from server, and second time when the player TTL is overdue??
    You guessed right yes. OnPlayerLeftRoom(Player otherPlayer) can be called twice when PlayerTTL > 0. You can check otherPlayer.IsInactive, the first time it's true the second time it's not.

    EDIT: correct way to tell when an actor is removed from the room vs. became inactive is shown below here.
    @harlan FYI
  • harlan
    harlan
    edited August 2019
    that's good ,thanks @JohnTube
  • Sathyaraj
    Sathyaraj
    edited November 2019
    Hi @JohnTube
    I tried your solution but on both OnPlayerLeftCalls calls IsInactive is true. The only thing changes during the second call is PhotonNetwork.PlayerList.Length. The first time it is 2 and on second call it's 1.
    How to handle actual disconnection in such cases!
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @Sathyaraj,

    You're right, I will rectify the other post.
    Until we have a better way to handle this, you could do this:
    void OnPlayerLeftRoom(Player otherPlayer)
    {
        bool leftForGood = !PhotonNetwork.CurrentRoom.Players.ContainsKey(otherPlayer.ActorNumber); 
    }
    Thank you for your understanding!
  • Hi @JohnTube,
    Yes. for now we are using the above suggested workaround. Thanks.