@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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { EntrySetup } from '../entry/index.ts'
|
|
2
2
|
import { HookedRoom } from '../hooked/index.ts'
|
|
3
3
|
import type { GamePeer } from '../peer/index.ts'
|
|
4
|
-
import { Room
|
|
4
|
+
import { Room } from '../room/index.ts'
|
|
5
|
+
import type { RoomServices } from '../services/index.ts'
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Every room of one Game Server
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import type { ExcludedUser } from '../../registry/index.ts'
|
|
2
|
+
import { Actor } from '../actor/index.ts'
|
|
3
|
+
import { InterestGroups } from '../groups/index.ts'
|
|
4
|
+
import type { GamePeer } from '../peer/index.ts'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Who sits in one room, connected or away
|
|
8
|
+
* @class
|
|
9
|
+
*/
|
|
10
|
+
export class Seats {
|
|
11
|
+
/**
|
|
12
|
+
* Connected actors in the order they came
|
|
13
|
+
*/
|
|
14
|
+
public readonly active: Actor[]
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Actors that are away, in the order they went
|
|
18
|
+
*/
|
|
19
|
+
public readonly inactive: Actor[]
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Who hears which group
|
|
23
|
+
*/
|
|
24
|
+
public readonly groups: InterestGroups
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Highest actor number given out
|
|
28
|
+
*/
|
|
29
|
+
public counter: number
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Actor number of the master client, or 0
|
|
33
|
+
*/
|
|
34
|
+
public master: number
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* User ids with a seat kept
|
|
38
|
+
*/
|
|
39
|
+
public expected: string[]
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Users kept out
|
|
43
|
+
*/
|
|
44
|
+
public excluded: readonly ExcludedUser[]
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The connected actor of each connection
|
|
48
|
+
*/
|
|
49
|
+
private readonly peers: Map<GamePeer, Actor>
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Starts with every seat empty
|
|
53
|
+
*/
|
|
54
|
+
public constructor() {
|
|
55
|
+
this.active = []
|
|
56
|
+
this.inactive = []
|
|
57
|
+
this.groups = new InterestGroups()
|
|
58
|
+
this.counter = 0
|
|
59
|
+
this.master = 0
|
|
60
|
+
this.expected = []
|
|
61
|
+
this.excluded = []
|
|
62
|
+
this.peers = new Map<GamePeer, Actor>()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Every actor, connected ones first
|
|
67
|
+
*/
|
|
68
|
+
public get everyone(): readonly Actor[] {
|
|
69
|
+
return [...this.active, ...this.inactive]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* How many seats are taken, connected or away
|
|
74
|
+
*/
|
|
75
|
+
public get taken(): number {
|
|
76
|
+
return this.active.length + this.inactive.length
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Numbers of the connected actors in the order they came
|
|
81
|
+
*/
|
|
82
|
+
public get numbers(): readonly number[] {
|
|
83
|
+
return this.active.map<number>((actor: Actor): number => actor.number)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* User ids with a seat kept that never showed up
|
|
88
|
+
*/
|
|
89
|
+
public get awaited(): number {
|
|
90
|
+
return this.pending(this.expected)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The connected actor of a connection, or null
|
|
95
|
+
* @param peer the connection
|
|
96
|
+
*/
|
|
97
|
+
public playing(peer: GamePeer): Actor | null {
|
|
98
|
+
return this.peers.get(peer) ?? null
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The actor with a number, connected or away, or null
|
|
103
|
+
* @param number actor number
|
|
104
|
+
*/
|
|
105
|
+
public numbered(number: number): Actor | null {
|
|
106
|
+
for (const actor of this.active) {
|
|
107
|
+
if (actor.number === number) return actor
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
for (const actor of this.inactive) {
|
|
111
|
+
if (actor.number === number) return actor
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return null
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The actor of a user, connected or away, or null
|
|
119
|
+
* @param userId who to look for
|
|
120
|
+
*/
|
|
121
|
+
public user(userId: string): Actor | null {
|
|
122
|
+
return (
|
|
123
|
+
this.everyone.find((actor: Actor): boolean => actor.userId === userId) ??
|
|
124
|
+
null
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* How many of some user ids have no actor
|
|
130
|
+
* @param users user ids to look for
|
|
131
|
+
*/
|
|
132
|
+
public pending(users: readonly string[]): number {
|
|
133
|
+
return users.filter((user: string): boolean => this.user(user) === null)
|
|
134
|
+
.length
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Gives a connection a new seat
|
|
139
|
+
* @param peer who sits down
|
|
140
|
+
*/
|
|
141
|
+
public add(peer: GamePeer): Actor {
|
|
142
|
+
this.counter += 1
|
|
143
|
+
|
|
144
|
+
const actor = Actor.of(this.counter, peer)
|
|
145
|
+
this.active.push(actor)
|
|
146
|
+
this.peers.set(peer, actor)
|
|
147
|
+
|
|
148
|
+
return actor
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Gives a connection its old seat back
|
|
153
|
+
* @param actor the seat
|
|
154
|
+
* @param peer who sits down
|
|
155
|
+
*/
|
|
156
|
+
public reactivate(actor: Actor, peer: GamePeer): Actor {
|
|
157
|
+
actor.expiry?.cancel()
|
|
158
|
+
actor.expiry = null
|
|
159
|
+
actor.peer = peer
|
|
160
|
+
actor.deactivatedAt = null
|
|
161
|
+
|
|
162
|
+
this.inactive.splice(this.inactive.indexOf(actor), 1)
|
|
163
|
+
this.active.push(actor)
|
|
164
|
+
this.peers.set(peer, actor)
|
|
165
|
+
this.groups.resume(actor)
|
|
166
|
+
|
|
167
|
+
return actor
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Keeps the seat of a connected actor that went away
|
|
172
|
+
* @param actor who went away
|
|
173
|
+
* @param now clock time in ms
|
|
174
|
+
*/
|
|
175
|
+
public suspend(actor: Actor, now: number): void {
|
|
176
|
+
this.groups.suspend(actor)
|
|
177
|
+
if (actor.peer !== null) this.peers.delete(actor.peer)
|
|
178
|
+
actor.peer = null
|
|
179
|
+
actor.deactivatedAt = now
|
|
180
|
+
this.active.splice(this.active.indexOf(actor), 1)
|
|
181
|
+
this.inactive.push(actor)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Frees the seat of an actor for good
|
|
186
|
+
* @param actor who's out
|
|
187
|
+
*/
|
|
188
|
+
public drop(actor: Actor): void {
|
|
189
|
+
const list = actor.active ? this.active : this.inactive
|
|
190
|
+
|
|
191
|
+
list.splice(list.indexOf(actor), 1)
|
|
192
|
+
actor.expiry?.cancel()
|
|
193
|
+
actor.expiry = null
|
|
194
|
+
if (actor.peer !== null) this.peers.delete(actor.peer)
|
|
195
|
+
actor.peer = null
|
|
196
|
+
this.groups.forget(actor)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Makes the connected actor with the lowest number the master client
|
|
201
|
+
*/
|
|
202
|
+
public elect(): number {
|
|
203
|
+
this.master = this.numbers.reduce<number>(
|
|
204
|
+
(lowest: number, number: number): number =>
|
|
205
|
+
lowest === 0 || number < lowest ? number : lowest,
|
|
206
|
+
0,
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
return this.master
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Keeps seats for some users and says who's new, or null if there's no room
|
|
214
|
+
* @param users user ids to keep a seat for
|
|
215
|
+
* @param limit most players allowed, 0 for any number
|
|
216
|
+
*/
|
|
217
|
+
public reserve(
|
|
218
|
+
users: readonly string[],
|
|
219
|
+
limit: number,
|
|
220
|
+
): readonly string[] | null {
|
|
221
|
+
const added = users.filter(
|
|
222
|
+
(user: string): boolean => !this.expected.includes(user),
|
|
223
|
+
)
|
|
224
|
+
const taken = this.active.length + this.awaited + this.pending(added)
|
|
225
|
+
if (limit !== 0 && taken > limit) return null
|
|
226
|
+
|
|
227
|
+
let seats = this.taken + this.awaited
|
|
228
|
+
for (const user of added) {
|
|
229
|
+
if (this.user(user) !== null) continue
|
|
230
|
+
if (limit !== 0 && seats === limit) return null
|
|
231
|
+
seats += 1
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
this.expected.push(...added)
|
|
235
|
+
return added
|
|
236
|
+
}
|
|
237
|
+
}
|
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
ServerAddress,
|
|
20
20
|
} from '../../registry/index.ts'
|
|
21
21
|
import type { Authenticator } from '../authenticator/index.ts'
|
|
22
|
+
import { Broadcaster } from '../broadcast/index.ts'
|
|
22
23
|
import {
|
|
23
24
|
type Alarm,
|
|
24
25
|
type Clock,
|
|
@@ -31,8 +32,8 @@ import { GameHandler } from '../handler/index.ts'
|
|
|
31
32
|
import { GamePeer } from '../peer/index.ts'
|
|
32
33
|
import { Herald } from '../report/index.ts'
|
|
33
34
|
import { Rooms } from '../rooms/index.ts'
|
|
34
|
-
import { SharedFrames } from '../shared/index.ts'
|
|
35
35
|
import { GameConfiguration, type GameSettings } from '../settings/index.ts'
|
|
36
|
+
import { SharedFrames } from '../shared/index.ts'
|
|
36
37
|
import { TouchHandler } from '../touch/index.ts'
|
|
37
38
|
|
|
38
39
|
/**
|
|
@@ -70,6 +71,11 @@ export class GameServer {
|
|
|
70
71
|
*/
|
|
71
72
|
public readonly rooms: Rooms
|
|
72
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Sends room events to several clients
|
|
76
|
+
*/
|
|
77
|
+
public readonly broadcaster: Broadcaster
|
|
78
|
+
|
|
73
79
|
/**
|
|
74
80
|
* Limits, waits and addresses
|
|
75
81
|
*/
|
|
@@ -134,6 +140,9 @@ export class GameServer {
|
|
|
134
140
|
}
|
|
135
141
|
const peers = new Set<GamePeer>()
|
|
136
142
|
const guard = new CallGuard(configuration, clock)
|
|
143
|
+
const broadcaster = new Broadcaster(
|
|
144
|
+
configuration.sharedFrames ? new SharedFrames() : null,
|
|
145
|
+
)
|
|
137
146
|
const rooms = new Rooms(
|
|
138
147
|
{
|
|
139
148
|
/**
|
|
@@ -162,12 +171,13 @@ export class GameServer {
|
|
|
162
171
|
/**
|
|
163
172
|
* Encodes an event once for plain TCP clients
|
|
164
173
|
*/
|
|
165
|
-
|
|
174
|
+
broadcaster,
|
|
166
175
|
},
|
|
167
176
|
changed,
|
|
168
177
|
)
|
|
169
178
|
|
|
170
179
|
this.rooms = rooms
|
|
180
|
+
this.broadcaster = broadcaster
|
|
171
181
|
this.configuration = configuration
|
|
172
182
|
this.feed = feed
|
|
173
183
|
this.authenticator = authenticator
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { HookSender } from '../../hooks/sender/index.ts'
|
|
2
|
+
import type { Authenticator } from '../authenticator/index.ts'
|
|
3
|
+
import type { Broadcaster } from '../broadcast/index.ts'
|
|
4
|
+
import type { Clock } from '../clock/index.ts'
|
|
5
|
+
import type { Herald } from '../report/index.ts'
|
|
6
|
+
import type { GameConfiguration } from '../settings/index.ts'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* What every room of a Game Server shares
|
|
10
|
+
*/
|
|
11
|
+
export type RoomServices = {
|
|
12
|
+
/**
|
|
13
|
+
* Limits and waits
|
|
14
|
+
*/
|
|
15
|
+
readonly configuration: GameConfiguration
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Tells the time and runs the waits
|
|
19
|
+
*/
|
|
20
|
+
readonly clock: Clock
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Tells the Master what happens
|
|
24
|
+
*/
|
|
25
|
+
readonly herald: Herald
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Compares the tokens of two connections
|
|
29
|
+
*/
|
|
30
|
+
readonly authenticator: Authenticator
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Posts the WebHooks, or null
|
|
34
|
+
*/
|
|
35
|
+
readonly hooks: HookSender | null
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Sends one event to several clients
|
|
39
|
+
*/
|
|
40
|
+
readonly broadcaster: Broadcaster
|
|
41
|
+
}
|
|
@@ -95,6 +95,16 @@ export type GameSettings = {
|
|
|
95
95
|
*/
|
|
96
96
|
readonly actorEventCacheLimit?: number
|
|
97
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Most rooms the server holds, 50000 by default
|
|
100
|
+
*/
|
|
101
|
+
readonly roomsCountLimit?: number
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Most custom properties a room or an actor holds, 1000 by default
|
|
105
|
+
*/
|
|
106
|
+
readonly propertiesCountLimit?: number
|
|
107
|
+
|
|
98
108
|
/**
|
|
99
109
|
* Forwarded operations a room takes per second, 0 for no limit
|
|
100
110
|
*/
|
|
@@ -241,6 +251,16 @@ export class GameConfiguration {
|
|
|
241
251
|
*/
|
|
242
252
|
public readonly actorEventCacheLimit: number
|
|
243
253
|
|
|
254
|
+
/**
|
|
255
|
+
* Most rooms the server holds
|
|
256
|
+
*/
|
|
257
|
+
public readonly roomsCountLimit: number
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Most custom properties a room or an actor holds
|
|
261
|
+
*/
|
|
262
|
+
public readonly propertiesCountLimit: number
|
|
263
|
+
|
|
244
264
|
/**
|
|
245
265
|
* Forwarded operations a room takes per second, or 0
|
|
246
266
|
*/
|
|
@@ -316,6 +336,8 @@ export class GameConfiguration {
|
|
|
316
336
|
this.eventCacheLimit = settings.eventCacheLimit ?? 10_000
|
|
317
337
|
this.sliceLimit = settings.sliceLimit ?? 1000
|
|
318
338
|
this.actorEventCacheLimit = settings.actorEventCacheLimit ?? 10_000
|
|
339
|
+
this.roomsCountLimit = settings.roomsCountLimit ?? 50_000
|
|
340
|
+
this.propertiesCountLimit = settings.propertiesCountLimit ?? 1000
|
|
319
341
|
this.httpForwardLimit = settings.httpForwardLimit ?? 0
|
|
320
342
|
this.sharedFrames = settings.sharedFrames ?? true
|
|
321
343
|
this.rpc = settings.rpc ?? null
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { Lobby } from '../../balancing/entity/lobby/index.ts'
|
|
1
2
|
import type { PhotonHashtable } from '../../binary/hashtable/index.ts'
|
|
2
3
|
import type { PhotonValue } from '../../binary/value/index.ts'
|
|
3
4
|
import type { ExcludedUser } from '../../registry/index.ts'
|
|
5
|
+
import { Actor } from '../actor/index.ts'
|
|
4
6
|
import type { CacheSlice } from '../cache/index.ts'
|
|
7
|
+
import type { History } from '../history/index.ts'
|
|
8
|
+
import type { RoomProperties } from '../properties/index.ts'
|
|
9
|
+
import type { Seats } from '../seats/index.ts'
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* One seat of a room as it's saved
|
|
@@ -122,3 +127,131 @@ export type RoomSnapshot = {
|
|
|
122
127
|
*/
|
|
123
128
|
readonly expected: readonly string[]
|
|
124
129
|
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Saves a room and brings it back
|
|
133
|
+
* @class
|
|
134
|
+
*/
|
|
135
|
+
export class RoomArchive {
|
|
136
|
+
/**
|
|
137
|
+
* Properties and options of the room
|
|
138
|
+
*/
|
|
139
|
+
private readonly properties: RoomProperties
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Who sits in the room
|
|
143
|
+
*/
|
|
144
|
+
private readonly seats: Seats
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The events the room keeps
|
|
148
|
+
*/
|
|
149
|
+
private readonly history: History
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @param properties properties and options of the room
|
|
153
|
+
* @param seats who sits in the room
|
|
154
|
+
* @param history the events the room keeps
|
|
155
|
+
*/
|
|
156
|
+
public constructor(
|
|
157
|
+
properties: RoomProperties,
|
|
158
|
+
seats: Seats,
|
|
159
|
+
history: History,
|
|
160
|
+
) {
|
|
161
|
+
this.properties = properties
|
|
162
|
+
this.seats = seats
|
|
163
|
+
this.history = history
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Everything the room needs to come back later
|
|
168
|
+
*/
|
|
169
|
+
public capture(): RoomSnapshot {
|
|
170
|
+
const properties = this.properties
|
|
171
|
+
const seats = this.seats
|
|
172
|
+
const everyone = seats.everyone
|
|
173
|
+
|
|
174
|
+
const groups = new Map<number, readonly number[]>()
|
|
175
|
+
for (const id of seats.groups.ids()) {
|
|
176
|
+
groups.set(
|
|
177
|
+
id,
|
|
178
|
+
everyone
|
|
179
|
+
.filter((actor: Actor): boolean => actor.groups.has(id))
|
|
180
|
+
.map<number>((actor: Actor): number => actor.number),
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
counter: seats.counter,
|
|
186
|
+
actors: everyone.map<ActorSnapshot>((actor: Actor): ActorSnapshot => ({
|
|
187
|
+
number: actor.number,
|
|
188
|
+
userId: actor.userId,
|
|
189
|
+
active: actor.active,
|
|
190
|
+
properties: actor.properties.all(),
|
|
191
|
+
deactivatedAt: actor.deactivatedAt,
|
|
192
|
+
})),
|
|
193
|
+
properties: properties.saved(),
|
|
194
|
+
slices: this.history.filled(),
|
|
195
|
+
groups,
|
|
196
|
+
emptyRoomTtl: properties.emptyRoomTtl,
|
|
197
|
+
isOpen: properties.isOpen,
|
|
198
|
+
isVisible: properties.isVisible,
|
|
199
|
+
lobbyId: properties.lobby?.name ?? null,
|
|
200
|
+
lobbyType: properties.lobby?.type ?? 0,
|
|
201
|
+
lobbyProperties: properties.filter,
|
|
202
|
+
maxPlayers: properties.maxPlayers,
|
|
203
|
+
playerTtl: properties.playerTtl,
|
|
204
|
+
slice: this.history.current,
|
|
205
|
+
flags: properties.flags,
|
|
206
|
+
excluded: seats.excluded,
|
|
207
|
+
expected: seats.expected,
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Brings back a saved room with every seat empty
|
|
213
|
+
* @param snapshot the room as it was saved
|
|
214
|
+
*/
|
|
215
|
+
public restore(snapshot: RoomSnapshot): void {
|
|
216
|
+
const properties = this.properties
|
|
217
|
+
const seats = this.seats
|
|
218
|
+
|
|
219
|
+
seats.counter = snapshot.counter
|
|
220
|
+
for (const saved of snapshot.actors ?? []) {
|
|
221
|
+
seats.inactive.push(
|
|
222
|
+
Actor.away(
|
|
223
|
+
saved.number,
|
|
224
|
+
saved.userId,
|
|
225
|
+
saved.properties,
|
|
226
|
+
saved.deactivatedAt,
|
|
227
|
+
),
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (snapshot.properties !== null) {
|
|
232
|
+
properties.bag.merge(snapshot.properties)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
this.history.load(snapshot.slices, snapshot.slice)
|
|
236
|
+
for (const [id, numbers] of snapshot.groups ?? []) {
|
|
237
|
+
for (const number of numbers) {
|
|
238
|
+
seats.groups.recall(seats.numbered(number), id)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
properties.adopt(snapshot.flags)
|
|
243
|
+
properties.revive(snapshot)
|
|
244
|
+
|
|
245
|
+
properties.lobby =
|
|
246
|
+
snapshot.lobbyId === null
|
|
247
|
+
? null
|
|
248
|
+
: Lobby.of(snapshot.lobbyId, snapshot.lobbyType)
|
|
249
|
+
if (snapshot.lobbyProperties !== null) {
|
|
250
|
+
properties.filter = snapshot.lobbyProperties
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
seats.master = 0
|
|
254
|
+
seats.excluded = [...snapshot.excluded]
|
|
255
|
+
seats.expected = [...snapshot.expected]
|
|
256
|
+
}
|
|
257
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { WebFlag } from '../../balancing/code/web/index.ts'
|
|
2
|
+
import type { Clock } from '../clock/index.ts'
|
|
3
|
+
import type { GameConfiguration } from '../settings/index.ts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Counts the operations a room forwards each second
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
export class Throttle {
|
|
10
|
+
/**
|
|
11
|
+
* Where the limit comes from
|
|
12
|
+
*/
|
|
13
|
+
private readonly configuration: GameConfiguration
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Tells the time
|
|
17
|
+
*/
|
|
18
|
+
private readonly clock: Clock
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Clock second the count belongs to
|
|
22
|
+
*/
|
|
23
|
+
private second: number
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Forwarded operations in that second
|
|
27
|
+
*/
|
|
28
|
+
private count: number
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param configuration where the limit comes from
|
|
32
|
+
* @param clock tells the time
|
|
33
|
+
*/
|
|
34
|
+
public constructor(configuration: GameConfiguration, clock: Clock) {
|
|
35
|
+
this.configuration = configuration
|
|
36
|
+
this.clock = clock
|
|
37
|
+
this.second = 0
|
|
38
|
+
this.count = 0
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Whether one more forwarded operation is over the limit
|
|
43
|
+
* @param webFlags web flags of the request, or null
|
|
44
|
+
*/
|
|
45
|
+
public throttled(webFlags: number | null): boolean {
|
|
46
|
+
const limit = this.configuration.httpForwardLimit
|
|
47
|
+
if (limit <= 0 || ((webFlags ?? 0) & WebFlag.HTTP_FORWARD) === 0) {
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const second = Math.floor(this.clock.now() / 1000)
|
|
52
|
+
if (second !== this.second) {
|
|
53
|
+
this.second = second
|
|
54
|
+
this.count = 0
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this.count += 1
|
|
58
|
+
return this.count > limit
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -33,11 +33,8 @@ export class TouchHandler extends InboundHandlerAdapter {
|
|
|
33
33
|
* @param context the connection
|
|
34
34
|
* @param message whatever arrived
|
|
35
35
|
*/
|
|
36
|
-
public override channelRead(
|
|
37
|
-
context: HandlerContext,
|
|
38
|
-
message: unknown,
|
|
39
|
-
): void | Promise<void> {
|
|
36
|
+
public override channelRead(context: HandlerContext, message: unknown): void {
|
|
40
37
|
this.peer.touched = this.clock.now()
|
|
41
|
-
|
|
38
|
+
context.fireChannelRead(message)
|
|
42
39
|
}
|
|
43
40
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Actor } from '../actor/index.ts'
|
|
2
|
+
import type { GameChanges } from '../report/index.ts'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What the parts of a room call back into
|
|
6
|
+
*/
|
|
7
|
+
export type Venue = {
|
|
8
|
+
/**
|
|
9
|
+
* Sends one packet to several actors
|
|
10
|
+
* @param actors who gets it
|
|
11
|
+
* @param packet a typed packet
|
|
12
|
+
*/
|
|
13
|
+
tell(actors: readonly Actor[], packet: unknown): void
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Tells the Master something about the room
|
|
17
|
+
* @param changes what's new
|
|
18
|
+
*/
|
|
19
|
+
report(changes: GameChanges): void
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Ends the room
|
|
23
|
+
*/
|
|
24
|
+
close(): void
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Takes out an actor whose time away ran out
|
|
28
|
+
* @param actor who stayed away
|
|
29
|
+
*/
|
|
30
|
+
expire(actor: Actor): void
|
|
31
|
+
}
|
|
@@ -126,6 +126,13 @@ export class MasterApplication implements MasterFeed, LobbyHost {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
+
/**
|
|
130
|
+
* How many games the whole application knows
|
|
131
|
+
*/
|
|
132
|
+
public get tracked(): number {
|
|
133
|
+
return this.games.size
|
|
134
|
+
}
|
|
135
|
+
|
|
129
136
|
/**
|
|
130
137
|
* A game of any lobby by name, or null
|
|
131
138
|
* @param id name of the game
|
|
@@ -84,23 +84,27 @@ export class OperationGate extends InboundHandlerAdapter {
|
|
|
84
84
|
* @param context the connection
|
|
85
85
|
* @param message an envelope from the message layer
|
|
86
86
|
*/
|
|
87
|
-
public override channelRead(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
public override channelRead(context: HandlerContext, message: unknown): void {
|
|
88
|
+
if (!(message instanceof Envelope)) {
|
|
89
|
+
context.fireChannelRead(message)
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
92
|
|
|
93
93
|
const envelope = message as Envelope
|
|
94
94
|
const request = envelope.message
|
|
95
95
|
if (!(request instanceof OperationRequest)) {
|
|
96
|
-
|
|
96
|
+
context.fireChannelRead(message)
|
|
97
|
+
return
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
const peer = Session.of<MasterPeer>(context.channel).user
|
|
100
101
|
const refusal = this.refusal(peer, request)
|
|
101
|
-
if (refusal === null)
|
|
102
|
+
if (refusal === null) {
|
|
103
|
+
context.fireChannelRead(message)
|
|
104
|
+
return
|
|
105
|
+
}
|
|
102
106
|
|
|
103
|
-
context.
|
|
107
|
+
context.writeAndFlush(
|
|
104
108
|
Travel.from(envelope)
|
|
105
109
|
.reply()
|
|
106
110
|
.wrap<OperationResponse>(
|