I'm thinking of creating a web multiplayer game in Node.js. This means I'll be using the same language in the backend and in the frontend. It would be in realtime and about 20 people max in each 'room', so I have a few thoughts:
How do I compensate for the delay among all users so that everyone sees the same thing the same time? I'm thinking of tracking the average ping time of each player, find the slowest one, and inform the other clients of the ms they have to be delayed each one so that everyone is as sync as possible.
I'm thinking of running the game code in the backend as well as in the frontend (since it's Javascript on both ends) and just have an error-correction mechanism to synchronize with the 'real game' in the backend. That way the game should perform smoothly on the frontend and with only few glitches when the sync happens. Also that would minimize frontend JS hacking since cheaters would be synced down to the backend game.
Should I receive player actions through the socket (keypresses), inform all other clients of the other players' actions and in the mean time 'playing' the game in the backend and send a sync to everyone of the entire game state every once in a while to sync them?
What do you think? Are there more stuff I should consider or pay attention to?
Please post any thoughts or links to documentation or articles regarding multiplayer gaming.
EDIT: These are useful:
- Gaffer on Games - Very good articles by Glenn Fiedler on multiplayer game networking and physics
- The Quake3 Networking Model