@serenityjs/raknet 0.3.2 → 0.3.3-beta-20240611195516
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.d.ts +27 -5
- package/dist/index.js +43 -29
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -137,7 +137,7 @@ declare class Connection {
|
|
|
137
137
|
/**
|
|
138
138
|
* The server instance
|
|
139
139
|
*/
|
|
140
|
-
protected readonly server:
|
|
140
|
+
protected readonly server: Server;
|
|
141
141
|
/**
|
|
142
142
|
* The status of the connection
|
|
143
143
|
*/
|
|
@@ -175,7 +175,7 @@ declare class Connection {
|
|
|
175
175
|
* @param guid The GUID
|
|
176
176
|
* @param mtu The maximum transmission unit
|
|
177
177
|
*/
|
|
178
|
-
constructor(server:
|
|
178
|
+
constructor(server: Server, identifier: NetworkIdentifier, guid: bigint, mtu: number);
|
|
179
179
|
/**
|
|
180
180
|
* Ticks the connection
|
|
181
181
|
*/
|
|
@@ -260,7 +260,7 @@ declare class Connection {
|
|
|
260
260
|
/**
|
|
261
261
|
* The raknet server
|
|
262
262
|
*/
|
|
263
|
-
declare class
|
|
263
|
+
declare class Server extends Emitter<RaknetEvents> {
|
|
264
264
|
/**
|
|
265
265
|
* The server tick interval
|
|
266
266
|
*/
|
|
@@ -340,7 +340,7 @@ declare class Offline {
|
|
|
340
340
|
/**
|
|
341
341
|
* The server instance
|
|
342
342
|
*/
|
|
343
|
-
static server:
|
|
343
|
+
static server: Server;
|
|
344
344
|
/**
|
|
345
345
|
* Handles all incoming offline packets
|
|
346
346
|
* @param buffer The packet buffer
|
|
@@ -791,6 +791,28 @@ declare class ConnectionRequestAccepted extends BasePacket {
|
|
|
791
791
|
timestamp: bigint;
|
|
792
792
|
}
|
|
793
793
|
|
|
794
|
+
/**
|
|
795
|
+
* Represents an open connection reply 1 packet.
|
|
796
|
+
*/
|
|
797
|
+
declare class NewIncomingConnection extends BasePacket {
|
|
798
|
+
/**
|
|
799
|
+
* the server adress of the reply.
|
|
800
|
+
*/
|
|
801
|
+
serverAddress: string;
|
|
802
|
+
/**
|
|
803
|
+
* unknown what this is used for.
|
|
804
|
+
*/
|
|
805
|
+
internalAddress: string;
|
|
806
|
+
/**
|
|
807
|
+
* The incoming timestamp of the reply.
|
|
808
|
+
*/
|
|
809
|
+
incomingTimestamp: bigint;
|
|
810
|
+
/**
|
|
811
|
+
* The server timestamp of the reply.
|
|
812
|
+
*/
|
|
813
|
+
serverTimestamp: bigint;
|
|
814
|
+
}
|
|
815
|
+
|
|
794
816
|
/**
|
|
795
817
|
* Proto decorator for packet classes.
|
|
796
818
|
*
|
|
@@ -826,4 +848,4 @@ declare const MinMtuSize = 400;
|
|
|
826
848
|
*/
|
|
827
849
|
declare const MaxMtuSize = 1492;
|
|
828
850
|
|
|
829
|
-
export { Ack, Address, BasePacket, Bitflags, ConnectedPing, ConnectedPong, Connection, ConnectionRequest, ConnectionRequestAccepted, DataType, Disconnect, Frame, FrameSet, MTU, Magic, MaxMtuSize, MinMtuSize, Nack, type NetworkIdentifier, Offline, OpenConnectionReply1, OpenConnectionReply2, OpenConnectionRequest1, OpenConnectionRequest2, Packet, type PacketMetadata, Priority, Proto, Protocol, type RaknetEvents,
|
|
851
|
+
export { Ack, Address, BasePacket, Bitflags, ConnectedPing, ConnectedPong, Connection, ConnectionRequest, ConnectionRequestAccepted, DataType, Disconnect, Frame, FrameSet, MTU, Magic, MaxMtuSize, MinMtuSize, Nack, type NetworkIdentifier, NewIncomingConnection, Offline, OpenConnectionReply1, OpenConnectionReply2, OpenConnectionRequest1, OpenConnectionRequest2, Packet, type PacketMetadata, Priority, Proto, Protocol, type RaknetEvents, RaknetTPS, RaknetTickLength, Reliability, Serialize, Server, Status, SystemAddress, UnconnectedPing, UnconnectedPong, type ValidTypes, udpHeaderSize };
|
package/dist/index.js
CHANGED
|
@@ -21,8 +21,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
21
21
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
22
|
if (decorator = decorators[i])
|
|
23
23
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
-
if (kind && result)
|
|
25
|
-
__defProp(target, key, result);
|
|
24
|
+
if (kind && result) __defProp(target, key, result);
|
|
26
25
|
return result;
|
|
27
26
|
};
|
|
28
27
|
|
|
@@ -47,6 +46,7 @@ __export(src_exports, {
|
|
|
47
46
|
MaxMtuSize: () => MaxMtuSize,
|
|
48
47
|
MinMtuSize: () => MinMtuSize,
|
|
49
48
|
Nack: () => Nack,
|
|
49
|
+
NewIncomingConnection: () => NewIncomingConnection,
|
|
50
50
|
Offline: () => Offline,
|
|
51
51
|
OpenConnectionReply1: () => OpenConnectionReply1,
|
|
52
52
|
OpenConnectionReply2: () => OpenConnectionReply2,
|
|
@@ -56,11 +56,11 @@ __export(src_exports, {
|
|
|
56
56
|
Priority: () => Priority,
|
|
57
57
|
Proto: () => Proto,
|
|
58
58
|
Protocol: () => Protocol,
|
|
59
|
-
RaknetServer: () => RaknetServer,
|
|
60
59
|
RaknetTPS: () => RaknetTPS,
|
|
61
60
|
RaknetTickLength: () => RaknetTickLength,
|
|
62
61
|
Reliability: () => Reliability,
|
|
63
62
|
Serialize: () => Serialize,
|
|
63
|
+
Server: () => Server,
|
|
64
64
|
Status: () => Status,
|
|
65
65
|
SystemAddress: () => SystemAddress,
|
|
66
66
|
UnconnectedPing: () => UnconnectedPing,
|
|
@@ -83,8 +83,7 @@ function Proto(id) {
|
|
|
83
83
|
target.prototype.serialize = function() {
|
|
84
84
|
this.flush();
|
|
85
85
|
target.id_type.write(this, target.id);
|
|
86
|
-
if (!metadata)
|
|
87
|
-
return this.getBuffer();
|
|
86
|
+
if (!metadata) return this.getBuffer();
|
|
88
87
|
for (const { name, type, endian, parameter } of metadata) {
|
|
89
88
|
if (parameter) {
|
|
90
89
|
const value = this[parameter];
|
|
@@ -97,11 +96,9 @@ function Proto(id) {
|
|
|
97
96
|
};
|
|
98
97
|
if (!properties.includes("deserialize"))
|
|
99
98
|
target.prototype.deserialize = function() {
|
|
100
|
-
if (this.binary.length === 0)
|
|
101
|
-
return this;
|
|
99
|
+
if (this.binary.length === 0) return this;
|
|
102
100
|
target.id_type.read(this);
|
|
103
|
-
if (!metadata)
|
|
104
|
-
return this;
|
|
101
|
+
if (!metadata) return this;
|
|
105
102
|
for (const { name, type, endian, parameter } of metadata) {
|
|
106
103
|
if (parameter) {
|
|
107
104
|
const value = this[parameter];
|
|
@@ -133,8 +130,7 @@ function Proto(id) {
|
|
|
133
130
|
// src/decorators/serialize.ts
|
|
134
131
|
var import_binarystream = require("@serenityjs/binarystream");
|
|
135
132
|
function Serialize(type, endian = import_binarystream.Endianness.Big, parameter) {
|
|
136
|
-
if (!type)
|
|
137
|
-
throw new Error("@Serialize() failed, no type provided.");
|
|
133
|
+
if (!type) throw new Error("@Serialize() failed, no type provided.");
|
|
138
134
|
return function(target, name) {
|
|
139
135
|
const properties = Reflect.getMetadata("properties", target) || [];
|
|
140
136
|
properties.push({ name, type, endian, parameter });
|
|
@@ -979,6 +975,30 @@ ConnectionRequestAccepted = __decorateClass([
|
|
|
979
975
|
Proto(16 /* ConnectionRequestAccepted */)
|
|
980
976
|
], ConnectionRequestAccepted);
|
|
981
977
|
|
|
978
|
+
// src/proto/data/new-incoming-connection.ts
|
|
979
|
+
var import_binarystream18 = require("@serenityjs/binarystream");
|
|
980
|
+
var NewIncomingConnection = class extends BasePacket {
|
|
981
|
+
serverAddress;
|
|
982
|
+
internalAddress;
|
|
983
|
+
incomingTimestamp;
|
|
984
|
+
serverTimestamp;
|
|
985
|
+
};
|
|
986
|
+
__decorateClass([
|
|
987
|
+
Serialize(Address)
|
|
988
|
+
], NewIncomingConnection.prototype, "serverAddress", 2);
|
|
989
|
+
__decorateClass([
|
|
990
|
+
Serialize(Address)
|
|
991
|
+
], NewIncomingConnection.prototype, "internalAddress", 2);
|
|
992
|
+
__decorateClass([
|
|
993
|
+
Serialize(import_binarystream18.Long)
|
|
994
|
+
], NewIncomingConnection.prototype, "incomingTimestamp", 2);
|
|
995
|
+
__decorateClass([
|
|
996
|
+
Serialize(import_binarystream18.Long)
|
|
997
|
+
], NewIncomingConnection.prototype, "serverTimestamp", 2);
|
|
998
|
+
NewIncomingConnection = __decorateClass([
|
|
999
|
+
Proto(19 /* NewIncomingConnection */)
|
|
1000
|
+
], NewIncomingConnection);
|
|
1001
|
+
|
|
982
1002
|
// src/server/raknet.ts
|
|
983
1003
|
var import_node_dgram = require("dgram");
|
|
984
1004
|
var import_emitter = require("@serenityjs/emitter");
|
|
@@ -993,7 +1013,7 @@ var MinMtuSize = 400;
|
|
|
993
1013
|
var MaxMtuSize = 1492;
|
|
994
1014
|
|
|
995
1015
|
// src/server/connection.ts
|
|
996
|
-
var
|
|
1016
|
+
var import_binarystream19 = require("@serenityjs/binarystream");
|
|
997
1017
|
var Connection = class {
|
|
998
1018
|
/**
|
|
999
1019
|
* The server instance
|
|
@@ -1277,8 +1297,7 @@ var Connection = class {
|
|
|
1277
1297
|
* @param frame The frame
|
|
1278
1298
|
*/
|
|
1279
1299
|
handleFrame(frame) {
|
|
1280
|
-
if (frame.isFragmented())
|
|
1281
|
-
return this.handleFragment(frame);
|
|
1300
|
+
if (frame.isFragmented()) return this.handleFragment(frame);
|
|
1282
1301
|
if (frame.isSequenced()) {
|
|
1283
1302
|
if (frame.sequenceIndex < this.inputHighestSequenceIndex[frame.orderChannel] || frame.orderIndex < this.inputOrderIndex[frame.orderChannel]) {
|
|
1284
1303
|
this.server.logger.debug(
|
|
@@ -1304,8 +1323,7 @@ var Connection = class {
|
|
|
1304
1323
|
);
|
|
1305
1324
|
for (; outOfOrderQueue.has(index); index++) {
|
|
1306
1325
|
const frame2 = outOfOrderQueue.get(index);
|
|
1307
|
-
if (!frame2)
|
|
1308
|
-
break;
|
|
1326
|
+
if (!frame2) break;
|
|
1309
1327
|
this.incomingBatch(frame2.payload);
|
|
1310
1328
|
outOfOrderQueue.delete(index);
|
|
1311
1329
|
}
|
|
@@ -1313,8 +1331,7 @@ var Connection = class {
|
|
|
1313
1331
|
this.inputOrderIndex[frame.orderChannel] = index;
|
|
1314
1332
|
} else if (frame.orderIndex > this.inputOrderIndex[frame.orderChannel]) {
|
|
1315
1333
|
const unordered = this.inputOrderingQueue.get(frame.orderChannel);
|
|
1316
|
-
if (!unordered)
|
|
1317
|
-
return;
|
|
1334
|
+
if (!unordered) return;
|
|
1318
1335
|
unordered.set(frame.orderIndex, frame);
|
|
1319
1336
|
}
|
|
1320
1337
|
} else {
|
|
@@ -1328,11 +1345,10 @@ var Connection = class {
|
|
|
1328
1345
|
handleFragment(frame) {
|
|
1329
1346
|
if (this.fragmentsQueue.has(frame.fragmentId)) {
|
|
1330
1347
|
const fragment = this.fragmentsQueue.get(frame.fragmentId);
|
|
1331
|
-
if (!fragment)
|
|
1332
|
-
return;
|
|
1348
|
+
if (!fragment) return;
|
|
1333
1349
|
fragment.set(frame.fragmentIndex, frame);
|
|
1334
1350
|
if (fragment.size === frame.fragmentSize) {
|
|
1335
|
-
const stream = new
|
|
1351
|
+
const stream = new import_binarystream19.BinaryStream();
|
|
1336
1352
|
for (let index = 0; index < fragment.size; index++) {
|
|
1337
1353
|
const sframe = fragment.get(index);
|
|
1338
1354
|
stream.writeBuffer(sframe.payload);
|
|
@@ -1374,8 +1390,7 @@ var Connection = class {
|
|
|
1374
1390
|
const buffer = Buffer.from(frame.payload);
|
|
1375
1391
|
const fragmentId = this.outputFragmentIndex++ % 65536;
|
|
1376
1392
|
for (let index = 0; index < buffer.byteLength; index += maxSize) {
|
|
1377
|
-
if (index !== 0)
|
|
1378
|
-
frame.reliableIndex = this.outputReliableIndex++;
|
|
1393
|
+
if (index !== 0) frame.reliableIndex = this.outputReliableIndex++;
|
|
1379
1394
|
frame.payload = buffer.subarray(index, index + maxSize);
|
|
1380
1395
|
frame.fragmentIndex = index / maxSize;
|
|
1381
1396
|
frame.fragmentId = fragmentId;
|
|
@@ -1400,8 +1415,7 @@ var Connection = class {
|
|
|
1400
1415
|
this.sendFrameQueue();
|
|
1401
1416
|
}
|
|
1402
1417
|
this.outputFrameQueue.frames.push(frame);
|
|
1403
|
-
if (priority === 1 /* Immediate */)
|
|
1404
|
-
return this.sendFrameQueue();
|
|
1418
|
+
if (priority === 1 /* Immediate */) return this.sendFrameQueue();
|
|
1405
1419
|
}
|
|
1406
1420
|
/**
|
|
1407
1421
|
* Sends the output frame queue
|
|
@@ -1567,7 +1581,7 @@ var Offline = class {
|
|
|
1567
1581
|
};
|
|
1568
1582
|
|
|
1569
1583
|
// src/server/raknet.ts
|
|
1570
|
-
var
|
|
1584
|
+
var Server = class extends import_emitter.Emitter {
|
|
1571
1585
|
/**
|
|
1572
1586
|
* The server tick interval
|
|
1573
1587
|
*/
|
|
@@ -1659,8 +1673,7 @@ var RaknetServer = class extends import_emitter.Emitter {
|
|
|
1659
1673
|
*/
|
|
1660
1674
|
stop() {
|
|
1661
1675
|
try {
|
|
1662
|
-
if (this.interval)
|
|
1663
|
-
clearInterval(this.interval);
|
|
1676
|
+
if (this.interval) clearInterval(this.interval);
|
|
1664
1677
|
this.socket.close();
|
|
1665
1678
|
} catch {
|
|
1666
1679
|
void this.emit("error", new Error("Failed to close the server"));
|
|
@@ -1728,6 +1741,7 @@ var RaknetServer = class extends import_emitter.Emitter {
|
|
|
1728
1741
|
MaxMtuSize,
|
|
1729
1742
|
MinMtuSize,
|
|
1730
1743
|
Nack,
|
|
1744
|
+
NewIncomingConnection,
|
|
1731
1745
|
Offline,
|
|
1732
1746
|
OpenConnectionReply1,
|
|
1733
1747
|
OpenConnectionReply2,
|
|
@@ -1737,11 +1751,11 @@ var RaknetServer = class extends import_emitter.Emitter {
|
|
|
1737
1751
|
Priority,
|
|
1738
1752
|
Proto,
|
|
1739
1753
|
Protocol,
|
|
1740
|
-
RaknetServer,
|
|
1741
1754
|
RaknetTPS,
|
|
1742
1755
|
RaknetTickLength,
|
|
1743
1756
|
Reliability,
|
|
1744
1757
|
Serialize,
|
|
1758
|
+
Server,
|
|
1745
1759
|
Status,
|
|
1746
1760
|
SystemAddress,
|
|
1747
1761
|
UnconnectedPing,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serenityjs/raknet",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3-beta-20240611195516",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"repository": "https://github.com/SerenityJS/serenity",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"preset": "@serenityjs/jest-presets/jest/node"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@serenityjs/eslint-config": "
|
|
22
|
-
"@serenityjs/jest-presets": "
|
|
23
|
-
"@serenityjs/typescript-config": "
|
|
21
|
+
"@serenityjs/eslint-config": "0.3.3-beta-20240611195516",
|
|
22
|
+
"@serenityjs/jest-presets": "0.3.3-beta-20240611195516",
|
|
23
|
+
"@serenityjs/typescript-config": "0.3.3-beta-20240611195516",
|
|
24
24
|
"@types/jest": "^29.5.12",
|
|
25
25
|
"@types/node": "^20.11.24",
|
|
26
26
|
"jest": "^29.7.0",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@serenityjs/binarystream": "^2.5.2",
|
|
32
|
-
"@serenityjs/emitter": "
|
|
33
|
-
"@serenityjs/logger": "
|
|
32
|
+
"@serenityjs/emitter": "0.3.3-beta-20240611195516",
|
|
33
|
+
"@serenityjs/logger": "0.3.3-beta-20240611195516",
|
|
34
34
|
"reflect-metadata": "^0.2.1",
|
|
35
35
|
"typedoc": "^0.25.13"
|
|
36
36
|
}
|