mc-beta-server/server/packets/LoginRequest.ts

38 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-06-22 12:43:28 +01:00
import { createWriter, IReader, Endian } from "bufferstuff";
2023-04-08 20:52:47 +01:00
import { IPacket } from "./IPacket";
import { Packet } from "../enums/Packet";
2023-04-08 20:52:47 +01:00
export class PacketLoginRequest implements IPacket {
2023-04-10 21:52:30 +01:00
public packetId = Packet.LoginRequest;
2023-04-08 20:52:47 +01:00
public protocolVersion:number;
public username:string;
public mapSeed:number;
public dimension:number;
public constructor(protocolVersion?:number, username?:string, mapSpeed?:number, dimension?:number) {
if (typeof(protocolVersion) === "number" && typeof(username) === "string" && typeof(mapSpeed) === "number" && typeof(dimension) === "number") {
this.protocolVersion = protocolVersion;
this.username = username;
this.mapSeed = mapSpeed;
this.dimension = dimension;
} else {
this.protocolVersion = Number.MIN_VALUE;
this.username = "";
this.mapSeed = Number.MIN_VALUE;
this.dimension = Number.MIN_VALUE;
}
}
public readData(reader:IReader) {
2023-04-08 20:52:47 +01:00
this.protocolVersion = reader.readInt();
this.username = reader.readString16();
2023-04-08 20:52:47 +01:00
this.mapSeed = Number(reader.readLong());
this.dimension = reader.readByte();
return this;
}
public writeData() {
return createWriter(Endian.BE, 16 + (2 * this.username.length)).writeUByte(this.packetId).writeInt(this.protocolVersion).writeString16(this.username).writeLong(this.mapSeed).writeByte(this.dimension).toBuffer();
2023-04-08 20:52:47 +01:00
}
}