I'm trying to make a realtime multiplayer web-game in node.js with express framework and socket.io library. But I can't seem to make my server-side logic independent of client interactions. I want client to interact only when I (server side logic) want but I can't seem to be able to do that. For example:
I want 2 users to start playing a game. I have to first initialize the game, like set up environment, variables and stuff.. all in a separate, call it: The Game Logic. Only then can I "allow" the clients to interact.
But how am I supposed to carry on with my Game logic when my socket.on event is "calling the shots"? With socket.io you have to define triggers like
io.sockets.on('connection', function(socket) { socket.on('event', function(data) { //supposed this is fired when client hits an "interact with X" button }); } All my logic seem to be dependent on these triggers. I only wanted client to be able to fire that event when I want (after I've set up the game env etc), but defining it like so, separated from my game logic, it creates problems like how am I supposed to transfer the execution control from socket into my game logic? And even if I managed to, there's that whole client "calling the shots" problem. I then have no control when client could want to interact.
Any advice what should I do?