DoubleDeez / MDFramework

A multiplayer C# game framework for Godot 3.4 Mono.
https://discord.gg/UH49eHK
MIT License
76 stars 13 forks source link

Bug: Desynch issue with MDPlayerInfo and Replicated properties. #13

Closed Beider closed 4 years ago

Beider commented 4 years ago

I noticed while making the synchronizer that the MDPlayerInfo is created, then other clients are notified that it is created followed immediately by asking the MDPlayerInfo to synch itself to other clients.

If for some reason the create player info packet drops or is delayed and arrive after the synchronization the game could end up in a desynchronized state. This can also happen for network nodes as replication starts immediately and if a value is set to OnChange and only changed one time it may never reach the clients. RSet just throws an error if the node doesn't exist and never retries as far as I know.

You can replicate this kind of behavior with Clumsy and a high packet drop rate and high out of order rate.

I think there are two solutions to this problem

Implement a buffer

For this we would supply our own secure versions of all the Rpc and Rset calls and also make the replicator use those. The calls would go through our own class that supports retry and will store any call that fails for a set amount of time. Then we hook into node created and if the node is created we would send all buffered calls.

Personally I think this would be the perfered solution as no callbacks are needed, as such the properties would be set as soon as possible.

Use game synchronizer with callbacks

Second option also includes custom Rpc and Rset except in this instance we implement a callback through the GameSynchronizer so the server is notified when an instance is created on the client. Then the server would be the one to buffer any commands and only send them once the node exists on the client.

The tricky thing here would be to handle things like nodes that exist in the game from the start and if some child node of an instanced network scene is registered. We can probably solve this by checking the hierarchy to see if a parent is a networked scene but it is something to consider.

Beider commented 4 years ago

Ok this was my bad, I actualy made a test for this now and I seems this was not the problem. I don't know if it is the NetworkedMultiplayerENet or Godot Rpc / Rset calls that takes care of this but it seems to not be a problem.

I made a test that spawned a node and immediately changed it's color with both the MDFramework and Rpc calls and both worked even if they arrived out of order.