diff --git a/CHANGELOG.md b/CHANGELOG.md index 623042488ca1614a734eed1f16e840609be3a1b9..4f8b988337ddec616df0da2f3d4f30fd97e85e71 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 19b0f65d854f79b2ac838b552119c7f941de5e61..253af9379f04457b9ba8256a396a39deb0576cc6 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 836f264b1521b676ca0b790abc9e21429cc0b6f4..94e3e4575eaeac05ac1cc9cf69da99a2830d161c 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 c9c1787e5e8c4e4047371b61d7b7be1fc84f1ab3..d44c7dec18ef56856422f940f7edcdcdbfcb2cee 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")