From cf654a65590acbf636e72d5beffbd539ea6b6723 Mon Sep 17 00:00:00 2001 From: Andrei Mihu Date: Sun, 4 Dec 2022 20:57:11 +0000 Subject: [PATCH] Ensure default parameters for tournament listings are consistent between API and runtimes. --- CHANGELOG.md | 1 + server/api_tournament.go | 4 ++-- server/runtime_javascript_nakama.go | 4 ++-- server/runtime_lua_nakama.go | 31 +++++++++++++++++++++-------- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 623042488..4f8b98833 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr - Handle Google IAP validation token caching when using credential overrides. - More graceful handling of no-op authoritative storage delete operations. - Ensure rank cache is correctly updated when joining tournaments. +- Ensure default parameters for tournament listings are consistent between API and runtimes. ## [3.14.0] - 2022-10-14 ### Added diff --git a/server/api_tournament.go b/server/api_tournament.go index 19b0f65d8..253af9379 100644 --- a/server/api_tournament.go +++ b/server/api_tournament.go @@ -214,12 +214,12 @@ func (s *ApiServer) ListTournaments(ctx context.Context, in *api.ListTournaments } // If startTime and endTime are both not set the API will only return active or future tournaments. - startTime := -1 // don't include start time in query + startTime := -1 // Don't include start time in query by default. if in.GetStartTime() != nil { startTime = int(in.GetStartTime().GetValue()) } - endTime := -1 // don't include end time in query + endTime := -1 // Don't include end time in query by default. if in.GetEndTime() != nil { endTime = int(in.GetEndTime().GetValue()) if endTime != 0 && endTime < startTime { // Allow 0 value to explicitly request tournaments with no end time set. diff --git a/server/runtime_javascript_nakama.go b/server/runtime_javascript_nakama.go index 836f264b1..94e3e4575 100644 --- a/server/runtime_javascript_nakama.go +++ b/server/runtime_javascript_nakama.go @@ -6182,7 +6182,7 @@ func (n *runtimeJavascriptNakamaModule) tournamentList(r *goja.Runtime) func(goj panic(r.NewTypeError("category end must be >= category start")) } - startTime := 0 + startTime := -1 if f.Argument(2) != goja.Undefined() && f.Argument(2) != goja.Null() { startTime = int(getJsInt(r, f.Argument(2))) if startTime < 0 { @@ -6190,7 +6190,7 @@ func (n *runtimeJavascriptNakamaModule) tournamentList(r *goja.Runtime) func(goj } } - endTime := 0 + endTime := -1 if f.Argument(3) != goja.Undefined() && f.Argument(3) != goja.Null() { endTime = int(getJsInt(r, f.Argument(3))) if endTime < 0 { diff --git a/server/runtime_lua_nakama.go b/server/runtime_lua_nakama.go index c9c1787e5..d44c7dec1 100644 --- a/server/runtime_lua_nakama.go +++ b/server/runtime_lua_nakama.go @@ -7720,15 +7720,30 @@ func (n *RuntimeLuaNakamaModule) tournamentList(l *lua.LState) int { l.ArgError(2, "categoryEnd must be >= categoryStart") return 0 } - startTime := l.OptInt(3, 0) - if startTime < 0 { - l.ArgError(3, "startTime must be >= 0") - return 0 + + startTime := -1 + if v := l.Get(3); v.Type() != lua.LTNil { + if v.Type() != lua.LTNumber { + l.ArgError(3, "startTime must be >= 0") + return 0 + } + startTime = int(lua.LVAsNumber(v)) + if startTime < 0 { + l.ArgError(3, "startTime must be >= 0") + return 0 + } } - endTime := l.OptInt(4, 0) - if endTime < 0 { - l.ArgError(4, "endTime must be >= 0") - return 0 + endTime := -1 + if v := l.Get(4); v.Type() != lua.LTNil { + if v.Type() != lua.LTNumber { + l.ArgError(4, "endTime must be >= 0") + return 0 + } + endTime = int(lua.LVAsNumber(v)) + if endTime < 0 { + l.ArgError(4, "endTime must be >= 0") + return 0 + } } if startTime > endTime { l.ArgError(4, "endTime must be >= startTime") -- GitLab