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?
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\$