Commit 67292354 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Allow leaderboard sorting by additional values. (#185)

parent 145a13ad
Loading
Loading
Loading
Loading
+664 −239

File changed.

Preview size limit exceeded, changes collapsed.

+194 −0
Original line number Diff line number Diff line
@@ -256,6 +256,33 @@ func request_Nakama_DeleteFriends_0(ctx context.Context, marshaler runtime.Marsh

}

func request_Nakama_DeleteLeaderboardRecord_0(ctx context.Context, marshaler runtime.Marshaler, client NakamaClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
	var protoReq DeleteLeaderboardRecordRequest
	var metadata runtime.ServerMetadata

	var (
		val string
		ok  bool
		err error
		_   = err
	)

	val, ok = pathParams["leaderboard_id"]
	if !ok {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "leaderboard_id")
	}

	protoReq.LeaderboardId, err = runtime.String(val)

	if err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "leaderboard_id", err)
	}

	msg, err := client.DeleteLeaderboardRecord(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
	return msg, metadata, err

}

var (
	filter_Nakama_DeleteNotifications_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
@@ -468,6 +495,41 @@ func request_Nakama_ListFriends_0(ctx context.Context, marshaler runtime.Marshal

}

var (
	filter_Nakama_ListLeaderboardRecords_0 = &utilities.DoubleArray{Encoding: map[string]int{"leaderboard_id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
)

func request_Nakama_ListLeaderboardRecords_0(ctx context.Context, marshaler runtime.Marshaler, client NakamaClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
	var protoReq ListLeaderboardRecordsRequest
	var metadata runtime.ServerMetadata

	var (
		val string
		ok  bool
		err error
		_   = err
	)

	val, ok = pathParams["leaderboard_id"]
	if !ok {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "leaderboard_id")
	}

	protoReq.LeaderboardId, err = runtime.String(val)

	if err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "leaderboard_id", err)
	}

	if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_Nakama_ListLeaderboardRecords_0); err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
	}

	msg, err := client.ListLeaderboardRecords(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
	return msg, metadata, err

}

var (
	filter_Nakama_ListMatches_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
@@ -794,6 +856,39 @@ func request_Nakama_UpdateAccount_0(ctx context.Context, marshaler runtime.Marsh

}

func request_Nakama_WriteLeaderboardRecord_0(ctx context.Context, marshaler runtime.Marshaler, client NakamaClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
	var protoReq WriteLeaderboardRecordRequest
	var metadata runtime.ServerMetadata

	if req.ContentLength > 0 {
		if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Record); err != nil {
			return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
		}
	}

	var (
		val string
		ok  bool
		err error
		_   = err
	)

	val, ok = pathParams["leaderboard_id"]
	if !ok {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "leaderboard_id")
	}

	protoReq.LeaderboardId, err = runtime.String(val)

	if err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "leaderboard_id", err)
	}

	msg, err := client.WriteLeaderboardRecord(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
	return msg, metadata, err

}

