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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/package.json +2 -2
  2. package/src/codec/index.ts +51 -221
  3. package/src/dispatch/dispatcher/index.ts +89 -47
  4. package/src/dispatch/session/index.ts +6 -24
  5. package/src/index.ts +2 -4
  6. package/src/photon/balancing/codec/index.ts +27 -53
  7. package/src/photon/balancing/format/authenticate/request/index.ts +52 -6
  8. package/src/photon/balancing/format/friends/request/index.ts +21 -5
  9. package/src/photon/balancing/format/game/create/request/index.ts +45 -8
  10. package/src/photon/balancing/format/game/debug/request/index.ts +19 -4
  11. package/src/photon/balancing/format/game/join/request/index.ts +65 -13
  12. package/src/photon/balancing/format/game/list/request/index.ts +29 -3
  13. package/src/photon/balancing/format/game/random/request/index.ts +58 -10
  14. package/src/photon/balancing/format/groups/request/index.ts +19 -3
  15. package/src/photon/balancing/format/index.ts +7 -0
  16. package/src/photon/balancing/format/leave/request/index.ts +19 -3
  17. package/src/photon/balancing/format/lobby/join/request/index.ts +23 -3
  18. package/src/photon/balancing/format/lobby/stats/request/index.ts +19 -3
  19. package/src/photon/balancing/format/once/request/index.ts +31 -8
  20. package/src/photon/balancing/format/properties/get/request/index.ts +31 -4
  21. package/src/photon/balancing/format/properties/set/request/index.ts +36 -7
  22. package/src/photon/balancing/format/raise/request/index.ts +76 -10
  23. package/src/photon/balancing/format/reader/index.ts +75 -6
  24. package/src/photon/balancing/format/regions/request/index.ts +16 -1
  25. package/src/photon/balancing/format/rpc/request/index.ts +26 -3
  26. package/src/photon/balancing/format/settings/request/index.ts +15 -2
  27. package/src/photon/balancing/format/shared/credentials/index.ts +77 -33
  28. package/src/photon/balancing/format/shared/lobby/index.ts +41 -5
  29. package/src/photon/balancing/format/shared/options/index.ts +56 -24
  30. package/src/photon/balancing/format/table/index.ts +399 -0
  31. package/src/photon/balancing/index.ts +11 -1
  32. package/src/photon/balancing/travel/index.ts +15 -12
  33. package/src/photon/client/connection/index.ts +6 -6
  34. package/src/photon/cluster/back/index.ts +32 -45
  35. package/src/photon/cluster/dresser/index.ts +7 -8
  36. package/src/photon/cluster/front/index.ts +25 -49
  37. package/src/photon/cluster/grid/index.ts +1 -1
  38. package/src/photon/cluster/mover/index.ts +12 -12
  39. package/src/photon/cluster/press/index.ts +2 -18
  40. package/src/photon/cluster/route/game/index.ts +9 -11
  41. package/src/photon/cluster/route/master/index.ts +15 -34
  42. package/src/photon/cluster/route/name/index.ts +4 -21
  43. package/src/photon/cluster/seat/game/index.ts +6 -26
  44. package/src/photon/cluster/seat/master/index.ts +1 -1
  45. package/src/photon/cluster/sessions/index.ts +5 -6
  46. package/src/photon/cluster/spread/index.ts +8 -147
  47. package/src/photon/enet/client/index.ts +1 -8
  48. package/src/photon/enet/gateway/index.ts +5 -15
  49. package/src/photon/enet/index.ts +1 -1
  50. package/src/photon/enet/link/index.ts +34 -15
  51. package/src/photon/enet/outbound/index.ts +279 -0
  52. package/src/photon/enet/peer/index.ts +59 -0
  53. package/src/photon/enet/transport/index.ts +8 -24
  54. package/src/photon/game/admission/index.ts +353 -0
  55. package/src/photon/game/bag/index.ts +13 -0
  56. package/src/photon/game/broadcast/index.ts +79 -0
  57. package/src/photon/game/editor/index.ts +446 -0
  58. package/src/photon/game/gate/index.ts +9 -8
  59. package/src/photon/game/handler/index.ts +30 -3
  60. package/src/photon/game/history/index.ts +234 -0
  61. package/src/photon/game/hooked/index.ts +16 -15
  62. package/src/photon/game/index.ts +12 -1
  63. package/src/photon/game/lifecycle/index.ts +193 -0
  64. package/src/photon/game/peer/index.ts +1 -10
  65. package/src/photon/game/properties/index.ts +342 -0
  66. package/src/photon/game/room/index.ts +435 -1793
  67. package/src/photon/game/rooms/index.ts +2 -1
  68. package/src/photon/game/seats/index.ts +237 -0
  69. package/src/photon/game/server/index.ts +12 -2
  70. package/src/photon/game/services/index.ts +41 -0
  71. package/src/photon/game/settings/index.ts +22 -0
  72. package/src/photon/game/snapshot/index.ts +133 -0
  73. package/src/photon/game/throttle/index.ts +60 -0
  74. package/src/photon/game/touch/index.ts +2 -5
  75. package/src/photon/game/venue/index.ts +31 -0
  76. package/src/photon/master/application/index.ts +7 -0
  77. package/src/photon/master/gate/index.ts +12 -8
  78. package/src/photon/master/handler/index.ts +36 -748
  79. package/src/photon/master/index.ts +5 -0
  80. package/src/photon/master/list/sql/index.ts +37 -3
  81. package/src/photon/master/listing/index.ts +133 -0
  82. package/src/photon/master/lobby/index.ts +9 -0
  83. package/src/photon/master/login/index.ts +424 -0
  84. package/src/photon/master/matchmaking/index.ts +282 -0
  85. package/src/photon/master/query/index.ts +45 -0
  86. package/src/photon/master/redirect/index.ts +8 -7
  87. package/src/photon/master/services/index.ts +35 -0
  88. package/src/photon/master/settings/index.ts +44 -0
  89. package/src/photon/master/sql/cost/index.ts +263 -0
  90. package/src/photon/master/sql/index.ts +1 -0
  91. package/src/photon/message/client/index.ts +14 -11
  92. package/src/photon/message/handler/index.ts +22 -64
  93. package/src/photon/message/pipeline/index.ts +12 -12
  94. package/src/photon/message/server/index.ts +87 -43
  95. package/src/photon/message/watch/index.ts +14 -37
  96. package/src/photon/server/deferral/index.ts +57 -0
  97. package/src/photon/server/host/index.ts +32 -10
  98. package/src/photon/server/index.ts +1 -0
  99. package/src/photon/tcp/client/index.ts +1 -1
  100. package/src/photon/tcp/codec/index.ts +13 -42
  101. package/src/photon/tcp/server/index.ts +4 -4
  102. package/src/photon/websocket/bridge/index.ts +16 -20
  103. package/src/photon/websocket/message/index.ts +27 -39
  104. package/src/photon/websocket/path/index.ts +2 -5
  105. package/src/scale/fanout/index.ts +6 -6
  106. package/src/scale/index.ts +2 -4
  107. package/src/scale/outbound/index.ts +192 -0
  108. package/src/scale/relay/index.ts +20 -31
  109. package/src/scale/sink/index.ts +6 -11
  110. package/src/scale/transport/index.ts +27 -44
  111. package/src/scale/tunnel/index.ts +37 -91
  112. package/src/smartfox/common/bluebox/gateway/index.ts +401 -0
  113. package/src/smartfox/common/bluebox/index.ts +4 -0
  114. package/src/smartfox/{x2 → common}/bluebox/transport/index.ts +36 -23
  115. package/src/smartfox/common/index.ts +5 -0
  116. package/src/smartfox/common/strikes/index.ts +74 -0
  117. package/src/smartfox/pro/bluebox/index.ts +176 -4
  118. package/src/smartfox/pro/codec/index.ts +8 -7
  119. package/src/smartfox/pro/escalation/index.ts +28 -20
  120. package/src/smartfox/pro/flood/index.ts +2 -2
  121. package/src/smartfox/pro/format/extension/raw/index.ts +12 -2
  122. package/src/smartfox/pro/handler/chat/index.ts +11 -8
  123. package/src/smartfox/pro/handler/login/index.ts +2 -25
  124. package/src/smartfox/pro/handler/shared/index.ts +4 -3
  125. package/src/smartfox/pro/index.ts +11 -5
  126. package/src/smartfox/pro/login/gate/index.ts +166 -0
  127. package/src/smartfox/pro/login/index.ts +1 -0
  128. package/src/smartfox/pro/moderation/index.ts +220 -0
  129. package/src/smartfox/pro/options/index.ts +5 -5
  130. package/src/smartfox/pro/protocol/index.ts +62 -8
  131. package/src/smartfox/pro/web/index.ts +33 -26
  132. package/src/smartfox/pro/zone/index.ts +59 -282
  133. package/src/smartfox/pro/zones/index.ts +3 -3
  134. package/src/smartfox/x2/bluebox/index.ts +149 -4
  135. package/src/smartfox/x2/chat/index.ts +9 -19
  136. package/src/smartfox/x2/codec/index.ts +31 -39
  137. package/src/smartfox/x2/config/index.ts +6 -1
  138. package/src/smartfox/x2/data/array/index.ts +96 -60
  139. package/src/smartfox/x2/data/object/index.ts +144 -82
  140. package/src/smartfox/x2/data/serializer/index.ts +41 -23
  141. package/src/smartfox/x2/flood/gate/index.ts +19 -13
  142. package/src/smartfox/x2/format/buddy/init/response/index.ts +4 -3
  143. package/src/smartfox/x2/format/find/rooms/response/index.ts +4 -3
  144. package/src/smartfox/x2/format/find/users/response/index.ts +4 -3
  145. package/src/smartfox/x2/format/group/subscribe/response/index.ts +4 -3
  146. package/src/smartfox/x2/format/login/response/index.ts +4 -3
  147. package/src/smartfox/x2/format/mmo/position/response/index.ts +8 -6
  148. package/src/smartfox/x2/format/room/join/response/index.ts +4 -3
  149. package/src/smartfox/x2/games/index.ts +35 -8
  150. package/src/smartfox/x2/hall/index.ts +0 -6
  151. package/src/smartfox/x2/handler/session/index.ts +1 -1
  152. package/src/smartfox/x2/index.ts +8 -3
  153. package/src/smartfox/x2/member/index.ts +10 -3
  154. package/src/smartfox/x2/packet/login/response/index.ts +12 -0
  155. package/src/smartfox/x2/protocol/index.ts +11 -1
  156. package/src/smartfox/x2/rooms/index.ts +1 -2
  157. package/src/smartfox/x2/sessions/index.ts +6 -0
  158. package/src/smartfox/x2/udp/index.ts +61 -24
  159. package/src/smartfox/x2/web/index.ts +35 -17
  160. package/src/smartfox/x2/websocket/index.ts +18 -36
  161. package/src/smartfox/x2/zone/index.ts +77 -28
  162. package/src/smartfox/x2/zones/index.ts +17 -5
  163. package/src/photon/enet/handler/index.ts +0 -65
  164. package/src/scale/hosted/index.ts +0 -68
  165. package/src/scale/outlet/index.ts +0 -121
  166. package/src/smartfox/pro/bluebox/gateway/index.ts +0 -310
  167. package/src/smartfox/pro/bluebox/session/index.ts +0 -63
  168. package/src/smartfox/pro/bluebox/transport/index.ts +0 -104
  169. package/src/smartfox/x2/bluebox/gateway/index.ts +0 -315
  170. /package/src/smartfox/{x2 → common}/bluebox/session/index.ts +0 -0
  171. /package/src/smartfox/{pro → common}/counters/index.ts +0 -0
  172. /package/src/smartfox/{pro → common}/counters/memory/index.ts +0 -0
  173. /package/src/smartfox/{pro → common}/counters/offender/index.ts +0 -0
  174. /package/src/smartfox/{pro → common}/counters/store/index.ts +0 -0
  175. /package/src/smartfox/{pro → common}/sequence/index.ts +0 -0
