diff --git a/server/match_handler.go b/server/match_handler.go index a090c165892acb9e5e1232a295d68469ba11bf25..e4038c694e99e7f13ea88696af44520a393935aa 100644 --- a/server/match_handler.go +++ b/server/match_handler.go @@ -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{ diff --git a/server/runtime_go_match_core.go b/server/runtime_go_match_core.go index b003fdaf230a696d9871642bad551c2e34a3920f..2090f5355b2b914aa24915d2ffb47aff7bca8781 100644 --- a/server/runtime_go_match_core.go +++ b/server/runtime_go_match_core.go @@ -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 diff --git a/server/runtime_javascript_match_core.go b/server/runtime_javascript_match_core.go index f27144c22b37d0b5fce2fdafb916e60dba71f23c..cf858a52dbf871968a330677f27cea6dcb0ced2e 100644 --- a/server/runtime_javascript_match_core.go +++ b/server/runtime_javascript_match_core.go @@ -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 diff --git a/server/runtime_lua_match_core.go b/server/runtime_lua_match_core.go index e068d5dd3e5a5f062188df561e6055d849789bf4..1b4389fb77cb6a9d23a5e4bbb3b772adae40a3a7 100644 --- a/server/runtime_lua_match_core.go +++ b/server/runtime_lua_match_core.go @@ -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.