@sanctumterra/raknet 1.4.2 → 1.4.3
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/dist/client/client.d.ts +3 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +33 -5
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +1 -0
- package/dist/shared/proto/offline/open-connection-reply-one.d.ts +1 -0
- package/dist/shared/proto/offline/open-connection-reply-one.d.ts.map +1 -1
- package/dist/shared/proto/offline/open-connection-reply-one.js +8 -0
- package/dist/shared/proto/offline/open-connection-request-two.d.ts +1 -0
- package/dist/shared/proto/offline/open-connection-request-two.d.ts.map +1 -1
- package/dist/shared/proto/offline/open-connection-request-two.js +8 -0
- package/dist/tests/client-once.js +3 -1
- package/package.json +1 -1
package/dist/client/client.d.ts
CHANGED
|
@@ -3,12 +3,15 @@ import type { ClientEvents } from "./types";
|
|
|
3
3
|
import { type ClientOptions } from "./types/client-options";
|
|
4
4
|
import { type RemoteInfo } from "node:dgram";
|
|
5
5
|
export declare class Client extends EventEmitter<ClientEvents> {
|
|
6
|
+
private static readonly MTU_VALUES;
|
|
7
|
+
private static readonly MTU_RETRY_INTERVAL;
|
|
6
8
|
options: ClientOptions;
|
|
7
9
|
private socket;
|
|
8
10
|
private interval;
|
|
9
11
|
private status;
|
|
10
12
|
tick: number;
|
|
11
13
|
private session;
|
|
14
|
+
private gotReply1;
|
|
12
15
|
constructor(options?: Partial<ClientOptions>);
|
|
13
16
|
connect(): Promise<void>;
|
|
14
17
|
onTick(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,YAAY,EAWZ,QAAQ,EAIR,KAAK,KAAK,EAIV,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,E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IAAI;IAQZ,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIxB,UAAU,IAAI,IAAI;CAIzB"}
|
package/dist/client/client.js
CHANGED
|
@@ -6,12 +6,15 @@ const client_options_1 = require("./types/client-options");
|
|
|
6
6
|
const node_dgram_1 = require("node:dgram");
|
|
7
7
|
const shared_2 = require("../shared");
|
|
8
8
|
class Client extends shared_1.EventEmitter {
|
|
9
|
+
static MTU_VALUES = [1492, 1400, 1200, 576];
|
|
10
|
+
static MTU_RETRY_INTERVAL = 500;
|
|
9
11
|
options;
|
|
10
12
|
socket;
|
|
11
13
|
interval;
|
|
12
14
|
status;
|
|
13
15
|
tick;
|
|
14
16
|
session;
|
|
17
|
+
gotReply1 = false;
|
|
15
18
|
constructor(options = {}) {
|
|
16
19
|
super();
|
|
17
20
|
this.options = { ...client_options_1.defaultClientOptions, ...options };
|
|
@@ -30,18 +33,41 @@ class Client extends shared_1.EventEmitter {
|
|
|
30
33
|
connect() {
|
|
31
34
|
return new Promise((resolve, reject) => {
|
|
32
35
|
this.status = shared_1.ConnectionStatus.Connecting;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
36
|
+
this.gotReply1 = false;
|
|
37
|
+
let mtuIndex = 0;
|
|
38
|
+
let retryTimeout = null;
|
|
39
|
+
const sendRequest = () => {
|
|
40
|
+
if (mtuIndex >= Client.MTU_VALUES.length) {
|
|
41
|
+
reject(new Error("Connection timed out, all MTU values exhausted"));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const mtu = Client.MTU_VALUES[mtuIndex];
|
|
45
|
+
// Should not happen but for the linter sake
|
|
46
|
+
if (!mtu)
|
|
47
|
+
throw new Error("MTU value is undefined");
|
|
48
|
+
const request = new shared_1.OpenConnectionRequestOne();
|
|
49
|
+
request.mtu = mtu;
|
|
50
|
+
request.protocol = 11;
|
|
51
|
+
this.send(request.serialize());
|
|
52
|
+
retryTimeout = setTimeout(() => {
|
|
53
|
+
if (!this.gotReply1) {
|
|
54
|
+
mtuIndex++;
|
|
55
|
+
sendRequest();
|
|
56
|
+
}
|
|
57
|
+
}, Client.MTU_RETRY_INTERVAL);
|
|
58
|
+
};
|
|
38
59
|
const timeout = setTimeout(() => {
|
|
60
|
+
if (retryTimeout)
|
|
61
|
+
clearTimeout(retryTimeout);
|
|
39
62
|
reject(new Error("Connection timed out"));
|
|
40
63
|
}, this.options.timeout);
|
|
41
64
|
this.once("connect", () => {
|
|
42
65
|
clearTimeout(timeout);
|
|
66
|
+
if (retryTimeout)
|
|
67
|
+
clearTimeout(retryTimeout);
|
|
43
68
|
resolve();
|
|
44
69
|
});
|
|
70
|
+
sendRequest();
|
|
45
71
|
});
|
|
46
72
|
}
|
|
47
73
|
onTick() {
|
|
@@ -67,11 +93,13 @@ class Client extends shared_1.EventEmitter {
|
|
|
67
93
|
break;
|
|
68
94
|
}
|
|
69
95
|
case shared_1.Packets.OpenConnectionReply1: {
|
|
96
|
+
this.gotReply1 = true;
|
|
70
97
|
const reply = new shared_1.OpenConnectionReplyOne(data).deserialize();
|
|
71
98
|
const request = new shared_1.OpenConnectionRequestTwo();
|
|
72
99
|
request.address = shared_1.Address.fromIdentifier(rinfo);
|
|
73
100
|
request.mtu = reply.mtu;
|
|
74
101
|
request.guid = this.options.guid;
|
|
102
|
+
request.cookie = reply.cookie;
|
|
75
103
|
this.send(request.serialize());
|
|
76
104
|
break;
|
|
77
105
|
}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;IA8EV,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAGzD"}
|
package/dist/server/server.js
CHANGED
|
@@ -65,6 +65,7 @@ class Server extends shared_1.EventEmitter {
|
|
|
65
65
|
id = 0x80;
|
|
66
66
|
switch (id) {
|
|
67
67
|
case shared_1.Packets.UnconnectedPing: {
|
|
68
|
+
console.log("Received Ping! from: ", rinfo.address);
|
|
68
69
|
const pong = new shared_1.UnconnectedPong();
|
|
69
70
|
pong.guid = this.options.guid;
|
|
70
71
|
pong.message = (0, types_1.AdvertisementToString)(this.advertisement);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"open-connection-reply-one.d.ts","sourceRoot":"","sources":["../../../../src/shared/proto/offline/open-connection-reply-one.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,
|
|
1
|
+
{"version":3,"file":"open-connection-reply-one.d.ts","sourceRoot":"","sources":["../../../../src/shared/proto/offline/open-connection-reply-one.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EAMZ,MAAM,0BAA0B,CAAC;AAIlC,qBAAa,sBAAuB,SAAQ,YAAY;IAChD,IAAI,EAAG,MAAM,CAAC;IACd,QAAQ,EAAG,OAAO,CAAC;IACnB,MAAM,EAAG,MAAM,GAAG,IAAI,CAAC;IACvB,GAAG,EAAG,MAAM,CAAC;IAEb,SAAS,IAAI,MAAM;IAYnB,WAAW,IAAI,sBAAsB;CAY5C"}
|
|
@@ -7,12 +7,16 @@ const types_1 = require("../types");
|
|
|
7
7
|
class OpenConnectionReplyOne extends binarystream_1.BinaryStream {
|
|
8
8
|
guid;
|
|
9
9
|
security;
|
|
10
|
+
cookie;
|
|
10
11
|
mtu;
|
|
11
12
|
serialize() {
|
|
12
13
|
binarystream_1.Uint8.write(this, enums_1.Packets.OpenConnectionReply1);
|
|
13
14
|
types_1.Magic.write(this);
|
|
14
15
|
binarystream_1.Int64.write(this, this.guid);
|
|
15
16
|
binarystream_1.Bool.write(this, this.security);
|
|
17
|
+
if (this.security && this.cookie != null) {
|
|
18
|
+
binarystream_1.Int32.write(this, this.cookie);
|
|
19
|
+
}
|
|
16
20
|
binarystream_1.Int16.write(this, this.mtu);
|
|
17
21
|
return this.getBuffer();
|
|
18
22
|
}
|
|
@@ -21,6 +25,10 @@ class OpenConnectionReplyOne extends binarystream_1.BinaryStream {
|
|
|
21
25
|
types_1.Magic.read(this);
|
|
22
26
|
this.guid = binarystream_1.Int64.read(this);
|
|
23
27
|
this.security = binarystream_1.Bool.read(this);
|
|
28
|
+
this.cookie = null;
|
|
29
|
+
if (this.security) {
|
|
30
|
+
this.cookie = binarystream_1.Int32.read(this);
|
|
31
|
+
}
|
|
24
32
|
this.mtu = binarystream_1.Int16.read(this);
|
|
25
33
|
return this;
|
|
26
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"open-connection-request-two.d.ts","sourceRoot":"","sources":["../../../../src/shared/proto/offline/open-connection-request-two.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"open-connection-request-two.d.ts","sourceRoot":"","sources":["../../../../src/shared/proto/offline/open-connection-request-two.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EAMZ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,OAAO,EAAS,MAAM,UAAU,CAAC;AAE1C,qBAAa,wBAAyB,SAAQ,YAAY;IAClD,OAAO,EAAG,OAAO,CAAC;IAClB,GAAG,EAAG,MAAM,CAAC;IACb,IAAI,EAAG,MAAM,CAAC;IACd,MAAM,EAAG,MAAM,GAAG,IAAI,CAAC;IAEvB,SAAS,IAAI,MAAM;IAanB,WAAW,IAAI,wBAAwB;CAW9C"}
|
|
@@ -8,9 +8,14 @@ class OpenConnectionRequestTwo extends binarystream_1.BinaryStream {
|
|
|
8
8
|
address;
|
|
9
9
|
mtu;
|
|
10
10
|
guid;
|
|
11
|
+
cookie;
|
|
11
12
|
serialize() {
|
|
12
13
|
binarystream_1.Uint8.write(this, enums_1.Packets.OpenConnectionRequest2);
|
|
13
14
|
types_1.Magic.write(this);
|
|
15
|
+
if (this.cookie != null) {
|
|
16
|
+
binarystream_1.Int32.write(this, this.cookie);
|
|
17
|
+
binarystream_1.Bool.write(this, true); //Not sure about this (https://minecraft.wiki/w/RakNet#Open_Connection_Reply_2)
|
|
18
|
+
}
|
|
14
19
|
types_1.Address.write(this, this.address);
|
|
15
20
|
binarystream_1.Int16.write(this, this.mtu);
|
|
16
21
|
binarystream_1.Int64.write(this, this.guid);
|
|
@@ -19,6 +24,9 @@ class OpenConnectionRequestTwo extends binarystream_1.BinaryStream {
|
|
|
19
24
|
deserialize() {
|
|
20
25
|
binarystream_1.Uint8.read(this);
|
|
21
26
|
types_1.Magic.read(this);
|
|
27
|
+
//TODO:If server uses security need to Deserialize cookie
|
|
28
|
+
//But this implemntion doesnt seem to use cookies
|
|
29
|
+
//https://minecraft.wiki/w/RakNet#Open_Connection_Request_2
|
|
22
30
|
this.address = types_1.Address.read(this);
|
|
23
31
|
this.mtu = binarystream_1.Int16.read(this);
|
|
24
32
|
this.guid = binarystream_1.Int64.read(this);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const client_1 = require("../client");
|
|
4
|
-
const client = new client_1.Client(
|
|
4
|
+
const client = new client_1.Client({
|
|
5
|
+
address: "donutsmp.net",
|
|
6
|
+
});
|
|
5
7
|
client.on("unconnectedPong", (packet) => {
|
|
6
8
|
console.log(packet);
|
|
7
9
|
});
|