PUN, PLayfab and Unity - RPC Reconnect to Game

Options
Wichael
Wichael
edited October 2020 in DotNet
Hi,

So I'm working on a 2 player turn based game. All moves will be handled via RPC events. So when player A moves an RPC will be sent to player B and player B's client will recreate that move.

So far this RPC method is working perfectly well for my game.

My problem now is that I need to setup a way for a player that disconnected and rejoined the room to be able to go back to the state that they were in before they left.

So my current plan is as follows:

Reconnecting to Game
1. Player A creates a room. Room name = player A's Playfab ID.
2. Player B joins the room and game starts. Room name is changed to Player A + Player B ID. This room name is then updated in both player's backend Playfab "Player Data". So now both player's backend "Current Game" will be that unique room name.
3.1 Game Ends - Both player's "Current Room" is set to null.
3.2 Player A/B disconnects and reopens client.
On Login the current game ID will be pulled, Photon will then check if there are any current rooms open with
that ID, if there is the player will be able to rejoin that game. If not a "Lose Game" function will be run, updating the
player's stats and setting their current game ID to null.

Resyncing Player's Moves
1. Add a component to the game that is network instantiated and synced.
2. When a move is made, that component is updated.
3. When a player reconnects to a room, they will pull the game state info from that component and recreate the moves that were made and update any data like timers, current player turn, chat history etc...

So my questions are:
1. Is there a better way to do all of this?
2. Would it be better to just RPC everything from the current connected client to the rejoined client when they reconnect? I'd prefer a synced component on a game object that the reconnecting player can just pull info from instead.
3. How can I sync a component?

My main need right now is to know if a component can be synced over the network, as this will also allow me to sync the timers for each player right down to the second. It could also make some other code a lot easier as I'd be able to sync the entire Game Manager over the network and reduce some RPC calls.

Thank you in advance,
Michael.