Loading data/modules/clientrpc.lua +9 −9 Original line number Diff line number Diff line Loading @@ -42,12 +42,12 @@ local function send_notification(context, payload) local decoded = nk.json_decode(payload) local new_notifications = { { Code = 1, Content = { reward_coins = 1000 }, Persistent = true, SenderId = context.UserId, Subject = "You've unlocked level 100!", UserId = decoded.user_id code = 1, content = { reward_coins = 1000 }, persistent = true, sender_id = context.user_id, subject = "You've unlocked level 100!", user_id = decoded.user_id } } nk.notifications_send(new_notifications) Loading @@ -56,10 +56,10 @@ nk.register_rpc(send_notification, "clientrpc.send_notification") local function send_stream_data(context, payload) local stream = { Mode = 20, Label = "Stream Data Test", mode = 20, label = "Stream Data Test", } nk.stream_user_join(context.UserId, context.SessionId, stream, false, false) nk.stream_user_join(context.user_id, context.session_id, stream, false, false) nk.stream_send(stream, tostring(payload)) end nk.register_rpc(send_stream_data, "clientrpc.send_stream_data") Loading data/modules/match.lua +39 −39 Original line number Diff line number Diff line Loading @@ -21,10 +21,10 @@ Called when a match is created as a result of nk.match_create(). Context represents information about the match and server, for information purposes. Format: { Env = {}, -- key-value data set in the runtime.env server configuration. ExecutionMode = "Match", MatchId = "client-friendly match ID, can be shared with clients and used in match join operations", MatchNode = "name of the Nakama node hosting this match" env = {}, -- key-value data set in the runtime.env server configuration. execution_mode = "Match", match_id = "client-friendly match ID, can be shared with clients and used in match join operations", match_node = "name of the Nakama node hosting this match" } Params is the optional arbitrary second argument passed to `nk.match_create()`, or `nil` if none was used. Loading Loading @@ -52,12 +52,12 @@ Called when a user attempts to join the match using the client's match join oper Context represents information about the match and server, for information purposes. Format: { Env = {}, -- key-value data set in the runtime.env server configuration. ExecutionMode = "Match", MatchId = "client-friendly match ID, can be shared with clients and used in match join operations", MatchNode = "name of the Nakama node hosting this match", MatchLabel = "the label string returned from match_init", MatchTickrate = 1 -- the tick rate returned by match_init env = {}, -- key-value data set in the runtime.env server configuration. execution_mode = "Match", match_id = "client-friendly match ID, can be shared with clients and used in match join operations", match_node = "name of the Nakama node hosting this match", match_label = "the label string returned from match_init", match_tick_rate = 1 -- the tick rate returned by match_init } Dispatcher exposes useful functions to the match. Format: Loading @@ -78,10 +78,10 @@ State is the current in-memory match state, may be any Lua term except nil. Presence is the user attempting to join the match. Format: { UserId: "user unique ID", SessionId: "session ID of the user's current connection", Username: "user's unique username", Node: "name of the Nakama node the user is connected to" 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" } Expected return these values (all required) in order: Loading @@ -100,12 +100,12 @@ Called when one or more users have left the match for any reason, including conn Context represents information about the match and server, for information purposes. Format: { Env = {}, -- key-value data set in the runtime.env server configuration. ExecutionMode = "Match", MatchId = "client-friendly match ID, can be shared with clients and used in match join operations", MatchNode = "name of the Nakama node hosting this match", MatchLabel = "the label string returned from match_init", MatchTickrate = 1 -- the tick rate returned by match_init env = {}, -- key-value data set in the runtime.env server configuration. execution_mode = "Match", match_id = "client-friendly match ID, can be shared with clients and used in match join operations", match_node = "name of the Nakama node hosting this match", match_label = "the label string returned from match_init", match_tick_rate = 1 -- the tick rate returned by match_init } Dispatcher exposes useful functions to the match. Format: Loading @@ -127,10 +127,10 @@ State is the current in-memory match state, may be any Lua term except nil. Presences is a list of users that have left the match. Format: { { UserId: "user unique ID", SessionId: "session ID of the user's current connection", Username: "user's unique username", Node: "name of the Nakama node the user is connected to" 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" }, ... } Loading @@ -150,12 +150,12 @@ Called on an interval based on the tick rate returned by match_init. Context represents information about the match and server, for information purposes. Format: { Env = {}, -- key-value data set in the runtime.env server configuration. ExecutionMode = "Match", MatchId = "client-friendly match ID, can be shared with clients and used in match join operations", MatchNode = "name of the Nakama node hosting this match", MatchLabel = "the label string returned from match_init", MatchTickrate = 1 -- the tick rate returned by match_init env = {}, -- key-value data set in the runtime.env server configuration. executionMode = "Match", match_id = "client-friendly match ID, can be shared with clients and used in match join operations", match_node = "name of the Nakama node hosting this match", match_label = "the label string returned from match_init", match_tick_rate = 1 -- the tick rate returned by match_init } Dispatcher exposes useful functions to the match. Format: Loading @@ -177,14 +177,14 @@ State is the current in-memory match state, may be any Lua term except nil. Messages is a list of data messages received from users between the previous and current ticks. Format: { { Sender = { UserId: "user unique ID", SessionId: "session ID of the user's current connection", Username: "user's unique username", Node: "name of the Nakama node the user is connected to" sender = { 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" }, OpCode = 1, -- numeric op code set by the sender. Data = "any string data set by the sender" -- may be nil. op_code = 1, -- numeric op code set by the sender. data = "any string data set by the sender" -- may be nil. }, ... } Loading @@ -194,8 +194,8 @@ Expected return these values (all required) in order: --]] local function match_loop(context, dispatcher, tick, state, messages) if state.debug then print("match " .. context.MatchId .. " tick " .. tick) print("match " .. context.MatchId .. " messages:\n" .. du.print_r(messages)) print("match " .. context.match_id .. " tick " .. tick) print("match " .. context.match_id .. " messages:\n" .. du.print_r(messages)) end if tick < 180 then return state Loading data/modules/match_init.lua +1 −1 Original line number Diff line number Diff line Loading @@ -14,4 +14,4 @@ limitations under the License. --]] --require("nakama").match_create("match", {debug = true}) require("nakama").match_create("match", {debug = true}) server/api_authenticate.go +1 −1 Original line number Diff line number Diff line Loading @@ -154,7 +154,7 @@ func (s *ApiServer) AuthenticateFacebook(ctx context.Context, in *api.Authentica // Import friends if requested. if in.Import == nil || in.Import.Value { importFacebookFriends(s.logger, s.db, s.socialClient, uuid.FromStringOrNil(dbUserID), dbUsername, in.Account.Token) importFacebookFriends(s.logger, s.db, s.socialClient, uuid.FromStringOrNil(dbUserID), dbUsername, in.Account.Token, false) } token := generateToken(s.config, dbUserID, dbUsername) Loading server/api_friend.go +11 −1 Original line number Diff line number Diff line Loading @@ -166,5 +166,15 @@ func (s *ApiServer) BlockFriends(ctx context.Context, in *api.BlockFriendsReques } func (s *ApiServer) ImportFacebookFriends(ctx context.Context, in *api.ImportFacebookFriendsRequest) (*empty.Empty, error) { return nil, nil if in.Account == nil || in.Account.Token == "" { return nil, status.Error(codes.InvalidArgument, "Facebook token is required.") } err := importFacebookFriends(s.logger, s.db, s.socialClient, ctx.Value(ctxUserIDKey{}).(uuid.UUID), ctx.Value(ctxUsernameKey{}).(string), in.Account.Token, in.Reset_ != nil && in.Reset_.Value) if err != nil { // Already logged inside the core importFacebookFriends function. return nil, err } return &empty.Empty{}, nil } Loading
data/modules/clientrpc.lua +9 −9 Original line number Diff line number Diff line Loading @@ -42,12 +42,12 @@ local function send_notification(context, payload) local decoded = nk.json_decode(payload) local new_notifications = { { Code = 1, Content = { reward_coins = 1000 }, Persistent = true, SenderId = context.UserId, Subject = "You've unlocked level 100!", UserId = decoded.user_id code = 1, content = { reward_coins = 1000 }, persistent = true, sender_id = context.user_id, subject = "You've unlocked level 100!", user_id = decoded.user_id } } nk.notifications_send(new_notifications) Loading @@ -56,10 +56,10 @@ nk.register_rpc(send_notification, "clientrpc.send_notification") local function send_stream_data(context, payload) local stream = { Mode = 20, Label = "Stream Data Test", mode = 20, label = "Stream Data Test", } nk.stream_user_join(context.UserId, context.SessionId, stream, false, false) nk.stream_user_join(context.user_id, context.session_id, stream, false, false) nk.stream_send(stream, tostring(payload)) end nk.register_rpc(send_stream_data, "clientrpc.send_stream_data") Loading
data/modules/match.lua +39 −39 Original line number Diff line number Diff line Loading @@ -21,10 +21,10 @@ Called when a match is created as a result of nk.match_create(). Context represents information about the match and server, for information purposes. Format: { Env = {}, -- key-value data set in the runtime.env server configuration. ExecutionMode = "Match", MatchId = "client-friendly match ID, can be shared with clients and used in match join operations", MatchNode = "name of the Nakama node hosting this match" env = {}, -- key-value data set in the runtime.env server configuration. execution_mode = "Match", match_id = "client-friendly match ID, can be shared with clients and used in match join operations", match_node = "name of the Nakama node hosting this match" } Params is the optional arbitrary second argument passed to `nk.match_create()`, or `nil` if none was used. Loading Loading @@ -52,12 +52,12 @@ Called when a user attempts to join the match using the client's match join oper Context represents information about the match and server, for information purposes. Format: { Env = {}, -- key-value data set in the runtime.env server configuration. ExecutionMode = "Match", MatchId = "client-friendly match ID, can be shared with clients and used in match join operations", MatchNode = "name of the Nakama node hosting this match", MatchLabel = "the label string returned from match_init", MatchTickrate = 1 -- the tick rate returned by match_init env = {}, -- key-value data set in the runtime.env server configuration. execution_mode = "Match", match_id = "client-friendly match ID, can be shared with clients and used in match join operations", match_node = "name of the Nakama node hosting this match", match_label = "the label string returned from match_init", match_tick_rate = 1 -- the tick rate returned by match_init } Dispatcher exposes useful functions to the match. Format: Loading @@ -78,10 +78,10 @@ State is the current in-memory match state, may be any Lua term except nil. Presence is the user attempting to join the match. Format: { UserId: "user unique ID", SessionId: "session ID of the user's current connection", Username: "user's unique username", Node: "name of the Nakama node the user is connected to" 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" } Expected return these values (all required) in order: Loading @@ -100,12 +100,12 @@ Called when one or more users have left the match for any reason, including conn Context represents information about the match and server, for information purposes. Format: { Env = {}, -- key-value data set in the runtime.env server configuration. ExecutionMode = "Match", MatchId = "client-friendly match ID, can be shared with clients and used in match join operations", MatchNode = "name of the Nakama node hosting this match", MatchLabel = "the label string returned from match_init", MatchTickrate = 1 -- the tick rate returned by match_init env = {}, -- key-value data set in the runtime.env server configuration. execution_mode = "Match", match_id = "client-friendly match ID, can be shared with clients and used in match join operations", match_node = "name of the Nakama node hosting this match", match_label = "the label string returned from match_init", match_tick_rate = 1 -- the tick rate returned by match_init } Dispatcher exposes useful functions to the match. Format: Loading @@ -127,10 +127,10 @@ State is the current in-memory match state, may be any Lua term except nil. Presences is a list of users that have left the match. Format: { { UserId: "user unique ID", SessionId: "session ID of the user's current connection", Username: "user's unique username", Node: "name of the Nakama node the user is connected to" 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" }, ... } Loading @@ -150,12 +150,12 @@ Called on an interval based on the tick rate returned by match_init. Context represents information about the match and server, for information purposes. Format: { Env = {}, -- key-value data set in the runtime.env server configuration. ExecutionMode = "Match", MatchId = "client-friendly match ID, can be shared with clients and used in match join operations", MatchNode = "name of the Nakama node hosting this match", MatchLabel = "the label string returned from match_init", MatchTickrate = 1 -- the tick rate returned by match_init env = {}, -- key-value data set in the runtime.env server configuration. executionMode = "Match", match_id = "client-friendly match ID, can be shared with clients and used in match join operations", match_node = "name of the Nakama node hosting this match", match_label = "the label string returned from match_init", match_tick_rate = 1 -- the tick rate returned by match_init } Dispatcher exposes useful functions to the match. Format: Loading @@ -177,14 +177,14 @@ State is the current in-memory match state, may be any Lua term except nil. Messages is a list of data messages received from users between the previous and current ticks. Format: { { Sender = { UserId: "user unique ID", SessionId: "session ID of the user's current connection", Username: "user's unique username", Node: "name of the Nakama node the user is connected to" sender = { 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" }, OpCode = 1, -- numeric op code set by the sender. Data = "any string data set by the sender" -- may be nil. op_code = 1, -- numeric op code set by the sender. data = "any string data set by the sender" -- may be nil. }, ... } Loading @@ -194,8 +194,8 @@ Expected return these values (all required) in order: --]] local function match_loop(context, dispatcher, tick, state, messages) if state.debug then print("match " .. context.MatchId .. " tick " .. tick) print("match " .. context.MatchId .. " messages:\n" .. du.print_r(messages)) print("match " .. context.match_id .. " tick " .. tick) print("match " .. context.match_id .. " messages:\n" .. du.print_r(messages)) end if tick < 180 then return state Loading
data/modules/match_init.lua +1 −1 Original line number Diff line number Diff line Loading @@ -14,4 +14,4 @@ limitations under the License. --]] --require("nakama").match_create("match", {debug = true}) require("nakama").match_create("match", {debug = true})
server/api_authenticate.go +1 −1 Original line number Diff line number Diff line Loading @@ -154,7 +154,7 @@ func (s *ApiServer) AuthenticateFacebook(ctx context.Context, in *api.Authentica // Import friends if requested. if in.Import == nil || in.Import.Value { importFacebookFriends(s.logger, s.db, s.socialClient, uuid.FromStringOrNil(dbUserID), dbUsername, in.Account.Token) importFacebookFriends(s.logger, s.db, s.socialClient, uuid.FromStringOrNil(dbUserID), dbUsername, in.Account.Token, false) } token := generateToken(s.config, dbUserID, dbUsername) Loading
server/api_friend.go +11 −1 Original line number Diff line number Diff line Loading @@ -166,5 +166,15 @@ func (s *ApiServer) BlockFriends(ctx context.Context, in *api.BlockFriendsReques } func (s *ApiServer) ImportFacebookFriends(ctx context.Context, in *api.ImportFacebookFriendsRequest) (*empty.Empty, error) { return nil, nil if in.Account == nil || in.Account.Token == "" { return nil, status.Error(codes.InvalidArgument, "Facebook token is required.") } err := importFacebookFriends(s.logger, s.db, s.socialClient, ctx.Value(ctxUserIDKey{}).(uuid.UUID), ctx.Value(ctxUsernameKey{}).(string), in.Account.Token, in.Reset_ != nil && in.Reset_.Value) if err != nil { // Already logged inside the core importFacebookFriends function. return nil, err } return &empty.Empty{}, nil }