Handle Disconnect and Reconnect
Key Problem
UploadWhen player disconnected midgame and then reattempt to reconnect again, how to handle player data when runner call OnDisconnected(). Due to having a connection loss or timeout
Expected Output/Definition of Done
Able to reconnect.
Key Solution
By Theory:
- In
ProgressMP, the player data (& object) should just be kept as is in the server/host, create a timeout limit, if the player is able to reconnect, the should just takeover their player back (or the server can give him the authority back). - If the timeout is triggered, then we gracefully remove the player data (and object), if that player attempts to reconnect, we treat them as a new player (so either spawn new player, or refuse the connection if joining mid game is not allowed)
- Joining mid game should be treated the same as joining from the start, they joining player should automatically get the latest state of all object data, and they should spawn player as usual
By Implementation:
- Found documentation but only has theory https://doc.photonengine.com/en-us/fusion/current/troubleshooting/analyzing-disconnects#reconnect
- Currently trying to replicate disconnect without being despawned then can reconnect and regain control
- Session Name can be saved in PlayerPerfs or other save system to gain ability to reconnect since there’s no specific API for this
- Reconnect is managed by fusion and OnPlayerJoined is not called in client anymore (but called in host)
- Player automatically gain control over its own object if he is reconnected. if its not destroyed yet, if it is already destroyed, player will run OnPlayerJoined again like new player.
- Other option is to handle data like position in client or host, save it with user id, and then destroy it. when player reconnect, they can use that data to resume their progress
- Network situation can be simulated (low ping, lagging, RTO) by using Network Simulation in NetworkProjectConfig.
- (Extra) Photon has ability to do multiple instance in one project bu using Multi-Peer (but this is not tried yet)
Reconnect Implementation (without despawning)
- Use Save System to save last room name
- when user start game, directly get to lobby
- when lobby loaded check room name and its properties if available
- when room is still available make user go to room
- host got callback OnPlayerJoined (to handle switching input back to player?)