Recent Changes - Search:

Main.SideBar (edit)

PmWiki

NetworkSync

A NetworkSync is (in our terminology) the task of brining an out-of-sync client back into sync.

For this we first have to find out whether a client is out of sync (see NetworkSyncCheck). If we detected that this is the case, we have to do some tricky things

  • Stop sending advance messages (immediately, even before game is paused)
  • Pause the game
    • Wait until all clients actually are in pause mode

We first stop sending advance messages because pausing the game works asynchronously. If we had to wait until the GamePaused message is actually received, we would have sent out several additional advance messages, making the out-of-sync problem even worse.

Once the game is paused we need to make sure that no other messages are delivered anymore, except of those that are mentioned in our Sync protocol. This is very important, as it may otherwise be possible that a message changes a game state before the client is synced on client A, but after it was synced on client B. Then we are out of sync immediately again. I believe such a bug would be hard to find, so we need to avoid it right from the start. Once that has been ensured, we create a Sync message. That is actually just the game saved to a stream. Optionally we may take a look at where the syncing error occurred (see NetworkSyncCheck) and load that part only (which would be a lot faster). But the principles discussed here remain valid.

The ADMIN sends that message to all CLIENTs, including itself. That is important, because the saving/loading code may contain bugs as well and then these bugs must appear on all clients, otherwise we won't be in sync. After the ADMIN loaded the game from the stream, it should send out another SyncCheck message, but not a usual one, but rather one that contains nearly the whole game (we had to pause the game anyway, so speed is not relevant anymore). After all clients sent back their ACK (positive or negative doesn't matter here), we can unlock the game (i.e. enable message delivery again). Unpausing should be done manually by the user.

Here a (handmade) image illustrating the protocol:

Edit - History - Print - Recent Changes - Search
Page last modified on January 11, 2005, at 17:55