Loading CHANGELOG.md +3 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,9 @@ 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 - Rejoining a match the user is already part of will now return the match label. ### Fixed - Correctly report execution mode in Lua runtime after hooks. - Use correct parameter type for creator ID in group update queries. Loading server/match_registry.go +22 −0 Original line number Diff line number Diff line Loading @@ -95,6 +95,8 @@ type MatchRegistry interface { // Remove a tracked match and ensure all its presences are cleaned up. // Does not ensure the match process itself is no longer running, that must be handled separately. RemoveMatch(id uuid.UUID, stream PresenceStream) // Get the label for a match. GetMatchLabel(ctx context.Context, id uuid.UUID, node string) (string, error) // Update the label entry for a given match. UpdateMatchLabel(id uuid.UUID, label string) error // List (and optionally filter) currently running matches. Loading Loading @@ -226,6 +228,26 @@ func (r *LocalMatchRegistry) RemoveMatch(id uuid.UUID, stream PresenceStream) { } } func (r *LocalMatchRegistry) GetMatchLabel(ctx context.Context, id uuid.UUID, node string) (string, error) { query := bleve.NewDocIDQuery([]string{fmt.Sprintf("%v.%v", id.String(), node)}) search := bleve.NewSearchRequestOptions(query, 1, 0, false) search.Fields = []string{"label_string"} results, err := r.index.SearchInContext(ctx, search) if err != nil { return "", fmt.Errorf("error getting match label: %v", err.Error()) } if results.Hits.Len() == 0 { // No such match or label is not available yet. return "", nil } label, ok := results.Hits[0].Fields["label_string"].(string) if !ok { // Label was not a string, should not happen. return "", errors.New("error getting match label: not a valid label string") } return label, nil } func (r *LocalMatchRegistry) UpdateMatchLabel(id uuid.UUID, label string) error { if len(label) > MaxLabelSize { return ErrMatchLabelTooLong Loading server/pipeline_match.go +14 −0 Original line number Diff line number Diff line Loading @@ -209,6 +209,20 @@ func (p *Pipeline) matchJoin(logger *zap.Logger, session Session, envelope *rtap return } meta = &m } else if mode == StreamModeMatchAuthoritative { // The user was already in the match, and it's an authoritative match. // Look up the match label to return it anyway. l, err := p.matchRegistry.GetMatchLabel(session.Context(), matchID, node) if err != nil { // There was a problem looking up the label. logger.Error("Error looking up match label", zap.String("match_id", matchIDString), zap.String("node", node), zap.Error(err)) session.Send(false, 0, &rtapi.Envelope{Cid: envelope.Cid, Message: &rtapi.Envelope_Error{Error: &rtapi.Error{ Code: int32(rtapi.Error_RUNTIME_EXCEPTION), Message: "Match label lookup failed.", }}}) return } label = &wrappers.StringValue{Value: l} } // Whether the user has just (successfully) joined the match or was already a member, return the match info anyway. Loading Loading
CHANGELOG.md +3 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,9 @@ 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 - Rejoining a match the user is already part of will now return the match label. ### Fixed - Correctly report execution mode in Lua runtime after hooks. - Use correct parameter type for creator ID in group update queries. Loading
server/match_registry.go +22 −0 Original line number Diff line number Diff line Loading @@ -95,6 +95,8 @@ type MatchRegistry interface { // Remove a tracked match and ensure all its presences are cleaned up. // Does not ensure the match process itself is no longer running, that must be handled separately. RemoveMatch(id uuid.UUID, stream PresenceStream) // Get the label for a match. GetMatchLabel(ctx context.Context, id uuid.UUID, node string) (string, error) // Update the label entry for a given match. UpdateMatchLabel(id uuid.UUID, label string) error // List (and optionally filter) currently running matches. Loading Loading @@ -226,6 +228,26 @@ func (r *LocalMatchRegistry) RemoveMatch(id uuid.UUID, stream PresenceStream) { } } func (r *LocalMatchRegistry) GetMatchLabel(ctx context.Context, id uuid.UUID, node string) (string, error) { query := bleve.NewDocIDQuery([]string{fmt.Sprintf("%v.%v", id.String(), node)}) search := bleve.NewSearchRequestOptions(query, 1, 0, false) search.Fields = []string{"label_string"} results, err := r.index.SearchInContext(ctx, search) if err != nil { return "", fmt.Errorf("error getting match label: %v", err.Error()) } if results.Hits.Len() == 0 { // No such match or label is not available yet. return "", nil } label, ok := results.Hits[0].Fields["label_string"].(string) if !ok { // Label was not a string, should not happen. return "", errors.New("error getting match label: not a valid label string") } return label, nil } func (r *LocalMatchRegistry) UpdateMatchLabel(id uuid.UUID, label string) error { if len(label) > MaxLabelSize { return ErrMatchLabelTooLong Loading
server/pipeline_match.go +14 −0 Original line number Diff line number Diff line Loading @@ -209,6 +209,20 @@ func (p *Pipeline) matchJoin(logger *zap.Logger, session Session, envelope *rtap return } meta = &m } else if mode == StreamModeMatchAuthoritative { // The user was already in the match, and it's an authoritative match. // Look up the match label to return it anyway. l, err := p.matchRegistry.GetMatchLabel(session.Context(), matchID, node) if err != nil { // There was a problem looking up the label. logger.Error("Error looking up match label", zap.String("match_id", matchIDString), zap.String("node", node), zap.Error(err)) session.Send(false, 0, &rtapi.Envelope{Cid: envelope.Cid, Message: &rtapi.Envelope_Error{Error: &rtapi.Error{ Code: int32(rtapi.Error_RUNTIME_EXCEPTION), Message: "Match label lookup failed.", }}}) return } label = &wrappers.StringValue{Value: l} } // Whether the user has just (successfully) joined the match or was already a member, return the match info anyway. Loading