q13x-eaglerproxy/server/proxy/packets/SCIdentifyPacket.js

34 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-09-04 05:02:00 -07:00
import { NETWORK_VERSION, PROXY_BRANDING, PROXY_VERSION, VANILLA_PROTOCOL_VERSION, } from "../../meta.js";
import { Enums } from "../Enums.js";
import { MineProtocol } from "../Protocol.js";
export default class SCIdentifyPacket {
packetId = Enums.PacketId.SCIdentifyPacket;
type = "packet";
boundTo = Enums.PacketBounds.C;
sentAfterHandshake = false;
protocolVer = NETWORK_VERSION;
gameVersion = VANILLA_PROTOCOL_VERSION;
branding = PROXY_BRANDING;
version = PROXY_VERSION;
serialize() {
return Buffer.concat([
[0x02],
MineProtocol.writeShort(this.protocolVer),
MineProtocol.writeShort(this.gameVersion),
MineProtocol.writeString(this.branding),
MineProtocol.writeString(this.version),
[0x00, 0x00, 0x00],
].map((arr) => (arr instanceof Uint8Array ? arr : Buffer.from(arr))));
}
deserialize(packet) {
if (packet[0] != this.packetId)
throw TypeError("Invalid packet ID detected!");
packet = packet.subarray(1);
const protoVer = MineProtocol.readShort(packet), gameVer = MineProtocol.readShort(protoVer.newBuffer), branding = MineProtocol.readString(gameVer.newBuffer), version = MineProtocol.readString(branding.newBuffer);
this.gameVersion = gameVer.value;
this.branding = branding.value;
this.version = version.value;
return this;
}
}