Unverified Commit dfb4e0c3 authored by Simon Esposito's avatar Simon Esposito Committed by GitHub
Browse files

Lax leaderboard/tournament creation params (#937)

Accept operator strings in their expanded form.
Add authoritative flag to tournament get/list results.
parent ce41b152
Loading
Loading
Loading
Loading
+1 −1
Changes for go.mod: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ require (
	github.com/gorilla/mux v1.8.0
	github.com/gorilla/websocket v1.5.0
	github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3
	github.com/heroiclabs/nakama-common v1.25.0
	github.com/heroiclabs/nakama-common v1.25.1-0.20221124142234-d30d90a403a0
	github.com/jackc/pgconn v1.13.0
	github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa
	github.com/jackc/pgtype v1.12.0
+2
Changes for go.sum: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -287,6 +287,8 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/heroiclabs/nakama-common v1.25.0 h1:EtYBlUQtQCsCGEpCQQc6zAtRZMYv2yjs8fUYfpN1ROw=
github.com/heroiclabs/nakama-common v1.25.0/go.mod h1:zdYggBBPmykSfz4zYFJmBDX5wyURSPAGANtJPEDdbx8=
github.com/heroiclabs/nakama-common v1.25.1-0.20221124142234-d30d90a403a0 h1:e+TBC3Gkmn2g/a7WPPB9OSDDBcw7aC1Pyf+Lb/Ntrwg=
github.com/heroiclabs/nakama-common v1.25.1-0.20221124142234-d30d90a403a0/go.mod h1:zdYggBBPmykSfz4zYFJmBDX5wyURSPAGANtJPEDdbx8=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
+2
Changes for server/core_leaderboard.go: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ func LeaderboardList(logger *zap.Logger, leaderboardCache LeaderboardCache, cate
			NextReset:     uint32(nextReset),
			Metadata:      leaderboard.Metadata,
			CreateTime:    &timestamppb.Timestamp{Seconds: leaderboard.CreateTime},
			Authoritative: leaderboard.Authoritative,
		}
		records = append(records, record)
	}
@@ -654,6 +655,7 @@ func LeaderboardsGet(leaderboardCache LeaderboardCache, leaderboardIDs []string)
			NextReset:     uint32(nextReset),
			Metadata:      l.Metadata,
			CreateTime:    &timestamppb.Timestamp{Seconds: l.CreateTime},
			Authoritative: l.Authoritative,
		})
	}

+2
Changes for server/core_tournament.go: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -237,6 +237,7 @@ func TournamentsGet(ctx context.Context, logger *zap.Logger, db *sql.DB, leaderb
			StartTime:     &timestamppb.Timestamp{Seconds: tournament.StartTime},
			Duration:      uint32(tournament.Duration),
			StartActive:   uint32(startActive),
			Authoritative: tournament.Authoritative,
		}

		if endTime > 0 {
@@ -374,6 +375,7 @@ func TournamentList(ctx context.Context, logger *zap.Logger, db *sql.DB, leaderb
			StartTime:     &timestamppb.Timestamp{Seconds: leaderboard.StartTime},
			Duration:      uint32(leaderboard.Duration),
			StartActive:   uint32(startActive),
			Authoritative: leaderboard.Authoritative,
		}
		if leaderboard.EndTime != 0 {
			record.EndTime = &timestamppb.Timestamp{Seconds: leaderboard.EndTime}
+8 −8
Changes for server/runtime_go_nakama.go: 8 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -2182,9 +2182,9 @@ func (n *RuntimeGoNakamaModule) LeaderboardCreate(ctx context.Context, id string

	sort := LeaderboardSortOrderDescending
	switch sortOrder {
	case "desc":
	case "desc", "descending":
		sort = LeaderboardSortOrderDescending
	case "asc":
	case "asc", "ascending":
		sort = LeaderboardSortOrderAscending
	default:
		return errors.New("expects sort order to be 'asc' or 'desc'")
@@ -2196,9 +2196,9 @@ func (n *RuntimeGoNakamaModule) LeaderboardCreate(ctx context.Context, id string
		oper = LeaderboardOperatorBest
	case "set":
		oper = LeaderboardOperatorSet
	case "incr":
	case "incr", "increment":
		oper = LeaderboardOperatorIncrement
	case "decr":
	case "decr", "decrement":
		oper = LeaderboardOperatorDecrement
	default:
		return errors.New("expects operator to be 'best', 'set', 'incr' or 'decr'")
@@ -2453,9 +2453,9 @@ func (n *RuntimeGoNakamaModule) TournamentCreate(ctx context.Context, id string,

	sort := LeaderboardSortOrderDescending
	switch sortOrder {
	case "desc":
	case "desc", "descending":
		sort = LeaderboardSortOrderDescending
	case "asc":
	case "asc", "ascending":
		sort = LeaderboardSortOrderAscending
	default:
		return errors.New("expects sort order to be 'asc' or 'desc'")
@@ -2467,9 +2467,9 @@ func (n *RuntimeGoNakamaModule) TournamentCreate(ctx context.Context, id string,
		oper = LeaderboardOperatorBest
	case "set":
		oper = LeaderboardOperatorSet
	case "incr":
	case "incr", "increment":
		oper = LeaderboardOperatorIncrement
	case "decr":
	case "decr", "decrement":
		oper = LeaderboardOperatorDecrement
	default:
		return errors.New("expects sort order to be 'best', 'set', 'incr' or 'decr'")
Loading