const ByteStream = require("../../ByteStream/ByteStream") class LoginMessage { constructor(config, crypto, logger, data = null) { this.config = config this.crypto = crypto this.logger = logger this.type = 10101 this.data = data } encode() { const stream = new ByteStream() stream.writeUInt32(0) const playerId = Math.floor(Math.random() * 1000000) stream.writeUInt32(playerId) const token = this.config.auth.token || "" stream.writeString(token) stream.writeUInt32(this.config.client.version.major) stream.writeUInt32(this.config.client.version.minor) stream.writeUInt32(this.config.client.version.build) stream.writeString("") stream.writeString(this.config.client.device) stream.writeString(this.config.client.language) this.logger.debug(`Encoding LoginMessage`, { playerId: playerId, device: this.config.client.device, language: this.config.client.language, hasToken: token.length > 0, cryptoEnabled: this.config.crypto.enabled, }) return stream.getBuffer() } decode(buffer) { const stream = new ByteStream(buffer) const data = { highId: stream.readUInt32(), lowId: stream.readUInt32(), token: stream.readString(), majorVersion: stream.readUInt32(), minorVersion: stream.readUInt32(), buildVersion: stream.readUInt32(), hash: stream.readString(), device: stream.readString(), language: stream.readString(), } this.logger.debug(`Decoded LoginMessage`, data) return data } getType() { return this.type } } module.exports = LoginMessage