Loading CHANGELOG.md +2 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,8 @@ All notable changes to this project are documented below. The format is based on [keep a changelog](http://keepachangelog.com) and this project uses [semantic versioning](http://semver.org). ## [Unreleased] ### Changed - Sort match listings to show newer created matches first by default. ## [3.1.1] - 2021-02-15 ### Changed Loading server/match_registry.go +7 −2 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ type MatchIndexEntry struct { LabelString string `json:"label_string"` TickRate int `json:"tick_rate"` HandlerName string `json:"handler_name"` CreateTime int64 `json:"create_time"` } type MatchJoinResult struct { Loading @@ -95,7 +96,7 @@ type MatchRegistry interface { // Does not ensure the match process itself is no longer running, that must be handled separately. RemoveMatch(id uuid.UUID, stream PresenceStream) // Update the label entry for a given match. UpdateMatchLabel(id uuid.UUID, tickRate int, handlerName, label string) error UpdateMatchLabel(id uuid.UUID, tickRate int, handlerName, label string, createTime int64) error // List (and optionally filter) currently running matches. // This can list across both authoritative and relayed matches. ListMatches(ctx context.Context, limit int, authoritative *wrappers.BoolValue, label *wrappers.StringValue, minSize *wrappers.Int32Value, maxSize *wrappers.Int32Value, query *wrappers.StringValue) ([]*api.Match, error) Loading Loading @@ -275,7 +276,7 @@ func (r *LocalMatchRegistry) RemoveMatch(id uuid.UUID, stream PresenceStream) { } } func (r *LocalMatchRegistry) UpdateMatchLabel(id uuid.UUID, tickRate int, handlerName, label string) error { func (r *LocalMatchRegistry) UpdateMatchLabel(id uuid.UUID, tickRate int, handlerName, label string, createTime int64) error { if len(label) > MatchLabelMaxBytes { return ErrMatchLabelTooLong } Loading @@ -288,6 +289,7 @@ func (r *LocalMatchRegistry) UpdateMatchLabel(id uuid.UUID, tickRate int, handle TickRate: tickRate, HandlerName: handlerName, LabelString: label, CreateTime: createTime, }) } Loading Loading @@ -322,6 +324,7 @@ func (r *LocalMatchRegistry) ListMatches(ctx context.Context, limit int, authori } searchReq := bleve.NewSearchRequestOptions(q, count, 0, false) searchReq.Fields = []string{"label_string", "tick_rate", "handler_name"} searchReq.SortBy([]string{"-create_time"}) var err error labelResults, err = r.index.SearchInContext(ctx, searchReq) if err != nil { Loading @@ -347,6 +350,7 @@ func (r *LocalMatchRegistry) ListMatches(ctx context.Context, limit int, authori indexQuery.SetField("label_string") searchReq := bleve.NewSearchRequestOptions(indexQuery, count, 0, false) searchReq.Fields = []string{"label_string", "tick_rate", "handler_name"} searchReq.SortBy([]string{"-create_time"}) var err error labelResults, err = r.index.SearchInContext(ctx, searchReq) if err != nil { Loading @@ -366,6 +370,7 @@ func (r *LocalMatchRegistry) ListMatches(ctx context.Context, limit int, authori indexQuery := bleve.NewMatchAllQuery() searchReq := bleve.NewSearchRequestOptions(indexQuery, count, 0, false) searchReq.Fields = []string{"label_string", "tick_rate", "handler_name"} searchReq.SortBy([]string{"-create_time"}) var err error labelResults, err = r.index.SearchInContext(ctx, searchReq) if err != nil { Loading server/runtime_go_match_core.go +19 −15 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ import ( "database/sql" "errors" "fmt" "time" "github.com/gofrs/uuid" "github.com/heroiclabs/nakama-common/rtapi" "github.com/heroiclabs/nakama-common/runtime" Loading @@ -42,6 +44,7 @@ type RuntimeGoMatchCore struct { node string module string tickRate int createTime int64 stopped *atomic.Bool idStr string stream PresenceStream Loading Loading @@ -77,6 +80,7 @@ func NewRuntimeGoMatchCore(logger *zap.Logger, module string, matchRegistry Matc stopped: stopped, idStr: fmt.Sprintf("%v.%v", id.String(), node), module: module, createTime: time.Now().UTC().UnixNano() / int64(time.Millisecond), stream: PresenceStream{ Mode: StreamModeMatchAuthoritative, Subject: id, Loading Loading @@ -104,7 +108,7 @@ func (r *RuntimeGoMatchCore) MatchInit(presenceList *MatchPresenceList, deferMes } r.tickRate = tickRate if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, label); err != nil { if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, label, r.createTime); err != nil { return nil, 0, err } r.label.Store(label) Loading Loading @@ -363,7 +367,7 @@ func (r *RuntimeGoMatchCore) MatchLabelUpdate(label string) error { if r.stopped.Load() { return ErrMatchStopped } if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, label); err != nil { if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, label, r.createTime); err != nil { return fmt.Errorf("error updating match label: %v", err.Error()) } r.label.Store(label) Loading server/runtime_javascript_match_core.go +19 −15 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ import ( "encoding/json" "errors" "fmt" "time" "github.com/dop251/goja" "github.com/gofrs/uuid" "github.com/golang/protobuf/jsonpb" Loading @@ -42,6 +44,7 @@ type RuntimeJavaScriptMatchCore struct { node string module string tickRate int createTime int64 stopped *atomic.Bool idStr string stream PresenceStream Loading Loading @@ -130,6 +133,7 @@ func NewRuntimeJavascriptMatchCore(logger *zap.Logger, module string, db *sql.DB stopped: stopped, idStr: fmt.Sprintf("%v.%v", id.String(), node), module: module, createTime: time.Now().UTC().UnixNano() / int64(time.Millisecond), stream: PresenceStream{ Mode: StreamModeMatchAuthoritative, Subject: id, Loading Loading @@ -211,7 +215,7 @@ func (rm *RuntimeJavaScriptMatchCore) MatchInit(presenceList *MatchPresenceList, return nil, 0, errors.New("matchInit is expected to return an object with a 'state' property") } if err := rm.matchRegistry.UpdateMatchLabel(rm.id, rm.tickRate, rm.module, label); err != nil { if err := rm.matchRegistry.UpdateMatchLabel(rm.id, rm.tickRate, rm.module, label, rm.createTime); err != nil { return nil, 0, err } rm.label.Store(label) Loading Loading @@ -706,7 +710,7 @@ func (rm *RuntimeJavaScriptMatchCore) matchLabelUpdate(r *goja.Runtime) func(goj input := getJsString(r, f.Argument(0)) if err := rm.matchRegistry.UpdateMatchLabel(rm.id, rm.tickRate, rm.module, input); err != nil { if err := rm.matchRegistry.UpdateMatchLabel(rm.id, rm.tickRate, rm.module, input, rm.createTime); err != nil { panic(r.NewGoError(fmt.Errorf("error updating match label: %v", err.Error()))) } rm.label.Store(input) Loading server/runtime_lua_match_core.go +18 −15 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import ( "fmt" "strings" "sync" "time" "github.com/gofrs/uuid" "github.com/golang/protobuf/jsonpb" Loading @@ -44,6 +45,7 @@ type RuntimeLuaMatchCore struct { node string module string tickRate int createTime int64 stopped *atomic.Bool idStr string stream PresenceStream Loading Loading @@ -171,6 +173,7 @@ func NewRuntimeLuaMatchCore(logger *zap.Logger, module string, db *sql.DB, jsonp stopped: stopped, idStr: fmt.Sprintf("%v.%v", id.String(), node), module: module, createTime: time.Now().UTC().UnixNano() / int64(time.Millisecond), stream: PresenceStream{ Mode: StreamModeMatchAuthoritative, Subject: id, Loading Loading @@ -259,7 +262,7 @@ func (r *RuntimeLuaMatchCore) MatchInit(presenceList *MatchPresenceList, deferMe } r.vm.Pop(1) if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, labelStr); err != nil { if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, labelStr, r.createTime); err != nil { return nil, 0, err } r.label.Store(labelStr) Loading Loading @@ -846,7 +849,7 @@ func (r *RuntimeLuaMatchCore) matchLabelUpdate(l *lua.LState) int { input := l.OptString(1, "") if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, input); err != nil { if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, input, r.createTime); err != nil { l.RaiseError("error updating match label: %v", err.Error()) return 0 } Loading Loading
CHANGELOG.md +2 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,8 @@ All notable changes to this project are documented below. The format is based on [keep a changelog](http://keepachangelog.com) and this project uses [semantic versioning](http://semver.org). ## [Unreleased] ### Changed - Sort match listings to show newer created matches first by default. ## [3.1.1] - 2021-02-15 ### Changed Loading
server/match_registry.go +7 −2 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ type MatchIndexEntry struct { LabelString string `json:"label_string"` TickRate int `json:"tick_rate"` HandlerName string `json:"handler_name"` CreateTime int64 `json:"create_time"` } type MatchJoinResult struct { Loading @@ -95,7 +96,7 @@ type MatchRegistry interface { // Does not ensure the match process itself is no longer running, that must be handled separately. RemoveMatch(id uuid.UUID, stream PresenceStream) // Update the label entry for a given match. UpdateMatchLabel(id uuid.UUID, tickRate int, handlerName, label string) error UpdateMatchLabel(id uuid.UUID, tickRate int, handlerName, label string, createTime int64) error // List (and optionally filter) currently running matches. // This can list across both authoritative and relayed matches. ListMatches(ctx context.Context, limit int, authoritative *wrappers.BoolValue, label *wrappers.StringValue, minSize *wrappers.Int32Value, maxSize *wrappers.Int32Value, query *wrappers.StringValue) ([]*api.Match, error) Loading Loading @@ -275,7 +276,7 @@ func (r *LocalMatchRegistry) RemoveMatch(id uuid.UUID, stream PresenceStream) { } } func (r *LocalMatchRegistry) UpdateMatchLabel(id uuid.UUID, tickRate int, handlerName, label string) error { func (r *LocalMatchRegistry) UpdateMatchLabel(id uuid.UUID, tickRate int, handlerName, label string, createTime int64) error { if len(label) > MatchLabelMaxBytes { return ErrMatchLabelTooLong } Loading @@ -288,6 +289,7 @@ func (r *LocalMatchRegistry) UpdateMatchLabel(id uuid.UUID, tickRate int, handle TickRate: tickRate, HandlerName: handlerName, LabelString: label, CreateTime: createTime, }) } Loading Loading @@ -322,6 +324,7 @@ func (r *LocalMatchRegistry) ListMatches(ctx context.Context, limit int, authori } searchReq := bleve.NewSearchRequestOptions(q, count, 0, false) searchReq.Fields = []string{"label_string", "tick_rate", "handler_name"} searchReq.SortBy([]string{"-create_time"}) var err error labelResults, err = r.index.SearchInContext(ctx, searchReq) if err != nil { Loading @@ -347,6 +350,7 @@ func (r *LocalMatchRegistry) ListMatches(ctx context.Context, limit int, authori indexQuery.SetField("label_string") searchReq := bleve.NewSearchRequestOptions(indexQuery, count, 0, false) searchReq.Fields = []string{"label_string", "tick_rate", "handler_name"} searchReq.SortBy([]string{"-create_time"}) var err error labelResults, err = r.index.SearchInContext(ctx, searchReq) if err != nil { Loading @@ -366,6 +370,7 @@ func (r *LocalMatchRegistry) ListMatches(ctx context.Context, limit int, authori indexQuery := bleve.NewMatchAllQuery() searchReq := bleve.NewSearchRequestOptions(indexQuery, count, 0, false) searchReq.Fields = []string{"label_string", "tick_rate", "handler_name"} searchReq.SortBy([]string{"-create_time"}) var err error labelResults, err = r.index.SearchInContext(ctx, searchReq) if err != nil { Loading
server/runtime_go_match_core.go +19 −15 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ import ( "database/sql" "errors" "fmt" "time" "github.com/gofrs/uuid" "github.com/heroiclabs/nakama-common/rtapi" "github.com/heroiclabs/nakama-common/runtime" Loading @@ -42,6 +44,7 @@ type RuntimeGoMatchCore struct { node string module string tickRate int createTime int64 stopped *atomic.Bool idStr string stream PresenceStream Loading Loading @@ -77,6 +80,7 @@ func NewRuntimeGoMatchCore(logger *zap.Logger, module string, matchRegistry Matc stopped: stopped, idStr: fmt.Sprintf("%v.%v", id.String(), node), module: module, createTime: time.Now().UTC().UnixNano() / int64(time.Millisecond), stream: PresenceStream{ Mode: StreamModeMatchAuthoritative, Subject: id, Loading Loading @@ -104,7 +108,7 @@ func (r *RuntimeGoMatchCore) MatchInit(presenceList *MatchPresenceList, deferMes } r.tickRate = tickRate if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, label); err != nil { if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, label, r.createTime); err != nil { return nil, 0, err } r.label.Store(label) Loading Loading @@ -363,7 +367,7 @@ func (r *RuntimeGoMatchCore) MatchLabelUpdate(label string) error { if r.stopped.Load() { return ErrMatchStopped } if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, label); err != nil { if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, label, r.createTime); err != nil { return fmt.Errorf("error updating match label: %v", err.Error()) } r.label.Store(label) Loading
server/runtime_javascript_match_core.go +19 −15 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ import ( "encoding/json" "errors" "fmt" "time" "github.com/dop251/goja" "github.com/gofrs/uuid" "github.com/golang/protobuf/jsonpb" Loading @@ -42,6 +44,7 @@ type RuntimeJavaScriptMatchCore struct { node string module string tickRate int createTime int64 stopped *atomic.Bool idStr string stream PresenceStream Loading Loading @@ -130,6 +133,7 @@ func NewRuntimeJavascriptMatchCore(logger *zap.Logger, module string, db *sql.DB stopped: stopped, idStr: fmt.Sprintf("%v.%v", id.String(), node), module: module, createTime: time.Now().UTC().UnixNano() / int64(time.Millisecond), stream: PresenceStream{ Mode: StreamModeMatchAuthoritative, Subject: id, Loading Loading @@ -211,7 +215,7 @@ func (rm *RuntimeJavaScriptMatchCore) MatchInit(presenceList *MatchPresenceList, return nil, 0, errors.New("matchInit is expected to return an object with a 'state' property") } if err := rm.matchRegistry.UpdateMatchLabel(rm.id, rm.tickRate, rm.module, label); err != nil { if err := rm.matchRegistry.UpdateMatchLabel(rm.id, rm.tickRate, rm.module, label, rm.createTime); err != nil { return nil, 0, err } rm.label.Store(label) Loading Loading @@ -706,7 +710,7 @@ func (rm *RuntimeJavaScriptMatchCore) matchLabelUpdate(r *goja.Runtime) func(goj input := getJsString(r, f.Argument(0)) if err := rm.matchRegistry.UpdateMatchLabel(rm.id, rm.tickRate, rm.module, input); err != nil { if err := rm.matchRegistry.UpdateMatchLabel(rm.id, rm.tickRate, rm.module, input, rm.createTime); err != nil { panic(r.NewGoError(fmt.Errorf("error updating match label: %v", err.Error()))) } rm.label.Store(input) Loading
server/runtime_lua_match_core.go +18 −15 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import ( "fmt" "strings" "sync" "time" "github.com/gofrs/uuid" "github.com/golang/protobuf/jsonpb" Loading @@ -44,6 +45,7 @@ type RuntimeLuaMatchCore struct { node string module string tickRate int createTime int64 stopped *atomic.Bool idStr string stream PresenceStream Loading Loading @@ -171,6 +173,7 @@ func NewRuntimeLuaMatchCore(logger *zap.Logger, module string, db *sql.DB, jsonp stopped: stopped, idStr: fmt.Sprintf("%v.%v", id.String(), node), module: module, createTime: time.Now().UTC().UnixNano() / int64(time.Millisecond), stream: PresenceStream{ Mode: StreamModeMatchAuthoritative, Subject: id, Loading Loading @@ -259,7 +262,7 @@ func (r *RuntimeLuaMatchCore) MatchInit(presenceList *MatchPresenceList, deferMe } r.vm.Pop(1) if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, labelStr); err != nil { if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, labelStr, r.createTime); err != nil { return nil, 0, err } r.label.Store(labelStr) Loading Loading @@ -846,7 +849,7 @@ func (r *RuntimeLuaMatchCore) matchLabelUpdate(l *lua.LState) int { input := l.OptString(1, "") if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, input); err != nil { if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, input, r.createTime); err != nil { l.RaiseError("error updating match label: %v", err.Error()) return 0 } Loading