Match Runtime Reference
This page lists all functions exposed in the match handler Dispatcher type.
Match runtime
BroadcastMessage
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 |
---|---|---|
opCode int64 REQUIRED | Numeric message op code. | |
data []byte REQUIRED | Data as slice of bytes to be sent to the provided presences. | |
presences []runtime.Presence REQUIRED | List of presences (a subset of match participants) to use as message targets, or 'nil' to send to the whole match. | |
sender runtime.Presence REQUIRED | A presence to tag on the message as the sender, or nil. |
Returns |
---|
Name | Description |
---|---|
error error | An optional error that may indicate a problem broadcasting data to match participants. |
func (m *Match) MatchLoop(ctx context.Context, logger runtime.Logger, db *sql.DB, lg runtime.layerGModule, dispatcher runtime.MatchDispatcher, tick int64, state interface{}, messages []runtime.MatchData) interface{} {
var opCode int64 = 123
var data []byte = []byte("test")
dispatcher.BroadcastMessage(opcodeHello, b, nil, nil) // Broadcast to all match participants.
return state
}
MatchKick
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.Presence REQUIRED | A list of match participant presences to remove from the match. |
Returns |
---|
Name | Description |
---|---|
error error | An optional error that may indicate a problem kicking the selected match participants. |
func (m *Match) MatchLoop(ctx context.Context, logger runtime.Logger, db *sql.DB, lg runtime.layerGModule, dispatcher runtime.MatchDispatcher, tick int64, state interface{}, messages []runtime.MatchData) interface{} {
if tick >= 10 {
// For example we'll kick everyone that sends a message on or after tick 10.
for _, message := range messages {
// Each message implements the runtime.Presence interface to identify its sender.
dispatcher.MatchKick(message)
}
}
return state
}
MatchLabelUpdate
Sets a new label for the match.
Parameters |
---|
Name | Default | Description |
---|---|---|
label string REQUIRED | New label to set for the match. |
Returns |
---|
Name | Description |
---|---|
error error | An optional error that may indicate a problem applying the new match label. |
func (m *Match) MatchLoop(ctx context.Context, logger runtime.Logger, db *sql.DB, lg runtime.layerGModule, dispatcher runtime.MatchDispatcher, tick int64, state interface{}, messages []runtime.MatchData) interface{} {
// As an example update the match label in the 10th match tick.
if tick == 10 {
dispatcher.MatchLabelUpdate("Crossed 10 ticks!")
}
return state
}```