How to handle lobby-based multi-matchhandler games

Hi there,
lets discuss an approach i’m currently planning. I have a game lobby where the host can change some game settings prior to starting the game. Now i want to implement a new game mode which is very different than the current one. But lets explain from the start:

I have set up my game (authoritative) with a pretty strong matchHandler class (caring about security, error handling, logging, message-relaying, saving and restoring when the server restarts, etc). Match state looks like this:

export interface ServerMatchState {
  players: { [userId: string]: Player };
  presences: { [sessionId: string]: nkruntime.Presence | null };
  lobbyCode: string;
  options: /* changable options type */
  /* ... more state properties ommited */

As you see there are “options” that may be set in the Lobby which define behaviour of game logics. Also, the Lobby is the “get together” point where users assemble, chat, etc. before the game starts.

What i’m trying to achive: Have the Lobby system the same and single entry point for players, and let the host then decide, which game mode to play.

I was thinking about registering a new match handler, but there is so much logic i probably have to duplicate then. Also the handler type has to change (which is a nakama thing i’m not sure if that is even possible mid game?).

The more managable approach in my opinion is to have the game mode defined in “options” and care from that point onward, limiting the allowed messages (op codes, so to say) and using different state properties, etc. On this side there are plenty of things to be considered and tested.

I am thinking of a third approach, which would be to ask the game-creator in advance, which type of game he wants to start, and then use different matchHandlers and have the lobby system in both.

Fourth thought: Use the party-system to set up the lobby and get people together. I’m not sure if this is good, as my lobby has a chat, relies on active connections, and already broadcasts the set options to all players, and there may be up to 100 players in a lobby.

What are your opinions? Has anybody implemented a multi-match-handler setup yet?

Hi @dela,

One option here which you alluded to as your first option is to create a new match handler exclusively for the new game mode (don’t include existing Lobby logic there).

From inside your lobby match handler, you would allow the host (or whoever has permission in your case) to modify the game options for the upcoming game etc. Once the decisions are finalised, the host could trigger a message to the lobby match handler that tells it to create a new match for the chosen game mode, passing along all relevant options as match parameters. The lobby would then broadcast this new match ID to all connected players, at which point they can all join the new match.

This new match handler would contain all of the state and logic to handle your new game mode.