title: Multiplayer game with JavaScript backend and frontend. What are the best practices?
body: <p>I'm thinking of creating a web multiplayer game in <a href="http://nodejs.org" rel="noreferrer">Node.js</a>. 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:</p>
  
  <ol>
  <li><p>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 time (in milliseconds) they have to be delayed each one so that everyone is as synchronised as possible.</p></li>
  <li><p>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 synchronisation happens. Also that would minimize frontend JavaScript hacking since cheaters would be synchronised down to the backend game.</p></li>
  <li><p>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 synchronisation information to everyone of the entire game state every once in a while to synchronise them?</p></li>
  </ol>
  
  <p>What do you think? Are there more stuff I should consider or pay attention to? </p>
  
  <p>Please post any thoughts or links to documentation or articles regarding multiplayer gaming.</p>
  
  <hr>
  
  <p>EDIT: These are useful:</p>
  
  <ul>
  <li><a href="http://gafferongames.com/" rel="noreferrer">Gaffer on Games</a> - Very good articles by Glenn Fiedler on multiplayer game networking and physics</li>
  <li><a href="http://trac.bookofhook.com/bookofhook/trac.cgi/wiki/Quake3Networking" rel="noreferrer">The Quake3 Networking Model</a></li>
  </ul>