Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AnyBananaGAME committed Oct 28, 2024
1 parent a796255 commit 6ffa55c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ db/
src/tools/level
src/history/
note.txt
bun.lockb
bun.lockb
src/tools/z.ts
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sanctumterra/client",
"version": "2.1.9",
"version": "2.1.10",
"minecraft": "1.21.30",
"description": "We'll be singing Baraye.",
"main": "./dist/index.js",
Expand Down
21 changes: 11 additions & 10 deletions src/Connection.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import {
Client as RakNetClient,
type Advertisement,
} from "@sanctumterra/raknet";

import {
type ClientOptions,
defaultOptions,
Expand Down Expand Up @@ -45,6 +40,9 @@ import {
} from "node:crypto";
import { measureExecutionTime } from "./vendor/debug-tools";

import { Client as RakNetClient, type Advertisement } from "../../Raknet/src/";

Check failure on line 43 in src/Connection.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module '../../Raknet/src/' or its corresponding type declarations.

Check failure on line 43 in src/Connection.ts

View workflow job for this annotation

GitHub Actions / build-and-release

Cannot find module '../../Raknet/src/' or its corresponding type declarations.


declare global {
var __DEBUG: boolean;
}
Expand Down Expand Up @@ -72,9 +70,9 @@ class Connection extends Listener {
globalThis.__DEBUG = options.debug ?? false;
this.protocol = ProtocolList[this.options.version];
this.raknet = new RakNetClient({
host: this.options.host,
address: this.options.host,
port: this.options.port,
debug: this.options.debug,
debug: false, // this.options.debug,
});
this.data = new ClientData(this);
this.packetSorter = new PacketSorter(this);
Expand All @@ -95,9 +93,9 @@ class Connection extends Listener {
disconnectPacket.message = new DisconnectMessage();
disconnectPacket.hideDisconnectScreen = true;
this.sendPacket(disconnectPacket, Priority.Immediate);
this.raknet.close();
// this.raknet.close();
} else {
this.raknet.close();
// this.raknet.close();
}
clearInterval(this.ticker);
this.removeAllListeners();
Expand All @@ -117,8 +115,9 @@ class Connection extends Listener {
try {
this.packetSorter.sendPacket(packet, priority);
} catch (error) {
console.log(error)
Logger.error(
`Error sending packet: ${error instanceof Error ? error.message : String(error)}`,
"Error sending packet: ", (error as Error),
);
}
}
Expand All @@ -144,6 +143,7 @@ class Connection extends Listener {
}

private handleConnect(): void {
console.log("handle")
const networkSettingsPacket = new RequestNetworkSettingsPacket();
networkSettingsPacket.protocol = this.protocol;
this.sendPacket(networkSettingsPacket);
Expand Down Expand Up @@ -248,6 +248,7 @@ class Connection extends Listener {
const login = new LoginPacket();
login.protocol = this.protocol;
login.tokens = new LoginTokens(userChain, encodedChain);
console.log("test")
this.sendPacket(login, Priority.Immediate);
}

Expand Down
34 changes: 20 additions & 14 deletions src/vendor/PacketSorter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Disconnect,
Frame,
type Priority,
Reliability,
} from "@serenityjs/raknet";
Expand Down Expand Up @@ -36,22 +35,29 @@ import { AddEntityPacket } from "./packets/AddActorPacket";
import { AddItemActorPacket } from "./packets/add-item-actor";
import { LegacyTelemetryEventPacket } from "./packets/LegacyTelemetryEventPacket";
import { UpdateSubChunkBlocksPacket } from "./packets/UpdateSubChunkBlocksPacket";
import { Frame } from "../../../Raknet/src/";

Check failure on line 38 in src/vendor/PacketSorter.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module '../../../Raknet/src/' or its corresponding type declarations.

Check failure on line 38 in src/vendor/PacketSorter.ts

View workflow job for this annotation

GitHub Actions / build-and-release

Cannot find module '../../../Raknet/src/' or its corresponding type declarations.

export class PacketSorter {
constructor(private readonly connection: Connection) {
this.initializeListeners();
}

public sendPacket(packet: DataPacket, priority: Priority): void {
const serialized = packet.serialize();
const framed = Framer.frame(serialized);
const payload = this.preparePayload(framed);

const frame = new Frame();
frame.reliability = Reliability.ReliableOrdered;
frame.orderChannel = 0;
frame.payload = payload;
this.connection.raknet.sender.sendFrame(frame, priority);
try {
const serialized = packet.serialize();
const framed = Framer.frame(serialized);
const payload = this.preparePayload(framed);
const frame = new Frame();
frame.reliability = Reliability.ReliableOrdered;
frame.orderChannel = 0;
frame.splitFrameIndex = 0;
frame.payload = payload;
this.connection.raknet.framer.sendFrame(frame, priority);
} catch (error) {
Logger.error(
`Error sending packet: ${(error as Error).message}`, (error as Error),
);
}
}

public handleDisconnect(payload: Buffer): void {
Expand All @@ -65,13 +71,13 @@ export class PacketSorter {
);
}

private handleEncapsulatedPacket(frame: Frame): void {
const header = frame.payload[0] as number;
private handleEncapsulatedPacket(payload: Buffer): void {
const header = payload[0] as number;
try {
if (header === 254) {
this.handleGamePacket(frame.payload);
this.handleGamePacket(payload);
} else if (header === 21) {
this.handleDisconnect(frame.payload);
this.handleDisconnect(payload);
} else {
if (globalThis.__DEBUG) Logger.debug(`Unknown header ${header}`);
}
Expand Down

0 comments on commit 6ffa55c

Please sign in to comment.