@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.
Files changed (183) hide show
  1. package/package.json +2 -2
  2. package/src/codec/index.ts +82 -157
  3. package/src/dispatch/dispatcher/index.ts +116 -33
  4. package/src/dispatch/session/index.ts +9 -3
  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/binary/v18/index.ts +26 -1
  34. package/src/photon/binary/value/index.ts +52 -3
  35. package/src/photon/client/connection/index.ts +6 -6
  36. package/src/photon/cluster/back/index.ts +32 -45
  37. package/src/photon/cluster/dresser/index.ts +7 -8
  38. package/src/photon/cluster/front/index.ts +25 -49
  39. package/src/photon/cluster/grid/index.ts +1 -1
  40. package/src/photon/cluster/mover/index.ts +12 -12
  41. package/src/photon/cluster/press/index.ts +2 -18
  42. package/src/photon/cluster/route/game/index.ts +9 -11
  43. package/src/photon/cluster/route/master/index.ts +15 -34
  44. package/src/photon/cluster/route/name/index.ts +4 -21
  45. package/src/photon/cluster/seat/game/index.ts +6 -26
  46. package/src/photon/cluster/seat/master/index.ts +1 -1
  47. package/src/photon/cluster/sessions/index.ts +5 -6
  48. package/src/photon/cluster/spread/index.ts +8 -147
  49. package/src/photon/enet/client/index.ts +1 -8
  50. package/src/photon/enet/gateway/index.ts +5 -15
  51. package/src/photon/enet/index.ts +1 -1
  52. package/src/photon/enet/link/index.ts +34 -15
  53. package/src/photon/enet/outbound/index.ts +279 -0
  54. package/src/photon/enet/peer/index.ts +59 -0
  55. package/src/photon/enet/transport/index.ts +8 -24
  56. package/src/photon/game/admission/index.ts +353 -0
  57. package/src/photon/game/bag/index.ts +13 -0
  58. package/src/photon/game/broadcast/index.ts +79 -0
  59. package/src/photon/game/editor/index.ts +446 -0
  60. package/src/photon/game/gate/index.ts +9 -8
  61. package/src/photon/game/handler/index.ts +30 -3
  62. package/src/photon/game/history/index.ts +234 -0
  63. package/src/photon/game/hooked/index.ts +16 -15
  64. package/src/photon/game/index.ts +12 -1
  65. package/src/photon/game/lifecycle/index.ts +193 -0
  66. package/src/photon/game/peer/index.ts +1 -10
  67. package/src/photon/game/properties/index.ts +342 -0
  68. package/src/photon/game/room/index.ts +435 -1793
  69. package/src/photon/game/rooms/index.ts +2 -1
  70. package/src/photon/game/seats/index.ts +237 -0
  71. package/src/photon/game/server/index.ts +12 -2
  72. package/src/photon/game/services/index.ts +41 -0
  73. package/src/photon/game/settings/index.ts +22 -0
  74. package/src/photon/game/snapshot/index.ts +133 -0
  75. package/src/photon/game/throttle/index.ts +60 -0
  76. package/src/photon/game/touch/index.ts +2 -5
  77. package/src/photon/game/venue/index.ts +31 -0
  78. package/src/photon/master/application/index.ts +7 -0
  79. package/src/photon/master/gate/index.ts +12 -8
  80. package/src/photon/master/handler/index.ts +36 -748
  81. package/src/photon/master/index.ts +5 -0
  82. package/src/photon/master/list/sql/index.ts +37 -3
  83. package/src/photon/master/listing/index.ts +133 -0
  84. package/src/photon/master/lobby/index.ts +9 -0
  85. package/src/photon/master/login/index.ts +424 -0
  86. package/src/photon/master/matchmaking/index.ts +282 -0
  87. package/src/photon/master/query/index.ts +45 -0
  88. package/src/photon/master/redirect/index.ts +8 -7
  89. package/src/photon/master/services/index.ts +35 -0
  90. package/src/photon/master/settings/index.ts +44 -0
  91. package/src/photon/master/sql/cost/index.ts +263 -0
  92. package/src/photon/master/sql/index.ts +1 -0
  93. package/src/photon/message/binary/index.ts +35 -1
  94. package/src/photon/message/client/index.ts +14 -11
  95. package/src/photon/message/format/index.ts +9 -0
  96. package/src/photon/message/handler/index.ts +48 -63
  97. package/src/photon/message/pipeline/index.ts +12 -12
  98. package/src/photon/message/server/index.ts +87 -43
  99. package/src/photon/message/watch/index.ts +127 -15
  100. package/src/photon/server/config/index.ts +5 -0
  101. package/src/photon/server/deferral/index.ts +57 -0
  102. package/src/photon/server/host/index.ts +36 -10
  103. package/src/photon/server/index.ts +1 -0
  104. package/src/photon/server/listeners/index.ts +11 -0
  105. package/src/photon/tcp/client/index.ts +1 -1
  106. package/src/photon/tcp/codec/index.ts +41 -38
  107. package/src/photon/tcp/framing/index.ts +24 -4
  108. package/src/photon/tcp/server/index.ts +4 -4
  109. package/src/photon/websocket/bridge/index.ts +16 -20
  110. package/src/photon/websocket/message/index.ts +27 -39
  111. package/src/photon/websocket/path/index.ts +2 -5
  112. package/src/scale/batch/index.ts +14 -6
  113. package/src/scale/fanout/index.ts +6 -6
  114. package/src/scale/index.ts +2 -4
  115. package/src/scale/outbound/index.ts +192 -0
  116. package/src/scale/relay/index.ts +24 -16
  117. package/src/scale/sink/index.ts +6 -11
  118. package/src/scale/transport/index.ts +27 -44
  119. package/src/scale/tunnel/index.ts +56 -86
  120. package/src/smartfox/common/bluebox/gateway/index.ts +401 -0
  121. package/src/smartfox/common/bluebox/index.ts +4 -0
  122. package/src/smartfox/{x2 → common}/bluebox/transport/index.ts +36 -23
  123. package/src/smartfox/common/index.ts +5 -0
  124. package/src/smartfox/common/strikes/index.ts +74 -0
  125. package/src/smartfox/pro/bluebox/index.ts +176 -4
  126. package/src/smartfox/pro/codec/index.ts +8 -7
  127. package/src/smartfox/pro/escalation/index.ts +28 -20
  128. package/src/smartfox/pro/flood/index.ts +2 -2
  129. package/src/smartfox/pro/format/extension/raw/index.ts +12 -2
  130. package/src/smartfox/pro/handler/chat/index.ts +11 -8
  131. package/src/smartfox/pro/handler/login/index.ts +2 -25
  132. package/src/smartfox/pro/handler/shared/index.ts +4 -3
  133. package/src/smartfox/pro/index.ts +11 -5
  134. package/src/smartfox/pro/login/gate/index.ts +166 -0
  135. package/src/smartfox/pro/login/index.ts +1 -0
  136. package/src/smartfox/pro/moderation/index.ts +220 -0
  137. package/src/smartfox/pro/options/index.ts +5 -5
  138. package/src/smartfox/pro/protocol/index.ts +62 -8
  139. package/src/smartfox/pro/web/index.ts +33 -26
  140. package/src/smartfox/pro/zone/index.ts +59 -282
  141. package/src/smartfox/pro/zones/index.ts +3 -3
  142. package/src/smartfox/x2/bluebox/index.ts +149 -4
  143. package/src/smartfox/x2/chat/index.ts +9 -19
  144. package/src/smartfox/x2/codec/index.ts +34 -40
  145. package/src/smartfox/x2/config/index.ts +6 -1
  146. package/src/smartfox/x2/data/array/index.ts +96 -60
  147. package/src/smartfox/x2/data/object/index.ts +144 -82
  148. package/src/smartfox/x2/data/serializer/index.ts +41 -23
  149. package/src/smartfox/x2/flood/gate/index.ts +19 -13
  150. package/src/smartfox/x2/format/buddy/init/response/index.ts +4 -3
  151. package/src/smartfox/x2/format/find/rooms/response/index.ts +4 -3
  152. package/src/smartfox/x2/format/find/users/response/index.ts +4 -3
  153. package/src/smartfox/x2/format/group/subscribe/response/index.ts +4 -3
  154. package/src/smartfox/x2/format/login/response/index.ts +4 -3
  155. package/src/smartfox/x2/format/mmo/position/response/index.ts +8 -6
  156. package/src/smartfox/x2/format/room/join/response/index.ts +4 -3
  157. package/src/smartfox/x2/games/index.ts +35 -8
  158. package/src/smartfox/x2/hall/index.ts +0 -6
  159. package/src/smartfox/x2/handler/session/index.ts +1 -1
  160. package/src/smartfox/x2/index.ts +8 -3
  161. package/src/smartfox/x2/member/index.ts +10 -3
  162. package/src/smartfox/x2/packet/login/response/index.ts +12 -0
  163. package/src/smartfox/x2/protocol/index.ts +11 -1
  164. package/src/smartfox/x2/rooms/index.ts +1 -2
  165. package/src/smartfox/x2/sessions/index.ts +6 -0
  166. package/src/smartfox/x2/udp/index.ts +61 -24
  167. package/src/smartfox/x2/web/index.ts +35 -17
  168. package/src/smartfox/x2/websocket/index.ts +18 -36
  169. package/src/smartfox/x2/zone/index.ts +77 -28
  170. package/src/smartfox/x2/zones/index.ts +17 -5
  171. package/src/photon/enet/handler/index.ts +0 -65
  172. package/src/scale/hosted/index.ts +0 -68
  173. package/src/scale/outlet/index.ts +0 -121
  174. package/src/smartfox/pro/bluebox/gateway/index.ts +0 -310
  175. package/src/smartfox/pro/bluebox/session/index.ts +0 -63
  176. package/src/smartfox/pro/bluebox/transport/index.ts +0 -104
  177. package/src/smartfox/x2/bluebox/gateway/index.ts +0 -315
  178. /package/src/smartfox/{x2 → common}/bluebox/session/index.ts +0 -0
  179. /package/src/smartfox/{pro → common}/counters/index.ts +0 -0
  180. /package/src/smartfox/{pro → common}/counters/memory/index.ts +0 -0
  181. /package/src/smartfox/{pro → common}/counters/offender/index.ts +0 -0
  182. /package/src/smartfox/{pro → common}/counters/store/index.ts +0 -0
  183. /package/src/smartfox/{pro → common}/sequence/index.ts +0 -0
