@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
|
@@ -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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
40
|
-
|
|
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
|
-
*
|
|
16
|
+
* The parameters that say who's logging in
|
|
14
17
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
ParameterCode.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
|
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
|
|
29
|
+
* @param values what the table read
|
|
15
30
|
*/
|
|
16
|
-
public
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
*
|
|
13
|
+
* The parameters of the block
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
ParameterCode.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
ParameterCode.
|
|
23
|
-
|
|
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
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|