Monday 19 December 2016

Spawning new Node websocket servers on demand for private game lobbies?

I'm trying to figure out the backend for a game project and would love to get some ideas, since I've never used Node beyond simple static asset servers.I assume my approach has some pretty big flaws I haven't considered, so feel free to bash it and say how it should be done instead.Here's the first part:A client connects to the master server and they are presented with a simple UI to either join an existing lobby or create a new lobby.When they create a lobby, they receive a short code and direct connect URL for sharing other clients can use for joining.This server provides the private room for players, allows them to assign nicknames, keeps track of who is the owner of the lobby and handles automatic reconnection if a client drops and comes back.This bit is fairly trivial with Socket.io and I didn't have too much trouble getting it to work. Basically I've just got an object with room codes as keys, with the connected clients listed inside and synced to everyone in the room.However, here's the part I'm struggling with:I want to present a list of games to the players, which is generated through manifest files defining the names, "cover art" and such.I'd like each of the games to be an isolated module. It provides a server that is only concerned with game state, not the overall lobby system.The game would contain a client-side application, common constants for action types and a node server to manage the state based on the actions.Ideally, the master server would just spin up a new game server that receives the participating players and updates on their connection status. The state handling and websocket communication within the game isn't the master server's business, it only knows if the clients are currently in a game that exists at some point.And thus, a couple of questions:Would it be more feasible to start a new node server for each new game and communicate it's address to the clients from the master server? (e.g. "here's your client-side files for the game and here's the endpoint for communication")Since I'd want to provide the list of players with their roles and status from the master server, would it be a bad idea to establish websocket communication between the master and game server as well?The goal here would be to provide a single system for handling rooms and connections where players in each room can switch between games, which are kinda isolated projects/processes that can define their own UI and server-side logic.Again, any ideas much appreciated. I'm a front-end guy who is mostly clueless about how a system like this should work in the first place.

Submitted December 19, 2016 at 11:13AM by Voidsheep

No comments:

Post a Comment