1
\$\begingroup\$

I am using socket.io and HTML 5 canvas to build a MMO game as a practice. I finished the client side first and currently I am working on server side. Apparently the position/physics update is on client side for now. But I am facing the decision of moving the position update logic and physics update to the server or leaving them on the client side. If I put the update on the server side I will pass the mousemove/keystrokes to the server. But if I update positions only on clients side I will pass the positinos/directions/speed to the server. Which approach is better in my case?

\$\endgroup\$
  • 1
    \$\begingroup\$ Possible duplicate of Should collision detection be done server-side or cooperatively between client/server? \$\endgroup\$ – Alexandre Vaillancourt Nov 24 '16 at 12:52
  • 2
    \$\begingroup\$ Never trust the client. \$\endgroup\$ – Alexandre Vaillancourt Nov 24 '16 at 12:52
  • \$\begingroup\$ @AlexandreVaillancourt Thanks the link you posted suggests a mix solution which detects the changes in the client and then verify them on the server. Does that mean sending the actual positions/directions/speeds to the server is OK? Sending these data vs sending mousemove/keystrokes have great impact on the structure of my code so I need to choose carefully. \$\endgroup\$ – newguy Nov 24 '16 at 13:02
  • 1
    \$\begingroup\$ The theory tells that the client sends the input to the server, then 'presume' what the server will return and show it to the player, and 'correct' what's displayed to the player when the answer from the server comes. It's called client side prediction. Since the server is the authority, it prevents some cheating. Take a look at this Source Multiplayer Networking article for more inspiration. \$\endgroup\$ – Alexandre Vaillancourt Nov 24 '16 at 13:08
4
\$\begingroup\$

Unless you want players to be able to teleport through walls using their browsers build-in JavaScript debugger, you will have to implement any game mechanics worth manipulating on the server.

This will lead to more noticeable lag, so you might implement it both on the client and the server. That way the client can perform the action locally so the player gets an immediate response to their input, but revert that action when the server says it failed.

\$\endgroup\$
  • \$\begingroup\$ So the game updates codes in client and server are pretty much the same except for reformatting the received data and state interpolation? \$\endgroup\$ – newguy Nov 25 '16 at 3:37
  • \$\begingroup\$ @newguy Basically yes. \$\endgroup\$ – Philipp Nov 25 '16 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.