@@ -8,6 +8,7 @@ import {
8
8
  type MessageKindId,
9
9
  } from '../../contract/index.ts'
10
10
  import type { ParameterReader } from '../../reader/index.ts'
11
+ import { OperationTable, Parameter } from '../../table/index.ts'
11
12
  import type { ParameterWriter } from '../../writer/index.ts'
12
13
 
13
14
  /**
@@ -15,6 +16,24 @@ import type { ParameterWriter } from '../../writer/index.ts'
15
16
  * @class
16
17
  */
17
18
  export class WebRpcRequestFormat implements BalancingFormat<WebRpcRequest> {
19
+ /**
20
+ * Every parameter the request reads
21
+ */
22
+ private static readonly table = OperationTable.of({
23
+ /**
24
+ * Path of the call
25
+ */
26
+ path: Parameter.text(ParameterCode.URI_PATH).required(),
27
+ /**
28
+ * Parameters of the call
29
+ */
30
+ parameters: Parameter.value(ParameterCode.WEB_RPC_PARAMETERS),
31
+ /**
32
+ * Web flags for forwarding to a web service
33
+ */
34
+ webFlags: Parameter.convertible(ParameterCode.EVENT_FORWARD),
35
+ })
36
+
18
37
  /**
19
38
  * Always a request
20
39
  */
@@ -35,10 +54,14 @@ export class WebRpcRequestFormat implements BalancingFormat<WebRpcRequest> {
35
54
  * @param reader the request's parameters
36
55
  */
37
56
  public read(reader: ParameterReader): WebRpcRequest {
57
+ const values = reader.read<typeof WebRpcRequestFormat.table>(
58
+ WebRpcRequestFormat.table,
59
+ )
60
+
38
61
  return WebRpcRequest.of(
39
- reader.require(ParameterCode.URI_PATH).text(ParameterCode.URI_PATH) ?? '',
40
- reader.value(ParameterCode.WEB_RPC_PARAMETERS),
41
- reader.convertible(ParameterCode.EVENT_FORWARD),
62
+ values.path ?? '',
63
+ values.parameters,
64
+ values.webFlags,
42
65
  )
43
66
  }
44
67
 
@@ -8,6 +8,7 @@ import {
8
8
  type MessageKindId,
9
9
  } from '../../contract/index.ts'
10
10
  import type { ParameterReader } from '../../reader/index.ts'
11
+ import { OperationTable, Parameter } from '../../table/index.ts'
11
12
  import type { ParameterWriter } from '../../writer/index.ts'
12
13
 
13
14
  /**
@@ -15,6 +16,16 @@ import type { ParameterWriter } from '../../writer/index.ts'
15
16
  * @class
16
17
  */
17
18
  export class ServerSettingsRequestFormat implements BalancingFormat<ServerSettingsRequest> {
19
+ /**
20
+ * Every parameter the request reads
21
+ */
22
+ private static readonly table = OperationTable.of({
23
+ /**
24
+ * Whether the client wants lobby statistics
25
+ */
26
+ lobbyStats: Parameter.flag(ParameterCode.SERVER_SETTINGS_LOBBY_STATS),
27
+ })
28
+
18
29
  /**
19
30
  * Always a request
20
31
  */
@@ -36,9 +47,11 @@ export class ServerSettingsRequestFormat implements BalancingFormat<ServerSettin
36
47
  * @param reader the request's parameters
37
48
  */
38
49
  public read(reader: ParameterReader): ServerSettingsRequest {
39
- return ServerSettingsRequest.of(
40
- reader.flag(ParameterCode.SERVER_SETTINGS_LOBBY_STATS),
50
+ const values = reader.read<typeof ServerSettingsRequestFormat.table>(
51
+ ServerSettingsRequestFormat.table,
41
52
  )
53
+
54
+ return ServerSettingsRequest.of(values.lobbyStats)
42
55
  }
43
56
 
44
57
  /**
@@ -1,7 +1,10 @@
1
+ import { Kind } from '../../../../binary/kind/index.ts'
2
+ import { ErrorMessage } from '../../../code/message/index.ts'
1
3
  import { ParameterCode } from '../../../code/parameter/index.ts'
2
4
  import { CustomAuthentication } from '../../../entity/authentication/index.ts'
3
5
  import { Credentials } from '../../../entity/credentials/index.ts'
4
6
  import type { ParameterReader } from '../../reader/index.ts'
7
+ import { type OperationValues, Parameter } from '../../table/index.ts'
5
8
  import type { ParameterWriter } from '../../writer/index.ts'
6
9
 
7
10
  /**
@@ -10,37 +13,93 @@ import type { ParameterWriter } from '../../writer/index.ts'
10
13
  */
11
14
  export class CredentialsFormat {
12
15
  /**
13
- * Parameter codes that make an authenticate a full one
16
+ * The parameters that say who's logging in
14
17
  */
15
- private static readonly codes: readonly number[] = [
16
- ParameterCode.APPLICATION_ID,
17
- ParameterCode.APP_VERSION,
18
- ParameterCode.REGION,
19
- ParameterCode.USER_ID,
20
- ParameterCode.CLIENT_AUTHENTICATION_TYPE,
21
- ParameterCode.CLIENT_AUTHENTICATION_PARAMS,
22
- ParameterCode.CLIENT_AUTHENTICATION_DATA,
23
- ]
18
+ public static readonly table = {
19
+ /**
20
+ * Application id
21
+ */
22
+ applicationId: Parameter.text(ParameterCode.APPLICATION_ID),
23
+ /**
24
+ * Application version
25
+ */
26
+ appVersion: Parameter.text(ParameterCode.APP_VERSION),
27
+ /**
28
+ * Region the client wants
29
+ */
30
+ region: Parameter.text(ParameterCode.REGION),
31
+ /**
32
+ * User id the client asks for
33
+ */
34
+ userId: Parameter.text(ParameterCode.USER_ID),
35
+ /**
36
+ * Which authentication provider
37
+ */
38
+ authenticationType: Parameter.byte(
39
+ ParameterCode.CLIENT_AUTHENTICATION_TYPE,
40
+ ),
41
+ /**
42
+ * Query string for the provider
43
+ */
44
+ authenticationParameters: Parameter.text(
45
+ ParameterCode.CLIENT_AUTHENTICATION_PARAMS,
46
+ ).given('authenticationType'),
47
+ /**
48
+ * Body for the provider
49
+ */
50
+ authenticationData: Parameter.value(
51
+ ParameterCode.CLIENT_AUTHENTICATION_DATA,
52
+ ).given('authenticationType'),
53
+ }
24
54
 
25
55
  /**
26
56
  * The credentials a message carries, or null
27
57
  * @param reader the message's parameters
58
+ * @param values what the table read
28
59
  */
29
- public read(reader: ParameterReader): Credentials | null {
30
- const present = CredentialsFormat.codes.some((code: number): boolean =>
31
- reader.has(code),
60
+ public static from(
61
+ reader: ParameterReader,
62
+ values: OperationValues<typeof CredentialsFormat.table>,
63
+ ): Credentials | null {
64
+ const present = Object.values<Parameter>(CredentialsFormat.table).some(
65
+ (parameter: Parameter): boolean => reader.has(parameter.code),
32
66
  )
33
67
  if (!present) return null
34
68
 
69
+ const type = values.authenticationType
70
+
35
71
  return Credentials.of(
36
- reader.text(ParameterCode.APPLICATION_ID),
37
- reader.text(ParameterCode.APP_VERSION),
38
- reader.text(ParameterCode.REGION),
39
- reader.text(ParameterCode.USER_ID),
40
- this.authentication(reader),
72
+ values.applicationId,
73
+ values.appVersion,
74
+ values.region,
75
+ values.userId,
76
+ type === null
77
+ ? null
78
+ : CustomAuthentication.of(
79
+ type,
80
+ values.authenticationParameters,
81
+ values.authenticationData,
82
+ ),
41
83
  )
42
84
  }
43
85
 
86
+ /**
87
+ * Why the body for the provider can't be used, or null
88
+ * @param credentials what the client sent, or null
89
+ */
90
+ public static refusal(credentials: Credentials | null): string | null {
91
+ const data = credentials?.authentication?.data ?? null
92
+ if (
93
+ data === null ||
94
+ data.kind === Kind.STRING ||
95
+ data.kind === Kind.BYTES
96
+ ) {
97
+ return null
98
+ }
99
+
100
+ return ErrorMessage.INVALID_TYPE_FOR_AUTH_DATA
101
+ }
102
+
44
103
  /**
45
104
  * Writes whatever the credentials hold
46
105
  * @param credentials what to write, or null
@@ -66,19 +125,4 @@ export class CredentialsFormat {
66
125
  )
67
126
  .value(ParameterCode.CLIENT_AUTHENTICATION_DATA, authentication.data)
68
127
  }
69
-
70
- /**
71
- * The values for an authentication provider, or null
72
- * @param reader the message's parameters
73
- */
74
- private authentication(reader: ParameterReader): CustomAuthentication | null {
75
- const type = reader.byte(ParameterCode.CLIENT_AUTHENTICATION_TYPE)
76
- if (type === null) return null
77
-
78
- return CustomAuthentication.of(
79
- type,
80
- reader.text(ParameterCode.CLIENT_AUTHENTICATION_PARAMS),
81
- reader.value(ParameterCode.CLIENT_AUTHENTICATION_DATA),
82
- )
83
- }
84
128
  }
@@ -1,7 +1,8 @@
1
1
  import { LobbyType } from '../../../code/lobby/index.ts'
2
+ import { ErrorMessage } from '../../../code/message/index.ts'
2
3
  import { ParameterCode } from '../../../code/parameter/index.ts'
3
4
  import { Lobby } from '../../../entity/lobby/index.ts'
4
- import type { ParameterReader } from '../../reader/index.ts'
5
+ import { type OperationValues, Parameter } from '../../table/index.ts'
5
6
  import type { ParameterWriter } from '../../writer/index.ts'
6
7
 
7
8
  /**
@@ -9,18 +10,53 @@ import type { ParameterWriter } from '../../writer/index.ts'
9
10
  * @class
10
11
  */
11
12
  export class LobbyFormat {
13
+ /**
14
+ * The two lobby parameters
15
+ */
16
+ public static readonly table = {
17
+ /**
18
+ * Name of the lobby
19
+ */
20
+ lobbyName: Parameter.text(ParameterCode.LOBBY_NAME),
21
+ /**
22
+ * One of the lobby types
23
+ */
24
+ lobbyType: Parameter.byte(ParameterCode.LOBBY_TYPE),
25
+ }
26
+
12
27
  /**
13
28
  * The lobby a message names, or null
14
- * @param reader the message's parameters
29
+ * @param values what the table read
15
30
  */
16
- public read(reader: ParameterReader): Lobby | null {
17
- const name = reader.text(ParameterCode.LOBBY_NAME)
18
- const type = reader.byte(ParameterCode.LOBBY_TYPE)
31
+ public static from(
32
+ values: OperationValues<typeof LobbyFormat.table>,
33
+ ): Lobby | null {
34
+ const name = values.lobbyName
35
+ const type = values.lobbyType
19
36
  if (name === null && type === null) return null
20
37
 
21
38
  return Lobby.of(name ?? '', type ?? LobbyType.DEFAULT)
22
39
  }
23
40
 
41
+ /**
42
+ * Why a lobby can't hold games a client makes or joins, or null
43
+ * @param lobby what the request names, or null
44
+ */
45
+ public static refusal(lobby: Lobby | null): string | null {
46
+ const type = lobby?.type ?? LobbyType.DEFAULT
47
+ if (type <= LobbyType.ASYNC_RANDOM) return null
48
+
49
+ return LobbyFormat.unknown(type)
50
+ }
51
+
52
+ /**
53
+ * The refusal for a lobby type that doesn't fit
54
+ * @param type what the client sent
55
+ */
56
+ public static unknown(type: number): string {
57
+ return `${ErrorMessage.INVALID_LOBBY_TYPE} ${String(type)}`
58
+ }
59
+
24
60
  /**
25
61
  * Writes the name and kind of a lobby
26
62
  * @param lobby what to name, or null
@@ -1,6 +1,7 @@
1
1
  import { ParameterCode } from '../../../code/parameter/index.ts'
2
2
  import { RoomOptions } from '../../../entity/options/index.ts'
3
3
  import type { ParameterReader } from '../../reader/index.ts'
4
+ import { type OperationValues, Parameter } from '../../table/index.ts'
4
5
  import type { ParameterWriter } from '../../writer/index.ts'
5
6
 
6
7
  /**
@@ -9,40 +10,71 @@ import type { ParameterWriter } from '../../writer/index.ts'
9
10
  */
10
11
  export class RoomOptionsFormat {
11
12
  /**
12
- * Parameter codes of the block
13
+ * The parameters of the block
13
14
  */
14
- private static readonly codes: readonly number[] = [
15
- ParameterCode.GAME_PROPERTIES,
16
- ParameterCode.ROOM_OPTION_FLAGS,
17
- ParameterCode.PLAYER_TTL,
18
- ParameterCode.EMPTY_ROOM_TTL,
19
- ParameterCode.PLUGINS,
20
- ParameterCode.CLEANUP_CACHE_ON_LEAVE,
21
- ParameterCode.CHECK_USER_ON_JOIN,
22
- ParameterCode.SUPPRESS_ROOM_EVENTS,
23
- ParameterCode.PUBLISH_USER_ID,
24
- ]
15
+ public static readonly table = {
16
+ /**
17
+ * Properties of the room
18
+ */
19
+ gameProperties: Parameter.table(ParameterCode.GAME_PROPERTIES),
20
+ /**
21
+ * Room option bits
22
+ */
23
+ roomOptionFlags: Parameter.int(ParameterCode.ROOM_OPTION_FLAGS),
24
+ /**
25
+ * How long a player's seat is kept in ms
26
+ */
27
+ playerTtl: Parameter.int(ParameterCode.PLAYER_TTL),
28
+ /**
29
+ * How long the empty room stays in ms
30
+ */
31
+ emptyRoomTtl: Parameter.int(ParameterCode.EMPTY_ROOM_TTL),
32
+ /**
33
+ * Plugins the room asks for
34
+ */
35
+ plugins: Parameter.texts(ParameterCode.PLUGINS),
36
+ /**
37
+ * Old flag for dropping a leaver's cached events
38
+ */
39
+ cleanupCacheOnLeave: Parameter.flag(ParameterCode.CLEANUP_CACHE_ON_LEAVE),
40
+ /**
41
+ * Old flag for checking user ids
42
+ */
43
+ checkUserOnJoin: Parameter.flag(ParameterCode.CHECK_USER_ON_JOIN),
44
+ /**
45
+ * Old flag for hiding join and leave events
46
+ */
47
+ suppressRoomEvents: Parameter.flag(ParameterCode.SUPPRESS_ROOM_EVENTS),
48
+ /**
49
+ * Old flag for sharing user ids
50
+ */
51
+ publishUserId: Parameter.flag(ParameterCode.PUBLISH_USER_ID),
52
+ }
25
53
 
26
54
  /**
27
55
  * The options a request carries, or null
28
56
  * @param reader the request's parameters
57
+ * @param values what the table read
29
58
  */
30
- public read(reader: ParameterReader): RoomOptions | null {
31
- const present = RoomOptionsFormat.codes.some((code: number): boolean =>
32
- reader.has(code),
59
+ public static from(
60
+ reader: ParameterReader,
61
+ values: OperationValues<typeof RoomOptionsFormat.table>,
62
+ ): RoomOptions | null {
63
+ const present = Object.values<Parameter>(RoomOptionsFormat.table).some(
64
+ (parameter: Parameter): boolean => reader.has(parameter.code),
33
65
  )
34
66
  if (!present) return null
35
67
 
36
68
  return RoomOptions.of(
37
- reader.table(ParameterCode.GAME_PROPERTIES),
38
- reader.int(ParameterCode.ROOM_OPTION_FLAGS),
39
- reader.int(ParameterCode.PLAYER_TTL),
40
- reader.int(ParameterCode.EMPTY_ROOM_TTL),
41
- reader.texts(ParameterCode.PLUGINS),
42
- reader.flag(ParameterCode.CLEANUP_CACHE_ON_LEAVE),
43
- reader.flag(ParameterCode.CHECK_USER_ON_JOIN),
44
- reader.flag(ParameterCode.SUPPRESS_ROOM_EVENTS),
45
- reader.flag(ParameterCode.PUBLISH_USER_ID),
69
+ values.gameProperties,
70
+ values.roomOptionFlags,
71
+ values.playerTtl,
72
+ values.emptyRoomTtl,
73
+ values.plugins,
74
+ values.cleanupCacheOnLeave,
75
+ values.checkUserOnJoin,
76
+ values.suppressRoomEvents,
77
+ values.publishUserId,
46
78
  )
47
79
  }
48
80