-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathindex.d.ts
5360 lines (4740 loc) · 188 KB
/
index.d.ts
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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2021 The Nakama Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
declare namespace nkruntime {
// System User
const SystemUserId = "00000000-0000-0000-0000-000000000000";
/**
* The context of the current execution; used to observe and pass on cancellation signals.
*/
export type Context = {
env: {[key: string]: string},
executionMode: string,
node: string,
version: string,
headers?: {[key: string]: string[]},
queryParams?: {[key: string]: string[]},
userId?: string,
username?: string,
vars?: {[key: string]: string}
userSessionExp?: number,
sessionId?: string,
clientIp?: string,
clientPort?: string,
matchId?: string,
matchNode?: string,
matchLabel?: string,
matchTickRate?: number,
lang?: string,
}
type ReadPermissionValues = 0 | 1 | 2;
type WritePermissionValues = 0 | 1;
/**
* GRPC Error codes supported for thrown custom errors.
*
* These errors map to HTTP status codes as shown here: https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md/.
*/
const enum Codes {
// HTTP Mapping: 499 Client Closed Request
CANCELLED = 1, // The operation was cancelled, typically by the caller.
// HTTP Mapping: 500 Internal Server Error
UNKNOWN = 2, // Unknown error. For example, this error may be returned when a Status value received from another address space belongs to an error space that is not known in this address space. Also errors raised by APIs that do not return enough error information may be converted to this error.
// HTTP Mapping: 400 Bad Request
INVALID_ARGUMENT = 3, // The client specified an invalid argument. Note that this differs from FAILED_PRECONDITION. INVALID_ARGUMENT indicates arguments that are problematic regardless of the state of the system (e.g., a malformed file name).
// HTTP Mapping: 504 Gateway Timeout
DEADLINE_EXCEEDED = 4, // The deadline expired before the operation could complete. For operations that change the state of the system, this error may be returned even if the operation has completed successfully. For example, a successful response from a server could have been delayed long
// HTTP Mapping: 404 Not Found
NOT_FOUND = 5, // Some requested entity (e.g., file or directory) was not found. Note to server developers: if a request is denied for an entire class of users, such as gradual feature rollout or undocumented allowlist, NOT_FOUND may be used. If a request is denied for some users within a class of users, such as user-based access control, PERMISSION_DENIED must be used.
// HTTP Mapping: 409 Conflict
ALREADY_EXISTS = 6, // The entity that a client attempted to create (e.g., file or directory) already exists.
// HTTP Mapping: 403 Forbidden
PERMISSION_DENIED = 7, // The caller does not have permission to execute the specified operation. PERMISSION_DENIED must not be used for rejections caused by exhausting some resource (use RESOURCE_EXHAUSTED instead for those errors). PERMISSION_DENIED must not be used if the caller can not be identified (use UNAUTHENTICATED instead for those errors). This error code does not imply the request is valid or the requested entity exists or satisfies other pre-conditions.
// HTTP Mapping: 429 Too Many Requests
RESOURCE_EXHAUSTED = 8, // Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space.
// HTTP Mapping: 400 Bad Request
FAILED_PRECONDITION = 9, // The operation was rejected because the system is not in a state required for the operation's execution. For example, the directory to be deleted is non-empty, an rmdir operation is applied to a non-directory, etc. Service implementors can use the following guidelines to decide between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE: (a) Use UNAVAILABLE if the client can retry just the failing call. (b) Use ABORTED if the client should retry at a higher level (e.g., when a client-specified test-and-set fails, indicating the client should restart a read-modify-write sequence). (c) Use FAILED_PRECONDITION if the client should not retry until the system state has been explicitly fixed. E.g., if an "rmdir" fails because the directory is non-empty, FAILED_PRECONDITION should be returned since the client should not retry unless the files are deleted from the directory.
// HTTP Mapping: 409 Conflict
ABORTED = 10, // The operation was aborted, typically due to a concurrency issue such as a sequencer check failure or transaction abort. See the guidelines above for deciding between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE.
// HTTP Mapping: 400 Bad Request
OUT_OF_RANGE = 11, // The operation was attempted past the valid range. E.g., seeking or reading past end-of-file. Unlike INVALID_ARGUMENT, this error indicates a problem that may be fixed if the system state changes. For example, a 32-bit file system will generate INVALID_ARGUMENT if asked to read at an offset that is not in the range [0,2^32-1], but it will generate OUT_OF_RANGE if asked to read from an offset past the current file size. There is a fair bit of overlap between FAILED_PRECONDITION and OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more specific error) when it applies so that callers who are iterating through a space can easily look for an OUT_OF_RANGE error to detect when they are done.
// HTTP Mapping: 501 Not Implemented
UNIMPLEMENTED = 12, // The operation is not implemented or is not supported/enabled in this service.
// HTTP Mapping: 500 Internal Server Error
INTERNAL = 13, // Internal errors. This means that some invariants expected by the underlying system have been broken. This error code is reserved for serious errors.
// HTTP Mapping: 503 Service Unavailable
UNAVAILABLE = 14, // The service is currently unavailable. This is most likely a transient condition, which can be corrected by retrying with a backoff. Note that it is not always safe to retry non-idempotent operations.
// HTTP Mapping: 500 Internal Server Error
DATA_LOSS = 15, // Unrecoverable data loss or corruption.
// HTTP Mapping: 401 Unauthorized
UNAUTHENTICATED = 16, // The request does not have valid authentication credentials for the operation.
}
/**
* A custom Runtime Error
*/
export type Error = {
message: string
code: Codes
}
/**
* An RPC function definition.
*/
export interface RpcFunction {
/**
* An RPC function to be executed when called by ID.
*
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
* @param payload - The input data to the function call. This is usually an escaped JSON object.
* @throws {TypeError}
* @returns A response payload or error if one occurred.
*/
(ctx: Context, logger: Logger, nk: Nakama, payload: string): string | void;
}
/**
* A Before Hook function definition.
*/
export interface BeforeHookFunction<T> {
/**
* A Register Hook function definition.
*
* @remarks
* The function must return the T payload as this is what will be passed on to the hooked function.
* Return null to bail out of executing the function instead.
*
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
* @param data - The input data to the function call.
* @returns The escaped JSON payload.
*/
(ctx: Context, logger: Logger, nk: Nakama, data: T): T | void;
}
/**
* A After Hook function definition.
*/
export interface AfterHookFunction<T, K> {
/**
* A Register Hook function definition.
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
* @param data - The data returned by the function call.
* @param request - The request payload.
*/
(ctx: Context, logger: Logger, nk: Nakama, data: T, request: K): void;
}
/**
* A realtime before hook function definition.
*/
export interface RtBeforeHookFunction<T extends Envelope> {
/**
* A Register Hook function definition.
*
* * @remarks
* The function must return the T payload as this is what will be passed on to the hooked function.
* Return null to bail out of executing the function instead.
*
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
* @param envelope - The Envelope message received by the function.
*/
(ctx: Context, logger: Logger, nk: Nakama, envelope: T): T | void;
}
/**
* A realtime after hook function definition.
*/
export interface RtAfterHookFunction<T extends Envelope> {
/**
* A Register Hook function definition.
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
* @param output - The response envelope, if any.
* @param input - The Envelope message received by the function.
*/
(ctx: Context, logger: Logger, nk: Nakama, output: T | null, input: T): void;
}
/**
* Matchmaker matched hook function definition.
*/
export interface MatchmakerMatchedFunction {
/**
* A Matchmaker matched register hook function definition.
*
* @remarks
* Expected to return an authoritative match ID for a match ready to receive
* these users, or void if the match should proceed through the peer-to-peer relayed mode.
*
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
* @param matches - The matched users presences and properties.
*/
(ctx: Context, logger: Logger, nk: Nakama, matches: MatchmakerResult[]): string | void;
}
/**
* Tournament end hook function definition.
*/
export interface TournamentEndFunction {
/**
* A Tournament end register hook function definition.
*
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
* @param tournament - The ended tournament.
* @param end - End time unix timestamp.
* @param reset - Reset time unix timestamp.
*/
(ctx: Context, logger: Logger, nk: Nakama, tournament: Tournament, end: number, reset: number): void;
}
/**
* Tournament reset hook function definition.
*/
export interface TournamentResetFunction {
/**
* A Tournament reset register hook function definition.
*
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
* @param tournament - The reset tournament.
* @param end - End time unix timestamp.
* @param reset - Reset time unix timestamp.
*/
(ctx: Context, logger: Logger, nk: Nakama, tournament: Tournament, end: number, reset: number): void;
}
/**
* Leaderboard reset hook function definition.
*/
export interface LeaderboardResetFunction {
/**
* A Leaderboard reset register hook function definition.
*
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
* @param leaderboard - The reset leaderboard.
* @param reset - Reset time unix timestamp.
*/
(ctx: Context, logger: Logger, nk: Nakama, leaderboard: Leaderboard, reset: number): void;
}
export interface ShutdownFunction {
/**
* A Shutdown hook function definition.
*
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
*/
(ctx: Context, logger: Logger, nk: Nakama): void;
}
/**
* Purchase Notification Apple function definition.
*/
export interface PurchaseNotificationAppleFunction {
/**
* A Purchase Notification Apple register hook function definition.
*
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
* @param purchase - The notification purchase.
* @param providerPayload - The raw payload of the provider notificaton.
*/
(ctx: Context, logger: Logger, nk: Nakama, purchase: ValidatedPurchase, providerPayload: string): void;
}
/**
* Subscription Notification Apple function definition.
*/
export interface SubscriptionNotificationAppleFunction {
/**
* A Subscription Notification Apple register hook function definition.
*
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
* @param subscription - The notification subscription.
* @param providerPayload - The raw payload of the provider notificaton.
*/
(ctx: Context, logger: Logger, nk: Nakama, subscription: ValidatedSubscription, providerPayload: string): void;
}
/**
* Purchase Notification Google function definition.
*/
export interface PurchaseNotificationGoogleFunction {
/**
* A Purchase Notification Google register hook function definition.
*
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
* @param purchase - The notification purchase.
* @param providerPayload - The raw payload of the provider notificaton.
*/
(ctx: Context, logger: Logger, nk: Nakama, purchase: ValidatedPurchase, providerPayload: string): void;
}
/**
* Subscription Notification Google function definition.
*/
export interface SubscriptionNotificationGoogleFunction {
/**
* A Subscription Notification Google register hook function definition.
*
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
* @param subscription - The notification subscription.
* @param providerPayload - The raw payload of the provider notificaton.
*/
(ctx: Context, logger: Logger, nk: Nakama, subscription: ValidatedSubscription, providerPayload: string): void;
}
/**
* Storage Index Filter function definition.
*/
export interface StorageIndexFilterFunction {
/**
* A storage index hook function to apply custom filtering logic to storage objects.
*
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
* @param write - the write to be indexed or deleted from the index
* @return a boolean - true to index the object and false to delete any indexed object (if any exists).
*/
(ctx: Context, logger: Logger, nk: Nakama, write: StorageWriteRequest): boolean;
}
/**
* Match Dispatcher API definition.
*/
export interface MatchDispatcher {
/**
* Broadcast a message to match presences.
*
* @param opcode - Numeric message op code.
* @param data - Opt. Data payload string, or null.
* @param presences - Opt. List of presences (a subset of match participants) to use as message targets, or null to send to the whole match. Defaults to null.
* @param sender - Opt. A presence to tag on the message as the 'sender', or null.
* @param reliable - Opt. Broadcast the message with delivery guarantees or not. Defaults to true.
* @throws {TypeError, GoError}
*/
broadcastMessage(opcode: number, data?: ArrayBuffer | string | null, presences?: Presence[] | null, sender?: Presence | null, reliable?: boolean): void;
/**
* Defer message broadcast to match presences.
*
* @param opcode - Numeric message op code.
* @param data - Opt. Data payload string, or null.
* @param presences - Opt. List of presences (a subset of match participants) to use as message targets, or null to send to the whole match. Defaults to null
* @param sender - Opt. A presence to tag on the message as the 'sender', or null.
* @param reliable - Opt. Broadcast the message with delivery guarantees or not. Defaults to true.
* @throws {TypeError, GoError}
*/
broadcastMessageDeferred(opcode: number, data?: ArrayBuffer | string | null, presences?: Presence[] | null, sender?: Presence, reliable?: boolean): void;
/**
* Kick presences from match.
*
* @param presences - List of presences to kick from the match.
* @throws {TypeError, GoError}
*/
matchKick(presences: Presence[]): void;
/**
* Update match label.
*
* @param label - New label for the match.
* @throws {TypeError, GoError}
*/
matchLabelUpdate(label: string): void;
}
type SessionVars = {[key: string]: string}
/**
* Match Message definition
*/
export interface MatchMessage {
sender: Presence;
persistence: boolean;
status: string;
opCode: number;
data: ArrayBuffer;
reliable: boolean;
receiveTimeMs: number;
}
/**
* Match state definition
*/
export interface MatchState {
[key: string]: any;
}
/**
* Hooks payloads definitions
*/
export interface AccountApple {
token?: string
vars?: SessionVars
}
export interface AuthenticateAppleRequest {
account?: AccountApple
create?: boolean
username?: string
}
export interface AccountCustom {
id?: string
vars?: SessionVars
}
export interface AuthenticateCustomRequest {
account?: AccountCustom
create?: boolean
username?: string
}
export interface AuthenticateDeviceRequest {
account?: AccountDevice
create?: boolean
username?: string
}
export interface AccountEmail {
email?: string
password?: string
vars?: SessionVars
}
export interface AuthenticateEmailRequest {
account: AccountEmail
create: boolean
username: string
}
export interface AuthenticateFacebookRequest {
account?: AccountFacebook
create?: boolean
username?: string
sync?: boolean
}
export interface AccountFacebook {
token?: string
vars?: SessionVars
}
export interface AccountFacebookInstantGame {
signedPlayerInfo?: string
vars?: SessionVars
}
export interface AuthenticateFacebookInstantGameRequest {
account?: AccountFacebookInstantGame
create?: boolean
username?: string
}
export interface AccountGameCenter {
playerId?: string
bundleId?: string
timestampSeconds?: string
salt?: string
signature?: string
publicKeyUrl?: string
vars?: SessionVars
}
export interface AuthenticateGameCenterRequest {
account?: AccountGameCenter
create?: boolean
username?: string
}
export interface AccountGoogle {
token?: string
vars?: SessionVars
}
export interface AuthenticateGoogleRequest {
account?: AccountGoogle
create?: boolean
username?: string
}
export interface AccountSteam {
token?: string
vars?: SessionVars
}
export interface AuthenticateSteamRequest {
account?: AccountSteam
create?: boolean
username?: string
}
export interface ListChannelMessagesRequest {
channelId?: string
limit?: number
forward?: boolean
cursor?: string
}
export interface ChannelMessage {
channelId?: string
messageId?: string
code?: number
senderId?: string
username?: string
content?: string
createTime?: number
updateTime?: number
persistent?: boolean
roomName?: string
groupId?: string
userIdOne?: string
userIdTwo?: string
}
export interface ListFriendsRequest {
limit?: number
state?: number
cursor?: string
}
export interface ListFriendsOfFriendsRequest {
limit?: number
cursor?: string
}
export interface AddFriendsRequest {
ids?: string[]
usernames?: string[]
}
export interface DeleteFriendsRequest {
ids?: string[]
usernames?: string[]
}
export interface BlockFriendsRequest {
ids?: string[]
usernames?: string[]
}
export interface ImportFacebookFriendsRequest {
account?: AccountFacebook
reset?: boolean
}
export interface ImportSteamFriendsRequest {
account?: AccountSteam
reset?: boolean
}
export interface CreateGroupRequest {
name?: string
description?: string
langTag?: string
avatarUrl?: string
open?: boolean
maxCount?: number
}
export interface UpdateGroupRequest {
name?: string
description?: string
langTag?: string
avatarUrl?: string
open?: boolean
}
export interface DeleteGroupRequest {
groupId?: string
}
export interface JoinGroupRequest {
groupId?: string
}
export interface LeaveGroupRequest {
groupId?: string
}
export interface AddGroupUsersRequest {
groupId?: string
userIds?: string[]
}
export interface BanGroupUsersRequest {
groupId?: string
userIds?: string[]
}
export interface KickGroupUsersRequest {
groupId?: string
userIds?: string[]
}
export interface PromoteGroupUsersRequest {
groupId?: string
userIds?: string[]
}
export interface DemoteGroupUsersRequest {
groupId?: string
userIds?: string[]
}
export interface ListGroupUsersRequest {
groupId?: string
limit?: number
state?: number
cursor?: string
}
export interface ListUserGroupsRequest {
userId?: string
limit?: number
state?: number
cursor?: string
}
export interface ListGroupsRequest {
name?: string
cursor?: string
limit?: number
}
export interface DeleteLeaderboardRecordRequest {
leaderboardId?: string
}
export interface DeleteTournamentRecordRequest {
tournamentId?: string
}
export interface ListLeaderboardRecordsRequest {
leaderboardId?: string
ownerIds?: string[]
limit?: number
cursor?: string
expiry?: string
}
export interface WriteLeaderboardRecordRequestLeaderboardRecordWrite {
score?: string
subscore?: string
metadata?: string
}
export interface WriteLeaderboardRecordRequest {
leaderboardId?: string
record?: WriteLeaderboardRecordRequestLeaderboardRecordWrite
}
export interface ListLeaderboardRecordsAroundOwnerRequest {
leaderboardId?: string
limit?: number
ownerId?: string
expiry?: string
}
export interface AccountApple {
token?: string
vars?: SessionVars
}
export interface AccountAppleVarsEntry {
key?: string
value?: string
}
export interface AccountCustom {
id?: string
vars?: SessionVars
}
export interface AccountCustomVarsEntry {
key?: string
value?: string
}
export interface LinkFacebookRequest {
account?: AccountFacebook
sync?: boolean
}
export interface LinkSteamRequest {
account?: AccountSteam
sync?: boolean
}
export interface ListMatchesRequest {
limit?: number
authoritative?: boolean
label?: string
minSize?: number
maxSize?: number
query?: string
}
export interface ListNotificationsRequest {
limit?: number
cacheableCursor?: string
}
export interface ListStorageObjectsRequest {
collection: string
userId: string
limit: number
cursor: string
}
export interface ReadStorageObjectId {
collection?: string
key?: string
userId?: string
}
export interface ReadStorageObjectsRequest {
objectIds?: ReadStorageObjectId[]
}
export interface WriteStorageObject {
collection?: string
key?: string
value?: string
version?: string
permissionRead?: number
permissionWrite?: number
}
export interface WriteStorageObjectsRequest {
objects?: WriteStorageObject[]
}
export interface DeleteStorageObjectId {
collection?: string
key?: string
version?: string
}
export interface DeleteStorageObjectsRequest {
objectIds?: DeleteStorageObjectId[]
}
export interface JoinTournamentRequest {
tournamentId?: string
}
export interface ListTournamentRecordsRequest {
tournamentId?: string
ownerIds?: string[]
limit?: number
cursor?: string
expiry?: string
}
export interface ListTournamentsRequest {
categoryStart?: number
categoryEnd?: number
startTime?: number
endTime?: number
limit?: number
cursor?: string
}
export interface WriteTournamentRecordRequest {
tournamentId?: string
record?: WriteTournamentRecordRequestTournamentRecordWrite
}
export interface WriteTournamentRecordRequestTournamentRecordWrite {
score?: string
subscore?: string
metadata?: string
}
export interface ListTournamentRecordsAroundOwnerRequest {
tournamentId?: string
limit?: number
ownerId?: string
expiry?: string
}
export interface GetUsersRequest {
ids?: string[]
usernames?: string[]
facebookIds?: string[]
}
export interface Event {
name?: string
properties?: EventPropertiesEntry[]
timestamp?: string
external?: boolean
}
export interface EventPropertiesEntry {
key?: string
value?: string
}
export interface Session {
created?: boolean
token?: string
refreshToken?: string
}
export interface ChannelMessageList {
messages?: ChannelMessage[]
nextCursor?: string
prevCursor?: string
cacheableCursor?: string
}
export interface Friend {
user?: User
state?: number
updateTime?: number
}
export interface FriendList {
friends?: Friend[]
cursor?: string
}
export interface FriendsOfFriendsList {
friendsOfFriends?: FriendOfFriend[]
cursor?: string
}
export interface FriendOfFriend {
referrer: string
user: User
}
const enum GroupUserState {
Superadmin = 0,
Admin = 1,
Member = 2,
JoinRequest = 3,
Banned = 4,
}
export interface GroupUser {
user: User
state?: GroupUserState
}
export interface GroupUserList {
groupUsers?: GroupUser[]
cursor?: string
}
export interface LeaderboardRecordList {
records?: LeaderboardRecord[]
ownerRecords?: LeaderboardRecord[]
nextCursor?: string
prevCursor?: string
rankCount?: number
}
export interface MatchList {
matches: Match[]
}
export interface DeleteNotificationsRequest {
ids: string[]
}
export interface StorageObjectList {
objects?: StorageObject[]
cursor?: string
}
export interface StorageObjects {
objects?: StorageObject[]
}
export interface TournamentRecordList {
records?: LeaderboardRecord[]
ownerRecords?: LeaderboardRecord[]
prevCursor?: string
nextCursor?: string
rankCount?: number
}
export interface TournamentList {
tournaments: Tournament[]
cursor?: string
}
export interface Users {
users: Users[]
}
export interface MatchmakerResult {
properties: {[key: string]: string}
presence: Presence
partyId?: string
}
export interface LeaderboardList {
leaderboards: Leaderboard[]
cursor?: string
}
/**
* Realtime hook messages
*/
export type RtHookMessage = 'ChannelJoin' | 'ChannelLeave' | 'ChannelMessageSend' | 'ChannelMessageUpdate' | 'ChannelMessageRemove' | 'MatchCreate' | 'MatchDataSend' | 'MatchJoin' | 'MatchLeave' | 'MatchmakerAdd' | 'MatchmakerRemove' | 'PartyCreate' | 'PartyJoin' | 'PartyLeave' | 'PartyPromote' | 'PartyAccept' | 'PartyRemove' | 'PartyClose' | 'PartyJoinRequestList' | 'PartyMatchmakerAdd' | 'PartyMatchmakerRemove' | 'PartyDataSend' | 'StatusFollow' | 'StatusUnfollow' | 'StatusUpdate' | 'Ping' | 'Pong'
/**
* Match handler definitions
*/
export interface MatchHandler<State = MatchState> {
matchInit: MatchInitFunction<State>;
matchJoinAttempt: MatchJoinAttemptFunction<State>;
matchJoin: MatchJoinFunction<State>;
matchLeave: MatchLeaveFunction<State>;
matchLoop: MatchLoopFunction<State>;
matchTerminate: MatchTerminateFunction<State>;
matchSignal: MatchSignalFunction<State>;
}
/**
* Match initialization function definition.
*/
export interface MatchInitFunction<State = MatchState> {
/**
* Match initialization function definition.
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
* @param params - Parameters that were passed to nk.matchCreate, if any.
* @returns An object with the match state, tick rate and labels.
*/
(ctx: Context, logger: Logger, nk: Nakama, params: {[key: string]: any}): {state: State, tickRate: number, label: string};
}
/**
* Match join attempt function definition.
*/
export interface MatchJoinAttemptFunction<State = MatchState> {
/**
* User match join attempt function definition.
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
* @param dispatcher - Message dispatcher APIs.
* @param tick - Current match loop tick.
* @param state - Current match state.
* @param presence - Presence of user attempting to join.
* @param metadata - Metadata object.
* @returns object with state, acceptUser and optional rejection message if acceptUser is false.
*/
(ctx: Context, logger: Logger, nk: Nakama, dispatcher: MatchDispatcher, tick: number, state: State, presence: Presence, metadata: {[key: string]: any}): {state: State, accept: boolean, rejectMessage?: string} | null;
}
/**
* Match join function definition.
*/
export interface MatchJoinFunction<State = MatchState> {
/**
* User match join function definition.
* @param ctx - The context for the execution.
* @param logger - The server logger.
* @param nk - The Nakama server APIs.
* @param dispatcher - Message dispatcher APIs.
* @param tick - Current match loop tick.
* @param state - Current match state.
* @param presences - List of presences.
* @returns object with the new state of the match.
*/
(ctx: Context, logger: Logger, nk: Nakama, dispatcher: MatchDispatcher, tick: number, state: State, presences: Presence[]): {state: State} | null;
}
/**
* Match leave function definition.
*/
export interface MatchLeaveFunction<State = MatchState> {
/**
* User match leave function definition.