@sanctumterra/raknet 1.3.79 → 1.4.0
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/README.md +1 -1
- package/dist/client/client.d.ts +19 -24
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +135 -278
- package/dist/client/index.d.ts +1 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -2
- package/dist/client/types/client-events.d.ts +8 -0
- package/dist/client/types/client-events.d.ts.map +1 -0
- package/dist/client/types/client-options.d.ts +12 -0
- package/dist/client/types/client-options.d.ts.map +1 -0
- package/dist/client/types/client-options.js +14 -0
- package/dist/client/types/index.d.ts +3 -0
- package/dist/client/types/index.d.ts.map +1 -0
- package/dist/{proto/decorators → client/types}/index.js +2 -2
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/server/connection.d.ts +20 -59
- package/dist/server/connection.d.ts.map +1 -1
- package/dist/server/connection.js +53 -365
- package/dist/server/index.d.ts +2 -3
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -3
- package/dist/server/server.d.ts +11 -18
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +98 -137
- package/dist/{proto → server}/types/advertisement.d.ts +1 -1
- package/dist/server/types/advertisement.d.ts.map +1 -0
- package/dist/{proto → server}/types/advertisement.js +14 -10
- package/dist/server/types/connection-events.d.ts +4 -0
- package/dist/server/types/connection-events.d.ts.map +1 -0
- package/dist/server/types/index.d.ts +5 -0
- package/dist/server/types/index.d.ts.map +1 -0
- package/dist/{proto → server}/types/index.js +3 -1
- package/dist/server/types/server-events.d.ts +7 -0
- package/dist/server/types/server-events.d.ts.map +1 -0
- package/dist/server/types/server-options.d.ts +12 -0
- package/dist/server/types/server-options.d.ts.map +1 -0
- package/dist/server/types/server-options.js +14 -0
- package/dist/shared/emitter.d.ts +28 -0
- package/dist/shared/emitter.d.ts.map +1 -0
- package/dist/shared/emitter.js +71 -0
- package/dist/shared/index.d.ts +5 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/{utils → shared}/index.js +4 -1
- package/dist/{utils/Logger.d.ts → shared/logger.d.ts} +1 -1
- package/dist/shared/logger.d.ts.map +1 -0
- package/dist/shared/network_session.d.ts +34 -0
- package/dist/shared/network_session.d.ts.map +1 -0
- package/dist/shared/network_session.js +247 -0
- package/dist/shared/proto/enums/connectionStatus.d.ts +8 -0
- package/dist/shared/proto/enums/connectionStatus.d.ts.map +1 -0
- package/dist/shared/proto/enums/connectionStatus.js +11 -0
- package/dist/shared/proto/enums/index.d.ts +5 -0
- package/dist/shared/proto/enums/index.d.ts.map +1 -0
- package/dist/{proto → shared/proto}/enums/index.js +2 -3
- package/dist/shared/proto/enums/packets.d.ts +19 -0
- package/dist/shared/proto/enums/packets.d.ts.map +1 -0
- package/dist/shared/proto/enums/packets.js +23 -0
- package/dist/shared/proto/enums/priority.d.ts +6 -0
- package/dist/shared/proto/enums/priority.d.ts.map +1 -0
- package/dist/shared/proto/enums/priority.js +4 -0
- package/dist/shared/proto/enums/reliability.d.ts.map +1 -0
- package/dist/shared/proto/index.d.ts +5 -0
- package/dist/shared/proto/index.d.ts.map +1 -0
- package/dist/{proto → shared/proto}/index.js +3 -3
- package/dist/shared/proto/offline/index.d.ts +7 -0
- package/dist/shared/proto/offline/index.d.ts.map +1 -0
- package/dist/shared/proto/offline/index.js +22 -0
- package/dist/shared/proto/offline/open-connection-reply-one.d.ts +9 -0
- package/dist/shared/proto/offline/open-connection-reply-one.d.ts.map +1 -0
- package/dist/shared/proto/offline/open-connection-reply-one.js +28 -0
- package/dist/shared/proto/offline/open-connection-reply-two.d.ts +11 -0
- package/dist/shared/proto/offline/open-connection-reply-two.d.ts.map +1 -0
- package/dist/shared/proto/offline/open-connection-reply-two.js +31 -0
- package/dist/shared/proto/offline/open-connection-request-one.d.ts +8 -0
- package/dist/shared/proto/offline/open-connection-request-one.d.ts.map +1 -0
- package/dist/shared/proto/offline/open-connection-request-one.js +25 -0
- package/dist/shared/proto/offline/open-connection-request-two.d.ts +10 -0
- package/dist/shared/proto/offline/open-connection-request-two.d.ts.map +1 -0
- package/dist/shared/proto/offline/open-connection-request-two.js +28 -0
- package/dist/shared/proto/offline/unconnected-ping.d.ts +8 -0
- package/dist/shared/proto/offline/unconnected-ping.d.ts.map +1 -0
- package/dist/shared/proto/offline/unconnected-ping.js +25 -0
- package/dist/shared/proto/offline/unconnected-pong.d.ts +9 -0
- package/dist/shared/proto/offline/unconnected-pong.d.ts.map +1 -0
- package/dist/shared/proto/offline/unconnected-pong.js +28 -0
- package/dist/shared/proto/online/ack.d.ts +7 -0
- package/dist/shared/proto/online/ack.d.ts.map +1 -0
- package/dist/{proto/packets → shared/proto/online}/ack.js +16 -31
- package/dist/shared/proto/online/connected-ping.d.ts +7 -0
- package/dist/shared/proto/online/connected-ping.d.ts.map +1 -0
- package/dist/shared/proto/online/connected-ping.js +19 -0
- package/dist/shared/proto/online/connected-pong.d.ts +8 -0
- package/dist/shared/proto/online/connected-pong.d.ts.map +1 -0
- package/dist/shared/proto/online/connected-pong.js +22 -0
- package/dist/shared/proto/online/connection-request-accepted.d.ts +12 -0
- package/dist/shared/proto/online/connection-request-accepted.d.ts.map +1 -0
- package/dist/shared/proto/online/connection-request-accepted.js +37 -0
- package/dist/shared/proto/online/connection-request.d.ts +9 -0
- package/dist/shared/proto/online/connection-request.d.ts.map +1 -0
- package/dist/shared/proto/online/connection-request.js +25 -0
- package/dist/shared/proto/online/disconnect-message.d.ts +6 -0
- package/dist/shared/proto/online/disconnect-message.d.ts.map +1 -0
- package/dist/shared/proto/online/disconnect-message.js +15 -0
- package/dist/shared/proto/online/frame-set.d.ts +9 -0
- package/dist/shared/proto/online/frame-set.d.ts.map +1 -0
- package/dist/shared/proto/online/frame-set.js +23 -0
- package/dist/shared/proto/online/index.d.ts +9 -0
- package/dist/shared/proto/online/index.d.ts.map +1 -0
- package/dist/shared/proto/online/index.js +24 -0
- package/dist/shared/proto/online/new-incomming-connection.d.ts +11 -0
- package/dist/shared/proto/online/new-incomming-connection.d.ts.map +1 -0
- package/dist/shared/proto/online/new-incomming-connection.js +33 -0
- package/dist/shared/proto/types/address.d.ts +12 -0
- package/dist/shared/proto/types/address.d.ts.map +1 -0
- package/dist/shared/proto/types/address.js +61 -0
- package/dist/shared/proto/types/frame.d.ts +23 -0
- package/dist/shared/proto/types/frame.d.ts.map +1 -0
- package/dist/shared/proto/types/frame.js +119 -0
- package/dist/{proto/packets → shared/proto}/types/index.d.ts +0 -2
- package/dist/shared/proto/types/index.d.ts.map +1 -0
- package/dist/{proto/packets → shared/proto}/types/index.js +0 -2
- package/dist/shared/proto/types/magic.d.ts +7 -0
- package/dist/shared/proto/types/magic.d.ts.map +1 -0
- package/dist/shared/proto/types/magic.js +15 -0
- package/dist/shared/proto/types/mtu.d.ts +7 -0
- package/dist/shared/proto/types/mtu.d.ts.map +1 -0
- package/dist/shared/proto/types/mtu.js +13 -0
- package/dist/tests/client-connect.d.ts +2 -0
- package/dist/tests/client-connect.d.ts.map +1 -0
- package/dist/tests/client-connect.js +32 -0
- package/dist/tests/client-once.d.ts +2 -0
- package/dist/tests/client-once.d.ts.map +1 -0
- package/dist/tests/client-once.js +11 -0
- package/dist/tests/server-listen.d.ts +2 -0
- package/dist/tests/server-listen.d.ts.map +1 -0
- package/dist/tests/server-listen.js +5 -0
- package/package.json +8 -8
- package/bun.lock +0 -67
- package/dist/client/client-events.d.ts +0 -23
- package/dist/client/client-events.d.ts.map +0 -1
- package/dist/client/client-options.d.ts +0 -13
- package/dist/client/client-options.d.ts.map +0 -1
- package/dist/client/client-options.js +0 -14
- package/dist/client/client_options.d.ts +0 -10
- package/dist/client/client_options.d.ts.map +0 -1
- package/dist/client/client_options.js +0 -11
- package/dist/client/framer.d.ts +0 -56
- package/dist/client/framer.d.ts.map +0 -1
- package/dist/client/framer.js +0 -467
- package/dist/proto/decorators/create.d.ts +0 -8
- package/dist/proto/decorators/create.d.ts.map +0 -1
- package/dist/proto/decorators/create.js +0 -77
- package/dist/proto/decorators/index.d.ts +0 -3
- package/dist/proto/decorators/index.d.ts.map +0 -1
- package/dist/proto/decorators/serialize.d.ts +0 -4
- package/dist/proto/decorators/serialize.d.ts.map +0 -1
- package/dist/proto/decorators/serialize.js +0 -12
- package/dist/proto/enums/flags.d.ts +0 -7
- package/dist/proto/enums/flags.d.ts.map +0 -1
- package/dist/proto/enums/flags.js +0 -10
- package/dist/proto/enums/index.d.ts +0 -6
- package/dist/proto/enums/index.d.ts.map +0 -1
- package/dist/proto/enums/packet.d.ts +0 -122
- package/dist/proto/enums/packet.d.ts.map +0 -1
- package/dist/proto/enums/packet.js +0 -125
- package/dist/proto/enums/priority.d.ts +0 -5
- package/dist/proto/enums/priority.d.ts.map +0 -1
- package/dist/proto/enums/priority.js +0 -8
- package/dist/proto/enums/reliability.d.ts.map +0 -1
- package/dist/proto/enums/status.d.ts +0 -7
- package/dist/proto/enums/status.d.ts.map +0 -1
- package/dist/proto/enums/status.js +0 -10
- package/dist/proto/index.d.ts +0 -5
- package/dist/proto/index.d.ts.map +0 -1
- package/dist/proto/packets/ack.d.ts +0 -10
- package/dist/proto/packets/ack.d.ts.map +0 -1
- package/dist/proto/packets/base-packet.d.ts +0 -26
- package/dist/proto/packets/base-packet.d.ts.map +0 -1
- package/dist/proto/packets/base-packet.js +0 -37
- package/dist/proto/packets/connected-ping.d.ts +0 -5
- package/dist/proto/packets/connected-ping.d.ts.map +0 -1
- package/dist/proto/packets/connected-ping.js +0 -27
- package/dist/proto/packets/connected-pong.d.ts +0 -6
- package/dist/proto/packets/connected-pong.d.ts.map +0 -1
- package/dist/proto/packets/connected-pong.js +0 -32
- package/dist/proto/packets/connection-request-accepted.d.ts +0 -10
- package/dist/proto/packets/connection-request-accepted.d.ts.map +0 -1
- package/dist/proto/packets/connection-request-accepted.js +0 -48
- package/dist/proto/packets/connection-request.d.ts +0 -7
- package/dist/proto/packets/connection-request.d.ts.map +0 -1
- package/dist/proto/packets/connection-request.js +0 -37
- package/dist/proto/packets/disconnect.d.ts +0 -5
- package/dist/proto/packets/disconnect.d.ts.map +0 -1
- package/dist/proto/packets/disconnect.js +0 -17
- package/dist/proto/packets/frame.d.ts +0 -1
- package/dist/proto/packets/frame.d.ts.map +0 -1
- package/dist/proto/packets/frame.js +0 -1
- package/dist/proto/packets/frameset.d.ts +0 -11
- package/dist/proto/packets/frameset.d.ts.map +0 -1
- package/dist/proto/packets/frameset.js +0 -37
- package/dist/proto/packets/incompatible-protocol-version.d.ts +0 -8
- package/dist/proto/packets/incompatible-protocol-version.d.ts.map +0 -1
- package/dist/proto/packets/incompatible-protocol-version.js +0 -38
- package/dist/proto/packets/index.d.ts +0 -19
- package/dist/proto/packets/index.d.ts.map +0 -1
- package/dist/proto/packets/index.js +0 -34
- package/dist/proto/packets/nack.d.ts +0 -8
- package/dist/proto/packets/nack.d.ts.map +0 -1
- package/dist/proto/packets/nack.js +0 -88
- package/dist/proto/packets/new-incoming-connection.d.ts +0 -9
- package/dist/proto/packets/new-incoming-connection.d.ts.map +0 -1
- package/dist/proto/packets/new-incoming-connection.js +0 -43
- package/dist/proto/packets/open-connection-reply-one.d.ts +0 -8
- package/dist/proto/packets/open-connection-reply-one.d.ts.map +0 -1
- package/dist/proto/packets/open-connection-reply-one.js +0 -43
- package/dist/proto/packets/open-connection-reply-two.d.ts +0 -10
- package/dist/proto/packets/open-connection-reply-two.d.ts.map +0 -1
- package/dist/proto/packets/open-connection-reply-two.js +0 -48
- package/dist/proto/packets/open-connection-request-one.d.ts +0 -7
- package/dist/proto/packets/open-connection-request-one.d.ts.map +0 -1
- package/dist/proto/packets/open-connection-request-one.js +0 -38
- package/dist/proto/packets/open-connection-request-two.d.ts +0 -9
- package/dist/proto/packets/open-connection-request-two.d.ts.map +0 -1
- package/dist/proto/packets/open-connection-request-two.js +0 -43
- package/dist/proto/packets/types/address.d.ts +0 -48
- package/dist/proto/packets/types/address.d.ts.map +0 -1
- package/dist/proto/packets/types/address.js +0 -99
- package/dist/proto/packets/types/data-type.d.ts +0 -21
- package/dist/proto/packets/types/data-type.d.ts.map +0 -1
- package/dist/proto/packets/types/data-type.js +0 -29
- package/dist/proto/packets/types/frame.d.ts +0 -23
- package/dist/proto/packets/types/frame.d.ts.map +0 -1
- package/dist/proto/packets/types/frame.js +0 -94
- package/dist/proto/packets/types/index.d.ts.map +0 -1
- package/dist/proto/packets/types/magic.d.ts +0 -7
- package/dist/proto/packets/types/magic.d.ts.map +0 -1
- package/dist/proto/packets/types/magic.js +0 -14
- package/dist/proto/packets/types/mtu.d.ts +0 -9
- package/dist/proto/packets/types/mtu.d.ts.map +0 -1
- package/dist/proto/packets/types/mtu.js +0 -18
- package/dist/proto/packets/types/sys-address.d.ts +0 -11
- package/dist/proto/packets/types/sys-address.d.ts.map +0 -1
- package/dist/proto/packets/types/sys-address.js +0 -32
- package/dist/proto/packets/unconnected-ping.d.ts +0 -7
- package/dist/proto/packets/unconnected-ping.d.ts.map +0 -1
- package/dist/proto/packets/unconnected-ping.js +0 -38
- package/dist/proto/packets/unconnected-pong.d.ts +0 -8
- package/dist/proto/packets/unconnected-pong.d.ts.map +0 -1
- package/dist/proto/packets/unconnected-pong.js +0 -43
- package/dist/proto/types/advertisement.d.ts.map +0 -1
- package/dist/proto/types/index.d.ts +0 -3
- package/dist/proto/types/index.d.ts.map +0 -1
- package/dist/proto/types/valid.d.ts +0 -4
- package/dist/proto/types/valid.d.ts.map +0 -1
- package/dist/server/server-events.d.ts +0 -9
- package/dist/server/server-events.d.ts.map +0 -1
- package/dist/server/server-options.d.ts +0 -26
- package/dist/server/server-options.d.ts.map +0 -1
- package/dist/server/server-options.js +0 -20
- package/dist/tests/client.d.ts +0 -2
- package/dist/tests/client.d.ts.map +0 -1
- package/dist/tests/client.js +0 -15
- package/dist/tests/localhost.d.ts +0 -2
- package/dist/tests/localhost.d.ts.map +0 -1
- package/dist/tests/localhost.js +0 -34
- package/dist/tests/server.d.ts +0 -2
- package/dist/tests/server.d.ts.map +0 -1
- package/dist/tests/server.js +0 -32
- package/dist/tests/test.d.ts +0 -2
- package/dist/tests/test.d.ts.map +0 -1
- package/dist/tests/test.js +0 -49
- package/dist/utils/Logger.d.ts.map +0 -1
- package/dist/utils/decorators.d.ts +0 -2
- package/dist/utils/decorators.d.ts.map +0 -1
- package/dist/utils/decorators.js +0 -17
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.d.ts.map +0 -1
- /package/dist/client/{client-events.js → types/client-events.js} +0 -0
- /package/dist/{proto/types/valid.js → server/types/connection-events.js} +0 -0
- /package/dist/server/{server-events.js → types/server-events.js} +0 -0
- /package/dist/{utils/Logger.js → shared/logger.js} +0 -0
- /package/dist/{proto → shared/proto}/enums/reliability.d.ts +0 -0
- /package/dist/{proto → shared/proto}/enums/reliability.js +0 -0
|
@@ -1,62 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { RemoteInfo } from "node:dgram";
|
|
1
|
+
import { type Ack, EventEmitter, type Frame, type FrameSet, Priority } from "../shared";
|
|
3
2
|
import type { Server } from "./server";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
status: Status;
|
|
24
|
-
private lastUpdate;
|
|
25
|
-
protected readonly receivedFrameSequences: Set<number>;
|
|
26
|
-
protected readonly lostFrameSequences: Set<number>;
|
|
27
|
-
protected lastInputSequence: number;
|
|
28
|
-
protected fragmentsQueue: Map<number, FragmentGroup>;
|
|
29
|
-
private inputOrderIndex;
|
|
30
|
-
protected inputOrderingQueue: Map<number, Map<number, QueuedFrame>>;
|
|
31
|
-
private inputHighestSequenceIndex;
|
|
32
|
-
outputOrderIndex: number[];
|
|
33
|
-
outputSequenceIndex: number[];
|
|
34
|
-
protected outputFrameQueue: Frame[];
|
|
35
|
-
protected outputFramesByteLength: number;
|
|
36
|
-
protected outputSequence: number;
|
|
37
|
-
protected outputSplitIndex: number;
|
|
38
|
-
protected outputReliableIndex: number;
|
|
39
|
-
outputBackup: Map<number, Frame[]>;
|
|
40
|
-
private readonly ORDERING_QUEUE_TIMEOUT;
|
|
41
|
-
constructor(server: Server, remoteInfo: RemoteInfo, guid: bigint, mtu: number);
|
|
42
|
-
tick(): void;
|
|
43
|
-
private handlePackets;
|
|
44
|
-
handle(message: Buffer): void;
|
|
45
|
-
private handleFrameSet;
|
|
46
|
-
private handleFrame;
|
|
47
|
-
private handleSplit;
|
|
48
|
-
private handleOrdered;
|
|
49
|
-
private handleSequenced;
|
|
50
|
-
sendFrame(frame: Frame, priority: Priority): void;
|
|
51
|
-
private handleLargePayload;
|
|
52
|
-
private createSplitFrame;
|
|
53
|
-
private queueFrame;
|
|
54
|
-
sendQueue(amount: number): void;
|
|
55
|
-
frameAndSend(payload: Buffer | BinaryStream, priority: Priority): void;
|
|
56
|
-
send(message: Buffer): void;
|
|
57
|
-
disconnect(timeout?: boolean): void;
|
|
58
|
-
getConnectionTime(type?: "ms" | "s" | "min"): number;
|
|
59
|
-
getAddress(): Address;
|
|
3
|
+
import type { RemoteInfo } from "node:dgram";
|
|
4
|
+
import type { ConnectionEvents } from "./types";
|
|
5
|
+
export declare class Connection extends EventEmitter<ConnectionEvents> {
|
|
6
|
+
private server;
|
|
7
|
+
private rinfo;
|
|
8
|
+
private mtu;
|
|
9
|
+
private guid;
|
|
10
|
+
private session;
|
|
11
|
+
constructor(server: Server, rinfo: RemoteInfo, mtu: number, guid: bigint);
|
|
12
|
+
onTick(tick: number): void;
|
|
13
|
+
onFrameSet(frameSet: FrameSet): void;
|
|
14
|
+
getAddress(): RemoteInfo;
|
|
15
|
+
onMessage(data: Buffer): void;
|
|
16
|
+
onAck(message: Ack): void;
|
|
17
|
+
/** Nack Packet is same as Ack just different id's and we do not care about the ids. */
|
|
18
|
+
onNack(message: Ack): void;
|
|
19
|
+
sendFrame(frame: Frame, priority?: Priority): void;
|
|
20
|
+
frameAndSend(payload: Buffer, priority?: Priority): void;
|
|
21
|
+
send(data: Buffer): void;
|
|
60
22
|
}
|
|
61
|
-
export { Connection };
|
|
62
23
|
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/server/connection.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/server/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,GAAG,EAMR,YAAY,EACZ,KAAK,KAAK,EACV,KAAK,QAAQ,EAIb,QAAQ,EACR,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,qBAAa,UAAW,SAAQ,YAAY,CAAC,gBAAgB,CAAC;IAI5D,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,IAAI;IANb,OAAO,CAAC,OAAO,CAAiB;gBAGvB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,UAAU,EACjB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM;IAQd,MAAM,CAAC,IAAI,EAAE,MAAM;IAInB,UAAU,CAAC,QAAQ,EAAE,QAAQ;IAI7B,UAAU,IAAI,UAAU;IAIxB,SAAS,CAAC,IAAI,EAAE,MAAM;IAqDtB,KAAK,CAAC,OAAO,EAAE,GAAG;IAIzB,uFAAuF;IAChF,MAAM,CAAC,OAAO,EAAE,GAAG;IAInB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,GAAE,QAAwB;IAI1D,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAE,QAAwB;IAIhE,IAAI,CAAC,IAAI,EAAE,MAAM;CAGxB"}
|
|
@@ -1,400 +1,88 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.Connection = void 0;
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const utils_1 = require("../utils");
|
|
10
|
-
const binarystream_1 = require("@serenityjs/binarystream");
|
|
11
|
-
const disconnect_1 = __importDefault(require("../proto/packets/disconnect"));
|
|
12
|
-
class Connection extends emitter_1.default {
|
|
4
|
+
const shared_1 = require("../shared");
|
|
5
|
+
class Connection extends shared_1.EventEmitter {
|
|
13
6
|
server;
|
|
14
|
-
|
|
15
|
-
guid;
|
|
7
|
+
rinfo;
|
|
16
8
|
mtu;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
lostFrameSequences = new Set();
|
|
21
|
-
lastInputSequence = -1;
|
|
22
|
-
fragmentsQueue = new Map();
|
|
23
|
-
inputOrderIndex = new Array(64).fill(0);
|
|
24
|
-
inputOrderingQueue = new Map();
|
|
25
|
-
inputHighestSequenceIndex = new Array(64).fill(0);
|
|
26
|
-
outputOrderIndex;
|
|
27
|
-
outputSequenceIndex;
|
|
28
|
-
outputFrameQueue = [];
|
|
29
|
-
outputFramesByteLength = 0;
|
|
30
|
-
outputSequence = 0;
|
|
31
|
-
outputSplitIndex = 0;
|
|
32
|
-
outputReliableIndex = 0;
|
|
33
|
-
outputBackup = new Map();
|
|
34
|
-
ORDERING_QUEUE_TIMEOUT = 500;
|
|
35
|
-
constructor(server, remoteInfo, guid, mtu) {
|
|
9
|
+
guid;
|
|
10
|
+
session;
|
|
11
|
+
constructor(server, rinfo, mtu, guid) {
|
|
36
12
|
super();
|
|
37
13
|
this.server = server;
|
|
38
|
-
this.
|
|
39
|
-
this.guid = guid;
|
|
14
|
+
this.rinfo = rinfo;
|
|
40
15
|
this.mtu = mtu;
|
|
41
|
-
this.
|
|
42
|
-
this.
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
45
|
-
for (let i = 0; i < 64; i++) {
|
|
46
|
-
this.inputOrderingQueue.set(i, new Map());
|
|
47
|
-
}
|
|
16
|
+
this.guid = guid;
|
|
17
|
+
this.session = new shared_1.NetworkSession(this.mtu);
|
|
18
|
+
this.session.send = this.send.bind(this);
|
|
19
|
+
this.session.handle = this.onMessage.bind(this);
|
|
48
20
|
}
|
|
49
|
-
tick
|
|
50
|
-
|
|
51
|
-
utils_1.Logger.debug(`[Connection] Time since last update: ${now - this.lastUpdate} ms`);
|
|
52
|
-
if (now - this.lastUpdate > this.server.options.connectionTimeout) {
|
|
53
|
-
utils_1.Logger.warn(`Connection to ${this.remoteInfo.address}:${this.remoteInfo.port} timed out`);
|
|
54
|
-
this.server.deleteConnection(`${this.remoteInfo.address}:${this.remoteInfo.port}`);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (this.receivedFrameSequences.size > 0) {
|
|
58
|
-
const ack = new proto_1.Ack();
|
|
59
|
-
ack.sequences = Array.from(this.receivedFrameSequences);
|
|
60
|
-
this.receivedFrameSequences.clear();
|
|
61
|
-
this.send(ack.serialize());
|
|
62
|
-
}
|
|
63
|
-
if (this.lostFrameSequences.size > 0) {
|
|
64
|
-
const nack = new proto_1.Nack();
|
|
65
|
-
nack.sequences = Array.from(this.lostFrameSequences);
|
|
66
|
-
this.lostFrameSequences.clear();
|
|
67
|
-
this.send(nack.serialize());
|
|
68
|
-
}
|
|
69
|
-
for (let channel = 0; channel < 64; channel++) {
|
|
70
|
-
const queue = this.inputOrderingQueue.get(channel);
|
|
71
|
-
if (!queue)
|
|
72
|
-
continue;
|
|
73
|
-
const expectedIndex = this.inputOrderIndex[channel];
|
|
74
|
-
if (queue.has(expectedIndex)) {
|
|
75
|
-
const queued = queue.get(expectedIndex);
|
|
76
|
-
if (queued && now - queued.timestamp > this.ORDERING_QUEUE_TIMEOUT) {
|
|
77
|
-
utils_1.Logger.warn(`[Connection] Timeout waiting for ordered frame ${expectedIndex} on channel ${channel}; processing it to unblock.`);
|
|
78
|
-
this.handlePackets(queued.frame.payload);
|
|
79
|
-
queue.delete(expectedIndex);
|
|
80
|
-
this.inputOrderIndex[channel] = expectedIndex + 1;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
this.sendQueue(this.outputFrameQueue.length);
|
|
21
|
+
onTick(tick) {
|
|
22
|
+
this.session.onTick(tick);
|
|
85
23
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
accepted
|
|
98
|
-
accepted.
|
|
24
|
+
onFrameSet(frameSet) {
|
|
25
|
+
this.session.onFrameSet(frameSet);
|
|
26
|
+
}
|
|
27
|
+
getAddress() {
|
|
28
|
+
return this.rinfo;
|
|
29
|
+
}
|
|
30
|
+
onMessage(data) {
|
|
31
|
+
const id = data[0];
|
|
32
|
+
switch (id) {
|
|
33
|
+
case shared_1.Packets.ConnectionRequest: {
|
|
34
|
+
const request = new shared_1.ConnectionRequest(data).deserialize();
|
|
35
|
+
const accepted = new shared_1.ConnectionRequestAccepted();
|
|
36
|
+
accepted.address = new shared_1.Address(this.rinfo.address, this.rinfo.port, this.rinfo.family === "IPv4" ? 4 : 6);
|
|
37
|
+
// 20 addresses
|
|
38
|
+
accepted.addresses = Array().fill(new shared_1.Address("0.0.0.0", this.server.options.port, 4), 0, 20);
|
|
39
|
+
accepted.requestTimestamp = request.timestamp;
|
|
99
40
|
accepted.systemIndex = 0;
|
|
100
|
-
|
|
41
|
+
accepted.timestamp = BigInt(Date.now());
|
|
42
|
+
this.session.frameAndSend(accepted.serialize(), shared_1.Priority.High);
|
|
101
43
|
break;
|
|
102
44
|
}
|
|
103
|
-
case
|
|
104
|
-
const packet = new proto_1.NewIncomingConnection(message).deserialize();
|
|
105
|
-
if (packet.serverAddress.port !== this.server.options.port) {
|
|
106
|
-
this.disconnect();
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
this.status = proto_1.Status.Connected;
|
|
110
|
-
const startTime = this.server.connectionTimes.get(`${this.remoteInfo.address}:${this.remoteInfo.port}`);
|
|
111
|
-
if (startTime) {
|
|
112
|
-
const latency = Date.now() - startTime;
|
|
113
|
-
this.server.connectionTimes.set(`${this.remoteInfo.address}:${this.remoteInfo.port}`, latency);
|
|
114
|
-
}
|
|
45
|
+
case shared_1.Packets.NewIncomingConnection: {
|
|
115
46
|
this.server.emit("connect", this);
|
|
116
47
|
break;
|
|
117
48
|
}
|
|
118
|
-
case
|
|
119
|
-
|
|
120
|
-
const pong = new proto_1.ConnectedPong();
|
|
121
|
-
pong.pongTime = BigInt(Date.now());
|
|
122
|
-
pong.pingTime = connectedPing.timestamp;
|
|
123
|
-
this.frameAndSend(pong.serialize(), proto_1.Priority.Immediate);
|
|
49
|
+
case shared_1.Packets.Disconnect: {
|
|
50
|
+
this.server.emit("disconnect", this);
|
|
124
51
|
break;
|
|
125
52
|
}
|
|
126
|
-
case
|
|
127
|
-
|
|
128
|
-
|
|
53
|
+
case shared_1.Packets.ConnectedPing: {
|
|
54
|
+
const ping = new shared_1.ConnectedPing(data).deserialize();
|
|
55
|
+
const pong = new shared_1.ConnectedPong();
|
|
56
|
+
pong.pingTimestamp = ping.timestamp;
|
|
57
|
+
pong.pongTimestamp = BigInt(Date.now());
|
|
58
|
+
this.session.frameAndSend(pong.serialize(), shared_1.Priority.High);
|
|
129
59
|
break;
|
|
130
60
|
}
|
|
131
61
|
case 254: {
|
|
132
|
-
this.
|
|
133
|
-
this.emit("encapsulated", message);
|
|
62
|
+
this.emit("encapsulated", data);
|
|
134
63
|
break;
|
|
135
64
|
}
|
|
136
65
|
default: {
|
|
137
|
-
|
|
66
|
+
shared_1.Logger.warn(`Unknown packet received ${id} - `, data.slice(0, 25));
|
|
138
67
|
break;
|
|
139
68
|
}
|
|
140
69
|
}
|
|
141
70
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return;
|
|
145
|
-
this.lastUpdate = Date.now();
|
|
146
|
-
let packetId = message[0];
|
|
147
|
-
if ((packetId & 0xf0) === 0x80)
|
|
148
|
-
packetId = 0x80;
|
|
149
|
-
switch (packetId) {
|
|
150
|
-
case proto_1.Packet.FrameSet: {
|
|
151
|
-
const frameset = new proto_1.Frameset(message).deserialize();
|
|
152
|
-
utils_1.Logger.debug(`Received FrameSet from ${this.remoteInfo.address}:${this.remoteInfo.port} with sequence ${frameset.sequence}`);
|
|
153
|
-
this.handleFrameSet(frameset);
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
case proto_1.Packet.Ack: {
|
|
157
|
-
const ack = new proto_1.Ack(message).deserialize();
|
|
158
|
-
for (const seq of ack.sequences) {
|
|
159
|
-
this.outputBackup.delete(seq);
|
|
160
|
-
}
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
case proto_1.Packet.Nack: {
|
|
164
|
-
const nack = new proto_1.Nack(message).deserialize();
|
|
165
|
-
for (const seq of nack.sequences) {
|
|
166
|
-
const lostFrames = this.outputBackup.get(seq);
|
|
167
|
-
if (lostFrames && lostFrames.length > 0) {
|
|
168
|
-
for (const lostFrame of lostFrames) {
|
|
169
|
-
this.sendFrame(lostFrame, proto_1.Priority.Immediate);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
default: {
|
|
176
|
-
utils_1.Logger.warn(`Received unknown packet ${packetId} from ${this.remoteInfo.address}:${this.remoteInfo.port}`);
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
71
|
+
onAck(message) {
|
|
72
|
+
this.session.onAck(message);
|
|
180
73
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
this.receivedFrameSequences.has(sequence)) {
|
|
185
|
-
utils_1.Logger.debug(`Skipping FrameSet from ${this.remoteInfo.address}:${this.remoteInfo.port} - sequence ${sequence} (duplicate/old)`);
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
this.lostFrameSequences.delete(sequence);
|
|
189
|
-
if (frameset.sequence < this.lastInputSequence ||
|
|
190
|
-
frameset.sequence === this.lastInputSequence) {
|
|
191
|
-
utils_1.Logger.debug(`Out of order Frameset from ${this.remoteInfo.address}:${this.remoteInfo.port}`);
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
this.receivedFrameSequences.add(sequence);
|
|
195
|
-
if (frameset.sequence - this.lastInputSequence > 1) {
|
|
196
|
-
for (let index = this.lastInputSequence + 1; index < frameset.sequence; index++)
|
|
197
|
-
this.lostFrameSequences.add(index);
|
|
198
|
-
}
|
|
199
|
-
this.lastInputSequence = sequence;
|
|
200
|
-
for (let i = 0, len = frameset.frames.length; i < len; i++) {
|
|
201
|
-
this.handleFrame(frameset.frames[i]);
|
|
202
|
-
}
|
|
74
|
+
/** Nack Packet is same as Ack just different id's and we do not care about the ids. */
|
|
75
|
+
onNack(message) {
|
|
76
|
+
this.session.onNack(message);
|
|
203
77
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
this.handleSplit(frame);
|
|
207
|
-
}
|
|
208
|
-
else if (frame.isSequenced) {
|
|
209
|
-
this.handleSequenced(frame);
|
|
210
|
-
}
|
|
211
|
-
else if (frame.isOrdered) {
|
|
212
|
-
this.handleOrdered(frame);
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
this.handlePackets(frame.payload);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
handleSplit(frame) {
|
|
219
|
-
const splitId = frame.splitId;
|
|
220
|
-
let group = this.fragmentsQueue.get(splitId);
|
|
221
|
-
if (!group) {
|
|
222
|
-
group = { fragments: new Map(), timestamp: Date.now() };
|
|
223
|
-
this.fragmentsQueue.set(splitId, group);
|
|
224
|
-
}
|
|
225
|
-
group.fragments.set(frame.splitFrameIndex, frame);
|
|
226
|
-
if (group.fragments.size === frame.splitCount) {
|
|
227
|
-
let totalSize = 0;
|
|
228
|
-
for (let i = 0; i < frame.splitCount; i++) {
|
|
229
|
-
const sframe = group.fragments.get(i);
|
|
230
|
-
if (!sframe) {
|
|
231
|
-
utils_1.Logger.error(`Missing fragment at index ${i} for splitId=${splitId}`);
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
totalSize += sframe.payload.length;
|
|
235
|
-
}
|
|
236
|
-
const buffer = Buffer.allocUnsafe(totalSize);
|
|
237
|
-
let offset = 0;
|
|
238
|
-
for (let i = 0; i < frame.splitCount; i++) {
|
|
239
|
-
const sframe = group.fragments.get(i);
|
|
240
|
-
if (sframe) {
|
|
241
|
-
sframe.payload.copy(buffer, offset);
|
|
242
|
-
offset += sframe.payload.length;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
const reassembledFrame = new proto_1.Frame();
|
|
246
|
-
reassembledFrame.reliability = frame.reliability;
|
|
247
|
-
reassembledFrame.reliableFrameIndex = frame.reliableFrameIndex;
|
|
248
|
-
reassembledFrame.sequenceFrameIndex = frame.sequenceFrameIndex;
|
|
249
|
-
reassembledFrame.orderedFrameIndex = frame.orderedFrameIndex;
|
|
250
|
-
reassembledFrame.orderChannel = frame.orderChannel;
|
|
251
|
-
reassembledFrame.payload = buffer;
|
|
252
|
-
this.fragmentsQueue.delete(splitId);
|
|
253
|
-
this.handleFrame(reassembledFrame);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
handleOrdered(frame) {
|
|
257
|
-
const channel = frame.orderChannel;
|
|
258
|
-
const expectedIndex = this.inputOrderIndex[channel];
|
|
259
|
-
const frameIndex = frame.orderedFrameIndex;
|
|
260
|
-
if (frameIndex === expectedIndex) {
|
|
261
|
-
this.handlePackets(frame.payload);
|
|
262
|
-
this.inputOrderIndex[channel] = frameIndex + 1;
|
|
263
|
-
this.inputHighestSequenceIndex[channel] = 0;
|
|
264
|
-
const queue = this.inputOrderingQueue.get(channel);
|
|
265
|
-
if (queue) {
|
|
266
|
-
let nextIndex = frameIndex + 1;
|
|
267
|
-
while (queue.has(nextIndex)) {
|
|
268
|
-
const queued = queue.get(nextIndex);
|
|
269
|
-
if (queued) {
|
|
270
|
-
this.handlePackets(queued.frame.payload);
|
|
271
|
-
queue.delete(nextIndex);
|
|
272
|
-
nextIndex++;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
this.inputOrderIndex[channel] = nextIndex;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
else if (frameIndex > expectedIndex) {
|
|
279
|
-
const queue = this.inputOrderingQueue.get(channel);
|
|
280
|
-
if (queue) {
|
|
281
|
-
queue.set(frameIndex, { frame, timestamp: Date.now() });
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
handleSequenced(frame) {
|
|
286
|
-
const channel = frame.orderChannel;
|
|
287
|
-
const newSequence = frame.sequenceFrameIndex;
|
|
288
|
-
const currentHighest = this.inputHighestSequenceIndex[channel];
|
|
289
|
-
if (newSequence >= currentHighest &&
|
|
290
|
-
frame.orderedFrameIndex >= this.inputOrderIndex[channel]) {
|
|
291
|
-
this.inputHighestSequenceIndex[channel] = newSequence + 1;
|
|
292
|
-
this.handlePackets(frame.payload);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
sendFrame(frame, priority) {
|
|
296
|
-
const channel = frame.orderChannel;
|
|
297
|
-
if (frame.isSequenced) {
|
|
298
|
-
frame.orderedFrameIndex = this.outputOrderIndex[channel];
|
|
299
|
-
frame.sequenceFrameIndex = this.outputSequenceIndex[channel]++;
|
|
300
|
-
}
|
|
301
|
-
else if (frame.isOrdered) {
|
|
302
|
-
frame.orderedFrameIndex = this.outputOrderIndex[channel]++;
|
|
303
|
-
this.outputSequenceIndex[channel] = 0;
|
|
304
|
-
}
|
|
305
|
-
const payloadSize = frame.payload.byteLength;
|
|
306
|
-
const maxSize = this.mtu - 36;
|
|
307
|
-
if (payloadSize > maxSize) {
|
|
308
|
-
const splitSize = Math.ceil(payloadSize / maxSize);
|
|
309
|
-
this.handleLargePayload(frame, maxSize, splitSize);
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
if (frame.isReliable) {
|
|
313
|
-
frame.reliableFrameIndex = this.outputReliableIndex++;
|
|
314
|
-
}
|
|
315
|
-
this.queueFrame(frame, priority);
|
|
316
|
-
}
|
|
317
|
-
handleLargePayload(frame, maxSize, splitSize) {
|
|
318
|
-
const splitId = this.outputSplitIndex++ % 65536;
|
|
319
|
-
for (let index = 0; index < frame.payload.byteLength; index += maxSize) {
|
|
320
|
-
const nframe = this.createSplitFrame(frame, index, maxSize, splitId, splitSize);
|
|
321
|
-
this.queueFrame(nframe, proto_1.Priority.Immediate);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
createSplitFrame(originalFrame, index, maxSize, splitId, splitSize) {
|
|
325
|
-
const nframe = new proto_1.Frame();
|
|
326
|
-
nframe.reliableFrameIndex = this.outputReliableIndex++;
|
|
327
|
-
nframe.sequenceFrameIndex = originalFrame.sequenceFrameIndex;
|
|
328
|
-
nframe.orderedFrameIndex = originalFrame.orderedFrameIndex;
|
|
329
|
-
nframe.orderChannel = originalFrame.orderChannel;
|
|
330
|
-
nframe.reliability = originalFrame.reliability;
|
|
331
|
-
nframe.payload = originalFrame.payload.subarray(index, index + maxSize);
|
|
332
|
-
nframe.splitFrameIndex = index / maxSize;
|
|
333
|
-
nframe.splitId = splitId;
|
|
334
|
-
nframe.splitCount = splitSize;
|
|
335
|
-
return nframe;
|
|
78
|
+
sendFrame(frame, priority = shared_1.Priority.High) {
|
|
79
|
+
this.session.sendFrame(frame, priority);
|
|
336
80
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
utils_1.Logger.debug(`[Connection] Queueing frame (length=${frameLength}). Queue count before push: ${this.outputFrameQueue.length}.`);
|
|
340
|
-
this.outputFrameQueue.push(frame);
|
|
341
|
-
this.outputFramesByteLength += frameLength;
|
|
342
|
-
if (priority === proto_1.Priority.Immediate) {
|
|
343
|
-
utils_1.Logger.debug("[Connection] Immediate frame queued. Flushing output queue.");
|
|
344
|
-
this.sendQueue(this.outputFrameQueue.length);
|
|
345
|
-
}
|
|
81
|
+
frameAndSend(payload, priority = shared_1.Priority.High) {
|
|
82
|
+
this.session.frameAndSend(payload, priority);
|
|
346
83
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
return;
|
|
350
|
-
utils_1.Logger.debug(`[Connection] Flushing output queue: sending ${amount} frame(s), total bytes = ${this.outputFramesByteLength}.`);
|
|
351
|
-
const frameset = new proto_1.Frameset();
|
|
352
|
-
frameset.sequence = this.outputSequence++;
|
|
353
|
-
const framesToSend = this.outputFrameQueue.splice(0, amount);
|
|
354
|
-
let sentLength = 0;
|
|
355
|
-
for (const frame of framesToSend) {
|
|
356
|
-
sentLength += frame.getByteLength();
|
|
357
|
-
}
|
|
358
|
-
this.outputFramesByteLength -= sentLength;
|
|
359
|
-
frameset.frames = framesToSend;
|
|
360
|
-
this.outputBackup.set(frameset.sequence, frameset.frames);
|
|
361
|
-
const serialized = frameset.serialize();
|
|
362
|
-
utils_1.Logger.debug(`[Connection] Sending frameset sequence ${frameset.sequence}, serialized length = ${serialized.byteLength}.`);
|
|
363
|
-
this.send(serialized);
|
|
364
|
-
}
|
|
365
|
-
frameAndSend(payload, priority) {
|
|
366
|
-
const frame = new proto_1.Frame();
|
|
367
|
-
frame.payload =
|
|
368
|
-
payload instanceof binarystream_1.BinaryStream ? payload.getBuffer() : payload;
|
|
369
|
-
frame.reliability = proto_1.Reliability.ReliableOrdered;
|
|
370
|
-
frame.orderChannel = 0;
|
|
371
|
-
this.sendFrame(frame, priority);
|
|
372
|
-
}
|
|
373
|
-
send(message) {
|
|
374
|
-
this.server.send(message, this.remoteInfo);
|
|
375
|
-
}
|
|
376
|
-
disconnect(timeout = true) {
|
|
377
|
-
const disconnect = new disconnect_1.default();
|
|
378
|
-
this.frameAndSend(disconnect.serialize(), proto_1.Priority.Immediate);
|
|
379
|
-
this.status = proto_1.Status.Disconnected;
|
|
380
|
-
if (timeout) {
|
|
381
|
-
setTimeout(() => {
|
|
382
|
-
this.server.deleteConnection(`${this.remoteInfo.address}:${this.remoteInfo.port}`);
|
|
383
|
-
}, 1000);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
getConnectionTime(type = "ms") {
|
|
387
|
-
const time = this.server.connectionTimes.get(`${this.remoteInfo.address}:${this.remoteInfo.port}`) ?? 0;
|
|
388
|
-
if (type === "ms")
|
|
389
|
-
return time;
|
|
390
|
-
if (type === "s")
|
|
391
|
-
return time / 1000;
|
|
392
|
-
if (type === "min")
|
|
393
|
-
return time / 60000;
|
|
394
|
-
return time;
|
|
395
|
-
}
|
|
396
|
-
getAddress() {
|
|
397
|
-
return proto_1.Address.fromIdentifier(this.remoteInfo);
|
|
84
|
+
send(data) {
|
|
85
|
+
this.server.send(data, this.rinfo.address, this.rinfo.port);
|
|
398
86
|
}
|
|
399
87
|
}
|
|
400
88
|
exports.Connection = Connection;
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
package/dist/server/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./server"), exports);
|
|
18
|
-
__exportStar(require("./server-events"), exports);
|
|
19
17
|
__exportStar(require("./connection"), exports);
|
|
20
|
-
__exportStar(require("./server
|
|
18
|
+
__exportStar(require("./server"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
package/dist/server/server.d.ts
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
import { type RemoteInfo } from "node:dgram";
|
|
5
|
-
declare class Server extends Emitter<ServerEvents> {
|
|
6
|
-
options: ServerOptions;
|
|
7
|
-
connectionTimes: Map<string, number>;
|
|
1
|
+
import { EventEmitter } from "../shared";
|
|
2
|
+
import { type Advertisement, type RaknetServerEvents, type RaknetServerOptions } from "./types";
|
|
3
|
+
export declare class Server extends EventEmitter<RaknetServerEvents> {
|
|
8
4
|
private socket;
|
|
5
|
+
readonly options: RaknetServerOptions;
|
|
6
|
+
advertisement: Advertisement;
|
|
9
7
|
private connections;
|
|
10
|
-
private timer;
|
|
11
8
|
private tickCount;
|
|
12
|
-
private
|
|
13
|
-
|
|
14
|
-
private readonly validFlagsMask;
|
|
15
|
-
constructor(options: Partial<ServerOptions>);
|
|
16
|
-
start(): Promise<void>;
|
|
9
|
+
private tickInterval;
|
|
10
|
+
constructor(options?: Partial<RaknetServerOptions>);
|
|
17
11
|
tick(): void;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
listen(): void;
|
|
13
|
+
private onDisconnect;
|
|
14
|
+
private onMessage;
|
|
15
|
+
send(buffer: Buffer, address: string, port: number): void;
|
|
22
16
|
}
|
|
23
|
-
export { Server };
|
|
24
17
|
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,YAAY,EAQZ,MAAM,WAAW,CAAC;AAEnB,OAAO,EACN,KAAK,aAAa,EAElB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EAExB,MAAM,SAAS,CAAC;AAGjB,qBAAa,MAAO,SAAQ,YAAY,CAAC,kBAAkB,CAAC;IAC3D,OAAO,CAAC,MAAM,CAAS;IACvB,SAAgB,OAAO,EAAE,mBAAmB,CAAC;IACtC,aAAa,EAAE,aAAa,CAAC;IACpC,OAAO,CAAC,WAAW,CAA0B;IAC7C,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,YAAY,CAAiB;gBAEzB,OAAO,GAAE,OAAO,CAAC,mBAAmB,CAAM;IAuB/C,IAAI;IAOJ,MAAM;IAab,OAAO,CAAC,YAAY;IAYpB,OAAO,CAAC,SAAS;IA6EV,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAGzD"}
|