@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.
- package/package.json +2 -2
- package/src/codec/index.ts +51 -221
- package/src/dispatch/dispatcher/index.ts +89 -47
- package/src/dispatch/session/index.ts +6 -24
- package/src/index.ts +2 -4
- package/src/photon/balancing/codec/index.ts +27 -53
- package/src/photon/balancing/format/authenticate/request/index.ts +52 -6
- package/src/photon/balancing/format/friends/request/index.ts +21 -5
- package/src/photon/balancing/format/game/create/request/index.ts +45 -8
- package/src/photon/balancing/format/game/debug/request/index.ts +19 -4
- package/src/photon/balancing/format/game/join/request/index.ts +65 -13
- package/src/photon/balancing/format/game/list/request/index.ts +29 -3
- package/src/photon/balancing/format/game/random/request/index.ts +58 -10
- package/src/photon/balancing/format/groups/request/index.ts +19 -3
- package/src/photon/balancing/format/index.ts +7 -0
- package/src/photon/balancing/format/leave/request/index.ts +19 -3
- package/src/photon/balancing/format/lobby/join/request/index.ts +23 -3
- package/src/photon/balancing/format/lobby/stats/request/index.ts +19 -3
- package/src/photon/balancing/format/once/request/index.ts +31 -8
- package/src/photon/balancing/format/properties/get/request/index.ts +31 -4
- package/src/photon/balancing/format/properties/set/request/index.ts +36 -7
- package/src/photon/balancing/format/raise/request/index.ts +76 -10
- package/src/photon/balancing/format/reader/index.ts +75 -6
- package/src/photon/balancing/format/regions/request/index.ts +16 -1
- package/src/photon/balancing/format/rpc/request/index.ts +26 -3
- package/src/photon/balancing/format/settings/request/index.ts +15 -2
- package/src/photon/balancing/format/shared/credentials/index.ts +77 -33
- package/src/photon/balancing/format/shared/lobby/index.ts +41 -5
- package/src/photon/balancing/format/shared/options/index.ts +56 -24
- package/src/photon/balancing/format/table/index.ts +399 -0
- package/src/photon/balancing/index.ts +11 -1
- package/src/photon/balancing/travel/index.ts +15 -12
- package/src/photon/client/connection/index.ts +6 -6
- package/src/photon/cluster/back/index.ts +32 -45
- package/src/photon/cluster/dresser/index.ts +7 -8
- package/src/photon/cluster/front/index.ts +25 -49
- package/src/photon/cluster/grid/index.ts +1 -1
- package/src/photon/cluster/mover/index.ts +12 -12
- package/src/photon/cluster/press/index.ts +2 -18
- package/src/photon/cluster/route/game/index.ts +9 -11
- package/src/photon/cluster/route/master/index.ts +15 -34
- package/src/photon/cluster/route/name/index.ts +4 -21
- package/src/photon/cluster/seat/game/index.ts +6 -26
- package/src/photon/cluster/seat/master/index.ts +1 -1
- package/src/photon/cluster/sessions/index.ts +5 -6
- package/src/photon/cluster/spread/index.ts +8 -147
- package/src/photon/enet/client/index.ts +1 -8
- package/src/photon/enet/gateway/index.ts +5 -15
- package/src/photon/enet/index.ts +1 -1
- package/src/photon/enet/link/index.ts +34 -15
- package/src/photon/enet/outbound/index.ts +279 -0
- package/src/photon/enet/peer/index.ts +59 -0
- package/src/photon/enet/transport/index.ts +8 -24
- package/src/photon/game/admission/index.ts +353 -0
- package/src/photon/game/bag/index.ts +13 -0
- package/src/photon/game/broadcast/index.ts +79 -0
- package/src/photon/game/editor/index.ts +446 -0
- package/src/photon/game/gate/index.ts +9 -8
- package/src/photon/game/handler/index.ts +30 -3
- package/src/photon/game/history/index.ts +234 -0
- package/src/photon/game/hooked/index.ts +16 -15
- package/src/photon/game/index.ts +12 -1
- package/src/photon/game/lifecycle/index.ts +193 -0
- package/src/photon/game/peer/index.ts +1 -10
- package/src/photon/game/properties/index.ts +342 -0
- package/src/photon/game/room/index.ts +435 -1793
- package/src/photon/game/rooms/index.ts +2 -1
- package/src/photon/game/seats/index.ts +237 -0
- package/src/photon/game/server/index.ts +12 -2
- package/src/photon/game/services/index.ts +41 -0
- package/src/photon/game/settings/index.ts +22 -0
- package/src/photon/game/snapshot/index.ts +133 -0
- package/src/photon/game/throttle/index.ts +60 -0
- package/src/photon/game/touch/index.ts +2 -5
- package/src/photon/game/venue/index.ts +31 -0
- package/src/photon/master/application/index.ts +7 -0
- package/src/photon/master/gate/index.ts +12 -8
- package/src/photon/master/handler/index.ts +36 -748
- package/src/photon/master/index.ts +5 -0
- package/src/photon/master/list/sql/index.ts +37 -3
- package/src/photon/master/listing/index.ts +133 -0
- package/src/photon/master/lobby/index.ts +9 -0
- package/src/photon/master/login/index.ts +424 -0
- package/src/photon/master/matchmaking/index.ts +282 -0
- package/src/photon/master/query/index.ts +45 -0
- package/src/photon/master/redirect/index.ts +8 -7
- package/src/photon/master/services/index.ts +35 -0
- package/src/photon/master/settings/index.ts +44 -0
- package/src/photon/master/sql/cost/index.ts +263 -0
- package/src/photon/master/sql/index.ts +1 -0
- package/src/photon/message/client/index.ts +14 -11
- package/src/photon/message/handler/index.ts +22 -64
- package/src/photon/message/pipeline/index.ts +12 -12
- package/src/photon/message/server/index.ts +87 -43
- package/src/photon/message/watch/index.ts +14 -37
- package/src/photon/server/deferral/index.ts +57 -0
- package/src/photon/server/host/index.ts +32 -10
- package/src/photon/server/index.ts +1 -0
- package/src/photon/tcp/client/index.ts +1 -1
- package/src/photon/tcp/codec/index.ts +13 -42
- package/src/photon/tcp/server/index.ts +4 -4
- package/src/photon/websocket/bridge/index.ts +16 -20
- package/src/photon/websocket/message/index.ts +27 -39
- package/src/photon/websocket/path/index.ts +2 -5
- package/src/scale/fanout/index.ts +6 -6
- package/src/scale/index.ts +2 -4
- package/src/scale/outbound/index.ts +192 -0
- package/src/scale/relay/index.ts +20 -31
- package/src/scale/sink/index.ts +6 -11
- package/src/scale/transport/index.ts +27 -44
- package/src/scale/tunnel/index.ts +37 -91
- package/src/smartfox/common/bluebox/gateway/index.ts +401 -0
- package/src/smartfox/common/bluebox/index.ts +4 -0
- package/src/smartfox/{x2 → common}/bluebox/transport/index.ts +36 -23
- package/src/smartfox/common/index.ts +5 -0
- package/src/smartfox/common/strikes/index.ts +74 -0
- package/src/smartfox/pro/bluebox/index.ts +176 -4
- package/src/smartfox/pro/codec/index.ts +8 -7
- package/src/smartfox/pro/escalation/index.ts +28 -20
- package/src/smartfox/pro/flood/index.ts +2 -2
- package/src/smartfox/pro/format/extension/raw/index.ts +12 -2
- package/src/smartfox/pro/handler/chat/index.ts +11 -8
- package/src/smartfox/pro/handler/login/index.ts +2 -25
- package/src/smartfox/pro/handler/shared/index.ts +4 -3
- package/src/smartfox/pro/index.ts +11 -5
- package/src/smartfox/pro/login/gate/index.ts +166 -0
- package/src/smartfox/pro/login/index.ts +1 -0
- package/src/smartfox/pro/moderation/index.ts +220 -0
- package/src/smartfox/pro/options/index.ts +5 -5
- package/src/smartfox/pro/protocol/index.ts +62 -8
- package/src/smartfox/pro/web/index.ts +33 -26
- package/src/smartfox/pro/zone/index.ts +59 -282
- package/src/smartfox/pro/zones/index.ts +3 -3
- package/src/smartfox/x2/bluebox/index.ts +149 -4
- package/src/smartfox/x2/chat/index.ts +9 -19
- package/src/smartfox/x2/codec/index.ts +31 -39
- package/src/smartfox/x2/config/index.ts +6 -1
- package/src/smartfox/x2/data/array/index.ts +96 -60
- package/src/smartfox/x2/data/object/index.ts +144 -82
- package/src/smartfox/x2/data/serializer/index.ts +41 -23
- package/src/smartfox/x2/flood/gate/index.ts +19 -13
- package/src/smartfox/x2/format/buddy/init/response/index.ts +4 -3
- package/src/smartfox/x2/format/find/rooms/response/index.ts +4 -3
- package/src/smartfox/x2/format/find/users/response/index.ts +4 -3
- package/src/smartfox/x2/format/group/subscribe/response/index.ts +4 -3
- package/src/smartfox/x2/format/login/response/index.ts +4 -3
- package/src/smartfox/x2/format/mmo/position/response/index.ts +8 -6
- package/src/smartfox/x2/format/room/join/response/index.ts +4 -3
- package/src/smartfox/x2/games/index.ts +35 -8
- package/src/smartfox/x2/hall/index.ts +0 -6
- package/src/smartfox/x2/handler/session/index.ts +1 -1
- package/src/smartfox/x2/index.ts +8 -3
- package/src/smartfox/x2/member/index.ts +10 -3
- package/src/smartfox/x2/packet/login/response/index.ts +12 -0
- package/src/smartfox/x2/protocol/index.ts +11 -1
- package/src/smartfox/x2/rooms/index.ts +1 -2
- package/src/smartfox/x2/sessions/index.ts +6 -0
- package/src/smartfox/x2/udp/index.ts +61 -24
- package/src/smartfox/x2/web/index.ts +35 -17
- package/src/smartfox/x2/websocket/index.ts +18 -36
- package/src/smartfox/x2/zone/index.ts +77 -28
- package/src/smartfox/x2/zones/index.ts +17 -5
- package/src/photon/enet/handler/index.ts +0 -65
- package/src/scale/hosted/index.ts +0 -68
- package/src/scale/outlet/index.ts +0 -121
- package/src/smartfox/pro/bluebox/gateway/index.ts +0 -310
- package/src/smartfox/pro/bluebox/session/index.ts +0 -63
- package/src/smartfox/pro/bluebox/transport/index.ts +0 -104
- package/src/smartfox/x2/bluebox/gateway/index.ts +0 -315
- /package/src/smartfox/{x2 → common}/bluebox/session/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/memory/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/offender/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/store/index.ts +0 -0
- /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 {
|
|
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
|
-
*
|
|
10
|
+
* One shared travel per delivery mode on channel 0, unencrypted
|
|
11
11
|
*/
|
|
12
|
-
private static readonly plain: Travel =
|
|
13
|
-
Delivery.
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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):
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
public override channelRead(context: HandlerContext, message: unknown): void {
|
|
46
|
+
if (!(message instanceof ByteBuf)) {
|
|
47
|
+
context.fireChannelRead(message)
|
|
48
|
+
return
|
|
49
|
+
}
|
|
51
50
|
|
|
52
|
-
|
|
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
|
|
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
|
|
70
|
-
|
|
71
|
-
const cargo = cargoes[index]
|
|
72
|
-
if (cargo === undefined) continue
|
|
68
|
+
): void {
|
|
69
|
+
const channel = context.channel
|
|
73
70
|
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
this.pass(context, cargoes, index
|
|
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
|
|
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
|
-
|
|
96
|
+
context.fireUserEventTriggered(this.init)
|
|
97
|
+
return
|
|
96
98
|
}
|
|
97
99
|
|
|
98
100
|
if (cargo === 'idle') {
|
|
99
|
-
|
|
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)
|
|
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):
|
|
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
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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.
|
|
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
|
/**
|