@netifyjs/protocol 1.0.0-alpha.2 → 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 +82 -157
- package/src/dispatch/dispatcher/index.ts +116 -33
- package/src/dispatch/session/index.ts +9 -3
- 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/binary/v18/index.ts +26 -1
- package/src/photon/binary/value/index.ts +52 -3
- 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/binary/index.ts +35 -1
- package/src/photon/message/client/index.ts +14 -11
- package/src/photon/message/format/index.ts +9 -0
- package/src/photon/message/handler/index.ts +48 -63
- 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 +127 -15
- package/src/photon/server/config/index.ts +5 -0
- package/src/photon/server/deferral/index.ts +57 -0
- package/src/photon/server/host/index.ts +36 -10
- package/src/photon/server/index.ts +1 -0
- package/src/photon/server/listeners/index.ts +11 -0
- package/src/photon/tcp/client/index.ts +1 -1
- package/src/photon/tcp/codec/index.ts +41 -38
- package/src/photon/tcp/framing/index.ts +24 -4
- 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/batch/index.ts +14 -6
- 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 +24 -16
- package/src/scale/sink/index.ts +6 -11
- package/src/scale/transport/index.ts +27 -44
- package/src/scale/tunnel/index.ts +56 -86
- 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 +34 -40
- 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
|
/**
|
|
@@ -261,6 +261,11 @@ const Code = {
|
|
|
261
261
|
* @class
|
|
262
262
|
*/
|
|
263
263
|
export class Protocol18 extends BinaryProtocolAdapter {
|
|
264
|
+
/**
|
|
265
|
+
* Longest text read straight away through the name cache
|
|
266
|
+
*/
|
|
267
|
+
private static readonly named: number = 24
|
|
268
|
+
|
|
264
269
|
/**
|
|
265
270
|
* Custom type codes below this go out in the slim form
|
|
266
271
|
*/
|
|
@@ -376,7 +381,7 @@ export class Protocol18 extends BinaryProtocolAdapter {
|
|
|
376
381
|
case Code.DOUBLE_ZERO:
|
|
377
382
|
return PhotonValue.double(0)
|
|
378
383
|
case Code.STRING:
|
|
379
|
-
return
|
|
384
|
+
return this.decodeText(buffer)
|
|
380
385
|
case Code.BYTE_ARRAY:
|
|
381
386
|
return PhotonValue.bytes(this.decodeBytes(buffer))
|
|
382
387
|
case Code.CUSTOM:
|
|
@@ -392,6 +397,13 @@ export class Protocol18 extends BinaryProtocolAdapter {
|
|
|
392
397
|
* @param buffer where it goes
|
|
393
398
|
*/
|
|
394
399
|
protected encodeValue(value: PhotonValue, buffer: ByteBuf): void {
|
|
400
|
+
const spelt = value.spelling
|
|
401
|
+
if (spelt !== null) {
|
|
402
|
+
buffer.writeUint8(Code.STRING)
|
|
403
|
+
this.encodeBytes(spelt, buffer)
|
|
404
|
+
return
|
|
405
|
+
}
|
|
406
|
+
|
|
395
407
|
const data = value.data
|
|
396
408
|
|
|
397
409
|
switch (value.shape.kind) {
|
|
@@ -606,6 +618,19 @@ export class Protocol18 extends BinaryProtocolAdapter {
|
|
|
606
618
|
return BigInt.asIntN(64, (raw >> 1n) ^ -(raw & 1n))
|
|
607
619
|
}
|
|
608
620
|
|
|
621
|
+
/**
|
|
622
|
+
* Reads a string value, keeping a long one as bytes until it's read
|
|
623
|
+
* @param buffer bytes to read from
|
|
624
|
+
*/
|
|
625
|
+
private decodeText(buffer: ByteBuf): PhotonValue {
|
|
626
|
+
const size = this.size(this.decodeCount(buffer), buffer)
|
|
627
|
+
if (size <= Protocol18.named) {
|
|
628
|
+
return PhotonValue.string(this.names.read(size, buffer))
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
return PhotonValue.text(buffer.readBytes(size))
|
|
632
|
+
}
|
|
633
|
+
|
|
609
634
|
/**
|
|
610
635
|
* Reads a string with its length
|
|
611
636
|
* @param buffer bytes to read from
|
|
@@ -55,15 +55,30 @@ export class PhotonValue {
|
|
|
55
55
|
(string | undefined)[]
|
|
56
56
|
>()
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Turns kept UTF-8 bytes into text
|
|
60
|
+
*/
|
|
61
|
+
private static readonly utf8: TextDecoder = new TextDecoder()
|
|
62
|
+
|
|
58
63
|
/**
|
|
59
64
|
* Its exact type
|
|
60
65
|
*/
|
|
61
66
|
public readonly shape: Shape
|
|
62
67
|
|
|
63
68
|
/**
|
|
64
|
-
* What it holds
|
|
69
|
+
* What it holds, once it's been read
|
|
70
|
+
*/
|
|
71
|
+
private held: PhotonData
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* UTF-8 bytes of a text that came off the wire, or null
|
|
65
75
|
*/
|
|
66
|
-
|
|
76
|
+
private spelt: Uint8Array | null
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Whether the text still has to be read out of its bytes
|
|
80
|
+
*/
|
|
81
|
+
private waiting: boolean
|
|
67
82
|
|
|
68
83
|
/**
|
|
69
84
|
* What tables file it under once it's been worked out, or null
|
|
@@ -81,11 +96,33 @@ export class PhotonValue {
|
|
|
81
96
|
*/
|
|
82
97
|
private constructor(shape: Shape, data: PhotonData) {
|
|
83
98
|
this.shape = shape
|
|
84
|
-
this.
|
|
99
|
+
this.held = data
|
|
100
|
+
this.spelt = null
|
|
101
|
+
this.waiting = false
|
|
85
102
|
this.label = null
|
|
86
103
|
this.labelled = false
|
|
87
104
|
}
|
|
88
105
|
|
|
106
|
+
/**
|
|
107
|
+
* What it holds
|
|
108
|
+
*/
|
|
109
|
+
public get data(): PhotonData {
|
|
110
|
+
const spelt = this.spelt
|
|
111
|
+
if (this.waiting && spelt !== null) {
|
|
112
|
+
this.held = PhotonValue.utf8.decode(spelt)
|
|
113
|
+
this.waiting = false
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return this.held
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* UTF-8 bytes of a text read off the wire, or null
|
|
121
|
+
*/
|
|
122
|
+
public get spelling(): Uint8Array | null {
|
|
123
|
+
return this.spelt
|
|
124
|
+
}
|
|
125
|
+
|
|
89
126
|
/**
|
|
90
127
|
* A value of any shape
|
|
91
128
|
* @param shape its exact type
|
|
@@ -177,6 +214,18 @@ export class PhotonValue {
|
|
|
177
214
|
return new PhotonValue(Shape.string(), value)
|
|
178
215
|
}
|
|
179
216
|
|
|
217
|
+
/**
|
|
218
|
+
* A text kept as its UTF-8 bytes until something reads it
|
|
219
|
+
* @param bytes the text as UTF-8, owned by the value from now on
|
|
220
|
+
*/
|
|
221
|
+
public static text(bytes: Uint8Array): PhotonValue {
|
|
222
|
+
const value = new PhotonValue(Shape.string(), '')
|
|
223
|
+
value.spelt = bytes
|
|
224
|
+
value.waiting = true
|
|
225
|
+
|
|
226
|
+
return value
|
|
227
|
+
}
|
|
228
|
+
|
|
180
229
|
/**
|
|
181
230
|
* Raw bytes
|
|
182
231
|
* @param value what to hold
|
|
@@ -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
|