@netifyjs/protocol 1.0.0-alpha.3 → 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/package.json +2 -2
  2. package/src/codec/index.ts +51 -221
  3. package/src/dispatch/dispatcher/index.ts +89 -47
  4. package/src/dispatch/session/index.ts +6 -24
  5. package/src/index.ts +2 -4
  6. package/src/photon/balancing/codec/index.ts +27 -53
  7. package/src/photon/balancing/format/authenticate/request/index.ts +52 -6
  8. package/src/photon/balancing/format/friends/request/index.ts +21 -5
  9. package/src/photon/balancing/format/game/create/request/index.ts +45 -8
  10. package/src/photon/balancing/format/game/debug/request/index.ts +19 -4
  11. package/src/photon/balancing/format/game/join/request/index.ts +65 -13
  12. package/src/photon/balancing/format/game/list/request/index.ts +29 -3
  13. package/src/photon/balancing/format/game/random/request/index.ts +58 -10
  14. package/src/photon/balancing/format/groups/request/index.ts +19 -3
  15. package/src/photon/balancing/format/index.ts +7 -0
  16. package/src/photon/balancing/format/leave/request/index.ts +19 -3
  17. package/src/photon/balancing/format/lobby/join/request/index.ts +23 -3
  18. package/src/photon/balancing/format/lobby/stats/request/index.ts +19 -3
  19. package/src/photon/balancing/format/once/request/index.ts +31 -8
  20. package/src/photon/balancing/format/properties/get/request/index.ts +31 -4
  21. package/src/photon/balancing/format/properties/set/request/index.ts +36 -7
  22. package/src/photon/balancing/format/raise/request/index.ts +76 -10
  23. package/src/photon/balancing/format/reader/index.ts +75 -6
  24. package/src/photon/balancing/format/regions/request/index.ts +16 -1
  25. package/src/photon/balancing/format/rpc/request/index.ts +26 -3
  26. package/src/photon/balancing/format/settings/request/index.ts +15 -2
  27. package/src/photon/balancing/format/shared/credentials/index.ts +77 -33
  28. package/src/photon/balancing/format/shared/lobby/index.ts +41 -5
  29. package/src/photon/balancing/format/shared/options/index.ts +56 -24
  30. package/src/photon/balancing/format/table/index.ts +399 -0
  31. package/src/photon/balancing/index.ts +11 -1
  32. package/src/photon/balancing/travel/index.ts +15 -12
  33. package/src/photon/client/connection/index.ts +6 -6
  34. package/src/photon/cluster/back/index.ts +32 -45
  35. package/src/photon/cluster/dresser/index.ts +7 -8
  36. package/src/photon/cluster/front/index.ts +25 -49
  37. package/src/photon/cluster/grid/index.ts +1 -1
  38. package/src/photon/cluster/mover/index.ts +12 -12
  39. package/src/photon/cluster/press/index.ts +2 -18
  40. package/src/photon/cluster/route/game/index.ts +9 -11
  41. package/src/photon/cluster/route/master/index.ts +15 -34
  42. package/src/photon/cluster/route/name/index.ts +4 -21
  43. package/src/photon/cluster/seat/game/index.ts +6 -26
  44. package/src/photon/cluster/seat/master/index.ts +1 -1
  45. package/src/photon/cluster/sessions/index.ts +5 -6
  46. package/src/photon/cluster/spread/index.ts +8 -147
  47. package/src/photon/enet/client/index.ts +1 -8
  48. package/src/photon/enet/gateway/index.ts +5 -15
  49. package/src/photon/enet/index.ts +1 -1
  50. package/src/photon/enet/link/index.ts +34 -15
  51. package/src/photon/enet/outbound/index.ts +279 -0
  52. package/src/photon/enet/peer/index.ts +59 -0
  53. package/src/photon/enet/transport/index.ts +8 -24
  54. package/src/photon/game/admission/index.ts +353 -0
  55. package/src/photon/game/bag/index.ts +13 -0
  56. package/src/photon/game/broadcast/index.ts +79 -0
  57. package/src/photon/game/editor/index.ts +446 -0
  58. package/src/photon/game/gate/index.ts +9 -8
  59. package/src/photon/game/handler/index.ts +30 -3
  60. package/src/photon/game/history/index.ts +234 -0
  61. package/src/photon/game/hooked/index.ts +16 -15
  62. package/src/photon/game/index.ts +12 -1
  63. package/src/photon/game/lifecycle/index.ts +193 -0
  64. package/src/photon/game/peer/index.ts +1 -10
  65. package/src/photon/game/properties/index.ts +342 -0
  66. package/src/photon/game/room/index.ts +435 -1793
  67. package/src/photon/game/rooms/index.ts +2 -1
  68. package/src/photon/game/seats/index.ts +237 -0
  69. package/src/photon/game/server/index.ts +12 -2
  70. package/src/photon/game/services/index.ts +41 -0
  71. package/src/photon/game/settings/index.ts +22 -0
  72. package/src/photon/game/snapshot/index.ts +133 -0
  73. package/src/photon/game/throttle/index.ts +60 -0
  74. package/src/photon/game/touch/index.ts +2 -5
  75. package/src/photon/game/venue/index.ts +31 -0
  76. package/src/photon/master/application/index.ts +7 -0
  77. package/src/photon/master/gate/index.ts +12 -8
  78. package/src/photon/master/handler/index.ts +36 -748
  79. package/src/photon/master/index.ts +5 -0
  80. package/src/photon/master/list/sql/index.ts +37 -3
  81. package/src/photon/master/listing/index.ts +133 -0
  82. package/src/photon/master/lobby/index.ts +9 -0
  83. package/src/photon/master/login/index.ts +424 -0
  84. package/src/photon/master/matchmaking/index.ts +282 -0
  85. package/src/photon/master/query/index.ts +45 -0
  86. package/src/photon/master/redirect/index.ts +8 -7
  87. package/src/photon/master/services/index.ts +35 -0
  88. package/src/photon/master/settings/index.ts +44 -0
  89. package/src/photon/master/sql/cost/index.ts +263 -0
  90. package/src/photon/master/sql/index.ts +1 -0
  91. package/src/photon/message/client/index.ts +14 -11
  92. package/src/photon/message/handler/index.ts +22 -64
  93. package/src/photon/message/pipeline/index.ts +12 -12
  94. package/src/photon/message/server/index.ts +87 -43
  95. package/src/photon/message/watch/index.ts +14 -37
  96. package/src/photon/server/deferral/index.ts +57 -0
  97. package/src/photon/server/host/index.ts +32 -10
  98. package/src/photon/server/index.ts +1 -0
  99. package/src/photon/tcp/client/index.ts +1 -1
  100. package/src/photon/tcp/codec/index.ts +13 -42
  101. package/src/photon/tcp/server/index.ts +4 -4
  102. package/src/photon/websocket/bridge/index.ts +16 -20
  103. package/src/photon/websocket/message/index.ts +27 -39
  104. package/src/photon/websocket/path/index.ts +2 -5
  105. package/src/scale/fanout/index.ts +6 -6
  106. package/src/scale/index.ts +2 -4
  107. package/src/scale/outbound/index.ts +192 -0
  108. package/src/scale/relay/index.ts +20 -31
  109. package/src/scale/sink/index.ts +6 -11
  110. package/src/scale/transport/index.ts +27 -44
  111. package/src/scale/tunnel/index.ts +37 -91
  112. package/src/smartfox/common/bluebox/gateway/index.ts +401 -0
  113. package/src/smartfox/common/bluebox/index.ts +4 -0
  114. package/src/smartfox/{x2 → common}/bluebox/transport/index.ts +36 -23
  115. package/src/smartfox/common/index.ts +5 -0
  116. package/src/smartfox/common/strikes/index.ts +74 -0
  117. package/src/smartfox/pro/bluebox/index.ts +176 -4
  118. package/src/smartfox/pro/codec/index.ts +8 -7
  119. package/src/smartfox/pro/escalation/index.ts +28 -20
  120. package/src/smartfox/pro/flood/index.ts +2 -2
  121. package/src/smartfox/pro/format/extension/raw/index.ts +12 -2
  122. package/src/smartfox/pro/handler/chat/index.ts +11 -8
  123. package/src/smartfox/pro/handler/login/index.ts +2 -25
  124. package/src/smartfox/pro/handler/shared/index.ts +4 -3
  125. package/src/smartfox/pro/index.ts +11 -5
  126. package/src/smartfox/pro/login/gate/index.ts +166 -0
  127. package/src/smartfox/pro/login/index.ts +1 -0
  128. package/src/smartfox/pro/moderation/index.ts +220 -0
  129. package/src/smartfox/pro/options/index.ts +5 -5
  130. package/src/smartfox/pro/protocol/index.ts +62 -8
  131. package/src/smartfox/pro/web/index.ts +33 -26
  132. package/src/smartfox/pro/zone/index.ts +59 -282
  133. package/src/smartfox/pro/zones/index.ts +3 -3
  134. package/src/smartfox/x2/bluebox/index.ts +149 -4
  135. package/src/smartfox/x2/chat/index.ts +9 -19
  136. package/src/smartfox/x2/codec/index.ts +31 -39
  137. package/src/smartfox/x2/config/index.ts +6 -1
  138. package/src/smartfox/x2/data/array/index.ts +96 -60
  139. package/src/smartfox/x2/data/object/index.ts +144 -82
  140. package/src/smartfox/x2/data/serializer/index.ts +41 -23
  141. package/src/smartfox/x2/flood/gate/index.ts +19 -13
  142. package/src/smartfox/x2/format/buddy/init/response/index.ts +4 -3
  143. package/src/smartfox/x2/format/find/rooms/response/index.ts +4 -3
  144. package/src/smartfox/x2/format/find/users/response/index.ts +4 -3
  145. package/src/smartfox/x2/format/group/subscribe/response/index.ts +4 -3
  146. package/src/smartfox/x2/format/login/response/index.ts +4 -3
  147. package/src/smartfox/x2/format/mmo/position/response/index.ts +8 -6
  148. package/src/smartfox/x2/format/room/join/response/index.ts +4 -3
  149. package/src/smartfox/x2/games/index.ts +35 -8
  150. package/src/smartfox/x2/hall/index.ts +0 -6
  151. package/src/smartfox/x2/handler/session/index.ts +1 -1
  152. package/src/smartfox/x2/index.ts +8 -3
  153. package/src/smartfox/x2/member/index.ts +10 -3
  154. package/src/smartfox/x2/packet/login/response/index.ts +12 -0
  155. package/src/smartfox/x2/protocol/index.ts +11 -1
  156. package/src/smartfox/x2/rooms/index.ts +1 -2
  157. package/src/smartfox/x2/sessions/index.ts +6 -0
  158. package/src/smartfox/x2/udp/index.ts +61 -24
  159. package/src/smartfox/x2/web/index.ts +35 -17
  160. package/src/smartfox/x2/websocket/index.ts +18 -36
  161. package/src/smartfox/x2/zone/index.ts +77 -28
  162. package/src/smartfox/x2/zones/index.ts +17 -5
  163. package/src/photon/enet/handler/index.ts +0 -65
  164. package/src/scale/hosted/index.ts +0 -68
  165. package/src/scale/outlet/index.ts +0 -121
  166. package/src/smartfox/pro/bluebox/gateway/index.ts +0 -310
  167. package/src/smartfox/pro/bluebox/session/index.ts +0 -63
  168. package/src/smartfox/pro/bluebox/transport/index.ts +0 -104
  169. package/src/smartfox/x2/bluebox/gateway/index.ts +0 -315
  170. /package/src/smartfox/{x2 → common}/bluebox/session/index.ts +0 -0
  171. /package/src/smartfox/{pro → common}/counters/index.ts +0 -0
  172. /package/src/smartfox/{pro → common}/counters/memory/index.ts +0 -0
  173. /package/src/smartfox/{pro → common}/counters/offender/index.ts +0 -0
  174. /package/src/smartfox/{pro → common}/counters/store/index.ts +0 -0
  175. /package/src/smartfox/{pro → common}/sequence/index.ts +0 -0
