How to automatically remove empty matches?

hi.
how to automatically remove matches with no player?
is there an option in server config?
And consider that players may not be able to leave the match logically and sometimes they get disconnected

Hello @mrbug,

There’s the max_empty_sec config that will automatically close matches that are empty after the configured amount of time.

Best.

ty for your respond!
I did test that already and seems that it was for Authoritative matches not relayed types.
and also idk how to create an authoritative match. because there is no tutorial on best practice for it.

Relayed matches only exist as long as there’s players connected to the match, after the last player leaves the match ceases to exist.

There’s examples on how to create authoritative matches here.

Essentially, you need to expose a custom RPC that calls the runtime match create function from the server side or use the matchmaker.

You can see a full example in multiple languages in our project template.

Hope this helps.

1 Like

I’m using unity for developing a game.
in relayed matches if player’s application/game crash somehow(or in unity editor just press the stop button) the match doesn’t destroy and be exist in infinite time until same player join it again and then match be closed and player cannot join it anyway! that is a bug or idk maybe some one has explanation to this logic.
btw. tanks for example project. i’ll try to do it in authoritative way…

Is there a way to use relayed type matches but also have nakama runtime match code for the startup and shutdown?

I am using relayed matches but want to use the runtime to generate a key that can be used to join the match. I have this working currently with the host calling an rpc after creating the match to generate the key and save it in storage with the match id.

The problem is when everyone leaves the match the match cleans up and removes just fine but i dont have a way to remove the key from storage at the same time. If I was using authoritative i could have the key creation be part of the match init and the key removal be in the match terminate.

@ryanbbernstein it would be possible with some before and after hooks on matchCreate and matchLeave, but I think it would be more reliable to just use authoritative matches, you can mimic relayed matches by having some very simple match handlers that just forward messages to connected players, it’s very simple to implement. You can use the template shared above as an example.

Just be weary that matchTerminate may not do what you think it does, you should have some logic in your matchLoop that detects when the match should terminate itself, do the required cleanup and shut itself down by returning a null state.