Structure of Nakama's server for a MORPG with multiple "servers"

Hello~

I am trying to wrap my head around how I should structure Nakama’s matches for my requirements.
So, let’s take this beautiful illustration of the communication (authentication) flow for the game :

image

Client A: The client sends some credentials to Nakama for authentication
Server A: Nakama answers with the session and a list of matches (servers) the user can connect to
Client B: The client chooses to connect to match Y that essentially is the same as every other match but for english speakers

Now, let’s say that, although every match is pretty much the same, I’d like to run special logic based on the match the player is connected to. For example, run some special event during September 7th only in the Brazilian match (Independence Day).

After reading through the documentation I can’t see how to make the server have different MatchHandlers because the module needs it’s functions to be at the top level and it seems they need to have specific names (matchInit, matchLoop etc.) so I can’t isolate them using classes and I can’t name the functions by server (brazilMatchInit, brazilMatchJoinAttempt etc.).

The only way I could think of doing this would be to make all the logic for each match/server inside a single function (matchLoop, for example) and inside the function itself I’d identify which match the user is connected to and then, if needed, I’d handle custom logic for that match. But doing it this way would make the server code impossible to maintain depending on how many matches and/or custom logic per match I had.

So, any tips on how to structure a server like this would be appreciated.

@Zinnavoy Hey Zinn
Your idea to have matches based on different countries, could be seen as have a matches based on xy params. In our game we have different modes, and different style of matches. To be able to do that, we have used params for match initializiation.
When match is being created you can pass params to it, let say for your Brazillian match, before that match is being created it would need to receive params for setup it for brazillian independence day:
and you could update match label, then depending on country where player is, you could filter matches for specific label and access those matches.

In Lua we have something like this:

Noticed that nk.match_create takes two params:

  • one is module name, that will be used and second are params for match initialization.
    So In your case you could either have if logic is fully different:
    BrazillianMatchHandler module and GenericMatch or if the logics are not different then just passing of the params.
1 Like