Addendum

How I did multiplayer
27 Nov 2013, 12:30 p.m.
I had short scare earlier on where I encountered desynchronization during a multiplayer game, until I determined it was simply because I'd left in some code from the non-multiplayer version of combat, and targeting commands were being executed locally rather than sent across the network.

Still, I needed tools to diagnose this, so these are some things I'm planning to add to the multiplayer code:

Sync checking

Every once in a while, clients store a serialized copy of the game state and send across the checksum for that state. Upon receiving a checksum message, the client then compares the checksums for the same point in time, allowing it to detect if things have gone out of sync. The next step is to allow the client to then request the other client's version of the state, which it can use to diff the states.

Authentication

Right now, clients are perfectly at liberty to fake commands, giving orders to ships that don't belong to them. To fix this, the server can tag each message with the ID of the client it received it from. Clients can then verify that the client actually has the right to give this command, preventing spoofing.

Reliability

It would be nice if the client/server could smooth over short-term disconnects. To make this work, the server gives the client an identification key it can use to reconnect under the same identity after a disconnect. The client also acknowledges receipt of each server update, which allows the server to keep track of which updates may have failed to be received. This means that if the connection temporarily breaks, the server can send the client all the updates that it may have missed.