I'm developing a simple web game for learning purposes. It's the classic tic tac toe game multiplayer. Every cell is marked with a number from 1 to 9, and to communicate it to the server (Node/Express) I use the following method
io.emit("mark", 3);
where io is a socket.io object and 3 identifies the cell on the first row and third column.
It works, but since the socket.io framework is mostly running on the client, cheating is as simple as press F12. In fact I tried to open the console and send to the server some moves, and it accepted all. How can I prevent this kind of injections? The only information which I found on the web is this Stack Overflow question, but it deals only with the authentication security and not with generic requests, so it didn't help me. The only idea that came in my mind is to see if the command received from the server is coherent with the context of the game. Actually it can fit with these simple games. But how should I treat more complex applications? And how can I prevent that some ill-disposed person send thousands of requests, with the risk of server crashing?
Thank you