ReconnectAndRejoin issue

Hi @jeanfabre ,

I am making a game with using PUN multiplayer in which I am using PUN turnManager class.
I am having one query regarding the disconnection issue.
I noticed that if any joined player got some network fluctuations then he gets the call OnConnectionFail(). So , i handle reconnection in OnDisconnectedFromPhoton() by ReconnectAndRejoin().
But, my question is that in between this disconnection and reconnection process if any game progress/state is changed then how could get the updated game state to reconnected/rejoined player. Because every player in that room should have the same game state while playing the game.So regaining Game state like current players turn, missed turns, etc etc

Thanks in advance.

Comments

  • Hi :)

    All the data for the turn management are hosted in the Room custom properties, so when you rejoin, the player can check all data related to the current state of the game.

    now, if inside your game rules, you also have some data, I suggest you also use Room custom properties and player custom properties to host these specific data.

    Does that make sense?

    else, what are the information you are missing when rejoining? do you experience a case where you can default the turn Management system? If yes, what is your base for handling the turn management, did you wrote it from scratch or use one of our demo?

    Bye,

    Jean
  • Hi @jeanfabre ,

    I m developing one multiplayer turn based tile game by using PUNTurnManager. In that 2 players are there (say player1 & player2).

    Steps:
    1. Both 2 players are playing the game.
    2. If player2 get disconnected in between gameplay.
    3. Then I call ReconnectAndRejoin() to get connected again to same game for player2.
    4. If player2 gets connected to same game, but in that reconnection process if player2 took 3 seconds to rejoin and in that 3 seconds player1 moves some steps in game.
    5. But after reconnecting player2 to the same game, player2 didn't get its updated new position of player1(played in that 3 seconds duration)
    6. Basically my question is, I want to get all updated position for all the players regardless of reconnection for any player.
    7. In short I want to synchronise same game state to all the players.
  • Hi,

    Did you set PlayerTtl to non 0? if non 0, how much?

    If your player leave the room but stay inactive, position will be kept when he rejoin, but if the player left the room and was not inactive ( properly left the room)(, then coming back will not keep the position, and he be joining at the default position.

    Bye,

    Jean
  • Hi,

    I set PlayerTtl = 20000.
    My player not leaving the room, he just got disconnected due to some internet connection fluctuation. Below is the code I handled for Reconnection. (NOTE: this is just filtered code for focussing on exact query...)

    public override void OnConnectionFail (DisconnectCause cause)
    {
    rejoin = true;
    }

    private void OnDisconnectedFromPhoton ()
    {
    if ((PhotonNetwork.connectionState == ConnectionState.Disconnected) && rejoin) {
    ReJoinServer();
    }
    }

    private void ReJoinServer ()
    {
    if (PhotonNetwork.ReconnectAndRejoin ()) {
    rejoin = false;
    }
    }

    Yeah, players self position kept as it is. But I want to sync new updated position of other players, if they moved any steps in between these methods execution.
  • Hi,

    - are you sure the player reconnects to the same room?
    - how do you synchornize player position?

    One way to guarantee position, is that at the end of each turn, you save the position for each players in the room custom properties, then you never loose positioning.

    Bye,

    Jean
  • Hi,

    Yes I am sure that player reconnects to the same room.

    I synchornize player position by receiving the step count number of every player,
    e.g. if player1 gets step count 3 then step count(3) is passed through turnManager's sendMove method then player2 receive 3 as step count and player2 calculates with received step count(3) for player1 and moves player1 with 3 steps. In short, player position is calculated locally by receiving the steps count.

    And what should I keep playerTtl....?
  • Hi @jeanfabre ,

    Hi,

    Yes I am sure that player reconnects to the same room.

    I synchornize player position by receiving the step count number of every player,
    e.g. if player1 gets step count 3 then step count(3) is passed through turnManager's sendMove method then player2 receive 3 as step count and player2 calculates with received step count(3) for player1 and moves player1 with 3 steps. In short, player position is calculated locally by receiving the steps count.

    And what should I keep playerTtl....?
  • Hi,

    Yes, so as I said, Keep the step count for each player either in room Properties or Player Properties, then when you reconnect, you will now the total amount of steps.

    PlayerTtl is a timer to keep a Player that got disconnected inside the room, but inactive, so in your case players will be inactive in a room for 20 seconds maximum.


    Bye,

    Jean
  • Hi @jeanfabre ,

    Thank you for reply. I got your point for saving player position in room properties.

    Can I store array of integers in room custom properties for every player....? Below is an array of position of 2 players.
    int[] posArray1 = new int[4]{ 1, 2, 3, 4 };
    int[] posArray2 = new int[4]{ 5, 6, 7, 8 };

    If yes, then how could I set it.....?

    And then vice versa how could I use it apply to every players.....?

    I mean, how serialization and deserialization works for photon room custom room properties to get back to original arrays....?
  • Hi,

    custom properties are hashtables, so indeed you can have an int array as value and the player Id or index or name as key is you are saving in room custom properties, or simply have a key "positions" if you are saving inside player custom properties.

    there is no worry to have with serialization and deserialization here, you simply set custom properties and you will be notified of properties that changes.

    https://doc-api.exitgames.com/en/pun/current/class_photon_player.html#af8815abb8edaafbe6bddbf328f9612fb

    https://doc-api.photonengine.com/en/pun/current/class_room.html#a9f8ac164f4f24be4140221b72792250a

    https://doc-api.photonengine.com/en/pun/current/class_photon_1_1_pun_behaviour.html#abf25d63a39ef13cb9a0519e6e7672a2f

    https://doc-api.photonengine.com/en/pun/current/class_photon_1_1_pun_behaviour.html#aaec2f5973228b99c6ad781d5cedadb6f

    Bye,

    Jean
  • VitthalVitthal
    edited February 13
    Hi @jeanfabre ,

    Now I completely agree that we can set custom room properties for player position, I done using following code with hashtable and it is getting saved to room properties. But I am not able to apply it to players

    code=====>
    int[] posArray1 = new int[4]{ 1, 2, 3, 4 };
    int[] posArray2 = new int[4]{ 5, 6, 7, 8 };

    ExitGames.Client.Photon.Hashtable roomPositionDetails = new ExitGames.Client.Photon.Hashtable ();

    roomPositionDetails.Add ("p1Pos", posArray1);
    roomPositionDetails.Add ("p2Pos", posArray2);

    Debug.Log ("pos1: " + PhotonNetwork.room.CustomProperties ["p1Pos"].ToString ());
    Debug.Log ("pos2: " + PhotonNetwork.room.CustomProperties ["p2Pos"].ToString ());

    like take an example that i have to store in arr1 and arr2 like below
    PhotonNetwork.room.CustomProperties ["p1Pos"] => arr1
    PhotonNetwork.room.CustomProperties ["p2Pos"] => arr2

    Please help
  • Hi,

    What you do with the values is outside Photon really you can save anything inside the Player and Room Custom Properties and they don't mean anything for Photon, it's up to your own game Logic to decide what to do with it.

    In your case, when a player joins, he would get the array of position and process this array to move itself to the right spot in your game board or world.

    Bye,

    Jean
  • Hi @jeanfabre ,

    Thanks for your reply. I am able to sort out and manage with customRoomProperties.
    I have one more question as below,

    1. there are 2 players(p1,p2) in game.
    2. every player gets 45 seconds(turnTime) to play his turn
    3. if current players(p1) turn finished then turnTime gets resetted in my game logic.
    4. so, is there any variable in photon turn manager to get remaining time in actual current players turn

    I am asking this because it will be hectic to set remaining time in customRoomProperties in update
  • Hi,

    Yes, there is a RemainingSecondsInTurn property available in PunTurnManager. Have you tried it?

    Bye,

    Jean
  • Hi @jeanfabre ,

    Yes I tried it. But its for whole complete turn. Means, it is one cycle of turn.

    e.g. if there are 2 players then the RemainingSecondsInTurn is for one cycle of these 2 players.
    turn1: p1=>p2
    turn2: p2=>p1 (at this point remaining time gets resetted ).

    but i want remaining time for every players turn.....

    I hope it clarifies my query.....

    Thanks.
  • Hi,

    I am afraid I don't understand... can you give a timeline description and where this time fits into that timeline?

    Bye,

    Jean
  • Hi @jeanfabre ,

    Okay, lets take an example there are 2 players (p1 and p2)

    1. I set playerTurnTime = 45 for each player.
    2. means p1 has 45 seconds to play his turn and p2 has the same as well.
    3. So, when p1 completes its turn then playerTurnTime has to reset
    4. playerTurnTime reset to 45 seconds when p2 tuen start

    But, In PUN TurnManager Class remainingTurn is for complete turn cycle (p1=>p2 and then p2=>p1)
  • Hi,

    Yes, this is something you will have to build on top of Pun turn Manager. I don't think there is a built in timer for your case.

    bye,

    Jean
  • Hi @jeanfabre ,

    Thanks for your reply. But I think there should be built in timer for this case.
    If you agree this, then can you please consider it in next PUN update.....?
  • Hi,

    Do I understand correctly that while P1 plays, P2 can not play at all?

    Bye,

    Jean
  • Hi, @jeanfabre ,

    Yes, exactly. But I think this is actual turnBased Logic for types of turn based games. But my query is that there should be separate timer in PUN TurnManager Class for every players turn.
    Like, if we set 45 seconds for every players turn then it has to start from 0 to 45 when P1 starts its turn and then again that timer has to reset to 0 when P1 finishes or plays his turn regardless of turnFinished, turnPlayed with extra chance to play, turnTimeout etc etc.

    And I guess there would be few types of cases in every players turn as below:
    1. Turn Played and passed to next player.
    2. Turn Played and got another chance to play turn.
    3. Turn Timeout and passes to next Player.

    I hope you got my point.

    Thanks. :smile:
  • Hi,

    Then, I would suggest using 2 turns per "round" what you call turn becomes a round or 2 pun turns. during a turn, only one player can play, other players simply wait ( input disable, and simply call the system that they already played or something), and in your interfacem the number of turns is divided by two compared to what PunTurnManager has.

    Does that make sense?

    Bye,

    Jean
  • Hi @jeanfabre ,

    I think, I am going in wrong way for ReconnectAndRejoin. I am confused how to explain it elaborately.
    An I guess you also got fed up with my lengthy query... :neutral:
Sign In or Register to comment.