This page lists all functions for Nakama’s Server Authoritative multiplayer match handler. To register a match handler, see the match handler documentation.
Invoked when a match is created as a result of the match create function and sets up the initial state of a match. This will be called once at match start.
Parameters
Name
Default
Description
ctxnkruntime.ContextREQUIRED
The context object represents information about the match and server for information purposes.
loggernkruntime.LoggerREQUIRED
The logger allows access to log messages at variable severity.
nknkruntime.NakamaREQUIRED
Exposes runtime functions to interact with various server systems and features.
params{[key: string]: any}REQUIRED
Map of various parameters that may be sent from MatchCreate() function while creating the match. It could be list of matched users, their properties or any other relevant information that you would like to pass to the match.
Returns
Name
Description
statenkruntime.MatchState
The initial in-memory state of the match. May be any interface{} value that will store the match state as it progresses. It will be available to, and can be updated by, all match handler functions.
tickratenumber
Tick rate representing the desired number of MatchLoop() calls per second. Must be between 1 and 60, inclusive. For example a tickrate of 2 will call the match loop twice every second, which is every 500ms.
labelstring
A string label that can be used to filter matches in listing operations. Must be between 0 and 2048 characters long. This is used in match listing to filter matches.
Executed when one or more users have successfully completed the match join process after their MatchJoinAttempt() returns true. When their presences are sent to this function the users are ready to receive match data messages and can be targets for the dispatcher's BroadcastMessage() function.
Parameters
Name
Default
Description
ctxnkruntime.ContextREQUIRED
The context object represents information about the match and server for information purposes.
loggernkruntime.LoggerREQUIRED
The logger allows access to log messages at variable severity.
nknkruntime.NakamaREQUIRED
Exposes runtime functions to interact with various server systems and features.
dispatchernkruntime.MatchDispatcherREQUIRED
Exposes useful functions to the match, and may be used by the server to send messages to the participants of the match.
ticknumberREQUIRED
Tick is the current match tick number, starts at 0 and increments after every MatchLoop call. Does not increment with calls to MatchJoinAttempt, MatchJoin, or MatchLeave.
statenkruntime.MatchStateREQUIRED
Custom match state interface, use this to manage the state of your game. You may choose any structure for this interface depending on your game's needs.
presencesnkruntime.Presence[]REQUIRED
A list of presences that have successfully completed the match join process.
Returns
Name
Description
statenkruntime.MatchState
An (optionally) updated state. May be any non-null value, or null to end the match.
Executed when a user attempts to join the match using the client's match join operation. This includes any re-join request from a client after a lost connection is resumed, where client will need to explicitly re-join upon reconnection. Match join attempt can be used to prevent more players from joining after a match has started or disallow the user for any other game specific reason.
Parameters
Name
Default
Description
ctxnkruntime.ContextREQUIRED
The context object represents information about the match and server for information purposes.
loggernkruntime.LoggerREQUIRED
The logger allows access to log messages at variable severity.
nknkruntime.NakamaREQUIRED
Exposes runtime functions to interact with various server systems and features.
dispatchernkruntime.MatchDispatcherREQUIRED
Exposes useful functions to the match, and may be used by the server to send messages to the participants of the match.
ticknumberREQUIRED
Tick is the current match tick number, starts at 0 and increments after every MatchLoop call. Does not increment with calls to MatchJoinAttempt, MatchJoin, or MatchLeave.
statenkruntime.MatchStateREQUIRED
Custom match state interface, use this to manage the state of your game. You may choose any structure for this interface depending on your game's needs.
presencenkruntime.PresenceREQUIRED
A presence structure containing identifying information for the user attempting to join the match.
metadata{[key: string]: any }REQUIRED
Arbitrary key-value pairs received from the client as part of the join request.
Returns
Name
Description
statenkruntime.MatchState
An (optionally) updated state. May be any non-null value, or null to end the match.
acceptbool
True if the join attempt should be allowed, False otherwise.
rejectMessagestring
If the join attempt should be rejected, an optional string rejection reason can be returned to the client.
Executed when one or more users have left the match for any reason including connection loss.
Parameters
Name
Default
Description
ctxnkruntime.ContextREQUIRED
The context object represents information about the match and server for information purposes.
loggernkruntime.LoggerREQUIRED
The logger allows access to log messages at variable severity.
nknkruntime.NakamaREQUIRED
Exposes runtime functions to interact with various server systems and features.
dispatchernkruntime.MatchDispatcherREQUIRED
Exposes useful functions to the match, and may be used by the server to send messages to the participants of the match.
ticknumberREQUIRED
Tick is the current match tick number, starts at 0 and increments after every MatchLoop call. Does not increment with calls to MatchJoinAttempt, MatchJoin, or MatchLeave.
statenkruntime.MatchStateREQUIRED
Custom match state interface, use this to manage the state of your game. You may choose any structure for this interface depending on your game's needs.
presencesnkruntime.Presence[]REQUIRED
A list of presences that have left the match.
Returns
Name
Description
statenkruntime.MatchState
An (optionally) updated state. May be any non-null value, or null to end the match.
Executed on an interval based on the tick rate returned by MatchInit(). Each tick the match loop is run which can process messages received from clients and apply changes to the match state before the next tick. It can also dispatch messages to one or more connected match participants. To send messages back to the participants in the match you can keep track of them in the game state and use the dispatcher object to send messages to subsets of the users or all of them.
Parameters
Name
Default
Description
ctxnkruntime.ContextREQUIRED
The context object represents information about the match and server for information purposes.
loggernkruntime.LoggerREQUIRED
The logger allows access to log messages at variable severity.
nknkruntime.NakamaREQUIRED
Exposes runtime functions to interact with various server systems and features.
dispatchernkruntime.MatchDispatcherREQUIRED
Exposes useful functions to the match, and may be used by the server to send messages to the participants of the match.
ticknumberREQUIRED
Tick is the current match tick number, starts at 0 and increments after every MatchLoop call. Does not increment with calls to MatchJoinAttempt, MatchJoin, or MatchLeave.
statenkruntime.MatchStateREQUIRED
Custom match state interface, use this to manage the state of your game. You may choose any structure for this interface depending on your game's needs.
messagesnkruntime.MatchMessage[]REQUIRED
A list of data messages received from users between the previous and current tick.
Returns
Name
Description
statenkruntime.MatchState
An (optionally) updated state. May be any non-null value, or null to end the match.
Called when the match handler receives a runtime signal. Match signals allow the match handler to be sent a reservation signal to mark a user ID or session ID into the match state ahead of their join attempt and eventual join flow. This is useful to apply reservations to a matchmaking system with Nakama's matchmaker or match listings APIs.
Parameters
Name
Default
Description
ctxnkruntime.ContextREQUIRED
The context object represents information about the match and server for information purposes.
loggernkruntime.LoggerREQUIRED
The logger allows access to log messages at variable severity.
nknkruntime.NakamaREQUIRED
Exposes runtime functions to interact with various server systems and features.
dispatchernkruntime.MatchDispatcherREQUIRED
Exposes useful functions to the match, and may be used by the server to send messages to the participants of the match.
ticknumberREQUIRED
Tick is the current match tick number, starts at 0 and increments after every MatchLoop call. Does not increment with calls to MatchJoinAttempt, MatchJoin, or MatchLeave.
statenkruntime.MatchStateREQUIRED
Custom match state interface, use this to manage the state of your game. You may choose any structure for this interface depending on your game's needs.
datastringREQUIRED
An arbitrary input supplied by the runtime caller of the signal.
Returns
Name
Description
statenkruntime.MatchState
An (optionally) updated state. May be any non-null value, or null to end the match.
datastring
Arbitrary data to return to the runtime caller of the signal. May be a string or null.
1
2
3
4
5
6
7
8
constmatchSignal=function(ctx: nkruntime.Context,logger: nkruntime.Logger,nk: nkruntime.Nakama,dispatcher: nkruntime.MatchDispatcher,tick: number,state: nkruntime.MatchState,data: string):{state: nkruntime.MatchState,data?: string}|null{logger.debug('Lobby match signal received: '+data);return{state,data:"Lobby match signal received: "+data};}
Called when the server begins a graceful shutdown process. Will not be called if graceful shutdown is disabled. The match should attempt to complete any processing before the given number of seconds elapses, and optionally send a message to clients to inform them the server is shutting down. When the grace period expires the match will be forcefully closed if it is still running, clients will be disconnected, and the server will shut down.
Parameters
Name
Default
Description
ctxnkruntime.ContextREQUIRED
The context object represents information about the match and server for information purposes.
loggernkruntime.LoggerREQUIRED
The logger allows access to log messages at variable severity.
nknkruntime.NakamaREQUIRED
Exposes runtime functions to interact with various server systems and features.
dispatchernkruntime.MatchDispatcherREQUIRED
Exposes useful functions to the match, and may be used by the server to send messages to the participants of the match.
ticknumberREQUIRED
Tick is the current match tick number, starts at 0 and increments after every MatchLoop call. Does not increment with calls to MatchJoinAttempt, MatchJoin, or MatchLeave.
statenkruntime.MatchStateREQUIRED
Custom match state interface, use this to manage the state of your game. You may choose any structure for this interface depending on your game's needs.
graceSecondsnumberREQUIRED
The number of seconds provided to complete a graceful termination before a match is forcefully closed.
Returns
Name
Description
statenkruntime.MatchState
An (optionally) updated state. May be any non-null value, or null to end the match.