保护API #

有许多情况都需要限制或完全阻止客户端访问任何或所有Nakama API,例如对客户端请求执行任何所需的验证或防止客户端试图绕过您的游戏逻辑。

Nakama提供了多种途径来保护您的游戏,防范恶意客户端操作:

  • 在服务器上实现RPC或挂钩式游戏逻辑
  • 对存储对象设置访问控制。通过REST API创建的对象将始终由经过身份验证的用户拥有,您可以设置相应的读取权限来设置其他玩家是否具有对此数据的读取权限。
  • 服务器到服务器调用可通过HTTP密钥保护。
  • 使用before挂钩禁用不想让任何开发的直接访问的API。

使用before挂钩 #

要禁用任何API,在想要禁用的函数调用上注册before挂钩,而不返回请求输入而返回nil。Nakama会将任何此类情况当作禁用API调用自动处理。

在以下示例实现中,所有被注释掉的消息名称和API调用对客户端仍然可用,而其他所有消息名称和调用都被禁用:

Server
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
package metagame

import (
  "context"
  "database/sql"

  "github.com/heroiclabs/nakama-common/api"
  "github.com/heroiclabs/nakama-common/rtapi"
  "github.com/heroiclabs/nakama-common/runtime"
)

func registerGuard(initializer runtime.Initializer) error {
  rtMessages := []string{
    //"ChannelJoin",
    //"ChannelLeave",
    //"ChannelMessageSend",
    "ChannelMessageUpdate",
    "ChannelMessageRemove",
    "MatchCreate",
    //"MatchDataSend",
    //"MatchJoin",
    //"MatchLeave",
    "MatchmakerAdd",
    "MatchmakerRemove",
    "PartyCreate",
    "PartyCreate",
    "PartyJoin",
    "PartyLeave",
    "PartyPromote",
    "PartyAccept",
    "PartyRemove",
    "PartyClose",
    "PartyJoinRequestList",
    "PartyMatchmakerAdd",
    "PartyMatchmakerRemove",
    "PartyDataSend",
    //"Ping",
    //"Pong",
    //"Rpc",
    "StatusFollow",
    "StatusUnfollow",
    "StatusUpdate",
  }
  for _, rtMessage := range rtMessages {
    if err := initializer.RegisterBeforeRt(rtMessage, func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, envelope *rtapi.Envelope) (*rtapi.Envelope, error) {
      return nil, nil
    }); err != nil {
      return err
    }
  }

  if err := initializer.RegisterBeforeGetAccount(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule) error {
    return nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeUpdateAccount(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.UpdateAccountRequest) (*api.UpdateAccountRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  //if err := initializer.RegisterBeforeSessionRefresh(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.SessionRefreshRequest) (*api.SessionRefreshRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  //if err := initializer.RegisterBeforeAuthenticateApple(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateAppleRequest) (*api.AuthenticateAppleRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeAuthenticateCustom(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateCustomRequest) (*api.AuthenticateCustomRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeAuthenticateDevice(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateDeviceRequest) (*api.AuthenticateDeviceRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeAuthenticateEmail(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateEmailRequest) (*api.AuthenticateEmailRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeAuthenticateFacebook(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateFacebookRequest) (*api.AuthenticateFacebookRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeAuthenticateFacebookInstantGame(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateFacebookInstantGameRequest) (*api.AuthenticateFacebookInstantGameRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeAuthenticateGameCenter(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateGameCenterRequest) (*api.AuthenticateGameCenterRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  //if err := initializer.RegisterBeforeAuthenticateGoogle(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateGoogleRequest) (*api.AuthenticateGoogleRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeAuthenticateSteam(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AuthenticateSteamRequest) (*api.AuthenticateSteamRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeListChannelMessages(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListChannelMessagesRequest) (*api.ListChannelMessagesRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeListFriends(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListFriendsRequest) (*api.ListFriendsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeAddFriends(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AddFriendsRequest) (*api.AddFriendsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeDeleteFriends(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteFriendsRequest) (*api.DeleteFriendsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeBlockFriends(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.BlockFriendsRequest) (*api.BlockFriendsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeImportFacebookFriends(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ImportFacebookFriendsRequest) (*api.ImportFacebookFriendsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeCreateGroup(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.CreateGroupRequest) (*api.CreateGroupRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeUpdateGroup(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.UpdateGroupRequest) (*api.UpdateGroupRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeDeleteGroup(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteGroupRequest) (*api.DeleteGroupRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeJoinGroup(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.JoinGroupRequest) (*api.JoinGroupRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeLeaveGroup(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.LeaveGroupRequest) (*api.LeaveGroupRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  // if err := initializer.RegisterBeforeAddGroupUsers(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AddGroupUsersRequest) (*api.AddGroupUsersRequest, error) {
  // 	return nil, nil
  // }); err != nil {
  // 	return err
  // }
  if err := initializer.RegisterBeforeBanGroupUsers(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.BanGroupUsersRequest) (*api.BanGroupUsersRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  // if err := initializer.RegisterBeforeKickGroupUsers(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.KickGroupUsersRequest) (*api.KickGroupUsersRequest, error) {
  // 	return nil, nil
  // }); err != nil {
  // 	return err
  // }
  // if err := initializer.RegisterBeforePromoteGroupUsers(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.PromoteGroupUsersRequest) (*api.PromoteGroupUsersRequest, error) {
  // 	return nil, nil
  // }); err != nil {
  // 	return err
  // }
  // if err := initializer.RegisterBeforeDemoteGroupUsers(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DemoteGroupUsersRequest) (*api.DemoteGroupUsersRequest, error) {
  // 	return nil, nil
  // }); err != nil {
  // 	return err
  // }
  // if err := initializer.RegisterBeforeListGroupUsers(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListGroupUsersRequest) (*api.ListGroupUsersRequest, error) {
  // 	return nil, nil
  // }); err != nil {
  // 	return err
  // }
  // if err := initializer.RegisterBeforeListUserGroups(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListUserGroupsRequest) (*api.ListUserGroupsRequest, error) {
  // 	return nil, nil
  // }); err != nil {
  // 	return err
  // }
  // if err := initializer.RegisterBeforeListGroups(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListGroupsRequest) (*api.ListGroupsRequest, error) {
  // 	return nil, nil
  // }); err != nil {
  // 	return err
  // }
  if err := initializer.RegisterBeforeDeleteLeaderboardRecord(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteLeaderboardRecordRequest) (*api.DeleteLeaderboardRecordRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeListLeaderboardRecords(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListLeaderboardRecordsRequest) (*api.ListLeaderboardRecordsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeWriteLeaderboardRecord(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.WriteLeaderboardRecordRequest) (*api.WriteLeaderboardRecordRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeListLeaderboardRecordsAroundOwner(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListLeaderboardRecordsAroundOwnerRequest) (*api.ListLeaderboardRecordsAroundOwnerRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeLinkApple(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountApple) (*api.AccountApple, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeLinkCustom(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountCustom) (*api.AccountCustom, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeLinkDevice(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountDevice) (*api.AccountDevice, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeLinkEmail(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountEmail) (*api.AccountEmail, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeLinkFacebook(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.LinkFacebookRequest) (*api.LinkFacebookRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeLinkFacebookInstantGame(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountFacebookInstantGame) (*api.AccountFacebookInstantGame, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeLinkGameCenter(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGameCenter) (*api.AccountGameCenter, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  //if err := initializer.RegisterBeforeLinkGoogle(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGoogle) (*api.AccountGoogle, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeLinkSteam(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.LinkSteamRequest) (*api.LinkSteamRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeListMatches(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListMatchesRequest) (*api.ListMatchesRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeListNotifications(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListNotificationsRequest) (*api.ListNotificationsRequest, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  // if err := initializer.RegisterBeforeDeleteNotification(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteNotificationsRequest) (*api.DeleteNotificationsRequest, error) {
  // 	return nil, nil
  // }); err != nil {
  // 	return err
  // }
  if err := initializer.RegisterBeforeListStorageObjects(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListStorageObjectsRequest) (*api.ListStorageObjectsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeReadStorageObjects(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ReadStorageObjectsRequest) (*api.ReadStorageObjectsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeWriteStorageObjects(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.WriteStorageObjectsRequest) (*api.WriteStorageObjectsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeDeleteStorageObjects(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.DeleteStorageObjectsRequest) (*api.DeleteStorageObjectsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeJoinTournament(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.JoinTournamentRequest) (*api.JoinTournamentRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeListTournamentRecords(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListTournamentRecordsRequest) (*api.ListTournamentRecordsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeListTournaments(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListTournamentsRequest) (*api.ListTournamentsRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeWriteTournamentRecord(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.WriteTournamentRecordRequest) (*api.WriteTournamentRecordRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeListTournamentRecordsAroundOwner(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.ListTournamentRecordsAroundOwnerRequest) (*api.ListTournamentRecordsAroundOwnerRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeUnlinkApple(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountApple) (*api.AccountApple, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeUnlinkCustom(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountCustom) (*api.AccountCustom, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeUnlinkDevice(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountDevice) (*api.AccountDevice, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeUnlinkEmail(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountEmail) (*api.AccountEmail, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  //if err := initializer.RegisterBeforeUnlinkFacebook(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountFacebook) (*api.AccountFacebook, error) {
  //	return nil, nil
  //}); err != nil {
  //	return err
  //}
  if err := initializer.RegisterBeforeUnlinkFacebookInstantGame(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountFacebookInstantGame) (*api.AccountFacebookInstantGame, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeUnlinkGameCenter(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGameCenter) (*api.AccountGameCenter, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeUnlinkGoogle(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountGoogle) (*api.AccountGoogle, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeUnlinkSteam(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.AccountSteam) (*api.AccountSteam, error) {
    return nil, nil
  }); err != nil {
    return err
  }
  if err := initializer.RegisterBeforeGetUsers(func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, in *api.GetUsersRequest) (*api.GetUsersRequest, error) {
    return nil, nil
  }); err != nil {
    return err
  }

  return nil
}
Server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
let InitModule: nkruntime.InitModule = function (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, initializer: nkruntime.Initializer) {
  // initializer.registerRtBefore("ChannelJoin", guardFunction);
  // initializer.registerRtBefore("ChannelLeave", guardFunction);
  // initializer.registerRtBefore("ChannelMessageSend", guardFunction);
  initializer.registerRtBefore("ChannelMessageUpdate", guardFunction);
  initializer.registerRtBefore("ChannelMessageRemove", guardFunction);
  initializer.registerRtBefore("MatchCreate", guardFunction);
  // initializer.registerRtBefore("MatchDataSend", guardFunction);
  // initializer.registerRtBefore("MatchJoin", guardFunction);
  // initializer.registerRtBefore("MatchLeave", guardFunction);
  initializer.registerRtBefore("MatchmakerAdd", guardFunction);
  initializer.registerRtBefore("MatchmakerRemove", guardFunction);
  // initializer.registerRtBefore("Ping", guardFunction);
  // initializer.registerRtBefore("Pong", guardFunction);
  initializer.registerRtBefore("StatusFollow", guardFunction);
  initializer.registerRtBefore("StatusUnfollow", guardFunction);
  initializer.registerRtBefore("StatusUpdate", guardFunction);
  // initializer.registerBeforeUpdateAccount(guardFunction);
  // initializer.registerBeforeAuthenticateApple(guardFunction);
  initializer.registerBeforeAuthenticateCustom(guardFunction);
  // initializer.registerBeforeAuthenticateDevice(guardFunction);
  initializer.registerBeforeAuthenticateEmail(guardFunction);
  // initializer.registerBeforeAuthenticateFacebook(guardFunction);
  initializer.registerBeforeAuthenticateFacebookInstantGame(guardFunction);
  // initializer.registerBeforeAuthenticateGameCenter(guardFunction);
  // initializer.registerBeforeAuthenticateGoogle(guardFunction);
  initializer.registerBeforeAuthenticateSteam(guardFunction);
  // initializer.registerBeforeListChannelMessages(guardFunction);
  initializer.registerBeforeListFriends(guardFunction);
  initializer.registerBeforeAddFriends(guardFunction);
  initializer.registerBeforeDeleteFriends(guardFunction);
  initializer.registerBeforeBlockFriends(guardFunction);
  initializer.registerBeforeImportFacebookFriends(guardFunction);
  initializer.registerBeforeCreateGroup(guardFunction);
  initializer.registerBeforeUpdateGroup(guardFunction);
  initializer.registerBeforeDeleteGroup(guardFunction);
  initializer.registerBeforeJoinGroup(guardFunction);
  initializer.registerBeforeLeaveGroup(guardFunction);
  // initializer.registerBeforeAddGroupUsers(guardFunction);
  initializer.registerBeforeBanGroupUsers(guardFunction);
  // initializer.registerBeforeKickGroupUsers(guardFunction);
  // initializer.registerBeforePromoteGroupUsers(guardFunction);
  // initializer.registerBeforeDemoteGroupUsers(guardFunction);
  // initializer.registerBeforeListGroupUsers(guardFunction);
  // initializer.registerBeforeListUserGroups(guardFunction);
  // initializer.registerBeforeListGroups(guardFunction);
  initializer.registerBeforeDeleteLeaderboardRecord(guardFunction);
  initializer.registerBeforeListLeaderboardRecords(guardFunction);
  initializer.registerBeforeWriteLeaderboardRecord(guardFunction);
  initializer.registerBeforeListLeaderboardRecordsAroundOwner(guardFunction);
  // initializer.registerBeforeLinkApple(guardFunction);
  initializer.registerBeforeLinkCustom(guardFunction);
  // initializer.registerBeforeLinkDevice(guardFunction);
  initializer.registerBeforeLinkEmail(guardFunction);
  // initializer.registerBeforeLinkFacebook(guardFunction);
  initializer.registerBeforeLinkFacebookInstantGame(guardFunction);
  // initializer.registerBeforeLinkGameCenter(guardFunction);
  // initializer.registerBeforeLinkGoogle(guardFunction);
  initializer.registerBeforeLinkSteam(guardFunction);
  // initializer.registerBeforeListNotifications(guardFunction);
  // initializer.registerBeforeDeleteNotifications(guardFunction);
  initializer.registerBeforeListStorageObjects(guardFunction);
  initializer.registerBeforeReadStorageObjects(guardFunction);
  initializer.registerBeforeWriteStorageObjects(guardFunction);
  initializer.registerBeforeDeleteStorageObjects(guardFunction);
  initializer.registerBeforeJoinTournament(guardFunction);
  initializer.registerBeforeListTournamentRecords(guardFunction);
  initializer.registerBeforeListTournaments(guardFunction);
  initializer.registerBeforeWriteTournamentRecord(guardFunction);
  initializer.registerBeforeListTournamentRecordsAroundOwner(guardFunction);
  // initializer.registerBeforeUnlinkApple(guardFunction);
  initializer.registerBeforeUnlinkCustom(guardFunction);
  // initializer.registerBeforeUnlinkDevice(guardFunction);
  initializer.registerBeforeUnlinkEmail(guardFunction);
  // initializer.registerBeforeUnlinkFacebook(guardFunction);
  initializer.registerBeforeUnlinkFacebookInstantGame(guardFunction);
  initializer.registerBeforeUnlinkGameCenter(guardFunction);
  initializer.registerBeforeUnlinkSteam(guardFunction);
  initializer.registerBeforeGetUsers(guardFunction);
}

const guardFunction = function() {
  return null;
};

// Reference InitModule to avoid it getting removed on build
!InitModule && InitModule.bind(null);
Code snippet for this language Lua has not been found. Please choose another language to show equivalent examples.
无法返回null以防止TypeScript服务器运行时中的registerBeforeGetAccount函数。如需防止TypeScript中的此函数,可以抛出错误,例如throw new Error("Function disabled")。注意,这将在Nakama中生成错误记录。