Skip to content

Commit 5d0808e

Browse files
committed
Server implementation
1 parent 4f7216d commit 5d0808e

15 files changed

+937
-15
lines changed

README.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# RakNet Library
2+
3+
This is a library for the RakNet protocol.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @sanctumterra/raknet
9+
```
10+
11+
12+
## Examples
13+
14+
### Server
15+
16+
```ts
17+
import { Server } from "./src/index";
18+
19+
const server = new Server({
20+
host: "0.0.0.0",
21+
port: 19132,
22+
});
23+
24+
server.on("connect", (connection) => {
25+
console.log(`New connection from ${connection.remoteInfo.address}`);
26+
connection.on("encapsulated", (buffer) => {
27+
console.log(`Received encapsulated data from ${connection.remoteInfo.address}`);
28+
console.log(buffer);
29+
});
30+
});
31+
server.start();
32+
```
33+
34+
### Client
35+
36+
```ts
37+
const client = new Client({
38+
address: "127.0.0.1",
39+
port: 19132,
40+
mtuSize: 1492,
41+
debug: false,
42+
});
43+
client.connect().then((ad) => {
44+
console.log(ad);
45+
});
46+
```

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sanctumterra/raknet",
3-
"version": "1.3.67",
3+
"version": "1.3.68",
44
"description": "",
55
"main": "dist/index.js",
66
"scripts": {
@@ -14,9 +14,10 @@
1414
"author": "",
1515
"license": "ISC",
1616
"dependencies": {
17-
"reflect-metadata": "^0.2.2",
17+
"@serenityjs/binarystream": "^2.6.6",
1818
"@serenityjs/emitter": "^0.5.2",
19-
"@serenityjs/binarystream": "^2.6.6"
19+
"@serenityjs/protocol": "^0.6.4",
20+
"reflect-metadata": "^0.2.2"
2021
},
2122
"devDependencies": {
2223
"@biomejs/biome": "^1.9.4",

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ import "reflect-metadata";
22
export * from "./proto";
33
export * from "./utils";
44
export * from "./client";
5+
export * from "./server";

src/proto/packets/disconnect.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Create } from "../decorators";
2+
import { Packet } from "../enums";
3+
import { BasePacket } from "./base-packet";
4+
5+
@Create(Packet.DisconnectionNotification)
6+
class DisconnectionNotification extends BasePacket {}
7+
8+
export default DisconnectionNotification;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Long, Uint8 } from "@serenityjs/binarystream";
2+
import { Create, Serialize } from "../decorators";
3+
import { Packet } from "../enums";
4+
import { BasePacket } from "./base-packet";
5+
import { Magic } from "./types";
6+
7+
@Create(Packet.IncompatibleProtocolVersion)
8+
export class IncompatibleProtocolVersion extends BasePacket {
9+
@Serialize(Uint8) protocol!: number;
10+
@Serialize(Magic) magic!: Magic;
11+
@Serialize(Long) guid!: bigint;
12+
}

src/proto/packets/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ export * from "./connected-ping";
1414
export * from "./connected-pong";
1515
export * from "./new-incoming-connection";
1616
export * from "./connection-request-accepted";
17+
export * from "./incompatible-protocol-version";
18+
export * from "./disconnect";

src/proto/types/advertisement.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,18 @@ function fromString(message: string): Advertisement {
3737
};
3838
}
3939

40-
export { type Advertisement, fromString };
40+
function AdvertisementToString(advertisement: Advertisement): string {
41+
return [
42+
advertisement.type,
43+
advertisement.message,
44+
advertisement.protocol,
45+
advertisement.version,
46+
advertisement.playerCount,
47+
advertisement.maxPlayers,
48+
advertisement.serverGUID,
49+
advertisement.serverName,
50+
advertisement.gamemode,
51+
].join(";");
52+
}
53+
54+
export { type Advertisement, fromString, AdvertisementToString };

0 commit comments

Comments
 (0)