diff --git a/.gitignore b/.gitignore index 2fa89f2..df1396a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ db/ src/tools/level src/history/ note.txt -bun.lockb \ No newline at end of file +bun.lockb +src/tools/z.ts \ No newline at end of file diff --git a/package.json b/package.json index 0b44469..6c1466e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/Connection.ts b/src/Connection.ts index 577a907..3c3685a 100644 --- a/src/Connection.ts +++ b/src/Connection.ts @@ -1,8 +1,3 @@ -import { - Client as RakNetClient, - type Advertisement, -} from "@sanctumterra/raknet"; - import { type ClientOptions, defaultOptions, @@ -45,6 +40,9 @@ import { } from "node:crypto"; import { measureExecutionTime } from "./vendor/debug-tools"; +import { Client as RakNetClient, type Advertisement } from "../../Raknet/src/"; + + declare global { var __DEBUG: boolean; } @@ -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); @@ -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(); @@ -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), ); } } @@ -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); @@ -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); } diff --git a/src/vendor/PacketSorter.ts b/src/vendor/PacketSorter.ts index baf8807..8770aed 100644 --- a/src/vendor/PacketSorter.ts +++ b/src/vendor/PacketSorter.ts @@ -1,6 +1,5 @@ import { Disconnect, - Frame, type Priority, Reliability, } from "@serenityjs/raknet"; @@ -36,6 +35,7 @@ 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/"; export class PacketSorter { constructor(private readonly connection: Connection) { @@ -43,15 +43,21 @@ export class PacketSorter { } 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 { @@ -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}`); }