@sanctumterra/raknet 1.4.14 → 1.4.15
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.
|
@@ -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,EAKV,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EACN,KAAK,aAAa,EAElB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAgB,KAAK,UAAU,EAAe,MAAM,YAAY,CAAC;AAKxE,qBAAa,MAAO,SAAQ,YAAY,CAAC,YAAY,CAAC;IACrD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAiC;IACnE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAO;IACjD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IACjD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAO;IAE3C,OAAO,EAAE,aAAa,CAAC;IAC9B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAwB;IACxC,OAAO,CAAC,MAAM,CAAmB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,SAAS,CAAS;IAE1B,OAAO,CAAC,WAAW,CAA0B;IAC7C,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,UAAU,CAAS;IAE3B,OAAO,CAAC,YAAY,CAAsB;IAC1C,OAAO,CAAC,gBAAgB,CAAsB;IAC9C,OAAO,CAAC,cAAc,CAAS;gBAEnB,OAAO,G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BzB,OAAO,CAAC,qBAAqB;IA4B7B,OAAO,CAAC,oBAAoB;IA2Bf,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAwE9B,MAAM,IAAI,IAAI;IA6BrB,OAAO,CAAC,iBAAiB;IAMzB,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,OAAO;IAgBR,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI;IA0EhD,YAAY,CAAC,IAAI,EAAE,MAAM;IAiDzB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,GAAE,QAA0B;IAI5D,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,QAA0B;IAI/D,IAAI,IAAI,IAAI;IAOZ,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAWxB,UAAU,IAAI,IAAI;CAWzB"}
|
package/dist/client/client.js
CHANGED
|
@@ -8,7 +8,7 @@ const shared_2 = require("../shared");
|
|
|
8
8
|
const node_net_1 = require("node:net");
|
|
9
9
|
const promises_1 = require("node:dns/promises");
|
|
10
10
|
class Client extends shared_1.EventEmitter {
|
|
11
|
-
static MTU_VALUES = [
|
|
11
|
+
static MTU_VALUES = [1400, 1200, 1028, 576, 1492];
|
|
12
12
|
static MTU_RETRY_INTERVAL = 500;
|
|
13
13
|
static STALE_TIMEOUT_MS = 10000; // 10 seconds without pong = stale
|
|
14
14
|
static PING_INTERVAL_TICKS = 100; // Send connected ping every ~2 seconds at 50 tick rate
|
|
@@ -33,14 +33,20 @@ class Client extends shared_1.EventEmitter {
|
|
|
33
33
|
this.status = shared_1.ConnectionStatus.Disconnected;
|
|
34
34
|
this.tick = 0;
|
|
35
35
|
this.socket = (0, node_dgram_1.createSocket)("udp4");
|
|
36
|
-
this.socket.bind();
|
|
37
36
|
this.interval = setInterval(this.onTick.bind(this), 1000 / this.options.tickRate);
|
|
38
37
|
this.socket.on("message", this.onMessage.bind(this));
|
|
38
|
+
this.socket.on("error", (err) => {
|
|
39
|
+
shared_2.Logger.error(`Socket error: ${err.message}`);
|
|
40
|
+
});
|
|
39
41
|
this.session = new shared_1.NetworkSession(this.options.mtu, this.options.debug);
|
|
40
42
|
this.session.send = this.send.bind(this);
|
|
41
43
|
this.session.handle = (data) => {
|
|
42
44
|
this.handleOnline(data);
|
|
43
45
|
};
|
|
46
|
+
// Enable debug logging if debug option is set
|
|
47
|
+
if (this.options.debug) {
|
|
48
|
+
shared_2.Logger.debugEnabled = true;
|
|
49
|
+
}
|
|
44
50
|
}
|
|
45
51
|
async setupProxy() {
|
|
46
52
|
if (!this.options.proxy)
|
|
@@ -202,6 +208,11 @@ class Client extends shared_1.EventEmitter {
|
|
|
202
208
|
return null;
|
|
203
209
|
}
|
|
204
210
|
async connect() {
|
|
211
|
+
// Ensure socket is bound and ready
|
|
212
|
+
await new Promise((resolve) => {
|
|
213
|
+
this.socket.once("listening", () => resolve());
|
|
214
|
+
this.socket.bind();
|
|
215
|
+
});
|
|
205
216
|
if (this.options.proxy) {
|
|
206
217
|
await this.setupProxy();
|
|
207
218
|
}
|
|
@@ -217,7 +228,7 @@ class Client extends shared_1.EventEmitter {
|
|
|
217
228
|
let mtuIndex = 0;
|
|
218
229
|
let retryTimeout = null;
|
|
219
230
|
// Use configured MTU or fall back to default values
|
|
220
|
-
const mtuValues = this.options.mtu
|
|
231
|
+
const mtuValues = this.options.mtu && this.options.mtu > 0
|
|
221
232
|
? [this.options.mtu]
|
|
222
233
|
: Client.MTU_VALUES;
|
|
223
234
|
const sendRequest = () => {
|
|
@@ -231,9 +242,13 @@ class Client extends shared_1.EventEmitter {
|
|
|
231
242
|
const request = new shared_1.OpenConnectionRequestOne();
|
|
232
243
|
request.mtu = mtu;
|
|
233
244
|
request.protocol = 11;
|
|
245
|
+
if (this.options.debug) {
|
|
246
|
+
shared_2.Logger.debug(`Sending OpenConnectionRequestOne with MTU ${mtu}`);
|
|
247
|
+
}
|
|
234
248
|
this.send(request.serialize());
|
|
235
249
|
retryTimeout = setTimeout(() => {
|
|
236
250
|
if (!this.gotReply1) {
|
|
251
|
+
shared_2.Logger.warn(`No reply for MTU ${mtu}, trying next value...`);
|
|
237
252
|
mtuIndex++;
|
|
238
253
|
sendRequest();
|
|
239
254
|
}
|
|
@@ -319,6 +334,9 @@ class Client extends shared_1.EventEmitter {
|
|
|
319
334
|
const isOnline = (id & 0xf0) === 0x80;
|
|
320
335
|
if (isOnline)
|
|
321
336
|
id = 0x80;
|
|
337
|
+
if (this.options.debug) {
|
|
338
|
+
shared_2.Logger.debug(`Received packet ID: 0x${id?.toString(16).padStart(2, "0")} from ${rinfo.address}:${rinfo.port}`);
|
|
339
|
+
}
|
|
322
340
|
switch (id) {
|
|
323
341
|
case shared_1.Packets.UnconnectedPong: {
|
|
324
342
|
const pong = new shared_1.UnconnectedPong(actualData).deserialize();
|
|
@@ -4,7 +4,7 @@ exports.createDefaultClientOptions = exports.generateGuid = void 0;
|
|
|
4
4
|
const generateGuid = () => BigInt(Math.floor(Date.now() + Math.random() * 10000000));
|
|
5
5
|
exports.generateGuid = generateGuid;
|
|
6
6
|
const createDefaultClientOptions = () => ({
|
|
7
|
-
mtu:
|
|
7
|
+
mtu: 0, // 0 means use MTU_VALUES array
|
|
8
8
|
address: "127.0.0.1",
|
|
9
9
|
port: 19132,
|
|
10
10
|
guid: (0, exports.generateGuid)(),
|