Commit b4eb1697 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Faster handling of matches that fail init step.

parent c9acf9e5
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import (
	"go.uber.org/zap"
)

var ErrMatchInitStateNil = errors.New("Match initial state must not be nil")

type MatchDataMessage struct {
	UserID      uuid.UUID
	SessionID   uuid.UUID
@@ -131,11 +133,6 @@ func NewMatchHandler(logger *zap.Logger, config Config, sessionRegistry SessionR
		core.Cleanup()
		return nil, err
	}
	if state == nil {
		core.Cancel()
		core.Cleanup()
		return nil, errors.New("Match initial state must not be nil")
	}

	// Construct the match.
	mh := &MatchHandler{
+3 −0
Original line number Diff line number Diff line
@@ -107,6 +107,9 @@ func (r *RuntimeGoMatchCore) MatchInit(presenceList *MatchPresenceList, deferMes
		return nil, 0, errors.New("MatchInit returned invalid tick rate, must be between 1 and 60")
	}
	r.tickRate = tickRate
	if state == nil {
		return nil, 0, ErrMatchInitStateNil
	}

	if err := r.matchRegistry.UpdateMatchLabel(r.id, r.tickRate, r.module, label, r.createTime); err != nil {
		return nil, 0, err
+3 −0
Original line number Diff line number Diff line
@@ -230,6 +230,9 @@ func (rm *RuntimeJavaScriptMatchCore) MatchInit(presenceList *MatchPresenceList,
	if !ok {
		return nil, 0, errors.New("matchInit is expected to return an object with a 'state' property")
	}
	if state == nil {
		return nil, 0, ErrMatchInitStateNil
	}

	if err := rm.matchRegistry.UpdateMatchLabel(rm.id, rm.tickRate, rm.module, label, rm.createTime); err != nil {
		return nil, 0, err
+3 −0
Original line number Diff line number Diff line
@@ -261,6 +261,9 @@ func (r *RuntimeLuaMatchCore) MatchInit(presenceList *MatchPresenceList, deferMe
	if state.Type() == LTSentinel {
		return nil, 0, errors.New("match_init returned unexpected first value, must be a state")
	}
	if state.Type() == lua.LTNil {
		return nil, 0, ErrMatchInitStateNil
	}
	r.vm.Pop(1)

	// Drop the sentinel value from the stack.