Send a message to one or more presences. This may be called at any point in the match loop to give match participants information about match state changes. May also be useful inside the match join callback to send initial state to the user on successful join. Note that when broadcasting to multiple presences, if any presence is invalid then the broadcast will not occur.
Parameters
Name
Default
Description
opCodeint64REQUIRED
Numeric message op code.
data[]byteREQUIRED
Data as slice of bytes to be sent to the provided presences.
presences[]runtime.PresenceREQUIRED
List of presences (a subset of match participants) to use as message targets, or 'nil' to send to the whole match.
senderruntime.PresenceREQUIRED
A presence to tag on the message as the sender, or nil.
Returns
Name
Description
errorerror
An optional error that may indicate a problem broadcasting data to match participants.
1
2
3
4
5
6
7
func(m*Match)MatchLoop(ctxcontext.Context,loggerruntime.Logger,db*sql.DB,nkruntime.NakamaModule,dispatcherruntime.MatchDispatcher,tickint64,stateinterface{},messages[]runtime.MatchData)interface{}{varopCodeint64=123vardata[]byte=[]byte("test")dispatcher.BroadcastMessage(opcodeHello,b,nil,nil)// Broadcast to all match participants.
returnstate}
Removes participants from the match. Call at any point during the match loop to remove participants based on misbehavior or other game-specific rules.
Parameters
Name
Default
Description
presences[]runtime.PresenceREQUIRED
A list of match participant presences to remove from the match.
Returns
Name
Description
errorerror
An optional error that may indicate a problem kicking the selected match participants.
1
2
3
4
5
6
7
8
9
10
11
func(m*Match)MatchLoop(ctxcontext.Context,loggerruntime.Logger,db*sql.DB,nkruntime.NakamaModule,dispatcherruntime.MatchDispatcher,tickint64,stateinterface{},messages[]runtime.MatchData)interface{}{iftick>=10{// For example we'll kick everyone that sends a message on or after tick 10.
for_,message:=rangemessages{// Each message implements the runtime.Presence interface to identify its sender.
dispatcher.MatchKick(message)}}returnstate}
An optional error that may indicate a problem applying the new match label.
1
2
3
4
5
6
7
8
func(m*Match)MatchLoop(ctxcontext.Context,loggerruntime.Logger,db*sql.DB,nkruntime.NakamaModule,dispatcherruntime.MatchDispatcher,tickint64,stateinterface{},messages[]runtime.MatchData)interface{}{// As an example update the match label in the 10th match tick.
iftick==10{dispatcher.MatchLabelUpdate("Crossed 10 ticks!")}returnstate}