Skip to content

Commit

Permalink
Allow script runtime to create authoritative matches for matchmaker. (h…
Browse files Browse the repository at this point in the history
  • Loading branch information
zyro committed Apr 26, 2018
1 parent 8a8c5b4 commit 91dc2c9
Show file tree
Hide file tree
Showing 1,380 changed files with 559,826 additions and 212 deletions.
139 changes: 138 additions & 1 deletion Gopkg.lock

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

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@
[[constraint]]
name = "github.com/cockroachdb/cockroach-go"
revision = "59c0560478b705bf9bd12f9252224a0fad7c87df"

[[constraint]]
name = "github.com/blevesearch/bleve"
version = "~0.7.0"
47 changes: 47 additions & 0 deletions data/modules/match_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,50 @@
--]]

--require("nakama").match_create("match", {debug = true})

local nk = require("nakama")

--[[
Called when the matchmaker has found a match for some set of users.
Context represents information about the match and server, for information purposes. Format:
{
env = {}, -- key-value data set in the runtime.env server configuration.
execution_mode = "Matchmaker",
}
Matchmaker users will contain a table array of the users that have matched together and their properties. Format:
{
{
presence: {
user_id: "user unique ID",
session_id: "session ID of the user's current connection",
username: "user's unique username",
node: "name of the Nakama node the user is connected to"
},
properties: {
foo: "any properties the client set when it started its matchmaking process",
baz: 1.5
}
},
...
}
Expected to return an authoritative match ID for a match ready to receive these users, or `nil` if the match should
proceed through the peer-to-peer relayed mode.
--]]
local function matchmaker_matched(context, matchmaker_users)
if #matchmaker_users ~= 2 then
return nil
end

if matchmaker_users[1].properties["mode"] ~= "authoritative" then
return nil
end
if matchmaker_users[2].properties["mode"] ~= "authoritative" then
return nil
end

return nk.match_create("match", {debug = true, expected_users = matchmaker_users})
end
nk.register_matchmaker_matched(matchmaker_matched)
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func main() {
once := &sync.Once{}

// Start up server components.
matchmaker := server.NewLocalMatchmaker(multiLogger, config.GetName())
sessionRegistry := server.NewSessionRegistry()
tracker := server.StartLocalTracker(jsonLogger, sessionRegistry, jsonpbMarshaler, config.GetName())
router := server.NewLocalMessageRouter(sessionRegistry, tracker, jsonpbMarshaler)
Expand All @@ -115,11 +116,11 @@ func main() {
multiLogger.Fatal("Failed initializing runtime modules", zap.Error(err))
}
runtimePool := server.NewRuntimePool(jsonLogger, multiLogger, db, config, socialClient, leaderboardCache, sessionRegistry, matchRegistry, tracker, router, stdLibs, modules, regCallbacks, once)
pipeline := server.NewPipeline(config, db, jsonpbMarshaler, jsonpbUnmarshaler, sessionRegistry, matchRegistry, tracker, router, runtimePool)
pipeline := server.NewPipeline(config, db, jsonpbMarshaler, jsonpbUnmarshaler, sessionRegistry, matchRegistry, matchmaker, tracker, router, runtimePool)
metrics := server.NewMetrics(multiLogger, config)

consoleServer := server.StartConsoleServer(jsonLogger, multiLogger, config, db)
apiServer := server.StartApiServer(jsonLogger, multiLogger, db, jsonpbMarshaler, jsonpbUnmarshaler, config, socialClient, leaderboardCache, sessionRegistry, matchRegistry, tracker, router, pipeline, runtimePool)
apiServer := server.StartApiServer(jsonLogger, multiLogger, db, jsonpbMarshaler, jsonpbUnmarshaler, config, socialClient, leaderboardCache, sessionRegistry, matchRegistry, matchmaker, tracker, router, pipeline, runtimePool)

gaenabled := len(os.Getenv("NAKAMA_TELEMETRY")) < 1
cookie := newOrLoadCookie(config)
Expand Down
Loading

0 comments on commit 91dc2c9

Please sign in to comment.