@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
package/dist/server/server.js
CHANGED
|
@@ -1,169 +1,130 @@
|
|
|
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.Server = void 0;
|
|
7
|
-
const
|
|
8
|
-
const server_options_1 = require("./server-options");
|
|
9
|
-
const node_dgram_1 = require("node:dgram");
|
|
10
|
-
const proto_1 = require("../proto");
|
|
11
|
-
const utils_1 = require("../utils");
|
|
4
|
+
const shared_1 = require("../shared");
|
|
12
5
|
const connection_1 = require("./connection");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
const types_1 = require("./types");
|
|
7
|
+
const node_dgram_1 = require("node:dgram");
|
|
8
|
+
class Server extends shared_1.EventEmitter {
|
|
16
9
|
socket;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
constructor(options) {
|
|
10
|
+
options;
|
|
11
|
+
advertisement;
|
|
12
|
+
connections;
|
|
13
|
+
tickCount;
|
|
14
|
+
tickInterval;
|
|
15
|
+
constructor(options = {}) {
|
|
24
16
|
super();
|
|
25
|
-
this.options = { ...server_options_1.defaultOptions, ...options };
|
|
26
17
|
this.socket = (0, node_dgram_1.createSocket)("udp4");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
18
|
+
this.options = { ...types_1.defaultRaknetServerOptions, ...options };
|
|
19
|
+
this.connections = new Map();
|
|
20
|
+
this.advertisement = {
|
|
21
|
+
gamemode: "Survival",
|
|
22
|
+
guid: this.options.guid,
|
|
23
|
+
maxPlayers: this.options.maxConnections,
|
|
24
|
+
message: this.options.motd,
|
|
25
|
+
playerCount: this.connections.size,
|
|
26
|
+
version: "0",
|
|
27
|
+
protocol: 0,
|
|
28
|
+
serverName: "SanctumTerra Server",
|
|
29
|
+
type: "MCPE",
|
|
30
|
+
};
|
|
31
|
+
this.tickCount = 0;
|
|
32
|
+
this.tickInterval = setInterval(this.tick.bind(this), 1000 / this.options.tickRate);
|
|
36
33
|
}
|
|
37
34
|
tick() {
|
|
38
|
-
this.tickCount++;
|
|
39
35
|
for (const connection of this.connections.values()) {
|
|
40
|
-
connection.
|
|
41
|
-
}
|
|
42
|
-
const currentTime = Date.now();
|
|
43
|
-
// Check every 1s
|
|
44
|
-
if (this.tickCount % this.options.tickRate === 0) {
|
|
45
|
-
for (const [addr, blockTime] of this.blockedConnections) {
|
|
46
|
-
if (blockTime < currentTime) {
|
|
47
|
-
utils_1.Logger.warn(`Unblocking ${addr} for excessive packets`);
|
|
48
|
-
this.blockedConnections.delete(addr);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
this.packetsPerSecond.clear();
|
|
36
|
+
connection.onTick(this.tickCount);
|
|
52
37
|
}
|
|
53
|
-
this.
|
|
38
|
+
this.tickCount++;
|
|
54
39
|
}
|
|
55
|
-
|
|
56
|
-
this.socket.
|
|
40
|
+
listen() {
|
|
41
|
+
this.socket.bind(this.options.port, this.options.address, () => {
|
|
42
|
+
this.emit("listening");
|
|
43
|
+
if (this.options.enableServerLogs) {
|
|
44
|
+
shared_1.Logger.info(`Server listening on ${this.options.address}:${this.options.port}`);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
this.socket.on("message", this.onMessage.bind(this));
|
|
48
|
+
this.on("disconnect", this.onDisconnect.bind(this));
|
|
57
49
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (this.blockedConnections.has(remoteAddr)) {
|
|
65
|
-
return;
|
|
50
|
+
onDisconnect(connection, executedByServer = false) {
|
|
51
|
+
const address = connection.getAddress();
|
|
52
|
+
this.connections.delete(`${address.address}:${address.port}`);
|
|
53
|
+
this.advertisement.playerCount = this.connections.size;
|
|
54
|
+
if (executedByServer) {
|
|
55
|
+
this.emit("disconnect", connection);
|
|
66
56
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (currentPackets > this.options.maxPacketsPerSecond) {
|
|
70
|
-
const blockUntil = Date.now() + this.options.blockTime;
|
|
71
|
-
this.blockedConnections.set(remoteAddr, blockUntil);
|
|
72
|
-
utils_1.Logger.warn(`Blocking ${remoteAddr} for ${this.options.blockTime}ms for excessive packets`);
|
|
73
|
-
return;
|
|
57
|
+
if (this.options.enableServerLogs) {
|
|
58
|
+
shared_1.Logger.info(`Client disconnected ${address.address}:${address.port}`);
|
|
74
59
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
60
|
+
}
|
|
61
|
+
onMessage(message, rinfo) {
|
|
62
|
+
let id = message[0];
|
|
63
|
+
const isOnline = (id & 0xf0) === 0x80;
|
|
64
|
+
if (isOnline)
|
|
65
|
+
id = 0x80;
|
|
66
|
+
switch (id) {
|
|
67
|
+
case shared_1.Packets.UnconnectedPing: {
|
|
68
|
+
const pong = new shared_1.UnconnectedPong();
|
|
69
|
+
pong.guid = this.options.guid;
|
|
70
|
+
pong.message = (0, types_1.AdvertisementToString)(this.advertisement);
|
|
71
|
+
pong.timestamp = BigInt(Date.now());
|
|
72
|
+
this.send(pong.serialize(), rinfo.address, rinfo.port);
|
|
73
|
+
break;
|
|
80
74
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
switch (packetId) {
|
|
88
|
-
case proto_1.Packet.UnconnectedPing: {
|
|
89
|
-
const ping = new proto_1.UnconnectedPing(message).deserialize();
|
|
90
|
-
const pong = new proto_1.UnconnectedPong();
|
|
91
|
-
pong.serverGuid = this.options.guid;
|
|
92
|
-
pong.serverTimestamp = BigInt(Date.now());
|
|
93
|
-
pong.message = (0, proto_1.AdvertisementToString)({
|
|
94
|
-
type: "MCPE",
|
|
95
|
-
gamemode: "Survival",
|
|
96
|
-
maxPlayers: this.options.maxConnections,
|
|
97
|
-
playerCount: this.connections.size,
|
|
98
|
-
protocol: this.options.protocol,
|
|
99
|
-
serverName: this.options.levelName,
|
|
100
|
-
version: this.options.version,
|
|
101
|
-
serverGUID: Number(this.options.guid),
|
|
102
|
-
message: this.options.motd,
|
|
103
|
-
});
|
|
104
|
-
this.socket.send(pong.serialize(), remote.port, remote.address);
|
|
75
|
+
case shared_1.Packets.OpenConnectionRequest1: {
|
|
76
|
+
const reply = new shared_1.OpenConnectionReplyOne();
|
|
77
|
+
reply.guid = this.options.guid;
|
|
78
|
+
reply.mtu = this.options.mtu;
|
|
79
|
+
reply.security = false;
|
|
80
|
+
this.send(reply.serialize(), rinfo.address, rinfo.port);
|
|
105
81
|
break;
|
|
106
82
|
}
|
|
107
|
-
case
|
|
108
|
-
|
|
109
|
-
|
|
83
|
+
case shared_1.Packets.OpenConnectionRequest2: {
|
|
84
|
+
const request = new shared_1.OpenConnectionRequestTwo(message).deserialize();
|
|
85
|
+
const reply = new shared_1.OpenConnectionReplyTwo();
|
|
86
|
+
reply.address = new shared_1.Address("0.0.0.0", 0, 4);
|
|
87
|
+
reply.encryptionEnabled = false;
|
|
88
|
+
reply.guid = this.options.guid;
|
|
89
|
+
reply.mtu = this.options.mtu;
|
|
90
|
+
const connection = new connection_1.Connection(this, rinfo, request.mtu, request.guid);
|
|
91
|
+
this.connections.set(`${rinfo.address}:${rinfo.port}`, connection);
|
|
92
|
+
this.send(reply.serialize(), rinfo.address, rinfo.port);
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case shared_1.Packets.FrameSet: {
|
|
96
|
+
const frameSet = new shared_1.FrameSet(message).deserialize();
|
|
97
|
+
const connection = this.connections.get(`${rinfo.address}:${rinfo.port}`);
|
|
98
|
+
if (!connection) {
|
|
99
|
+
break;
|
|
110
100
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
incompatible.guid = this.options.guid;
|
|
118
|
-
this.socket.send(incompatible.serialize(), remote.port, remote.address);
|
|
101
|
+
connection.onFrameSet(frameSet);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
case shared_1.Packets.Ack: {
|
|
105
|
+
const connection = this.connections.get(`${rinfo.address}:${rinfo.port}`);
|
|
106
|
+
if (!connection) {
|
|
119
107
|
break;
|
|
120
108
|
}
|
|
121
|
-
|
|
122
|
-
const reply = new proto_1.OpenConnectionReplyOne();
|
|
123
|
-
reply.mtu = this.options.mtu;
|
|
124
|
-
reply.serverGuid = this.options.guid;
|
|
125
|
-
reply.serverHasSecurity = false;
|
|
126
|
-
this.socket.send(reply.serialize(), remote.port, remote.address);
|
|
109
|
+
connection.onAck(new shared_1.Ack(message).deserialize());
|
|
127
110
|
break;
|
|
128
111
|
}
|
|
129
|
-
case
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
reply.encryptionEnabled = false;
|
|
136
|
-
reply.serverGuid = this.options.guid;
|
|
137
|
-
this.socket.send(reply.serialize(), remote.port, remote.address);
|
|
138
|
-
const connection = new connection_1.Connection(this, remote, request.clientGuid, request.mtu);
|
|
139
|
-
this.connections.set(`${remote.address}:${remote.port}`, connection);
|
|
112
|
+
case shared_1.Packets.Nack: {
|
|
113
|
+
const connection = this.connections.get(`${rinfo.address}:${rinfo.port}`);
|
|
114
|
+
if (!connection) {
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
connection.onNack(new shared_1.Ack(message).deserialize());
|
|
140
118
|
break;
|
|
141
119
|
}
|
|
142
120
|
default: {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return;
|
|
146
|
-
utils_1.Logger.info(`Received unknown packet: ${packetId}`);
|
|
121
|
+
shared_1.Logger.warn(`Unknown packet type ${id}`);
|
|
122
|
+
break;
|
|
147
123
|
}
|
|
148
124
|
}
|
|
149
125
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (connection) {
|
|
153
|
-
this.emit("closeConnection", connection);
|
|
154
|
-
}
|
|
155
|
-
this.connections.delete(address);
|
|
156
|
-
this.connectionTimes.delete(address);
|
|
157
|
-
}
|
|
158
|
-
close() {
|
|
159
|
-
clearTimeout(this.timer);
|
|
160
|
-
for (const connection of this.connections.values()) {
|
|
161
|
-
connection.disconnect();
|
|
162
|
-
}
|
|
163
|
-
// just wait for all connections to disconnect
|
|
164
|
-
setTimeout(() => {
|
|
165
|
-
this.socket.close();
|
|
166
|
-
}, 200);
|
|
126
|
+
send(buffer, address, port) {
|
|
127
|
+
this.socket.send(buffer, port, address);
|
|
167
128
|
}
|
|
168
129
|
}
|
|
169
130
|
exports.Server = Server;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advertisement.d.ts","sourceRoot":"","sources":["../../../src/server/types/advertisement.ts"],"names":[],"mappings":"AAAA,KAAK,iBAAiB,GAAG,MAAM,GAAG,MAAM,CAAC;AAEzC,UAAU,aAAa;IACtB,IAAI,EAAE,iBAAiB,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,iBAAS,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,CA6BlD;AAED,iBAAS,qBAAqB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAYnE;AAED,OAAO,EAAE,KAAK,aAAa,EAAE,UAAU,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -3,17 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.fromString = fromString;
|
|
4
4
|
exports.AdvertisementToString = AdvertisementToString;
|
|
5
5
|
function fromString(message) {
|
|
6
|
-
const
|
|
6
|
+
const parts = message.split(";");
|
|
7
|
+
if (parts.length < 9) {
|
|
8
|
+
throw new Error(`Invalid advertisement string: expected >=9 fields, got ${parts.length}`);
|
|
9
|
+
}
|
|
10
|
+
const [type, motd, protocol, version, players, maxPlayers, guid, gamemode, serverName,] = parts;
|
|
7
11
|
return {
|
|
8
12
|
type: type,
|
|
9
|
-
|
|
10
|
-
protocol: Number.parseInt(protocol),
|
|
13
|
+
serverName,
|
|
14
|
+
protocol: Number.parseInt(protocol, 10),
|
|
11
15
|
version,
|
|
12
|
-
playerCount: Number.parseInt(players),
|
|
13
|
-
maxPlayers: Number.parseInt(maxPlayers),
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
gamemode
|
|
16
|
+
playerCount: Number.parseInt(players, 10),
|
|
17
|
+
maxPlayers: Number.parseInt(maxPlayers, 10),
|
|
18
|
+
guid: BigInt(guid),
|
|
19
|
+
message: motd,
|
|
20
|
+
gamemode,
|
|
17
21
|
};
|
|
18
22
|
}
|
|
19
23
|
function AdvertisementToString(advertisement) {
|
|
@@ -24,8 +28,8 @@ function AdvertisementToString(advertisement) {
|
|
|
24
28
|
advertisement.version,
|
|
25
29
|
advertisement.playerCount,
|
|
26
30
|
advertisement.maxPlayers,
|
|
27
|
-
advertisement.
|
|
28
|
-
advertisement.serverName,
|
|
31
|
+
Number(advertisement.guid),
|
|
29
32
|
advertisement.gamemode,
|
|
33
|
+
advertisement.serverName,
|
|
30
34
|
].join(";");
|
|
31
35
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-events.d.ts","sourceRoot":"","sources":["../../../src/server/types/connection-events.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC9B,YAAY,EAAE,MAAM,CAAC;CACrB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
|
|
@@ -14,5 +14,7 @@ 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("./
|
|
17
|
+
__exportStar(require("./server-events"), exports);
|
|
18
|
+
__exportStar(require("./server-options"), exports);
|
|
18
19
|
__exportStar(require("./advertisement"), exports);
|
|
20
|
+
__exportStar(require("./connection-events"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-events.d.ts","sourceRoot":"","sources":["../../../src/server/types/server-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,WAAW,kBAAkB;IAClC,SAAS,EAAE,SAAS,CAAC;IACrB,OAAO,EAAE,UAAU,CAAC;IACpB,UAAU,EAAE,UAAU,CAAC;CACvB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type RaknetServerOptions = {
|
|
2
|
+
port: number;
|
|
3
|
+
address: string;
|
|
4
|
+
guid: bigint;
|
|
5
|
+
motd: string;
|
|
6
|
+
maxConnections: number;
|
|
7
|
+
tickRate: number;
|
|
8
|
+
mtu: number;
|
|
9
|
+
enableServerLogs: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare const defaultRaknetServerOptions: RaknetServerOptions;
|
|
12
|
+
//# sourceMappingURL=server-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-options.d.ts","sourceRoot":"","sources":["../../../src/server/types/server-options.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,mBAAmB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,mBASxC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultRaknetServerOptions = void 0;
|
|
4
|
+
const client_1 = require("../../client");
|
|
5
|
+
exports.defaultRaknetServerOptions = {
|
|
6
|
+
port: 19132,
|
|
7
|
+
address: "0.0.0.0",
|
|
8
|
+
guid: (0, client_1.getRandomGuid)(),
|
|
9
|
+
motd: "SanctumTerra",
|
|
10
|
+
maxConnections: 100,
|
|
11
|
+
tickRate: 20,
|
|
12
|
+
mtu: 1492,
|
|
13
|
+
enableServerLogs: true,
|
|
14
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
type EventMapp = Record<string | symbol, any>;
|
|
2
|
+
type EventKey<T extends EventMapp> = Extract<keyof T, string | symbol>;
|
|
3
|
+
type EventReceiver<T> = (params: T) => void;
|
|
4
|
+
interface Emitter<T extends EventMapp> {
|
|
5
|
+
on<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): this;
|
|
6
|
+
off<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): this;
|
|
7
|
+
emit<K extends EventKey<T>>(eventName: K, ...params: T[K] extends void ? [] : [T[K]]): void;
|
|
8
|
+
once<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): this;
|
|
9
|
+
removeAllListeners<K extends EventKey<T>>(eventName?: K): this;
|
|
10
|
+
listenerCount<K extends EventKey<T>>(eventName: K): number;
|
|
11
|
+
listeners<K extends EventKey<T>>(eventName: K): EventReceiver<T[K]>[];
|
|
12
|
+
hasListener<K extends EventKey<T>>(eventName: K, fn?: EventReceiver<T[K]>): boolean;
|
|
13
|
+
hasAnyListeners<K extends EventKey<T>>(eventName: K): boolean;
|
|
14
|
+
}
|
|
15
|
+
declare class EventEmitter<T extends EventMapp> implements Emitter<T> {
|
|
16
|
+
private events;
|
|
17
|
+
on<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): this;
|
|
18
|
+
off<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): this;
|
|
19
|
+
emit<K extends EventKey<T>>(eventName: K, ...params: T[K] extends void ? [] : [T[K]]): void;
|
|
20
|
+
once<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): this;
|
|
21
|
+
removeAllListeners<K extends EventKey<T>>(eventName?: K): this;
|
|
22
|
+
listenerCount<K extends EventKey<T>>(eventName: K): number;
|
|
23
|
+
listeners<K extends EventKey<T>>(eventName: K): EventReceiver<T[K]>[];
|
|
24
|
+
hasListener<K extends EventKey<T>>(eventName: K, fn?: EventReceiver<T[K]>): boolean;
|
|
25
|
+
hasAnyListeners<K extends EventKey<T>>(eventName: K): boolean;
|
|
26
|
+
}
|
|
27
|
+
export { EventEmitter };
|
|
28
|
+
//# sourceMappingURL=emitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitter.d.ts","sourceRoot":"","sources":["../../src/shared/emitter.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventEmitter = void 0;
|
|
4
|
+
class EventEmitter {
|
|
5
|
+
events = {};
|
|
6
|
+
on(eventName, fn) {
|
|
7
|
+
if (!this.events[eventName]) {
|
|
8
|
+
this.events[eventName] = new Set();
|
|
9
|
+
}
|
|
10
|
+
this.events[eventName]?.add(fn);
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
13
|
+
off(eventName, fn) {
|
|
14
|
+
const eventSet = this.events[eventName];
|
|
15
|
+
if (eventSet) {
|
|
16
|
+
eventSet.delete(fn);
|
|
17
|
+
if (eventSet.size === 0) {
|
|
18
|
+
delete this.events[eventName];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
emit(eventName, ...params) {
|
|
24
|
+
const eventSet = this.events[eventName];
|
|
25
|
+
if (eventSet) {
|
|
26
|
+
for (const fn of eventSet) {
|
|
27
|
+
fn(params[0]);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
once(eventName, fn) {
|
|
32
|
+
const onceWrapper = (params) => {
|
|
33
|
+
this.off(eventName, onceWrapper);
|
|
34
|
+
fn(params);
|
|
35
|
+
};
|
|
36
|
+
this.on(eventName, onceWrapper);
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
removeAllListeners(eventName) {
|
|
40
|
+
if (eventName) {
|
|
41
|
+
delete this.events[eventName];
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.events = {};
|
|
45
|
+
}
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
listenerCount(eventName) {
|
|
49
|
+
const eventSet = this.events[eventName];
|
|
50
|
+
return eventSet ? eventSet.size : 0;
|
|
51
|
+
}
|
|
52
|
+
listeners(eventName) {
|
|
53
|
+
const eventSet = this.events[eventName];
|
|
54
|
+
return eventSet ? Array.from(eventSet) : [];
|
|
55
|
+
}
|
|
56
|
+
hasListener(eventName, fn) {
|
|
57
|
+
const eventSet = this.events[eventName];
|
|
58
|
+
if (!eventSet || eventSet.size === 0) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (fn) {
|
|
62
|
+
return eventSet.has(fn);
|
|
63
|
+
}
|
|
64
|
+
return eventSet.size > 0;
|
|
65
|
+
}
|
|
66
|
+
hasAnyListeners(eventName) {
|
|
67
|
+
const eventSet = this.events[eventName];
|
|
68
|
+
return eventSet ? eventSet.size > 0 : false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.EventEmitter = EventEmitter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
|
@@ -14,4 +14,7 @@ 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("./
|
|
17
|
+
__exportStar(require("./network_session"), exports);
|
|
18
|
+
__exportStar(require("./proto"), exports);
|
|
19
|
+
__exportStar(require("./emitter"), exports);
|
|
20
|
+
__exportStar(require("./logger"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/shared/logger.ts"],"names":[],"mappings":"AAAA,KAAK,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;AAuC/E,QAAA,MAAM,MAAM;;;;;;;;;kBAMG,OAAO,EAAE,GAAG,IAAI;mBAIf,OAAO,EAAE,GAAG,IAAI;kBAIjB,OAAO,EAAE,GAAG,IAAI;mBAIf,OAAO,EAAE,GAAG,IAAI;kBAKjB,OAAO,EAAE,GAAG,IAAI;YAItB,MAAM;iBAOD,OAAO,EAAE,GAAG,IAAI;kBAKf,OAAO,EAAE,GAAG,IAAI;sBAIZ,OAAO,EAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,EAAE;eAmCvC,IAAI;CAKf,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Ack, Frame, FrameSet, Priority } from "./proto";
|
|
2
|
+
export declare class NetworkSession {
|
|
3
|
+
mtu: number;
|
|
4
|
+
send: (data: Buffer) => void;
|
|
5
|
+
handle: (data: Buffer) => void;
|
|
6
|
+
outputReliableIndex: number;
|
|
7
|
+
outputSplitIndex: number;
|
|
8
|
+
protected outputSequence: number;
|
|
9
|
+
outputSequenceIndex: number[];
|
|
10
|
+
outputOrderIndex: number[];
|
|
11
|
+
outputFrames: Set<Frame>;
|
|
12
|
+
outputBackup: Map<number, Frame[]>;
|
|
13
|
+
receivedFrameSequences: Set<number>;
|
|
14
|
+
lostFrameSequences: Set<number>;
|
|
15
|
+
lastInputSequence: number;
|
|
16
|
+
fragmentsQueue: Map<number, Map<number, Frame>>;
|
|
17
|
+
inputHighestSequenceIndex: Array<number>;
|
|
18
|
+
inputOrderIndex: Array<number>;
|
|
19
|
+
protected inputOrderingQueue: Map<number, Map<number, Frame>>;
|
|
20
|
+
constructor(mtu: number);
|
|
21
|
+
onTick(tick: number): void;
|
|
22
|
+
onAck(ack: Ack): void;
|
|
23
|
+
onNack(nack: Ack): void;
|
|
24
|
+
frameAndSend(data: Buffer, priority?: Priority): void;
|
|
25
|
+
sendFrame(frame: Frame, priority?: Priority): void;
|
|
26
|
+
queueFrame(frame: Frame, priority: Priority): void;
|
|
27
|
+
sendQueue(amount: number): void;
|
|
28
|
+
onFrameSet(frameSet: FrameSet): void;
|
|
29
|
+
handleFrame(frame: Frame): void;
|
|
30
|
+
handleSplitFrame(frame: Frame): void;
|
|
31
|
+
handleSequenced(frame: Frame): void;
|
|
32
|
+
handleOrdered(frame: Frame): void;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=network_session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network_session.d.ts","sourceRoot":"","sources":["../../src/shared/network_session.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAW,QAAQ,EAAe,MAAM,SAAS,CAAC;AAK/E,qBAAa,cAAc;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAG,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,MAAM,EAAG,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAGhC,mBAAmB,SAAK;IACxB,gBAAgB,SAAK;IAC5B,SAAS,CAAC,cAAc,SAAK;IACtB,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,YAAY,EAAE,GAAG,CAAC,KAAK,CAAC,CAAa;IACrC,YAAY,uBAA8B;IAG1C,sBAAsB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAa;IAChD,kBAAkB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAa;IAC5C,iBAAiB,SAAM;IACvB,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAa;IAC5D,yBAAyB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACzC,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACtC,SAAS,CAAC,kBAAkB,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAa;gBAE9D,GAAG,EAAE,MAAM;IAUvB,MAAM,CAAC,IAAI,EAAE,MAAM;IAuBnB,KAAK,CAAC,GAAG,EAAE,GAAG;IAMd,MAAM,CAAC,IAAI,EAAE,GAAG;IAUT,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,QAA0B;IAO/D,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,GAAE,QAA0B;IA8C5D,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ;IAW3C,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAiB/B,UAAU,CAAC,QAAQ,EAAE,QAAQ;IA6B7B,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAY/B,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAiCpC,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAcnC,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;CA8BxC"}
|