diff --git a/CHANGELOG.md b/CHANGELOG.md index 14f00acb1fd3f16381f7009f02a47aacdf82a351..f3d7cbb89778a7de887d57ec6a7e3e07793b2ce6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr - Lua runtime token generator function now returns a second value representing the token's expiry. - Add local cache for in-memory storage to the Lua runtime. - Graceful server shutdown and match termination. +- Expose incoming request data in runtime after hooks. ### Changed - Improved Postgres compatibility on TIMESTAMPTZ types. diff --git a/runtime/runtime.go b/runtime/runtime.go index ff7593737f80f4c8733db393b0bfcd6f850ed826..1f9dec4c20a80995d53cbf1243c0c0c6ecc3f975 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -19,7 +19,6 @@ import ( "database/sql" "log" - "github.com/golang/protobuf/ptypes/empty" "github.com/heroiclabs/nakama/api" "github.com/heroiclabs/nakama/rtapi" ) @@ -40,126 +39,139 @@ const ( RUNTIME_CTX_MATCH_TICK_RATE = "match_tick_rate" ) +type Error struct { + Message string + Code int +} + +func (e *Error) Error() string { + return e.Message +} + +func NewError(message string, code int) *Error { + return &Error{Message: message, Code: code} +} + type Initializer interface { - RegisterRpc(id string, fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, payload string) (string, error, int)) error + RegisterRpc(id string, fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, payload string) (string, error)) error RegisterBeforeRt(id string, fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, envelope *rtapi.Envelope) (*rtapi.Envelope, error)) error RegisterAfterRt(id string, fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, envelope *rtapi.Envelope) error) error - RegisterBeforeGetAccount(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *empty.Empty) (*empty.Empty, error, int)) error + RegisterBeforeGetAccount(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule) error) error RegisterAfterGetAccount(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Account) error) error - RegisterBeforeUpdateAccount(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.UpdateAccountRequest) (*api.UpdateAccountRequest, error, int)) error - RegisterAfterUpdateAccount(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeAuthenticateCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AuthenticateCustomRequest) (*api.AuthenticateCustomRequest, error, int)) error - RegisterAfterAuthenticateCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Session) error) error - RegisterBeforeAuthenticateDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AuthenticateDeviceRequest) (*api.AuthenticateDeviceRequest, error, int)) error - RegisterAfterAuthenticateDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Session) error) error - RegisterBeforeAuthenticateEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AuthenticateEmailRequest) (*api.AuthenticateEmailRequest, error, int)) error - RegisterAfterAuthenticateEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Session) error) error - RegisterBeforeAuthenticateFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AuthenticateFacebookRequest) (*api.AuthenticateFacebookRequest, error, int)) error - RegisterAfterAuthenticateFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Session) error) error - RegisterBeforeAuthenticateGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AuthenticateGameCenterRequest) (*api.AuthenticateGameCenterRequest, error, int)) error - RegisterAfterAuthenticateGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Session) error) error - RegisterBeforeAuthenticateGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AuthenticateGoogleRequest) (*api.AuthenticateGoogleRequest, error, int)) error - RegisterAfterAuthenticateGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Session) error) error - RegisterBeforeAuthenticateSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AuthenticateSteamRequest) (*api.AuthenticateSteamRequest, error, int)) error - RegisterAfterAuthenticateSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Session) error) error - RegisterBeforeListChannelMessages(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListChannelMessagesRequest) (*api.ListChannelMessagesRequest, error, int)) error - RegisterAfterListChannelMessages(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.ChannelMessageList) error) error - RegisterBeforeListFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *empty.Empty) (*empty.Empty, error, int)) error + RegisterBeforeUpdateAccount(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.UpdateAccountRequest) (*api.UpdateAccountRequest, error)) error + RegisterAfterUpdateAccount(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.UpdateAccountRequest) error) error + RegisterBeforeAuthenticateCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AuthenticateCustomRequest) (*api.AuthenticateCustomRequest, error)) error + RegisterAfterAuthenticateCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Session, in *api.AuthenticateCustomRequest) error) error + RegisterBeforeAuthenticateDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AuthenticateDeviceRequest) (*api.AuthenticateDeviceRequest, error)) error + RegisterAfterAuthenticateDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Session, in *api.AuthenticateDeviceRequest) error) error + RegisterBeforeAuthenticateEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AuthenticateEmailRequest) (*api.AuthenticateEmailRequest, error)) error + RegisterAfterAuthenticateEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Session, in *api.AuthenticateEmailRequest) error) error + RegisterBeforeAuthenticateFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AuthenticateFacebookRequest) (*api.AuthenticateFacebookRequest, error)) error + RegisterAfterAuthenticateFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Session, in *api.AuthenticateFacebookRequest) error) error + RegisterBeforeAuthenticateGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AuthenticateGameCenterRequest) (*api.AuthenticateGameCenterRequest, error)) error + RegisterAfterAuthenticateGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Session, in *api.AuthenticateGameCenterRequest) error) error + RegisterBeforeAuthenticateGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AuthenticateGoogleRequest) (*api.AuthenticateGoogleRequest, error)) error + RegisterAfterAuthenticateGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Session, in *api.AuthenticateGoogleRequest) error) error + RegisterBeforeAuthenticateSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AuthenticateSteamRequest) (*api.AuthenticateSteamRequest, error)) error + RegisterAfterAuthenticateSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Session, in *api.AuthenticateSteamRequest) error) error + RegisterBeforeListChannelMessages(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListChannelMessagesRequest) (*api.ListChannelMessagesRequest, error)) error + RegisterAfterListChannelMessages(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.ChannelMessageList, in *api.ListChannelMessagesRequest) error) error + RegisterBeforeListFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule) error) error RegisterAfterListFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Friends) error) error - RegisterBeforeAddFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AddFriendsRequest) (*api.AddFriendsRequest, error, int)) error - RegisterAfterAddFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeDeleteFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.DeleteFriendsRequest) (*api.DeleteFriendsRequest, error, int)) error - RegisterAfterDeleteFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeBlockFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.BlockFriendsRequest) (*api.BlockFriendsRequest, error, int)) error - RegisterAfterBlockFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeImportFacebookFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ImportFacebookFriendsRequest) (*api.ImportFacebookFriendsRequest, error, int)) error - RegisterAfterImportFacebookFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeCreateGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.CreateGroupRequest) (*api.CreateGroupRequest, error, int)) error - RegisterAfterCreateGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Group) error) error - RegisterBeforeUpdateGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.UpdateGroupRequest) (*api.UpdateGroupRequest, error, int)) error - RegisterAfterUpdateGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeDeleteGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.DeleteGroupRequest) (*api.DeleteGroupRequest, error, int)) error - RegisterAfterDeleteGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeJoinGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.JoinGroupRequest) (*api.JoinGroupRequest, error, int)) error - RegisterAfterJoinGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeLeaveGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.LeaveGroupRequest) (*api.LeaveGroupRequest, error, int)) error - RegisterAfterLeaveGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeAddGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AddGroupUsersRequest) (*api.AddGroupUsersRequest, error, int)) error - RegisterAfterAddGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeKickGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.KickGroupUsersRequest) (*api.KickGroupUsersRequest, error, int)) error - RegisterAfterKickGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforePromoteGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.PromoteGroupUsersRequest) (*api.PromoteGroupUsersRequest, error, int)) error - RegisterAfterPromoteGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeListGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListGroupUsersRequest) (*api.ListGroupUsersRequest, error, int)) error - RegisterAfterListGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.GroupUserList) error) error - RegisterBeforeListUserGroups(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListUserGroupsRequest) (*api.ListUserGroupsRequest, error, int)) error - RegisterAfterListUserGroups(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.UserGroupList) error) error - RegisterBeforeListGroups(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListGroupsRequest) (*api.ListGroupsRequest, error, int)) error - RegisterAfterListGroups(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.GroupList) error) error - RegisterBeforeDeleteLeaderboardRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.DeleteLeaderboardRecordRequest) (*api.DeleteLeaderboardRecordRequest, error, int)) error - RegisterAfterDeleteLeaderboardRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeListLeaderboardRecords(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListLeaderboardRecordsRequest) (*api.ListLeaderboardRecordsRequest, error, int)) error - RegisterAfterListLeaderboardRecords(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.LeaderboardRecordList) error) error - RegisterBeforeWriteLeaderboardRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.WriteLeaderboardRecordRequest) (*api.WriteLeaderboardRecordRequest, error, int)) error - RegisterAfterWriteLeaderboardRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.LeaderboardRecord) error) error - RegisterBeforeListLeaderboardRecordsAroundOwner(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListLeaderboardRecordsAroundOwnerRequest) (*api.ListLeaderboardRecordsAroundOwnerRequest, error, int)) error - RegisterAfterListLeaderboardRecordsAroundOwner(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.LeaderboardRecordList) error) error - RegisterBeforeLinkCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountCustom) (*api.AccountCustom, error, int)) error - RegisterAfterLinkCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeLinkDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountDevice) (*api.AccountDevice, error, int)) error - RegisterAfterLinkDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeLinkEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountEmail) (*api.AccountEmail, error, int)) error - RegisterAfterLinkEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeLinkFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.LinkFacebookRequest) (*api.LinkFacebookRequest, error, int)) error - RegisterAfterLinkFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeLinkGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountGameCenter) (*api.AccountGameCenter, error, int)) error - RegisterAfterLinkGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeLinkGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountGoogle) (*api.AccountGoogle, error, int)) error - RegisterAfterLinkGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeLinkSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountSteam) (*api.AccountSteam, error, int)) error - RegisterAfterLinkSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeListMatches(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListMatchesRequest) (*api.ListMatchesRequest, error, int)) error - RegisterAfterListMatches(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.MatchList) error) error - RegisterBeforeListNotifications(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListNotificationsRequest) (*api.ListNotificationsRequest, error, int)) error - RegisterAfterListNotifications(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.NotificationList) error) error - RegisterBeforeDeleteNotification(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.DeleteNotificationsRequest) (*api.DeleteNotificationsRequest, error, int)) error - RegisterAfterDeleteNotification(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeListStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListStorageObjectsRequest) (*api.ListStorageObjectsRequest, error, int)) error - RegisterAfterListStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.StorageObjectList) error) error - RegisterBeforeReadStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ReadStorageObjectsRequest) (*api.ReadStorageObjectsRequest, error, int)) error - RegisterAfterReadStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.StorageObjects) error) error - RegisterBeforeWriteStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.WriteStorageObjectsRequest) (*api.WriteStorageObjectsRequest, error, int)) error - RegisterAfterWriteStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.StorageObjectAcks) error) error - RegisterBeforeDeleteStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.DeleteStorageObjectsRequest) (*api.DeleteStorageObjectsRequest, error, int)) error - RegisterAfterDeleteStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeJoinTournament(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.JoinTournamentRequest) (*api.JoinTournamentRequest, error, int)) error - RegisterAfterJoinTournament(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeListTournamentRecords(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListTournamentRecordsRequest) (*api.ListTournamentRecordsRequest, error, int)) error - RegisterAfterListTournamentRecords(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.TournamentRecordList) error) error - RegisterBeforeListTournaments(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListTournamentsRequest) (*api.ListTournamentsRequest, error, int)) error - RegisterAfterListTournaments(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.TournamentList) error) error - RegisterBeforeWriteTournamentRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.WriteTournamentRecordRequest) (*api.WriteTournamentRecordRequest, error, int)) error - RegisterAfterWriteTournamentRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.LeaderboardRecord) error) error - RegisterBeforeListTournamentRecordsAroundOwner(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListTournamentRecordsAroundOwnerRequest) (*api.ListTournamentRecordsAroundOwnerRequest, error, int)) error - RegisterAfterListTournamentRecordsAroundOwner(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.TournamentRecordList) error) error - RegisterBeforeUnlinkCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountCustom) (*api.AccountCustom, error, int)) error - RegisterAfterUnlinkCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeUnlinkDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountDevice) (*api.AccountDevice, error, int)) error - RegisterAfterUnlinkDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeUnlinkEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountEmail) (*api.AccountEmail, error, int)) error - RegisterAfterUnlinkEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeUnlinkFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountFacebook) (*api.AccountFacebook, error, int)) error - RegisterAfterUnlinkFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeUnlinkGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountGameCenter) (*api.AccountGameCenter, error, int)) error - RegisterAfterUnlinkGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeUnlinkGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountGoogle) (*api.AccountGoogle, error, int)) error - RegisterAfterUnlinkGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeUnlinkSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountSteam) (*api.AccountSteam, error, int)) error - RegisterAfterUnlinkSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *empty.Empty) error) error - RegisterBeforeGetUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.GetUsersRequest) (*api.GetUsersRequest, error, int)) error - RegisterAfterGetUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Users) error) error + RegisterBeforeAddFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AddFriendsRequest) (*api.AddFriendsRequest, error)) error + RegisterAfterAddFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AddFriendsRequest) error) error + RegisterBeforeDeleteFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.DeleteFriendsRequest) (*api.DeleteFriendsRequest, error)) error + RegisterAfterDeleteFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.DeleteFriendsRequest) error) error + RegisterBeforeBlockFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.BlockFriendsRequest) (*api.BlockFriendsRequest, error)) error + RegisterAfterBlockFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.BlockFriendsRequest) error) error + RegisterBeforeImportFacebookFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ImportFacebookFriendsRequest) (*api.ImportFacebookFriendsRequest, error)) error + RegisterAfterImportFacebookFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ImportFacebookFriendsRequest) error) error + RegisterBeforeCreateGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.CreateGroupRequest) (*api.CreateGroupRequest, error)) error + RegisterAfterCreateGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Group, in *api.CreateGroupRequest) error) error + RegisterBeforeUpdateGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.UpdateGroupRequest) (*api.UpdateGroupRequest, error)) error + RegisterAfterUpdateGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.UpdateGroupRequest) error) error + RegisterBeforeDeleteGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.DeleteGroupRequest) (*api.DeleteGroupRequest, error)) error + RegisterAfterDeleteGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.DeleteGroupRequest) error) error + RegisterBeforeJoinGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.JoinGroupRequest) (*api.JoinGroupRequest, error)) error + RegisterAfterJoinGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.JoinGroupRequest) error) error + RegisterBeforeLeaveGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.LeaveGroupRequest) (*api.LeaveGroupRequest, error)) error + RegisterAfterLeaveGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.LeaveGroupRequest) error) error + RegisterBeforeAddGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AddGroupUsersRequest) (*api.AddGroupUsersRequest, error)) error + RegisterAfterAddGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AddGroupUsersRequest) error) error + RegisterBeforeKickGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.KickGroupUsersRequest) (*api.KickGroupUsersRequest, error)) error + RegisterAfterKickGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.KickGroupUsersRequest) error) error + RegisterBeforePromoteGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.PromoteGroupUsersRequest) (*api.PromoteGroupUsersRequest, error)) error + RegisterAfterPromoteGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.PromoteGroupUsersRequest) error) error + RegisterBeforeListGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListGroupUsersRequest) (*api.ListGroupUsersRequest, error)) error + RegisterAfterListGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.GroupUserList, in *api.ListGroupUsersRequest) error) error + RegisterBeforeListUserGroups(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListUserGroupsRequest) (*api.ListUserGroupsRequest, error)) error + RegisterAfterListUserGroups(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.UserGroupList, in *api.ListUserGroupsRequest) error) error + RegisterBeforeListGroups(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListGroupsRequest) (*api.ListGroupsRequest, error)) error + RegisterAfterListGroups(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.GroupList, in *api.ListGroupsRequest) error) error + RegisterBeforeDeleteLeaderboardRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.DeleteLeaderboardRecordRequest) (*api.DeleteLeaderboardRecordRequest, error)) error + RegisterAfterDeleteLeaderboardRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.DeleteLeaderboardRecordRequest) error) error + RegisterBeforeListLeaderboardRecords(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListLeaderboardRecordsRequest) (*api.ListLeaderboardRecordsRequest, error)) error + RegisterAfterListLeaderboardRecords(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.LeaderboardRecordList, in *api.ListLeaderboardRecordsRequest) error) error + RegisterBeforeWriteLeaderboardRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.WriteLeaderboardRecordRequest) (*api.WriteLeaderboardRecordRequest, error)) error + RegisterAfterWriteLeaderboardRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.LeaderboardRecord, in *api.WriteLeaderboardRecordRequest) error) error + RegisterBeforeListLeaderboardRecordsAroundOwner(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListLeaderboardRecordsAroundOwnerRequest) (*api.ListLeaderboardRecordsAroundOwnerRequest, error)) error + RegisterAfterListLeaderboardRecordsAroundOwner(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.LeaderboardRecordList, in *api.ListLeaderboardRecordsAroundOwnerRequest) error) error + RegisterBeforeLinkCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountCustom) (*api.AccountCustom, error)) error + RegisterAfterLinkCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountCustom) error) error + RegisterBeforeLinkDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountDevice) (*api.AccountDevice, error)) error + RegisterAfterLinkDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountDevice) error) error + RegisterBeforeLinkEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountEmail) (*api.AccountEmail, error)) error + RegisterAfterLinkEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountEmail) error) error + RegisterBeforeLinkFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.LinkFacebookRequest) (*api.LinkFacebookRequest, error)) error + RegisterAfterLinkFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.LinkFacebookRequest) error) error + RegisterBeforeLinkGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountGameCenter) (*api.AccountGameCenter, error)) error + RegisterAfterLinkGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountGameCenter) error) error + RegisterBeforeLinkGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountGoogle) (*api.AccountGoogle, error)) error + RegisterAfterLinkGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountGoogle) error) error + RegisterBeforeLinkSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountSteam) (*api.AccountSteam, error)) error + RegisterAfterLinkSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountSteam) error) error + RegisterBeforeListMatches(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListMatchesRequest) (*api.ListMatchesRequest, error)) error + RegisterAfterListMatches(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.MatchList, in *api.ListMatchesRequest) error) error + RegisterBeforeListNotifications(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListNotificationsRequest) (*api.ListNotificationsRequest, error)) error + RegisterAfterListNotifications(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.NotificationList, in *api.ListNotificationsRequest) error) error + RegisterBeforeDeleteNotification(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.DeleteNotificationsRequest) (*api.DeleteNotificationsRequest, error)) error + RegisterAfterDeleteNotification(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.DeleteNotificationsRequest) error) error + RegisterBeforeListStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListStorageObjectsRequest) (*api.ListStorageObjectsRequest, error)) error + RegisterAfterListStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.StorageObjectList, in *api.ListStorageObjectsRequest) error) error + RegisterBeforeReadStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ReadStorageObjectsRequest) (*api.ReadStorageObjectsRequest, error)) error + RegisterAfterReadStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.StorageObjects, in *api.ReadStorageObjectsRequest) error) error + RegisterBeforeWriteStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.WriteStorageObjectsRequest) (*api.WriteStorageObjectsRequest, error)) error + RegisterAfterWriteStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.StorageObjectAcks, in *api.WriteStorageObjectsRequest) error) error + RegisterBeforeDeleteStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.DeleteStorageObjectsRequest) (*api.DeleteStorageObjectsRequest, error)) error + RegisterAfterDeleteStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.DeleteStorageObjectsRequest) error) error + RegisterBeforeJoinTournament(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.JoinTournamentRequest) (*api.JoinTournamentRequest, error)) error + RegisterAfterJoinTournament(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.JoinTournamentRequest) error) error + RegisterBeforeListTournamentRecords(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListTournamentRecordsRequest) (*api.ListTournamentRecordsRequest, error)) error + RegisterAfterListTournamentRecords(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.TournamentRecordList, in *api.ListTournamentRecordsRequest) error) error + RegisterBeforeListTournaments(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListTournamentsRequest) (*api.ListTournamentsRequest, error)) error + RegisterAfterListTournaments(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.TournamentList, in *api.ListTournamentsRequest) error) error + RegisterBeforeWriteTournamentRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.WriteTournamentRecordRequest) (*api.WriteTournamentRecordRequest, error)) error + RegisterAfterWriteTournamentRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.LeaderboardRecord, in *api.WriteTournamentRecordRequest) error) error + RegisterBeforeListTournamentRecordsAroundOwner(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.ListTournamentRecordsAroundOwnerRequest) (*api.ListTournamentRecordsAroundOwnerRequest, error)) error + RegisterAfterListTournamentRecordsAroundOwner(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.TournamentRecordList, in *api.ListTournamentRecordsAroundOwnerRequest) error) error + RegisterBeforeUnlinkCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountCustom) (*api.AccountCustom, error)) error + RegisterAfterUnlinkCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountCustom) error) error + RegisterBeforeUnlinkDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountDevice) (*api.AccountDevice, error)) error + RegisterAfterUnlinkDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountDevice) error) error + RegisterBeforeUnlinkEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountEmail) (*api.AccountEmail, error)) error + RegisterAfterUnlinkEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountEmail) error) error + RegisterBeforeUnlinkFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountFacebook) (*api.AccountFacebook, error)) error + RegisterAfterUnlinkFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountFacebook) error) error + RegisterBeforeUnlinkGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountGameCenter) (*api.AccountGameCenter, error)) error + RegisterAfterUnlinkGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountGameCenter) error) error + RegisterBeforeUnlinkGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountGoogle) (*api.AccountGoogle, error)) error + RegisterAfterUnlinkGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountGoogle) error) error + RegisterBeforeUnlinkSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountSteam) (*api.AccountSteam, error)) error + RegisterAfterUnlinkSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.AccountSteam) error) error + RegisterBeforeGetUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, in *api.GetUsersRequest) (*api.GetUsersRequest, error)) error + RegisterAfterGetUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, out *api.Users, in *api.GetUsersRequest) error) error RegisterMatchmakerMatched(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk NakamaModule, entries []MatchmakerEntry) (string, error)) error diff --git a/server/api_account.go b/server/api_account.go index d5f5a3beba73fcff08af878c13602f9d95d031b3..de97b952a42c76482b6565cf819d3f9a7f0668dc 100644 --- a/server/api_account.go +++ b/server/api_account.go @@ -44,16 +44,11 @@ func (s *ApiServer) GetAccount(ctx context.Context, in *empty.Empty) (*api.Accou // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - result, err, code := fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) + err, code := fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort) if err != nil { return nil, status.Error(code, err.Error()) } - if result == nil { - // If result is nil, requested resource is disabled. - s.logger.Warn("Intercepted a disabled resource.", zap.Any("resource", fullMethod), zap.String("uid", userID.String())) - return nil, status.Error(codes.NotFound, "Requested resource was not found.") - } - in = result + // Empty input never overridden. // Stats measurement end boundary. span.End() @@ -143,7 +138,7 @@ func (s *ApiServer) UpdateAccount(ctx context.Context, in *api.UpdateAccountRequ // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() diff --git a/server/api_authenticate.go b/server/api_authenticate.go index 1dee4598da2af8766242a8e28c31582e3235189f..23cbb4f21aaada3b0027bc2ed01f028e4ad7e28c 100644 --- a/server/api_authenticate.go +++ b/server/api_authenticate.go @@ -103,7 +103,7 @@ func (s *ApiServer) AuthenticateCustom(ctx context.Context, in *api.Authenticate // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session) + fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session, in) // Stats measurement end boundary. span.End() @@ -178,7 +178,7 @@ func (s *ApiServer) AuthenticateDevice(ctx context.Context, in *api.Authenticate // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session) + fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session, in) // Stats measurement end boundary. span.End() @@ -260,7 +260,7 @@ func (s *ApiServer) AuthenticateEmail(ctx context.Context, in *api.AuthenticateE // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session) + fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session, in) // Stats measurement end boundary. span.End() @@ -336,7 +336,7 @@ func (s *ApiServer) AuthenticateFacebook(ctx context.Context, in *api.Authentica // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session) + fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session, in) // Stats measurement end boundary. span.End() @@ -419,7 +419,7 @@ func (s *ApiServer) AuthenticateGameCenter(ctx context.Context, in *api.Authenti // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session) + fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session, in) // Stats measurement end boundary. span.End() @@ -490,7 +490,7 @@ func (s *ApiServer) AuthenticateGoogle(ctx context.Context, in *api.Authenticate // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session) + fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session, in) // Stats measurement end boundary. span.End() @@ -565,7 +565,7 @@ func (s *ApiServer) AuthenticateSteam(ctx context.Context, in *api.AuthenticateS // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session) + fn(s.logger, dbUserID, dbUsername, exp, clientIP, clientPort, session, in) // Stats measurement end boundary. span.End() diff --git a/server/api_channel.go b/server/api_channel.go index f5802d8a88937ae684cdffc2cd0261cc285bd4a7..0a5fc106c9ebc91eb3b807df8be9c2b0b71ce7a3 100644 --- a/server/api_channel.go +++ b/server/api_channel.go @@ -99,7 +99,7 @@ func (s *ApiServer) ListChannelMessages(ctx context.Context, in *api.ListChannel // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, messageList) + fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, messageList, in) // Stats measurement end boundary. span.End() diff --git a/server/api_friend.go b/server/api_friend.go index 9c7db1ea7e6434911c94e5e9f812b7cb9b07f8a6..ff1332204aa71327f1f5044ce8ae06f3d4f76b4f 100644 --- a/server/api_friend.go +++ b/server/api_friend.go @@ -43,16 +43,11 @@ func (s *ApiServer) ListFriends(ctx context.Context, in *empty.Empty) (*api.Frie // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - result, err, code := fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) + err, code := fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort) if err != nil { return nil, status.Error(code, err.Error()) } - if result == nil { - // If result is nil, requested resource is disabled. - s.logger.Warn("Intercepted a disabled resource.", zap.Any("resource", fullMethod), zap.String("uid", userID.String())) - return nil, status.Error(codes.NotFound, "Requested resource was not found.") - } - in = result + // Empty input never overridden. // Stats measurement end boundary. span.End() @@ -163,7 +158,7 @@ func (s *ApiServer) AddFriends(ctx context.Context, in *api.AddFriendsRequest) ( // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -252,7 +247,7 @@ func (s *ApiServer) DeleteFriends(ctx context.Context, in *api.DeleteFriendsRequ // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -340,7 +335,7 @@ func (s *ApiServer) BlockFriends(ctx context.Context, in *api.BlockFriendsReques // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -398,7 +393,7 @@ func (s *ApiServer) ImportFacebookFriends(ctx context.Context, in *api.ImportFac // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() diff --git a/server/api_group.go b/server/api_group.go index db3d9efa738316834339b7b6549dc65a5ab1667b..309eae5de7b1b32c83d39a048ee36925fb01b67e 100644 --- a/server/api_group.go +++ b/server/api_group.go @@ -81,7 +81,7 @@ func (s *ApiServer) CreateGroup(ctx context.Context, in *api.CreateGroupRequest) // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, group) + fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, group, in) // Stats measurement end boundary. span.End() @@ -164,7 +164,7 @@ func (s *ApiServer) UpdateGroup(ctx context.Context, in *api.UpdateGroupRequest) // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -231,7 +231,7 @@ func (s *ApiServer) DeleteGroup(ctx context.Context, in *api.DeleteGroupRequest) // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -300,7 +300,7 @@ func (s *ApiServer) JoinGroup(ctx context.Context, in *api.JoinGroupRequest) (*e // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -367,7 +367,7 @@ func (s *ApiServer) LeaveGroup(ctx context.Context, in *api.LeaveGroupRequest) ( // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -449,7 +449,7 @@ func (s *ApiServer) AddGroupUsers(ctx context.Context, in *api.AddGroupUsersRequ // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -528,7 +528,7 @@ func (s *ApiServer) KickGroupUsers(ctx context.Context, in *api.KickGroupUsersRe // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -608,7 +608,7 @@ func (s *ApiServer) PromoteGroupUsers(ctx context.Context, in *api.PromoteGroupU // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -670,7 +670,7 @@ func (s *ApiServer) ListGroupUsers(ctx context.Context, in *api.ListGroupUsersRe // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, groupUsers) + fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, groupUsers, in) // Stats measurement end boundary. span.End() @@ -732,7 +732,7 @@ func (s *ApiServer) ListUserGroups(ctx context.Context, in *api.ListUserGroupsRe // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, userGroups) + fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, userGroups, in) // Stats measurement end boundary. span.End() @@ -793,7 +793,7 @@ func (s *ApiServer) ListGroups(ctx context.Context, in *api.ListGroupsRequest) ( // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, groups) + fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, groups, in) // Stats measurement end boundary. span.End() diff --git a/server/api_leaderboard.go b/server/api_leaderboard.go index eb581a9336cbdca477d7faf0a05b76b5df33ca49..50ba33b48f03acca81fddd0fb7cfd6e6668b282e 100644 --- a/server/api_leaderboard.go +++ b/server/api_leaderboard.go @@ -85,7 +85,7 @@ func (s *ApiServer) DeleteLeaderboardRecord(ctx context.Context, in *api.DeleteL // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -164,7 +164,7 @@ func (s *ApiServer) ListLeaderboardRecords(ctx context.Context, in *api.ListLead // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, records) + fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, records, in) // Stats measurement end boundary. span.End() @@ -235,7 +235,7 @@ func (s *ApiServer) WriteLeaderboardRecord(ctx context.Context, in *api.WriteLea // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), username, ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, record) + fn(s.logger, userID.String(), username, ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, record, in) // Stats measurement end boundary. span.End() @@ -313,7 +313,7 @@ func (s *ApiServer) ListLeaderboardRecordsAroundOwner(ctx context.Context, in *a // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, recordList) + fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, recordList, in) // Stats measurement end boundary. span.End() diff --git a/server/api_link.go b/server/api_link.go index 2bef3027c35acdd45377258de5e8fd5e1472ec64..5361e9b13746a6bf88d6068bc27df8d56f69692f 100644 --- a/server/api_link.go +++ b/server/api_link.go @@ -102,7 +102,7 @@ AND (NOT EXISTS // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -202,7 +202,7 @@ func (s *ApiServer) LinkDevice(ctx context.Context, in *api.AccountDevice) (*emp // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -286,7 +286,7 @@ AND (NOT EXISTS // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -369,7 +369,7 @@ AND (NOT EXISTS // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -457,7 +457,7 @@ AND (NOT EXISTS // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -535,7 +535,7 @@ AND (NOT EXISTS // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -617,7 +617,7 @@ AND (NOT EXISTS // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() diff --git a/server/api_match.go b/server/api_match.go index 8d1402938eb06224aee1b5c564d7d335a3f98203..17a1325b5e398a609e33c2a06af1eb98d02d8883 100644 --- a/server/api_match.go +++ b/server/api_match.go @@ -92,7 +92,7 @@ func (s *ApiServer) ListMatches(ctx context.Context, in *api.ListMatchesRequest) // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, list) + fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, list, in) // Stats measurement end boundary. span.End() diff --git a/server/api_notification.go b/server/api_notification.go index 1a27d54795fc8db52d7de2fde215937bc2878789..ab08c1958dace35f8b739d3fdfdae566f0b3cd6e 100644 --- a/server/api_notification.go +++ b/server/api_notification.go @@ -101,7 +101,7 @@ func (s *ApiServer) ListNotifications(ctx context.Context, in *api.ListNotificat // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, notificationList) + fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, notificationList, in) // Stats measurement end boundary. span.End() @@ -159,7 +159,7 @@ func (s *ApiServer) DeleteNotifications(ctx context.Context, in *api.DeleteNotif // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() diff --git a/server/api_storage.go b/server/api_storage.go index 8e013855389b35c1c5f1f46044ec559b58aaacee..b3845de4a80a6102b965c8cbaf1f3739a6243c72 100644 --- a/server/api_storage.go +++ b/server/api_storage.go @@ -97,7 +97,7 @@ func (s *ApiServer) ListStorageObjects(ctx context.Context, in *api.ListStorageO // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, caller.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, storageObjectList) + fn(s.logger, caller.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, storageObjectList, in) // Stats measurement end boundary. span.End() @@ -168,7 +168,7 @@ func (s *ApiServer) ReadStorageObjects(ctx context.Context, in *api.ReadStorageO // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, objects) + fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, objects, in) // Stats measurement end boundary. span.End() @@ -257,7 +257,7 @@ func (s *ApiServer) WriteStorageObjects(ctx context.Context, in *api.WriteStorag // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, acks) + fn(s.logger, userID.String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, acks, in) // Stats measurement end boundary. span.End() @@ -326,7 +326,7 @@ func (s *ApiServer) DeleteStorageObjects(ctx context.Context, in *api.DeleteStor // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() diff --git a/server/api_tournament.go b/server/api_tournament.go index e678f95d03d4801e54f588edd68a023efe8159e3..392696078f9fceb9bde285efd4114fca50775371 100644 --- a/server/api_tournament.go +++ b/server/api_tournament.go @@ -90,7 +90,7 @@ func (s *ApiServer) JoinTournament(ctx context.Context, in *api.JoinTournamentRe // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), username, ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.String(), username, ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -185,7 +185,7 @@ func (s *ApiServer) ListTournamentRecords(ctx context.Context, in *api.ListTourn // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, recordList) + fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, recordList, in) // Stats measurement end boundary. span.End() @@ -289,7 +289,7 @@ func (s *ApiServer) ListTournaments(ctx context.Context, in *api.ListTournaments // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, records) + fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, records, in) // Stats measurement end boundary. span.End() @@ -379,7 +379,7 @@ func (s *ApiServer) WriteTournamentRecord(ctx context.Context, in *api.WriteTour // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.String(), username, ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, record) + fn(s.logger, userID.String(), username, ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, record, in) // Stats measurement end boundary. span.End() @@ -457,7 +457,7 @@ func (s *ApiServer) ListTournamentRecordsAroundOwner(ctx context.Context, in *ap // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, list) + fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, list, in) // Stats measurement end boundary. span.End() diff --git a/server/api_unlink.go b/server/api_unlink.go index 5e44db85f5ab05e45f42416e33d686f194e4fad0..16792fbdf54891dc77207dfd52ae12bbb28c98f8 100644 --- a/server/api_unlink.go +++ b/server/api_unlink.go @@ -97,7 +97,7 @@ AND ((facebook_id IS NOT NULL // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -197,7 +197,7 @@ AND (EXISTS (SELECT id FROM users WHERE id = $1 AND // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -272,7 +272,7 @@ AND ((facebook_id IS NOT NULL // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -352,7 +352,7 @@ AND ((custom_id IS NOT NULL // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -442,7 +442,7 @@ AND ((custom_id IS NOT NULL // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -522,7 +522,7 @@ AND ((custom_id IS NOT NULL // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() @@ -606,7 +606,7 @@ AND ((custom_id IS NOT NULL // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, &empty.Empty{}) + fn(s.logger, userID.(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, in) // Stats measurement end boundary. span.End() diff --git a/server/api_user.go b/server/api_user.go index 5f7daf992b04b111047f0b13ecec78b155c2c0a7..bce560ebbd6c99ffb3905a5d68728a6e7172e830 100644 --- a/server/api_user.go +++ b/server/api_user.go @@ -97,7 +97,7 @@ func (s *ApiServer) GetUsers(ctx context.Context, in *api.GetUsersRequest) (*api // Extract request information and execute the hook. clientIP, clientPort := extractClientAddress(s.logger, ctx) - fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, users) + fn(s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, users, in) // Stats measurement end boundary. span.End() diff --git a/server/runtime.go b/server/runtime.go index 90e4eb088396b882e45abd8828ce578b03907811..a36a48599494bc144559ec2f61bc376b3eefdc51 100644 --- a/server/runtime.go +++ b/server/runtime.go @@ -23,7 +23,6 @@ import ( "github.com/gofrs/uuid" "github.com/golang/protobuf/jsonpb" - "github.com/golang/protobuf/ptypes/empty" "github.com/heroiclabs/nakama/api" "github.com/heroiclabs/nakama/rtapi" "github.com/heroiclabs/nakama/social" @@ -45,120 +44,120 @@ type ( RuntimeBeforeRtFunction func(logger *zap.Logger, userID, username string, expiry int64, sessionID, clientIP, clientPort string, envelope *rtapi.Envelope) (*rtapi.Envelope, error) RuntimeAfterRtFunction func(logger *zap.Logger, userID, username string, expiry int64, sessionID, clientIP, clientPort string, envelope *rtapi.Envelope) error - RuntimeBeforeGetAccountFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) (*empty.Empty, error, codes.Code) + RuntimeBeforeGetAccountFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string) (error, codes.Code) RuntimeAfterGetAccountFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Account) error RuntimeBeforeUpdateAccountFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.UpdateAccountRequest) (*api.UpdateAccountRequest, error, codes.Code) - RuntimeAfterUpdateAccountFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterUpdateAccountFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.UpdateAccountRequest) error RuntimeBeforeAuthenticateCustomFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AuthenticateCustomRequest) (*api.AuthenticateCustomRequest, error, codes.Code) - RuntimeAfterAuthenticateCustomFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session) error + RuntimeAfterAuthenticateCustomFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateCustomRequest) error RuntimeBeforeAuthenticateDeviceFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AuthenticateDeviceRequest) (*api.AuthenticateDeviceRequest, error, codes.Code) - RuntimeAfterAuthenticateDeviceFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session) error + RuntimeAfterAuthenticateDeviceFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateDeviceRequest) error RuntimeBeforeAuthenticateEmailFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AuthenticateEmailRequest) (*api.AuthenticateEmailRequest, error, codes.Code) - RuntimeAfterAuthenticateEmailFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session) error + RuntimeAfterAuthenticateEmailFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateEmailRequest) error RuntimeBeforeAuthenticateFacebookFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AuthenticateFacebookRequest) (*api.AuthenticateFacebookRequest, error, codes.Code) - RuntimeAfterAuthenticateFacebookFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session) error + RuntimeAfterAuthenticateFacebookFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateFacebookRequest) error RuntimeBeforeAuthenticateGameCenterFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AuthenticateGameCenterRequest) (*api.AuthenticateGameCenterRequest, error, codes.Code) - RuntimeAfterAuthenticateGameCenterFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session) error + RuntimeAfterAuthenticateGameCenterFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateGameCenterRequest) error RuntimeBeforeAuthenticateGoogleFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AuthenticateGoogleRequest) (*api.AuthenticateGoogleRequest, error, codes.Code) - RuntimeAfterAuthenticateGoogleFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session) error + RuntimeAfterAuthenticateGoogleFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateGoogleRequest) error RuntimeBeforeAuthenticateSteamFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AuthenticateSteamRequest) (*api.AuthenticateSteamRequest, error, codes.Code) - RuntimeAfterAuthenticateSteamFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session) error + RuntimeAfterAuthenticateSteamFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateSteamRequest) error RuntimeBeforeListChannelMessagesFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListChannelMessagesRequest) (*api.ListChannelMessagesRequest, error, codes.Code) - RuntimeAfterListChannelMessagesFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.ChannelMessageList) error - RuntimeBeforeListFriendsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) (*empty.Empty, error, codes.Code) + RuntimeAfterListChannelMessagesFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.ChannelMessageList, in *api.ListChannelMessagesRequest) error + RuntimeBeforeListFriendsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string) (error, codes.Code) RuntimeAfterListFriendsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Friends) error RuntimeBeforeAddFriendsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AddFriendsRequest) (*api.AddFriendsRequest, error, codes.Code) - RuntimeAfterAddFriendsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterAddFriendsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AddFriendsRequest) error RuntimeBeforeDeleteFriendsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteFriendsRequest) (*api.DeleteFriendsRequest, error, codes.Code) - RuntimeAfterDeleteFriendsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterDeleteFriendsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteFriendsRequest) error RuntimeBeforeBlockFriendsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.BlockFriendsRequest) (*api.BlockFriendsRequest, error, codes.Code) - RuntimeAfterBlockFriendsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterBlockFriendsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.BlockFriendsRequest) error RuntimeBeforeImportFacebookFriendsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ImportFacebookFriendsRequest) (*api.ImportFacebookFriendsRequest, error, codes.Code) - RuntimeAfterImportFacebookFriendsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterImportFacebookFriendsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ImportFacebookFriendsRequest) error RuntimeBeforeCreateGroupFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.CreateGroupRequest) (*api.CreateGroupRequest, error, codes.Code) - RuntimeAfterCreateGroupFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Group) error + RuntimeAfterCreateGroupFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Group, in *api.CreateGroupRequest) error RuntimeBeforeUpdateGroupFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.UpdateGroupRequest) (*api.UpdateGroupRequest, error, codes.Code) - RuntimeAfterUpdateGroupFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterUpdateGroupFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.UpdateGroupRequest) error RuntimeBeforeDeleteGroupFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteGroupRequest) (*api.DeleteGroupRequest, error, codes.Code) - RuntimeAfterDeleteGroupFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterDeleteGroupFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteGroupRequest) error RuntimeBeforeJoinGroupFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.JoinGroupRequest) (*api.JoinGroupRequest, error, codes.Code) - RuntimeAfterJoinGroupFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterJoinGroupFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.JoinGroupRequest) error RuntimeBeforeLeaveGroupFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.LeaveGroupRequest) (*api.LeaveGroupRequest, error, codes.Code) - RuntimeAfterLeaveGroupFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterLeaveGroupFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.LeaveGroupRequest) error RuntimeBeforeAddGroupUsersFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AddGroupUsersRequest) (*api.AddGroupUsersRequest, error, codes.Code) - RuntimeAfterAddGroupUsersFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterAddGroupUsersFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AddGroupUsersRequest) error RuntimeBeforeKickGroupUsersFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.KickGroupUsersRequest) (*api.KickGroupUsersRequest, error, codes.Code) - RuntimeAfterKickGroupUsersFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterKickGroupUsersFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.KickGroupUsersRequest) error RuntimeBeforePromoteGroupUsersFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.PromoteGroupUsersRequest) (*api.PromoteGroupUsersRequest, error, codes.Code) - RuntimeAfterPromoteGroupUsersFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterPromoteGroupUsersFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.PromoteGroupUsersRequest) error RuntimeBeforeListGroupUsersFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListGroupUsersRequest) (*api.ListGroupUsersRequest, error, codes.Code) - RuntimeAfterListGroupUsersFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.GroupUserList) error + RuntimeAfterListGroupUsersFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.GroupUserList, in *api.ListGroupUsersRequest) error RuntimeBeforeListUserGroupsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListUserGroupsRequest) (*api.ListUserGroupsRequest, error, codes.Code) - RuntimeAfterListUserGroupsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.UserGroupList) error + RuntimeAfterListUserGroupsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.UserGroupList, in *api.ListUserGroupsRequest) error RuntimeBeforeListGroupsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListGroupsRequest) (*api.ListGroupsRequest, error, codes.Code) - RuntimeAfterListGroupsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.GroupList) error + RuntimeAfterListGroupsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.GroupList, in *api.ListGroupsRequest) error RuntimeBeforeDeleteLeaderboardRecordFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteLeaderboardRecordRequest) (*api.DeleteLeaderboardRecordRequest, error, codes.Code) - RuntimeAfterDeleteLeaderboardRecordFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterDeleteLeaderboardRecordFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteLeaderboardRecordRequest) error RuntimeBeforeListLeaderboardRecordsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListLeaderboardRecordsRequest) (*api.ListLeaderboardRecordsRequest, error, codes.Code) - RuntimeAfterListLeaderboardRecordsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecordList) error + RuntimeAfterListLeaderboardRecordsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecordList, in *api.ListLeaderboardRecordsRequest) error RuntimeBeforeWriteLeaderboardRecordFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.WriteLeaderboardRecordRequest) (*api.WriteLeaderboardRecordRequest, error, codes.Code) - RuntimeAfterWriteLeaderboardRecordFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecord) error + RuntimeAfterWriteLeaderboardRecordFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecord, in *api.WriteLeaderboardRecordRequest) error RuntimeBeforeListLeaderboardRecordsAroundOwnerFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListLeaderboardRecordsAroundOwnerRequest) (*api.ListLeaderboardRecordsAroundOwnerRequest, error, codes.Code) - RuntimeAfterListLeaderboardRecordsAroundOwnerFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecordList) error + RuntimeAfterListLeaderboardRecordsAroundOwnerFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecordList, in *api.ListLeaderboardRecordsAroundOwnerRequest) error RuntimeBeforeLinkCustomFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountCustom) (*api.AccountCustom, error, codes.Code) - RuntimeAfterLinkCustomFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterLinkCustomFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountCustom) error RuntimeBeforeLinkDeviceFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountDevice) (*api.AccountDevice, error, codes.Code) - RuntimeAfterLinkDeviceFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterLinkDeviceFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountDevice) error RuntimeBeforeLinkEmailFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountEmail) (*api.AccountEmail, error, codes.Code) - RuntimeAfterLinkEmailFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterLinkEmailFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountEmail) error RuntimeBeforeLinkFacebookFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.LinkFacebookRequest) (*api.LinkFacebookRequest, error, codes.Code) - RuntimeAfterLinkFacebookFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterLinkFacebookFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.LinkFacebookRequest) error RuntimeBeforeLinkGameCenterFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGameCenter) (*api.AccountGameCenter, error, codes.Code) - RuntimeAfterLinkGameCenterFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterLinkGameCenterFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGameCenter) error RuntimeBeforeLinkGoogleFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGoogle) (*api.AccountGoogle, error, codes.Code) - RuntimeAfterLinkGoogleFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterLinkGoogleFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGoogle) error RuntimeBeforeLinkSteamFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountSteam) (*api.AccountSteam, error, codes.Code) - RuntimeAfterLinkSteamFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterLinkSteamFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountSteam) error RuntimeBeforeListMatchesFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListMatchesRequest) (*api.ListMatchesRequest, error, codes.Code) - RuntimeAfterListMatchesFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.MatchList) error + RuntimeAfterListMatchesFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.MatchList, in *api.ListMatchesRequest) error RuntimeBeforeListNotificationsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListNotificationsRequest) (*api.ListNotificationsRequest, error, codes.Code) - RuntimeAfterListNotificationsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.NotificationList) error + RuntimeAfterListNotificationsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.NotificationList, in *api.ListNotificationsRequest) error RuntimeBeforeDeleteNotificationFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteNotificationsRequest) (*api.DeleteNotificationsRequest, error, codes.Code) - RuntimeAfterDeleteNotificationFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterDeleteNotificationFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteNotificationsRequest) error RuntimeBeforeListStorageObjectsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListStorageObjectsRequest) (*api.ListStorageObjectsRequest, error, codes.Code) - RuntimeAfterListStorageObjectsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.StorageObjectList) error + RuntimeAfterListStorageObjectsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.StorageObjectList, in *api.ListStorageObjectsRequest) error RuntimeBeforeReadStorageObjectsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ReadStorageObjectsRequest) (*api.ReadStorageObjectsRequest, error, codes.Code) - RuntimeAfterReadStorageObjectsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.StorageObjects) error + RuntimeAfterReadStorageObjectsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.StorageObjects, in *api.ReadStorageObjectsRequest) error RuntimeBeforeWriteStorageObjectsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.WriteStorageObjectsRequest) (*api.WriteStorageObjectsRequest, error, codes.Code) - RuntimeAfterWriteStorageObjectsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.StorageObjectAcks) error + RuntimeAfterWriteStorageObjectsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.StorageObjectAcks, in *api.WriteStorageObjectsRequest) error RuntimeBeforeDeleteStorageObjectsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteStorageObjectsRequest) (*api.DeleteStorageObjectsRequest, error, codes.Code) - RuntimeAfterDeleteStorageObjectsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterDeleteStorageObjectsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteStorageObjectsRequest) error RuntimeBeforeJoinTournamentFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.JoinTournamentRequest) (*api.JoinTournamentRequest, error, codes.Code) - RuntimeAfterJoinTournamentFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterJoinTournamentFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.JoinTournamentRequest) error RuntimeBeforeListTournamentRecordsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListTournamentRecordsRequest) (*api.ListTournamentRecordsRequest, error, codes.Code) - RuntimeAfterListTournamentRecordsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.TournamentRecordList) error + RuntimeAfterListTournamentRecordsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.TournamentRecordList, in *api.ListTournamentRecordsRequest) error RuntimeBeforeListTournamentsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListTournamentsRequest) (*api.ListTournamentsRequest, error, codes.Code) - RuntimeAfterListTournamentsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.TournamentList) error + RuntimeAfterListTournamentsFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.TournamentList, in *api.ListTournamentsRequest) error RuntimeBeforeWriteTournamentRecordFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.WriteTournamentRecordRequest) (*api.WriteTournamentRecordRequest, error, codes.Code) - RuntimeAfterWriteTournamentRecordFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecord) error + RuntimeAfterWriteTournamentRecordFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecord, in *api.WriteTournamentRecordRequest) error RuntimeBeforeListTournamentRecordsAroundOwnerFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListTournamentRecordsAroundOwnerRequest) (*api.ListTournamentRecordsAroundOwnerRequest, error, codes.Code) - RuntimeAfterListTournamentRecordsAroundOwnerFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.TournamentRecordList) error + RuntimeAfterListTournamentRecordsAroundOwnerFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.TournamentRecordList, in *api.ListTournamentRecordsAroundOwnerRequest) error RuntimeBeforeUnlinkCustomFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountCustom) (*api.AccountCustom, error, codes.Code) - RuntimeAfterUnlinkCustomFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterUnlinkCustomFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountCustom) error RuntimeBeforeUnlinkDeviceFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountDevice) (*api.AccountDevice, error, codes.Code) - RuntimeAfterUnlinkDeviceFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterUnlinkDeviceFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountDevice) error RuntimeBeforeUnlinkEmailFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountEmail) (*api.AccountEmail, error, codes.Code) - RuntimeAfterUnlinkEmailFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterUnlinkEmailFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountEmail) error RuntimeBeforeUnlinkFacebookFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountFacebook) (*api.AccountFacebook, error, codes.Code) - RuntimeAfterUnlinkFacebookFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterUnlinkFacebookFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountFacebook) error RuntimeBeforeUnlinkGameCenterFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGameCenter) (*api.AccountGameCenter, error, codes.Code) - RuntimeAfterUnlinkGameCenterFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterUnlinkGameCenterFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGameCenter) error RuntimeBeforeUnlinkGoogleFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGoogle) (*api.AccountGoogle, error, codes.Code) - RuntimeAfterUnlinkGoogleFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterUnlinkGoogleFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGoogle) error RuntimeBeforeUnlinkSteamFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountSteam) (*api.AccountSteam, error, codes.Code) - RuntimeAfterUnlinkSteamFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error + RuntimeAfterUnlinkSteamFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountSteam) error RuntimeBeforeGetUsersFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.GetUsersRequest) (*api.GetUsersRequest, error, codes.Code) - RuntimeAfterGetUsersFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Users) error + RuntimeAfterGetUsersFunction func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Users, in *api.GetUsersRequest) error RuntimeMatchmakerMatchedFunction func(entries []*MatchmakerEntry) (string, bool, error) diff --git a/server/runtime_go.go b/server/runtime_go.go index d61bcaada0b173111cae245cd7208cd09def8056..2e930705a4eae74e0cff0eb0de184f5c4d313761 100644 --- a/server/runtime_go.go +++ b/server/runtime_go.go @@ -25,7 +25,6 @@ import ( "sync" "github.com/gofrs/uuid" - "github.com/golang/protobuf/ptypes/empty" "github.com/heroiclabs/nakama/api" "github.com/heroiclabs/nakama/rtapi" "github.com/heroiclabs/nakama/runtime" @@ -36,7 +35,7 @@ import ( // No need for a stateful RuntimeProviderGo here. -type RuntimeGoInitialiser struct { +type RuntimeGoInitializer struct { logger *log.Logger db *sql.DB env map[string]string @@ -56,21 +55,28 @@ type RuntimeGoInitialiser struct { matchLock *sync.RWMutex } -func (ri *RuntimeGoInitialiser) RegisterRpc(id string, fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterRpc(id string, fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error)) error { id = strings.ToLower(id) ri.rpc[id] = func(queryParams map[string][]string, userID, username string, expiry int64, sessionID, clientIP, clientPort, payload string) (string, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeRPC, queryParams, expiry, userID, username, sessionID, clientIP, clientPort) - result, fnErr, code := fn(ctx, ri.logger, ri.db, ri.nk, payload) - if fnErr != nil && (code <= 0 || code >= 17) { - // If error is present but code is invalid then default to 13 (Internal) as the error code. - code = 13 + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, payload) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal } - return result, fnErr, codes.Code(code) + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeRt(id string, fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, envelope *rtapi.Envelope) (*rtapi.Envelope, error)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeRt(id string, fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, envelope *rtapi.Envelope) (*rtapi.Envelope, error)) error { id = strings.ToLower(RTAPI_PREFIX + id) ri.beforeRt[id] = func(logger *zap.Logger, userID, username string, expiry int64, sessionID, clientIP, clientPort string, envelope *rtapi.Envelope) (*rtapi.Envelope, error) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, sessionID, clientIP, clientPort) @@ -79,7 +85,7 @@ func (ri *RuntimeGoInitialiser) RegisterBeforeRt(id string, fn func(ctx context. return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterRt(id string, fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, envelope *rtapi.Envelope) error) error { +func (ri *RuntimeGoInitializer) RegisterAfterRt(id string, fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, envelope *rtapi.Envelope) error) error { id = strings.ToLower(RTAPI_PREFIX + id) ri.afterRt[id] = func(logger *zap.Logger, userID, username string, expiry int64, sessionID, clientIP, clientPort string, envelope *rtapi.Envelope) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, sessionID, clientIP, clientPort) @@ -88,186 +94,307 @@ func (ri *RuntimeGoInitialiser) RegisterAfterRt(id string, fn func(ctx context.C return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeGetAccount(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *empty.Empty) (*empty.Empty, error, int)) error { - ri.beforeReq.beforeGetAccountFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) (*empty.Empty, error, codes.Code) { +func (ri *RuntimeGoInitializer) RegisterBeforeGetAccount(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule) error) error { + ri.beforeReq.beforeGetAccountFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string) (error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + fnErr := fn(ctx, ri.logger, ri.db, ri.nk) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return runtimeErr, codes.Internal + } + return runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return fnErr, codes.Internal + } + return nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterGetAccount(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Account) error) error { - ri.afterReq.afterGetAccountFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.Account) error { +func (ri *RuntimeGoInitializer) RegisterAfterGetAccount(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Account) error) error { + ri.afterReq.afterGetAccountFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Account) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeUpdateAccount(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.UpdateAccountRequest) (*api.UpdateAccountRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeUpdateAccount(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.UpdateAccountRequest) (*api.UpdateAccountRequest, error)) error { ri.beforeReq.beforeUpdateAccountFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.UpdateAccountRequest) (*api.UpdateAccountRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterUpdateAccount(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterUpdateAccountFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterUpdateAccount(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.UpdateAccountRequest) error) error { + ri.afterReq.afterUpdateAccountFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.UpdateAccountRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeAuthenticateCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateCustomRequest) (*api.AuthenticateCustomRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeAuthenticateCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateCustomRequest) (*api.AuthenticateCustomRequest, error)) error { ri.beforeReq.beforeAuthenticateCustomFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AuthenticateCustomRequest) (*api.AuthenticateCustomRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterAuthenticateCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Session) error) error { - ri.afterReq.afterAuthenticateCustomFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.Session) error { +func (ri *RuntimeGoInitializer) RegisterAfterAuthenticateCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Session, in *api.AuthenticateCustomRequest) error) error { + ri.afterReq.afterAuthenticateCustomFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateCustomRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeAuthenticateDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateDeviceRequest) (*api.AuthenticateDeviceRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeAuthenticateDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateDeviceRequest) (*api.AuthenticateDeviceRequest, error)) error { ri.beforeReq.beforeAuthenticateDeviceFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AuthenticateDeviceRequest) (*api.AuthenticateDeviceRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterAuthenticateDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Session) error) error { - ri.afterReq.afterAuthenticateDeviceFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.Session) error { +func (ri *RuntimeGoInitializer) RegisterAfterAuthenticateDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Session, in *api.AuthenticateDeviceRequest) error) error { + ri.afterReq.afterAuthenticateDeviceFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateDeviceRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeAuthenticateEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateEmailRequest) (*api.AuthenticateEmailRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeAuthenticateEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateEmailRequest) (*api.AuthenticateEmailRequest, error)) error { ri.beforeReq.beforeAuthenticateEmailFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AuthenticateEmailRequest) (*api.AuthenticateEmailRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterAuthenticateEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Session) error) error { - ri.afterReq.afterAuthenticateEmailFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.Session) error { +func (ri *RuntimeGoInitializer) RegisterAfterAuthenticateEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Session, in *api.AuthenticateEmailRequest) error) error { + ri.afterReq.afterAuthenticateEmailFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateEmailRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeAuthenticateFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateFacebookRequest) (*api.AuthenticateFacebookRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeAuthenticateFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateFacebookRequest) (*api.AuthenticateFacebookRequest, error)) error { ri.beforeReq.beforeAuthenticateFacebookFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AuthenticateFacebookRequest) (*api.AuthenticateFacebookRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterAuthenticateFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Session) error) error { - ri.afterReq.afterAuthenticateFacebookFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.Session) error { +func (ri *RuntimeGoInitializer) RegisterAfterAuthenticateFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Session, in *api.AuthenticateFacebookRequest) error) error { + ri.afterReq.afterAuthenticateFacebookFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateFacebookRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeAuthenticateGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateGameCenterRequest) (*api.AuthenticateGameCenterRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeAuthenticateGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateGameCenterRequest) (*api.AuthenticateGameCenterRequest, error)) error { ri.beforeReq.beforeAuthenticateGameCenterFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AuthenticateGameCenterRequest) (*api.AuthenticateGameCenterRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterAuthenticateGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Session) error) error { - ri.afterReq.afterAuthenticateGameCenterFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.Session) error { +func (ri *RuntimeGoInitializer) RegisterAfterAuthenticateGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Session, in *api.AuthenticateGameCenterRequest) error) error { + ri.afterReq.afterAuthenticateGameCenterFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateGameCenterRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeAuthenticateGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateGoogleRequest) (*api.AuthenticateGoogleRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeAuthenticateGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateGoogleRequest) (*api.AuthenticateGoogleRequest, error)) error { ri.beforeReq.beforeAuthenticateGoogleFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AuthenticateGoogleRequest) (*api.AuthenticateGoogleRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterAuthenticateGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Session) error) error { - ri.afterReq.afterAuthenticateGoogleFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.Session) error { +func (ri *RuntimeGoInitializer) RegisterAfterAuthenticateGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Session, in *api.AuthenticateGoogleRequest) error) error { + ri.afterReq.afterAuthenticateGoogleFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateGoogleRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeAuthenticateSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateSteamRequest) (*api.AuthenticateSteamRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeAuthenticateSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateSteamRequest) (*api.AuthenticateSteamRequest, error)) error { ri.beforeReq.beforeAuthenticateSteamFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AuthenticateSteamRequest) (*api.AuthenticateSteamRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterAuthenticateSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Session) error) error { - ri.afterReq.afterAuthenticateSteamFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.Session) error { +func (ri *RuntimeGoInitializer) RegisterAfterAuthenticateSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Session, in *api.AuthenticateSteamRequest) error) error { + ri.afterReq.afterAuthenticateSteamFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateSteamRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeListChannelMessages(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListChannelMessagesRequest) (*api.ListChannelMessagesRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeListChannelMessages(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListChannelMessagesRequest) (*api.ListChannelMessagesRequest, error)) error { ri.beforeReq.beforeListChannelMessagesFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListChannelMessagesRequest) (*api.ListChannelMessagesRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterListChannelMessages(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.ChannelMessageList) error) error { - ri.afterReq.afterListChannelMessagesFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ChannelMessageList) error { +func (ri *RuntimeGoInitializer) RegisterAfterListChannelMessages(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.ChannelMessageList, in *api.ListChannelMessagesRequest) error) error { + ri.afterReq.afterListChannelMessagesFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.ChannelMessageList, in *api.ListChannelMessagesRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeListFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *empty.Empty) (*empty.Empty, error, int)) error { - ri.beforeReq.beforeListFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) (*empty.Empty, error, codes.Code) { +func (ri *RuntimeGoInitializer) RegisterBeforeListFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule) error) error { + ri.beforeReq.beforeListFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string) (error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + fnErr := fn(ctx, ri.logger, ri.db, ri.nk) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return runtimeErr, codes.Internal + } + return runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return fnErr, codes.Internal + } + return nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterListFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Friends) error) error { +func (ri *RuntimeGoInitializer) RegisterAfterListFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Friends) error) error { ri.afterReq.afterListFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.Friends) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) @@ -275,789 +402,1295 @@ func (ri *RuntimeGoInitialiser) RegisterAfterListFriends(fn func(ctx context.Con return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeAddFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AddFriendsRequest) (*api.AddFriendsRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeAddFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AddFriendsRequest) (*api.AddFriendsRequest, error)) error { ri.beforeReq.beforeAddFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AddFriendsRequest) (*api.AddFriendsRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterAddFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterAddFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterAddFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AddFriendsRequest) error) error { + ri.afterReq.afterAddFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AddFriendsRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeDeleteFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteFriendsRequest) (*api.DeleteFriendsRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeDeleteFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteFriendsRequest) (*api.DeleteFriendsRequest, error)) error { ri.beforeReq.beforeDeleteFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteFriendsRequest) (*api.DeleteFriendsRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterDeleteFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterDeleteFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterDeleteFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteFriendsRequest) error) error { + ri.afterReq.afterDeleteFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteFriendsRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeBlockFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.BlockFriendsRequest) (*api.BlockFriendsRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeBlockFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.BlockFriendsRequest) (*api.BlockFriendsRequest, error)) error { ri.beforeReq.beforeBlockFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.BlockFriendsRequest) (*api.BlockFriendsRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterBlockFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterBlockFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterBlockFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.BlockFriendsRequest) error) error { + ri.afterReq.afterBlockFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.BlockFriendsRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeImportFacebookFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ImportFacebookFriendsRequest) (*api.ImportFacebookFriendsRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeImportFacebookFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ImportFacebookFriendsRequest) (*api.ImportFacebookFriendsRequest, error)) error { ri.beforeReq.beforeImportFacebookFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ImportFacebookFriendsRequest) (*api.ImportFacebookFriendsRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterImportFacebookFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterImportFacebookFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterImportFacebookFriends(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ImportFacebookFriendsRequest) error) error { + ri.afterReq.afterImportFacebookFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ImportFacebookFriendsRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeCreateGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.CreateGroupRequest) (*api.CreateGroupRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeCreateGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.CreateGroupRequest) (*api.CreateGroupRequest, error)) error { ri.beforeReq.beforeCreateGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.CreateGroupRequest) (*api.CreateGroupRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterCreateGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Group) error) error { - ri.afterReq.afterCreateGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.Group) error { +func (ri *RuntimeGoInitializer) RegisterAfterCreateGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Group, in *api.CreateGroupRequest) error) error { + ri.afterReq.afterCreateGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Group, in *api.CreateGroupRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeUpdateGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.UpdateGroupRequest) (*api.UpdateGroupRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeUpdateGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.UpdateGroupRequest) (*api.UpdateGroupRequest, error)) error { ri.beforeReq.beforeUpdateGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.UpdateGroupRequest) (*api.UpdateGroupRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterUpdateGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterUpdateGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterUpdateGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.UpdateGroupRequest) error) error { + ri.afterReq.afterUpdateGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.UpdateGroupRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeDeleteGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteGroupRequest) (*api.DeleteGroupRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeDeleteGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteGroupRequest) (*api.DeleteGroupRequest, error)) error { ri.beforeReq.beforeDeleteGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteGroupRequest) (*api.DeleteGroupRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterDeleteGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterDeleteGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterDeleteGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteGroupRequest) error) error { + ri.afterReq.afterDeleteGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteGroupRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeJoinGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.JoinGroupRequest) (*api.JoinGroupRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeJoinGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.JoinGroupRequest) (*api.JoinGroupRequest, error)) error { ri.beforeReq.beforeJoinGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.JoinGroupRequest) (*api.JoinGroupRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterJoinGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterJoinGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterJoinGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.JoinGroupRequest) error) error { + ri.afterReq.afterJoinGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.JoinGroupRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeLeaveGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.LeaveGroupRequest) (*api.LeaveGroupRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeLeaveGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.LeaveGroupRequest) (*api.LeaveGroupRequest, error)) error { ri.beforeReq.beforeLeaveGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.LeaveGroupRequest) (*api.LeaveGroupRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterLeaveGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterLeaveGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterLeaveGroup(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.LeaveGroupRequest) error) error { + ri.afterReq.afterLeaveGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.LeaveGroupRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeAddGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AddGroupUsersRequest) (*api.AddGroupUsersRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeAddGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AddGroupUsersRequest) (*api.AddGroupUsersRequest, error)) error { ri.beforeReq.beforeAddGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AddGroupUsersRequest) (*api.AddGroupUsersRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterAddGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterAddGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterAddGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AddGroupUsersRequest) error) error { + ri.afterReq.afterAddGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AddGroupUsersRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeKickGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.KickGroupUsersRequest) (*api.KickGroupUsersRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeKickGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.KickGroupUsersRequest) (*api.KickGroupUsersRequest, error)) error { ri.beforeReq.beforeKickGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.KickGroupUsersRequest) (*api.KickGroupUsersRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterKickGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterKickGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterKickGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.KickGroupUsersRequest) error) error { + ri.afterReq.afterKickGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.KickGroupUsersRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforePromoteGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.PromoteGroupUsersRequest) (*api.PromoteGroupUsersRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforePromoteGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.PromoteGroupUsersRequest) (*api.PromoteGroupUsersRequest, error)) error { ri.beforeReq.beforePromoteGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.PromoteGroupUsersRequest) (*api.PromoteGroupUsersRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterPromoteGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterPromoteGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterPromoteGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.PromoteGroupUsersRequest) error) error { + ri.afterReq.afterPromoteGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.PromoteGroupUsersRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeListGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListGroupUsersRequest) (*api.ListGroupUsersRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeListGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListGroupUsersRequest) (*api.ListGroupUsersRequest, error)) error { ri.beforeReq.beforeListGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListGroupUsersRequest) (*api.ListGroupUsersRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterListGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.GroupUserList) error) error { - ri.afterReq.afterListGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.GroupUserList) error { +func (ri *RuntimeGoInitializer) RegisterAfterListGroupUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.GroupUserList, in *api.ListGroupUsersRequest) error) error { + ri.afterReq.afterListGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.GroupUserList, in *api.ListGroupUsersRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeListUserGroups(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListUserGroupsRequest) (*api.ListUserGroupsRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeListUserGroups(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListUserGroupsRequest) (*api.ListUserGroupsRequest, error)) error { ri.beforeReq.beforeListUserGroupsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListUserGroupsRequest) (*api.ListUserGroupsRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterListUserGroups(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.UserGroupList) error) error { - ri.afterReq.afterListUserGroupsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.UserGroupList) error { +func (ri *RuntimeGoInitializer) RegisterAfterListUserGroups(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.UserGroupList, in *api.ListUserGroupsRequest) error) error { + ri.afterReq.afterListUserGroupsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.UserGroupList, in *api.ListUserGroupsRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeListGroups(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListGroupsRequest) (*api.ListGroupsRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeListGroups(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListGroupsRequest) (*api.ListGroupsRequest, error)) error { ri.beforeReq.beforeListGroupsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListGroupsRequest) (*api.ListGroupsRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterListGroups(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.GroupList) error) error { - ri.afterReq.afterListGroupsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.GroupList) error { +func (ri *RuntimeGoInitializer) RegisterAfterListGroups(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.GroupList, in *api.ListGroupsRequest) error) error { + ri.afterReq.afterListGroupsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.GroupList, in *api.ListGroupsRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeDeleteLeaderboardRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteLeaderboardRecordRequest) (*api.DeleteLeaderboardRecordRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeDeleteLeaderboardRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteLeaderboardRecordRequest) (*api.DeleteLeaderboardRecordRequest, error)) error { ri.beforeReq.beforeDeleteLeaderboardRecordFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteLeaderboardRecordRequest) (*api.DeleteLeaderboardRecordRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterDeleteLeaderboardRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterDeleteLeaderboardRecordFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterDeleteLeaderboardRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteLeaderboardRecordRequest) error) error { + ri.afterReq.afterDeleteLeaderboardRecordFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteLeaderboardRecordRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeListLeaderboardRecords(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListLeaderboardRecordsRequest) (*api.ListLeaderboardRecordsRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeListLeaderboardRecords(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListLeaderboardRecordsRequest) (*api.ListLeaderboardRecordsRequest, error)) error { ri.beforeReq.beforeListLeaderboardRecordsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListLeaderboardRecordsRequest) (*api.ListLeaderboardRecordsRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterListLeaderboardRecords(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.LeaderboardRecordList) error) error { - ri.afterReq.afterListLeaderboardRecordsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.LeaderboardRecordList) error { +func (ri *RuntimeGoInitializer) RegisterAfterListLeaderboardRecords(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.LeaderboardRecordList, in *api.ListLeaderboardRecordsRequest) error) error { + ri.afterReq.afterListLeaderboardRecordsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecordList, in *api.ListLeaderboardRecordsRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeWriteLeaderboardRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.WriteLeaderboardRecordRequest) (*api.WriteLeaderboardRecordRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeWriteLeaderboardRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.WriteLeaderboardRecordRequest) (*api.WriteLeaderboardRecordRequest, error)) error { ri.beforeReq.beforeWriteLeaderboardRecordFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.WriteLeaderboardRecordRequest) (*api.WriteLeaderboardRecordRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterWriteLeaderboardRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.LeaderboardRecord) error) error { - ri.afterReq.afterWriteLeaderboardRecordFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.LeaderboardRecord) error { +func (ri *RuntimeGoInitializer) RegisterAfterWriteLeaderboardRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.LeaderboardRecord, in *api.WriteLeaderboardRecordRequest) error) error { + ri.afterReq.afterWriteLeaderboardRecordFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecord, in *api.WriteLeaderboardRecordRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeListLeaderboardRecordsAroundOwner(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListLeaderboardRecordsAroundOwnerRequest) (*api.ListLeaderboardRecordsAroundOwnerRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeListLeaderboardRecordsAroundOwner(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListLeaderboardRecordsAroundOwnerRequest) (*api.ListLeaderboardRecordsAroundOwnerRequest, error)) error { ri.beforeReq.beforeListLeaderboardRecordsAroundOwnerFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListLeaderboardRecordsAroundOwnerRequest) (*api.ListLeaderboardRecordsAroundOwnerRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterListLeaderboardRecordsAroundOwner(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.LeaderboardRecordList) error) error { - ri.afterReq.afterListLeaderboardRecordsAroundOwnerFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.LeaderboardRecordList) error { +func (ri *RuntimeGoInitializer) RegisterAfterListLeaderboardRecordsAroundOwner(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.LeaderboardRecordList, in *api.ListLeaderboardRecordsAroundOwnerRequest) error) error { + ri.afterReq.afterListLeaderboardRecordsAroundOwnerFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecordList, in *api.ListLeaderboardRecordsAroundOwnerRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeLinkCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountCustom) (*api.AccountCustom, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeLinkCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountCustom) (*api.AccountCustom, error)) error { ri.beforeReq.beforeLinkCustomFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountCustom) (*api.AccountCustom, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterLinkCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterLinkCustomFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterLinkCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountCustom) error) error { + ri.afterReq.afterLinkCustomFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountCustom) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeLinkDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountDevice) (*api.AccountDevice, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeLinkDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountDevice) (*api.AccountDevice, error)) error { ri.beforeReq.beforeLinkDeviceFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountDevice) (*api.AccountDevice, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterLinkDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterLinkDeviceFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterLinkDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountDevice) error) error { + ri.afterReq.afterLinkDeviceFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountDevice) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeLinkEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountEmail) (*api.AccountEmail, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeLinkEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountEmail) (*api.AccountEmail, error)) error { ri.beforeReq.beforeLinkEmailFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountEmail) (*api.AccountEmail, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterLinkEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterLinkEmailFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterLinkEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountEmail) error) error { + ri.afterReq.afterLinkEmailFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountEmail) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeLinkFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.LinkFacebookRequest) (*api.LinkFacebookRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeLinkFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.LinkFacebookRequest) (*api.LinkFacebookRequest, error)) error { ri.beforeReq.beforeLinkFacebookFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.LinkFacebookRequest) (*api.LinkFacebookRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterLinkFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterLinkFacebookFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterLinkFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.LinkFacebookRequest) error) error { + ri.afterReq.afterLinkFacebookFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.LinkFacebookRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeLinkGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGameCenter) (*api.AccountGameCenter, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeLinkGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGameCenter) (*api.AccountGameCenter, error)) error { ri.beforeReq.beforeLinkGameCenterFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGameCenter) (*api.AccountGameCenter, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterLinkGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterLinkGameCenterFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterLinkGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGameCenter) error) error { + ri.afterReq.afterLinkGameCenterFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGameCenter) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeLinkGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGoogle) (*api.AccountGoogle, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeLinkGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGoogle) (*api.AccountGoogle, error)) error { ri.beforeReq.beforeLinkGoogleFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGoogle) (*api.AccountGoogle, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterLinkGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterLinkGoogleFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterLinkGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGoogle) error) error { + ri.afterReq.afterLinkGoogleFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGoogle) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeLinkSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountSteam) (*api.AccountSteam, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeLinkSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountSteam) (*api.AccountSteam, error)) error { ri.beforeReq.beforeLinkSteamFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountSteam) (*api.AccountSteam, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterLinkSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterLinkSteamFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterLinkSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountSteam) error) error { + ri.afterReq.afterLinkSteamFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountSteam) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeListMatches(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListMatchesRequest) (*api.ListMatchesRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeListMatches(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListMatchesRequest) (*api.ListMatchesRequest, error)) error { ri.beforeReq.beforeListMatchesFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListMatchesRequest) (*api.ListMatchesRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterListMatches(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.MatchList) error) error { - ri.afterReq.afterListMatchesFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.MatchList) error { +func (ri *RuntimeGoInitializer) RegisterAfterListMatches(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.MatchList, in *api.ListMatchesRequest) error) error { + ri.afterReq.afterListMatchesFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.MatchList, in *api.ListMatchesRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeListNotifications(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListNotificationsRequest) (*api.ListNotificationsRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeListNotifications(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListNotificationsRequest) (*api.ListNotificationsRequest, error)) error { ri.beforeReq.beforeListNotificationsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListNotificationsRequest) (*api.ListNotificationsRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterListNotifications(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.NotificationList) error) error { - ri.afterReq.afterListNotificationsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.NotificationList) error { +func (ri *RuntimeGoInitializer) RegisterAfterListNotifications(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.NotificationList, in *api.ListNotificationsRequest) error) error { + ri.afterReq.afterListNotificationsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.NotificationList, in *api.ListNotificationsRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeDeleteNotification(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteNotificationsRequest) (*api.DeleteNotificationsRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeDeleteNotification(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteNotificationsRequest) (*api.DeleteNotificationsRequest, error)) error { ri.beforeReq.beforeDeleteNotificationFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteNotificationsRequest) (*api.DeleteNotificationsRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterDeleteNotification(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterDeleteNotificationFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterDeleteNotification(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteNotificationsRequest) error) error { + ri.afterReq.afterDeleteNotificationFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteNotificationsRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeListStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListStorageObjectsRequest) (*api.ListStorageObjectsRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeListStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListStorageObjectsRequest) (*api.ListStorageObjectsRequest, error)) error { ri.beforeReq.beforeListStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListStorageObjectsRequest) (*api.ListStorageObjectsRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterListStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.StorageObjectList) error) error { - ri.afterReq.afterListStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.StorageObjectList) error { +func (ri *RuntimeGoInitializer) RegisterAfterListStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.StorageObjectList, in *api.ListStorageObjectsRequest) error) error { + ri.afterReq.afterListStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.StorageObjectList, in *api.ListStorageObjectsRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeReadStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ReadStorageObjectsRequest) (*api.ReadStorageObjectsRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeReadStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ReadStorageObjectsRequest) (*api.ReadStorageObjectsRequest, error)) error { ri.beforeReq.beforeReadStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ReadStorageObjectsRequest) (*api.ReadStorageObjectsRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterReadStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.StorageObjects) error) error { - ri.afterReq.afterReadStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.StorageObjects) error { +func (ri *RuntimeGoInitializer) RegisterAfterReadStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.StorageObjects, in *api.ReadStorageObjectsRequest) error) error { + ri.afterReq.afterReadStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.StorageObjects, in *api.ReadStorageObjectsRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeWriteStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.WriteStorageObjectsRequest) (*api.WriteStorageObjectsRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeWriteStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.WriteStorageObjectsRequest) (*api.WriteStorageObjectsRequest, error)) error { ri.beforeReq.beforeWriteStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.WriteStorageObjectsRequest) (*api.WriteStorageObjectsRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterWriteStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.StorageObjectAcks) error) error { - ri.afterReq.afterWriteStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.StorageObjectAcks) error { +func (ri *RuntimeGoInitializer) RegisterAfterWriteStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.StorageObjectAcks, in *api.WriteStorageObjectsRequest) error) error { + ri.afterReq.afterWriteStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.StorageObjectAcks, in *api.WriteStorageObjectsRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeDeleteStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteStorageObjectsRequest) (*api.DeleteStorageObjectsRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeDeleteStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteStorageObjectsRequest) (*api.DeleteStorageObjectsRequest, error)) error { ri.beforeReq.beforeDeleteStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteStorageObjectsRequest) (*api.DeleteStorageObjectsRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterDeleteStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterDeleteStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterDeleteStorageObjects(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteStorageObjectsRequest) error) error { + ri.afterReq.afterDeleteStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteStorageObjectsRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeJoinTournament(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.JoinTournamentRequest) (*api.JoinTournamentRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeJoinTournament(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.JoinTournamentRequest) (*api.JoinTournamentRequest, error)) error { ri.beforeReq.beforeJoinTournamentFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.JoinTournamentRequest) (*api.JoinTournamentRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterJoinTournament(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterJoinTournamentFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterJoinTournament(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.JoinTournamentRequest) error) error { + ri.afterReq.afterJoinTournamentFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.JoinTournamentRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeListTournamentRecords(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListTournamentRecordsRequest) (*api.ListTournamentRecordsRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeListTournamentRecords(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListTournamentRecordsRequest) (*api.ListTournamentRecordsRequest, error)) error { ri.beforeReq.beforeListTournamentRecordsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListTournamentRecordsRequest) (*api.ListTournamentRecordsRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterListTournamentRecords(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.TournamentRecordList) error) error { - ri.afterReq.afterListTournamentRecordsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.TournamentRecordList) error { +func (ri *RuntimeGoInitializer) RegisterAfterListTournamentRecords(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.TournamentRecordList, in *api.ListTournamentRecordsRequest) error) error { + ri.afterReq.afterListTournamentRecordsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.TournamentRecordList, in *api.ListTournamentRecordsRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeListTournaments(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListTournamentsRequest) (*api.ListTournamentsRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeListTournaments(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListTournamentsRequest) (*api.ListTournamentsRequest, error)) error { ri.beforeReq.beforeListTournamentsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListTournamentsRequest) (*api.ListTournamentsRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterListTournaments(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.TournamentList) error) error { - ri.afterReq.afterListTournamentsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.TournamentList) error { +func (ri *RuntimeGoInitializer) RegisterAfterListTournaments(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.TournamentList, in *api.ListTournamentsRequest) error) error { + ri.afterReq.afterListTournamentsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.TournamentList, in *api.ListTournamentsRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeWriteTournamentRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.WriteTournamentRecordRequest) (*api.WriteTournamentRecordRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeWriteTournamentRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.WriteTournamentRecordRequest) (*api.WriteTournamentRecordRequest, error)) error { ri.beforeReq.beforeWriteTournamentRecordFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.WriteTournamentRecordRequest) (*api.WriteTournamentRecordRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterWriteTournamentRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.LeaderboardRecord) error) error { - ri.afterReq.afterWriteTournamentRecordFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.LeaderboardRecord) error { +func (ri *RuntimeGoInitializer) RegisterAfterWriteTournamentRecord(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.LeaderboardRecord, in *api.WriteTournamentRecordRequest) error) error { + ri.afterReq.afterWriteTournamentRecordFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecord, in *api.WriteTournamentRecordRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeListTournamentRecordsAroundOwner(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListTournamentRecordsAroundOwnerRequest) (*api.ListTournamentRecordsAroundOwnerRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeListTournamentRecordsAroundOwner(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListTournamentRecordsAroundOwnerRequest) (*api.ListTournamentRecordsAroundOwnerRequest, error)) error { ri.beforeReq.beforeListTournamentRecordsAroundOwnerFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ListTournamentRecordsAroundOwnerRequest) (*api.ListTournamentRecordsAroundOwnerRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterListTournamentRecordsAroundOwner(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.TournamentRecordList) error) error { - ri.afterReq.afterListTournamentRecordsAroundOwnerFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.TournamentRecordList) error { +func (ri *RuntimeGoInitializer) RegisterAfterListTournamentRecordsAroundOwner(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.TournamentRecordList, in *api.ListTournamentRecordsAroundOwnerRequest) error) error { + ri.afterReq.afterListTournamentRecordsAroundOwnerFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.TournamentRecordList, in *api.ListTournamentRecordsAroundOwnerRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeUnlinkCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountCustom) (*api.AccountCustom, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeUnlinkCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountCustom) (*api.AccountCustom, error)) error { ri.beforeReq.beforeUnlinkCustomFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountCustom) (*api.AccountCustom, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterUnlinkCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterUnlinkCustomFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterUnlinkCustom(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountCustom) error) error { + ri.afterReq.afterUnlinkCustomFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountCustom) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeUnlinkDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountDevice) (*api.AccountDevice, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeUnlinkDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountDevice) (*api.AccountDevice, error)) error { ri.beforeReq.beforeUnlinkDeviceFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountDevice) (*api.AccountDevice, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterUnlinkDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterUnlinkDeviceFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterUnlinkDevice(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountDevice) error) error { + ri.afterReq.afterUnlinkDeviceFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountDevice) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeUnlinkEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountEmail) (*api.AccountEmail, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeUnlinkEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountEmail) (*api.AccountEmail, error)) error { ri.beforeReq.beforeUnlinkEmailFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountEmail) (*api.AccountEmail, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterUnlinkEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterUnlinkEmailFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterUnlinkEmail(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountEmail) error) error { + ri.afterReq.afterUnlinkEmailFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountEmail) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeUnlinkFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountFacebook) (*api.AccountFacebook, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeUnlinkFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountFacebook) (*api.AccountFacebook, error)) error { ri.beforeReq.beforeUnlinkFacebookFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountFacebook) (*api.AccountFacebook, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterUnlinkFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterUnlinkFacebookFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterUnlinkFacebook(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountFacebook) error) error { + ri.afterReq.afterUnlinkFacebookFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountFacebook) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeUnlinkGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGameCenter) (*api.AccountGameCenter, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeUnlinkGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGameCenter) (*api.AccountGameCenter, error)) error { ri.beforeReq.beforeUnlinkGameCenterFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGameCenter) (*api.AccountGameCenter, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterUnlinkGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterUnlinkGameCenterFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterUnlinkGameCenter(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGameCenter) error) error { + ri.afterReq.afterUnlinkGameCenterFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGameCenter) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeUnlinkGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGoogle) (*api.AccountGoogle, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeUnlinkGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGoogle) (*api.AccountGoogle, error)) error { ri.beforeReq.beforeUnlinkGoogleFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGoogle) (*api.AccountGoogle, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterUnlinkGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterUnlinkGoogleFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterUnlinkGoogle(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGoogle) error) error { + ri.afterReq.afterUnlinkGoogleFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGoogle) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeUnlinkSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountSteam) (*api.AccountSteam, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeUnlinkSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountSteam) (*api.AccountSteam, error)) error { ri.beforeReq.beforeUnlinkSteamFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountSteam) (*api.AccountSteam, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterUnlinkSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *empty.Empty) error) error { - ri.afterReq.afterUnlinkSteamFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) error { +func (ri *RuntimeGoInitializer) RegisterAfterUnlinkSteam(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountSteam) error) error { + ri.afterReq.afterUnlinkSteamFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountSteam) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) return fn(ctx, ri.logger, ri.db, ri.nk, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterBeforeGetUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.GetUsersRequest) (*api.GetUsersRequest, error, int)) error { +func (ri *RuntimeGoInitializer) RegisterBeforeGetUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.GetUsersRequest) (*api.GetUsersRequest, error)) error { ri.beforeReq.beforeGetUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.GetUsersRequest) (*api.GetUsersRequest, error, codes.Code) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeBefore, nil, expiry, userID, username, "", clientIP, clientPort) - result, err, code := fn(ctx, ri.logger, ri.db, ri.nk, in) - return result, err, codes.Code(code) + result, fnErr := fn(ctx, ri.logger, ri.db, ri.nk, in) + if fnErr != nil { + if runtimeErr, ok := fnErr.(*runtime.Error); ok { + if runtimeErr.Code <= 0 || runtimeErr.Code >= 17 { + // If error is present but code is invalid then default to 13 (Internal) as the error code. + return result, runtimeErr, codes.Internal + } + return result, runtimeErr, codes.Code(runtimeErr.Code) + } + // Not a runtime error that contains a code. + return result, fnErr, codes.Internal + } + return result, nil, codes.OK } return nil } -func (ri *RuntimeGoInitialiser) RegisterAfterGetUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Users) error) error { - ri.afterReq.afterGetUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.Users) error { +func (ri *RuntimeGoInitializer) RegisterAfterGetUsers(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, out *api.Users, in *api.GetUsersRequest) error) error { + ri.afterReq.afterGetUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Users, in *api.GetUsersRequest) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeAfter, nil, expiry, userID, username, "", clientIP, clientPort) - return fn(ctx, ri.logger, ri.db, ri.nk, in) + return fn(ctx, ri.logger, ri.db, ri.nk, out, in) } return nil } -func (ri *RuntimeGoInitialiser) RegisterMatchmakerMatched(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, entries []runtime.MatchmakerEntry) (string, error)) error { +func (ri *RuntimeGoInitializer) RegisterMatchmakerMatched(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, entries []runtime.MatchmakerEntry) (string, error)) error { ri.matchmakerMatched = func(entries []*MatchmakerEntry) (string, bool, error) { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeMatchmaker, nil, 0, "", "", "", "", "") runtimeEntries := make([]runtime.MatchmakerEntry, len(entries)) @@ -1073,7 +1706,7 @@ func (ri *RuntimeGoInitialiser) RegisterMatchmakerMatched(fn func(ctx context.Co return nil } -func (ri *RuntimeGoInitialiser) RegisterTournamentEnd(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, tournament *api.Tournament, end, reset int64) error) error { +func (ri *RuntimeGoInitializer) RegisterTournamentEnd(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, tournament *api.Tournament, end, reset int64) error) error { ri.tournamentEnd = func(tournament *api.Tournament, end, reset int64) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeTournamentEnd, nil, 0, "", "", "", "", "") return fn(ctx, ri.logger, ri.db, ri.nk, tournament, end, reset) @@ -1081,7 +1714,7 @@ func (ri *RuntimeGoInitialiser) RegisterTournamentEnd(fn func(ctx context.Contex return nil } -func (ri *RuntimeGoInitialiser) RegisterTournamentReset(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, tournament *api.Tournament, end, reset int64) error) error { +func (ri *RuntimeGoInitializer) RegisterTournamentReset(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, tournament *api.Tournament, end, reset int64) error) error { ri.tournamentReset = func(tournament *api.Tournament, end, reset int64) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeTournamentReset, nil, 0, "", "", "", "", "") return fn(ctx, ri.logger, ri.db, ri.nk, tournament, end, reset) @@ -1089,7 +1722,7 @@ func (ri *RuntimeGoInitialiser) RegisterTournamentReset(fn func(ctx context.Cont return nil } -func (ri *RuntimeGoInitialiser) RegisterLeaderboardReset(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, leaderboard runtime.Leaderboard, reset int64) error) error { +func (ri *RuntimeGoInitializer) RegisterLeaderboardReset(fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule, leaderboard runtime.Leaderboard, reset int64) error) error { ri.leaderboardReset = func(leaderboard runtime.Leaderboard, reset int64) error { ctx := NewRuntimeGoContext(ri.env, RuntimeExecutionModeLeaderboardReset, nil, 0, "", "", "", "", "") return fn(ctx, ri.logger, ri.db, ri.nk, leaderboard, reset) @@ -1097,7 +1730,7 @@ func (ri *RuntimeGoInitialiser) RegisterLeaderboardReset(fn func(ctx context.Con return nil } -func (ri *RuntimeGoInitialiser) RegisterMatch(name string, fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule) (runtime.Match, error)) error { +func (ri *RuntimeGoInitializer) RegisterMatch(name string, fn func(ctx context.Context, logger *log.Logger, db *sql.DB, nk runtime.NakamaModule) (runtime.Match, error)) error { ri.matchLock.Lock() ri.match[name] = fn ri.matchLock.Unlock() @@ -1139,7 +1772,7 @@ func NewRuntimeProviderGo(logger, startupLogger *zap.Logger, db *sql.DB, config return matchNames } - initializer := &RuntimeGoInitialiser{ + initializer := &RuntimeGoInitializer{ logger: stdLogger, db: db, env: env, @@ -1181,7 +1814,7 @@ func NewRuntimeProviderGo(logger, startupLogger *zap.Logger, db *sql.DB, config } // Ensure the function has the correct signature. - fn, ok := f.(func(context.Context, *log.Logger, *sql.DB, runtime.NakamaModule, runtime.Initializer)) + fn, ok := f.(func(context.Context, *log.Logger, *sql.DB, runtime.NakamaModule, runtime.Initializer) error) if !ok { startupLogger.Fatal("Error reading InitModule function in Go module", zap.String("name", name)) return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, errors.New("error reading InitModule function in Go module") diff --git a/server/runtime_lua.go b/server/runtime_lua.go index 85249c7725d4561c3cc02c5f824a7c2759f69985..359de870432b6f17f9c014cd7881b8da0efc41a5 100644 --- a/server/runtime_lua.go +++ b/server/runtime_lua.go @@ -31,7 +31,6 @@ import ( "github.com/gofrs/uuid" "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/proto" - "github.com/golang/protobuf/ptypes/empty" "github.com/heroiclabs/nakama/api" "github.com/heroiclabs/nakama/rtapi" "github.com/heroiclabs/nakama/runtime" @@ -218,12 +217,12 @@ func NewRuntimeProviderLua(logger, startupLogger *zap.Logger, db *sql.DB, jsonpb shortId := strings.TrimPrefix(id, strings.ToLower(API_PREFIX)) switch shortId { case "getaccount": - beforeReqFunctions.beforeGetAccountFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) (*empty.Empty, error, codes.Code) { - result, err, code := runtimeProviderLua.BeforeReq(id, logger, userID, username, expiry, clientIP, clientPort, in) - if result == nil || err != nil { - return nil, err, code + beforeReqFunctions.beforeGetAccountFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string) (error, codes.Code) { + _, err, code := runtimeProviderLua.BeforeReq(id, logger, userID, username, expiry, clientIP, clientPort, nil) + if err != nil { + return err, code } - return result.(*empty.Empty), nil, 0 + return nil, 0 } case "updateaccount": beforeReqFunctions.beforeUpdateAccountFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.UpdateAccountRequest) (*api.UpdateAccountRequest, error, codes.Code) { @@ -298,12 +297,12 @@ func NewRuntimeProviderLua(logger, startupLogger *zap.Logger, db *sql.DB, jsonpb return result.(*api.ListChannelMessagesRequest), nil, 0 } case "listfriends": - beforeReqFunctions.beforeListFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *empty.Empty) (*empty.Empty, error, codes.Code) { - result, err, code := runtimeProviderLua.BeforeReq(id, logger, userID, username, expiry, clientIP, clientPort, in) - if result == nil || err != nil { - return nil, err, code + beforeReqFunctions.beforeListFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string) (error, codes.Code) { + _, err, code := runtimeProviderLua.BeforeReq(id, logger, userID, username, expiry, clientIP, clientPort, nil) + if err != nil { + return err, code } - return result.(*empty.Empty), nil, 0 + return nil, 0 } case "addfriends": beforeReqFunctions.beforeAddFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AddFriendsRequest) (*api.AddFriendsRequest, error, codes.Code) { @@ -685,231 +684,231 @@ func NewRuntimeProviderLua(logger, startupLogger *zap.Logger, db *sql.DB, jsonpb switch shortId { case "getaccount": afterReqFunctions.afterGetAccountFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Account) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, nil) } case "updateaccount": - afterReqFunctions.afterUpdateAccountFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterUpdateAccountFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.UpdateAccountRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "authenticatecustom": - afterReqFunctions.afterAuthenticateCustomFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterAuthenticateCustomFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateCustomRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "authenticatedevice": - afterReqFunctions.afterAuthenticateDeviceFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterAuthenticateDeviceFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateDeviceRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "authenticateemail": - afterReqFunctions.afterAuthenticateEmailFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterAuthenticateEmailFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateEmailRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "authenticatefacebook": - afterReqFunctions.afterAuthenticateFacebookFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterAuthenticateFacebookFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateFacebookRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "authenticategamecenter": - afterReqFunctions.afterAuthenticateGameCenterFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterAuthenticateGameCenterFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateGameCenterRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "authenticategoogle": - afterReqFunctions.afterAuthenticateGoogleFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterAuthenticateGoogleFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateGoogleRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "authenticatesteam": - afterReqFunctions.afterAuthenticateSteamFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterAuthenticateSteamFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Session, in *api.AuthenticateSteamRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "listchannelmessages": - afterReqFunctions.afterListChannelMessagesFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.ChannelMessageList) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterListChannelMessagesFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.ChannelMessageList, in *api.ListChannelMessagesRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "listfriends": afterReqFunctions.afterListFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Friends) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, nil) } case "addfriends": - afterReqFunctions.afterAddFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterAddFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AddFriendsRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "deletefriends": - afterReqFunctions.afterDeleteFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterDeleteFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteFriendsRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "blockfriends": - afterReqFunctions.afterBlockFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterBlockFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.BlockFriendsRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "importfacebookfriends": - afterReqFunctions.afterImportFacebookFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterImportFacebookFriendsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.ImportFacebookFriendsRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "creategroup": - afterReqFunctions.afterCreateGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Group) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterCreateGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Group, in *api.CreateGroupRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "updategroup": - afterReqFunctions.afterUpdateGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterUpdateGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.UpdateGroupRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "deletegroup": - afterReqFunctions.afterDeleteGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterDeleteGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteGroupRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "joingroup": - afterReqFunctions.afterJoinGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterJoinGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.JoinGroupRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "leavegroup": - afterReqFunctions.afterLeaveGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterLeaveGroupFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.LeaveGroupRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "addgroupusers": - afterReqFunctions.afterAddGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterAddGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AddGroupUsersRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "kickgroupusers": - afterReqFunctions.afterKickGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterKickGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.KickGroupUsersRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "promotegroupusers": - afterReqFunctions.afterPromoteGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterPromoteGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.PromoteGroupUsersRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "listgroupusers": - afterReqFunctions.afterListGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.GroupUserList) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterListGroupUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.GroupUserList, in *api.ListGroupUsersRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "listusergroups": - afterReqFunctions.afterListUserGroupsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.UserGroupList) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterListUserGroupsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.UserGroupList, in *api.ListUserGroupsRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "listgroups": - afterReqFunctions.afterListGroupsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.GroupList) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterListGroupsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.GroupList, in *api.ListGroupsRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "deleteleaderboardrecord": - afterReqFunctions.afterDeleteLeaderboardRecordFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterDeleteLeaderboardRecordFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteLeaderboardRecordRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "listleaderboardrecords": - afterReqFunctions.afterListLeaderboardRecordsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecordList) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterListLeaderboardRecordsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecordList, in *api.ListLeaderboardRecordsRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "writeleaderboardrecord": - afterReqFunctions.afterWriteLeaderboardRecordFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecord) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterWriteLeaderboardRecordFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecord, in *api.WriteLeaderboardRecordRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "listleaderboardrecordsaroundowner": - afterReqFunctions.afterListLeaderboardRecordsAroundOwnerFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecordList) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterListLeaderboardRecordsAroundOwnerFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecordList, in *api.ListLeaderboardRecordsAroundOwnerRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "linkcustom": - afterReqFunctions.afterLinkCustomFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterLinkCustomFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountCustom) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "linkdevice": - afterReqFunctions.afterLinkDeviceFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterLinkDeviceFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountDevice) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "linkemail": - afterReqFunctions.afterLinkEmailFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterLinkEmailFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountEmail) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "linkfacebook": - afterReqFunctions.afterLinkFacebookFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterLinkFacebookFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.LinkFacebookRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "linkgamecenter": - afterReqFunctions.afterLinkGameCenterFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterLinkGameCenterFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGameCenter) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "linkgoogle": - afterReqFunctions.afterLinkGoogleFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterLinkGoogleFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGoogle) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "linksteam": - afterReqFunctions.afterLinkSteamFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterLinkSteamFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountSteam) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "listmatches": - afterReqFunctions.afterListMatchesFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.MatchList) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterListMatchesFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.MatchList, in *api.ListMatchesRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "listnotifications": - afterReqFunctions.afterListNotificationsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.NotificationList) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterListNotificationsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.NotificationList, in *api.ListNotificationsRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "deletenotification": - afterReqFunctions.afterDeleteNotificationFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterDeleteNotificationFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteNotificationsRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "liststorageobjects": - afterReqFunctions.afterListStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.StorageObjectList) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterListStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.StorageObjectList, in *api.ListStorageObjectsRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "readstorageobjects": - afterReqFunctions.afterReadStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.StorageObjects) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterReadStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.StorageObjects, in *api.ReadStorageObjectsRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "writestorageobjects": - afterReqFunctions.afterWriteStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.StorageObjectAcks) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterWriteStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.StorageObjectAcks, in *api.WriteStorageObjectsRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "deletestorageobjects": - afterReqFunctions.afterDeleteStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterDeleteStorageObjectsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.DeleteStorageObjectsRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "jointournament": - afterReqFunctions.afterJoinTournamentFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterJoinTournamentFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.JoinTournamentRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "listtournamentrecords": - afterReqFunctions.afterListTournamentRecordsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.TournamentRecordList) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterListTournamentRecordsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.TournamentRecordList, in *api.ListTournamentRecordsRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "listtournaments": - afterReqFunctions.afterListTournamentsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.TournamentList) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterListTournamentsFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.TournamentList, in *api.ListTournamentsRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "writetournamentrecord": - afterReqFunctions.afterWriteTournamentRecordFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecord) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterWriteTournamentRecordFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.LeaderboardRecord, in *api.WriteTournamentRecordRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "listtournamentrecordsaroundowner": - afterReqFunctions.afterListTournamentRecordsAroundOwnerFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.TournamentRecordList) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterListTournamentRecordsAroundOwnerFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.TournamentRecordList, in *api.ListTournamentRecordsAroundOwnerRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } case "unlinkcustom": - afterReqFunctions.afterUnlinkCustomFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterUnlinkCustomFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountCustom) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "unlinkdevice": - afterReqFunctions.afterUnlinkDeviceFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterUnlinkDeviceFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountDevice) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "unlinkemail": - afterReqFunctions.afterUnlinkEmailFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterUnlinkEmailFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountEmail) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "unlinkfacebook": - afterReqFunctions.afterUnlinkFacebookFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterUnlinkFacebookFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountFacebook) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "unlinkgamecenter": - afterReqFunctions.afterUnlinkGameCenterFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterUnlinkGameCenterFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGameCenter) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "unlinkgoogle": - afterReqFunctions.afterUnlinkGoogleFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterUnlinkGoogleFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountGoogle) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "unlinksteam": - afterReqFunctions.afterUnlinkSteamFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *empty.Empty) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterUnlinkSteamFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, in *api.AccountSteam) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, nil, in) } case "getusers": - afterReqFunctions.afterGetUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Users) error { - return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out) + afterReqFunctions.afterGetUsersFunction = func(logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, out *api.Users, in *api.GetUsersRequest) error { + return runtimeProviderLua.AfterReq(id, logger, userID, username, expiry, clientIP, clientPort, out, in) } } } @@ -1115,23 +1114,28 @@ func (rp *RuntimeProviderLua) BeforeReq(id string, logger *zap.Logger, userID, u return nil, errors.New("Runtime Before function not found."), codes.NotFound } - reqProto, ok := req.(proto.Message) - if !ok { - rp.Put(runtime) - logger.Error("Could not cast request to message", zap.Any("request", req)) - return nil, errors.New("Could not run runtime Before function."), codes.Internal - } - reqJSON, err := rp.jsonpbMarshaler.MarshalToString(reqProto) - if err != nil { - rp.Put(runtime) - logger.Error("Could not marshall request to JSON", zap.Any("request", reqProto), zap.Error(err)) - return nil, errors.New("Could not run runtime Before function."), codes.Internal - } var reqMap map[string]interface{} - if err := json.Unmarshal([]byte(reqJSON), &reqMap); err != nil { - rp.Put(runtime) - logger.Error("Could not unmarshall request to interface{}", zap.Any("request_json", reqJSON), zap.Error(err)) - return nil, errors.New("Could not run runtime Before function."), codes.Internal + var reqProto proto.Message + if req != nil { + // Req may be nil for requests that carry no input body. + var ok bool + reqProto, ok = req.(proto.Message) + if !ok { + rp.Put(runtime) + logger.Error("Could not cast request to message", zap.Any("request", req)) + return nil, errors.New("Could not run runtime Before function."), codes.Internal + } + reqJSON, err := rp.jsonpbMarshaler.MarshalToString(reqProto) + if err != nil { + rp.Put(runtime) + logger.Error("Could not marshall request to JSON", zap.Any("request", reqProto), zap.Error(err)) + return nil, errors.New("Could not run runtime Before function."), codes.Internal + } + if err := json.Unmarshal([]byte(reqJSON), &reqMap); err != nil { + rp.Put(runtime) + logger.Error("Could not unmarshall request to interface{}", zap.Any("request_json", reqJSON), zap.Error(err)) + return nil, errors.New("Could not run runtime Before function."), codes.Internal + } } result, fnErr, code := runtime.InvokeFunction(RuntimeExecutionModeBefore, lf, nil, userID, username, expiry, "", clientIP, clientPort, reqMap) @@ -1156,7 +1160,8 @@ func (rp *RuntimeProviderLua) BeforeReq(id string, logger *zap.Logger, userID, u } } - if result == nil { + if result == nil || reqMap == nil { + // There was no return value, or a return value was not expected (no input to override). return nil, nil, 0 } @@ -1174,7 +1179,7 @@ func (rp *RuntimeProviderLua) BeforeReq(id string, logger *zap.Logger, userID, u return req, nil, 0 } -func (rp *RuntimeProviderLua) AfterReq(id string, logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, req interface{}) error { +func (rp *RuntimeProviderLua) AfterReq(id string, logger *zap.Logger, userID, username string, expiry int64, clientIP, clientPort string, res interface{}, req interface{}) error { runtime := rp.Get() lf := runtime.GetCallback(RuntimeExecutionModeAfter, id) if lf == nil { @@ -1182,26 +1187,53 @@ func (rp *RuntimeProviderLua) AfterReq(id string, logger *zap.Logger, userID, us return errors.New("Runtime After function not found.") } - reqProto, ok := req.(proto.Message) - if !ok { - rp.Put(runtime) - logger.Error("Could not cast request to message", zap.Any("request", req)) - return errors.New("Could not run runtime After function.") - } - reqJSON, err := rp.jsonpbMarshaler.MarshalToString(reqProto) - if err != nil { - rp.Put(runtime) - logger.Error("Could not marshall request to JSON", zap.Any("request", reqProto), zap.Error(err)) - return errors.New("Could not run runtime After function.") + var resMap map[string]interface{} + if res != nil { + // Res may be nil if there is no response body. + resProto, ok := res.(proto.Message) + if !ok { + rp.Put(runtime) + logger.Error("Could not cast response to message", zap.Any("response", res)) + return errors.New("Could not run runtime After function.") + } + resJSON, err := rp.jsonpbMarshaler.MarshalToString(resProto) + if err != nil { + rp.Put(runtime) + logger.Error("Could not marshall response to JSON", zap.Any("response", resProto), zap.Error(err)) + return errors.New("Could not run runtime After function.") + } + + if err := json.Unmarshal([]byte(resJSON), &resMap); err != nil { + rp.Put(runtime) + logger.Error("Could not unmarshall response to interface{}", zap.Any("response_json", resJSON), zap.Error(err)) + return errors.New("Could not run runtime After function.") + } } + var reqMap map[string]interface{} - if err := json.Unmarshal([]byte(reqJSON), &reqMap); err != nil { - rp.Put(runtime) - logger.Error("Could not unmarshall request to interface{}", zap.Any("request_json", reqJSON), zap.Error(err)) - return errors.New("Could not run runtime After function.") + if req != nil { + // Req may be nil if there is no request body. + reqProto, ok := req.(proto.Message) + if !ok { + rp.Put(runtime) + logger.Error("Could not cast request to message", zap.Any("request", req)) + return errors.New("Could not run runtime After function.") + } + reqJSON, err := rp.jsonpbMarshaler.MarshalToString(reqProto) + if err != nil { + rp.Put(runtime) + logger.Error("Could not marshall request to JSON", zap.Any("request", reqProto), zap.Error(err)) + return errors.New("Could not run runtime After function.") + } + + if err := json.Unmarshal([]byte(reqJSON), &reqMap); err != nil { + rp.Put(runtime) + logger.Error("Could not unmarshall request to interface{}", zap.Any("request_json", reqJSON), zap.Error(err)) + return errors.New("Could not run runtime After function.") + } } - _, fnErr, _ := runtime.InvokeFunction(RuntimeExecutionModeBefore, lf, nil, userID, username, expiry, "", clientIP, clientPort, reqMap) + _, fnErr, _ := runtime.InvokeFunction(RuntimeExecutionModeBefore, lf, nil, userID, username, expiry, "", clientIP, clientPort, resMap, reqMap) rp.Put(runtime) if fnErr != nil { @@ -1571,14 +1603,14 @@ func (r *RuntimeLua) GetCallback(e RuntimeExecutionMode, key string) *lua.LFunct return nil } -func (r *RuntimeLua) InvokeFunction(execMode RuntimeExecutionMode, fn *lua.LFunction, queryParams map[string][]string, uid string, username string, sessionExpiry int64, sid string, clientIP string, clientPort string, payload interface{}) (interface{}, error, codes.Code) { +func (r *RuntimeLua) InvokeFunction(execMode RuntimeExecutionMode, fn *lua.LFunction, queryParams map[string][]string, uid string, username string, sessionExpiry int64, sid string, clientIP string, clientPort string, payloads ...interface{}) (interface{}, error, codes.Code) { ctx := NewRuntimeLuaContext(r.vm, r.luaEnv, execMode, queryParams, sessionExpiry, uid, username, sid, clientIP, clientPort) - var lv lua.LValue - if payload != nil { - lv = RuntimeLuaConvertValue(r.vm, payload) + lv := make([]lua.LValue, 0, len(payloads)) + for _, payload := range payloads { + lv = append(lv, RuntimeLuaConvertValue(r.vm, payload)) } - retValue, err, code := r.invokeFunction(r.vm, fn, ctx, lv) + retValue, err, code := r.invokeFunction(r.vm, fn, ctx, lv...) if err != nil { return nil, err, code }