I'm making a web-based action RPG game. I don't want players to cheat, but I also don't want the game to constantly pause to wait for the server to respond. I made it so the game is played on the client-side (for responsiveness) and the server does routine checking to validate the game state. But the system is very cumbersome. The server has to calculate every single frame and compare the entire game state to the game state sent from the client. If anything in the game states are different form each other, the server kicks the player off. However, this means the game has to send 30 requests a second, and the server must calculate it all in time. If many people are playing the game, I don't think my one free Heroku dyno can handle that. How do I implement an efficient and elegant way of validating players' moves on the server side?

  • \$\begingroup\$ The server does not validate the state from the client, it receives the input from the client, perform the simulation and checks (while the client 'guesses' what the server will send) and sends the state back to the client, then the client validate its own state w.r.t. what it received from the server and subtly adjusts the game objects so that the simulation looks smooth. See articles such as Source Multiplayer Networking. \$\endgroup\$
    – Vaillancourt
    Apr 17 '17 at 2:18
  • \$\begingroup\$ @AlexandreVaillancourt that is definitely the most popular design in gaming, though I would not agree other approaches, like the one in this question, to be invalid (that also doesnt it is a good idea). \$\endgroup\$
    – wondra
    Apr 17 '17 at 10:27
  • \$\begingroup\$ How big is the entire game state? \$\endgroup\$
    – wondra
    Apr 17 '17 at 10:36
  • \$\begingroup\$ Can you clarify, does your game include synchronous multiplayer, or are the frequent updates to the server solely for validating that each player is not cheating, rather than replicating player actions to other players? You can get away with even more minimal server involvement if you're not doing replication. \$\endgroup\$
    – DMGregory
    Apr 17 '17 at 12:20
  • \$\begingroup\$ However, this means the game has to send 30 requests a second, and the server must calculate it all in time.. Sounds like you're doing something terribly wrong here. Optimize your code so the client send all the data in 1 request. Do the check once every while (example every 5 min), not every second. Assume 99% of your game players are non-cheaters. If you really need to check the client state every second for every player, you should consider using "websockets" for real-time connection \$\endgroup\$
    – evilReiko
    Oct 4 '17 at 5:48