I'm not sure how to ask this, so I'll just get into it. I'm trying to figure out a way to handle network jitter, when packets received by the server aren't spaced out like the client sent them, using a de-jitter buffer.
The client sends commands immediately as they are given, they are not held in any buffer on the client. The server keeps them in a buffer until they are ready to be processed (validity checking, etc) and sends those updates to other clients at a rate of 20hz. The server's world simulation runs at 60hz as wells as the client's. The client does NOT send periodic position/state updates, it only sends changes. Like "player started moving in this direction at this speed", "player has stopped moving and is now here". If you start moving north and then after say, 100 ticks, you move east, the server might receive the first command(north) late and the second command(east) on time, which would put that player out of sync in the server until they stop and then they will snap to the correct position. The snapping isn't an issue as much as the player getting very much out of sync if they do not stop every once and a while.
My question is, how can I let the server know when the packet should be processed? I know I need to hold on to a command for a certain amount of time to let other commands come in to provide a smooth simulation, like when YouTube videos buffer. But I don't how the server will know for certain when a command was sent relative to the other commands.
The only solution I've heard of is to attach a "tick number" to each command and that way the server will know how many ticks are in between each command. But how would I handle a packet that comes late? Say you send two commands with 50ms between them. But for some reason, the second packet gets lost for 500ms and your buffer is only 100ms. By the time you get that second command it would be 350ms late. It can't just forget about that command because that command could be saying to stop the character or something.
Sorry if this is a dumb question, I want to be sure that my networking code is halfway decent before I code any further and inevitably run into a slew of bugs. I've heard WoW uses TCP and does just fine. If anyone has a link that explains how they do it, I would love that. Gaffer is awesome, but there's not enough about TCP that I've seen.