@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,353 @@
|
|
|
1
|
+
import { ErrorCode } from '../../balancing/code/error/index.ts'
|
|
2
|
+
import { JoinMode } from '../../balancing/code/join/index.ts'
|
|
3
|
+
import { ErrorMessage } from '../../balancing/code/message/index.ts'
|
|
4
|
+
import { RoomOptionFlag } from '../../balancing/code/room/index.ts'
|
|
5
|
+
import type { ExcludedUser } from '../../registry/index.ts'
|
|
6
|
+
import type { Actor } from '../actor/index.ts'
|
|
7
|
+
import type { EntrySetup } from '../entry/index.ts'
|
|
8
|
+
import { Fault } from '../fault/index.ts'
|
|
9
|
+
import type { History } from '../history/index.ts'
|
|
10
|
+
import type { Lifecycle } from '../lifecycle/index.ts'
|
|
11
|
+
import type { GamePeer } from '../peer/index.ts'
|
|
12
|
+
import type { RoomProperties } from '../properties/index.ts'
|
|
13
|
+
import type { Seats } from '../seats/index.ts'
|
|
14
|
+
import type { RoomServices } from '../services/index.ts'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Decides who gets a seat in one room and which one
|
|
18
|
+
* @class
|
|
19
|
+
*/
|
|
20
|
+
export class Admission {
|
|
21
|
+
/**
|
|
22
|
+
* How a GUID user id looks
|
|
23
|
+
*/
|
|
24
|
+
private static readonly GUID: RegExp =
|
|
25
|
+
/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Who sits in the room
|
|
29
|
+
*/
|
|
30
|
+
private readonly seats: Seats
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Limits and options of the room
|
|
34
|
+
*/
|
|
35
|
+
private readonly properties: RoomProperties
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Whether the caches overflowed
|
|
39
|
+
*/
|
|
40
|
+
private readonly history: History
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Keeps the room alive and times the empty seats
|
|
44
|
+
*/
|
|
45
|
+
private readonly lifecycle: Lifecycle
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* What every room shares
|
|
49
|
+
*/
|
|
50
|
+
private readonly services: RoomServices
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param seats who sits in the room
|
|
54
|
+
* @param properties limits and options of the room
|
|
55
|
+
* @param history whether the caches overflowed
|
|
56
|
+
* @param lifecycle keeps the room alive and times the empty seats
|
|
57
|
+
* @param services what every room shares
|
|
58
|
+
*/
|
|
59
|
+
public constructor(
|
|
60
|
+
seats: Seats,
|
|
61
|
+
properties: RoomProperties,
|
|
62
|
+
history: History,
|
|
63
|
+
lifecycle: Lifecycle,
|
|
64
|
+
services: RoomServices,
|
|
65
|
+
) {
|
|
66
|
+
this.seats = seats
|
|
67
|
+
this.properties = properties
|
|
68
|
+
this.history = history
|
|
69
|
+
this.lifecycle = lifecycle
|
|
70
|
+
this.services = services
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The refusal for a user the room keeps out
|
|
75
|
+
* @param ban who's kept out and why
|
|
76
|
+
*/
|
|
77
|
+
private static banned(ban: ExcludedUser): Fault {
|
|
78
|
+
switch (ban.reason) {
|
|
79
|
+
case 1:
|
|
80
|
+
return Fault.of(
|
|
81
|
+
ErrorCode.JOIN_FAILED_FOUND_EXCLUDED_USER_ID,
|
|
82
|
+
'User {0} is banned in this game',
|
|
83
|
+
ban.userId,
|
|
84
|
+
)
|
|
85
|
+
case 2:
|
|
86
|
+
return Fault.of(
|
|
87
|
+
ErrorCode.JOIN_FAILED_FOUND_EXCLUDED_USER_ID,
|
|
88
|
+
'User {0} is global banned',
|
|
89
|
+
ban.userId,
|
|
90
|
+
)
|
|
91
|
+
default:
|
|
92
|
+
return Fault.of(
|
|
93
|
+
ErrorCode.JOIN_FAILED_FOUND_EXCLUDED_USER_ID,
|
|
94
|
+
'Unknown reason {0} for excluding ',
|
|
95
|
+
ban.reason,
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Why a connection can't get into the room, or null
|
|
102
|
+
* @param peer who's asking
|
|
103
|
+
* @param setup the request as the room needs it
|
|
104
|
+
*/
|
|
105
|
+
public refusal(peer: GamePeer, setup: EntrySetup): Fault | null {
|
|
106
|
+
const userId = peer.userId
|
|
107
|
+
const awaited = this.seats.expected.includes(userId)
|
|
108
|
+
|
|
109
|
+
if (setup.rejoining) {
|
|
110
|
+
const fault = this.rejoin(peer, setup)
|
|
111
|
+
if (fault !== undefined) return fault
|
|
112
|
+
if (awaited) {
|
|
113
|
+
return Fault.denied(ErrorMessage.REJOIN_OR_JOIN_WITH_EXPECTED_PLAYER)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (!this.properties.isOpen) {
|
|
118
|
+
return Fault.of(
|
|
119
|
+
ErrorCode.GAME_CLOSED,
|
|
120
|
+
this.history.discarded
|
|
121
|
+
? ErrorMessage.GAME_CLOSED_CACHE_DISCARDED
|
|
122
|
+
: ErrorMessage.GAME_CLOSED,
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const limit = this.properties.maxPlayers
|
|
127
|
+
const taken = this.seats.taken + this.seats.awaited
|
|
128
|
+
if (limit > 0 && taken >= limit && !awaited) {
|
|
129
|
+
return Fault.of(ErrorCode.GAME_FULL, ErrorMessage.GAME_FULL)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return null
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The seat a connection comes back to, null for a new one, or why it can't sit
|
|
137
|
+
* @param peer who's asking
|
|
138
|
+
* @param setup the request as the room needs it
|
|
139
|
+
*/
|
|
140
|
+
public seat(peer: GamePeer, setup: EntrySetup): Actor | Fault | null {
|
|
141
|
+
if (this.seats.playing(peer) !== null) {
|
|
142
|
+
return Fault.of(
|
|
143
|
+
ErrorCode.JOIN_FAILED_PEER_ALREADY_JOINED,
|
|
144
|
+
'Join failed: Peer already joined the specified game.',
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const found = this.properties.has(RoomOptionFlag.CHECK_USER_ON_JOIN)
|
|
149
|
+
? this.seatByUser(peer, setup)
|
|
150
|
+
: this.seatByNumber(peer, setup)
|
|
151
|
+
if (found !== null) return found
|
|
152
|
+
|
|
153
|
+
return setup.mode === JoinMode.REJOIN_ONLY
|
|
154
|
+
? Fault.of(
|
|
155
|
+
ErrorCode.JOIN_FAILED_WITH_REJOINER_NOT_FOUND,
|
|
156
|
+
'Rejoin failed: userid={0} not found, actor nr={1}.',
|
|
157
|
+
peer.userId,
|
|
158
|
+
setup.actorNumber,
|
|
159
|
+
)
|
|
160
|
+
: null
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* How a rejoin request fares, undefined to go on as a plain join
|
|
165
|
+
* @param peer who's asking
|
|
166
|
+
* @param setup the request as the room needs it
|
|
167
|
+
*/
|
|
168
|
+
private rejoin(peer: GamePeer, setup: EntrySetup): Fault | null | undefined {
|
|
169
|
+
if (this.history.discarded) {
|
|
170
|
+
return Fault.of(
|
|
171
|
+
ErrorCode.EVENT_CACHE_EXCEEDED,
|
|
172
|
+
ErrorMessage.REJOINING_BLOCKED_CACHE_EXCEEDED,
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const lasting = this.properties.playerTtl !== 0
|
|
177
|
+
const only = setup.mode === JoinMode.REJOIN_ONLY
|
|
178
|
+
if (!lasting && only) {
|
|
179
|
+
return Fault.denied(ErrorMessage.REJOIN_NOT_SUPPORTED)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const named = this.properties.has(RoomOptionFlag.CHECK_USER_ON_JOIN)
|
|
183
|
+
const actor = named
|
|
184
|
+
? this.seats.user(peer.userId)
|
|
185
|
+
: this.seats.numbered(setup.actorNumber)
|
|
186
|
+
if (actor !== null) {
|
|
187
|
+
return lasting || only
|
|
188
|
+
? null
|
|
189
|
+
: Fault.denied(ErrorMessage.REJOIN_NOT_SUPPORTED)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (!only) return undefined
|
|
193
|
+
|
|
194
|
+
return named
|
|
195
|
+
? Fault.of(
|
|
196
|
+
ErrorCode.JOIN_FAILED_WITH_REJOINER_NOT_FOUND,
|
|
197
|
+
ErrorMessage.USER_NOT_FOUND,
|
|
198
|
+
)
|
|
199
|
+
: Fault.of(
|
|
200
|
+
ErrorCode.JOIN_FAILED_WITH_REJOINER_NOT_FOUND,
|
|
201
|
+
ErrorMessage.ACTOR_NOT_FOUND,
|
|
202
|
+
setup.actorNumber,
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The seat of a connection's user id, null for none, or why it can't sit
|
|
208
|
+
* @param peer who's asking
|
|
209
|
+
* @param setup the request as the room needs it
|
|
210
|
+
*/
|
|
211
|
+
private seatByUser(peer: GamePeer, setup: EntrySetup): Actor | Fault | null {
|
|
212
|
+
const userId = peer.userId
|
|
213
|
+
if (userId === '') {
|
|
214
|
+
return Fault.invalid(
|
|
215
|
+
'Join failed: UserId is not set, checkUserIdOnJoin=true expects a UserId.',
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const ban = this.seats.excluded.find(
|
|
220
|
+
(user: ExcludedUser): boolean => user.userId === userId,
|
|
221
|
+
)
|
|
222
|
+
if (ban !== undefined) return Admission.banned(ban)
|
|
223
|
+
|
|
224
|
+
const actor = this.seats.user(userId)
|
|
225
|
+
if (actor === null) return null
|
|
226
|
+
|
|
227
|
+
if (actor.active) {
|
|
228
|
+
return this.takeover(actor, peer, setup, setup.forceRejoin)
|
|
229
|
+
? actor
|
|
230
|
+
: Fault.of(
|
|
231
|
+
ErrorCode.JOIN_FAILED_FOUND_ACTIVE_JOINER,
|
|
232
|
+
ErrorMessage.USER_ALREADY_JOINED,
|
|
233
|
+
userId,
|
|
234
|
+
setup.mode,
|
|
235
|
+
)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (this.lifecycle.expired(actor)) {
|
|
239
|
+
return Fault.of(
|
|
240
|
+
ErrorCode.JOIN_FAILED_WITH_REJOINER_NOT_FOUND,
|
|
241
|
+
"Join failed: UserId '{0}' is expired (JoinMode={1}).",
|
|
242
|
+
userId,
|
|
243
|
+
setup.mode,
|
|
244
|
+
)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return setup.rejoining
|
|
248
|
+
? actor
|
|
249
|
+
: Fault.of(
|
|
250
|
+
ErrorCode.JOIN_FAILED_FOUND_INACTIVE_JOINER,
|
|
251
|
+
"Found inactive UserId '{0}', but not rejoining (JoinMode={1}).",
|
|
252
|
+
userId,
|
|
253
|
+
setup.mode,
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* The seat a request names by number, null for none, or why it can't sit
|
|
259
|
+
* @param peer who's asking
|
|
260
|
+
* @param setup the request as the room needs it
|
|
261
|
+
*/
|
|
262
|
+
private seatByNumber(
|
|
263
|
+
peer: GamePeer,
|
|
264
|
+
setup: EntrySetup,
|
|
265
|
+
): Actor | Fault | null {
|
|
266
|
+
const number = setup.actorNumber
|
|
267
|
+
if (number <= 0) return null
|
|
268
|
+
|
|
269
|
+
const actor = this.seats.numbered(number)
|
|
270
|
+
if (actor === null) {
|
|
271
|
+
return Fault.of(
|
|
272
|
+
ErrorCode.JOIN_FAILED_WITH_REJOINER_NOT_FOUND,
|
|
273
|
+
'Rejoin failed: actor nr={0} not found.',
|
|
274
|
+
number,
|
|
275
|
+
)
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (actor.active) {
|
|
279
|
+
return this.takeover(actor, peer, setup, false)
|
|
280
|
+
? actor
|
|
281
|
+
: Fault.of(
|
|
282
|
+
ErrorCode.JOIN_FAILED_FOUND_ACTIVE_JOINER,
|
|
283
|
+
ErrorMessage.USER_WITH_ACTOR_ID_ALREADY_JOINED,
|
|
284
|
+
number,
|
|
285
|
+
setup.mode,
|
|
286
|
+
)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const strangers =
|
|
290
|
+
actor.userId !== peer.userId &&
|
|
291
|
+
!(Admission.GUID.test(actor.userId) && Admission.GUID.test(peer.userId))
|
|
292
|
+
if (strangers) {
|
|
293
|
+
return Fault.internal(
|
|
294
|
+
"Rejoin failed: userId of peer doesn't match userid of actor.",
|
|
295
|
+
)
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (this.lifecycle.expired(actor)) {
|
|
299
|
+
return Fault.of(
|
|
300
|
+
ErrorCode.JOIN_FAILED_WITH_REJOINER_NOT_FOUND,
|
|
301
|
+
"Join failed: ActorNr '{0}' is expired.",
|
|
302
|
+
number,
|
|
303
|
+
)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return setup.rejoining
|
|
307
|
+
? actor
|
|
308
|
+
: Fault.internal(
|
|
309
|
+
"Found inactive ActorNr '{0}', but not rejoining (JoinMode={1}).",
|
|
310
|
+
number,
|
|
311
|
+
setup.mode,
|
|
312
|
+
)
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Frees a taken seat for a second connection of the same login
|
|
317
|
+
* @param actor the seat
|
|
318
|
+
* @param peer who's asking
|
|
319
|
+
* @param setup the request as the room needs it
|
|
320
|
+
* @param forced whether the request insists
|
|
321
|
+
*/
|
|
322
|
+
private takeover(
|
|
323
|
+
actor: Actor,
|
|
324
|
+
peer: GamePeer,
|
|
325
|
+
setup: EntrySetup,
|
|
326
|
+
forced: boolean,
|
|
327
|
+
): boolean {
|
|
328
|
+
const holder = actor.peer
|
|
329
|
+
if (
|
|
330
|
+
holder === null ||
|
|
331
|
+
this.properties.playerTtl === 0 ||
|
|
332
|
+
!setup.rejoining
|
|
333
|
+
) {
|
|
334
|
+
return false
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const first = holder.token
|
|
338
|
+
const second = peer.token
|
|
339
|
+
const same =
|
|
340
|
+
first !== null &&
|
|
341
|
+
second !== null &&
|
|
342
|
+
this.services.authenticator.same(first, second)
|
|
343
|
+
if (!forced && !same) return false
|
|
344
|
+
|
|
345
|
+
this.seats.suspend(actor, this.services.clock.now())
|
|
346
|
+
|
|
347
|
+
this.lifecycle.forget(holder)
|
|
348
|
+
holder.room = null
|
|
349
|
+
holder.drop()
|
|
350
|
+
|
|
351
|
+
return true
|
|
352
|
+
}
|
|
353
|
+
}
|
|
@@ -66,6 +66,19 @@ export class PropertyBag {
|
|
|
66
66
|
return this.table.size
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* How many properties it would hold after a merge
|
|
71
|
+
* @param properties what would be written
|
|
72
|
+
*/
|
|
73
|
+
public grown(properties: PhotonHashtable): number {
|
|
74
|
+
let size = this.table.size
|
|
75
|
+
for (const [key] of properties.entries()) {
|
|
76
|
+
if (!this.table.has(key)) size += 1
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return size
|
|
80
|
+
}
|
|
81
|
+
|
|
69
82
|
/**
|
|
70
83
|
* The value under a key, or null
|
|
71
84
|
* @param key typed key
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Channel } from '@netifyjs/netify'
|
|
2
|
+
|
|
3
|
+
import { SharedFrames } from '../shared/index.ts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Sends one packet to several connections
|
|
7
|
+
*/
|
|
8
|
+
export type Broadcast = {
|
|
9
|
+
/**
|
|
10
|
+
* Sends a packet to every connection given
|
|
11
|
+
* @param channels who gets it
|
|
12
|
+
* @param packet a typed packet
|
|
13
|
+
*/
|
|
14
|
+
spread(channels: readonly Channel[], packet: unknown): void
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Sends a room's broadcasts, encoding once for clients that read the same bytes
|
|
19
|
+
* @class
|
|
20
|
+
*/
|
|
21
|
+
export class Broadcaster implements Broadcast {
|
|
22
|
+
/**
|
|
23
|
+
* Encodes an event once, or null
|
|
24
|
+
*/
|
|
25
|
+
private readonly shared: SharedFrames | null
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Takes broadcasts over, or null
|
|
29
|
+
*/
|
|
30
|
+
private route: Broadcast | null
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param shared encodes an event once, or null
|
|
34
|
+
*/
|
|
35
|
+
public constructor(shared: SharedFrames | null) {
|
|
36
|
+
this.shared = shared
|
|
37
|
+
this.route = null
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Hands every later broadcast to something else
|
|
42
|
+
* @param route takes broadcasts over
|
|
43
|
+
*/
|
|
44
|
+
public reroute(route: Broadcast): void {
|
|
45
|
+
this.route = route
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Sends a packet to every connection given
|
|
50
|
+
* @param channels who gets it
|
|
51
|
+
* @param packet a typed packet
|
|
52
|
+
*/
|
|
53
|
+
public spread(channels: readonly Channel[], packet: unknown): void {
|
|
54
|
+
if (this.route !== null) {
|
|
55
|
+
this.route.spread(channels, packet)
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const shared = channels.length > 1 ? this.shared : null
|
|
60
|
+
let frame: Uint8Array | null = null
|
|
61
|
+
let framed = false
|
|
62
|
+
|
|
63
|
+
for (const channel of channels) {
|
|
64
|
+
if (!channel.isActive) continue
|
|
65
|
+
if (shared === null || !SharedFrames.reads(channel)) {
|
|
66
|
+
channel.writeAndFlush(packet)
|
|
67
|
+
continue
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!framed) {
|
|
71
|
+
frame = shared.frame(packet)
|
|
72
|
+
framed = true
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (frame === null) channel.writeAndFlush(packet)
|
|
76
|
+
else channel.send(frame)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|