Skip to content

Commit

Permalink
Authoritative multiplayer and match listings. (heroiclabs#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
zyro committed Apr 22, 2018
1 parent 5189ea6 commit e58b7e9
Show file tree
Hide file tree
Showing 34 changed files with 3,167 additions and 706 deletions.
605 changes: 386 additions & 219 deletions api/api.pb.go

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions api/api.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ service Nakama {
option (google.api.http).get = "/v2/friend";
}

// Fetch list of running matches.
rpc ListMatches (ListMatchesRequest) returns (MatchList) {
option (google.api.http).get = "/v2/match";
}

// Fetch list of notifications.
rpc ListNotifications (ListNotificationsRequest) returns (NotificationList) {
option (google.api.http).get = "/v2/notification";
Expand Down Expand Up @@ -685,6 +690,19 @@ message LinkFacebookRequest {
google.protobuf.BoolValue import = 4;
}

message ListMatchesRequest {
// Limit the number of returned matches.
google.protobuf.Int32Value limit = 1;
// Authoritative or relayed matches.
google.protobuf.BoolValue authoritative = 2;
// Label filter.
google.protobuf.StringValue label = 3;
// Minimum user count.
google.protobuf.Int32Value min_size = 4;
// Maximum user count.
google.protobuf.Int32Value max_size = 5;
}

// Get a list of unexpired notifications.
message ListNotificationsRequest {
// The number of notifications to get. Between 1 and 100.
Expand All @@ -705,6 +723,24 @@ message ListStorageObjectsRequest {
string cursor = 4; // value from StorageObjectList.cursor.
}

// Represents a realtime match.
message Match {
// The ID of the match, can be used to join.
string match_id = 1;
// True if it's an server-managed authoritative match, false otherwise.
bool authoritative = 2;
// Match label, if any.
google.protobuf.StringValue label = 3;
// Current number of users in the match.
int32 size = 4;
}

// A list of realtime matches.
message MatchList {
// A number of matches corresponding to a list operation.
repeated Match matches = 1;
}

// A notification in the server.
message Notification {
// ID of the Notification.
Expand Down
95 changes: 95 additions & 0 deletions api/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,64 @@
]
}
},
"/v2/match": {
"get": {
"summary": "Fetch list of running matches.",
"operationId": "ListMatches",
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/apiMatchList"
}
}
},
"parameters": [
{
"name": "limit",
"description": "Limit the number of returned matches.",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "authoritative",
"description": "Authoritative or relayed matches.",
"in": "query",
"required": false,
"type": "boolean",
"format": "boolean"
},
{
"name": "label",
"description": "Label filter.",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "min_size",
"description": "Minimum user count.",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "max_size",
"description": "Maximum user count.",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
}
],
"tags": [
"Nakama"
]
}
},
"/v2/notification": {
"get": {
"summary": "Fetch list of notifications.",
Expand Down Expand Up @@ -1379,6 +1437,43 @@
},
"description": "A collection of zero or more groups."
},
"apiMatch": {
"type": "object",
"properties": {
"match_id": {
"type": "string",
"description": "The ID of the match, can be used to join."
},
"authoritative": {
"type": "boolean",
"format": "boolean",
"description": "True if it's an server-managed authoritative match, false otherwise."
},
"label": {
"type": "string",
"description": "Match label, if any."
},
"size": {
"type": "integer",
"format": "int32",
"description": "Current number of users in the match."
}
},
"description": "Represents a realtime match."
},
"apiMatchList": {
"type": "object",
"properties": {
"matches": {
"type": "array",
"items": {
"$ref": "#/definitions/apiMatch"
},
"description": "A number of matches corresponding to a list operation."
}
},
"description": "A list of realtime matches."
},
"apiNotification": {
"type": "object",
"properties": {
Expand Down
6 changes: 6 additions & 0 deletions data/modules/clientrpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,9 @@ local function send_stream_data(context, payload)
nk.stream_send(stream, tostring(payload))
end
nk.register_rpc(send_stream_data, "clientrpc.send_stream_data")

local function create_authoritative_match(_context, _payload)
local match_id = nk.match_create("match", {})
return nk.json_encode({ match_id = match_id })
end
nk.register_rpc(create_authoritative_match, "clientrpc.create_authoritative_match")
45 changes: 45 additions & 0 deletions data/modules/debug_utils.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--[[
Copyright 2018 The Nakama Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--]]

local function print_r(arr, indentLevel)
if type(arr) ~= "table" then
return tostring(arr)
end

local str = ""
local indentStr = "#"

if(indentLevel == nil) then
return print_r(arr, 0)
end

for i = 0, indentLevel do
indentStr = indentStr.."\t"
end

for index,Value in pairs(arr) do
if type(Value) == "table" then
str = str..indentStr..index..": \n"..print_r(Value, (indentLevel + 1))
else
str = str..indentStr..index..": "..tostring(Value).."\n"
end
end
return str
end

return {
print_r = print_r
}
Loading

0 comments on commit e58b7e9

Please sign in to comment.