I am trying to understand the best design approach for potentially supporting Relayed and Authoritative multi-player at the same time. The Matchmaker Documentation provides an example function (below) to load the player into a known authoritative game mode (pingpong
) in this instance.
func MakeMatch(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, entries []runtime.MatchmakerEntry) (string, error) {
for _, e := range entries {
logger.Info("Matched user '%s' named '%s'", e.GetPresence().GetUserId(), e.GetPresence().GetUsername())
for k, v := range e.GetProperties() {
logger.Info("Matched on '%s' value '%v'", k, v)
}
}
matchId, err := nk.MatchCreate(ctx, "pingpong", map[string]interface{}{"invited": entries})
if err != nil {
return "", err
}
return matchId, nil
}
// Register as matchmaker matched hook, this call should be in InitModule.
if err := initializer.RegisterMatchmakerMatched(MakeMatch); err != nil {
logger.Error("Unable to register: %v", err)
return err
}
Assuming that users correctly query for (and provide the necessary properties) to only match on a particular game mode (as an example) can I safely call nk.MatchCreate(ctx, "")
to get the default relayed implementation, otherwise calling the provided module name for a known game-mode?
An example (not great, but illustrative idea being)
func MakeMatch(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, entries []runtime.MatchmakerEntry) (string, error) {
var authoritative bool
var moduleName string = ""
for _, e := range entries {
logger.Info("Matched user '%s' named '%s'", e.GetPresence().GetUserId(), e.GetPresence().GetUsername())
for k, v := range e.GetProperties() {
logger.Info("Matched on '%s' value '%v'", k, v)
if !authoritative && v == "authed_match" {
authoritative = true
moduleName = "authed_match"
}
}
}
matchId, err := nk.MatchCreate(ctx, moduleName, nil)
if err != nil {
return "", err
}
return matchId, nil
}
The IMatch
object returned correctly specifies the authoritative flag in both scenarios, but it does have a match id for both match types. According to the Matchmaker Documentation a non-authoritative server should return a token and not a matchId
. Is this an error in the demo adapted above or my misunderstanding of the docs (or both?)
EDIT: Alternatively is this better suited to a Before hook of some kind?