@sanctumterra/raknet 1.3.79 → 1.3.80

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,9 +1,8 @@
1
1
  import { Emitter } from "@serenityjs/emitter";
2
- import type { ClientEvents } from "./client-events";
3
2
  import { type Socket } from "node:dgram";
4
- import { Framer } from "./framer";
5
3
  import { type Address, type Advertisement, Frame, type Priority, Status } from "../proto";
6
- import { type ClientOptions } from "./client-options";
4
+ import { Framer } from "./framer";
5
+ import { type ClientEvents, type ClientOptions } from "./types";
7
6
  export declare class Client extends Emitter<ClientEvents> {
8
7
  socket: Socket | null;
9
8
  framer: Framer | null;
@@ -16,13 +15,10 @@ export declare class Client extends Emitter<ClientEvents> {
16
15
  constructor(options?: Partial<ClientOptions>);
17
16
  initSocket(): void;
18
17
  ping(): Promise<Advertisement>;
19
- connect(): Promise<Advertisement>;
18
+ connect(): Promise<Advertisement | null>;
20
19
  sendFrame(frame: Frame, priority: Priority): void;
21
20
  frameAndSend(payload: Buffer, priority: Priority): void;
22
21
  send(buffer: Buffer): void;
23
- private cleanupSocket;
24
- private cleanupFramer;
25
- cleanup(): void;
26
22
  disconnect(): Promise<void>;
27
23
  }
28
24
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAmB,KAAK,MAAM,EAAgB,MAAM,YAAY,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAEN,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,EAIL,KAAK,QAAQ,EACb,MAAM,EAGN,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,KAAK,aAAa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aAAa,EAElB,MAAM,SAAS,CAAC;AAKjB,qBAAa,MAAO,SAAQ,OAAO,CAAC,YAAY,CAAC;IACzC,MAAM,EAAG,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAG,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,EAAE,aAAa,CAAC;IAC9B,OAAO,CAAC,SAAS,CAAC,CAAiB;IACnC,OAAO,CAAC,iBAAiB,CAAC,CAAiB;IAC3C,OAAO,CAAC,eAAe,CAAC,CAAiB;IAClC,aAAa,EAAG,OAAO,GAAG,IAAI,CAAC;IAE/B,MAAM,SAAuB;gBAExB,OAAO,GAAE,OAAO,CAAC,aAAa,CAAwB;IAM3D,UAAU;IAuBJ,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC;IAkB9B,OAAO,IAAI,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAmG9C,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAYjD,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAOvD,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAiC1B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAiClC"}
@@ -6,11 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Client = void 0;
7
7
  const emitter_1 = require("@serenityjs/emitter");
8
8
  const node_dgram_1 = require("node:dgram");
9
- const framer_1 = require("./framer");
10
9
  const proto_1 = require("../proto");
11
10
  const disconnect_1 = __importDefault(require("../proto/packets/disconnect"));
12
- const client_options_1 = require("./client-options");
13
11
  const utils_1 = require("../utils");
12
+ const framer_1 = require("./framer");
13
+ const types_1 = require("./types");
14
14
  const TICK_INTERVAL = 50;
15
15
  const REQUEST_INTERVAL = 500;
16
16
  class Client extends emitter_1.Emitter {
@@ -22,9 +22,9 @@ class Client extends emitter_1.Emitter {
22
22
  requestInterval;
23
23
  serverAddress;
24
24
  status = proto_1.Status.Disconnected;
25
- constructor(options = client_options_1.defaultClientOptions) {
25
+ constructor(options = types_1.defaultClientOptions) {
26
26
  super();
27
- this.options = { ...client_options_1.defaultClientOptions, ...options };
27
+ this.options = { ...types_1.defaultClientOptions, ...options };
28
28
  this.maxListeners = 60;
29
29
  }
30
30
  initSocket() {
@@ -71,90 +71,75 @@ class Client extends emitter_1.Emitter {
71
71
  this.status = proto_1.Status.Connecting;
72
72
  this.initSocket();
73
73
  this.tickTimer = setInterval(() => this.emit("tick"), TICK_INTERVAL);
74
- try {
75
- const advertisement = await this.ping();
76
- if (!advertisement)
77
- throw new Error("Failed to get server advertisement");
78
- return new Promise((resolve, reject) => {
79
- let isResolved = false;
80
- let currentStage = "request-one"; // Track connection stage
81
- const cleanup = () => {
82
- if (this.connectionTimeout) {
83
- clearTimeout(this.connectionTimeout);
84
- this.connectionTimeout = undefined;
85
- }
86
- if (this.requestInterval) {
87
- clearInterval(this.requestInterval);
88
- this.requestInterval = undefined;
89
- }
90
- if (!isResolved) {
91
- utils_1.Logger.error("Could not resolve connection.");
92
- this.cleanup();
93
- }
94
- };
95
- // Setup connection timeout
96
- this.connectionTimeout = setTimeout(() => {
97
- cleanup();
74
+ let advertisement = null;
75
+ const pongHandler = (packet) => {
76
+ advertisement = (0, proto_1.fromString)(packet.message);
77
+ };
78
+ this.once("unconnected-pong", pongHandler);
79
+ const ping = new proto_1.UnconnectedPing();
80
+ ping.guid = this.options.clientId;
81
+ ping.clientTimestamp = BigInt(Date.now());
82
+ this.send(ping.serialize());
83
+ return new Promise((resolve, reject) => {
84
+ let isResolved = false;
85
+ let currentStage = 0; // 0: request-one, 1: request-two, 2: completed
86
+ this.connectionTimeout = setTimeout(() => {
87
+ if (!isResolved) {
88
+ isResolved = true;
89
+ this.disconnect();
98
90
  reject(new Error("Connection timed out"));
99
- }, this.options.timeout);
100
- // Prepare connection request one
101
- const requestOne = new proto_1.OpenConnectionRequestOne();
102
- requestOne.mtu = this.options.mtuSize;
103
- requestOne.protocol = this.options.protocolVersion;
104
- // Handle open-connection-reply-one event
105
- this.once("open-connection-reply-one", () => {
106
- currentStage = "request-two";
107
- utils_1.Logger.debug("[Client] Received OpenConnectionReplyOne, sending OpenConnectionRequestTwo");
108
- // Move to next connection stage
109
- if (this.requestInterval) {
110
- clearInterval(this.requestInterval);
111
- }
112
- // Here we would send OpenConnectionRequestTwo
113
- // The framer handles this transition
114
- });
115
- // Handle open-connection-reply-two event
116
- this.once("open-connection-reply-two", (packet) => {
117
- const mtu = packet.mtu;
118
- if (mtu > 400 && mtu < 1500) {
119
- currentStage = "completed";
120
- utils_1.Logger.debug(`[Client] Received OpenConnectionReplyTwo with MTU: ${mtu}`);
121
- }
122
- else {
123
- cleanup();
124
- reject(new Error(`Invalid MTU size: ${mtu}`));
125
- }
126
- });
127
- // Send initial request
128
- this.emit("open-connection-request-one", requestOne);
129
- this.send(requestOne.serialize());
130
- // Set up interval to resend requests
131
- this.requestInterval = setInterval(() => {
132
- if (!isResolved && currentStage === "request-one") {
133
- utils_1.Logger.debug("[Client] Resending OpenConnectionRequestOne");
134
- this.send(requestOne.serialize());
135
- }
136
- }, REQUEST_INTERVAL);
137
- // Handle successful connection
138
- this.once("new-incoming-connection", () => {
91
+ }
92
+ }, this.options.timeout);
93
+ const requestOne = new proto_1.OpenConnectionRequestOne();
94
+ requestOne.mtu = this.options.mtuSize;
95
+ requestOne.protocol = this.options.protocolVersion;
96
+ this.once("open-connection-reply-one", () => {
97
+ currentStage = 1;
98
+ utils_1.Logger.debug("[Client] Received OpenConnectionReplyOne, sending OpenConnectionRequestTwo");
99
+ if (this.requestInterval)
100
+ clearInterval(this.requestInterval);
101
+ });
102
+ this.once("open-connection-reply-two", (packet) => {
103
+ const mtu = packet.mtu;
104
+ if (mtu < 400 || mtu > 1500) {
139
105
  if (!isResolved) {
140
106
  isResolved = true;
141
- this.emit("connect", advertisement);
142
- this.status = proto_1.Status.Connected;
143
- cleanup();
144
- resolve(advertisement);
107
+ this.disconnect();
108
+ reject(new Error(`Invalid MTU size: ${mtu}`));
145
109
  }
146
- });
147
- // Handle connection errors
148
- this.once("error", (error) => {
149
- cleanup();
110
+ return;
111
+ }
112
+ currentStage = 2;
113
+ utils_1.Logger.debug(`[Client] Received OpenConnectionReplyTwo with MTU: ${mtu}`);
114
+ });
115
+ this.once("new-incoming-connection", () => {
116
+ if (!isResolved) {
117
+ isResolved = true;
118
+ this.status = proto_1.Status.Connected;
119
+ this.emit("connect");
120
+ if (this.connectionTimeout)
121
+ clearTimeout(this.connectionTimeout);
122
+ if (this.requestInterval)
123
+ clearInterval(this.requestInterval);
124
+ resolve(advertisement);
125
+ }
126
+ });
127
+ this.once("error", (error) => {
128
+ if (!isResolved) {
129
+ isResolved = true;
130
+ this.disconnect();
150
131
  reject(error);
151
- });
132
+ }
152
133
  });
153
- }
154
- catch (error) {
155
- this.status = proto_1.Status.Disconnected;
156
- throw error;
157
- }
134
+ this.emit("open-connection-request-one", requestOne);
135
+ this.send(requestOne.serialize());
136
+ this.requestInterval = setInterval(() => {
137
+ if (!isResolved && currentStage === 0) {
138
+ utils_1.Logger.debug("[Client] Resending OpenConnectionRequestOne");
139
+ this.send(requestOne.serialize());
140
+ }
141
+ }, REQUEST_INTERVAL);
142
+ });
158
143
  }
159
144
  sendFrame(frame, priority) {
160
145
  try {
@@ -195,113 +180,30 @@ class Client extends emitter_1.Emitter {
195
180
  utils_1.Logger.error("[Client] Failed to send packet", error);
196
181
  }
197
182
  }
198
- cleanupSocket() {
199
- if (!this.socket)
200
- return;
201
- try {
202
- this.socket.removeAllListeners();
203
- if (this.status === proto_1.Status.Connected) {
204
- const disconnect = new disconnect_1.default();
205
- this.socket.send(disconnect.serialize(), 0, disconnect.serialize().length, this.options.port, this.options.address);
206
- }
207
- const stateSymbol = Symbol.for("state symbol");
208
- const socketWithState = this.socket;
209
- const state = socketWithState[stateSymbol];
210
- if (state?.handle) {
211
- state.handle.close();
212
- state.handle = null;
213
- }
214
- this.socket.close(() => {
215
- utils_1.Logger.info("[Client] Socket closed");
216
- this.socket?.removeAllListeners();
217
- });
218
- // (this.socket as { _handle?: unknown })._handle = undefined;
219
- }
220
- catch (err) {
221
- utils_1.Logger.error("[Client] Error during socket cleanup", err);
222
- try {
223
- const stateSymbol = Symbol.for("state symbol");
224
- const socketWithState = this.socket;
225
- const state = socketWithState[stateSymbol];
226
- if (state?.handle) {
227
- state.handle.close();
228
- state.handle = null;
229
- }
230
- }
231
- catch (_) { }
232
- this.socket = null;
233
- }
234
- }
235
- cleanupFramer() {
236
- if (!this.framer)
237
- return;
238
- this.framer._events = undefined;
239
- this.framer._eventsCount = undefined;
240
- this.framer = null;
241
- }
242
- cleanup() {
243
- if (this.status === proto_1.Status.Disconnected)
244
- return;
245
- utils_1.Logger.debug("[Client] Cleaning up connection and resources");
246
- const wasConnected = this.status === proto_1.Status.Connected;
247
- this.status = proto_1.Status.Disconnecting;
248
- this.remove("tick", () => this.framer?.tick());
249
- if (this.tickTimer) {
250
- clearInterval(this.tickTimer);
251
- this.tickTimer = undefined;
252
- }
253
- if (this.connectionTimeout) {
254
- clearTimeout(this.connectionTimeout);
255
- this.connectionTimeout = undefined;
256
- }
257
- if (this.requestInterval) {
258
- clearInterval(this.requestInterval);
259
- this.requestInterval = undefined;
260
- }
261
- this.removeAll();
262
- this.removeAllAfter();
263
- this.removeAllBefore();
264
- this.cleanupSocket();
265
- this.cleanupFramer();
266
- this.serverAddress = null;
267
- this._events = undefined;
268
- this._eventsCount = undefined;
269
- this.status = proto_1.Status.Disconnected;
270
- utils_1.Logger.debug("[Client] Cleanup complete");
271
- }
272
183
  disconnect() {
273
- return new Promise((resolve, reject) => {
184
+ return new Promise((resolve) => {
274
185
  if (this.status === proto_1.Status.Disconnected) {
275
186
  resolve();
276
187
  return;
277
188
  }
278
- const cleanupTimeout = setTimeout(() => {
279
- utils_1.Logger.warn("[Client] Disconnect timeout reached, forcing cleanup");
280
- try {
281
- this.cleanup();
282
- resolve();
283
- }
284
- catch (error) {
285
- reject(error);
189
+ const wasConnected = this.status === proto_1.Status.Connected;
190
+ this.status = proto_1.Status.Disconnected;
191
+ if (this.tickTimer)
192
+ clearInterval(this.tickTimer);
193
+ if (this.connectionTimeout)
194
+ clearTimeout(this.connectionTimeout);
195
+ if (this.requestInterval)
196
+ clearInterval(this.requestInterval);
197
+ if (this.socket) {
198
+ if (wasConnected) {
199
+ const disconnect = new disconnect_1.default();
200
+ this.socket.send(disconnect.serialize(), 0, disconnect.serialize().length, this.options.port, this.options.address);
286
201
  }
287
- }, 5000);
288
- try {
289
- setImmediate(() => {
290
- try {
291
- this.cleanup();
292
- clearTimeout(cleanupTimeout);
293
- resolve();
294
- }
295
- catch (error) {
296
- clearTimeout(cleanupTimeout);
297
- reject(error);
298
- }
299
- });
300
- }
301
- catch (error) {
302
- clearTimeout(cleanupTimeout);
303
- reject(error);
202
+ this.socket.close();
203
+ this.socket = null;
304
204
  }
205
+ this.framer = null;
206
+ resolve();
305
207
  });
306
208
  }
307
209
  }
@@ -1,7 +1,6 @@
1
- import { Frame, Priority } from "../proto";
2
- import { Frameset } from "../proto";
3
- import type { Client } from "./client";
4
1
  import type { RemoteInfo } from "node:dgram";
2
+ import { Frame, Frameset, Priority } from "../proto";
3
+ import type { Client } from "./client";
5
4
  interface QueuedFrame {
6
5
  frame: Frame;
7
6
  timestamp: number;
@@ -50,7 +49,7 @@ export declare class Framer {
50
49
  sendFrame(frame: Frame, priority: Priority): void;
51
50
  private createSplitFrame;
52
51
  private queueFrame;
53
- sendQueue(amount: number): void;
52
+ sendQueue(): void;
54
53
  }
55
54
  export {};
56
55
  //# sourceMappingURL=framer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"framer.d.ts","sourceRoot":"","sources":["../../src/client/framer.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,EAGL,QAAQ,EAUR,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAA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AQ,GAAG,IAAI;IAiCxD,OAAO,CAAC,gBAAgB;IAsBxB,OAAO,CAAC,UAAU;IAqBX,SAAS,IAAI,IAAI;CA0BxB"}
@@ -1,16 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Framer = void 0;
4
- const proto_1 = require("../proto");
5
- const proto_2 = require("../proto");
6
- const utils_1 = require("../utils");
7
4
  const binarystream_1 = require("@serenityjs/binarystream");
5
+ const proto_1 = require("../proto");
8
6
  const connection_request_accepted_1 = require("../proto/packets/connection-request-accepted");
7
+ const utils_1 = require("../utils");
9
8
  // Constants for packet handling
10
9
  const PACKET_HEADER_MASK = 0xf0;
11
10
  const PACKET_HEADER_FRAMESET = 0x80;
12
11
  const PACKET_ENCAPSULATED = 0xfe;
13
- const PING_INTERVAL = 50; // Send ping every 50 ticks
12
+ const PING_INTERVAL = 50;
14
13
  const MTU_HEADER_SIZE = 36;
15
14
  class Framer {
16
15
  client;
@@ -32,13 +31,13 @@ class Framer {
32
31
  outputBackup = new Map();
33
32
  _tickCount = 0;
34
33
  mtuDiff;
35
- BATCH_SIZE = 32; // Maximum frames to process in a batch
36
- MAX_BATCH_INTERVAL = 50; // Maximum time (ms) to wait before processing a batch
34
+ BATCH_SIZE = 32;
35
+ MAX_BATCH_INTERVAL = 50;
37
36
  lastBatchTime = 0;
38
37
  ORDERING_QUEUE_TIMEOUT = 500;
39
38
  constructor(client) {
40
39
  this.client = client;
41
- this.outputFrameQueue = new proto_2.Frameset();
40
+ this.outputFrameQueue = new proto_1.Frameset();
42
41
  this.outputFrameQueue.frames = [];
43
42
  this.outputOrderIndex = new Array(32).fill(0);
44
43
  this.outputSequenceIndex = new Array(32).fill(0);
@@ -57,20 +56,16 @@ class Framer {
57
56
  ping.timestamp = BigInt(now);
58
57
  this.frameAndSend(ping.serialize(), proto_1.Priority.Immediate);
59
58
  }
60
- // Batch process ACKs and NACKs
61
59
  this.processBatchedAcksAndNacks();
62
- // Process ordered frames in batches
63
60
  this.processBatchedOrderedFrames(now);
64
- // Send queued frames if we have enough or enough time has passed
65
61
  if (this.outputFrames.length >= this.BATCH_SIZE ||
66
62
  (this.outputFrames.length > 0 &&
67
63
  now - this.lastBatchTime >= this.MAX_BATCH_INTERVAL)) {
68
- this.sendQueue(this.outputFrames.length);
64
+ this.sendQueue();
69
65
  this.lastBatchTime = now;
70
66
  }
71
67
  }
72
68
  processBatchedAcksAndNacks() {
73
- // Batch process ACKs
74
69
  if (this.receivedFrameSequences.size > 0) {
75
70
  const ackSeqs = Array.from(this.receivedFrameSequences);
76
71
  this.receivedFrameSequences.clear();
@@ -78,7 +73,6 @@ class Framer {
78
73
  ack.sequences = ackSeqs;
79
74
  this.client.send(ack.serialize());
80
75
  }
81
- // Batch process NACKs
82
76
  if (this.lostFrameSequences.size > 0) {
83
77
  const nackSeqs = Array.from(this.lostFrameSequences);
84
78
  this.lostFrameSequences.clear();
@@ -170,7 +164,7 @@ class Framer {
170
164
  break;
171
165
  }
172
166
  case PACKET_HEADER_FRAMESET: {
173
- const frameset = new proto_2.Frameset(payload).deserialize();
167
+ const frameset = new proto_1.Frameset(payload).deserialize();
174
168
  this.client.emit("frameset", frameset);
175
169
  this.handle(frameset);
176
170
  break;
@@ -210,7 +204,7 @@ class Framer {
210
204
  }
211
205
  case proto_1.Packet.DisconnectionNotification: {
212
206
  utils_1.Logger.info("[Framer] Received disconnection notification while connecting");
213
- this.client.cleanup();
207
+ this.client.disconnect();
214
208
  break;
215
209
  }
216
210
  }
@@ -240,7 +234,7 @@ class Framer {
240
234
  }
241
235
  case proto_1.Packet.DisconnectionNotification: {
242
236
  utils_1.Logger.info("[Framer] Received disconnection notification");
243
- this.client.cleanup();
237
+ this.client.disconnect();
244
238
  break;
245
239
  }
246
240
  }
@@ -272,7 +266,6 @@ class Framer {
272
266
  }
273
267
  }
274
268
  this.lastInputSequence = frameSet.sequence;
275
- // Process frames in batches
276
269
  const frames = frameSet.frames;
277
270
  for (let i = 0; i < frames.length; i += this.BATCH_SIZE) {
278
271
  const batch = frames.slice(i, i + this.BATCH_SIZE);
@@ -431,22 +424,21 @@ class Framer {
431
424
  const totalLength = 4 + this.outputFramesByteLength + frameLength;
432
425
  if (totalLength > this.mtuDiff ||
433
426
  this.outputFrames.length >= this.BATCH_SIZE) {
434
- this.sendQueue(this.outputFrames.length);
427
+ this.sendQueue();
435
428
  this.lastBatchTime = Date.now();
436
429
  }
437
430
  this.outputFrames.push(frame);
438
431
  this.outputFramesByteLength += frameLength;
439
432
  if (priority === proto_1.Priority.Immediate) {
440
- this.sendQueue(1);
433
+ this.sendQueue();
441
434
  this.lastBatchTime = Date.now();
442
435
  }
443
436
  }
444
- sendQueue(amount) {
437
+ sendQueue() {
445
438
  if (this.outputFrames.length === 0)
446
439
  return;
447
- const frameset = new proto_2.Frameset();
440
+ const frameset = new proto_1.Frameset();
448
441
  frameset.sequence = this.outputSequence++;
449
- // Send in batches if amount is larger than batch size
450
442
  const remainingFrames = [...this.outputFrames];
451
443
  this.outputFrames = [];
452
444
  while (remainingFrames.length > 0) {
@@ -457,7 +449,6 @@ class Framer {
457
449
  this.outputFramesByteLength -= sentLength;
458
450
  this.outputBackup.set(frameset.sequence, framesToSend);
459
451
  this.client.send(frameset.serialize());
460
- // Increment sequence for next batch if there are more frames
461
452
  if (remainingFrames.length > 0) {
462
453
  frameset.sequence = this.outputSequence++;
463
454
  }
@@ -1,4 +1,3 @@
1
- export * from "./client-events";
2
1
  export * from "./client";
3
- export * from "./client-options";
2
+ export * from "./types";
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
@@ -14,6 +14,5 @@ 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("./client-events"), exports);
18
17
  __exportStar(require("./client"), exports);
19
- __exportStar(require("./client-options"), exports);
18
+ __exportStar(require("./types"), exports);
@@ -1,5 +1,5 @@
1
- import type { Ack, Advertisement, ConnectedPing, ConnectedPong, ConnectionRequest, ConnectionRequestAccepted, NewIncomingConnection, OpenConnectionReplyOne, OpenConnectionReplyTwo, OpenConnectionRequestOne, OpenConnectionRequestTwo, UnconnectedPing, UnconnectedPong } from "../proto";
2
- import type { Frameset } from "../proto/packets/frameset";
1
+ import type { Ack, ConnectedPing, ConnectedPong, ConnectionRequest, ConnectionRequestAccepted, NewIncomingConnection, OpenConnectionReplyOne, OpenConnectionReplyTwo, OpenConnectionRequestOne, OpenConnectionRequestTwo, UnconnectedPing, UnconnectedPong } from "../../proto";
2
+ import type { Frameset } from "../../proto/packets/frameset";
3
3
  export interface ClientEvents {
4
4
  "open-connection-reply-one": [OpenConnectionReplyOne];
5
5
  "open-connection-reply-two": [OpenConnectionReplyTwo];
@@ -17,7 +17,7 @@ export interface ClientEvents {
17
17
  ack: [Ack];
18
18
  error: [Error];
19
19
  close: [];
20
- connect: [Advertisement];
20
+ connect: [];
21
21
  tick: [];
22
22
  }
23
23
  //# sourceMappingURL=client-events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-events.d.ts","sourceRoot":"","sources":["../../../src/client/types/client-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,GAAG,EAEH,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,eAAe,EACf,eAAe,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAE7D,MAAM,WAAW,YAAY;IAC5B,2BAA2B,EAAE,CAAC,sBAAsB,CAAC,CAAC;IACtD,2BAA2B,EAAE,CAAC,sBAAsB,CAAC,CAAC;IACtD,6BAA6B,EAAE,CAAC,wBAAwB,CAAC,CAAC;IAC1D,6BAA6B,EAAE,CAAC,wBAAwB,CAAC,CAAC;IAC1D,kBAAkB,EAAE,CAAC,eAAe,CAAC,CAAC;IACtC,kBAAkB,EAAE,CAAC,eAAe,CAAC,CAAC;IACtC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC;IACrB,gBAAgB,EAAE,CAAC,aAAa,CAAC,CAAC;IAClC,gBAAgB,EAAE,CAAC,aAAa,CAAC,CAAC;IAClC,oBAAoB,EAAE,CAAC,iBAAiB,CAAC,CAAC;IAC1C,6BAA6B,EAAE,CAAC,yBAAyB,CAAC,CAAC;IAC3D,yBAAyB,EAAE,CAAC,qBAAqB,CAAC,CAAC;IACnD,YAAY,EAAE,CAAC,MAAM,CAAC,CAAC;IACvB,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IACX,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;IACf,KAAK,EAAE,EAAE,CAAC;IACV,OAAO,EAAE,EAAE,CAAC;IACZ,IAAI,EAAE,EAAE,CAAC;CACT"}
@@ -9,5 +9,5 @@ type ClientOptions = {
9
9
  loggerDisabled: boolean;
10
10
  };
11
11
  declare const defaultClientOptions: ClientOptions;
12
- export { type ClientOptions, defaultClientOptions };
12
+ export { defaultClientOptions, type ClientOptions };
13
13
  //# sourceMappingURL=client-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-options.d.ts","sourceRoot":"","sources":["../../../src/client/types/client-options.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,GAAG;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,QAAA,MAAM,oBAAoB,EAAE,aAS3B,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,KAAK,aAAa,EAAE,CAAC"}
@@ -6,9 +6,9 @@ const defaultClientOptions = {
6
6
  port: 19132,
7
7
  protocolVersion: 11,
8
8
  mtuSize: 1492,
9
- clientId: BigInt(Math.floor(Math.random() * 1000000000000000000)),
9
+ clientId: BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)),
10
10
  debug: false,
11
- timeout: 5000,
11
+ timeout: 10000,
12
12
  loggerDisabled: false,
13
13
  };
14
14
  exports.defaultClientOptions = defaultClientOptions;
@@ -0,0 +1,3 @@
1
+ export * from "./client-events";
2
+ export * from "./client-options";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./client-events"), exports);
18
+ __exportStar(require("./client-options"), exports);
@@ -1,2 +1,3 @@
1
+ export * from "./decorators";
1
2
  export * from "./Logger";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC"}
@@ -14,4 +14,5 @@ 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("./decorators"), exports);
17
18
  __exportStar(require("./Logger"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanctumterra/raknet",
3
- "version": "1.3.79",
3
+ "version": "1.3.80",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "commonjs",
@@ -9,8 +9,8 @@
9
9
  "watch": "tsc --watch",
10
10
  "format": "npx @biomejs/biome format ./src",
11
11
  "lint": "npx @biomejs/biome lint ./src",
12
- "lint-write": "npx @biomejs/biome lint --write ./src",
13
- "format-write": "npx @biomejs/biome format --write ./src"
12
+ "lint:write": "npx @biomejs/biome lint --write ./src",
13
+ "format:write": "npx @biomejs/biome format --write ./src"
14
14
  },
15
15
  "keywords": [],
16
16
  "author": "",
@@ -1 +0,0 @@
1
- {"version":3,"file":"client-events.d.ts","sourceRoot":"","sources":["../../src/client/client-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,GAAG,E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,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,QAAA,MAAM,oBAAoB,EAAE,aAS3B,CAAC;AAEF,OAAO,EAAE,KAAK,aAAa,EAAE,oBAAoB,EAAE,CAAC"}
@@ -1,10 +0,0 @@
1
- type ClientOptions = {
2
- address: string;
3
- port: number;
4
- mtuSize: number;
5
- debug: boolean;
6
- timeout: number;
7
- };
8
- declare const defaultClientOptions: ClientOptions;
9
- export { type ClientOptions, defaultClientOptions };
10
- //# sourceMappingURL=client_options.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client_options.d.ts","sourceRoot":"","sources":["../../src/client/client_options.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,GAAG;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,QAAA,MAAM,oBAAoB,EAAE,aAM3B,CAAC;AAEF,OAAO,EAAE,KAAK,aAAa,EAAE,oBAAoB,EAAE,CAAC"}
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultClientOptions = void 0;
4
- const defaultClientOptions = {
5
- address: "127.0.0.1",
6
- port: 19132,
7
- mtuSize: 1492,
8
- debug: false,
9
- timeout: 5000,
10
- };
11
- exports.defaultClientOptions = defaultClientOptions;