@sanctumterra/raknet 1.3.0 → 1.3.2
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/.github/workflows/publish.yml +41 -0
- package/Cargo.toml +16 -0
- package/build.rs +3 -0
- package/dist/client/client-events.d.ts +22 -0
- package/dist/client/client-events.js +2 -0
- package/dist/client/client.d.ts +15 -0
- package/dist/client/client.js +117 -0
- package/dist/client/client_options.d.ts +9 -0
- package/dist/client/client_options.js +11 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +19 -0
- package/dist/proto/decorators/create.d.ts +7 -0
- package/dist/proto/decorators/create.js +79 -0
- package/dist/proto/decorators/index.d.ts +2 -0
- package/dist/proto/decorators/index.js +18 -0
- package/dist/proto/decorators/serialize.d.ts +3 -0
- package/dist/proto/decorators/serialize.js +12 -0
- package/dist/proto/enums/flags.d.ts +6 -0
- package/dist/proto/enums/flags.js +10 -0
- package/dist/proto/enums/index.d.ts +4 -0
- package/dist/proto/enums/index.js +20 -0
- package/dist/proto/enums/packet.d.ts +121 -0
- package/dist/proto/enums/packet.js +125 -0
- package/dist/proto/enums/priority.d.ts +4 -0
- package/dist/proto/enums/priority.js +8 -0
- package/dist/proto/enums/reliability.d.ts +10 -0
- package/dist/proto/enums/reliability.js +14 -0
- package/dist/proto/index.d.ts +4 -0
- package/dist/proto/index.js +20 -0
- package/dist/proto/packets/ack.d.ts +9 -0
- package/dist/proto/packets/ack.js +89 -0
- package/dist/proto/packets/base-packet.d.ts +25 -0
- package/dist/proto/packets/base-packet.js +37 -0
- package/dist/proto/packets/connected-ping.d.ts +4 -0
- package/dist/proto/packets/connected-ping.js +27 -0
- package/dist/proto/packets/connected-pong.d.ts +5 -0
- package/dist/proto/packets/connected-pong.js +32 -0
- package/dist/proto/packets/connection-request-accepted.d.ts +9 -0
- package/dist/proto/packets/connection-request-accepted.js +48 -0
- package/dist/proto/packets/connection-request.d.ts +6 -0
- package/dist/proto/packets/connection-request.js +37 -0
- package/dist/proto/packets/frameset.d.ts +10 -0
- package/dist/proto/packets/frameset.js +37 -0
- package/dist/proto/packets/index.d.ts +16 -0
- package/dist/proto/packets/index.js +32 -0
- package/dist/proto/packets/nack.d.ts +7 -0
- package/dist/proto/packets/nack.js +88 -0
- package/dist/proto/packets/new-incoming-connection.d.ts +8 -0
- package/dist/proto/packets/new-incoming-connection.js +43 -0
- package/dist/proto/packets/open-connection-reply-one.d.ts +7 -0
- package/dist/proto/packets/open-connection-reply-one.js +43 -0
- package/dist/proto/packets/open-connection-reply-two.d.ts +9 -0
- package/dist/proto/packets/open-connection-reply-two.js +48 -0
- package/dist/proto/packets/open-connection-request-one.d.ts +6 -0
- package/dist/proto/packets/open-connection-request-one.js +38 -0
- package/dist/proto/packets/open-connection-request-two.d.ts +8 -0
- package/dist/proto/packets/open-connection-request-two.js +43 -0
- package/dist/proto/packets/types/address.d.ts +47 -0
- package/dist/proto/packets/types/address.js +99 -0
- package/dist/proto/packets/types/data-type.d.ts +20 -0
- package/dist/proto/packets/types/data-type.js +29 -0
- package/dist/proto/packets/types/frame.d.ts +22 -0
- package/dist/proto/packets/types/frame.js +94 -0
- package/dist/proto/packets/types/index.d.ts +6 -0
- package/dist/proto/packets/types/index.js +22 -0
- package/dist/proto/packets/types/magic.d.ts +6 -0
- package/dist/proto/packets/types/magic.js +14 -0
- package/dist/proto/packets/types/mtu.d.ts +8 -0
- package/dist/proto/packets/types/mtu.js +18 -0
- package/dist/proto/packets/types/sys-address.d.ts +10 -0
- package/dist/proto/packets/types/sys-address.js +32 -0
- package/dist/proto/packets/unconnected-ping.d.ts +6 -0
- package/dist/proto/packets/unconnected-ping.js +38 -0
- package/dist/proto/packets/unconnected-pong.d.ts +7 -0
- package/dist/proto/packets/unconnected-pong.js +43 -0
- package/dist/proto/types/advertisement.d.ts +14 -0
- package/dist/proto/types/advertisement.js +17 -0
- package/dist/proto/types/index.d.ts +2 -0
- package/dist/proto/types/index.js +18 -0
- package/dist/proto/types/valid.d.ts +3 -0
- package/dist/proto/types/valid.js +2 -0
- package/package.json +1 -6
- package/src/binarystream/binarystream.rs +313 -0
- package/src/binarystream/endianess.rs +5 -0
- package/src/binarystream/mod.rs +6 -0
- package/src/client/client.rs +201 -0
- package/src/client/framer.rs +391 -0
- package/src/client/mod.rs +5 -0
- package/src/lib.rs +68 -0
- package/src/main.rs +46 -0
- package/src/packets/ack.rs +82 -0
- package/src/packets/connected_ping.rs +27 -0
- package/src/packets/connected_pong.rs +29 -0
- package/src/packets/connection_request.rs +34 -0
- package/src/packets/connection_request_accepted.rs +55 -0
- package/src/packets/frameset.rs +40 -0
- package/src/packets/mod.rs +34 -0
- package/src/packets/nack.rs +82 -0
- package/src/packets/new_incomming_connection.rs +49 -0
- package/src/packets/open_connection_reply_one.rs +48 -0
- package/src/packets/open_connection_reply_two.rs +43 -0
- package/src/packets/open_connection_request_one.rs +56 -0
- package/src/packets/open_connection_request_two.rs +34 -0
- package/src/packets/packet.rs +45 -0
- package/src/packets/packet_types.rs +62 -0
- package/src/packets/types/address.rs +75 -0
- package/src/packets/types/data_type.rs +6 -0
- package/src/packets/types/flags.rs +6 -0
- package/src/packets/types/frame.rs +74 -0
- package/src/packets/types/mod.rs +14 -0
- package/src/packets/types/priority.rs +5 -0
- package/src/packets/types/reliability.rs +45 -0
- package/src/packets/unconnected_ping.rs +41 -0
- package/src/socket/mod.rs +3 -0
- package/src/socket/socket.rs +60 -0
- package/src_client/client/client-events.ts +38 -0
- package/src_client/client/client.ts +146 -0
- package/src_client/client/client_options.ts +17 -0
- package/src_client/client/index.ts +3 -0
- package/src_client/index.ts +4 -0
- package/src_client/proto/decorators/create.ts +87 -0
- package/src_client/proto/decorators/index.ts +2 -0
- package/src_client/proto/decorators/serialize.ts +17 -0
- package/src_client/proto/enums/flags.ts +6 -0
- package/src_client/proto/enums/index.ts +4 -0
- package/src_client/proto/enums/packet.ts +121 -0
- package/src_client/proto/enums/priority.ts +4 -0
- package/src_client/proto/enums/reliability.ts +10 -0
- package/src_client/proto/index.ts +4 -0
- package/src_client/proto/packets/ack.ts +82 -0
- package/src_client/proto/packets/base-packet.ts +38 -0
- package/src_client/proto/packets/connected-ping.ts +9 -0
- package/src_client/proto/packets/connected-pong.ts +10 -0
- package/src_client/proto/packets/connection-request-accepted.ts +14 -0
- package/src_client/proto/packets/connection-request.ts +11 -0
- package/src_client/proto/packets/frameset.ts +15 -0
- package/src_client/proto/packets/index.ts +16 -0
- package/src_client/proto/packets/nack.ts +84 -0
- package/src_client/proto/packets/new-incoming-connection.ts +14 -0
- package/src_client/proto/packets/open-connection-reply-one.ts +22 -0
- package/src_client/proto/packets/open-connection-reply-two.ts +14 -0
- package/src_client/proto/packets/open-connection-request-one.ts +12 -0
- package/src_client/proto/packets/open-connection-request-two.ts +13 -0
- package/src_client/proto/packets/types/address.ts +106 -0
- package/src_client/proto/packets/types/data-type.ts +38 -0
- package/src_client/proto/packets/types/frame.ts +114 -0
- package/src_client/proto/packets/types/index.ts +6 -0
- package/src_client/proto/packets/types/magic.ts +14 -0
- package/src_client/proto/packets/types/mtu.ts +19 -0
- package/src_client/proto/packets/types/sys-address.ts +35 -0
- package/src_client/proto/packets/unconnected-ping.ts +12 -0
- package/src_client/proto/packets/unconnected-pong.ts +13 -0
- package/src_client/proto/types/advertisement.ts +40 -0
- package/src_client/proto/types/index.ts +2 -0
- package/src_client/proto/types/valid.ts +58 -0
- package/tsconfig.json +20 -0
- package/build/index.d.ts +0 -14
- package/build/index.js +0 -315
- package/build/raknet.linux-x64-gnu.node +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: Publish to NPM
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- develop
|
|
7
|
+
- main # Change this to your default branch if different
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
steps:
|
|
14
|
+
- name: Checkout code
|
|
15
|
+
uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- name: Set up Node.js
|
|
18
|
+
uses: actions/setup-node@v4
|
|
19
|
+
with:
|
|
20
|
+
node-version: '20' # Ensure this matches your engines.node version
|
|
21
|
+
registry-url: 'https://registry.npmjs.org'
|
|
22
|
+
|
|
23
|
+
- name: Install dependencies
|
|
24
|
+
run: npm install
|
|
25
|
+
|
|
26
|
+
- name: Run lint
|
|
27
|
+
run: npm run lint
|
|
28
|
+
|
|
29
|
+
- name: Clean build directory
|
|
30
|
+
run: rm -rf build dist # Clean previous build artifacts
|
|
31
|
+
|
|
32
|
+
- name: Build Rust
|
|
33
|
+
run: npm run build:rust
|
|
34
|
+
|
|
35
|
+
- name: Build TypeScript
|
|
36
|
+
run: npm run build:ts
|
|
37
|
+
|
|
38
|
+
- name: Publish to NPM
|
|
39
|
+
run: npm publish --access=public
|
|
40
|
+
env:
|
|
41
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/Cargo.toml
ADDED
package/build.rs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
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;
|
|
@@ -0,0 +1,11 @@
|
|
|
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;
|
|
@@ -0,0 +1,19 @@
|
|
|
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);
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./create"), exports);
|
|
18
|
+
__exportStar(require("./serialize"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 = {}));
|
|
@@ -0,0 +1,20 @@
|
|
|
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);
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export declare enum Packet {
|
|
2
|
+
ConnectedPing = 0,
|
|
3
|
+
UnconnectedPing = 1,
|
|
4
|
+
UnconnectedPingOpenConnections = 2,
|
|
5
|
+
ConnectedPong = 3,
|
|
6
|
+
DetectLostConnections = 4,
|
|
7
|
+
OpenConnectionRequestOne = 5,
|
|
8
|
+
OpenConnectionReplyOne = 6,
|
|
9
|
+
OpenConnectionRequestTwo = 7,
|
|
10
|
+
OpenConnectionReplyTwo = 8,
|
|
11
|
+
ConnectionRequest = 9,
|
|
12
|
+
RemoteSystemRequiresPublicKey = 10,
|
|
13
|
+
OurSystemRequiresSecurity = 11,
|
|
14
|
+
PublicKeyMismatch = 12,
|
|
15
|
+
OutOfBandInternal = 13,
|
|
16
|
+
SndReceiptAcked = 14,
|
|
17
|
+
SndReceiptLoss = 15,
|
|
18
|
+
ConnectionRequestAccepted = 16,
|
|
19
|
+
ConnectionAttemptFailed = 17,
|
|
20
|
+
AlreadyConnected = 18,
|
|
21
|
+
NewIncomingConnection = 19,
|
|
22
|
+
NoFreeIncomingConnections = 20,
|
|
23
|
+
DisconnectionNotification = 21,
|
|
24
|
+
ConnectionLost = 22,
|
|
25
|
+
ConnectionBanned = 23,
|
|
26
|
+
InvalidPassword = 24,
|
|
27
|
+
IncompatibleProtocolVersion = 25,
|
|
28
|
+
IpRecentlyConnected = 26,
|
|
29
|
+
Timestamp = 27,
|
|
30
|
+
UnconnectedPong = 28,
|
|
31
|
+
AdvertiseSystem = 29,
|
|
32
|
+
DownloadProgress = 30,
|
|
33
|
+
RemoteDisconnectionNotification = 31,
|
|
34
|
+
RemoteConnectionLost = 32,
|
|
35
|
+
RemoteNewIncomingConnection = 33,
|
|
36
|
+
FileListTransferHeader = 34,
|
|
37
|
+
FileListTransferFile = 35,
|
|
38
|
+
FileListReferenceTransferFile = 36,
|
|
39
|
+
DdtDownloadRequest = 37,
|
|
40
|
+
TransportString = 38,
|
|
41
|
+
ReplicaManagerConstruction = 39,
|
|
42
|
+
ReplicaManagerScope = 40,
|
|
43
|
+
ReplicaManagerSerialize = 41,
|
|
44
|
+
ReplicaManagerDownloadStarted = 42,
|
|
45
|
+
ReplicaManagerDownloadComplete = 43,
|
|
46
|
+
ConnectionGraphRequest = 44,
|
|
47
|
+
ConnectionGraphReply = 45,
|
|
48
|
+
ConnectionGraphUpdate = 46,
|
|
49
|
+
ConnectionGraphNewConnection = 47,
|
|
50
|
+
ConnectionGraphConnectionLost = 48,
|
|
51
|
+
ConnectionGraphDisconnectionNotification = 49,
|
|
52
|
+
RouteAndMulticast = 50,
|
|
53
|
+
RakVoice = 51,
|
|
54
|
+
AutopatcherGetChangelistSinceDate = 52,
|
|
55
|
+
AutopatcherCreationList = 53,
|
|
56
|
+
AutopatcherDeletionList = 54,
|
|
57
|
+
AutopatcherGetPatch = 55,
|
|
58
|
+
AutopatcherPatchList = 56,
|
|
59
|
+
AutopatcherRepositoryFatalError = 57,
|
|
60
|
+
AutopatcherFinishedInternal = 58,
|
|
61
|
+
AutopatcherFinished = 59,
|
|
62
|
+
AutopatcherRestartApplication = 60,
|
|
63
|
+
NatPunchthroughRequest = 61,
|
|
64
|
+
NatTarget = 62,
|
|
65
|
+
NatTargetNotConnected = 63,
|
|
66
|
+
NatTargetConnectionLost = 64,
|
|
67
|
+
NatConnectAtTime = 65,
|
|
68
|
+
NatSendOfflineMessageAtTime = 66,
|
|
69
|
+
NatClientReady = 67,
|
|
70
|
+
NatPunchthroughFailed = 68,
|
|
71
|
+
NatPunchthroughSucceeded = 69,
|
|
72
|
+
FlexibleChat = 70,
|
|
73
|
+
ReadyEventSet = 71,
|
|
74
|
+
ReadyEventUnset = 72,
|
|
75
|
+
ReadyEventAllSet = 73,
|
|
76
|
+
ReadyEventQuery = 74,
|
|
77
|
+
LobbyGeneral = 75,
|
|
78
|
+
AutoRpcCall = 76,
|
|
79
|
+
AutoRpcRemoteIndex = 77,
|
|
80
|
+
AutoRpcUnknownRemoteIndex = 78,
|
|
81
|
+
RpcRemoteError = 79,
|
|
82
|
+
FileListTransferFile2 = 80,
|
|
83
|
+
FileListReferenceTransferFile2 = 81,
|
|
84
|
+
ChatCommand = 82,
|
|
85
|
+
ChatMessage = 83,
|
|
86
|
+
BridgeDataTransfer = 84,
|
|
87
|
+
ViveSync = 85,
|
|
88
|
+
ViveSyncUnreliable = 86,
|
|
89
|
+
ViveSyncPong = 87,
|
|
90
|
+
ConnectionRequestAcceptedEx = 88,
|
|
91
|
+
ConnectionAttemptFailedEx = 89,
|
|
92
|
+
NewIncomingConnectionEx = 90,
|
|
93
|
+
TwoWayAuthenticationNegotiation = 91,
|
|
94
|
+
TwoWayAuthenticationIncomingChallengeSuccess = 92,
|
|
95
|
+
TwoWayAuthenticationOutgoingChallengeSuccess = 93,
|
|
96
|
+
TwoWayAuthenticationIncomingChallengeFailure = 94,
|
|
97
|
+
TwoWayAuthenticationOutgoingChallengeFailure = 95,
|
|
98
|
+
TwoWayAuthenticationOutgoingChallengeTimeout = 96,
|
|
99
|
+
CloudPostRequest = 97,
|
|
100
|
+
CloudReleaseRequest = 98,
|
|
101
|
+
CloudGetRequest = 99,
|
|
102
|
+
CloudGetResponse = 100,
|
|
103
|
+
CloudUnsubscribeRequest = 101,
|
|
104
|
+
CloudServerToServerCommand = 102,
|
|
105
|
+
CloudSubscriptionNotification = 103,
|
|
106
|
+
LibVoice = 122,
|
|
107
|
+
RelayPlugin = 123,
|
|
108
|
+
NatRequestBoundAddresses = 124,
|
|
109
|
+
NatRespondBoundAddresses = 125,
|
|
110
|
+
Fcm2UpdateUserContext = 126,
|
|
111
|
+
Reserved3 = 127,
|
|
112
|
+
FrameSet = 128,// Set this to FrameSet cause only this will be used
|
|
113
|
+
Reserved5 = 129,
|
|
114
|
+
Reserved6 = 130,
|
|
115
|
+
Reserved7 = 131,
|
|
116
|
+
Reserved8 = 132,
|
|
117
|
+
Reserved9 = 133,
|
|
118
|
+
UserPacketEnum = 134,
|
|
119
|
+
Nack = 160,
|
|
120
|
+
Ack = 192
|
|
121
|
+
}
|