- Client and server both running at 66.66Hz internally (15ms steps)
- Client send commands to the at a rate of 33.33Hz (30ms), so on average there are two commands per packet are sent to the server
Now, the server receives these commands from the client, put in a local command queue for a client and then executed one by one every 15ms, the queue is re-filled every 30ms by new commands from the client, and one command is picked of the queue every 15ms by the server. Those of you experienced with this kind of thing probably already knows what is "going wrong", let me give you an example:
- 30ms Client sends two commands to the server
- 60ms Client sends two more commands to the server
- The server receives both batches of commands from the client at the same time due to lag/etc.
- Now the client continues to send two commands every 30ms
- The server de-queues one command every 15ms, but will never catch up to the "latest" command due to there always arriving more commands and the initial "burst" of 2x2 commands due to network lag
- Limit the command queue to two commands and drop everything else, this will cause the occasional dropped package but it's not that big of a deal since it can be smoothed out
- Execute commands as fast as they come in to keep up with the client. This feels like it would open up the server for cheating though, by sending commands at a blazing speed to move your character faster for example. Maybe there is some clever way of deducing when commands are valid even when they coming in bursts to disable the ability to cheat.
How do I deal with this, the fact that packets don't always arrive with equal spacing, especially when they sometimes miss the current running fixed step update and get delayed another 15ms. This causes a "queue" of commands to build up on the server which creates even more lag for the client since the server has to chew through the first X commands that are queued before the last received one.
I've come up with a couple of options, none seems really satisfying:
Again, thanks everyone that has helped me so far!