-1

I am making a multiplayer card game and am using NodeJS as my server with SocketIO.

My question is how should I be managing multiple game rooms (say an n number of game rooms) ?

Currently I have it setup as the server holds a JavaScript object which will hold all the game objects.

let games: {
    “room367”: Game(),
    “room193”: Game(),
    ....
    “roomN”: Game()
};

So each time a new game is created, this happens

if (games[“room193”].exists()) {
    joinRoom();
}

Should I even have an object to hold all the game objects ? Is there a better way to go about doing this ?

2 Answers2

0

No, you probably should not hold the rooms in memory.

Try to make your apis as stateless as possible. In this case you can imagine having more than a single instance of your nodejs server, so that game requests can be load balanced across multiple servers.

Or, imagine that you have more rooms in play than you can comfortably handle on a single server.

In both situations you don't want to tie a client to a specific server. This means you will want to create the room object per request. Probably persisting it on a database, rather than holding it in memory

Ewan
  • 83,178
-2

I would recommend you to look into redis. Its a persistent data/central store. It stores the data in RAM/Memory instead of storing it on the disk like traditional DB's.