Comment by prezjordan

14 years ago

This is very nicely done, thanks for making it open-source - I'm learning node to work on a game idea I've had for a long time. Could someone explain the basic idea of server.js and some of the stuff in public? It's a little overwhelming.

Yea definitely, I wanted to comment this better but I was just too eager to release it hah.

The run down is this. server.js is a long running script and it only has a few global vars like games and playerQueue. These belong to the application as a whole. They're basically data structures that hold everything that's happening. Which games are being played, which players are waiting, and so on. The main stuff happens with socket.io in the io.sockets.on('connection' ... The paramter 'socket' in this code refers to the connection to a single player so if my server logic says that this player just won the game, I would say socket.emit('won-game') or in my situation I emit a 'gameover' message with some data specifying which username just won.

There's a lot more to it and I plan on getting to commenting the code better but that should point you in the right direction if you want to analyze the code.