func request_Nakama_WriteStorageObjects_0(ctx context.Context, marshaler runtime.Marshaler, client NakamaClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
	var protoReq WriteStorageObjectsRequest
	var metadata runtime.ServerMetadata
@@ -1166,6 +1261,35 @@ func RegisterNakamaHandlerClient(ctx context.Context, mux *runtime.ServeMux, cli

	})

	mux.Handle("DELETE", pattern_Nakama_DeleteLeaderboardRecord_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
		if cn, ok := w.(http.CloseNotifier); ok {
			go func(done <-chan struct{}, closed <-chan bool) {
				select {
				case <-done:
				case <-closed:
					cancel()
				}
			}(ctx.Done(), cn.CloseNotify())
		}
		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
		rctx, err := runtime.AnnotateContext(ctx, mux, req)
		if err != nil {
			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
			return
		}
		resp, md, err := request_Nakama_DeleteLeaderboardRecord_0(rctx, inboundMarshaler, client, req, pathParams)
		ctx = runtime.NewServerMetadataContext(ctx, md)
		if err != nil {
			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
			return
		}

		forward_Nakama_DeleteLeaderboardRecord_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)

	})

	mux.Handle("DELETE", pattern_Nakama_DeleteNotifications_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
@@ -1572,6 +1696,35 @@ func RegisterNakamaHandlerClient(ctx context.Context, mux *runtime.ServeMux, cli

	})

	mux.Handle("GET", pattern_Nakama_ListLeaderboardRecords_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
		if cn, ok := w.(http.CloseNotifier); ok {
			go func(done <-chan struct{}, closed <-chan bool) {
				select {
				case <-done:
				case <-closed:
					cancel()
				}
			}(ctx.Done(), cn.CloseNotify())
		}
		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
		rctx, err := runtime.AnnotateContext(ctx, mux, req)
		if err != nil {
			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
			return
		}
		resp, md, err := request_Nakama_ListLeaderboardRecords_0(rctx, inboundMarshaler, client, req, pathParams)
		ctx = runtime.NewServerMetadataContext(ctx, md)
		if err != nil {
			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
			return
		}

		forward_Nakama_ListLeaderboardRecords_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)

	})

	mux.Handle("GET", pattern_Nakama_ListMatches_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
@@ -2007,6 +2160,35 @@ func RegisterNakamaHandlerClient(ctx context.Context, mux *runtime.ServeMux, cli

	})

	mux.Handle("POST", pattern_Nakama_WriteLeaderboardRecord_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
		if cn, ok := w.(http.CloseNotifier); ok {
			go func(done <-chan struct{}, closed <-chan bool) {
				select {
				case <-done:
				case <-closed:
					cancel()
				}
			}(ctx.Done(), cn.CloseNotify())
		}
		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
		rctx, err := runtime.AnnotateContext(ctx, mux, req)
		if err != nil {
			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
			return
		}
		resp, md, err := request_Nakama_WriteLeaderboardRecord_0(rctx, inboundMarshaler, client, req, pathParams)
		ctx = runtime.NewServerMetadataContext(ctx, md)
		if err != nil {
			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
			return
		}

		forward_Nakama_WriteLeaderboardRecord_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)

	})

	mux.Handle("PUT", pattern_Nakama_WriteStorageObjects_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
@@ -2062,6 +2244,8 @@ var (

	pattern_Nakama_DeleteFriends_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v2", "friend"}, ""))

	pattern_Nakama_DeleteLeaderboardRecord_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v2", "leaderboard", "leaderboard_id"}, ""))

	pattern_Nakama_DeleteNotifications_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v2", "notification"}, ""))

	pattern_Nakama_DeleteStorageObjects_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v2", "storage", "delete"}, ""))
@@ -2090,6 +2274,8 @@ var (

	pattern_Nakama_ListFriends_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v2", "friend"}, ""))

	pattern_Nakama_ListLeaderboardRecords_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v2", "leaderboard", "leaderboard_id"}, ""))

	pattern_Nakama_ListMatches_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v2", "match"}, ""))

	pattern_Nakama_ListNotifications_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v2", "notification"}, ""))
@@ -2120,6 +2306,8 @@ var (

	pattern_Nakama_UpdateAccount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v2", "account"}, ""))

	pattern_Nakama_WriteLeaderboardRecord_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v2", "leaderboard", "leaderboard_id"}, ""))

	pattern_Nakama_WriteStorageObjects_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v2", "storage"}, ""))
)

@@ -2146,6 +2334,8 @@ var (

	forward_Nakama_DeleteFriends_0 = runtime.ForwardResponseMessage

	forward_Nakama_DeleteLeaderboardRecord_0 = runtime.ForwardResponseMessage

	forward_Nakama_DeleteNotifications_0 = runtime.ForwardResponseMessage

	forward_Nakama_DeleteStorageObjects_0 = runtime.ForwardResponseMessage
@@ -2174,6 +2364,8 @@ var (

	forward_Nakama_ListFriends_0 = runtime.ForwardResponseMessage

	forward_Nakama_ListLeaderboardRecords_0 = runtime.ForwardResponseMessage

	forward_Nakama_ListMatches_0 = runtime.ForwardResponseMessage

	forward_Nakama_ListNotifications_0 = runtime.ForwardResponseMessage
@@ -2204,5 +2396,7 @@ var (

	forward_Nakama_UpdateAccount_0 = runtime.ForwardResponseMessage

	forward_Nakama_WriteLeaderboardRecord_0 = runtime.ForwardResponseMessage

	forward_Nakama_WriteStorageObjects_0 = runtime.ForwardResponseMessage
)
+93 −0
Original line number Diff line number Diff line
@@ -166,6 +166,11 @@ service Nakama {
    option (google.api.http).delete = "/v2/friend";
  }

  // Delete a leaderboard record.
  rpc DeleteLeaderboardRecord (DeleteLeaderboardRecordRequest) returns (google.protobuf.Empty) {
    option (google.api.http).delete = "/v2/leaderboard/{leaderboard_id}";
  }

  // Delete one or more users by ID or username.
  rpc DeleteNotifications (DeleteNotificationsRequest) returns (google.protobuf.Empty) {
    option (google.api.http).delete = "/v2/notification";
@@ -263,6 +268,11 @@ service Nakama {
    option (google.api.http).get = "/v2/friend";
  }

  // List leaderboard records
  rpc ListLeaderboardRecords (ListLeaderboardRecordsRequest) returns (LeaderboardRecordList) {
    option (google.api.http).get = "/v2/leaderboard/{leaderboard_id}";
  }

  // Fetch list of running matches.
  rpc ListMatches (ListMatchesRequest) returns (MatchList) {
    option (google.api.http).get = "/v2/match";
@@ -366,6 +376,14 @@ service Nakama {
    };
  }

  // Write a record to a leaderboard.
  rpc WriteLeaderboardRecord (WriteLeaderboardRecordRequest) returns (LeaderboardRecord) {
    option (google.api.http) = {
      post: "/v2/leaderboard/{leaderboard_id}",
      body: "record"
    };
  }

  // Write objects into the storage engine.
  rpc WriteStorageObjects (WriteStorageObjectsRequest) returns (StorageObjectAcks) {
    option (google.api.http) = {
@@ -585,6 +603,12 @@ message DeleteFriendsRequest {
  repeated string usernames = 2;
}

// Delete a leaderboard record.
message DeleteLeaderboardRecordRequest {
  // The leaderboard ID to delete from.
  string leaderboard_id = 1;
}

// Delete one or more notifications for the current user.
message DeleteNotificationsRequest {
  // The id of notifications.
@@ -685,6 +709,44 @@ message ImportFacebookFriendsRequest {
  google.protobuf.BoolValue reset = 2;
}

// Represents a complete leaderboard record with all scores and associated metadata.
message LeaderboardRecord {
  // The ID of the leaderboard this score belongs to.
  string leaderboard_id = 1;
  // The ID of the score owner, usually a user or group.
  string owner_id = 2;
  // The username of the score owner, if the owner is a user.
  google.protobuf.StringValue username = 3;
  // The score value.
  int64 score = 4;
  // An optional subscore value.
  int64 subscore = 5;
  // The number of submissions to this score record.
  int32 num_score = 6;
  // Metadata.
  string metadata = 7;
  // The UNIX time when the leaderboard record was created.
  google.protobuf.Timestamp create_time = 8;
  // The UNIX time when the leaderboard record was updated.
  google.protobuf.Timestamp update_time = 9;
  // The UNIX time when the leaderboard record expires.
  google.protobuf.Timestamp expiry_time = 10;
  // The rank of this record.
  int64 rank = 11;
}

// A set of leaderboard records, may be part of a leaderboard records page or a batch of individual records.
message LeaderboardRecordList {
  // A list of leaderboard records.
  repeated LeaderboardRecord records = 1;
  // A batched set of leaderobard records belonging to specified owners.
  repeated LeaderboardRecord owner_records = 2;
  // The cursor to send when retireving the next page, if any.
  string next_cursor = 3;
  // The cursor to send when retrieving the previous page, if any.
  string prev_cursor = 4;
}

// Link Facebook to the current user's account.
message LinkFacebookRequest {
  // The Facebook account details.
@@ -693,6 +755,19 @@ message LinkFacebookRequest {
  google.protobuf.BoolValue import = 4;
}

// List leaderboard records from a given leaderboard.
message ListLeaderboardRecordsRequest {
  // The ID of the leaderboard to list for.
  string leaderboard_id = 1;
  // One or more owners to retrieve records for.
  repeated string owner_ids = 2;
  // Max number of records to return. Between 1 and 100.
  google.protobuf.Int32Value limit = 3;
  // A next or previous page cursor.
  string cursor = 4;
}

// List realtime matches.
message ListMatchesRequest {
  // Limit the number of returned matches.
  google.protobuf.Int32Value limit = 1;
@@ -918,6 +993,24 @@ message Users {
  repeated User users = 1;
}

// A request to submit a score to a leaderboard.
message WriteLeaderboardRecordRequest {
  // Record values to write.
  message LeaderboardRecordWrite {
    // The score value to submit.
    int64 score = 1;
    // An optional secondary value.
    int64 subscore = 2;
    // Optional record metadata.
    string metadata = 3;
  }

  // The ID of the leaderboard to write to.
  string leaderboard_id = 1;
  // Record data.
  LeaderboardRecordWrite record = 2;
}

// The object to store.
message WriteStorageObject {
  // The collection to store the object.
+209 −0
Original line number Diff line number Diff line
@@ -763,6 +763,110 @@
        ]
      }
    },
    "/v2/leaderboard/{leaderboard_id}": {
      "get": {
        "summary": "List leaderboard records",
        "operationId": "ListLeaderboardRecords",
        "responses": {
          "200": {
            "description": "",
            "schema": {
              "$ref": "#/definitions/apiLeaderboardRecordList"
            }
          }
        },
        "parameters": [
          {
            "name": "leaderboard_id",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "owner_ids",
            "description": "One or more owners to retrieve records for.",
            "in": "query",
            "required": false,
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "description": "Max number of records to return. Between 1 and 100.",
            "in": "query",
            "required": false,
            "type": "integer",
            "format": "int32"
          },
          {
            "name": "cursor",
            "description": "A next or previous page cursor.",
            "in": "query",
            "required": false,
            "type": "string"
          }
        ],
        "tags": [
          "Nakama"
        ]
      },
      "delete": {
        "summary": "Delete a leaderboard record.",
        "operationId": "DeleteLeaderboardRecord",
        "responses": {
          "200": {
            "description": "",
            "schema": {
              "$ref": "#/definitions/protobufEmpty"
            }
          }
        },
        "parameters": [
          {
            "name": "leaderboard_id",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ],
        "tags": [
          "Nakama"
        ]
      },
      "post": {
        "summary": "Write a record to a leaderboard.",
        "operationId": "WriteLeaderboardRecord",
        "responses": {
          "200": {
            "description": "",
            "schema": {
              "$ref": "#/definitions/apiLeaderboardRecord"
            }
          }
        },
        "parameters": [
          {
            "name": "leaderboard_id",
            "in": "path",
            "required": true,
            "type": "string"
          },
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/WriteLeaderboardRecordRequestLeaderboardRecordWrite"
            }
          }
        ],
        "tags": [
          "Nakama"
        ]
      }
    },
    "/v2/match": {
      "get": {
        "summary": "Fetch list of running matches.",
@@ -1194,6 +1298,26 @@
      },
      "description": "A group to create."
    },
    "WriteLeaderboardRecordRequestLeaderboardRecordWrite": {
      "type": "object",
      "properties": {
        "score": {
          "type": "string",
          "format": "int64",
          "description": "The score value to submit."
        },
        "subscore": {
          "type": "string",
          "format": "int64",
          "description": "An optional secondary value."
        },
        "metadata": {
          "type": "string",
          "description": "Optional record metadata."
        }
      },
      "description": "Record values to write."
    },
    "apiAccount": {
      "type": "object",
      "properties": {
@@ -1462,6 +1586,91 @@
      },
      "description": "A collection of zero or more groups."
    },
    "apiLeaderboardRecord": {
      "type": "object",
      "properties": {
        "leaderboard_id": {
          "type": "string",
          "description": "The ID of the leaderboard this score belongs to."
        },
        "owner_id": {
          "type": "string",
          "description": "The ID of the score owner, usually a user or group."
        },
        "username": {
          "type": "string",
          "description": "The username of the score owner, if the owner is a user."
        },
        "score": {
          "type": "string",
          "format": "int64",
          "description": "The score value."
        },
        "subscore": {
          "type": "string",
          "format": "int64",
          "description": "An optional subscore value."
        },
        "num_score": {
          "type": "integer",
          "format": "int32",
          "description": "The number of submissions to this score record."
        },
        "metadata": {
          "type": "string",
          "description": "Metadata."
        },
        "create_time": {
          "type": "string",
          "format": "date-time",
          "description": "The UNIX time when the leaderboard record was created."
        },
        "update_time": {
          "type": "string",
          "format": "date-time",
          "description": "The UNIX time when the leaderboard record was updated."
        },
        "expiry_time": {
          "type": "string",
          "format": "date-time",
          "description": "The UNIX time when the leaderboard record expires."
        },
        "rank": {
          "type": "string",
          "format": "int64",
          "description": "The rank of this record."
        }
      },
      "description": "Represents a complete leaderboard record with all scores and associated metadata."
    },
    "apiLeaderboardRecordList": {
      "type": "object",
      "properties": {
        "records": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/apiLeaderboardRecord"
          },
          "description": "A list of leaderboard records."
        },
        "owner_records": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/apiLeaderboardRecord"
          },
          "description": "A batched set of leaderobard records belonging to specified owners."
        },
        "next_cursor": {
          "type": "string",
          "description": "The cursor to send when retireving the next page, if any."
        },
        "prev_cursor": {
          "type": "string",
          "description": "The cursor to send when retrieving the previous page, if any."
        }
      },
      "description": "A set of leaderboard records, may be part of a leaderboard records page or a batch of individual records."
    },
    "apiMatch": {
      "type": "object",
      "properties": {
+137 −41

File changed.

Preview size limit exceeded, changes collapsed.

Loading