q13x-eaglerproxy/proxy/packets/CSUsernamePacket.js

25 lines
788 B
JavaScript
Raw Normal View History

2024-09-04 05:02:00 -07:00
import { Enums } from "../Enums.js";
import { MineProtocol } from "../Protocol.js";
export class CSUsernamePacket {
packetId = Enums.PacketId.CSUsernamePacket;
type = "packet";
boundTo = Enums.PacketBounds.S;
sentAfterHandshake = false;
username;
static DEFAULT = "default";
serialize() {
return Buffer.concat([
[this.packetId],
MineProtocol.writeString(this.username),
MineProtocol.writeString(CSUsernamePacket.DEFAULT),
[0x0],
].map((arr) => (arr instanceof Uint8Array ? arr : Buffer.from(arr))));
}
deserialize(packet) {
packet = packet.subarray(1);
const username = MineProtocol.readString(packet);
this.username = username.value;
return this;
}
}