@@ -0,0 +1,342 @@
1
+ import { GameProperty } from '../../balancing/code/game/index.ts'
2
+ import { ErrorMessage } from '../../balancing/code/message/index.ts'
3
+ import { RoomOptionFlag } from '../../balancing/code/room/index.ts'
4
+ import type { Lobby } from '../../balancing/entity/lobby/index.ts'
5
+ import { PhotonHashtable } from '../../binary/hashtable/index.ts'
6
+ import { Kind } from '../../binary/kind/index.ts'
7
+ import { Shape } from '../../binary/shape/index.ts'
8
+ import { PhotonValue } from '../../binary/value/index.ts'
9
+ import { PropertyBag } from '../bag/index.ts'
10
+ import type { EntrySetup } from '../entry/index.ts'
11
+ import { Fault } from '../fault/index.ts'
12
+ import type { RoomSnapshot } from '../snapshot/index.ts'
13
+ import { WellKnownProperties } from '../wellknown/index.ts'
14
+
15
+ /**
16
+ * The properties and options of one room
17
+ * @class
18
+ */
19
+ export class RoomProperties {
20
+ /**
21
+ * Lowest property code the server owns
22
+ */
23
+ private static readonly LOWEST_WELL_KNOWN: number = 235
24
+
25
+ /**
26
+ * Every property the room holds
27
+ */
28
+ public readonly bag: PropertyBag
29
+
30
+ /**
31
+ * Lobby it's listed in, or null
32
+ */
33
+ public lobby: Lobby | null
34
+
35
+ /**
36
+ * Property keys lobbies show, or null
37
+ */
38
+ public filter: readonly PhotonValue[] | null
39
+
40
+ /**
41
+ * Room option bits
42
+ */
43
+ private options: number
44
+
45
+ /**
46
+ * Starts open and visible with no player limit
47
+ */
48
+ public constructor() {
49
+ this.bag = PropertyBag.of()
50
+ this.lobby = null
51
+ this.filter = null
52
+ this.options = 0
53
+
54
+ this.bag.set(
55
+ RoomProperties.key(GameProperty.MAX_PLAYERS),
56
+ PhotonValue.byte(0),
57
+ )
58
+ this.bag.set(
59
+ RoomProperties.key(GameProperty.IS_OPEN),
60
+ PhotonValue.bool(true),
61
+ )
62
+ this.bag.set(
63
+ RoomProperties.key(GameProperty.IS_VISIBLE),
64
+ PhotonValue.bool(true),
65
+ )
66
+ }
67
+
68
+ /**
69
+ * The key of a well-known property
70
+ * @param code which property
71
+ */
72
+ public static key(code: number): PhotonValue {
73
+ return PhotonValue.byte(code)
74
+ }
75
+
76
+ /**
77
+ * A table with one well-known property
78
+ * @param code which property
79
+ * @param value what it holds
80
+ */
81
+ public static single(code: number, value: PhotonValue): PhotonHashtable {
82
+ return PhotonHashtable.of().set(RoomProperties.key(code), value)
83
+ }
84
+
85
+ /**
86
+ * User ids as a property value
87
+ * @param users who has a seat kept
88
+ */
89
+ public static names(users: readonly string[]): PhotonValue {
90
+ return PhotonValue.array(Shape.string(), [...users])
91
+ }
92
+
93
+ /**
94
+ * Whether a property is one a saved room keeps outside its table
95
+ * @param key typed key
96
+ */
97
+ private static wellKnown(key: PhotonValue): boolean {
98
+ const code = key.kind === Kind.BYTE ? (key.integer() ?? 0) : 0
99
+
100
+ return (
101
+ code >= RoomProperties.LOWEST_WELL_KNOWN &&
102
+ code !== GameProperty.PROPS_LISTED_IN_LOBBY
103
+ )
104
+ }
105
+
106
+ /**
107
+ * Room option bits
108
+ */
109
+ public get flags(): number {
110
+ return this.options
111
+ }
112
+
113
+ /**
114
+ * Most players allowed, 0 for any number
115
+ */
116
+ public get maxPlayers(): number {
117
+ return this.number(GameProperty.MAX_PLAYERS) ?? 0
118
+ }
119
+
120
+ /**
121
+ * Whether players may join
122
+ */
123
+ public get isOpen(): boolean {
124
+ return this.flag(GameProperty.IS_OPEN) ?? true
125
+ }
126
+
127
+ /**
128
+ * Whether lobbies list it
129
+ */
130
+ public get isVisible(): boolean {
131
+ return this.flag(GameProperty.IS_VISIBLE) ?? true
132
+ }
133
+
134
+ /**
135
+ * How long a player's seat is kept in ms
136
+ */
137
+ public get playerTtl(): number {
138
+ return this.number(GameProperty.PLAYER_TTL) ?? 0
139
+ }
140
+
141
+ /**
142
+ * How long the empty room stays in ms
143
+ */
144
+ public get emptyRoomTtl(): number {
145
+ return this.number(GameProperty.EMPTY_ROOM_TTL) ?? 0
146
+ }
147
+
148
+ /**
149
+ * Whether players hear nothing about each other
150
+ */
151
+ public get quiet(): boolean {
152
+ return this.has(RoomOptionFlag.SUPPRESS_PLAYER_INFO)
153
+ }
154
+
155
+ /**
156
+ * Whether join and leave events stay unsent
157
+ */
158
+ public get suppressed(): boolean {
159
+ return this.quiet || this.has(RoomOptionFlag.SUPPRESS_ROOM_EVENTS)
160
+ }
161
+
162
+ /**
163
+ * Whether a room option is on
164
+ * @param bit which option
165
+ */
166
+ public has(bit: number): boolean {
167
+ return (this.options & bit) !== 0
168
+ }
169
+
170
+ /**
171
+ * Takes on a set of room option bits
172
+ * @param flags the bits
173
+ */
174
+ public adopt(flags: number): void {
175
+ this.options = flags
176
+ this.bag.deleteNull = this.has(RoomOptionFlag.DELETE_NULL_PROPS)
177
+ }
178
+
179
+ /**
180
+ * Takes over the options of the request that made the room, or says why not
181
+ * @param setup the request as the room needs it
182
+ * @param longest longest empty room wait allowed in ms
183
+ */
184
+ public furnish(setup: EntrySetup, longest: number): Fault | null {
185
+ this.adopt(setup.flags)
186
+ if (setup.emptyRoomTtl > longest) {
187
+ return Fault.invalid(
188
+ ErrorMessage.MAX_TTL_EXCEEDED,
189
+ setup.emptyRoomTtl,
190
+ longest,
191
+ )
192
+ }
193
+
194
+ this.bag.merge(setup.properties)
195
+ if (setup.expectedUsers !== null) {
196
+ this.bag.set(
197
+ RoomProperties.key(GameProperty.EXPECTED_USERS),
198
+ RoomProperties.names(setup.expectedUsers),
199
+ )
200
+ }
201
+
202
+ if (setup.emptyRoomTtl !== 0) {
203
+ this.bag.set(
204
+ RoomProperties.key(GameProperty.EMPTY_ROOM_TTL),
205
+ PhotonValue.int(setup.emptyRoomTtl),
206
+ )
207
+ }
208
+
209
+ if (setup.playerTtl !== 0) {
210
+ this.bag.set(
211
+ RoomProperties.key(GameProperty.PLAYER_TTL),
212
+ PhotonValue.int(setup.playerTtl),
213
+ )
214
+ }
215
+
216
+ return null
217
+ }
218
+
219
+ /**
220
+ * Remembers which properties lobbies show
221
+ * @param properties room properties of a request
222
+ */
223
+ public list(properties: PhotonHashtable): void {
224
+ const key = RoomProperties.key(GameProperty.PROPS_LISTED_IN_LOBBY)
225
+ if (!properties.has(key)) return
226
+
227
+ this.filter = WellKnownProperties.filter(properties.get(key))
228
+ }
229
+
230
+ /**
231
+ * The properties of a table that lobbies show
232
+ * @param table properties to pick from
233
+ */
234
+ public listed(table: PhotonHashtable): PhotonHashtable {
235
+ const filter = this.filter
236
+ const shown =
237
+ filter === null
238
+ ? null
239
+ : new Set<string | null>(
240
+ filter.map<string | null>(
241
+ (key: PhotonValue): string | null => key.identity,
242
+ ),
243
+ )
244
+ const hidden = new Set<string | null>(
245
+ [
246
+ GameProperty.MAX_PLAYERS,
247
+ GameProperty.IS_OPEN,
248
+ GameProperty.IS_VISIBLE,
249
+ GameProperty.PROPS_LISTED_IN_LOBBY,
250
+ ].map<string | null>(
251
+ (code: number): string | null => RoomProperties.key(code).identity,
252
+ ),
253
+ )
254
+ const listed = PhotonHashtable.of()
255
+
256
+ for (const [key, value] of table.entries()) {
257
+ const identity = key.identity
258
+ if (shown === null ? hidden.has(identity) : !shown.has(identity)) continue
259
+ listed.set(key, value)
260
+ }
261
+
262
+ return listed
263
+ }
264
+
265
+ /**
266
+ * The properties a saved room keeps in its table
267
+ */
268
+ public saved(): PhotonHashtable {
269
+ const properties = PhotonHashtable.of()
270
+ for (const [key, value] of this.bag.all().entries()) {
271
+ if (!RoomProperties.wellKnown(key)) properties.set(key, value)
272
+ }
273
+
274
+ return properties
275
+ }
276
+
277
+ /**
278
+ * Writes the well-known properties of a saved room
279
+ * @param snapshot the room as it was saved
280
+ */
281
+ public revive(snapshot: RoomSnapshot): void {
282
+ const properties = PhotonHashtable.of()
283
+ .set(
284
+ RoomProperties.key(GameProperty.IS_OPEN),
285
+ PhotonValue.bool(snapshot.isOpen),
286
+ )
287
+ .set(
288
+ RoomProperties.key(GameProperty.IS_VISIBLE),
289
+ PhotonValue.bool(snapshot.isVisible),
290
+ )
291
+ .set(
292
+ RoomProperties.key(GameProperty.MASTER_CLIENT_ID),
293
+ PhotonValue.int(0),
294
+ )
295
+
296
+ if (snapshot.emptyRoomTtl !== 0) {
297
+ properties.set(
298
+ RoomProperties.key(GameProperty.EMPTY_ROOM_TTL),
299
+ PhotonValue.int(snapshot.emptyRoomTtl),
300
+ )
301
+ }
302
+
303
+ if (snapshot.maxPlayers !== 0) {
304
+ properties.set(
305
+ RoomProperties.key(GameProperty.MAX_PLAYERS),
306
+ PhotonValue.byte(snapshot.maxPlayers & 0xff),
307
+ )
308
+ }
309
+
310
+ if (snapshot.playerTtl !== 0) {
311
+ properties.set(
312
+ RoomProperties.key(GameProperty.PLAYER_TTL),
313
+ PhotonValue.int(snapshot.playerTtl),
314
+ )
315
+ }
316
+
317
+ if (snapshot.expected.length > 0) {
318
+ properties.set(
319
+ RoomProperties.key(GameProperty.EXPECTED_USERS),
320
+ RoomProperties.names(snapshot.expected),
321
+ )
322
+ }
323
+
324
+ this.bag.merge(properties)
325
+ }
326
+
327
+ /**
328
+ * A whole number property of the room, or null
329
+ * @param code which property
330
+ */
331
+ private number(code: number): number | null {
332
+ return this.bag.get(RoomProperties.key(code))?.integer() ?? null
333
+ }
334
+
335
+ /**
336
+ * A yes or no property of the room, or null
337
+ * @param code which property
338
+ */
339
+ private flag(code: number): boolean | null {
340
+ return this.bag.get(RoomProperties.key(code))?.flag() ?? null
341
+ }
342
+ }