@netifyjs/protocol 1.0.0-alpha.3 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/codec/index.ts +51 -221
- package/src/dispatch/dispatcher/index.ts +89 -47
- package/src/dispatch/session/index.ts +6 -24
- 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/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/client/index.ts +14 -11
- package/src/photon/message/handler/index.ts +22 -64
- 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 +14 -37
- package/src/photon/server/deferral/index.ts +57 -0
- package/src/photon/server/host/index.ts +32 -10
- package/src/photon/server/index.ts +1 -0
- package/src/photon/tcp/client/index.ts +1 -1
- package/src/photon/tcp/codec/index.ts +13 -42
- 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/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 +20 -31
- package/src/scale/sink/index.ts +6 -11
- package/src/scale/transport/index.ts +27 -44
- package/src/scale/tunnel/index.ts +37 -91
- 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 +31 -39
- 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,4 +1,5 @@
|
|
|
1
|
-
import type { CounterStore } from '../../
|
|
1
|
+
import type { CounterStore } from '../../common/counters/store/index.ts'
|
|
2
|
+
import { type Sentence, Strikes } from '../../common/strikes/index.ts'
|
|
2
3
|
import type { SfsObject } from '../data/object/index.ts'
|
|
3
4
|
import type { Hall } from '../hall/index.ts'
|
|
4
5
|
import type { Member } from '../member/index.ts'
|
|
@@ -25,11 +26,6 @@ type Kicks = {
|
|
|
25
26
|
readonly until: number
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
/**
|
|
29
|
-
* What the words filter does to someone it caught
|
|
30
|
-
*/
|
|
31
|
-
type Sentence = 'warn' | 'kick' | 'ban'
|
|
32
|
-
|
|
33
29
|
/**
|
|
34
30
|
* Messages between a zone's users
|
|
35
31
|
* @class
|
|
@@ -327,21 +323,15 @@ export class Chat {
|
|
|
327
323
|
words: WordsFilter,
|
|
328
324
|
counters: CounterStore,
|
|
329
325
|
): Promise<Sentence> {
|
|
330
|
-
const offender = this.zone.offender(member)
|
|
331
326
|
const window = (words.kicksBeforeBanMinutes ?? words.banMinutes) * 60_000
|
|
327
|
+
const strikes = new Strikes(
|
|
328
|
+
'swearing',
|
|
329
|
+
words.warningsBeforeKick,
|
|
330
|
+
words.kicksBeforeBan,
|
|
331
|
+
window,
|
|
332
|
+
)
|
|
332
333
|
|
|
333
|
-
|
|
334
|
-
const warned = await counters.hit(warnings, window)
|
|
335
|
-
if (warned <= words.warningsBeforeKick) return 'warn'
|
|
336
|
-
|
|
337
|
-
await counters.clear(warnings)
|
|
338
|
-
|
|
339
|
-
const kicks = offender.counter('swearing:kicks')
|
|
340
|
-
const kicked = await counters.hit(kicks, window)
|
|
341
|
-
if (kicked <= words.kicksBeforeBan) return 'kick'
|
|
342
|
-
|
|
343
|
-
await counters.clear(kicks)
|
|
344
|
-
return 'ban'
|
|
334
|
+
return strikes.count(counters, this.zone.offender(member))
|
|
345
335
|
}
|
|
346
336
|
|
|
347
337
|
/**
|
|
@@ -32,7 +32,7 @@ export class SmartFox2XCodec extends PacketCodec<object> {
|
|
|
32
32
|
/**
|
|
33
33
|
* What the codec speaks
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
protected override readonly protocol: SmartFox2X
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Bytes of an oversized message still to throw away
|
|
@@ -71,46 +71,29 @@ export class SmartFox2XCodec extends PacketCodec<object> {
|
|
|
71
71
|
* @param context the connection
|
|
72
72
|
* @param message a packet
|
|
73
73
|
*/
|
|
74
|
-
public override write(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
let frame: ByteBuf | null
|
|
79
|
-
try {
|
|
80
|
-
frame = this.frame(context, message)
|
|
81
|
-
} catch (cause) {
|
|
82
|
-
return Promise.reject(new EncoderError('Encoding failed', { cause }))
|
|
74
|
+
public override write(context: HandlerContext, message: unknown): void {
|
|
75
|
+
if (message instanceof ByteBuf || message instanceof Uint8Array) {
|
|
76
|
+
context.write(message)
|
|
77
|
+
return
|
|
83
78
|
}
|
|
84
79
|
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Frames a packet with the connection's key, without a promise
|
|
90
|
-
* @param context the connection
|
|
91
|
-
* @param message a packet
|
|
92
|
-
*/
|
|
93
|
-
public override writeSync(
|
|
94
|
-
context: HandlerContext,
|
|
95
|
-
message: unknown,
|
|
96
|
-
): boolean {
|
|
97
|
-
if (message instanceof ByteBuf) return PacketCodec.pass(context, message)
|
|
98
|
-
|
|
80
|
+
const direct = context.writesToSocket
|
|
99
81
|
let frame: ByteBuf | null
|
|
100
82
|
try {
|
|
101
83
|
frame = this.protocol.pack(
|
|
102
84
|
message,
|
|
103
85
|
SmartFox2XCodec.cipherOf(context.channel),
|
|
104
|
-
|
|
86
|
+
direct,
|
|
105
87
|
)
|
|
106
88
|
} catch (cause) {
|
|
107
89
|
throw new EncoderError('Encoding failed', { cause })
|
|
108
90
|
}
|
|
109
91
|
|
|
110
|
-
if (frame === null)
|
|
111
|
-
if (!
|
|
112
|
-
|
|
113
|
-
|
|
92
|
+
if (frame === null) context.write(message)
|
|
93
|
+
else if (!direct) context.write(frame)
|
|
94
|
+
else if (!this.place(context, frame)) {
|
|
95
|
+
context.write(frame.readBytes(frame.readableBytes))
|
|
96
|
+
}
|
|
114
97
|
}
|
|
115
98
|
|
|
116
99
|
/**
|
|
@@ -165,9 +148,7 @@ export class SmartFox2XCodec extends PacketCodec<object> {
|
|
|
165
148
|
|
|
166
149
|
input.skipBytes(prefix)
|
|
167
150
|
this.dropping = size
|
|
168
|
-
|
|
169
|
-
new DecoderError('Message is too large'),
|
|
170
|
-
)
|
|
151
|
+
context.fireExceptionCaught(new DecoderError('Message is too large'))
|
|
171
152
|
continue
|
|
172
153
|
}
|
|
173
154
|
|
|
@@ -190,14 +171,25 @@ export class SmartFox2XCodec extends PacketCodec<object> {
|
|
|
190
171
|
}
|
|
191
172
|
|
|
192
173
|
/**
|
|
193
|
-
*
|
|
194
|
-
* @param context the
|
|
195
|
-
* @param
|
|
174
|
+
* Copies a frame into the channel's staging slab, false if it won't fit
|
|
175
|
+
* @param context next to the socket
|
|
176
|
+
* @param frame a whole frame
|
|
196
177
|
*/
|
|
197
|
-
private
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
178
|
+
private place(context: HandlerContext, frame: ByteBuf): boolean {
|
|
179
|
+
const channel = context.channel
|
|
180
|
+
const size = frame.readableBytes
|
|
181
|
+
const offset = channel.reserve(size)
|
|
182
|
+
if (offset < 0) return false
|
|
183
|
+
|
|
184
|
+
ByteBuf.copyBytes(
|
|
185
|
+
frame.array,
|
|
186
|
+
frame.arrayOffset + frame.readerIndex,
|
|
187
|
+
channel.stagingBuffer,
|
|
188
|
+
offset,
|
|
189
|
+
size,
|
|
201
190
|
)
|
|
191
|
+
channel.commit()
|
|
192
|
+
|
|
193
|
+
return true
|
|
202
194
|
}
|
|
203
195
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Logger } from '@netifyjs/netify'
|
|
2
2
|
|
|
3
|
-
import type { CounterStore } from '../../
|
|
3
|
+
import type { CounterStore } from '../../common/counters/store/index.ts'
|
|
4
4
|
import type { BanStore } from '../ban/store/index.ts'
|
|
5
5
|
import type { PrivilegeId } from '../entity/privilege/index.ts'
|
|
6
6
|
import type {
|
|
@@ -311,6 +311,11 @@ export type ZoneConfig = {
|
|
|
311
311
|
*/
|
|
312
312
|
readonly maxJoinedRooms?: number
|
|
313
313
|
|
|
314
|
+
/**
|
|
315
|
+
* Invitations one user may have waiting for an answer, 20 by default
|
|
316
|
+
*/
|
|
317
|
+
readonly maxInvitations?: number
|
|
318
|
+
|
|
314
319
|
/**
|
|
315
320
|
* Every group clients may subscribe to
|
|
316
321
|
*/
|
|
@@ -8,14 +8,20 @@ import { DataType, type DataTypeId } from '../type/index.ts'
|
|
|
8
8
|
*/
|
|
9
9
|
export class SfsArray {
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Wire type of each value
|
|
12
12
|
*/
|
|
13
|
-
private readonly
|
|
13
|
+
private readonly types: DataTypeId[]
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Values by position, in step with the types
|
|
17
|
+
*/
|
|
18
|
+
private readonly values: SfsData[]
|
|
14
19
|
|
|
15
20
|
/**
|
|
16
21
|
* Starts empty
|
|
17
22
|
*/
|
|
18
23
|
private constructor() {
|
|
24
|
+
this.types = []
|
|
19
25
|
this.values = []
|
|
20
26
|
}
|
|
21
27
|
|
|
@@ -30,7 +36,7 @@ export class SfsArray {
|
|
|
30
36
|
* How many values it holds
|
|
31
37
|
*/
|
|
32
38
|
public get size(): number {
|
|
33
|
-
return this.
|
|
39
|
+
return this.types.length
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
/**
|
|
@@ -38,16 +44,35 @@ export class SfsArray {
|
|
|
38
44
|
* @param index position to look at
|
|
39
45
|
*/
|
|
40
46
|
public isNull(index: number): boolean {
|
|
41
|
-
const
|
|
47
|
+
const type = this.types[index]
|
|
42
48
|
|
|
43
|
-
return
|
|
49
|
+
return type === undefined || type === DataType.NULL
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
/**
|
|
47
53
|
* Every value with its wire type, in order
|
|
48
54
|
*/
|
|
49
|
-
public entries(): IterableIterator<SfsEntry> {
|
|
50
|
-
|
|
55
|
+
public *entries(): IterableIterator<SfsEntry> {
|
|
56
|
+
const types = this.types
|
|
57
|
+
for (let at = 0; at < types.length; at++) {
|
|
58
|
+
yield { type: types[at] ?? DataType.NULL, value: this.values[at] ?? null }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The wire type at a position, or null
|
|
64
|
+
* @param index position to look at
|
|
65
|
+
*/
|
|
66
|
+
public typeAt(index: number): DataTypeId | null {
|
|
67
|
+
return this.types[index] ?? null
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The value at a position, or null
|
|
72
|
+
* @param index position to look at
|
|
73
|
+
*/
|
|
74
|
+
public valueAt(index: number): SfsData {
|
|
75
|
+
return this.values[index] ?? null
|
|
51
76
|
}
|
|
52
77
|
|
|
53
78
|
/**
|
|
@@ -55,7 +80,10 @@ export class SfsArray {
|
|
|
55
80
|
* @param index position to look at
|
|
56
81
|
*/
|
|
57
82
|
public entry(index: number): SfsEntry | null {
|
|
58
|
-
|
|
83
|
+
const type = this.types[index]
|
|
84
|
+
if (type === undefined) return null
|
|
85
|
+
|
|
86
|
+
return { type, value: this.values[index] ?? null }
|
|
59
87
|
}
|
|
60
88
|
|
|
61
89
|
/**
|
|
@@ -64,7 +92,8 @@ export class SfsArray {
|
|
|
64
92
|
* @param value what to store
|
|
65
93
|
*/
|
|
66
94
|
public add(type: DataTypeId, value: SfsData): this {
|
|
67
|
-
this.
|
|
95
|
+
this.types.push(type)
|
|
96
|
+
this.values.push(value)
|
|
68
97
|
|
|
69
98
|
return this
|
|
70
99
|
}
|
|
@@ -241,7 +270,7 @@ export class SfsArray {
|
|
|
241
270
|
* @param index position to look at
|
|
242
271
|
*/
|
|
243
272
|
public getBool(index: number): boolean | null {
|
|
244
|
-
const value = this.
|
|
273
|
+
const value = this.value(index)
|
|
245
274
|
|
|
246
275
|
return typeof value === 'boolean' ? value : null
|
|
247
276
|
}
|
|
@@ -251,7 +280,7 @@ export class SfsArray {
|
|
|
251
280
|
* @param index position to look at
|
|
252
281
|
*/
|
|
253
282
|
public getNumber(index: number): number | null {
|
|
254
|
-
const value = this.
|
|
283
|
+
const value = this.value(index)
|
|
255
284
|
if (typeof value === 'number') return value
|
|
256
285
|
|
|
257
286
|
return typeof value === 'bigint' ? Number(value) : null
|
|
@@ -296,7 +325,7 @@ export class SfsArray {
|
|
|
296
325
|
* @param index position to look at
|
|
297
326
|
*/
|
|
298
327
|
public getLong(index: number): bigint | null {
|
|
299
|
-
const value = this.
|
|
328
|
+
const value = this.value(index)
|
|
300
329
|
if (typeof value === 'bigint') return value
|
|
301
330
|
|
|
302
331
|
return typeof value === 'number' && Number.isInteger(value)
|
|
@@ -325,7 +354,7 @@ export class SfsArray {
|
|
|
325
354
|
* @param index position to look at
|
|
326
355
|
*/
|
|
327
356
|
public getUtfString(index: number): string | null {
|
|
328
|
-
const value = this.
|
|
357
|
+
const value = this.value(index)
|
|
329
358
|
|
|
330
359
|
return typeof value === 'string' ? value : null
|
|
331
360
|
}
|
|
@@ -343,11 +372,10 @@ export class SfsArray {
|
|
|
343
372
|
* @param index position to look at
|
|
344
373
|
*/
|
|
345
374
|
public getBoolArray(index: number): readonly boolean[] | null {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
: null
|
|
375
|
+
return (
|
|
376
|
+
(this.typed(index, DataType.BOOL_ARRAY) as
|
|
377
|
+
readonly boolean[] | undefined) ?? null
|
|
378
|
+
)
|
|
351
379
|
}
|
|
352
380
|
|
|
353
381
|
/**
|
|
@@ -355,11 +383,9 @@ export class SfsArray {
|
|
|
355
383
|
* @param index position to look at
|
|
356
384
|
*/
|
|
357
385
|
public getByteArray(index: number): Uint8Array | null {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
? (entry.value as Uint8Array)
|
|
362
|
-
: null
|
|
386
|
+
return (
|
|
387
|
+
(this.typed(index, DataType.BYTE_ARRAY) as Uint8Array | undefined) ?? null
|
|
388
|
+
)
|
|
363
389
|
}
|
|
364
390
|
|
|
365
391
|
/**
|
|
@@ -367,11 +393,10 @@ export class SfsArray {
|
|
|
367
393
|
* @param index position to look at
|
|
368
394
|
*/
|
|
369
395
|
public getShortArray(index: number): readonly number[] | null {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
: null
|
|
396
|
+
return (
|
|
397
|
+
(this.typed(index, DataType.SHORT_ARRAY) as
|
|
398
|
+
readonly number[] | undefined) ?? null
|
|
399
|
+
)
|
|
375
400
|
}
|
|
376
401
|
|
|
377
402
|
/**
|
|
@@ -379,11 +404,10 @@ export class SfsArray {
|
|
|
379
404
|
* @param index position to look at
|
|
380
405
|
*/
|
|
381
406
|
public getIntArray(index: number): readonly number[] | null {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
: null
|
|
407
|
+
return (
|
|
408
|
+
(this.typed(index, DataType.INT_ARRAY) as
|
|
409
|
+
readonly number[] | undefined) ?? null
|
|
410
|
+
)
|
|
387
411
|
}
|
|
388
412
|
|
|
389
413
|
/**
|
|
@@ -391,11 +415,10 @@ export class SfsArray {
|
|
|
391
415
|
* @param index position to look at
|
|
392
416
|
*/
|
|
393
417
|
public getLongArray(index: number): readonly bigint[] | null {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
: null
|
|
418
|
+
return (
|
|
419
|
+
(this.typed(index, DataType.LONG_ARRAY) as
|
|
420
|
+
readonly bigint[] | undefined) ?? null
|
|
421
|
+
)
|
|
399
422
|
}
|
|
400
423
|
|
|
401
424
|
/**
|
|
@@ -403,11 +426,10 @@ export class SfsArray {
|
|
|
403
426
|
* @param index position to look at
|
|
404
427
|
*/
|
|
405
428
|
public getFloatArray(index: number): readonly number[] | null {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
: null
|
|
429
|
+
return (
|
|
430
|
+
(this.typed(index, DataType.FLOAT_ARRAY) as
|
|
431
|
+
readonly number[] | undefined) ?? null
|
|
432
|
+
)
|
|
411
433
|
}
|
|
412
434
|
|
|
413
435
|
/**
|
|
@@ -415,11 +437,10 @@ export class SfsArray {
|
|
|
415
437
|
* @param index position to look at
|
|
416
438
|
*/
|
|
417
439
|
public getDoubleArray(index: number): readonly number[] | null {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
: null
|
|
440
|
+
return (
|
|
441
|
+
(this.typed(index, DataType.DOUBLE_ARRAY) as
|
|
442
|
+
readonly number[] | undefined) ?? null
|
|
443
|
+
)
|
|
423
444
|
}
|
|
424
445
|
|
|
425
446
|
/**
|
|
@@ -427,11 +448,10 @@ export class SfsArray {
|
|
|
427
448
|
* @param index position to look at
|
|
428
449
|
*/
|
|
429
450
|
public getUtfStringArray(index: number): readonly string[] | null {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
: null
|
|
451
|
+
return (
|
|
452
|
+
(this.typed(index, DataType.UTF_STRING_ARRAY) as
|
|
453
|
+
readonly string[] | undefined) ?? null
|
|
454
|
+
)
|
|
435
455
|
}
|
|
436
456
|
|
|
437
457
|
/**
|
|
@@ -439,9 +459,9 @@ export class SfsArray {
|
|
|
439
459
|
* @param index position to look at
|
|
440
460
|
*/
|
|
441
461
|
public getSfsArray(index: number): SfsArray | null {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
462
|
+
return (
|
|
463
|
+
(this.typed(index, DataType.SFS_ARRAY) as SfsArray | undefined) ?? null
|
|
464
|
+
)
|
|
445
465
|
}
|
|
446
466
|
|
|
447
467
|
/**
|
|
@@ -449,11 +469,10 @@ export class SfsArray {
|
|
|
449
469
|
* @param index position to look at
|
|
450
470
|
*/
|
|
451
471
|
public getSfsObject(index: number): SfsObject | null {
|
|
452
|
-
const
|
|
453
|
-
if (entry === undefined) return null
|
|
472
|
+
const type = this.types[index]
|
|
454
473
|
|
|
455
|
-
return
|
|
456
|
-
? (
|
|
474
|
+
return type === DataType.SFS_OBJECT || type === DataType.CLASS
|
|
475
|
+
? (this.values[index] as SfsObject)
|
|
457
476
|
: null
|
|
458
477
|
}
|
|
459
478
|
|
|
@@ -464,4 +483,21 @@ export class SfsArray {
|
|
|
464
483
|
public getClass(index: number): SfsObject | null {
|
|
465
484
|
return this.getSfsObject(index)
|
|
466
485
|
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* The value at a position, or nothing
|
|
489
|
+
* @param index position to look at
|
|
490
|
+
*/
|
|
491
|
+
private value(index: number): SfsData | undefined {
|
|
492
|
+
return this.values[index]
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* The value at a position if it has the wire type asked for, or nothing
|
|
497
|
+
* @param index position to look at
|
|
498
|
+
* @param type wire type it has to be
|
|
499
|
+
*/
|
|
500
|
+
private typed(index: number, type: DataTypeId): SfsData | undefined {
|
|
501
|
+
return this.types[index] === type ? this.values[index] : undefined
|
|
502
|
+
}
|
|
467
503
|
}
|