@@ -0,0 +1,399 @@
1
+ import type { PhotonHashtable } from '../../../binary/hashtable/index.ts'
2
+ import type { PhotonValue } from '../../../binary/value/index.ts'
3
+
4
+ /**
5
+ * The types a parameter can be read as
6
+ */
7
+ export const ParameterKind = {
8
+ /**
9
+ * Any value
10
+ */
11
+ VALUE: 0,
12
+
13
+ /**
14
+ * A string
15
+ */
16
+ TEXT: 1,
17
+
18
+ /**
19
+ * A bool
20
+ */
21
+ FLAG: 2,
22
+
23
+ /**
24
+ * A byte
25
+ */
26
+ BYTE: 3,
27
+
28
+ /**
29
+ * An int
30
+ */
31
+ INT: 4,
32
+
33
+ /**
34
+ * A byte, or a bool read as 0 or 1
35
+ */
36
+ CONVERTIBLE: 5,
37
+
38
+ /**
39
+ * A byte array
40
+ */
41
+ BYTES: 6,
42
+
43
+ /**
44
+ * A Hashtable
45
+ */
46
+ TABLE: 7,
47
+
48
+ /**
49
+ * A string array
50
+ */
51
+ TEXTS: 8,
52
+
53
+ /**
54
+ * An int array
55
+ */
56
+ INTS: 9,
57
+
58
+ /**
59
+ * An object array
60
+ */
61
+ VALUES: 10,
62
+ } as const
63
+
64
+ /**
65
+ * One of the parameter kinds
66
+ */
67
+ export type ParameterKindId = (typeof ParameterKind)[keyof typeof ParameterKind]
68
+
69
+ /**
70
+ * What each kind of parameter reads as
71
+ */
72
+ export type ParameterTypes = {
73
+ /**
74
+ * Any value
75
+ */
76
+ readonly [ParameterKind.VALUE]: PhotonValue
77
+
78
+ /**
79
+ * A string
80
+ */
81
+ readonly [ParameterKind.TEXT]: string
82
+
83
+ /**
84
+ * A bool
85
+ */
86
+ readonly [ParameterKind.FLAG]: boolean
87
+
88
+ /**
89
+ * A byte
90
+ */
91
+ readonly [ParameterKind.BYTE]: number
92
+
93
+ /**
94
+ * An int
95
+ */
96
+ readonly [ParameterKind.INT]: number
97
+
98
+ /**
99
+ * A byte, or a bool read as 0 or 1
100
+ */
101
+ readonly [ParameterKind.CONVERTIBLE]: number
102
+
103
+ /**
104
+ * A byte array
105
+ */
106
+ readonly [ParameterKind.BYTES]: Uint8Array
107
+
108
+ /**
109
+ * A Hashtable
110
+ */
111
+ readonly [ParameterKind.TABLE]: PhotonHashtable
112
+
113
+ /**
114
+ * A string array
115
+ */
116
+ readonly [ParameterKind.TEXTS]: readonly string[]
117
+
118
+ /**
119
+ * An int array
120
+ */
121
+ readonly [ParameterKind.INTS]: readonly number[]
122
+
123
+ /**
124
+ * An object array
125
+ */
126
+ readonly [ParameterKind.VALUES]: readonly PhotonValue[]
127
+ }
128
+
129
+ /**
130
+ * One parameter of an operation, as its table lists it
131
+ * @class
132
+ */
133
+ export class Parameter<K extends ParameterKindId = ParameterKindId> {
134
+ /**
135
+ * Parameter code
136
+ */
137
+ public readonly code: number
138
+
139
+ /**
140
+ * Type it's read as
141
+ */
142
+ public readonly kind: K
143
+
144
+ /**
145
+ * Whether a request without it is refused
146
+ */
147
+ public readonly mandatory: boolean
148
+
149
+ /**
150
+ * Entry that has to hold a value before this one is read, or null
151
+ */
152
+ public readonly gate: string | null
153
+
154
+ /**
155
+ * @param code parameter code
156
+ * @param kind type it's read as
157
+ * @param mandatory whether a request without it is refused
158
+ * @param gate entry that has to hold a value first, or null
159
+ */
160
+ private constructor(
161
+ code: number,
162
+ kind: K,
163
+ mandatory: boolean,
164
+ gate: string | null,
165
+ ) {
166
+ this.code = code
167
+ this.kind = kind
168
+ this.mandatory = mandatory
169
+ this.gate = gate
170
+ }
171
+
172
+ /**
173
+ * A parameter of any type
174
+ * @param code parameter code
175
+ */
176
+ public static value(code: number): Parameter<typeof ParameterKind.VALUE> {
177
+ return new Parameter<typeof ParameterKind.VALUE>(
178
+ code,
179
+ ParameterKind.VALUE,
180
+ false,
181
+ null,
182
+ )
183
+ }
184
+
185
+ /**
186
+ * A string parameter
187
+ * @param code parameter code
188
+ */
189
+ public static text(code: number): Parameter<typeof ParameterKind.TEXT> {
190
+ return new Parameter<typeof ParameterKind.TEXT>(
191
+ code,
192
+ ParameterKind.TEXT,
193
+ false,
194
+ null,
195
+ )
196
+ }
197
+
198
+ /**
199
+ * A bool parameter
200
+ * @param code parameter code
201
+ */
202
+ public static flag(code: number): Parameter<typeof ParameterKind.FLAG> {
203
+ return new Parameter<typeof ParameterKind.FLAG>(
204
+ code,
205
+ ParameterKind.FLAG,
206
+ false,
207
+ null,
208
+ )
209
+ }
210
+
211
+ /**
212
+ * A byte parameter
213
+ * @param code parameter code
214
+ */
215
+ public static byte(code: number): Parameter<typeof ParameterKind.BYTE> {
216
+ return new Parameter<typeof ParameterKind.BYTE>(
217
+ code,
218
+ ParameterKind.BYTE,
219
+ false,
220
+ null,
221
+ )
222
+ }
223
+
224
+ /**
225
+ * An int parameter
226
+ * @param code parameter code
227
+ */
228
+ public static int(code: number): Parameter<typeof ParameterKind.INT> {
229
+ return new Parameter<typeof ParameterKind.INT>(
230
+ code,
231
+ ParameterKind.INT,
232
+ false,
233
+ null,
234
+ )
235
+ }
236
+
237
+ /**
238
+ * A byte parameter that may come as a bool
239
+ * @param code parameter code
240
+ */
241
+ public static convertible(
242
+ code: number,
243
+ ): Parameter<typeof ParameterKind.CONVERTIBLE> {
244
+ return new Parameter<typeof ParameterKind.CONVERTIBLE>(
245
+ code,
246
+ ParameterKind.CONVERTIBLE,
247
+ false,
248
+ null,
249
+ )
250
+ }
251
+
252
+ /**
253
+ * A byte array parameter
254
+ * @param code parameter code
255
+ */
256
+ public static bytes(code: number): Parameter<typeof ParameterKind.BYTES> {
257
+ return new Parameter<typeof ParameterKind.BYTES>(
258
+ code,
259
+ ParameterKind.BYTES,
260
+ false,
261
+ null,
262
+ )
263
+ }
264
+
265
+ /**
266
+ * A Hashtable parameter
267
+ * @param code parameter code
268
+ */
269
+ public static table(code: number): Parameter<typeof ParameterKind.TABLE> {
270
+ return new Parameter<typeof ParameterKind.TABLE>(
271
+ code,
272
+ ParameterKind.TABLE,
273
+ false,
274
+ null,
275
+ )
276
+ }
277
+
278
+ /**
279
+ * A string array parameter
280
+ * @param code parameter code
281
+ */
282
+ public static texts(code: number): Parameter<typeof ParameterKind.TEXTS> {
283
+ return new Parameter<typeof ParameterKind.TEXTS>(
284
+ code,
285
+ ParameterKind.TEXTS,
286
+ false,
287
+ null,
288
+ )
289
+ }
290
+
291
+ /**
292
+ * An int array parameter
293
+ * @param code parameter code
294
+ */
295
+ public static ints(code: number): Parameter<typeof ParameterKind.INTS> {
296
+ return new Parameter<typeof ParameterKind.INTS>(
297
+ code,
298
+ ParameterKind.INTS,
299
+ false,
300
+ null,
301
+ )
302
+ }
303
+
304
+ /**
305
+ * An object array parameter
306
+ * @param code parameter code
307
+ */
308
+ public static values(code: number): Parameter<typeof ParameterKind.VALUES> {
309
+ return new Parameter<typeof ParameterKind.VALUES>(
310
+ code,
311
+ ParameterKind.VALUES,
312
+ false,
313
+ null,
314
+ )
315
+ }
316
+
317
+ /**
318
+ * The same parameter, refused if it's missing
319
+ */
320
+ public required(): Parameter<K> {
321
+ return new Parameter<K>(this.code, this.kind, true, this.gate)
322
+ }
323
+
324
+ /**
325
+ * The same parameter, read only if another entry holds a value
326
+ * @param entry name of that entry in the table
327
+ */
328
+ public given(entry: string): Parameter<K> {
329
+ return new Parameter<K>(this.code, this.kind, this.mandatory, entry)
330
+ }
331
+ }
332
+
333
+ /**
334
+ * Every parameter of an operation by name
335
+ */
336
+ export type OperationShape = Readonly<Record<string, Parameter>>
337
+
338
+ /**
339
+ * What a shape reads as
340
+ */
341
+ export type OperationValues<S extends OperationShape> = {
342
+ readonly [N in keyof S]: ParameterTypes[S[N]['kind']] | null
343
+ }
344
+
345
+ /**
346
+ * An operation's parameters laid out flat for reading
347
+ * @class
348
+ */
349
+ export class OperationTable<S extends OperationShape = OperationShape> {
350
+ /**
351
+ * The parameters by name, as declared
352
+ */
353
+ public readonly shape: S
354
+
355
+ /**
356
+ * Names and parameters in read order
357
+ */
358
+ public readonly entries: readonly (readonly [string, Parameter])[]
359
+
360
+ /**
361
+ * Codes that have to be there
362
+ */
363
+ public readonly required: readonly number[]
364
+
365
+ /**
366
+ * Every name set to null, copied for each read
367
+ */
368
+ public readonly blank: Readonly<Record<string, null>>
369
+
370
+ /**
371
+ * @param shape the parameters by name
372
+ */
373
+ private constructor(shape: S) {
374
+ const entries = Object.entries<Parameter>(shape)
375
+
376
+ this.shape = shape
377
+ this.entries = entries
378
+ this.required = entries
379
+ .filter(
380
+ ([, parameter]: [string, Parameter]): boolean => parameter.mandatory,
381
+ )
382
+ .map<number>(
383
+ ([, parameter]: [string, Parameter]): number => parameter.code,
384
+ )
385
+ this.blank = Object.fromEntries(
386
+ entries.map<[string, null]>(
387
+ ([name]: [string, Parameter]): [string, null] => [name, null],
388
+ ),
389
+ )
390
+ }
391
+
392
+ /**
393
+ * Lays a shape out for reading
394
+ * @param shape the parameters by name
395
+ */
396
+ public static of<S extends OperationShape>(shape: S): OperationTable<S> {
397
+ return new OperationTable<S>(shape)
398
+ }
399
+ }
@@ -119,6 +119,9 @@ export {
119
119
  LobbyStatsFormat,
120
120
  MatchEventFormat,
121
121
  MessageKind,
122
+ OperationTable,
123
+ Parameter,
124
+ ParameterKind,
122
125
  ParameterReader,
123
126
  ParameterWriter,
124
127
  PingRequestFormat,
@@ -136,7 +139,14 @@ export {
136
139
  WebRpcRequestFormat,
137
140
  WebRpcResponseFormat,
138
141
  } from './format/index.ts'
139
- export type { BalancingFormat, MessageKindId } from './format/index.ts'
142
+ export type {
143
+ BalancingFormat,
144
+ MessageKindId,
145
+ OperationShape,
146
+ OperationValues,
147
+ ParameterKindId,
148
+ ParameterTypes,
149
+ } from './format/index.ts'
140
150
  export {
141
151
  AppStatsEvent,
142
152
  AuthEvent,
@@ -7,13 +7,14 @@ import { Delivery, type DeliveryMode } from '../../frame/index.ts'
7
7
  */
8
8
  export class Travel {
9
9
  /**
10
- * Reliable on channel 0 in the clear
10
+ * One shared travel per delivery mode on channel 0, unencrypted
11
11
  */
12
- private static readonly plain: Travel = new Travel(
13
- Delivery.RELIABLE,
14
- 0,
15
- false,
16
- )
12
+ private static readonly plain: readonly Travel[] = [
13
+ new Travel(Delivery.UNRELIABLE, 0, false),
14
+ new Travel(Delivery.RELIABLE, 0, false),
15
+ new Travel(Delivery.UNSEQUENCED, 0, false),
16
+ new Travel(Delivery.RELIABLE_UNSEQUENCED, 0, false),
17
+ ]
17
18
 
18
19
  /**
19
20
  * Channel it travels on
@@ -56,6 +57,10 @@ export class Travel {
56
57
  channel = 0,
57
58
  encrypted = false,
58
59
  ): Travel {
60
+ if (channel === 0 && !encrypted) {
61
+ return Travel.plain[delivery] ?? new Travel(delivery, channel, encrypted)
62
+ }
63
+
59
64
  return new Travel(delivery, channel, encrypted)
60
65
  }
61
66
 
@@ -65,9 +70,7 @@ export class Travel {
65
70
  * @param encrypted whether its body is encrypted on the wire
66
71
  */
67
72
  public static reliable(channel = 0, encrypted = false): Travel {
68
- if (channel === 0 && !encrypted) return Travel.plain
69
-
70
- return new Travel(Delivery.RELIABLE, channel, encrypted)
73
+ return Travel.of(Delivery.RELIABLE, channel, encrypted)
71
74
  }
72
75
 
73
76
  /**
@@ -75,7 +78,7 @@ export class Travel {
75
78
  * @param channel channel it travels on
76
79
  */
77
80
  public static unreliable(channel = 0): Travel {
78
- return new Travel(Delivery.UNRELIABLE, channel, false)
81
+ return Travel.of(Delivery.UNRELIABLE, channel)
79
82
  }
80
83
 
81
84
  /**
@@ -83,14 +86,14 @@ export class Travel {
83
86
  * @param envelope what the message layer handed up
84
87
  */
85
88
  public static from(envelope: Envelope): Travel {
86
- return new Travel(envelope.delivery, envelope.channel, envelope.encrypted)
89
+ return Travel.of(envelope.delivery, envelope.channel, envelope.encrypted)
87
90
  }
88
91
 
89
92
  /**
90
93
  * How the answer to a request travels
91
94
  */
92
95
  public reply(): Travel {
93
- return new Travel(Delivery.RELIABLE, this.channel, this.encrypted)
96
+ return Travel.of(Delivery.RELIABLE, this.channel, this.encrypted)
94
97
  }
95
98
 
96
99
  /**
@@ -178,11 +178,11 @@ export class ClientConnection extends InboundHandlerAdapter {
178
178
  * Switches encryption on once the init request is out
179
179
  * @param context the connection
180
180
  */
181
- public override channelActive(context: HandlerContext): void | Promise<void> {
181
+ public override channelActive(context: HandlerContext): void {
182
182
  const peer = PhotonPeer.of(context.channel)
183
183
  if (this.data !== null) peer?.encrypt(peer.encryption(this.data))
184
184
 
185
- return context.fireChannelActive()
185
+ context.fireChannelActive()
186
186
  }
187
187
 
188
188
  /**
@@ -206,14 +206,14 @@ export class ClientConnection extends InboundHandlerAdapter {
206
206
  * Tells everyone waiting that nothing more arrives
207
207
  * @param context the connection
208
208
  */
209
- public override channelInactive(context: HandlerContext): Promise<void> {
209
+ public override channelInactive(context: HandlerContext): void {
210
210
  this.ended = true
211
211
  this.left()
212
212
  for (const waiter of [...this.waiters]) {
213
213
  waiter.fail(new Error('Connection closed'))
214
214
  }
215
215
 
216
- return context.fireChannelInactive()
216
+ context.fireChannelInactive()
217
217
  }
218
218
 
219
219
  /**
@@ -224,7 +224,7 @@ export class ClientConnection extends InboundHandlerAdapter {
224
224
  public send(packet: PacketAdapter, encrypted = false): void {
225
225
  if (this.ended) throw new Error('Connection closed')
226
226
 
227
- this.channel.writeAndFlushSync(
227
+ this.channel.writeAndFlush(
228
228
  encrypted ? packet.via(Travel.reliable(0, true)) : packet,
229
229
  )
230
230
  }
@@ -280,7 +280,7 @@ export class ClientConnection extends InboundHandlerAdapter {
280
280
  const peer = PhotonPeer.of(this.channel)
281
281
  if (peer === null) throw new Error('Connection has no message layer')
282
282
 
283
- this.channel.writeAndFlushSync(peer.negotiate())
283
+ this.channel.writeAndFlush(peer.negotiate())
284
284
  for (;;) {
285
285
  const message = await this.next<WireMessage>(WireMessage)
286
286
  if (message.type === MessageType.INTERNAL_RESPONSE) return
@@ -3,7 +3,6 @@ import {
3
3
  DuplexHandlerAdapter,
4
4
  type HandlerContext,
5
5
  IdleStateEvent,
6
- pending,
7
6
  } from '@netifyjs/netify'
8
7
 
9
8
  import { ConnectionProtocol } from '../../crypto/protocol/index.ts'
@@ -43,13 +42,13 @@ export class BackBridge extends DuplexHandlerAdapter {
43
42
  * @param context the connection
44
43
  * @param message packed messages, or anything else
45
44
  */
46
- public override channelRead(
47
- context: HandlerContext,
48
- message: unknown,
49
- ): void | Promise<void> {
50
- if (!(message instanceof ByteBuf)) return context.fireChannelRead(message)
45
+ public override channelRead(context: HandlerContext, message: unknown): void {
46
+ if (!(message instanceof ByteBuf)) {
47
+ context.fireChannelRead(message)
48
+ return
49
+ }
51
50
 
52
- return this.pass(
51
+ this.pass(
53
52
  context,
54
53
  Carriage.unpack(message.readBytes(message.readableBytes)),
55
54
  0,
@@ -57,7 +56,7 @@ export class BackBridge extends DuplexHandlerAdapter {
57
56
  }
58
57
 
59
58
  /**
60
- * Hands on everything a run of bytes carried, in order
59
+ * Hands on everything a run of bytes carried in order, stopping while reads are paused
61
60
  * @param context the connection
62
61
  * @param cargoes what was unpacked
63
62
  * @param from the first one still to go
@@ -66,17 +65,19 @@ export class BackBridge extends DuplexHandlerAdapter {
66
65
  context: HandlerContext,
67
66
  cargoes: readonly Cargo[],
68
67
  from: number,
69
- ): void | Promise<void> {
70
- for (let index = from; index < cargoes.length; index++) {
71
- const cargo = cargoes[index]
72
- if (cargo === undefined) continue
68
+ ): void {
69
+ const channel = context.channel
73
70
 
74
- const handed = pending(this.hand(context, cargo))
75
- if (handed !== null) {
76
- return handed.then((): void | Promise<void> =>
77
- this.pass(context, cargoes, index + 1),
78
- )
71
+ for (let index = from; index < cargoes.length; index++) {
72
+ if (index > from && channel.isReadPaused && channel.isActive) {
73
+ channel.deferRead((): void => {
74
+ this.pass(context, cargoes, index)
75
+ })
76
+ return
79
77
  }
78
+
79
+ const cargo = cargoes[index]
80
+ if (cargo !== undefined) this.hand(context, cargo)
80
81
  }
81
82
  }
82
83
 
@@ -85,29 +86,31 @@ export class BackBridge extends DuplexHandlerAdapter {
85
86
  * @param context the connection
86
87
  * @param cargo a message or a note
87
88
  */
88
- private hand(context: HandlerContext, cargo: Cargo): void | Promise<void> {
89
+ private hand(context: HandlerContext, cargo: Cargo): void {
89
90
  if (cargo instanceof EnetClosure) {
90
91
  EnetClosure.note(context.channel, cargo)
91
92
  return
92
93
  }
93
94
 
94
95
  if (cargo === 'introduction') {
95
- return context.fireUserEventTriggered(this.init)
96
+ context.fireUserEventTriggered(this.init)
97
+ return
96
98
  }
97
99
 
98
100
  if (cargo === 'idle') {
99
- return context.fireUserEventTriggered(new IdleStateEvent('reader', true))
101
+ context.fireUserEventTriggered(new IdleStateEvent('reader', true))
102
+ return
100
103
  }
101
104
 
102
105
  const envelope = BackBridge.opened(context, cargo)
103
- if (envelope !== null) return context.fireChannelRead(envelope)
106
+ if (envelope !== null) context.fireChannelRead(envelope)
104
107
  }
105
108
 
106
109
  /**
107
110
  * Notes an ending this shard chose for a client on reliable UDP
108
111
  * @param context the connection
109
112
  */
110
- public override channelInactive(context: HandlerContext): Promise<void> {
113
+ public override channelInactive(context: HandlerContext): void {
111
114
  const channel = context.channel
112
115
  const datagrams =
113
116
  PhotonPeer.of(channel)?.transport === ConnectionProtocol.UDP
@@ -115,7 +118,7 @@ export class BackBridge extends DuplexHandlerAdapter {
115
118
  EnetClosure.note(channel, EnetClosure.local(DisconnectReason.LOGIC))
116
119
  }
117
120
 
118
- return context.fireChannelInactive()
121
+ context.fireChannelInactive()
119
122
  }
120
123
 
121
124
  /**
@@ -123,29 +126,13 @@ export class BackBridge extends DuplexHandlerAdapter {
123
126
  * @param context where the write goes
124
127
  * @param message an envelope, or anything else
125
128
  */
126
- public override write(
127
- context: HandlerContext,
128
- message: unknown,
129
- ): Promise<void> {
130
- if (!(message instanceof Envelope)) return context.write(message)
131
-
132
- return context.write(
133
- ByteBuf.wrap(BackBridge.packed(context, message as Envelope)),
134
- )
135
- }
136
-
137
- /**
138
- * Packs a message for the client's shard, without a promise
139
- * @param context where the write goes
140
- * @param message an envelope, or anything else
141
- */
142
- public writeSync(context: HandlerContext, message: unknown): boolean {
143
- if (!(message instanceof Envelope)) return false
129
+ public override write(context: HandlerContext, message: unknown): void {
130
+ if (!(message instanceof Envelope)) {
131
+ context.write(message)
132
+ return
133
+ }
144
134
 
145
- context.writeSync(
146
- ByteBuf.wrap(BackBridge.packed(context, message as Envelope)),
147
- )
148
- return true
135
+ context.write(BackBridge.packed(context, message as Envelope))
149
136
  }
150
137
 
151
138
  /**