@sanctumterra/raknet 1.3.21 → 1.3.30
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/.yarnrc.yml +3 -0
- package/Cargo.toml +19 -0
- package/build.rs +5 -0
- package/package.json +31 -47
- package/src/lib.rs +9 -0
- package/build/index.d.ts +0 -14
- package/build/raknet.node +0 -0
- package/dist/client/client-events.d.ts +0 -22
- package/dist/client/client-events.js +0 -2
- package/dist/client/client.d.ts +0 -15
- package/dist/client/client.js +0 -117
- package/dist/client/client_options.d.ts +0 -9
- package/dist/client/client_options.js +0 -11
- package/dist/client/index.d.ts +0 -3
- package/dist/client/index.js +0 -19
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -20
- package/dist/proto/decorators/create.d.ts +0 -7
- package/dist/proto/decorators/create.js +0 -79
- package/dist/proto/decorators/index.d.ts +0 -2
- package/dist/proto/decorators/index.js +0 -18
- package/dist/proto/decorators/serialize.d.ts +0 -3
- package/dist/proto/decorators/serialize.js +0 -12
- package/dist/proto/enums/flags.d.ts +0 -6
- package/dist/proto/enums/flags.js +0 -10
- package/dist/proto/enums/index.d.ts +0 -4
- package/dist/proto/enums/index.js +0 -20
- package/dist/proto/enums/packet.d.ts +0 -121
- package/dist/proto/enums/packet.js +0 -125
- package/dist/proto/enums/priority.d.ts +0 -4
- package/dist/proto/enums/priority.js +0 -8
- package/dist/proto/enums/reliability.d.ts +0 -10
- package/dist/proto/enums/reliability.js +0 -14
- package/dist/proto/index.d.ts +0 -4
- package/dist/proto/index.js +0 -20
- package/dist/proto/packets/ack.d.ts +0 -9
- package/dist/proto/packets/ack.js +0 -89
- package/dist/proto/packets/base-packet.d.ts +0 -25
- package/dist/proto/packets/base-packet.js +0 -37
- package/dist/proto/packets/connected-ping.d.ts +0 -4
- package/dist/proto/packets/connected-ping.js +0 -27
- package/dist/proto/packets/connected-pong.d.ts +0 -5
- package/dist/proto/packets/connected-pong.js +0 -32
- package/dist/proto/packets/connection-request-accepted.d.ts +0 -9
- package/dist/proto/packets/connection-request-accepted.js +0 -48
- package/dist/proto/packets/connection-request.d.ts +0 -6
- package/dist/proto/packets/connection-request.js +0 -37
- package/dist/proto/packets/frameset.d.ts +0 -10
- package/dist/proto/packets/frameset.js +0 -37
- package/dist/proto/packets/index.d.ts +0 -16
- package/dist/proto/packets/index.js +0 -32
- package/dist/proto/packets/nack.d.ts +0 -7
- package/dist/proto/packets/nack.js +0 -88
- package/dist/proto/packets/new-incoming-connection.d.ts +0 -8
- package/dist/proto/packets/new-incoming-connection.js +0 -43
- package/dist/proto/packets/open-connection-reply-one.d.ts +0 -7
- package/dist/proto/packets/open-connection-reply-one.js +0 -43
- package/dist/proto/packets/open-connection-reply-two.d.ts +0 -9
- package/dist/proto/packets/open-connection-reply-two.js +0 -48
- package/dist/proto/packets/open-connection-request-one.d.ts +0 -6
- package/dist/proto/packets/open-connection-request-one.js +0 -38
- package/dist/proto/packets/open-connection-request-two.d.ts +0 -8
- package/dist/proto/packets/open-connection-request-two.js +0 -43
- package/dist/proto/packets/types/address.d.ts +0 -47
- package/dist/proto/packets/types/address.js +0 -99
- package/dist/proto/packets/types/data-type.d.ts +0 -20
- package/dist/proto/packets/types/data-type.js +0 -29
- package/dist/proto/packets/types/frame.d.ts +0 -22
- package/dist/proto/packets/types/frame.js +0 -94
- package/dist/proto/packets/types/index.d.ts +0 -6
- package/dist/proto/packets/types/index.js +0 -22
- package/dist/proto/packets/types/magic.d.ts +0 -6
- package/dist/proto/packets/types/magic.js +0 -14
- package/dist/proto/packets/types/mtu.d.ts +0 -8
- package/dist/proto/packets/types/mtu.js +0 -18
- package/dist/proto/packets/types/sys-address.d.ts +0 -10
- package/dist/proto/packets/types/sys-address.js +0 -32
- package/dist/proto/packets/unconnected-ping.d.ts +0 -6
- package/dist/proto/packets/unconnected-ping.js +0 -38
- package/dist/proto/packets/unconnected-pong.d.ts +0 -7
- package/dist/proto/packets/unconnected-pong.js +0 -43
- package/dist/proto/types/advertisement.d.ts +0 -14
- package/dist/proto/types/advertisement.js +0 -17
- package/dist/proto/types/index.d.ts +0 -2
- package/dist/proto/types/index.js +0 -18
- package/dist/proto/types/valid.d.ts +0 -3
- package/dist/proto/types/valid.js +0 -2
- package/tsconfig.json +0 -20
package/.yarnrc.yml
ADDED
package/Cargo.toml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
edition = "2021"
|
|
3
|
+
name = "sanctumterra_raknet"
|
|
4
|
+
version = "0.0.0"
|
|
5
|
+
|
|
6
|
+
[lib]
|
|
7
|
+
crate-type = ["cdylib"]
|
|
8
|
+
|
|
9
|
+
[dependencies]
|
|
10
|
+
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
|
|
11
|
+
napi = { version = "2.12.2", default-features = false, features = ["napi4"] }
|
|
12
|
+
napi-derive = "2.12.2"
|
|
13
|
+
|
|
14
|
+
[build-dependencies]
|
|
15
|
+
napi-build = "2.0.1"
|
|
16
|
+
|
|
17
|
+
[profile.release]
|
|
18
|
+
lto = true
|
|
19
|
+
strip = "symbols"
|
package/build.rs
ADDED
package/package.json
CHANGED
|
@@ -1,60 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanctumterra/raknet",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"main": "
|
|
5
|
-
"types": "
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build:rust": "napi build --release build",
|
|
8
|
-
"build:ts": "tsc",
|
|
9
|
-
"dev": "npm run build:rust && npm run build:ts",
|
|
10
|
-
"format": "npx @biomejs/biome format ./src_client",
|
|
11
|
-
"lint": "npx @biomejs/biome lint ./src_client",
|
|
12
|
-
"lint:write": "npx @biomejs/biome lint --write ./src_client",
|
|
13
|
-
"format:write": "npx @biomejs/biome format --write ./src_client",
|
|
14
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
15
|
-
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
"raknet",
|
|
18
|
-
"napi",
|
|
19
|
-
"rust",
|
|
20
|
-
"native"
|
|
21
|
-
],
|
|
22
|
-
"author": "",
|
|
23
|
-
"license": "ISC",
|
|
24
|
-
"description": "RakNet implementation in Rust with Node.js bindings",
|
|
3
|
+
"version": "1.3.30",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"types": "index.d.ts",
|
|
25
6
|
"napi": {
|
|
26
7
|
"name": "raknet",
|
|
27
8
|
"triples": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
"x86_64-apple-darwin",
|
|
32
|
-
"aarch64-apple-darwin",
|
|
33
|
-
"x86_64-unknown-linux-gnu",
|
|
34
|
-
"aarch64-unknown-linux-gnu"
|
|
35
|
-
]
|
|
9
|
+
"darwin-x64": "x86_64-apple-darwin",
|
|
10
|
+
"linux-x64-gnu": "x86_64-unknown-linux-gnu",
|
|
11
|
+
"win32-x64-msvc": "x86_64-pc-windows-msvc"
|
|
36
12
|
}
|
|
37
13
|
},
|
|
38
|
-
"
|
|
39
|
-
"raknet-node-win.node",
|
|
40
|
-
"raknet-node-linux.node",
|
|
41
|
-
"raknet-node-osx.node",
|
|
42
|
-
"build",
|
|
43
|
-
"dist",
|
|
44
|
-
"tsconfig.json"
|
|
45
|
-
],
|
|
14
|
+
"license": "MIT",
|
|
46
15
|
"devDependencies": {
|
|
47
|
-
"@biomejs/biome": "^1.9.4",
|
|
48
16
|
"@napi-rs/cli": "^2.18.4",
|
|
49
|
-
"
|
|
50
|
-
|
|
17
|
+
"ava": "^6.0.1"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/SanctumTerra/rak"
|
|
22
|
+
},
|
|
23
|
+
"ava": {
|
|
24
|
+
"timeout": "3m"
|
|
51
25
|
},
|
|
52
26
|
"engines": {
|
|
53
|
-
"node": ">=
|
|
27
|
+
"node": ">= 10"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"artifacts": "napi artifacts",
|
|
31
|
+
"build": "napi build --platform --release",
|
|
32
|
+
"build:debug": "napi build --platform",
|
|
33
|
+
"prepublishOnly": "napi prepublish -t npm",
|
|
34
|
+
"test": "npm run build && ava",
|
|
35
|
+
"universal": "napi universal",
|
|
36
|
+
"version": "napi version"
|
|
54
37
|
},
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
"@
|
|
58
|
-
"
|
|
38
|
+
"packageManager": "yarn@4.5.1",
|
|
39
|
+
"optionalDependencies": {
|
|
40
|
+
"@sanctumterra/raknet-win32-x64-msvc": "1.3.30",
|
|
41
|
+
"@sanctumterra/raknet-darwin-x64": "1.3.30",
|
|
42
|
+
"@sanctumterra/raknet-linux-x64-gnu": "1.3.30"
|
|
59
43
|
}
|
|
60
|
-
}
|
|
44
|
+
}
|
package/src/lib.rs
ADDED
package/build/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
|
|
4
|
-
/* auto-generated by NAPI-RS */
|
|
5
|
-
|
|
6
|
-
export declare class RaknetClient {
|
|
7
|
-
constructor(ip?: string | undefined | null, port?: number | undefined | null, mtuSize?: number | undefined | null)
|
|
8
|
-
connect(): void
|
|
9
|
-
tick(): void
|
|
10
|
-
ping(): void
|
|
11
|
-
receive(): Buffer
|
|
12
|
-
frameAndSend(buffer: Buffer): void
|
|
13
|
-
send(buffer: Buffer): void
|
|
14
|
-
}
|
package/build/raknet.node
DELETED
|
Binary file
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Ack, ConnectedPing, ConnectionRequest, NewIncomingConnection, OpenConnectionReplyOne, OpenConnectionReplyTwo, OpenConnectionRequestOne, OpenConnectionRequestTwo, UnconnectedPing, UnconnectedPong, Frameset, Nack, ConnectedPong, ConnectionRequestAccepted } from "../proto";
|
|
2
|
-
export interface ClientEvents {
|
|
3
|
-
"open-connection-reply-one": [OpenConnectionReplyOne];
|
|
4
|
-
"open-connection-reply-two": [OpenConnectionReplyTwo];
|
|
5
|
-
"open-connection-request-one": [OpenConnectionRequestOne];
|
|
6
|
-
"open-connection-request-two": [OpenConnectionRequestTwo];
|
|
7
|
-
"unconnected-ping": [UnconnectedPing];
|
|
8
|
-
"unconnected-pong": [UnconnectedPong];
|
|
9
|
-
frameset: [Frameset];
|
|
10
|
-
"connected-ping": [ConnectedPing];
|
|
11
|
-
"connection-request": [ConnectionRequest];
|
|
12
|
-
"new-incoming-connection": [NewIncomingConnection];
|
|
13
|
-
"connection-request-accepted": [ConnectionRequestAccepted];
|
|
14
|
-
"connected-pong": [ConnectedPong];
|
|
15
|
-
encapsulated: [Buffer];
|
|
16
|
-
ack: [Ack];
|
|
17
|
-
nack: [Nack];
|
|
18
|
-
error: [Error];
|
|
19
|
-
close: [];
|
|
20
|
-
connect: [];
|
|
21
|
-
tick: [];
|
|
22
|
-
}
|
package/dist/client/client.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import Emitter from "@serenityjs/emitter";
|
|
2
|
-
import { type ClientOptions } from "./client_options";
|
|
3
|
-
import type { ClientEvents } from "./client-events";
|
|
4
|
-
export declare class Client extends Emitter<ClientEvents> {
|
|
5
|
-
private rakSocket;
|
|
6
|
-
options: ClientOptions;
|
|
7
|
-
ticker: NodeJS.Timeout;
|
|
8
|
-
tick: number;
|
|
9
|
-
private advertisement;
|
|
10
|
-
constructor(options: Partial<ClientOptions>);
|
|
11
|
-
connect(): Promise<string>;
|
|
12
|
-
ping(): Promise<string>;
|
|
13
|
-
frameAndSend(buffer: Buffer): void;
|
|
14
|
-
private handleData;
|
|
15
|
-
}
|
package/dist/client/client.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Client = void 0;
|
|
4
|
-
const emitter_1 = require("@serenityjs/emitter");
|
|
5
|
-
const index_1 = require("../index");
|
|
6
|
-
const client_options_1 = require("./client_options");
|
|
7
|
-
const proto_1 = require("../proto");
|
|
8
|
-
class Client extends emitter_1.default {
|
|
9
|
-
rakSocket;
|
|
10
|
-
options;
|
|
11
|
-
ticker;
|
|
12
|
-
tick = 0;
|
|
13
|
-
advertisement;
|
|
14
|
-
constructor(options) {
|
|
15
|
-
super();
|
|
16
|
-
this.options = { ...client_options_1.defaultClientOptions, ...options };
|
|
17
|
-
this.rakSocket = new index_1.RaknetClient(this.options.address, this.options.port, this.options.mtuSize);
|
|
18
|
-
}
|
|
19
|
-
async connect() {
|
|
20
|
-
this.rakSocket.connect();
|
|
21
|
-
this.ticker = setInterval(() => {
|
|
22
|
-
this.rakSocket.tick();
|
|
23
|
-
this.handleData(this.rakSocket.receive());
|
|
24
|
-
this.tick++;
|
|
25
|
-
}, 50);
|
|
26
|
-
await this.ping();
|
|
27
|
-
return new Promise((resolve, reject) => {
|
|
28
|
-
this.once("ack", () => {
|
|
29
|
-
resolve(this.advertisement);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
async ping() {
|
|
34
|
-
return new Promise((resolve, reject) => {
|
|
35
|
-
const timeout = setTimeout(() => {
|
|
36
|
-
cleanup();
|
|
37
|
-
reject(new Error("Ping timeout"));
|
|
38
|
-
}, 5000);
|
|
39
|
-
const pongHandler = (pong) => {
|
|
40
|
-
this.advertisement = pong.message;
|
|
41
|
-
cleanup();
|
|
42
|
-
resolve(pong.message);
|
|
43
|
-
};
|
|
44
|
-
const cleanup = () => {
|
|
45
|
-
clearTimeout(timeout);
|
|
46
|
-
this.remove("unconnected-pong", pongHandler);
|
|
47
|
-
};
|
|
48
|
-
this.rakSocket.ping();
|
|
49
|
-
this.once("unconnected-pong", pongHandler);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
frameAndSend(buffer) {
|
|
53
|
-
this.rakSocket.frameAndSend(buffer);
|
|
54
|
-
}
|
|
55
|
-
handleData(data) {
|
|
56
|
-
if (!data || data.length === 0) {
|
|
57
|
-
// console.log("Received empty data buffer");
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
let packetId = data[0];
|
|
61
|
-
if ((packetId & 0xf0) === 0x80)
|
|
62
|
-
packetId = 0x80;
|
|
63
|
-
switch (packetId) {
|
|
64
|
-
case proto_1.Packet.Ack: {
|
|
65
|
-
const ack = new proto_1.Ack(data).deserialize();
|
|
66
|
-
this.emit("ack", ack);
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
case proto_1.Packet.FrameSet: {
|
|
70
|
-
const frameset = new proto_1.Frameset(data).deserialize();
|
|
71
|
-
this.emit("frameset", frameset);
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
case proto_1.Packet.ConnectedPing: {
|
|
75
|
-
const connectedPing = new proto_1.ConnectedPing(data).deserialize();
|
|
76
|
-
this.emit("connected-ping", connectedPing);
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
case proto_1.Packet.ConnectionRequest: {
|
|
80
|
-
const connectionRequest = new proto_1.ConnectionRequest(data).deserialize();
|
|
81
|
-
this.emit("connection-request", connectionRequest);
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
case proto_1.Packet.NewIncomingConnection: {
|
|
85
|
-
const newIncomingConnection = new proto_1.NewIncomingConnection(data).deserialize();
|
|
86
|
-
this.emit("new-incoming-connection", newIncomingConnection);
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
case proto_1.Packet.UnconnectedPing: {
|
|
90
|
-
const unconnectedPing = new proto_1.UnconnectedPing(data).deserialize();
|
|
91
|
-
this.emit("unconnected-ping", unconnectedPing);
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
case proto_1.Packet.UnconnectedPong: {
|
|
95
|
-
const unconnectedPong = new proto_1.UnconnectedPong(data).deserialize();
|
|
96
|
-
this.emit("unconnected-pong", unconnectedPong);
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
case proto_1.Packet.Nack: {
|
|
100
|
-
const nack = new proto_1.Nack(data).deserialize();
|
|
101
|
-
this.emit("nack", nack);
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
case proto_1.Packet.ConnectedPong: {
|
|
105
|
-
const connectedPong = new proto_1.ConnectedPong(data).deserialize();
|
|
106
|
-
this.emit("connected-pong", connectedPong);
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
case proto_1.Packet.ConnectionRequestAccepted: {
|
|
110
|
-
const connectionRequestAccepted = new proto_1.ConnectionRequestAccepted(data).deserialize();
|
|
111
|
-
this.emit("connection-request-accepted", connectionRequestAccepted);
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
exports.Client = Client;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultClientOptions = void 0;
|
|
4
|
-
const defaultClientOptions = {
|
|
5
|
-
address: "127.0.0.1",
|
|
6
|
-
port: 19132,
|
|
7
|
-
mtuSize: 1492,
|
|
8
|
-
debug: false,
|
|
9
|
-
timeout: 5000,
|
|
10
|
-
};
|
|
11
|
-
exports.defaultClientOptions = defaultClientOptions;
|
package/dist/client/index.d.ts
DELETED
package/dist/client/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./client"), exports);
|
|
18
|
-
__exportStar(require("./client-events"), exports);
|
|
19
|
-
__exportStar(require("./client_options"), exports);
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
require("reflect-metadata");
|
|
18
|
-
__exportStar(require("../build"), exports);
|
|
19
|
-
__exportStar(require("./client"), exports);
|
|
20
|
-
__exportStar(require("./proto"), exports);
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Create = Create;
|
|
4
|
-
/**
|
|
5
|
-
* Thanks to SerenityJS as an example.
|
|
6
|
-
* @param id
|
|
7
|
-
* @returns
|
|
8
|
-
*/
|
|
9
|
-
function Create(id) {
|
|
10
|
-
return (target) => {
|
|
11
|
-
target.id = id;
|
|
12
|
-
const packetData = Reflect.getOwnMetadata("properties", target.prototype);
|
|
13
|
-
const properties = Reflect.getMetadata("properties", target) || [];
|
|
14
|
-
if (!properties.includes("serialize")) {
|
|
15
|
-
target.prototype.serialize = function () {
|
|
16
|
-
this.clear();
|
|
17
|
-
if (id < 1)
|
|
18
|
-
throw new Error("Packet ID cannot be less than 1.");
|
|
19
|
-
if (id <= 255)
|
|
20
|
-
this.writeUint8(id);
|
|
21
|
-
else if (id <= 65535)
|
|
22
|
-
this.writeUint16(id);
|
|
23
|
-
else if (id <= 4294967295)
|
|
24
|
-
this.writeUint32(id);
|
|
25
|
-
else
|
|
26
|
-
throw new Error("Packet ID cannot be greater than 4294967295.");
|
|
27
|
-
if (!packetData)
|
|
28
|
-
return this.getBuffer();
|
|
29
|
-
for (const { name, type, endian, parameter } of packetData) {
|
|
30
|
-
if (parameter) {
|
|
31
|
-
const value = this[parameter];
|
|
32
|
-
const dtype = type;
|
|
33
|
-
const data = this[name];
|
|
34
|
-
dtype.write(this, data, endian, value);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
const dtype = type;
|
|
38
|
-
const data = this[name];
|
|
39
|
-
dtype.write(this, data, endian);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return Buffer.from(this.binary);
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
if (!properties.includes("deserialize")) {
|
|
46
|
-
target.prototype.deserialize = function () {
|
|
47
|
-
if (this.binary.length === 0)
|
|
48
|
-
return this;
|
|
49
|
-
if (id <= 255)
|
|
50
|
-
target.id = this.readUint8();
|
|
51
|
-
else if (id <= 65535)
|
|
52
|
-
target.id = this.readUint16();
|
|
53
|
-
else if (id <= 4294967295)
|
|
54
|
-
target.id = this.readUint32();
|
|
55
|
-
else
|
|
56
|
-
throw new Error("Invalid packet ID range");
|
|
57
|
-
if (!packetData)
|
|
58
|
-
return this;
|
|
59
|
-
for (const { name, type, endian, parameter } of packetData) {
|
|
60
|
-
if (parameter) {
|
|
61
|
-
const value = this[parameter];
|
|
62
|
-
const dtype = type;
|
|
63
|
-
const data = this[name];
|
|
64
|
-
this[name] = dtype.read(this, endian, value);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
const dtype = type;
|
|
68
|
-
const data = this[name];
|
|
69
|
-
this[name] = dtype.read(this, endian);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return this;
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
if (!properties.includes("getId")) {
|
|
76
|
-
target.prototype.getId = () => target.id;
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./create"), exports);
|
|
18
|
-
__exportStar(require("./serialize"), exports);
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Serialize = Serialize;
|
|
4
|
-
function Serialize(type, endian = 0 /* Endianness.Big */, parameter) {
|
|
5
|
-
if (!type)
|
|
6
|
-
throw new Error("@Serialize() must be given a type.");
|
|
7
|
-
return (target, propertyKey) => {
|
|
8
|
-
const properties = Reflect.getMetadata("properties", target) || [];
|
|
9
|
-
properties.push({ name: propertyKey, type, endian, parameter });
|
|
10
|
-
Reflect.defineMetadata("properties", properties, target);
|
|
11
|
-
};
|
|
12
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Flags = void 0;
|
|
4
|
-
var Flags;
|
|
5
|
-
(function (Flags) {
|
|
6
|
-
Flags[Flags["Split"] = 16] = "Split";
|
|
7
|
-
Flags[Flags["Valid"] = 128] = "Valid";
|
|
8
|
-
Flags[Flags["Ack"] = 64] = "Ack";
|
|
9
|
-
Flags[Flags["Nak"] = 32] = "Nak";
|
|
10
|
-
})(Flags || (exports.Flags = Flags = {}));
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./packet"), exports);
|
|
18
|
-
__exportStar(require("./flags"), exports);
|
|
19
|
-
__exportStar(require("./reliability"), exports);
|
|
20
|
-
__exportStar(require("./priority"), exports);
|