Skip to content

Commit ada0c44

Browse files
committed
Update runtime Nakama module signatures.
1 parent c981070 commit ada0c44

File tree

4 files changed

+115
-98
lines changed

4 files changed

+115
-98
lines changed

runtime/runtime.go

+47-48
Original file line numberDiff line numberDiff line change
@@ -283,24 +283,23 @@ type StorageDelete struct {
283283
}
284284

285285
type NakamaModule interface {
286-
AuthenticateCustom(id, username string, create bool) (string, string, bool, error)
287-
AuthenticateDevice(id, username string, create bool) (string, string, bool, error)
288-
AuthenticateEmail(email, password, username string, create bool) (string, string, bool, error)
289-
AuthenticateFacebook(token string, importFriends bool, username string, create bool) (string, string, bool, error)
290-
AuthenticateGameCenter(playerID, bundleID string, timestamp int64, salt, signature, publicKeyUrl, username string, create bool) (string, string, bool, error)
291-
AuthenticateGoogle(token, username string, create bool) (string, string, bool, error)
292-
AuthenticateSteam(token, username string, create bool) (string, string, bool, error)
286+
AuthenticateCustom(ctx context.Context, id, username string, create bool) (string, string, bool, error)
287+
AuthenticateDevice(ctx context.Context, id, username string, create bool) (string, string, bool, error)
288+
AuthenticateEmail(ctx context.Context, email, password, username string, create bool) (string, string, bool, error)
289+
AuthenticateFacebook(ctx context.Context, token string, importFriends bool, username string, create bool) (string, string, bool, error)
290+
AuthenticateGameCenter(ctx context.Context, playerID, bundleID string, timestamp int64, salt, signature, publicKeyUrl, username string, create bool) (string, string, bool, error)
291+
AuthenticateGoogle(ctx context.Context, token, username string, create bool) (string, string, bool, error)
292+
AuthenticateSteam(ctx context.Context, token, username string, create bool) (string, string, bool, error)
293293

294294
AuthenticateTokenGenerate(userID, username string, exp int64) (string, int64, error)
295295

296-
AccountGetId(userID string) (*api.Account, error)
297-
// TODO nullable fields?
298-
AccountUpdateId(userID, username string, metadata map[string]interface{}, displayName, timezone, location, langTag, avatarUrl string) error
296+
AccountGetId(ctx context.Context, userID string) (*api.Account, error)
297+
AccountUpdateId(ctx context.Context, userID, username string, metadata map[string]interface{}, displayName, timezone, location, langTag, avatarUrl string) error
299298

300-
UsersGetId(userIDs []string) ([]*api.User, error)
301-
UsersGetUsername(usernames []string) ([]*api.User, error)
302-
UsersBanId(userIDs []string) error
303-
UsersUnbanId(userIDs []string) error
299+
UsersGetId(ctx context.Context, userIDs []string) ([]*api.User, error)
300+
UsersGetUsername(ctx context.Context, usernames []string) ([]*api.User, error)
301+
UsersBanId(ctx context.Context, userIDs []string) error
302+
UsersUnbanId(ctx context.Context, userIDs []string) error
304303

305304
StreamUserList(mode uint8, subject, descriptor, label string, includeHidden, includeNotHidden bool) ([]Presence, error)
306305
StreamUserGet(mode uint8, subject, descriptor, label, userID, sessionID string) (PresenceMeta, error)
@@ -312,38 +311,38 @@ type NakamaModule interface {
312311
StreamSend(mode uint8, subject, descriptor, label, data string) error
313312

314313
MatchCreate(module string, params map[string]interface{}) (string, error)
315-
MatchList(limit int, authoritative bool, label string, minSize, maxSize int) []*api.Match
316-
317-
NotificationSend(userID, subject string, content map[string]interface{}, code int, sender string, persistent bool) error
318-
NotificationsSend(notifications []*NotificationSend) error
319-
320-
WalletUpdate(userID string, changeset, metadata map[string]interface{}) error
321-
WalletsUpdate(updates []*WalletUpdate) error
322-
WalletLedgerUpdate(itemID string, metadata map[string]interface{}) (WalletLedgerItem, error)
323-
WalletLedgerList(userID string) ([]WalletLedgerItem, error)
324-
325-
StorageList(userID, collection string, limit int, cursor string) ([]*api.StorageObject, string, error)
326-
StorageRead(reads []*StorageRead) ([]*api.StorageObject, error)
327-
StorageWrite(writes []*StorageWrite) ([]*api.StorageObjectAck, error)
328-
StorageDelete(deletes []*StorageDelete) error
329-
330-
LeaderboardCreate(id string, authoritative bool, sortOrder, operator, resetSchedule string, metadata map[string]interface{}) error
331-
LeaderboardDelete(id string) error
332-
LeaderboardRecordsList(id string, ownerIDs []string, limit int, cursor string, expiry int64) ([]*api.LeaderboardRecord, []*api.LeaderboardRecord, string, string, error)
333-
LeaderboardRecordWrite(id, ownerID, username string, score, subscore int64, metadata map[string]interface{}) (*api.LeaderboardRecord, error)
334-
LeaderboardRecordDelete(id, ownerID string) error
335-
336-
TournamentCreate(id string, sortOrder, operator, resetSchedule string, metadata map[string]interface{}, title, description string, category, startTime, endTime, duration, maxSize, maxNumScore int, joinRequired bool) error
337-
TournamentDelete(id string) error
338-
TournamentAddAttempt(id, ownerID string, count int) error
339-
TournamentJoin(id, ownerID, username string) error
340-
TournamentList(categoryStart, categoryEnd, startTime, endTime, limit int, cursor string) (*api.TournamentList, error)
341-
TournamentRecordWrite(id, ownerID, username string, score, subscore int64, metadata map[string]interface{}) (*api.LeaderboardRecord, error)
342-
TournamentRecordsHaystack(id, ownerID string, limit int) ([]*api.LeaderboardRecord, error)
343-
344-
GroupCreate(userID, name, creatorID, langTag, description, avatarUrl string, open bool, metadata map[string]interface{}, maxCount int) (*api.Group, error)
345-
GroupUpdate(id, name, creatorID, langTag, description, avatarUrl string, open bool, metadata map[string]interface{}, maxCount int) error
346-
GroupDelete(id string) error
347-
GroupUsersList(id string) ([]*api.GroupUserList_GroupUser, error)
348-
UserGroupsList(userID string) ([]*api.UserGroupList_UserGroup, error)
314+
MatchList(ctx context.Context, limit int, authoritative bool, label string, minSize, maxSize int) []*api.Match
315+
316+
NotificationSend(ctx context.Context, userID, subject string, content map[string]interface{}, code int, sender string, persistent bool) error
317+
NotificationsSend(ctx context.Context, notifications []*NotificationSend) error
318+
319+
WalletUpdate(ctx context.Context, userID string, changeset, metadata map[string]interface{}) error
320+
WalletsUpdate(ctx context.Context, updates []*WalletUpdate) error
321+
WalletLedgerUpdate(ctx context.Context, itemID string, metadata map[string]interface{}) (WalletLedgerItem, error)
322+
WalletLedgerList(ctx context.Context, userID string) ([]WalletLedgerItem, error)
323+
324+
StorageList(ctx context.Context, userID, collection string, limit int, cursor string) ([]*api.StorageObject, string, error)
325+
StorageRead(ctx context.Context, reads []*StorageRead) ([]*api.StorageObject, error)
326+
StorageWrite(ctx context.Context, writes []*StorageWrite) ([]*api.StorageObjectAck, error)
327+
StorageDelete(ctx context.Context, deletes []*StorageDelete) error
328+
329+
LeaderboardCreate(ctx context.Context, id string, authoritative bool, sortOrder, operator, resetSchedule string, metadata map[string]interface{}) error
330+
LeaderboardDelete(ctx context.Context, id string) error
331+
LeaderboardRecordsList(ctx context.Context, id string, ownerIDs []string, limit int, cursor string, expiry int64) ([]*api.LeaderboardRecord, []*api.LeaderboardRecord, string, string, error)
332+
LeaderboardRecordWrite(ctx context.Context, id, ownerID, username string, score, subscore int64, metadata map[string]interface{}) (*api.LeaderboardRecord, error)
333+
LeaderboardRecordDelete(ctx context.Context, id, ownerID string) error
334+
335+
TournamentCreate(ctx context.Context, id string, sortOrder, operator, resetSchedule string, metadata map[string]interface{}, title, description string, category, startTime, endTime, duration, maxSize, maxNumScore int, joinRequired bool) error
336+
TournamentDelete(ctx context.Context, id string) error
337+
TournamentAddAttempt(ctx context.Context, id, ownerID string, count int) error
338+
TournamentJoin(ctx context.Context, id, ownerID, username string) error
339+
TournamentList(ctx context.Context, categoryStart, categoryEnd, startTime, endTime, limit int, cursor string) (*api.TournamentList, error)
340+
TournamentRecordWrite(ctx context.Context, id, ownerID, username string, score, subscore int64, metadata map[string]interface{}) (*api.LeaderboardRecord, error)
341+
TournamentRecordsHaystack(ctx context.Context, id, ownerID string, limit int) ([]*api.LeaderboardRecord, error)
342+
343+
GroupCreate(ctx context.Context, userID, name, creatorID, langTag, description, avatarUrl string, open bool, metadata map[string]interface{}, maxCount int) (*api.Group, error)
344+
GroupUpdate(ctx context.Context, id, name, creatorID, langTag, description, avatarUrl string, open bool, metadata map[string]interface{}, maxCount int) error
345+
GroupDelete(ctx context.Context, id string) error
346+
GroupUsersList(ctx context.Context, id string) ([]*api.GroupUserList_GroupUser, error)
347+
UserGroupsList(ctx context.Context, userID string) ([]*api.UserGroupList_UserGroup, error)
349348
}

sample_go_module/sample.go

+23-7
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,45 @@ package main
1717
import (
1818
"context"
1919
"database/sql"
20+
"github.com/heroiclabs/nakama/api"
2021
"github.com/heroiclabs/nakama/rtapi"
2122
"github.com/heroiclabs/nakama/runtime"
2223
"log"
2324
)
2425

25-
func InitModule(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, initializer runtime.Initializer) {
26-
initializer.RegisterRpc("go_echo_sample", rpcEcho)
27-
initializer.RegisterBeforeRt("ChannelJoin", beforeChannelJoin)
28-
initializer.RegisterMatch("match", func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule) (runtime.Match, error) {
26+
func InitModule(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, initializer runtime.Initializer) error {
27+
if err := initializer.RegisterRpc("go_echo_sample", rpcEcho); err != nil {
28+
return err
29+
}
30+
if err := initializer.RegisterBeforeRt("ChannelJoin", beforeChannelJoin); err != nil {
31+
return err
32+
}
33+
if err := initializer.RegisterAfterGetAccount(afterGetAccount); err != nil {
34+
return err
35+
}
36+
if err := initializer.RegisterMatch("match", func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule) (runtime.Match, error) {
2937
return &Match{}, nil
30-
})
38+
}); err != nil {
39+
return err
40+
}
41+
return nil
3142
}
3243

