@netifyjs/protocol 1.0.0-alpha.2 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/codec/index.ts +82 -157
- package/src/dispatch/dispatcher/index.ts +116 -33
- package/src/dispatch/session/index.ts +9 -3
- package/src/index.ts +2 -4
- package/src/photon/balancing/codec/index.ts +27 -53
- package/src/photon/balancing/format/authenticate/request/index.ts +52 -6
- package/src/photon/balancing/format/friends/request/index.ts +21 -5
- package/src/photon/balancing/format/game/create/request/index.ts +45 -8
- package/src/photon/balancing/format/game/debug/request/index.ts +19 -4
- package/src/photon/balancing/format/game/join/request/index.ts +65 -13
- package/src/photon/balancing/format/game/list/request/index.ts +29 -3
- package/src/photon/balancing/format/game/random/request/index.ts +58 -10
- package/src/photon/balancing/format/groups/request/index.ts +19 -3
- package/src/photon/balancing/format/index.ts +7 -0
- package/src/photon/balancing/format/leave/request/index.ts +19 -3
- package/src/photon/balancing/format/lobby/join/request/index.ts +23 -3
- package/src/photon/balancing/format/lobby/stats/request/index.ts +19 -3
- package/src/photon/balancing/format/once/request/index.ts +31 -8
- package/src/photon/balancing/format/properties/get/request/index.ts +31 -4
- package/src/photon/balancing/format/properties/set/request/index.ts +36 -7
- package/src/photon/balancing/format/raise/request/index.ts +76 -10
- package/src/photon/balancing/format/reader/index.ts +75 -6
- package/src/photon/balancing/format/regions/request/index.ts +16 -1
- package/src/photon/balancing/format/rpc/request/index.ts +26 -3
- package/src/photon/balancing/format/settings/request/index.ts +15 -2
- package/src/photon/balancing/format/shared/credentials/index.ts +77 -33
- package/src/photon/balancing/format/shared/lobby/index.ts +41 -5
- package/src/photon/balancing/format/shared/options/index.ts +56 -24
- package/src/photon/balancing/format/table/index.ts +399 -0
- package/src/photon/balancing/index.ts +11 -1
- package/src/photon/balancing/travel/index.ts +15 -12
- package/src/photon/binary/v18/index.ts +26 -1
- package/src/photon/binary/value/index.ts +52 -3
- package/src/photon/client/connection/index.ts +6 -6
- package/src/photon/cluster/back/index.ts +32 -45
- package/src/photon/cluster/dresser/index.ts +7 -8
- package/src/photon/cluster/front/index.ts +25 -49
- package/src/photon/cluster/grid/index.ts +1 -1
- package/src/photon/cluster/mover/index.ts +12 -12
- package/src/photon/cluster/press/index.ts +2 -18
- package/src/photon/cluster/route/game/index.ts +9 -11
- package/src/photon/cluster/route/master/index.ts +15 -34
- package/src/photon/cluster/route/name/index.ts +4 -21
- package/src/photon/cluster/seat/game/index.ts +6 -26
- package/src/photon/cluster/seat/master/index.ts +1 -1
- package/src/photon/cluster/sessions/index.ts +5 -6
- package/src/photon/cluster/spread/index.ts +8 -147
- package/src/photon/enet/client/index.ts +1 -8
- package/src/photon/enet/gateway/index.ts +5 -15
- package/src/photon/enet/index.ts +1 -1
- package/src/photon/enet/link/index.ts +34 -15
- package/src/photon/enet/outbound/index.ts +279 -0
- package/src/photon/enet/peer/index.ts +59 -0
- package/src/photon/enet/transport/index.ts +8 -24
- package/src/photon/game/admission/index.ts +353 -0
- package/src/photon/game/bag/index.ts +13 -0
- package/src/photon/game/broadcast/index.ts +79 -0
- package/src/photon/game/editor/index.ts +446 -0
- package/src/photon/game/gate/index.ts +9 -8
- package/src/photon/game/handler/index.ts +30 -3
- package/src/photon/game/history/index.ts +234 -0
- package/src/photon/game/hooked/index.ts +16 -15
- package/src/photon/game/index.ts +12 -1
- package/src/photon/game/lifecycle/index.ts +193 -0
- package/src/photon/game/peer/index.ts +1 -10
- package/src/photon/game/properties/index.ts +342 -0
- package/src/photon/game/room/index.ts +435 -1793
- package/src/photon/game/rooms/index.ts +2 -1
- package/src/photon/game/seats/index.ts +237 -0
- package/src/photon/game/server/index.ts +12 -2
- package/src/photon/game/services/index.ts +41 -0
- package/src/photon/game/settings/index.ts +22 -0
- package/src/photon/game/snapshot/index.ts +133 -0
- package/src/photon/game/throttle/index.ts +60 -0
- package/src/photon/game/touch/index.ts +2 -5
- package/src/photon/game/venue/index.ts +31 -0
- package/src/photon/master/application/index.ts +7 -0
- package/src/photon/master/gate/index.ts +12 -8
- package/src/photon/master/handler/index.ts +36 -748
- package/src/photon/master/index.ts +5 -0
- package/src/photon/master/list/sql/index.ts +37 -3
- package/src/photon/master/listing/index.ts +133 -0
- package/src/photon/master/lobby/index.ts +9 -0
- package/src/photon/master/login/index.ts +424 -0
- package/src/photon/master/matchmaking/index.ts +282 -0
- package/src/photon/master/query/index.ts +45 -0
- package/src/photon/master/redirect/index.ts +8 -7
- package/src/photon/master/services/index.ts +35 -0
- package/src/photon/master/settings/index.ts +44 -0
- package/src/photon/master/sql/cost/index.ts +263 -0
- package/src/photon/master/sql/index.ts +1 -0
- package/src/photon/message/binary/index.ts +35 -1
- package/src/photon/message/client/index.ts +14 -11
- package/src/photon/message/format/index.ts +9 -0
- package/src/photon/message/handler/index.ts +48 -63
- package/src/photon/message/pipeline/index.ts +12 -12
- package/src/photon/message/server/index.ts +87 -43
- package/src/photon/message/watch/index.ts +127 -15
- package/src/photon/server/config/index.ts +5 -0
- package/src/photon/server/deferral/index.ts +57 -0
- package/src/photon/server/host/index.ts +36 -10
- package/src/photon/server/index.ts +1 -0
- package/src/photon/server/listeners/index.ts +11 -0
- package/src/photon/tcp/client/index.ts +1 -1
- package/src/photon/tcp/codec/index.ts +41 -38
- package/src/photon/tcp/framing/index.ts +24 -4
- package/src/photon/tcp/server/index.ts +4 -4
- package/src/photon/websocket/bridge/index.ts +16 -20
- package/src/photon/websocket/message/index.ts +27 -39
- package/src/photon/websocket/path/index.ts +2 -5
- package/src/scale/batch/index.ts +14 -6
- package/src/scale/fanout/index.ts +6 -6
- package/src/scale/index.ts +2 -4
- package/src/scale/outbound/index.ts +192 -0
- package/src/scale/relay/index.ts +24 -16
- package/src/scale/sink/index.ts +6 -11
- package/src/scale/transport/index.ts +27 -44
- package/src/scale/tunnel/index.ts +56 -86
- package/src/smartfox/common/bluebox/gateway/index.ts +401 -0
- package/src/smartfox/common/bluebox/index.ts +4 -0
- package/src/smartfox/{x2 → common}/bluebox/transport/index.ts +36 -23
- package/src/smartfox/common/index.ts +5 -0
- package/src/smartfox/common/strikes/index.ts +74 -0
- package/src/smartfox/pro/bluebox/index.ts +176 -4
- package/src/smartfox/pro/codec/index.ts +8 -7
- package/src/smartfox/pro/escalation/index.ts +28 -20
- package/src/smartfox/pro/flood/index.ts +2 -2
- package/src/smartfox/pro/format/extension/raw/index.ts +12 -2
- package/src/smartfox/pro/handler/chat/index.ts +11 -8
- package/src/smartfox/pro/handler/login/index.ts +2 -25
- package/src/smartfox/pro/handler/shared/index.ts +4 -3
- package/src/smartfox/pro/index.ts +11 -5
- package/src/smartfox/pro/login/gate/index.ts +166 -0
- package/src/smartfox/pro/login/index.ts +1 -0
- package/src/smartfox/pro/moderation/index.ts +220 -0
- package/src/smartfox/pro/options/index.ts +5 -5
- package/src/smartfox/pro/protocol/index.ts +62 -8
- package/src/smartfox/pro/web/index.ts +33 -26
- package/src/smartfox/pro/zone/index.ts +59 -282
- package/src/smartfox/pro/zones/index.ts +3 -3
- package/src/smartfox/x2/bluebox/index.ts +149 -4
- package/src/smartfox/x2/chat/index.ts +9 -19
- package/src/smartfox/x2/codec/index.ts +34 -40
- package/src/smartfox/x2/config/index.ts +6 -1
- package/src/smartfox/x2/data/array/index.ts +96 -60
- package/src/smartfox/x2/data/object/index.ts +144 -82
- package/src/smartfox/x2/data/serializer/index.ts +41 -23
- package/src/smartfox/x2/flood/gate/index.ts +19 -13
- package/src/smartfox/x2/format/buddy/init/response/index.ts +4 -3
- package/src/smartfox/x2/format/find/rooms/response/index.ts +4 -3
- package/src/smartfox/x2/format/find/users/response/index.ts +4 -3
- package/src/smartfox/x2/format/group/subscribe/response/index.ts +4 -3
- package/src/smartfox/x2/format/login/response/index.ts +4 -3
- package/src/smartfox/x2/format/mmo/position/response/index.ts +8 -6
- package/src/smartfox/x2/format/room/join/response/index.ts +4 -3
- package/src/smartfox/x2/games/index.ts +35 -8
- package/src/smartfox/x2/hall/index.ts +0 -6
- package/src/smartfox/x2/handler/session/index.ts +1 -1
- package/src/smartfox/x2/index.ts +8 -3
- package/src/smartfox/x2/member/index.ts +10 -3
- package/src/smartfox/x2/packet/login/response/index.ts +12 -0
- package/src/smartfox/x2/protocol/index.ts +11 -1
- package/src/smartfox/x2/rooms/index.ts +1 -2
- package/src/smartfox/x2/sessions/index.ts +6 -0
- package/src/smartfox/x2/udp/index.ts +61 -24
- package/src/smartfox/x2/web/index.ts +35 -17
- package/src/smartfox/x2/websocket/index.ts +18 -36
- package/src/smartfox/x2/zone/index.ts +77 -28
- package/src/smartfox/x2/zones/index.ts +17 -5
- package/src/photon/enet/handler/index.ts +0 -65
- package/src/scale/hosted/index.ts +0 -68
- package/src/scale/outlet/index.ts +0 -121
- package/src/smartfox/pro/bluebox/gateway/index.ts +0 -310
- package/src/smartfox/pro/bluebox/session/index.ts +0 -63
- package/src/smartfox/pro/bluebox/transport/index.ts +0 -104
- package/src/smartfox/x2/bluebox/gateway/index.ts +0 -315
- /package/src/smartfox/{x2 → common}/bluebox/session/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/memory/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/offender/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/store/index.ts +0 -0
- /package/src/smartfox/{pro → common}/sequence/index.ts +0 -0
|
@@ -0,0 +1,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
|
+
}
|