@serenityjs/raknet 0.5.0 → 0.5.1-beta-20240915201114
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/index.js +998 -673
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
7
|
var __export = (target, all) => {
|
|
7
8
|
for (var name in all)
|
|
8
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,14 +17,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
return to;
|
|
17
18
|
};
|
|
18
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
20
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
21
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
|
-
if (decorator = decorators[i])
|
|
23
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
-
if (kind && result) __defProp(target, key, result);
|
|
25
|
-
return result;
|
|
26
|
-
};
|
|
27
20
|
|
|
28
21
|
// src/index.ts
|
|
29
22
|
var src_exports = {};
|
|
@@ -78,10 +71,7 @@ var import_nbt = require("@serenityjs/nbt");
|
|
|
78
71
|
function Proto(id) {
|
|
79
72
|
return function(target) {
|
|
80
73
|
target.id = id;
|
|
81
|
-
const metadata = Reflect.getOwnMetadata(
|
|
82
|
-
"properties",
|
|
83
|
-
target.prototype
|
|
84
|
-
);
|
|
74
|
+
const metadata = Reflect.getOwnMetadata("properties", target.prototype);
|
|
85
75
|
const properties = Object.getOwnPropertyNames(target.prototype);
|
|
86
76
|
if (!properties.includes("serialize"))
|
|
87
77
|
target.prototype.serialize = function() {
|
|
@@ -90,10 +80,7 @@ function Proto(id) {
|
|
|
90
80
|
if (!metadata) return this.getBuffer();
|
|
91
81
|
for (const { name, type, endian, parameter } of metadata) {
|
|
92
82
|
if (parameter) {
|
|
93
|
-
if (type.prototype === import_nbt.CompoundTag.prototype)
|
|
94
|
-
throw new Error(
|
|
95
|
-
"Parameters are not supported for CompoundTag serialization."
|
|
96
|
-
);
|
|
83
|
+
if (type.prototype === import_nbt.CompoundTag.prototype) throw new Error("Parameters are not supported for CompoundTag serialization.");
|
|
97
84
|
const value = this[parameter];
|
|
98
85
|
const dtype = type;
|
|
99
86
|
const data = this[name];
|
|
@@ -112,52 +99,37 @@ function Proto(id) {
|
|
|
112
99
|
}
|
|
113
100
|
return this.getBuffer();
|
|
114
101
|
};
|
|
115
|
-
if (!properties.includes("deserialize"))
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
this[name] =
|
|
129
|
-
this,
|
|
130
|
-
endian,
|
|
131
|
-
value
|
|
132
|
-
);
|
|
102
|
+
if (!properties.includes("deserialize")) target.prototype.deserialize = function() {
|
|
103
|
+
if (this.binary.length === 0) return this;
|
|
104
|
+
target.id_type.read(this);
|
|
105
|
+
if (!metadata) return this;
|
|
106
|
+
for (const { name, type, endian, parameter } of metadata) {
|
|
107
|
+
if (parameter) {
|
|
108
|
+
if (type.prototype === import_nbt.CompoundTag.prototype) throw new Error("Parameters are not supported for CompoundTag deserialization.");
|
|
109
|
+
const value = this[parameter];
|
|
110
|
+
const dtype = type;
|
|
111
|
+
this[name] = dtype.read(this, endian, value);
|
|
112
|
+
} else {
|
|
113
|
+
if (type.prototype === import_nbt.CompoundTag.prototype) {
|
|
114
|
+
const ctype = type;
|
|
115
|
+
this[name] = ctype.read(this, endian);
|
|
133
116
|
} else {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
this[name] = ctype.read(
|
|
137
|
-
this,
|
|
138
|
-
endian
|
|
139
|
-
);
|
|
140
|
-
} else {
|
|
141
|
-
const dtype = type;
|
|
142
|
-
this[name] = dtype.read(
|
|
143
|
-
this,
|
|
144
|
-
endian
|
|
145
|
-
);
|
|
146
|
-
}
|
|
117
|
+
const dtype = type;
|
|
118
|
+
this[name] = dtype.read(this, endian);
|
|
147
119
|
}
|
|
148
120
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (!properties.includes("getIdType"))
|
|
156
|
-
target.
|
|
157
|
-
|
|
158
|
-
};
|
|
121
|
+
}
|
|
122
|
+
return this;
|
|
123
|
+
};
|
|
124
|
+
if (!properties.includes("getId")) target.prototype.getId = function() {
|
|
125
|
+
return target.id;
|
|
126
|
+
};
|
|
127
|
+
if (!properties.includes("getIdType")) target.prototype.getIdType = function() {
|
|
128
|
+
return target.id_type;
|
|
129
|
+
};
|
|
159
130
|
};
|
|
160
131
|
}
|
|
132
|
+
__name(Proto, "Proto");
|
|
161
133
|
|
|
162
134
|
// src/decorators/serialize.ts
|
|
163
135
|
var import_binarystream = require("@serenityjs/binarystream");
|
|
@@ -165,105 +137,120 @@ function Serialize(type, endian = import_binarystream.Endianness.Big, parameter)
|
|
|
165
137
|
if (!type) throw new Error("@Serialize() failed, no type provided.");
|
|
166
138
|
return function(target, name) {
|
|
167
139
|
const properties = Reflect.getMetadata("properties", target) || [];
|
|
168
|
-
properties.push({
|
|
140
|
+
properties.push({
|
|
141
|
+
name,
|
|
142
|
+
type,
|
|
143
|
+
endian,
|
|
144
|
+
parameter
|
|
145
|
+
});
|
|
169
146
|
Reflect.defineMetadata("properties", properties, target);
|
|
170
147
|
};
|
|
171
148
|
}
|
|
149
|
+
__name(Serialize, "Serialize");
|
|
172
150
|
|
|
173
151
|
// src/proto/types/type.ts
|
|
174
152
|
var import_binarystream2 = require("@serenityjs/binarystream");
|
|
175
|
-
var DataType = class {
|
|
153
|
+
var DataType = class DataType2 {
|
|
154
|
+
static {
|
|
155
|
+
__name(this, "DataType");
|
|
156
|
+
}
|
|
176
157
|
/**
|
|
177
|
-
|
|
178
|
-
|
|
158
|
+
* Creates a new data type.
|
|
159
|
+
*/
|
|
179
160
|
constructor(..._arguments_) {
|
|
180
161
|
return;
|
|
181
162
|
}
|
|
182
163
|
/**
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
164
|
+
* Reads the data type from a binary stream.
|
|
165
|
+
* @param _stream The binary stream to read from.
|
|
166
|
+
* @param _endian The endianness to use.
|
|
167
|
+
* @param _parameter An optional parameter.
|
|
168
|
+
* @returns The data type.
|
|
169
|
+
*/
|
|
189
170
|
static read(_stream, _endian = import_binarystream2.Endianness.Big, _parameter) {
|
|
190
171
|
return;
|
|
191
172
|
}
|
|
192
173
|
/**
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
174
|
+
* Writes the data type to a binary stream.
|
|
175
|
+
* @param _stream The binary stream to write to.
|
|
176
|
+
* @param _value The data type to write.
|
|
177
|
+
* @param _endian The endianness to use.
|
|
178
|
+
* @param _parameter An optional parameter.
|
|
179
|
+
*/
|
|
199
180
|
static write(_stream, _value, _endian = import_binarystream2.Endianness.Big, _parameter) {
|
|
200
181
|
return;
|
|
201
182
|
}
|
|
202
183
|
};
|
|
203
184
|
|
|
204
185
|
// src/proto/types/magic.ts
|
|
205
|
-
var MagicBuffer = Buffer.from(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
186
|
+
var MagicBuffer = Buffer.from("\0\xFF\xFF\0\xFE\xFE\xFE\xFE\xFD\xFD\xFD\xFD4Vx", "binary");
|
|
187
|
+
var Magic = class Magic2 extends DataType {
|
|
188
|
+
static {
|
|
189
|
+
__name(this, "Magic");
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Reads the magic data type from a binary stream.
|
|
193
|
+
* @param stream The binary stream to read from.
|
|
194
|
+
* @returns The magic data type.
|
|
195
|
+
*/
|
|
215
196
|
static read(stream) {
|
|
216
197
|
return stream.readBuffer(MagicBuffer.length);
|
|
217
198
|
}
|
|
218
199
|
/**
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
200
|
+
* Writes the magic data type to a binary stream.
|
|
201
|
+
* @param stream The binary stream to write to.
|
|
202
|
+
*/
|
|
222
203
|
static write(stream) {
|
|
223
204
|
stream.writeBuffer(MagicBuffer);
|
|
224
205
|
}
|
|
225
206
|
};
|
|
226
207
|
|
|
227
208
|
// src/proto/types/mtu.ts
|
|
228
|
-
var MTU = class extends DataType {
|
|
209
|
+
var MTU = class MTU2 extends DataType {
|
|
210
|
+
static {
|
|
211
|
+
__name(this, "MTU");
|
|
212
|
+
}
|
|
229
213
|
/**
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
214
|
+
* Reads the mtu data type from a binary stream.
|
|
215
|
+
* @param stream The binary stream to read from.
|
|
216
|
+
* @returns The mtu data type.
|
|
217
|
+
*/
|
|
234
218
|
static read(stream) {
|
|
235
219
|
return stream.getBuffer().byteLength;
|
|
236
220
|
}
|
|
237
221
|
/**
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
222
|
+
* Writes the mtu data type to a binary stream.
|
|
223
|
+
* @param stream The binary stream to write to.
|
|
224
|
+
* @param value The value to write.
|
|
225
|
+
*/
|
|
242
226
|
static write(stream, value) {
|
|
243
227
|
stream.writeBuffer(Buffer.alloc(value - stream.getBuffer().length));
|
|
244
228
|
}
|
|
245
229
|
};
|
|
246
230
|
|
|
247
231
|
// src/proto/types/address.ts
|
|
248
|
-
var Address = class
|
|
232
|
+
var Address = class Address2 extends DataType {
|
|
233
|
+
static {
|
|
234
|
+
__name(this, "Address");
|
|
235
|
+
}
|
|
249
236
|
/**
|
|
250
|
-
|
|
251
|
-
|
|
237
|
+
* The address of the data type.
|
|
238
|
+
*/
|
|
252
239
|
address;
|
|
253
240
|
/**
|
|
254
|
-
|
|
255
|
-
|
|
241
|
+
* The port of the data type.
|
|
242
|
+
*/
|
|
256
243
|
port;
|
|
257
244
|
/**
|
|
258
|
-
|
|
259
|
-
|
|
245
|
+
* The version of the data type.
|
|
246
|
+
*/
|
|
260
247
|
version;
|
|
261
248
|
/**
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
249
|
+
* Initializes a new instance of the Address data type.
|
|
250
|
+
* @param address The address of the data type.
|
|
251
|
+
* @param port The port of the data type.
|
|
252
|
+
* @param version The version of the data type.
|
|
253
|
+
*/
|
|
267
254
|
constructor(address, port, version) {
|
|
268
255
|
super();
|
|
269
256
|
this.address = address;
|
|
@@ -271,30 +258,26 @@ var Address = class _Address extends DataType {
|
|
|
271
258
|
this.version = version;
|
|
272
259
|
}
|
|
273
260
|
/**
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
261
|
+
* Converts the Address data type to a NetworkIdentifier.
|
|
262
|
+
*
|
|
263
|
+
* @param identifier The NetworkIdentifier.
|
|
264
|
+
* @returns The NetworkIdentifier.
|
|
265
|
+
*/
|
|
279
266
|
static fromIdentifier(identifier) {
|
|
280
|
-
return new
|
|
281
|
-
identifier.address,
|
|
282
|
-
identifier.port,
|
|
283
|
-
identifier.family === "IPv4" ? 4 : 6
|
|
284
|
-
);
|
|
267
|
+
return new Address2(identifier.address, identifier.port, identifier.family === "IPv4" ? 4 : 6);
|
|
285
268
|
}
|
|
286
269
|
/**
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
270
|
+
* Reads the Address data type from a binary stream.
|
|
271
|
+
* @param stream The binary stream to read from.
|
|
272
|
+
* @returns The Address data type.
|
|
273
|
+
*/
|
|
291
274
|
static read(stream) {
|
|
292
275
|
const version = stream.readUint8();
|
|
293
276
|
if (version === 4) {
|
|
294
277
|
const addressBuffer = stream.read(4);
|
|
295
278
|
const address = addressBuffer.map((byte) => -byte - 1 & 255).join(".");
|
|
296
279
|
const port = stream.readUShort();
|
|
297
|
-
return new
|
|
280
|
+
return new Address2(address, port, version);
|
|
298
281
|
} else {
|
|
299
282
|
stream.skip(2);
|
|
300
283
|
const port = stream.readUShort();
|
|
@@ -302,14 +285,14 @@ var Address = class _Address extends DataType {
|
|
|
302
285
|
const addressBuffer = stream.read(4);
|
|
303
286
|
const address = addressBuffer.filter((byte) => byte !== 255).join(".");
|
|
304
287
|
stream.skip(4);
|
|
305
|
-
return new
|
|
288
|
+
return new Address2(address, port, version);
|
|
306
289
|
}
|
|
307
290
|
}
|
|
308
291
|
/**
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
292
|
+
* Writes the Address data type to a binary stream.
|
|
293
|
+
* @param stream The binary stream to write to.
|
|
294
|
+
* @param value The value to write.
|
|
295
|
+
*/
|
|
313
296
|
static write(stream, value) {
|
|
314
297
|
const { address, port, version } = value;
|
|
315
298
|
stream.writeUint8(version);
|
|
@@ -325,7 +308,8 @@ var Address = class _Address extends DataType {
|
|
|
325
308
|
var import_binarystream3 = require("@serenityjs/binarystream");
|
|
326
309
|
|
|
327
310
|
// src/enums/packet.ts
|
|
328
|
-
var Packet
|
|
311
|
+
var Packet;
|
|
312
|
+
(function(Packet2) {
|
|
329
313
|
Packet2[Packet2["ConnectedPing"] = 0] = "ConnectedPing";
|
|
330
314
|
Packet2[Packet2["UnconnectedPing"] = 1] = "UnconnectedPing";
|
|
331
315
|
Packet2[Packet2["ConnectedPong"] = 3] = "ConnectedPong";
|
|
@@ -342,36 +326,36 @@ var Packet = /* @__PURE__ */ ((Packet2) => {
|
|
|
342
326
|
Packet2[Packet2["FrameSet"] = 128] = "FrameSet";
|
|
343
327
|
Packet2[Packet2["Nack"] = 160] = "Nack";
|
|
344
328
|
Packet2[Packet2["Ack"] = 192] = "Ack";
|
|
345
|
-
|
|
346
|
-
})(Packet || {});
|
|
329
|
+
})(Packet || (Packet = {}));
|
|
347
330
|
|
|
348
331
|
// src/enums/bit-flags.ts
|
|
349
|
-
var Bitflags
|
|
332
|
+
var Bitflags;
|
|
333
|
+
(function(Bitflags2) {
|
|
350
334
|
Bitflags2[Bitflags2["Valid"] = 128] = "Valid";
|
|
351
335
|
Bitflags2[Bitflags2["Ack"] = 64] = "Ack";
|
|
352
336
|
Bitflags2[Bitflags2["Nak"] = 32] = "Nak";
|
|
353
337
|
Bitflags2[Bitflags2["Split"] = 16] = "Split";
|
|
354
|
-
|
|
355
|
-
})(Bitflags || {});
|
|
338
|
+
})(Bitflags || (Bitflags = {}));
|
|
356
339
|
|
|
357
340
|
// src/enums/priority.ts
|
|
358
|
-
var Priority
|
|
341
|
+
var Priority;
|
|
342
|
+
(function(Priority2) {
|
|
359
343
|
Priority2[Priority2["Normal"] = 0] = "Normal";
|
|
360
344
|
Priority2[Priority2["Immediate"] = 1] = "Immediate";
|
|
361
|
-
|
|
362
|
-
})(Priority || {});
|
|
345
|
+
})(Priority || (Priority = {}));
|
|
363
346
|
|
|
364
347
|
// src/enums/status.ts
|
|
365
|
-
var Status
|
|
348
|
+
var Status;
|
|
349
|
+
(function(Status2) {
|
|
366
350
|
Status2[Status2["Connecting"] = 0] = "Connecting";
|
|
367
351
|
Status2[Status2["Connected"] = 1] = "Connected";
|
|
368
352
|
Status2[Status2["Disconnecting"] = 2] = "Disconnecting";
|
|
369
353
|
Status2[Status2["Disconnected"] = 3] = "Disconnected";
|
|
370
|
-
|
|
371
|
-
})(Status || {});
|
|
354
|
+
})(Status || (Status = {}));
|
|
372
355
|
|
|
373
356
|
// src/enums/reliability.ts
|
|
374
|
-
var Reliability
|
|
357
|
+
var Reliability;
|
|
358
|
+
(function(Reliability2) {
|
|
375
359
|
Reliability2[Reliability2["Unreliable"] = 0] = "Unreliable";
|
|
376
360
|
Reliability2[Reliability2["UnreliableSequenced"] = 1] = "UnreliableSequenced";
|
|
377
361
|
Reliability2[Reliability2["Reliable"] = 2] = "Reliable";
|
|
@@ -380,122 +364,124 @@ var Reliability = /* @__PURE__ */ ((Reliability2) => {
|
|
|
380
364
|
Reliability2[Reliability2["UnreliableWithAckReceipt"] = 5] = "UnreliableWithAckReceipt";
|
|
381
365
|
Reliability2[Reliability2["ReliableWithAckReceipt"] = 6] = "ReliableWithAckReceipt";
|
|
382
366
|
Reliability2[Reliability2["ReliableOrderedWithAckReceipt"] = 7] = "ReliableOrderedWithAckReceipt";
|
|
383
|
-
|
|
384
|
-
})(Reliability || {});
|
|
367
|
+
})(Reliability || (Reliability = {}));
|
|
385
368
|
|
|
386
369
|
// src/proto/types/frame.ts
|
|
387
|
-
var Frame = class
|
|
370
|
+
var Frame = class Frame2 extends DataType {
|
|
371
|
+
static {
|
|
372
|
+
__name(this, "Frame");
|
|
373
|
+
}
|
|
388
374
|
/**
|
|
389
|
-
|
|
390
|
-
|
|
375
|
+
* The reliability of the frame.
|
|
376
|
+
*/
|
|
391
377
|
reliability;
|
|
392
378
|
/**
|
|
393
|
-
|
|
394
|
-
|
|
379
|
+
* The reliable index of the frame.
|
|
380
|
+
*/
|
|
395
381
|
reliableIndex;
|
|
396
382
|
/**
|
|
397
|
-
|
|
398
|
-
|
|
383
|
+
* The sequence index of the frame.
|
|
384
|
+
*/
|
|
399
385
|
sequenceIndex;
|
|
400
386
|
/**
|
|
401
|
-
|
|
402
|
-
|
|
387
|
+
* The order index of the frame.
|
|
388
|
+
*/
|
|
403
389
|
orderIndex;
|
|
404
390
|
/**
|
|
405
|
-
|
|
406
|
-
|
|
391
|
+
* The order channel of the frame.
|
|
392
|
+
*/
|
|
407
393
|
orderChannel;
|
|
408
394
|
/**
|
|
409
|
-
|
|
410
|
-
|
|
395
|
+
* The split size of the frame.
|
|
396
|
+
*/
|
|
411
397
|
splitSize;
|
|
412
398
|
/**
|
|
413
|
-
|
|
414
|
-
|
|
399
|
+
* The split id of the frame.
|
|
400
|
+
*/
|
|
415
401
|
splitId;
|
|
416
402
|
/**
|
|
417
|
-
|
|
418
|
-
|
|
403
|
+
* The split index of the frame.
|
|
404
|
+
*/
|
|
419
405
|
splitIndex;
|
|
420
406
|
/**
|
|
421
|
-
|
|
422
|
-
|
|
407
|
+
* The payload of the frame.
|
|
408
|
+
*/
|
|
423
409
|
payload;
|
|
424
410
|
/**
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
411
|
+
* Checks if the frame is split.
|
|
412
|
+
* @returns True if the frame is split; otherwise, false.
|
|
413
|
+
*/
|
|
428
414
|
isSplit() {
|
|
429
415
|
return this.splitSize > 0;
|
|
430
416
|
}
|
|
431
417
|
/**
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
418
|
+
* Checks if the frame is reliable.
|
|
419
|
+
* @returns True if the frame is reliable; otherwise, false.
|
|
420
|
+
*/
|
|
435
421
|
isReliable() {
|
|
436
422
|
const values = [
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
423
|
+
Reliability.Reliable,
|
|
424
|
+
Reliability.ReliableOrdered,
|
|
425
|
+
Reliability.ReliableSequenced,
|
|
426
|
+
Reliability.ReliableWithAckReceipt,
|
|
427
|
+
Reliability.ReliableOrderedWithAckReceipt
|
|
442
428
|
];
|
|
443
429
|
return values.includes(this.reliability);
|
|
444
430
|
}
|
|
445
431
|
/**
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
432
|
+
* Checks if the frame is sequenced.
|
|
433
|
+
* @returns True if the frame is sequenced; otherwise, false.
|
|
434
|
+
*/
|
|
449
435
|
isSequenced() {
|
|
450
436
|
const values = [
|
|
451
|
-
|
|
452
|
-
|
|
437
|
+
Reliability.ReliableSequenced,
|
|
438
|
+
Reliability.UnreliableSequenced
|
|
453
439
|
];
|
|
454
440
|
return values.includes(this.reliability);
|
|
455
441
|
}
|
|
456
442
|
/**
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
443
|
+
* Checks if the frame is ordered.
|
|
444
|
+
* @returns True if the frame is ordered; otherwise, false.
|
|
445
|
+
*/
|
|
460
446
|
isOrdered() {
|
|
461
447
|
const values = [
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
448
|
+
Reliability.UnreliableSequenced,
|
|
449
|
+
Reliability.ReliableOrdered,
|
|
450
|
+
Reliability.ReliableSequenced,
|
|
451
|
+
Reliability.ReliableOrderedWithAckReceipt
|
|
466
452
|
];
|
|
467
453
|
return values.includes(this.reliability);
|
|
468
454
|
}
|
|
469
455
|
/**
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
456
|
+
* Checks if the frame is order exclusive.
|
|
457
|
+
* @returns True if the frame is order exclusive; otherwise, false.
|
|
458
|
+
*/
|
|
473
459
|
isOrderExclusive() {
|
|
474
460
|
const values = [
|
|
475
|
-
|
|
476
|
-
|
|
461
|
+
Reliability.ReliableOrdered,
|
|
462
|
+
Reliability.ReliableOrderedWithAckReceipt
|
|
477
463
|
];
|
|
478
464
|
return values.includes(this.reliability);
|
|
479
465
|
}
|
|
480
466
|
/**
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
467
|
+
* Gets the byte length of the frame.
|
|
468
|
+
* @returns The byte length of the frame.
|
|
469
|
+
*/
|
|
484
470
|
getByteLength() {
|
|
485
471
|
return 3 + this.payload.byteLength + (this.isReliable() ? 3 : 0) + (this.isSequenced() ? 3 : 0) + (this.isOrdered() ? 4 : 0) + (this.isSplit() ? 10 : 0);
|
|
486
472
|
}
|
|
487
473
|
/**
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
474
|
+
* Reads the Frame data type from a binary stream.
|
|
475
|
+
* @param stream The binary stream to read from.
|
|
476
|
+
* @returns The Frame data type.
|
|
477
|
+
*/
|
|
492
478
|
static read(stream) {
|
|
493
479
|
const frames = [];
|
|
494
480
|
do {
|
|
495
|
-
const frame = new
|
|
481
|
+
const frame = new Frame2();
|
|
496
482
|
const header = stream.readUint8();
|
|
497
483
|
frame.reliability = (header & 224) >> 5;
|
|
498
|
-
const split = (header &
|
|
484
|
+
const split = (header & Bitflags.Split) !== 0;
|
|
499
485
|
const length = Math.ceil(stream.readUint16() / 8);
|
|
500
486
|
if (frame.isReliable()) {
|
|
501
487
|
frame.reliableIndex = stream.readUint24(import_binarystream3.Endianness.Little);
|
|
@@ -518,14 +504,12 @@ var Frame = class _Frame extends DataType {
|
|
|
518
504
|
return frames;
|
|
519
505
|
}
|
|
520
506
|
/**
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
507
|
+
* Writes the Frame data type to a binary stream.
|
|
508
|
+
* @param stream The binary stream to write to.
|
|
509
|
+
*/
|
|
524
510
|
static write(stream, value) {
|
|
525
511
|
for (const frame of value) {
|
|
526
|
-
stream.writeUint8(
|
|
527
|
-
frame.reliability << 5 | (frame.isSplit() ? 16 /* Split */ : 0)
|
|
528
|
-
);
|
|
512
|
+
stream.writeUint8(frame.reliability << 5 | (frame.isSplit() ? Bitflags.Split : 0));
|
|
529
513
|
stream.writeUint16(frame.payload.byteLength << 3);
|
|
530
514
|
if (frame.isReliable()) {
|
|
531
515
|
stream.writeUint24(frame.reliableIndex, import_binarystream3.Endianness.Little);
|
|
@@ -548,21 +532,24 @@ var Frame = class _Frame extends DataType {
|
|
|
548
532
|
};
|
|
549
533
|
|
|
550
534
|
// src/proto/types/system-address.ts
|
|
551
|
-
var SystemAddress = class extends DataType {
|
|
535
|
+
var SystemAddress = class SystemAddress2 extends DataType {
|
|
536
|
+
static {
|
|
537
|
+
__name(this, "SystemAddress");
|
|
538
|
+
}
|
|
552
539
|
/**
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
540
|
+
* Converts the Address data type to a NetworkIdentifier.
|
|
541
|
+
*
|
|
542
|
+
* @param identifier The NetworkIdentifier.
|
|
543
|
+
* @returns The NetworkIdentifier.
|
|
544
|
+
*/
|
|
558
545
|
static fromIdentifier(identifier) {
|
|
559
546
|
return new Address(identifier.address, identifier.port, identifier.version);
|
|
560
547
|
}
|
|
561
548
|
/**
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
549
|
+
* Reads the Address data type from a binary stream.
|
|
550
|
+
* @param stream The binary stream to read from.
|
|
551
|
+
* @returns The Address data type.
|
|
552
|
+
*/
|
|
566
553
|
static read(stream) {
|
|
567
554
|
const addresses = [];
|
|
568
555
|
for (let index = 0; index < 20; index++) {
|
|
@@ -572,64 +559,72 @@ var SystemAddress = class extends DataType {
|
|
|
572
559
|
return addresses;
|
|
573
560
|
}
|
|
574
561
|
/**
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
562
|
+
* Writes the Address data type to a binary stream.
|
|
563
|
+
* @param stream The binary stream to write to.
|
|
564
|
+
* @param value The value to write.
|
|
565
|
+
*/
|
|
579
566
|
static write(stream) {
|
|
580
567
|
const addresses = [
|
|
581
|
-
{
|
|
568
|
+
{
|
|
569
|
+
address: "127.0.0.1",
|
|
570
|
+
port: 0,
|
|
571
|
+
version: 4
|
|
572
|
+
}
|
|
582
573
|
];
|
|
583
574
|
for (let index = 0; index < 20; index++) {
|
|
584
|
-
Address.write(
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
575
|
+
Address.write(stream, addresses[index] || {
|
|
576
|
+
address: "0.0.0.0",
|
|
577
|
+
port: 0,
|
|
578
|
+
version: 4
|
|
579
|
+
});
|
|
588
580
|
}
|
|
589
581
|
}
|
|
590
582
|
};
|
|
591
583
|
|
|
592
584
|
// src/proto/data/base.ts
|
|
593
585
|
var import_binarystream4 = require("@serenityjs/binarystream");
|
|
594
|
-
var BasePacket = class extends import_binarystream4.BinaryStream {
|
|
586
|
+
var BasePacket = class BasePacket2 extends import_binarystream4.BinaryStream {
|
|
587
|
+
static {
|
|
588
|
+
__name(this, "BasePacket");
|
|
589
|
+
}
|
|
595
590
|
/**
|
|
596
|
-
|
|
597
|
-
|
|
591
|
+
* The packet id.
|
|
592
|
+
*/
|
|
598
593
|
static id;
|
|
599
594
|
/**
|
|
600
|
-
|
|
601
|
-
|
|
595
|
+
* The packet id data type.
|
|
596
|
+
*/
|
|
602
597
|
static id_type = import_binarystream4.Uint8;
|
|
603
598
|
/**
|
|
604
|
-
|
|
605
|
-
|
|
599
|
+
* Flushes the binary stream.
|
|
600
|
+
*/
|
|
606
601
|
flush() {
|
|
607
602
|
this.binary = [];
|
|
608
603
|
}
|
|
609
604
|
/**
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
605
|
+
* Gets the packet id.
|
|
606
|
+
* @returns The packet id.
|
|
607
|
+
*/
|
|
613
608
|
getId() {
|
|
614
609
|
throw new Error("BasePacket.getId() is not implemented.");
|
|
615
610
|
}
|
|
616
611
|
/**
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
612
|
+
* Gets the packet id data type.
|
|
613
|
+
* @returns The packet id data type.
|
|
614
|
+
*/
|
|
620
615
|
getIdType() {
|
|
621
616
|
throw new Error("BasePacket.getIdType() is not implemented.");
|
|
622
617
|
}
|
|
623
618
|
/**
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
619
|
+
* Serializes the packet.
|
|
620
|
+
* @returns The serialized packet.
|
|
621
|
+
*/
|
|
627
622
|
serialize() {
|
|
628
623
|
throw new Error("BasePacket.serialize() is not implemented.");
|
|
629
624
|
}
|
|
630
625
|
/**
|
|
631
|
-
|
|
632
|
-
|
|
626
|
+
* Deserializes the packet.
|
|
627
|
+
*/
|
|
633
628
|
deserialize() {
|
|
634
629
|
throw new Error("BasePacket.deserialize() is not implemented.");
|
|
635
630
|
}
|
|
@@ -637,211 +632,481 @@ var BasePacket = class extends import_binarystream4.BinaryStream {
|
|
|
637
632
|
|
|
638
633
|
// src/proto/data/unconnected-ping.ts
|
|
639
634
|
var import_binarystream5 = require("@serenityjs/binarystream");
|
|
640
|
-
|
|
635
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
636
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
637
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
638
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
639
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
640
|
+
}
|
|
641
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
642
|
+
function _ts_metadata(k, v) {
|
|
643
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
644
|
+
}
|
|
645
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
646
|
+
var UnconnectedPing = class UnconnectedPing2 extends BasePacket {
|
|
647
|
+
static {
|
|
648
|
+
__name(this, "UnconnectedPing");
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* The timestamp of the ping.
|
|
652
|
+
*/
|
|
641
653
|
timestamp;
|
|
654
|
+
/**
|
|
655
|
+
* The magic bytes of the ping.
|
|
656
|
+
*/
|
|
642
657
|
magic;
|
|
658
|
+
/**
|
|
659
|
+
* The client guid of the ping.
|
|
660
|
+
*/
|
|
643
661
|
client;
|
|
644
662
|
};
|
|
645
|
-
|
|
646
|
-
Serialize(import_binarystream5.Long)
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
663
|
+
_ts_decorate([
|
|
664
|
+
Serialize(import_binarystream5.Long),
|
|
665
|
+
_ts_metadata("design:type", typeof BigInt === "undefined" ? Object : BigInt)
|
|
666
|
+
], UnconnectedPing.prototype, "timestamp", void 0);
|
|
667
|
+
_ts_decorate([
|
|
668
|
+
Serialize(Magic),
|
|
669
|
+
_ts_metadata("design:type", typeof Buffer === "undefined" ? Object : Buffer)
|
|
670
|
+
], UnconnectedPing.prototype, "magic", void 0);
|
|
671
|
+
_ts_decorate([
|
|
672
|
+
Serialize(import_binarystream5.Long),
|
|
673
|
+
_ts_metadata("design:type", typeof BigInt === "undefined" ? Object : BigInt)
|
|
674
|
+
], UnconnectedPing.prototype, "client", void 0);
|
|
675
|
+
UnconnectedPing = _ts_decorate([
|
|
676
|
+
Proto(Packet.UnconnectedPing)
|
|
656
677
|
], UnconnectedPing);
|
|
657
678
|
|
|
658
679
|
// src/proto/data/unconnected-pong.ts
|
|
659
680
|
var import_binarystream6 = require("@serenityjs/binarystream");
|
|
660
|
-
|
|
681
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
682
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
683
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
684
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
685
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
686
|
+
}
|
|
687
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
688
|
+
function _ts_metadata2(k, v) {
|
|
689
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
690
|
+
}
|
|
691
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
692
|
+
var UnconnectedPong = class UnconnectedPong2 extends BasePacket {
|
|
693
|
+
static {
|
|
694
|
+
__name(this, "UnconnectedPong");
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* The timestamp of the pong.
|
|
698
|
+
*/
|
|
661
699
|
timestamp;
|
|
700
|
+
/**
|
|
701
|
+
* The server guid of the pong.
|
|
702
|
+
*/
|
|
662
703
|
guid;
|
|
704
|
+
/**
|
|
705
|
+
* The magic bytes of the pong.
|
|
706
|
+
*/
|
|
663
707
|
magic;
|
|
708
|
+
/**
|
|
709
|
+
* The server message of the pong.
|
|
710
|
+
*/
|
|
664
711
|
message;
|
|
665
712
|
};
|
|
666
|
-
|
|
667
|
-
Serialize(import_binarystream6.Long)
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
], UnconnectedPong.prototype, "
|
|
678
|
-
|
|
679
|
-
|
|
713
|
+
_ts_decorate2([
|
|
714
|
+
Serialize(import_binarystream6.Long),
|
|
715
|
+
_ts_metadata2("design:type", typeof BigInt === "undefined" ? Object : BigInt)
|
|
716
|
+
], UnconnectedPong.prototype, "timestamp", void 0);
|
|
717
|
+
_ts_decorate2([
|
|
718
|
+
Serialize(import_binarystream6.Long),
|
|
719
|
+
_ts_metadata2("design:type", typeof BigInt === "undefined" ? Object : BigInt)
|
|
720
|
+
], UnconnectedPong.prototype, "guid", void 0);
|
|
721
|
+
_ts_decorate2([
|
|
722
|
+
Serialize(Magic),
|
|
723
|
+
_ts_metadata2("design:type", typeof Buffer === "undefined" ? Object : Buffer)
|
|
724
|
+
], UnconnectedPong.prototype, "magic", void 0);
|
|
725
|
+
_ts_decorate2([
|
|
726
|
+
Serialize(import_binarystream6.String16),
|
|
727
|
+
_ts_metadata2("design:type", String)
|
|
728
|
+
], UnconnectedPong.prototype, "message", void 0);
|
|
729
|
+
UnconnectedPong = _ts_decorate2([
|
|
730
|
+
Proto(Packet.UnconnectedPong)
|
|
680
731
|
], UnconnectedPong);
|
|
681
732
|
|
|
682
733
|
// src/proto/data/open-connection-request-1.ts
|
|
683
734
|
var import_binarystream7 = require("@serenityjs/binarystream");
|
|
684
|
-
|
|
735
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
736
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
737
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
738
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
739
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
740
|
+
}
|
|
741
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
742
|
+
function _ts_metadata3(k, v) {
|
|
743
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
744
|
+
}
|
|
745
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
746
|
+
var OpenConnectionRequest1 = class OpenConnectionRequest12 extends BasePacket {
|
|
747
|
+
static {
|
|
748
|
+
__name(this, "OpenConnectionRequest1");
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* The magic bytes of the request.
|
|
752
|
+
*/
|
|
685
753
|
magic;
|
|
754
|
+
/**
|
|
755
|
+
* The protocol version of the request.
|
|
756
|
+
*/
|
|
686
757
|
protocol;
|
|
758
|
+
/**
|
|
759
|
+
* The maximum transfer unit of the request.
|
|
760
|
+
*/
|
|
687
761
|
mtu;
|
|
688
762
|
};
|
|
689
|
-
|
|
690
|
-
Serialize(Magic)
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
763
|
+
_ts_decorate3([
|
|
764
|
+
Serialize(Magic),
|
|
765
|
+
_ts_metadata3("design:type", typeof Buffer === "undefined" ? Object : Buffer)
|
|
766
|
+
], OpenConnectionRequest1.prototype, "magic", void 0);
|
|
767
|
+
_ts_decorate3([
|
|
768
|
+
Serialize(import_binarystream7.Uint8),
|
|
769
|
+
_ts_metadata3("design:type", Number)
|
|
770
|
+
], OpenConnectionRequest1.prototype, "protocol", void 0);
|
|
771
|
+
_ts_decorate3([
|
|
772
|
+
Serialize(MTU),
|
|
773
|
+
_ts_metadata3("design:type", Number)
|
|
774
|
+
], OpenConnectionRequest1.prototype, "mtu", void 0);
|
|
775
|
+
OpenConnectionRequest1 = _ts_decorate3([
|
|
776
|
+
Proto(Packet.OpenConnectionRequest1)
|
|
700
777
|
], OpenConnectionRequest1);
|
|
701
778
|
|
|
702
779
|
// src/proto/data/open-connection-reply-1.ts
|
|
703
780
|
var import_binarystream8 = require("@serenityjs/binarystream");
|
|
704
|
-
|
|
781
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
782
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
783
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
784
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
785
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
786
|
+
}
|
|
787
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
788
|
+
function _ts_metadata4(k, v) {
|
|
789
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
790
|
+
}
|
|
791
|
+
__name(_ts_metadata4, "_ts_metadata");
|
|
792
|
+
var OpenConnectionReply1 = class OpenConnectionReply12 extends BasePacket {
|
|
793
|
+
static {
|
|
794
|
+
__name(this, "OpenConnectionReply1");
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* The magic bytes of the reply.
|
|
798
|
+
*/
|
|
705
799
|
magic;
|
|
800
|
+
/**
|
|
801
|
+
* The server guid of the reply.
|
|
802
|
+
*/
|
|
706
803
|
guid;
|
|
804
|
+
/**
|
|
805
|
+
* If raknet is using security.
|
|
806
|
+
*/
|
|
707
807
|
security;
|
|
808
|
+
/**
|
|
809
|
+
* The maximum transfer unit of the reply.
|
|
810
|
+
*/
|
|
708
811
|
mtu;
|
|
709
812
|
};
|
|
710
|
-
|
|
711
|
-
Serialize(Magic)
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
], OpenConnectionReply1.prototype, "
|
|
722
|
-
|
|
723
|
-
|
|
813
|
+
_ts_decorate4([
|
|
814
|
+
Serialize(Magic),
|
|
815
|
+
_ts_metadata4("design:type", typeof Buffer === "undefined" ? Object : Buffer)
|
|
816
|
+
], OpenConnectionReply1.prototype, "magic", void 0);
|
|
817
|
+
_ts_decorate4([
|
|
818
|
+
Serialize(import_binarystream8.Long),
|
|
819
|
+
_ts_metadata4("design:type", typeof BigInt === "undefined" ? Object : BigInt)
|
|
820
|
+
], OpenConnectionReply1.prototype, "guid", void 0);
|
|
821
|
+
_ts_decorate4([
|
|
822
|
+
Serialize(import_binarystream8.Bool),
|
|
823
|
+
_ts_metadata4("design:type", Boolean)
|
|
824
|
+
], OpenConnectionReply1.prototype, "security", void 0);
|
|
825
|
+
_ts_decorate4([
|
|
826
|
+
Serialize(import_binarystream8.Short),
|
|
827
|
+
_ts_metadata4("design:type", Number)
|
|
828
|
+
], OpenConnectionReply1.prototype, "mtu", void 0);
|
|
829
|
+
OpenConnectionReply1 = _ts_decorate4([
|
|
830
|
+
Proto(Packet.OpenConnectionReply1)
|
|
724
831
|
], OpenConnectionReply1);
|
|
725
832
|
|
|
726
833
|
// src/proto/data/open-connection-request-2.ts
|
|
727
834
|
var import_binarystream9 = require("@serenityjs/binarystream");
|
|
728
|
-
|
|
835
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
836
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
837
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
838
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
839
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
840
|
+
}
|
|
841
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
842
|
+
function _ts_metadata5(k, v) {
|
|
843
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
844
|
+
}
|
|
845
|
+
__name(_ts_metadata5, "_ts_metadata");
|
|
846
|
+
var OpenConnectionRequest2 = class OpenConnectionRequest22 extends BasePacket {
|
|
847
|
+
static {
|
|
848
|
+
__name(this, "OpenConnectionRequest2");
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* The magic bytes of the request.
|
|
852
|
+
*/
|
|
729
853
|
magic;
|
|
854
|
+
/**
|
|
855
|
+
* The protocol version of the request.
|
|
856
|
+
*/
|
|
730
857
|
address;
|
|
858
|
+
/**
|
|
859
|
+
* The mtu of the request.
|
|
860
|
+
*/
|
|
731
861
|
mtu;
|
|
862
|
+
/**
|
|
863
|
+
* The client guid of the request.
|
|
864
|
+
*/
|
|
732
865
|
client;
|
|
733
866
|
};
|
|
734
|
-
|
|
735
|
-
Serialize(Magic)
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
], OpenConnectionRequest2.prototype, "
|
|
746
|
-
|
|
747
|
-
|
|
867
|
+
_ts_decorate5([
|
|
868
|
+
Serialize(Magic),
|
|
869
|
+
_ts_metadata5("design:type", typeof Buffer === "undefined" ? Object : Buffer)
|
|
870
|
+
], OpenConnectionRequest2.prototype, "magic", void 0);
|
|
871
|
+
_ts_decorate5([
|
|
872
|
+
Serialize(Address),
|
|
873
|
+
_ts_metadata5("design:type", typeof Address === "undefined" ? Object : Address)
|
|
874
|
+
], OpenConnectionRequest2.prototype, "address", void 0);
|
|
875
|
+
_ts_decorate5([
|
|
876
|
+
Serialize(import_binarystream9.Short),
|
|
877
|
+
_ts_metadata5("design:type", Number)
|
|
878
|
+
], OpenConnectionRequest2.prototype, "mtu", void 0);
|
|
879
|
+
_ts_decorate5([
|
|
880
|
+
Serialize(import_binarystream9.Long),
|
|
881
|
+
_ts_metadata5("design:type", typeof BigInt === "undefined" ? Object : BigInt)
|
|
882
|
+
], OpenConnectionRequest2.prototype, "client", void 0);
|
|
883
|
+
OpenConnectionRequest2 = _ts_decorate5([
|
|
884
|
+
Proto(Packet.OpenConnectionRequest2)
|
|
748
885
|
], OpenConnectionRequest2);
|
|
749
886
|
|
|
750
887
|
// src/proto/data/open-connection-reply-2.ts
|
|
751
888
|
var import_binarystream10 = require("@serenityjs/binarystream");
|
|
752
|
-
|
|
889
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
890
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
891
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
892
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
893
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
894
|
+
}
|
|
895
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
896
|
+
function _ts_metadata6(k, v) {
|
|
897
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
898
|
+
}
|
|
899
|
+
__name(_ts_metadata6, "_ts_metadata");
|
|
900
|
+
var OpenConnectionReply2 = class OpenConnectionReply22 extends BasePacket {
|
|
901
|
+
static {
|
|
902
|
+
__name(this, "OpenConnectionReply2");
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* The magic bytes of the reply.
|
|
906
|
+
*/
|
|
753
907
|
magic;
|
|
908
|
+
/**
|
|
909
|
+
* The server guid of the reply.
|
|
910
|
+
*/
|
|
754
911
|
guid;
|
|
912
|
+
/**
|
|
913
|
+
* Client adrress.
|
|
914
|
+
*/
|
|
755
915
|
address;
|
|
916
|
+
/**
|
|
917
|
+
* The maximum transfer unit of the reply.
|
|
918
|
+
*/
|
|
756
919
|
mtu;
|
|
920
|
+
/**
|
|
921
|
+
* If raknet is using encryption.
|
|
922
|
+
*/
|
|
757
923
|
encryption;
|
|
758
924
|
};
|
|
759
|
-
|
|
760
|
-
Serialize(Magic)
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
], OpenConnectionReply2.prototype, "
|
|
771
|
-
|
|
772
|
-
Serialize(import_binarystream10.
|
|
773
|
-
|
|
774
|
-
OpenConnectionReply2
|
|
775
|
-
|
|
925
|
+
_ts_decorate6([
|
|
926
|
+
Serialize(Magic),
|
|
927
|
+
_ts_metadata6("design:type", typeof Buffer === "undefined" ? Object : Buffer)
|
|
928
|
+
], OpenConnectionReply2.prototype, "magic", void 0);
|
|
929
|
+
_ts_decorate6([
|
|
930
|
+
Serialize(import_binarystream10.Long),
|
|
931
|
+
_ts_metadata6("design:type", typeof BigInt === "undefined" ? Object : BigInt)
|
|
932
|
+
], OpenConnectionReply2.prototype, "guid", void 0);
|
|
933
|
+
_ts_decorate6([
|
|
934
|
+
Serialize(Address),
|
|
935
|
+
_ts_metadata6("design:type", typeof Address === "undefined" ? Object : Address)
|
|
936
|
+
], OpenConnectionReply2.prototype, "address", void 0);
|
|
937
|
+
_ts_decorate6([
|
|
938
|
+
Serialize(import_binarystream10.Short),
|
|
939
|
+
_ts_metadata6("design:type", Number)
|
|
940
|
+
], OpenConnectionReply2.prototype, "mtu", void 0);
|
|
941
|
+
_ts_decorate6([
|
|
942
|
+
Serialize(import_binarystream10.Bool),
|
|
943
|
+
_ts_metadata6("design:type", Boolean)
|
|
944
|
+
], OpenConnectionReply2.prototype, "encryption", void 0);
|
|
945
|
+
OpenConnectionReply2 = _ts_decorate6([
|
|
946
|
+
Proto(Packet.OpenConnectionReply2)
|
|
776
947
|
], OpenConnectionReply2);
|
|
777
948
|
|
|
778
949
|
// src/proto/data/connected-pong.ts
|
|
779
950
|
var import_binarystream11 = require("@serenityjs/binarystream");
|
|
780
|
-
|
|
951
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
952
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
953
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
954
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
955
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
956
|
+
}
|
|
957
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
958
|
+
function _ts_metadata7(k, v) {
|
|
959
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
960
|
+
}
|
|
961
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
962
|
+
var ConnectedPong = class ConnectedPong2 extends BasePacket {
|
|
963
|
+
static {
|
|
964
|
+
__name(this, "ConnectedPong");
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* The timestamp of the ping.
|
|
968
|
+
*/
|
|
781
969
|
pingTimestamp;
|
|
970
|
+
/**
|
|
971
|
+
* The timestamp of the pong.
|
|
972
|
+
*/
|
|
782
973
|
timestamp;
|
|
783
974
|
};
|
|
784
|
-
|
|
785
|
-
Serialize(import_binarystream11.Long)
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
975
|
+
_ts_decorate7([
|
|
976
|
+
Serialize(import_binarystream11.Long),
|
|
977
|
+
_ts_metadata7("design:type", typeof BigInt === "undefined" ? Object : BigInt)
|
|
978
|
+
], ConnectedPong.prototype, "pingTimestamp", void 0);
|
|
979
|
+
_ts_decorate7([
|
|
980
|
+
Serialize(import_binarystream11.Long),
|
|
981
|
+
_ts_metadata7("design:type", typeof BigInt === "undefined" ? Object : BigInt)
|
|
982
|
+
], ConnectedPong.prototype, "timestamp", void 0);
|
|
983
|
+
ConnectedPong = _ts_decorate7([
|
|
984
|
+
Proto(Packet.ConnectedPong)
|
|
792
985
|
], ConnectedPong);
|
|
793
986
|
|
|
794
987
|
// src/proto/data/connected-ping.ts
|
|
795
988
|
var import_binarystream12 = require("@serenityjs/binarystream");
|
|
796
|
-
|
|
989
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
990
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
991
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
992
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
993
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
994
|
+
}
|
|
995
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
996
|
+
function _ts_metadata8(k, v) {
|
|
997
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
998
|
+
}
|
|
999
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
1000
|
+
var ConnectedPing = class ConnectedPing2 extends BasePacket {
|
|
1001
|
+
static {
|
|
1002
|
+
__name(this, "ConnectedPing");
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* The timestamp of the ping.
|
|
1006
|
+
*/
|
|
797
1007
|
timestamp;
|
|
798
1008
|
};
|
|
799
|
-
|
|
800
|
-
Serialize(import_binarystream12.Long)
|
|
801
|
-
|
|
802
|
-
ConnectedPing
|
|
803
|
-
|
|
1009
|
+
_ts_decorate8([
|
|
1010
|
+
Serialize(import_binarystream12.Long),
|
|
1011
|
+
_ts_metadata8("design:type", typeof BigInt === "undefined" ? Object : BigInt)
|
|
1012
|
+
], ConnectedPing.prototype, "timestamp", void 0);
|
|
1013
|
+
ConnectedPing = _ts_decorate8([
|
|
1014
|
+
Proto(Packet.ConnectedPing)
|
|
804
1015
|
], ConnectedPing);
|
|
805
1016
|
|
|
806
1017
|
// src/proto/data/connection-request.ts
|
|
807
1018
|
var import_binarystream13 = require("@serenityjs/binarystream");
|
|
808
|
-
|
|
1019
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
1020
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1021
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1022
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1023
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1024
|
+
}
|
|
1025
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
1026
|
+
function _ts_metadata9(k, v) {
|
|
1027
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1028
|
+
}
|
|
1029
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
1030
|
+
var ConnectionRequest = class ConnectionRequest2 extends BasePacket {
|
|
1031
|
+
static {
|
|
1032
|
+
__name(this, "ConnectionRequest");
|
|
1033
|
+
}
|
|
1034
|
+
/**
|
|
1035
|
+
* The client guid of the request.
|
|
1036
|
+
*/
|
|
809
1037
|
client;
|
|
1038
|
+
/**
|
|
1039
|
+
* The timestamp of the request.
|
|
1040
|
+
*/
|
|
810
1041
|
timestamp;
|
|
811
1042
|
};
|
|
812
|
-
|
|
813
|
-
Serialize(import_binarystream13.Long)
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
1043
|
+
_ts_decorate9([
|
|
1044
|
+
Serialize(import_binarystream13.Long),
|
|
1045
|
+
_ts_metadata9("design:type", typeof BigInt === "undefined" ? Object : BigInt)
|
|
1046
|
+
], ConnectionRequest.prototype, "client", void 0);
|
|
1047
|
+
_ts_decorate9([
|
|
1048
|
+
Serialize(import_binarystream13.Long),
|
|
1049
|
+
_ts_metadata9("design:type", typeof BigInt === "undefined" ? Object : BigInt)
|
|
1050
|
+
], ConnectionRequest.prototype, "timestamp", void 0);
|
|
1051
|
+
ConnectionRequest = _ts_decorate9([
|
|
1052
|
+
Proto(Packet.ConnectionRequest)
|
|
820
1053
|
], ConnectionRequest);
|
|
821
1054
|
|
|
822
1055
|
// src/proto/data/frame-set.ts
|
|
823
1056
|
var import_binarystream14 = require("@serenityjs/binarystream");
|
|
824
|
-
|
|
1057
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
1058
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1059
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1060
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1061
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1062
|
+
}
|
|
1063
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
1064
|
+
function _ts_metadata10(k, v) {
|
|
1065
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1066
|
+
}
|
|
1067
|
+
__name(_ts_metadata10, "_ts_metadata");
|
|
1068
|
+
var FrameSet = class FrameSet2 extends BasePacket {
|
|
1069
|
+
static {
|
|
1070
|
+
__name(this, "FrameSet");
|
|
1071
|
+
}
|
|
1072
|
+
/**
|
|
1073
|
+
* The sequence of the frame set.
|
|
1074
|
+
*/
|
|
825
1075
|
sequence;
|
|
1076
|
+
/**
|
|
1077
|
+
* The frames of the frame set.
|
|
1078
|
+
*/
|
|
826
1079
|
frames;
|
|
827
1080
|
};
|
|
828
|
-
|
|
829
|
-
Serialize(import_binarystream14.Uint24, import_binarystream14.Endianness.Little)
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
1081
|
+
_ts_decorate10([
|
|
1082
|
+
Serialize(import_binarystream14.Uint24, import_binarystream14.Endianness.Little),
|
|
1083
|
+
_ts_metadata10("design:type", Number)
|
|
1084
|
+
], FrameSet.prototype, "sequence", void 0);
|
|
1085
|
+
_ts_decorate10([
|
|
1086
|
+
Serialize(Frame),
|
|
1087
|
+
_ts_metadata10("design:type", typeof Array === "undefined" ? Object : Array)
|
|
1088
|
+
], FrameSet.prototype, "frames", void 0);
|
|
1089
|
+
FrameSet = _ts_decorate10([
|
|
1090
|
+
Proto(Packet.FrameSet)
|
|
836
1091
|
], FrameSet);
|
|
837
1092
|
|
|
838
1093
|
// src/proto/data/ack.ts
|
|
839
1094
|
var import_binarystream15 = require("@serenityjs/binarystream");
|
|
840
|
-
|
|
1095
|
+
function _ts_decorate11(decorators, target, key, desc) {
|
|
1096
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1097
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1098
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1099
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1100
|
+
}
|
|
1101
|
+
__name(_ts_decorate11, "_ts_decorate");
|
|
1102
|
+
var Ack = class Ack2 extends BasePacket {
|
|
1103
|
+
static {
|
|
1104
|
+
__name(this, "Ack");
|
|
1105
|
+
}
|
|
841
1106
|
sequences = [];
|
|
842
1107
|
// Override encode due to custom logic, maybe move into own type?
|
|
843
1108
|
serialize() {
|
|
844
|
-
this.writeUint8(
|
|
1109
|
+
this.writeUint8(Ack2.id);
|
|
845
1110
|
const stream = new import_binarystream15.BinaryStream();
|
|
846
1111
|
const count = this.sequences.length;
|
|
847
1112
|
let records = 0;
|
|
@@ -902,17 +1167,27 @@ var Ack = class extends BasePacket {
|
|
|
902
1167
|
return this;
|
|
903
1168
|
}
|
|
904
1169
|
};
|
|
905
|
-
Ack =
|
|
906
|
-
Proto(
|
|
1170
|
+
Ack = _ts_decorate11([
|
|
1171
|
+
Proto(Packet.Ack)
|
|
907
1172
|
], Ack);
|
|
908
1173
|
|
|
909
1174
|
// src/proto/data/nack.ts
|
|
910
1175
|
var import_binarystream16 = require("@serenityjs/binarystream");
|
|
911
|
-
|
|
1176
|
+
function _ts_decorate12(decorators, target, key, desc) {
|
|
1177
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1178
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1179
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1180
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1181
|
+
}
|
|
1182
|
+
__name(_ts_decorate12, "_ts_decorate");
|
|
1183
|
+
var Nack = class Nack2 extends BasePacket {
|
|
1184
|
+
static {
|
|
1185
|
+
__name(this, "Nack");
|
|
1186
|
+
}
|
|
912
1187
|
sequences = [];
|
|
913
1188
|
// Override encode due to custom logic, maybe move into own type?
|
|
914
1189
|
serialize() {
|
|
915
|
-
this.writeUint8(
|
|
1190
|
+
this.writeUint8(Nack2.id);
|
|
916
1191
|
const stream = new import_binarystream16.BinaryStream();
|
|
917
1192
|
const count = this.sequences.length;
|
|
918
1193
|
let records = 0;
|
|
@@ -973,87 +1248,178 @@ var Nack = class extends BasePacket {
|
|
|
973
1248
|
return this;
|
|
974
1249
|
}
|
|
975
1250
|
};
|
|
976
|
-
Nack =
|
|
977
|
-
Proto(
|
|
1251
|
+
Nack = _ts_decorate12([
|
|
1252
|
+
Proto(Packet.Nack)
|
|
978
1253
|
], Nack);
|
|
979
1254
|
|
|
980
1255
|
// src/proto/data/disconnect.ts
|
|
981
|
-
|
|
1256
|
+
function _ts_decorate13(decorators, target, key, desc) {
|
|
1257
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1258
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1259
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1260
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1261
|
+
}
|
|
1262
|
+
__name(_ts_decorate13, "_ts_decorate");
|
|
1263
|
+
var Disconnect = class Disconnect2 extends BasePacket {
|
|
1264
|
+
static {
|
|
1265
|
+
__name(this, "Disconnect");
|
|
1266
|
+
}
|
|
982
1267
|
};
|
|
983
|
-
Disconnect =
|
|
984
|
-
Proto(
|
|
1268
|
+
Disconnect = _ts_decorate13([
|
|
1269
|
+
Proto(Packet.Disconnect)
|
|
985
1270
|
], Disconnect);
|
|
986
1271
|
|
|
987
1272
|
// src/proto/data/incompatible-protocol.ts
|
|
988
1273
|
var import_binarystream17 = require("@serenityjs/binarystream");
|
|
989
|
-
|
|
1274
|
+
function _ts_decorate14(decorators, target, key, desc) {
|
|
1275
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1276
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1277
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1278
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1279
|
+
}
|
|
1280
|
+
__name(_ts_decorate14, "_ts_decorate");
|
|
1281
|
+
function _ts_metadata11(k, v) {
|
|
1282
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1283
|
+
}
|
|
1284
|
+
__name(_ts_metadata11, "_ts_metadata");
|
|
1285
|
+
var IncompatibleProtocolVersion = class IncompatibleProtocolVersion2 extends BasePacket {
|
|
1286
|
+
static {
|
|
1287
|
+
__name(this, "IncompatibleProtocolVersion");
|
|
1288
|
+
}
|
|
990
1289
|
protocol;
|
|
991
1290
|
magic;
|
|
992
1291
|
guid;
|
|
993
1292
|
};
|
|
994
|
-
|
|
995
|
-
Serialize(import_binarystream17.Uint8)
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1293
|
+
_ts_decorate14([
|
|
1294
|
+
Serialize(import_binarystream17.Uint8),
|
|
1295
|
+
_ts_metadata11("design:type", Number)
|
|
1296
|
+
], IncompatibleProtocolVersion.prototype, "protocol", void 0);
|
|
1297
|
+
_ts_decorate14([
|
|
1298
|
+
Serialize(Magic),
|
|
1299
|
+
_ts_metadata11("design:type", typeof Buffer === "undefined" ? Object : Buffer)
|
|
1300
|
+
], IncompatibleProtocolVersion.prototype, "magic", void 0);
|
|
1301
|
+
_ts_decorate14([
|
|
1302
|
+
Serialize(import_binarystream17.Uint64),
|
|
1303
|
+
_ts_metadata11("design:type", typeof BigInt === "undefined" ? Object : BigInt)
|
|
1304
|
+
], IncompatibleProtocolVersion.prototype, "guid", void 0);
|
|
1305
|
+
IncompatibleProtocolVersion = _ts_decorate14([
|
|
1306
|
+
Proto(Packet.IncompatibleProtocolVersion)
|
|
1005
1307
|
], IncompatibleProtocolVersion);
|
|
1006
1308
|
|
|
1007
1309
|
// src/proto/data/connection-request-accepted.ts
|
|
1008
1310
|
var import_binarystream18 = require("@serenityjs/binarystream");
|
|
1009
|
-
|
|
1311
|
+
function _ts_decorate15(decorators, target, key, desc) {
|
|
1312
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1313
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1314
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1315
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1316
|
+
}
|
|
1317
|
+
__name(_ts_decorate15, "_ts_decorate");
|
|
1318
|
+
function _ts_metadata12(k, v) {
|
|
1319
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1320
|
+
}
|
|
1321
|
+
__name(_ts_metadata12, "_ts_metadata");
|
|
1322
|
+
var ConnectionRequestAccepted = class ConnectionRequestAccepted2 extends BasePacket {
|
|
1323
|
+
static {
|
|
1324
|
+
__name(this, "ConnectionRequestAccepted");
|
|
1325
|
+
}
|
|
1326
|
+
/**
|
|
1327
|
+
* The client address of the request.
|
|
1328
|
+
*/
|
|
1010
1329
|
address;
|
|
1330
|
+
/**
|
|
1331
|
+
* The system index of the request.
|
|
1332
|
+
*/
|
|
1011
1333
|
systemIndex;
|
|
1334
|
+
/**
|
|
1335
|
+
* The system address of the request.
|
|
1336
|
+
*/
|
|
1012
1337
|
systemAddress;
|
|
1338
|
+
/**
|
|
1339
|
+
* The request timestamp of the request.
|
|
1340
|
+
*/
|
|
1013
1341
|
requestTimestamp;
|
|
1342
|
+
/**
|
|
1343
|
+
* The timestamp of the request.
|
|
1344
|
+
*/
|
|
1014
1345
|
timestamp;
|
|
1015
1346
|
};
|
|
1016
|
-
|
|
1017
|
-
Serialize(Address)
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
], ConnectionRequestAccepted.prototype, "
|
|
1028
|
-
|
|
1029
|
-
Serialize(import_binarystream18.Long)
|
|
1030
|
-
|
|
1031
|
-
ConnectionRequestAccepted
|
|
1032
|
-
|
|
1347
|
+
_ts_decorate15([
|
|
1348
|
+
Serialize(Address),
|
|
1349
|
+
_ts_metadata12("design:type", typeof Address === "undefined" ? Object : Address)
|
|
1350
|
+
], ConnectionRequestAccepted.prototype, "address", void 0);
|
|
1351
|
+
_ts_decorate15([
|
|
1352
|
+
Serialize(import_binarystream18.Short),
|
|
1353
|
+
_ts_metadata12("design:type", Number)
|
|
1354
|
+
], ConnectionRequestAccepted.prototype, "systemIndex", void 0);
|
|
1355
|
+
_ts_decorate15([
|
|
1356
|
+
Serialize(SystemAddress),
|
|
1357
|
+
_ts_metadata12("design:type", typeof Array === "undefined" ? Object : Array)
|
|
1358
|
+
], ConnectionRequestAccepted.prototype, "systemAddress", void 0);
|
|
1359
|
+
_ts_decorate15([
|
|
1360
|
+
Serialize(import_binarystream18.Long),
|
|
1361
|
+
_ts_metadata12("design:type", typeof BigInt === "undefined" ? Object : BigInt)
|
|
1362
|
+
], ConnectionRequestAccepted.prototype, "requestTimestamp", void 0);
|
|
1363
|
+
_ts_decorate15([
|
|
1364
|
+
Serialize(import_binarystream18.Long),
|
|
1365
|
+
_ts_metadata12("design:type", typeof BigInt === "undefined" ? Object : BigInt)
|
|
1366
|
+
], ConnectionRequestAccepted.prototype, "timestamp", void 0);
|
|
1367
|
+
ConnectionRequestAccepted = _ts_decorate15([
|
|
1368
|
+
Proto(Packet.ConnectionRequestAccepted)
|
|
1033
1369
|
], ConnectionRequestAccepted);
|
|
1034
1370
|
|
|
1035
1371
|
// src/proto/data/new-incoming-connection.ts
|
|
1036
1372
|
var import_binarystream19 = require("@serenityjs/binarystream");
|
|
1037
|
-
|
|
1373
|
+
function _ts_decorate16(decorators, target, key, desc) {
|
|
1374
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1375
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1376
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1377
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1378
|
+
}
|
|
1379
|
+
__name(_ts_decorate16, "_ts_decorate");
|
|
1380
|
+
function _ts_metadata13(k, v) {
|
|
1381
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1382
|
+
}
|
|
1383
|
+
__name(_ts_metadata13, "_ts_metadata");
|
|
1384
|
+
var NewIncomingConnection = class NewIncomingConnection2 extends BasePacket {
|
|
1385
|
+
static {
|
|
1386
|
+
__name(this, "NewIncomingConnection");
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* the server adress of the reply.
|
|
1390
|
+
*/
|
|
1038
1391
|
serverAddress;
|
|
1392
|
+
/**
|
|
1393
|
+
* unknown what this is used for.
|
|
1394
|
+
*/
|
|
1039
1395
|
internalAddress;
|
|
1396
|
+
/**
|
|
1397
|
+
* The incoming timestamp of the reply.
|
|
1398
|
+
*/
|
|
1040
1399
|
incomingTimestamp;
|
|
1400
|
+
/**
|
|
1401
|
+
* The server timestamp of the reply.
|
|
1402
|
+
*/
|
|
1041
1403
|
serverTimestamp;
|
|
1042
1404
|
};
|
|
1043
|
-
|
|
1044
|
-
Serialize(Address)
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
], NewIncomingConnection.prototype, "
|
|
1055
|
-
|
|
1056
|
-
|
|
1405
|
+
_ts_decorate16([
|
|
1406
|
+
Serialize(Address),
|
|
1407
|
+
_ts_metadata13("design:type", String)
|
|
1408
|
+
], NewIncomingConnection.prototype, "serverAddress", void 0);
|
|
1409
|
+
_ts_decorate16([
|
|
1410
|
+
Serialize(Address),
|
|
1411
|
+
_ts_metadata13("design:type", String)
|
|
1412
|
+
], NewIncomingConnection.prototype, "internalAddress", void 0);
|
|
1413
|
+
_ts_decorate16([
|
|
1414
|
+
Serialize(import_binarystream19.Long),
|
|
1415
|
+
_ts_metadata13("design:type", typeof BigInt === "undefined" ? Object : BigInt)
|
|
1416
|
+
], NewIncomingConnection.prototype, "incomingTimestamp", void 0);
|
|
1417
|
+
_ts_decorate16([
|
|
1418
|
+
Serialize(import_binarystream19.Long),
|
|
1419
|
+
_ts_metadata13("design:type", typeof BigInt === "undefined" ? Object : BigInt)
|
|
1420
|
+
], NewIncomingConnection.prototype, "serverTimestamp", void 0);
|
|
1421
|
+
NewIncomingConnection = _ts_decorate16([
|
|
1422
|
+
Proto(Packet.NewIncomingConnection)
|
|
1057
1423
|
], NewIncomingConnection);
|
|
1058
1424
|
|
|
1059
1425
|
// src/server/raknet.ts
|
|
@@ -1073,30 +1439,33 @@ var DGRAM_MTU_OVERHEAD = 36;
|
|
|
1073
1439
|
|
|
1074
1440
|
// src/server/connection.ts
|
|
1075
1441
|
var import_binarystream20 = require("@serenityjs/binarystream");
|
|
1076
|
-
var Connection = class {
|
|
1442
|
+
var Connection = class Connection2 {
|
|
1443
|
+
static {
|
|
1444
|
+
__name(this, "Connection");
|
|
1445
|
+
}
|
|
1077
1446
|
/**
|
|
1078
|
-
|
|
1079
|
-
|
|
1447
|
+
* The server instance
|
|
1448
|
+
*/
|
|
1080
1449
|
server;
|
|
1081
1450
|
/**
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
status =
|
|
1451
|
+
* The status of the connection
|
|
1452
|
+
*/
|
|
1453
|
+
status = Status.Connecting;
|
|
1085
1454
|
/**
|
|
1086
|
-
|
|
1087
|
-
|
|
1455
|
+
* The last update time of the connection
|
|
1456
|
+
*/
|
|
1088
1457
|
lastUpdate = Date.now();
|
|
1089
1458
|
/**
|
|
1090
|
-
|
|
1091
|
-
|
|
1459
|
+
* The network identifier of the connection
|
|
1460
|
+
*/
|
|
1092
1461
|
rinfo;
|
|
1093
1462
|
/**
|
|
1094
|
-
|
|
1095
|
-
|
|
1463
|
+
* The GUID of the connection
|
|
1464
|
+
*/
|
|
1096
1465
|
guid;
|
|
1097
1466
|
/**
|
|
1098
|
-
|
|
1099
|
-
|
|
1467
|
+
* The maximum transmission unit of the connection
|
|
1468
|
+
*/
|
|
1100
1469
|
mtu;
|
|
1101
1470
|
// Inputs
|
|
1102
1471
|
receivedFrameSequences = /* @__PURE__ */ new Set();
|
|
@@ -1115,134 +1484,127 @@ var Connection = class {
|
|
|
1115
1484
|
outputsplitIndex = 0;
|
|
1116
1485
|
outputReliableIndex = 0;
|
|
1117
1486
|
/**
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1487
|
+
* Creates a new connection
|
|
1488
|
+
* @param server The server instance
|
|
1489
|
+
* @param rinfo The remote info
|
|
1490
|
+
* @param guid The GUID
|
|
1491
|
+
* @param mtu The maximum transmission unit
|
|
1492
|
+
*/
|
|
1124
1493
|
constructor(server, rinfo, guid, mtu) {
|
|
1125
1494
|
this.server = server;
|
|
1126
1495
|
this.rinfo = rinfo;
|
|
1127
1496
|
this.guid = guid;
|
|
1128
1497
|
this.mtu = mtu;
|
|
1129
|
-
this.inputOrderIndex = Array.from({
|
|
1498
|
+
this.inputOrderIndex = Array.from({
|
|
1499
|
+
length: 32
|
|
1500
|
+
}).fill(0);
|
|
1130
1501
|
for (let index = 0; index < 32; index++) {
|
|
1131
1502
|
this.inputOrderingQueue.set(index, /* @__PURE__ */ new Map());
|
|
1132
1503
|
}
|
|
1133
|
-
this.inputHighestSequenceIndex = Array.from({
|
|
1134
|
-
|
|
1135
|
-
|
|
1504
|
+
this.inputHighestSequenceIndex = Array.from({
|
|
1505
|
+
length: 32
|
|
1506
|
+
}).fill(0);
|
|
1507
|
+
this.outputOrderIndex = Array.from({
|
|
1508
|
+
length: 32
|
|
1509
|
+
}).fill(0);
|
|
1510
|
+
this.outputSequenceIndex = Array.from({
|
|
1511
|
+
length: 32
|
|
1512
|
+
}).fill(0);
|
|
1136
1513
|
}
|
|
1137
1514
|
/**
|
|
1138
|
-
|
|
1139
|
-
|
|
1515
|
+
* Ticks the connection
|
|
1516
|
+
*/
|
|
1140
1517
|
tick() {
|
|
1141
1518
|
if (this.lastUpdate + 5e3 < Date.now()) {
|
|
1142
|
-
this.server.logger.warn(
|
|
1143
|
-
`Detected stale connection from \xA7c${this.rinfo.address}\xA7r:\xA7c${this.rinfo.port}\xA7r, disconnecting...`
|
|
1144
|
-
);
|
|
1519
|
+
this.server.logger.warn(`Detected stale connection from \xA7c${this.rinfo.address}\xA7r:\xA7c${this.rinfo.port}\xA7r, disconnecting...`);
|
|
1145
1520
|
return this.disconnect();
|
|
1146
1521
|
}
|
|
1147
|
-
if (this.status ===
|
|
1148
|
-
return;
|
|
1522
|
+
if (this.status === Status.Disconnecting || this.status === Status.Disconnected) return;
|
|
1149
1523
|
if (this.receivedFrameSequences.size > 0) {
|
|
1150
1524
|
const ack = new Ack();
|
|
1151
|
-
ack.sequences = [
|
|
1152
|
-
|
|
1153
|
-
|
|
1525
|
+
ack.sequences = [
|
|
1526
|
+
...this.receivedFrameSequences
|
|
1527
|
+
];
|
|
1528
|
+
for (const sequence of this.receivedFrameSequences) this.receivedFrameSequences.delete(sequence);
|
|
1154
1529
|
this.server.send(ack.serialize(), this.rinfo);
|
|
1155
1530
|
}
|
|
1156
1531
|
if (this.lostFrameSequences.size > 0) {
|
|
1157
1532
|
const nack = new Nack();
|
|
1158
|
-
nack.sequences = [
|
|
1159
|
-
|
|
1160
|
-
|
|
1533
|
+
nack.sequences = [
|
|
1534
|
+
...this.lostFrameSequences
|
|
1535
|
+
];
|
|
1536
|
+
for (const sequence of this.lostFrameSequences) this.lostFrameSequences.delete(sequence);
|
|
1161
1537
|
this.server.send(nack.serialize(), this.rinfo);
|
|
1162
1538
|
}
|
|
1163
1539
|
return this.sendQueue(this.outputFrames.size);
|
|
1164
1540
|
}
|
|
1165
1541
|
/**
|
|
1166
|
-
|
|
1167
|
-
|
|
1542
|
+
* Disconnects the connection
|
|
1543
|
+
*/
|
|
1168
1544
|
disconnect() {
|
|
1169
|
-
this.status =
|
|
1545
|
+
this.status = Status.Disconnecting;
|
|
1170
1546
|
const disconnect = new Disconnect();
|
|
1171
1547
|
const frame = new Frame();
|
|
1172
|
-
frame.reliability =
|
|
1548
|
+
frame.reliability = Reliability.ReliableOrdered;
|
|
1173
1549
|
frame.orderChannel = 0;
|
|
1174
1550
|
frame.payload = disconnect.serialize();
|
|
1175
|
-
this.sendFrame(frame,
|
|
1551
|
+
this.sendFrame(frame, Priority.Immediate);
|
|
1176
1552
|
void this.server.emit("disconnect", this);
|
|
1177
1553
|
this.server.connections.delete(this);
|
|
1178
|
-
this.status =
|
|
1554
|
+
this.status = Status.Disconnected;
|
|
1179
1555
|
}
|
|
1180
1556
|
/**
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1557
|
+
* Handles incoming packets
|
|
1558
|
+
* @param buffer The packet buffer
|
|
1559
|
+
*/
|
|
1184
1560
|
incoming(buffer) {
|
|
1185
1561
|
this.lastUpdate = Date.now();
|
|
1186
1562
|
const header = buffer[0] & 240;
|
|
1187
1563
|
switch (header) {
|
|
1188
1564
|
default: {
|
|
1189
1565
|
const id = header.toString(16).length === 1 ? "0" + header.toString(16) : header.toString(16);
|
|
1190
|
-
this.server.logger.debug(
|
|
1191
|
-
|
|
1192
|
-
);
|
|
1193
|
-
return void this.server.emit(
|
|
1194
|
-
"error",
|
|
1195
|
-
new Error(
|
|
1196
|
-
`Received unknown online packet 0x${id} from ${this.rinfo.address}:${this.rinfo.port}!`
|
|
1197
|
-
)
|
|
1198
|
-
);
|
|
1566
|
+
this.server.logger.debug(`Received unknown online packet 0x${id} from ${this.rinfo.address}:${this.rinfo.port}!`);
|
|
1567
|
+
return void this.server.emit("error", new Error(`Received unknown online packet 0x${id} from ${this.rinfo.address}:${this.rinfo.port}!`));
|
|
1199
1568
|
}
|
|
1200
|
-
case
|
|
1569
|
+
case Packet.Ack: {
|
|
1201
1570
|
this.ack(buffer);
|
|
1202
1571
|
break;
|
|
1203
1572
|
}
|
|
1204
|
-
case
|
|
1573
|
+
case Packet.Nack: {
|
|
1205
1574
|
this.nack(buffer);
|
|
1206
1575
|
break;
|
|
1207
1576
|
}
|
|
1208
|
-
case
|
|
1577
|
+
case Bitflags.Valid: {
|
|
1209
1578
|
this.handleIncomingFrameSet(buffer);
|
|
1210
1579
|
break;
|
|
1211
1580
|
}
|
|
1212
1581
|
}
|
|
1213
1582
|
}
|
|
1214
1583
|
/**
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1584
|
+
* Handles incoming batch packets
|
|
1585
|
+
* @param buffer The packet buffer
|
|
1586
|
+
*/
|
|
1218
1587
|
incomingBatch(buffer) {
|
|
1219
1588
|
const header = buffer[0];
|
|
1220
|
-
if (this.status ===
|
|
1589
|
+
if (this.status === Status.Connecting) {
|
|
1221
1590
|
switch (header) {
|
|
1222
1591
|
default: {
|
|
1223
1592
|
const id = header.toString(16).length === 1 ? "0" + header.toString(16) : header.toString(16);
|
|
1224
|
-
this.server.logger.debug(
|
|
1225
|
-
|
|
1226
|
-
);
|
|
1227
|
-
return void this.server.emit(
|
|
1228
|
-
"error",
|
|
1229
|
-
new Error(
|
|
1230
|
-
`Received unknown online packet 0x${id} from ${this.rinfo.address}:${this.rinfo.port}!`
|
|
1231
|
-
)
|
|
1232
|
-
);
|
|
1593
|
+
this.server.logger.debug(`Received unknown online packet 0x${id} from ${this.rinfo.address}:${this.rinfo.port}!`);
|
|
1594
|
+
return void this.server.emit("error", new Error(`Received unknown online packet 0x${id} from ${this.rinfo.address}:${this.rinfo.port}!`));
|
|
1233
1595
|
}
|
|
1234
|
-
case
|
|
1235
|
-
this.status =
|
|
1596
|
+
case Packet.Disconnect: {
|
|
1597
|
+
this.status = Status.Disconnecting;
|
|
1236
1598
|
this.server.connections.delete(this);
|
|
1237
|
-
this.status =
|
|
1599
|
+
this.status = Status.Disconnected;
|
|
1238
1600
|
break;
|
|
1239
1601
|
}
|
|
1240
|
-
case
|
|
1602
|
+
case Packet.ConnectionRequest: {
|
|
1241
1603
|
this.handleIncomingConnectionRequest(buffer);
|
|
1242
1604
|
break;
|
|
1243
1605
|
}
|
|
1244
|
-
case
|
|
1245
|
-
this.status =
|
|
1606
|
+
case Packet.NewIncomingConnection: {
|
|
1607
|
+
this.status = Status.Connected;
|
|
1246
1608
|
void this.server.emit("connect", this);
|
|
1247
1609
|
break;
|
|
1248
1610
|
}
|
|
@@ -1252,24 +1614,17 @@ var Connection = class {
|
|
|
1252
1614
|
switch (header) {
|
|
1253
1615
|
default: {
|
|
1254
1616
|
const id = header.toString(16).length === 1 ? "0" + header.toString(16) : header.toString(16);
|
|
1255
|
-
this.server.logger.debug(
|
|
1256
|
-
|
|
1257
|
-
);
|
|
1258
|
-
return void this.server.emit(
|
|
1259
|
-
"error",
|
|
1260
|
-
new Error(
|
|
1261
|
-
`Received unknown online packet 0x${id} from ${this.rinfo.address}:${this.rinfo.port}!`
|
|
1262
|
-
)
|
|
1263
|
-
);
|
|
1617
|
+
this.server.logger.debug(`Received unknown online packet 0x${id} from ${this.rinfo.address}:${this.rinfo.port}!`);
|
|
1618
|
+
return void this.server.emit("error", new Error(`Received unknown online packet 0x${id} from ${this.rinfo.address}:${this.rinfo.port}!`));
|
|
1264
1619
|
}
|
|
1265
|
-
case
|
|
1266
|
-
this.status =
|
|
1620
|
+
case Packet.Disconnect: {
|
|
1621
|
+
this.status = Status.Disconnecting;
|
|
1267
1622
|
void this.server.emit("disconnect", this);
|
|
1268
1623
|
this.server.connections.delete(this);
|
|
1269
|
-
this.status =
|
|
1624
|
+
this.status = Status.Disconnected;
|
|
1270
1625
|
break;
|
|
1271
1626
|
}
|
|
1272
|
-
case
|
|
1627
|
+
case Packet.ConnectedPing: {
|
|
1273
1628
|
return this.handleIncomingConnectedPing(buffer);
|
|
1274
1629
|
}
|
|
1275
1630
|
case 254: {
|
|
@@ -1278,65 +1633,47 @@ var Connection = class {
|
|
|
1278
1633
|
}
|
|
1279
1634
|
}
|
|
1280
1635
|
/**
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1636
|
+
* Handles incoming acks
|
|
1637
|
+
* @param buffer The packet buffer
|
|
1638
|
+
*/
|
|
1284
1639
|
ack(buffer) {
|
|
1285
1640
|
const ack = new Ack(buffer).deserialize();
|
|
1286
1641
|
for (const sequence of ack.sequences) {
|
|
1287
|
-
if (!this.outputBackup.has(sequence))
|
|
1288
|
-
this.server.logger.debug(
|
|
1289
|
-
`Received ack for unknown sequence ${sequence} from ${this.rinfo.address}:${this.rinfo.port}.`
|
|
1290
|
-
);
|
|
1642
|
+
if (!this.outputBackup.has(sequence)) this.server.logger.debug(`Received ack for unknown sequence ${sequence} from ${this.rinfo.address}:${this.rinfo.port}.`);
|
|
1291
1643
|
this.outputBackup.delete(sequence);
|
|
1292
1644
|
}
|
|
1293
1645
|
}
|
|
1294
1646
|
/**
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1647
|
+
* Handles incoming nacks
|
|
1648
|
+
* @param buffer The packet buffer
|
|
1649
|
+
*/
|
|
1298
1650
|
nack(buffer) {
|
|
1299
1651
|
const nack = new Nack(buffer).deserialize();
|
|
1300
1652
|
for (const sequence of nack.sequences) {
|
|
1301
1653
|
const frames = this.outputBackup.get(sequence) ?? [];
|
|
1302
1654
|
for (const frame of frames) {
|
|
1303
|
-
this.sendFrame(frame,
|
|
1655
|
+
this.sendFrame(frame, Priority.Immediate);
|
|
1304
1656
|
}
|
|
1305
1657
|
}
|
|
1306
1658
|
}
|
|
1307
1659
|
/**
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1660
|
+
* Handles incoming framesets
|
|
1661
|
+
* @param buffer The packet buffer
|
|
1662
|
+
*/
|
|
1311
1663
|
handleIncomingFrameSet(buffer) {
|
|
1312
1664
|
const frameset = new FrameSet(buffer).deserialize();
|
|
1313
1665
|
if (this.receivedFrameSequences.has(frameset.sequence)) {
|
|
1314
|
-
this.server.logger.debug(
|
|
1315
|
-
|
|
1316
|
-
);
|
|
1317
|
-
return void this.server.emit(
|
|
1318
|
-
"error",
|
|
1319
|
-
new Error(
|
|
1320
|
-
`Recieved duplicate frameset ${frameset.sequence} from ${this.rinfo.address}:${this.rinfo.port}!`
|
|
1321
|
-
)
|
|
1322
|
-
);
|
|
1666
|
+
this.server.logger.debug(`Received duplicate frameset ${frameset.sequence} from ${this.rinfo.address}:${this.rinfo.port}!`);
|
|
1667
|
+
return void this.server.emit("error", new Error(`Recieved duplicate frameset ${frameset.sequence} from ${this.rinfo.address}:${this.rinfo.port}!`));
|
|
1323
1668
|
}
|
|
1324
1669
|
this.lostFrameSequences.delete(frameset.sequence);
|
|
1325
1670
|
if (frameset.sequence < this.lastInputSequence || frameset.sequence === this.lastInputSequence) {
|
|
1326
|
-
this.server.logger.debug(
|
|
1327
|
-
|
|
1328
|
-
);
|
|
1329
|
-
return void this.server.emit(
|
|
1330
|
-
"error",
|
|
1331
|
-
new Error(
|
|
1332
|
-
`Recieved out of order frameset ${frameset.sequence} from ${this.rinfo.address}:${this.rinfo.port}!`
|
|
1333
|
-
)
|
|
1334
|
-
);
|
|
1671
|
+
this.server.logger.debug(`Received out of order frameset ${frameset.sequence} from ${this.rinfo.address}:${this.rinfo.port}!`);
|
|
1672
|
+
return void this.server.emit("error", new Error(`Recieved out of order frameset ${frameset.sequence} from ${this.rinfo.address}:${this.rinfo.port}!`));
|
|
1335
1673
|
}
|
|
1336
1674
|
this.receivedFrameSequences.add(frameset.sequence);
|
|
1337
1675
|
if (frameset.sequence - this.lastInputSequence > 1) {
|
|
1338
|
-
for (let index = this.lastInputSequence + 1; index < frameset.sequence; index++)
|
|
1339
|
-
this.lostFrameSequences.add(index);
|
|
1676
|
+
for (let index = this.lastInputSequence + 1; index < frameset.sequence; index++) this.lostFrameSequences.add(index);
|
|
1340
1677
|
}
|
|
1341
1678
|
this.lastInputSequence = frameset.sequence;
|
|
1342
1679
|
for (const frame of frameset.frames) {
|
|
@@ -1344,22 +1681,15 @@ var Connection = class {
|
|
|
1344
1681
|
}
|
|
1345
1682
|
}
|
|
1346
1683
|
/**
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1684
|
+
* Handles incoming frames
|
|
1685
|
+
* @param frame The frame
|
|
1686
|
+
*/
|
|
1350
1687
|
handleFrame(frame) {
|
|
1351
1688
|
if (frame.isSplit()) return this.handleFragment(frame);
|
|
1352
1689
|
if (frame.isSequenced()) {
|
|
1353
1690
|
if (frame.sequenceIndex < this.inputHighestSequenceIndex[frame.orderChannel] || frame.orderIndex < this.inputOrderIndex[frame.orderChannel]) {
|
|
1354
|
-
this.server.logger.debug(
|
|
1355
|
-
|
|
1356
|
-
);
|
|
1357
|
-
return void this.server.emit(
|
|
1358
|
-
"error",
|
|
1359
|
-
new Error(
|
|
1360
|
-
`Recieved out of order frame ${frame.sequenceIndex} from ${this.rinfo.address}:${this.rinfo.port}!`
|
|
1361
|
-
)
|
|
1362
|
-
);
|
|
1691
|
+
this.server.logger.debug(`Recieved out of order frame ${frame.sequenceIndex} from ${this.rinfo.address}:${this.rinfo.port}!`);
|
|
1692
|
+
return void this.server.emit("error", new Error(`Recieved out of order frame ${frame.sequenceIndex} from ${this.rinfo.address}:${this.rinfo.port}!`));
|
|
1363
1693
|
}
|
|
1364
1694
|
this.inputHighestSequenceIndex[frame.orderChannel] = frame.sequenceIndex + 1;
|
|
1365
1695
|
return this.incomingBatch(frame.payload);
|
|
@@ -1369,9 +1699,7 @@ var Connection = class {
|
|
|
1369
1699
|
this.inputOrderIndex[frame.orderChannel] = frame.orderIndex + 1;
|
|
1370
1700
|
this.incomingBatch(frame.payload);
|
|
1371
1701
|
let index = this.inputOrderIndex[frame.orderChannel];
|
|
1372
|
-
const outOfOrderQueue = this.inputOrderingQueue.get(
|
|
1373
|
-
frame.orderChannel
|
|
1374
|
-
);
|
|
1702
|
+
const outOfOrderQueue = this.inputOrderingQueue.get(frame.orderChannel);
|
|
1375
1703
|
for (; outOfOrderQueue.has(index); index++) {
|
|
1376
1704
|
const frame2 = outOfOrderQueue.get(index);
|
|
1377
1705
|
if (!frame2) break;
|
|
@@ -1390,9 +1718,9 @@ var Connection = class {
|
|
|
1390
1718
|
}
|
|
1391
1719
|
}
|
|
1392
1720
|
/**
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1721
|
+
* Handles fragmented frames
|
|
1722
|
+
* @param frame The frame
|
|
1723
|
+
*/
|
|
1396
1724
|
handleFragment(frame) {
|
|
1397
1725
|
if (this.fragmentsQueue.has(frame.splitId)) {
|
|
1398
1726
|
const fragment = this.fragmentsQueue.get(frame.splitId);
|
|
@@ -1415,18 +1743,20 @@ var Connection = class {
|
|
|
1415
1743
|
return this.handleFrame(nframe);
|
|
1416
1744
|
}
|
|
1417
1745
|
} else {
|
|
1418
|
-
this.fragmentsQueue.set(
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1746
|
+
this.fragmentsQueue.set(frame.splitId, /* @__PURE__ */ new Map([
|
|
1747
|
+
[
|
|
1748
|
+
frame.splitIndex,
|
|
1749
|
+
frame
|
|
1750
|
+
]
|
|
1751
|
+
]));
|
|
1422
1752
|
}
|
|
1423
1753
|
}
|
|
1424
1754
|
/**
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1755
|
+
* Sends a frame to the connection.
|
|
1756
|
+
*
|
|
1757
|
+
* @param frame - The frame to send
|
|
1758
|
+
* @param priority - The priority of the frame
|
|
1759
|
+
*/
|
|
1430
1760
|
sendFrame(frame, priority) {
|
|
1431
1761
|
if (frame.isSequenced()) {
|
|
1432
1762
|
frame.orderIndex = this.outputOrderIndex[frame.orderChannel];
|
|
@@ -1459,34 +1789,36 @@ var Connection = class {
|
|
|
1459
1789
|
}
|
|
1460
1790
|
}
|
|
1461
1791
|
/**
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1792
|
+
* Adds a frame to the output queue
|
|
1793
|
+
* @param frame The frame
|
|
1794
|
+
* @param priority The priority
|
|
1795
|
+
*/
|
|
1466
1796
|
queueFrame(frame, priority) {
|
|
1467
1797
|
let length = DGRAM_HEADER_SIZE;
|
|
1468
1798
|
for (const frame2 of this.outputFrames) length += frame2.getByteLength();
|
|
1469
1799
|
if (length + frame.getByteLength() > this.mtu - DGRAM_MTU_OVERHEAD)
|
|
1470
1800
|
this.sendQueue(this.outputFrames.size);
|
|
1471
1801
|
this.outputFrames.add(frame);
|
|
1472
|
-
if (priority ===
|
|
1802
|
+
if (priority === Priority.Immediate) return this.sendQueue(1);
|
|
1473
1803
|
}
|
|
1474
1804
|
/**
|
|
1475
|
-
|
|
1476
|
-
|
|
1805
|
+
* Sends the output frame queue
|
|
1806
|
+
*/
|
|
1477
1807
|
sendQueue(amount) {
|
|
1478
1808
|
if (this.outputFrames.size === 0) return;
|
|
1479
1809
|
const frameset = new FrameSet();
|
|
1480
1810
|
frameset.sequence = this.outputSequence++;
|
|
1481
|
-
frameset.frames = [
|
|
1811
|
+
frameset.frames = [
|
|
1812
|
+
...this.outputFrames
|
|
1813
|
+
].slice(0, amount);
|
|
1482
1814
|
this.outputBackup.set(frameset.sequence, frameset.frames);
|
|
1483
1815
|
for (const frame of frameset.frames) this.outputFrames.delete(frame);
|
|
1484
1816
|
return this.server.send(frameset.serialize(), this.rinfo);
|
|
1485
1817
|
}
|
|
1486
1818
|
/**
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1819
|
+
* Handles an incoming connection request
|
|
1820
|
+
* @param buffer The packet buffer
|
|
1821
|
+
*/
|
|
1490
1822
|
handleIncomingConnectionRequest(buffer) {
|
|
1491
1823
|
const request = new ConnectionRequest(buffer).deserialize();
|
|
1492
1824
|
const accepted = new ConnectionRequestAccepted();
|
|
@@ -1496,15 +1828,15 @@ var Connection = class {
|
|
|
1496
1828
|
accepted.requestTimestamp = request.timestamp;
|
|
1497
1829
|
accepted.timestamp = BigInt(Date.now());
|
|
1498
1830
|
const frame = new Frame();
|
|
1499
|
-
frame.reliability =
|
|
1831
|
+
frame.reliability = Reliability.ReliableOrdered;
|
|
1500
1832
|
frame.orderChannel = 0;
|
|
1501
1833
|
frame.payload = accepted.serialize();
|
|
1502
|
-
return this.sendFrame(frame,
|
|
1834
|
+
return this.sendFrame(frame, Priority.Normal);
|
|
1503
1835
|
}
|
|
1504
1836
|
/**
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1837
|
+
* Handles an incoming connected ping
|
|
1838
|
+
* @param buffer The packet buffer
|
|
1839
|
+
*/
|
|
1508
1840
|
handleIncomingConnectedPing(buffer) {
|
|
1509
1841
|
const ping = new ConnectedPing(buffer).deserialize();
|
|
1510
1842
|
const pong = new ConnectedPong();
|
|
@@ -1512,53 +1844,54 @@ var Connection = class {
|
|
|
1512
1844
|
pong.pingTimestamp = ping.timestamp;
|
|
1513
1845
|
pong.timestamp = BigInt(Date.now());
|
|
1514
1846
|
const frame = new Frame();
|
|
1515
|
-
frame.reliability =
|
|
1847
|
+
frame.reliability = Reliability.ReliableOrdered;
|
|
1516
1848
|
frame.orderChannel = 0;
|
|
1517
1849
|
frame.payload = pong.serialize();
|
|
1518
|
-
this.sendFrame(frame,
|
|
1850
|
+
this.sendFrame(frame, Priority.Normal);
|
|
1519
1851
|
}
|
|
1520
1852
|
};
|
|
1521
1853
|
|
|
1522
1854
|
// src/server/offline.ts
|
|
1523
|
-
var Offline = class {
|
|
1855
|
+
var Offline = class Offline2 {
|
|
1856
|
+
static {
|
|
1857
|
+
__name(this, "Offline");
|
|
1858
|
+
}
|
|
1524
1859
|
/**
|
|
1525
|
-
|
|
1526
|
-
|
|
1860
|
+
* The raknet server instance
|
|
1861
|
+
*/
|
|
1527
1862
|
static server;
|
|
1528
1863
|
/**
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1864
|
+
* Handles all incoming offline datagrams from remote clients
|
|
1865
|
+
* @param buffer The packet buffer from the remote client
|
|
1866
|
+
* @param rinfo The remote client information
|
|
1867
|
+
*/
|
|
1533
1868
|
static handle(buffer, rinfo) {
|
|
1534
1869
|
const header = buffer[0];
|
|
1535
1870
|
if (!header) throw new Error("Invalid offline packet header");
|
|
1536
1871
|
switch (header) {
|
|
1537
|
-
case
|
|
1872
|
+
case Packet.UnconnectedPing: {
|
|
1538
1873
|
this.unconnectedPing(buffer, rinfo);
|
|
1539
1874
|
break;
|
|
1540
1875
|
}
|
|
1541
|
-
case
|
|
1876
|
+
case Packet.OpenConnectionRequest1: {
|
|
1542
1877
|
this.openConnectionRequest1(buffer, rinfo);
|
|
1543
1878
|
break;
|
|
1544
1879
|
}
|
|
1545
|
-
case
|
|
1880
|
+
case Packet.OpenConnectionRequest2: {
|
|
1546
1881
|
this.openConnectionRequest2(buffer, rinfo);
|
|
1547
1882
|
break;
|
|
1548
1883
|
}
|
|
1549
1884
|
default: {
|
|
1550
1885
|
const id = header.toString(16).length === 1 ? "0" + header.toString(16) : header.toString(16);
|
|
1551
|
-
this.server.logger.debug(
|
|
1552
|
-
`Received an unknown offline packet identifier "0x${id}" from ${rinfo.address}:${rinfo.port}`
|
|
1553
|
-
);
|
|
1886
|
+
this.server.logger.debug(`Received an unknown offline packet identifier "0x${id}" from ${rinfo.address}:${rinfo.port}`);
|
|
1554
1887
|
}
|
|
1555
1888
|
}
|
|
1556
1889
|
}
|
|
1557
1890
|
/**
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1891
|
+
* Handles an unconnected ping packet
|
|
1892
|
+
* @param buffer The packet buffer from the remote client
|
|
1893
|
+
* @param rinfo The remote client information
|
|
1894
|
+
*/
|
|
1562
1895
|
static unconnectedPing(buffer, rinfo) {
|
|
1563
1896
|
const ping = new UnconnectedPing(buffer).deserialize();
|
|
1564
1897
|
const pong = new UnconnectedPong();
|
|
@@ -1566,7 +1899,6 @@ var Offline = class {
|
|
|
1566
1899
|
pong.guid = this.server.guid;
|
|
1567
1900
|
pong.message = [
|
|
1568
1901
|
"MCPE",
|
|
1569
|
-
// MCEE = Minecraft: Education Edition
|
|
1570
1902
|
this.server.message ?? "Raknet Server",
|
|
1571
1903
|
this.server.protocol ?? 100,
|
|
1572
1904
|
this.server.version ?? "1.0.0",
|
|
@@ -1582,19 +1914,17 @@ var Offline = class {
|
|
|
1582
1914
|
this.server.send(pong.serialize(), rinfo);
|
|
1583
1915
|
}
|
|
1584
1916
|
/**
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1917
|
+
* Handles an open connection request 1 packet
|
|
1918
|
+
* @param buffer The packet buffer from the remote client
|
|
1919
|
+
* @param rinfo The remote client information
|
|
1920
|
+
*/
|
|
1589
1921
|
static openConnectionRequest1(buffer, rinfo) {
|
|
1590
1922
|
const request = new OpenConnectionRequest1(buffer).deserialize();
|
|
1591
1923
|
if (request.protocol !== RAKNET_PROTOCOL) {
|
|
1592
1924
|
const incompatible = new IncompatibleProtocolVersion();
|
|
1593
1925
|
incompatible.protocol = RAKNET_PROTOCOL;
|
|
1594
1926
|
incompatible.guid = this.server.guid;
|
|
1595
|
-
this.server.logger.warn(
|
|
1596
|
-
`Refusing connection from ${rinfo.address}:${rinfo.port} due to incompatible protocol version v${request.protocol}, expected v${RAKNET_PROTOCOL}.`
|
|
1597
|
-
);
|
|
1927
|
+
this.server.logger.warn(`Refusing connection from ${rinfo.address}:${rinfo.port} due to incompatible protocol version v${request.protocol}, expected v${RAKNET_PROTOCOL}.`);
|
|
1598
1928
|
return this.server.send(incompatible.serialize(), rinfo);
|
|
1599
1929
|
}
|
|
1600
1930
|
const reply = new OpenConnectionReply1();
|
|
@@ -1605,38 +1935,30 @@ var Offline = class {
|
|
|
1605
1935
|
return this.server.send(reply.serialize(), rinfo);
|
|
1606
1936
|
}
|
|
1607
1937
|
/**
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1938
|
+
* Handles an open connection request 2 packet
|
|
1939
|
+
* @param buffer The packet buffer from the remote client
|
|
1940
|
+
* @param rinfo The remote client information
|
|
1941
|
+
*/
|
|
1612
1942
|
static openConnectionRequest2(buffer, rinfo) {
|
|
1613
1943
|
const request = new OpenConnectionRequest2(buffer).deserialize();
|
|
1614
1944
|
if (request.address.port !== this.server.port) {
|
|
1615
|
-
return this.server.logger.warn(
|
|
1616
|
-
`Refusing connection from ${rinfo.address}:${rinfo.port} due to mismatched port.`
|
|
1617
|
-
);
|
|
1945
|
+
return this.server.logger.warn(`Refusing connection from ${rinfo.address}:${rinfo.port} due to mismatched port.`);
|
|
1618
1946
|
}
|
|
1619
1947
|
if (request.mtu < this.server.minMtuSize || request.mtu > this.server.maxMtuSize) {
|
|
1620
|
-
return this.server.logger.warn(
|
|
1621
|
-
`Refusing connection from ${rinfo.address}:${rinfo.port} due to invalid mtu size.`
|
|
1622
|
-
);
|
|
1948
|
+
return this.server.logger.warn(`Refusing connection from ${rinfo.address}:${rinfo.port} due to invalid mtu size.`);
|
|
1623
1949
|
}
|
|
1624
|
-
const connection = [
|
|
1625
|
-
|
|
1626
|
-
);
|
|
1950
|
+
const connection = [
|
|
1951
|
+
...this.server.connections.values()
|
|
1952
|
+
].find((x) => x.rinfo.address === rinfo.address && x.rinfo.port === rinfo.port);
|
|
1627
1953
|
if (connection) {
|
|
1628
|
-
return this.server.logger.warn(
|
|
1629
|
-
`Refusing connection from ${rinfo.address}:${rinfo.port} due to already established connection.`
|
|
1630
|
-
);
|
|
1954
|
+
return this.server.logger.warn(`Refusing connection from ${rinfo.address}:${rinfo.port} due to already established connection.`);
|
|
1631
1955
|
}
|
|
1632
1956
|
const reply = new OpenConnectionReply2();
|
|
1633
1957
|
reply.guid = this.server.guid;
|
|
1634
1958
|
reply.address = Address.fromIdentifier(rinfo);
|
|
1635
1959
|
reply.mtu = request.mtu;
|
|
1636
1960
|
reply.encryption = false;
|
|
1637
|
-
this.server.logger.debug(
|
|
1638
|
-
`Establishing connection from ${rinfo.address}:${rinfo.port} with mtu size of ${request.mtu}.`
|
|
1639
|
-
);
|
|
1961
|
+
this.server.logger.debug(`Establishing connection from ${rinfo.address}:${rinfo.port} with mtu size of ${request.mtu}.`);
|
|
1640
1962
|
this.server.connections.add(
|
|
1641
1963
|
// Build a new connection instance
|
|
1642
1964
|
new Connection(this.server, rinfo, request.client, request.mtu)
|
|
@@ -1646,68 +1968,71 @@ var Offline = class {
|
|
|
1646
1968
|
};
|
|
1647
1969
|
|
|
1648
1970
|
// src/server/raknet.ts
|
|
1649
|
-
var Server = class extends import_emitter.Emitter {
|
|
1971
|
+
var Server = class Server2 extends import_emitter.Emitter {
|
|
1972
|
+
static {
|
|
1973
|
+
__name(this, "Server");
|
|
1974
|
+
}
|
|
1650
1975
|
/**
|
|
1651
|
-
|
|
1652
|
-
|
|
1976
|
+
* The server tick interval
|
|
1977
|
+
*/
|
|
1653
1978
|
interval = null;
|
|
1654
1979
|
/**
|
|
1655
|
-
|
|
1656
|
-
|
|
1980
|
+
* The raknet server logger
|
|
1981
|
+
*/
|
|
1657
1982
|
logger = new import_logger.Logger("Raknet", import_logger.LoggerColors.CyanBright);
|
|
1658
1983
|
/**
|
|
1659
|
-
|
|
1660
|
-
|
|
1984
|
+
* The server socket
|
|
1985
|
+
*/
|
|
1661
1986
|
socket = (0, import_node_dgram.createSocket)("udp4");
|
|
1662
1987
|
/**
|
|
1663
|
-
|
|
1664
|
-
|
|
1988
|
+
* The server address
|
|
1989
|
+
*/
|
|
1665
1990
|
address;
|
|
1666
1991
|
/**
|
|
1667
|
-
|
|
1668
|
-
|
|
1992
|
+
* The server port
|
|
1993
|
+
*/
|
|
1669
1994
|
port;
|
|
1670
1995
|
/**
|
|
1671
|
-
|
|
1672
|
-
|
|
1996
|
+
* The server guid
|
|
1997
|
+
*/
|
|
1673
1998
|
guid = BigInt(Math.floor(Math.random() * 2 ** 64));
|
|
1674
1999
|
/**
|
|
1675
|
-
|
|
1676
|
-
|
|
2000
|
+
* The server connections
|
|
2001
|
+
*/
|
|
1677
2002
|
connections = /* @__PURE__ */ new Set();
|
|
1678
2003
|
/**
|
|
1679
|
-
|
|
1680
|
-
|
|
2004
|
+
* The server max mtu size
|
|
2005
|
+
*/
|
|
1681
2006
|
maxMtuSize;
|
|
1682
2007
|
/**
|
|
1683
|
-
|
|
1684
|
-
|
|
2008
|
+
* The server min mtu size
|
|
2009
|
+
*/
|
|
1685
2010
|
minMtuSize;
|
|
1686
2011
|
/**
|
|
1687
|
-
|
|
1688
|
-
|
|
2012
|
+
* The server protocol
|
|
2013
|
+
*/
|
|
1689
2014
|
protocol = null;
|
|
1690
2015
|
/**
|
|
1691
|
-
|
|
1692
|
-
|
|
2016
|
+
* The server version
|
|
2017
|
+
*/
|
|
1693
2018
|
version = null;
|
|
1694
2019
|
/**
|
|
1695
|
-
|
|
1696
|
-
|
|
2020
|
+
* The server message
|
|
2021
|
+
*/
|
|
1697
2022
|
message = null;
|
|
1698
2023
|
/**
|
|
1699
|
-
|
|
1700
|
-
|
|
2024
|
+
* The server max connections
|
|
2025
|
+
*/
|
|
1701
2026
|
maxConnections = null;
|
|
1702
2027
|
/**
|
|
1703
|
-
|
|
1704
|
-
|
|
2028
|
+
* Weather the server is alive
|
|
2029
|
+
*/
|
|
1705
2030
|
alive = true;
|
|
1706
2031
|
/**
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
2032
|
+
* Creates a new raknet server
|
|
2033
|
+
* @param address the server address
|
|
2034
|
+
* @param port the server port
|
|
2035
|
+
*/
|
|
1711
2036
|
constructor(address, port = 19132, mtuMaxSize = MAX_MTU_SIZE, mtuMinSize = MIN_MTU_SIZE) {
|
|
1712
2037
|
super();
|
|
1713
2038
|
this.address = address;
|
|
@@ -1719,20 +2044,20 @@ var Server = class extends import_emitter.Emitter {
|
|
|
1719
2044
|
Offline.server = this;
|
|
1720
2045
|
}
|
|
1721
2046
|
/**
|
|
1722
|
-
|
|
1723
|
-
|
|
2047
|
+
* Starts the server
|
|
2048
|
+
*/
|
|
1724
2049
|
start() {
|
|
1725
2050
|
this.socket.bind(this.port, this.address);
|
|
1726
|
-
const tick = () => setTimeout(() => {
|
|
2051
|
+
const tick = /* @__PURE__ */ __name(() => setTimeout(() => {
|
|
1727
2052
|
if (!this.alive || !this.interval) return;
|
|
1728
2053
|
for (const connection of this.connections) connection.tick();
|
|
1729
2054
|
return tick();
|
|
1730
|
-
}, RAKNET_TICK_LEN);
|
|
2055
|
+
}, RAKNET_TICK_LEN), "tick");
|
|
1731
2056
|
this.interval = tick().unref();
|
|
1732
2057
|
}
|
|
1733
2058
|
/**
|
|
1734
|
-
|
|
1735
|
-
|
|
2059
|
+
* Stops the server
|
|
2060
|
+
*/
|
|
1736
2061
|
stop() {
|
|
1737
2062
|
try {
|
|
1738
2063
|
if (this.interval) this.interval = null;
|
|
@@ -1744,10 +2069,10 @@ var Server = class extends import_emitter.Emitter {
|
|
|
1744
2069
|
handle(buffer, rinfo) {
|
|
1745
2070
|
const header = buffer[0];
|
|
1746
2071
|
if (!header) throw new Error("Invalid packet header");
|
|
1747
|
-
const offline = (header &
|
|
1748
|
-
const connection = [
|
|
1749
|
-
(
|
|
1750
|
-
);
|
|
2072
|
+
const offline = (header & Bitflags.Valid) === 0;
|
|
2073
|
+
const connection = [
|
|
2074
|
+
...this.connections.values()
|
|
2075
|
+
].find((x) => x.rinfo.address === rinfo.address && x.rinfo.port === rinfo.port);
|
|
1751
2076
|
if (offline)
|
|
1752
2077
|
return Offline.handle(buffer, rinfo);
|
|
1753
2078
|
if (!offline && connection)
|