33-
func rpcEcho(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error, int) {
44+
func rpcEcho(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
3445
logger.Print("RUNNING IN GO")
35-
return payload, nil, 0
46+
return payload, nil
3647
}
3748

3849
func beforeChannelJoin(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, envelope *rtapi.Envelope) (*rtapi.Envelope, error) {
3950
logger.Printf("Intercepted request to join channel '%v'", envelope.GetChannelJoin().Target)
4051
return envelope, nil
4152
}
4253

54+
func afterGetAccount(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.Account) error {
55+
logger.Printf("Intercepted response to get account '%v'", in)
56+
return nil
57+
}
58+
4359
type MatchState struct {
4460
debug bool
4561
}

server/console.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ func StartConsoleServer(logger *zap.Logger, startupLogger *zap.Logger, config Co
8787

8888
grpcGatewayRouter := mux.NewRouter()
8989

90-
grpcGatewayRouter.Handle("/", console.Handler()).Methods("GET")
91-
grpcGatewayRouter.PathPrefix("/assets/").Handler(console.Handler()).Methods("GET")
90+
grpcGatewayRouter.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) }).Methods("GET")
91+
// grpcGatewayRouter.Handle("/", console.Handler()).Methods("GET")
92+
// grpcGatewayRouter.PathPrefix("/assets/").Handler(console.Handler()).Methods("GET")
9293

9394
grpcGatewayRouter.HandleFunc("/rpcz", func(w http.ResponseWriter, r *http.Request) {
9495
zpages.Handler.ServeHTTP(w, r)

0 commit comments

Comments
 (0)