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

Add TournamentRecordsList and FriendList to core (#475)

ListTournamentRecords logic moved from api to core so it can be reused.
Expose function to Go and Lua runtimes.
Fixes #470

Add friend listing function to lua runtime
Fixes #326
parent a628a294
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -8,9 +8,12 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Event contexts now contain user information for external events.
- Expose more metrics for socket activity.
- New [Docker release](https://hub.docker.com/repository/docker/heroiclabs/nakama-dsym) of the server with debug symbols enabled.
- Added `TournamentRecordsList` and `ListFriends` functions to the Go Runtime.
- Added `friends_list` and `tournament_records_list` functions to the Lua Runtime.

### Fixed
- Add missing 'rank' field from the Lua runtime `tournament_records_haystack` function results.
- Add missing cursor return values from the Go runtime `GroupUsersList` and `UsersGroupList` functions.

## [2.14.0] - 2020-10-03
### Added
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ require (
	github.com/gorilla/websocket v1.4.2
	github.com/grpc-ecosystem/grpc-gateway v1.13.0
	github.com/grpc-ecosystem/grpc-gateway/v2 v2.0.0-beta.5
	github.com/heroiclabs/nakama-common v1.8.0
	github.com/heroiclabs/nakama-common v1.8.1-0.20201023170947-267661dc1574
	github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 // indirect
	github.com/jackc/pgx v3.5.0+incompatible
	github.com/jmhodges/levigo v1.0.0 // indirect
+2 −2
+12 −27
Original line number Diff line number Diff line
@@ -113,17 +113,11 @@ func (s *ApiServer) ListTournamentRecords(ctx context.Context, in *api.ListTourn
		return nil, status.Error(codes.InvalidArgument, "Tournament ID must be provided")
	}

	tournament := s.leaderboardCache.Get(in.GetTournamentId())
	if tournament == nil {
		return nil, status.Error(codes.NotFound, "Tournament not found.")
	if len(in.GetOwnerIds()) != 0 {
		for _, ownerID := range in.OwnerIds {
			if _, err := uuid.FromString(ownerID); err != nil {
				return nil, status.Error(codes.InvalidArgument, "One or more owner IDs are invalid.")
			}

	overrideExpiry := int64(0)
	if in.Expiry != nil {
		overrideExpiry = in.Expiry.Value
	} else {
		if tournament.EndTime > 0 && tournament.EndTime <= time.Now().UTC().Unix() {
			return nil, status.Error(codes.NotFound, "Tournament not found or has ended.")
		}
	}

@@ -137,30 +131,22 @@ func (s *ApiServer) ListTournamentRecords(ctx context.Context, in *api.ListTourn
		limit = &wrappers.Int32Value{Value: 1}
	}

	if len(in.GetOwnerIds()) != 0 {
		for _, ownerID := range in.OwnerIds {
			if _, err := uuid.FromString(ownerID); err != nil {
				return nil, status.Error(codes.InvalidArgument, "One or more owner IDs are invalid.")
			}
		}
	overrideExpiry := int64(0)
	if in.Expiry != nil {
		overrideExpiry = in.Expiry.Value
	}

	records, err := LeaderboardRecordsList(ctx, s.logger, s.db, s.leaderboardCache, s.leaderboardRankCache, in.GetTournamentId(), limit, in.GetCursor(), in.GetOwnerIds(), overrideExpiry)
	if err == ErrLeaderboardNotFound {
	recordList, err := TournamentRecordsList(ctx, s.logger, s.db, s.leaderboardCache, s.leaderboardRankCache, in.GetTournamentId(), in.OwnerIds, limit, in.Cursor, overrideExpiry)
	if err == ErrTournamentNotFound {
		return nil, status.Error(codes.NotFound, "Tournament not found.")
	} else if err == ErrTournamentOutsideDuration {
		return nil, status.Error(codes.NotFound, "Tournament has ended.")
	} else if err == ErrLeaderboardInvalidCursor {
		return nil, status.Error(codes.InvalidArgument, "Cursor is invalid or expired.")
	} else if err != nil {
		return nil, status.Error(codes.Internal, "Error listing records from tournament.")
	}

	recordList := &api.TournamentRecordList{
		Records:      records.Records,
		OwnerRecords: records.OwnerRecords,
		NextCursor:   records.NextCursor,
		PrevCursor:   records.PrevCursor,
	}

	// After hook.
	if fn := s.runtime.AfterListTournamentRecords(); fn != nil {
		afterFn := func(clientIP, clientPort string) error {
@@ -172,7 +158,6 @@ func (s *ApiServer) ListTournamentRecords(ctx context.Context, in *api.ListTourn
	}

	return recordList, nil

}

func (s *ApiServer) ListTournaments(ctx context.Context, in *api.ListTournamentsRequest) (*api.TournamentList, error) {
+1 −1
Original line number Diff line number Diff line
@@ -263,7 +263,7 @@ func LeaderboardRecordsList(ctx context.Context, logger *zap.Logger, db *sql.DB,
		for rows.Next() {
			err = rows.Scan(&dbOwnerID, &dbUsername, &dbScore, &dbSubscore, &dbNumScore, &dbMaxNumScore, &dbMetadata, &dbCreateTime, &dbUpdateTime)
			if err != nil {
				_ = rows.Close()
				rows.Close()
				logger.Error("Error parsing read leaderboard records", zap.Error(err))
				return nil, err
			}
Loading