@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,282 @@
1
+ import { ErrorCode } from '../../balancing/code/error/index.ts'
2
+ import { JoinMode } from '../../balancing/code/join/index.ts'
3
+ import { LobbyType } from '../../balancing/code/lobby/index.ts'
4
+ import { ErrorMessage } from '../../balancing/code/message/index.ts'
5
+ import { OperationCode } from '../../balancing/code/operation/index.ts'
6
+ import { RoomOptionFlag } from '../../balancing/code/room/index.ts'
7
+ import type { Lobby } from '../../balancing/entity/lobby/index.ts'
8
+ import { LobbyFormat } from '../../balancing/format/shared/lobby/index.ts'
9
+ import type { RoomOptions } from '../../balancing/entity/options/index.ts'
10
+ import type { CreateGameRequest } from '../../balancing/packet/game/create/request/index.ts'
11
+ import { CreateGameResponse } from '../../balancing/packet/game/create/response/index.ts'
12
+ import type { JoinGameRequest } from '../../balancing/packet/game/join/request/index.ts'
13
+ import { JoinGameResponse } from '../../balancing/packet/game/join/response/index.ts'
14
+ import type { JoinRandomGameRequest } from '../../balancing/packet/game/random/request/index.ts'
15
+ import { JoinRandomGameResponse } from '../../balancing/packet/game/random/response/index.ts'
16
+ import type { ReplyAdapter } from '../../balancing/packet/reply/index.ts'
17
+ import { UnknownResponse } from '../../balancing/packet/unknown/index.ts'
18
+ import type { PhotonHashtable } from '../../binary/hashtable/index.ts'
19
+ import type { MasterApplication } from '../application/index.ts'
20
+ import { MasterFault } from '../fault/index.ts'
21
+ import type { AppLobby, Placement, Seat } from '../lobby/index.ts'
22
+ import type { MasterPeer } from '../peer/index.ts'
23
+ import type { QueryScreen } from '../query/index.ts'
24
+ import { WellKnownProperties } from '../wellknown/index.ts'
25
+
26
+ /**
27
+ * Creates games and finds clients a game to join
28
+ * @class
29
+ */
30
+ export class Matchmaker {
31
+ /**
32
+ * Lobbies, games and settings
33
+ */
34
+ private readonly application: MasterApplication
35
+
36
+ /**
37
+ * Turns away filters with banned words
38
+ */
39
+ private readonly screen: QueryScreen
40
+
41
+ /**
42
+ * @param application lobbies, games and settings
43
+ * @param screen turns away filters with banned words
44
+ */
45
+ public constructor(application: MasterApplication, screen: QueryScreen) {
46
+ this.application = application
47
+ this.screen = screen
48
+ }
49
+
50
+ /**
51
+ * Whether a create or join asks for its user id to be checked
52
+ * @param options the room options block, or null
53
+ */
54
+ private static checksUser(options: RoomOptions | null): boolean {
55
+ if (options === null) return false
56
+
57
+ return (
58
+ options.checkUserOnJoin === true ||
59
+ (options.roomFlags & RoomOptionFlag.CHECK_USER_ON_JOIN) !== 0
60
+ )
61
+ }
62
+
63
+ /**
64
+ * Creates a game and sends the creator to its Game Server
65
+ * @param peer who's asking
66
+ * @param packet name, lobby, properties and reserved users
67
+ */
68
+ public create(
69
+ peer: MasterPeer,
70
+ packet: CreateGameRequest,
71
+ ): ReplyAdapter | null {
72
+ const placement = this.placement(
73
+ peer,
74
+ packet.roomName,
75
+ peer.properties(packet.options?.gameProperties ?? null),
76
+ packet.expectedUsers,
77
+ )
78
+ const refusal = LobbyFormat.refusal(packet.lobby)
79
+ if (refusal !== null) throw MasterFault.invalid(refusal)
80
+
81
+ const lobby = this.lobby(peer, packet.lobby)
82
+ return this.queued(peer, OperationCode.CREATE_GAME, (): ReplyAdapter => {
83
+ const seat = lobby.create(peer, placement)
84
+
85
+ return CreateGameResponse.master(seat.address, seat.game)
86
+ })
87
+ }
88
+
89
+ /**
90
+ * Sends a client to the Game Server of a game it names
91
+ * @param peer who's asking
92
+ * @param packet name, join mode, lobby and reserved users
93
+ */
94
+ public join(peer: MasterPeer, packet: JoinGameRequest): ReplyAdapter | null {
95
+ const placement = this.placement(
96
+ peer,
97
+ packet.roomName,
98
+ peer.properties(packet.options?.gameProperties ?? null),
99
+ packet.expectedUsers,
100
+ )
101
+
102
+ const application = this.application
103
+ const known = application.find(packet.roomName)
104
+ const plain =
105
+ packet.joinMode === JoinMode.DEFAULT &&
106
+ !application.settings.allowAsyncJoin
107
+ if (known === null && plain) {
108
+ throw MasterFault.of(
109
+ ErrorCode.GAME_DOES_NOT_EXIST,
110
+ ErrorMessage.GAME_ID_DOES_NOT_EXIST,
111
+ )
112
+ }
113
+
114
+ const lobby = known?.lobby ?? this.lobby(peer, packet.lobby)
115
+ return this.queued(
116
+ peer,
117
+ OperationCode.JOIN_GAME,
118
+ (): ReplyAdapter | null => {
119
+ const seat = lobby.enter(peer, packet, {
120
+ ...placement,
121
+ /**
122
+ * Decides between joining, creating and rejoining
123
+ */
124
+ mode: packet.joinMode,
125
+ /**
126
+ * Asked for by flag or by the old parameter
127
+ */
128
+ checkUser: Matchmaker.checksUser(packet.options),
129
+ })
130
+
131
+ return seat === null
132
+ ? null
133
+ : JoinGameResponse.master(seat.address, null, null, 0)
134
+ },
135
+ )
136
+ }
137
+
138
+ /**
139
+ * Sends a client to a game that fits, or creates one if asked to
140
+ * @param peer who's asking
141
+ * @param packet filters, mode, lobby and reserved users
142
+ */
143
+ public random(
144
+ peer: MasterPeer,
145
+ packet: JoinRandomGameRequest,
146
+ ): ReplyAdapter | null {
147
+ const word = this.screen.refusal(packet.sqlFilter, false)
148
+ if (word !== null) throw word
149
+
150
+ const lobby = this.lobby(peer, packet.lobby)
151
+ return this.queued(
152
+ peer,
153
+ OperationCode.JOIN_RANDOM_GAME,
154
+ (): ReplyAdapter => {
155
+ const seat =
156
+ lobby.random(peer, {
157
+ /**
158
+ * Properties a game must have
159
+ */
160
+ filter: peer.filter(packet.gameProperties),
161
+ /**
162
+ * Where the walk through the games starts
163
+ */
164
+ mode: packet.matchmakingMode,
165
+ /**
166
+ * Filters of a SQL lobby
167
+ */
168
+ sql: packet.sqlFilter,
169
+ /**
170
+ * Checked by games that check user ids
171
+ */
172
+ users: packet.expectedUsers,
173
+ }) ?? this.fallback(peer, packet)
174
+
175
+ return JoinRandomGameResponse.success(seat.address, seat.game, 0)
176
+ },
177
+ )
178
+ }
179
+
180
+ /**
181
+ * Runs the lobby part of a create or join and keeps the flood counters
182
+ * @param peer who's asking
183
+ * @param code operation a failure is answered under
184
+ * @param work what the lobby does
185
+ */
186
+ private queued(
187
+ peer: MasterPeer,
188
+ code: number,
189
+ work: () => ReplyAdapter | null,
190
+ ): ReplyAdapter | null {
191
+ peer.concurrentJoins += 1
192
+
193
+ let reply: ReplyAdapter | null
194
+ try {
195
+ reply = work()
196
+ } catch (cause) {
197
+ const fault = MasterFault.from(cause)
198
+
199
+ reply = UnknownResponse.failure(code, fault.code, fault.message)
200
+ }
201
+
202
+ if (reply === null) return null
203
+
204
+ peer.concurrentJoins -= 1
205
+ if (reply.succeeded) peer.successfulJoins += 1
206
+
207
+ return reply
208
+ }
209
+
210
+ /**
211
+ * The lobby a create, join or random join runs in
212
+ * @param peer who's asking
213
+ * @param lobby what the request names, or null
214
+ */
215
+ private lobby(peer: MasterPeer, lobby: Lobby | null): AppLobby {
216
+ return this.application.lobby(
217
+ peer,
218
+ lobby?.name ?? null,
219
+ lobby?.type ?? LobbyType.DEFAULT,
220
+ )
221
+ }
222
+
223
+ /**
224
+ * Checks the properties and reserved users of a create or join
225
+ * @param peer who's asking
226
+ * @param name name of the game, or null
227
+ * @param properties properties the client sent, or null
228
+ * @param users user ids to keep seats for, or null
229
+ */
230
+ private placement(
231
+ peer: MasterPeer,
232
+ name: string | null,
233
+ properties: PhotonHashtable | null,
234
+ users: readonly string[] | null,
235
+ ): Placement {
236
+ const known =
237
+ properties === null || properties.size === 0
238
+ ? null
239
+ : WellKnownProperties.request(properties)
240
+ const wanted = users ?? known?.expectedUsers ?? null
241
+ const unique = wanted === null ? null : [...new Set<string>(wanted)]
242
+
243
+ if (unique !== null) {
244
+ const needed =
245
+ unique.length + (unique.includes(peer.userId ?? '') ? 0 : 1)
246
+ const most = known?.maxPlayers ?? 0
247
+ if (most !== 0 && needed > most) {
248
+ throw MasterFault.invalid(
249
+ 'Reserved slots count is bigger then max player value',
250
+ )
251
+ }
252
+
253
+ if (unique.includes('')) {
254
+ throw MasterFault.invalid(ErrorMessage.SLOT_CAN_NOT_HAVE_EMPTY_NAME)
255
+ }
256
+ }
257
+
258
+ return { name, properties: known?.table ?? properties, users: unique }
259
+ }
260
+
261
+ /**
262
+ * Creates the game a random join falls back to
263
+ * @param peer who's asking
264
+ * @param packet what they asked for
265
+ */
266
+ private fallback(peer: MasterPeer, packet: JoinRandomGameRequest): Seat {
267
+ if (packet.joinMode !== JoinMode.CREATE_IF_NOT_EXISTS) {
268
+ throw MasterFault.of(ErrorCode.NO_RANDOM_MATCH_FOUND, 'No match found')
269
+ }
270
+
271
+ const lobby = this.lobby(peer, packet.lobby)
272
+ return lobby.create(
273
+ peer,
274
+ this.placement(
275
+ peer,
276
+ packet.roomName,
277
+ peer.properties(packet.properties ?? packet.gameProperties),
278
+ packet.expectedUsers,
279
+ ),
280
+ )
281
+ }
282
+ }
@@ -0,0 +1,45 @@
1
+ import { ErrorMessage } from '../../balancing/code/message/index.ts'
2
+ import { MasterFault } from '../fault/index.ts'
3
+ import type { MasterSettings } from '../settings/index.ts'
4
+
5
+ /**
6
+ * Turns away SQL filters that hold words the Master bans
7
+ * @class
8
+ */
9
+ export class QueryScreen {
10
+ /**
11
+ * Where the banned words come from
12
+ */
13
+ private readonly settings: MasterSettings
14
+
15
+ /**
16
+ * @param settings where the banned words come from
17
+ */
18
+ public constructor(settings: MasterSettings) {
19
+ this.settings = settings
20
+ }
21
+
22
+ /**
23
+ * Why a filter is refused for what it holds, or null
24
+ * @param query the filter, or null
25
+ * @param single whether a semicolon counts too
26
+ */
27
+ public refusal(query: string | null, single: boolean): MasterFault | null {
28
+ const settings = this.settings
29
+ if (query === null || query === '' || settings.onlyLogQueryDataErrors) {
30
+ return null
31
+ }
32
+
33
+ if (single && query.includes(';')) {
34
+ return MasterFault.invalid(ErrorMessage.SEMICOLON_IN_QUERY_DATA)
35
+ }
36
+
37
+ const word = settings.wrongWordsForQueryData.find(
38
+ (wrong: string): boolean => query.includes(wrong),
39
+ )
40
+
41
+ return word === undefined
42
+ ? null
43
+ : MasterFault.invalid(ErrorMessage.WORD_IN_QUERY_DATA, word)
44
+ }
45
+ }
@@ -37,16 +37,17 @@ export class RedirectHandler extends InboundHandlerAdapter {
37
37
  * @param context the connection
38
38
  * @param message an envelope from the message layer
39
39
  */
40
- public override channelRead(
41
- context: HandlerContext,
42
- message: unknown,
43
- ): void | Promise<void> {
44
- if (!(message instanceof Envelope)) return context.fireChannelRead(message)
40
+ public override channelRead(context: HandlerContext, message: unknown): void {
41
+ if (!(message instanceof Envelope)) {
42
+ context.fireChannelRead(message)
43
+ return
44
+ }
45
45
 
46
46
  const envelope = message as Envelope
47
47
  const request = envelope.message
48
48
  if (!(request instanceof OperationRequest)) {
49
- return context.fireChannelRead(message)
49
+ context.fireChannelRead(message)
50
+ return
50
51
  }
51
52
 
52
53
  const transport = PhotonPeer.of(context.channel)?.transport ?? null
@@ -59,7 +60,7 @@ export class RedirectHandler extends InboundHandlerAdapter {
59
60
  )
60
61
  .set(ParameterCode.NODE_ID, PhotonValue.byte(0))
61
62
 
62
- context.writeAndFlushSync(
63
+ context.writeAndFlush(
63
64
  Travel.from(envelope)
64
65
  .reply()
65
66
  .wrap<OperationResponse>(
@@ -0,0 +1,35 @@
1
+ import type { Applications } from '../../application/index.ts'
2
+ import type { CustomAuthenticator } from '../../authentication/authenticator/index.ts'
3
+ import type { TokenGate } from '../../authentication/gate/index.ts'
4
+ import type { TokenAuthority } from '../../crypto/token/authority/index.ts'
5
+ import type { MasterApplication } from '../application/index.ts'
6
+
7
+ /**
8
+ * What the operations of a Master work with
9
+ */
10
+ export type MasterServices = {
11
+ /**
12
+ * Lobbies, games, statistics and settings
13
+ */
14
+ readonly application: MasterApplication
15
+
16
+ /**
17
+ * Checks the tokens clients bring
18
+ */
19
+ readonly gate: TokenGate
20
+
21
+ /**
22
+ * Issues tokens for logins without one, or null
23
+ */
24
+ readonly authority: TokenAuthority | null
25
+
26
+ /**
27
+ * Runs custom authentication
28
+ */
29
+ readonly authenticator: CustomAuthenticator
30
+
31
+ /**
32
+ * Checks app ids and versions of logins without a token
33
+ */
34
+ readonly applications: Applications
35
+ }
@@ -123,6 +123,21 @@ export type MasterServerConfig = {
123
123
  */
124
124
  readonly limitSqlFilterTime?: number
125
125
 
126
+ /**
127
+ * Longest SQL filter in characters, 1024 by default
128
+ */
129
+ readonly limitSqlFilterLength?: number
130
+
131
+ /**
132
+ * Deepest bracket nesting in a SQL filter, 8 by default
133
+ */
134
+ readonly limitSqlFilterDepth?: number
135
+
136
+ /**
137
+ * Most game rows the filters of one request may visit without a time limit, a million by default
138
+ */
139
+ readonly limitSqlFilterScan?: number
140
+
126
141
  /**
127
142
  * Lists without limits and SQL lobbies that send lists, false by default
128
143
  */
@@ -143,6 +158,11 @@ export type MasterServerConfig = {
143
158
  */
144
159
  readonly lobbiesCountLimit?: number
145
160
 
161
+ /**
162
+ * Most games one application keeps, 100000 by default
163
+ */
164
+ readonly gamesCountLimit?: number
165
+
146
166
  /**
147
167
  * Most create and join requests one client has open, 3 by default
148
168
  */
@@ -345,6 +365,21 @@ export class MasterSettings {
345
365
  */
346
366
  public readonly limitSqlFilterTime: number
347
367
 
368
+ /**
369
+ * Longest SQL filter in characters
370
+ */
371
+ public readonly limitSqlFilterLength: number
372
+
373
+ /**
374
+ * Deepest bracket nesting in a SQL filter
375
+ */
376
+ public readonly limitSqlFilterDepth: number
377
+
378
+ /**
379
+ * Most game rows the filters of one request may visit without a time limit
380
+ */
381
+ public readonly limitSqlFilterScan: number
382
+
348
383
  /**
349
384
  * Whether lists have no limits and SQL lobbies send lists
350
385
  */
@@ -365,6 +400,11 @@ export class MasterSettings {
365
400
  */
366
401
  public readonly lobbiesCountLimit: number
367
402
 
403
+ /**
404
+ * Most games one application keeps
405
+ */
406
+ public readonly gamesCountLimit: number
407
+
368
408
  /**
369
409
  * Most create and join requests one client has open
370
410
  */
@@ -484,11 +524,15 @@ export class MasterSettings {
484
524
  this.limitGameListUpdate = config.limitGameListUpdate ?? 500
485
525
  this.limitSqlFilterResults = config.limitSqlFilterResults ?? 100
486
526
  this.limitSqlFilterTime = config.limitSqlFilterTime ?? 0
527
+ this.limitSqlFilterLength = config.limitSqlFilterLength ?? 1024
528
+ this.limitSqlFilterDepth = config.limitSqlFilterDepth ?? 8
529
+ this.limitSqlFilterScan = config.limitSqlFilterScan ?? 1_000_000
487
530
  this.useLegacyLobbies = config.useLegacyLobbies ?? false
488
531
  this.lobbyStatsPublishInterval =
489
532
  (config.lobbyStatsPublishInterval ?? 120) * 1000
490
533
  this.lobbyStatsLimit = config.lobbyStatsLimit ?? 0
491
534
  this.lobbiesCountLimit = config.lobbiesCountLimit ?? 10_000
535
+ this.gamesCountLimit = config.gamesCountLimit ?? 100_000
492
536
  this.maxConcurrentJoinRequests = config.maxConcurrentJoinRequests ?? 3
493
537
  this.maxTotalJoinRequests = config.maxTotalJoinRequests ?? 4
494
538
  this.disconnectIfNoAuthInterval =