Commit 26094fa6 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Ensure authoritative match loggers correctly include only their own match identifier.

parent 1e0a3db2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Improve clarity of devconsole status view graph headers.
- Improve log messages from failed social provider requests.
- Improve Lua runtime function registration handling.
- Ensure authoritative match loggers correctly include only their own match identifier.

### Fixed
- Fix data returned by StreamUserList in JS runtime.
+4 −4
Original line number Diff line number Diff line
@@ -85,8 +85,8 @@ type MatchGetStateResult struct {
}

type MatchRegistry interface {
	// Create and start a new match, given a Lua module name or registered Go match function.
	CreateMatch(ctx context.Context, logger *zap.Logger, createFn RuntimeMatchCreateFunction, module string, params map[string]interface{}) (string, error)
	// Create and start a new match, given a Lua module name or registered Go or JS match function.
	CreateMatch(ctx context.Context, createFn RuntimeMatchCreateFunction, module string, params map[string]interface{}) (string, error)
	// Register and initialise a match that's ready to run.
	NewMatch(logger *zap.Logger, id uuid.UUID, core RuntimeMatchCore, stopped *atomic.Bool, params map[string]interface{}) (*MatchHandler, error)
	// Return a match by ID.
@@ -224,7 +224,7 @@ func (r *LocalMatchRegistry) processLabelUpdates(batch *index.Batch) {
	batch.Reset()
}

func (r *LocalMatchRegistry) CreateMatch(ctx context.Context, logger *zap.Logger, createFn RuntimeMatchCreateFunction, module string, params map[string]interface{}) (string, error) {
func (r *LocalMatchRegistry) CreateMatch(ctx context.Context, createFn RuntimeMatchCreateFunction, module string, params map[string]interface{}) (string, error) {
	buf := &bytes.Buffer{}
	if err := gob.NewEncoder(buf).Encode(params); err != nil {
		return "", runtime.ErrCannotEncodeParams
@@ -234,7 +234,7 @@ func (r *LocalMatchRegistry) CreateMatch(ctx context.Context, logger *zap.Logger
	}

	id := uuid.Must(uuid.NewV4())
	matchLogger := logger.With(zap.String("mid", id.String()))
	matchLogger := r.logger.With(zap.String("mid", id.String()))
	stopped := atomic.NewBool(false)

	core, err := createFn(ctx, matchLogger, id, r.node, stopped, module)
+1 −1
Original line number Diff line number Diff line
@@ -1482,7 +1482,7 @@ func (n *RuntimeGoNakamaModule) MatchCreate(ctx context.Context, module string,
	fn := n.matchCreateFn
	n.RUnlock()

	return n.matchRegistry.CreateMatch(ctx, n.logger, fn, module, params)
	return n.matchRegistry.CreateMatch(ctx, fn, module, params)
}

// @group matches
+1 −1
Original line number Diff line number Diff line
@@ -3336,7 +3336,7 @@ func (n *runtimeJavascriptNakamaModule) matchCreate(r *goja.Runtime) func(goja.F
			}
		}

		id, err := n.matchRegistry.CreateMatch(context.Background(), n.logger, n.matchCreateFn, module, paramsMap)
		id, err := n.matchRegistry.CreateMatch(context.Background(), n.matchCreateFn, module, paramsMap)
		if err != nil {
			panic(r.NewGoError(fmt.Errorf("error creating match: %s", err.Error())))
		}
+1 −1
Original line number Diff line number Diff line
@@ -4528,7 +4528,7 @@ func (n *RuntimeLuaNakamaModule) matchCreate(l *lua.LState) int {
		}
	}

	id, err := n.matchRegistry.CreateMatch(l.Context(), n.logger, n.matchCreateFn, module, paramsMap)
	id, err := n.matchRegistry.CreateMatch(l.Context(), n.matchCreateFn, module, paramsMap)
	if err != nil {
		l.RaiseError(err.Error())
		return 0