From 1cdb0e4c554d45c152f362858f79e07d27c672ed Mon Sep 17 00:00:00 2001 From: extremeheat Date: Sun, 20 Jun 2021 17:12:22 -0400 Subject: [PATCH] Update protodef version --- package.json | 2 +- src/client.js | 11 ++++++----- src/datatypes/util.js | 4 +++- src/serverPlayer.js | 4 ++-- src/transforms/framer.js | 2 +- src/transforms/serializer.js | 6 +++--- tools/compileProtocol.js | 2 +- 7 files changed, 17 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index f01299f..50e85f4 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "minecraft-folder-path": "^1.1.0", "node-fetch": "^2.6.1", "prismarine-nbt": "^1.5.0", - "protodef-compiler-fix": "latest", + "protodef": "^1.14.0", "smart-buffer": "^4.1.0", "uuid-1345": "^1.0.2" }, diff --git a/src/client.js b/src/client.js index 3bf263e..068dce5 100644 --- a/src/client.js +++ b/src/client.js @@ -1,7 +1,7 @@ const { ClientStatus, Connection } = require('./connection') const { createDeserializer, createSerializer } = require('./transforms/serializer') const { RakClient } = require('./rak') -const { serialize } = require('./datatypes/util') +const { serialize, isDebug } = require('./datatypes/util') const debug = require('debug')('minecraft-protocol') const Options = require('./options') const auth = require('./client/auth') @@ -35,7 +35,7 @@ class Client extends Connection { this.startGameData = {} this.clientRuntimeId = null - if (process.env.DEBUG.includes('minecraft-protocol')) { + if (isDebug) { this.inLog = (...args) => debug('C ->', ...args) this.outLog = (...args) => debug('C <-', ...args) } @@ -156,7 +156,7 @@ class Client extends Connection { readPacket (packet) { const des = this.deserializer.parsePacketBuffer(packet) const pakData = { name: des.data.name, params: des.data.params } - this.inLog('-> C', pakData.name, this.options.loggging ? serialize(pakData.params) : '') + this.inLog?.('-> C', pakData.name, this.options.loggging ? serialize(pakData.params) : '') this.emit('packet', des) if (debugging) { @@ -186,7 +186,7 @@ class Client extends Connection { break case 'play_status': if (this.status === ClientStatus.Authenticating) { - this.inLog('Server wants to skip encryption') + this.inLog?.('Server wants to skip encryption') this.emit('join') this.status = ClientStatus.Initializing } @@ -194,7 +194,8 @@ class Client extends Connection { break default: if (this.status !== ClientStatus.Initializing && this.status !== ClientStatus.Initialized) { - this.inLog(`Can't accept ${des.data.name}, client not yet authenticated : ${this.status}`) + // TODO: standardjs bug happens here with ?.(`something ${des.data.name}`) + if (this.inLog) this.inLog(`Can't accept ${des.data.name}, client not yet authenticated : ${this.status}`) return } } diff --git a/src/datatypes/util.js b/src/datatypes/util.js index b080577..4b29d57 100644 --- a/src/datatypes/util.js +++ b/src/datatypes/util.js @@ -43,4 +43,6 @@ function nextUUID () { return uuidFrom(Date.now().toString()) } -module.exports = { getFiles, sleep, waitFor, serialize, uuidFrom, nextUUID } +const isDebug = process.env.DEBUG?.includes('minecraft-protocol') + +module.exports = { getFiles, sleep, waitFor, serialize, uuidFrom, nextUUID, isDebug } diff --git a/src/serverPlayer.js b/src/serverPlayer.js index 954e86f..52693b8 100644 --- a/src/serverPlayer.js +++ b/src/serverPlayer.js @@ -1,6 +1,6 @@ const { ClientStatus, Connection } = require('./connection') const Options = require('./options') -const { serialize } = require('./datatypes/util') +const { serialize, isDebug } = require('./datatypes/util') const { KeyExchange } = require('./handshake/keyExchange') const Login = require('./handshake/login') const LoginVerify = require('./handshake/loginVerify') @@ -23,7 +23,7 @@ class Player extends Connection { this.startQueue() this.status = ClientStatus.Authenticating - if (process.env.DEBUG.includes('minecraft-protocol')) { + if (isDebug) { this.inLog = (...args) => debug('S ->', ...args) this.outLog = (...args) => debug('S <-', ...args) } diff --git a/src/transforms/framer.js b/src/transforms/framer.js index aa1b496..77f41e9 100644 --- a/src/transforms/framer.js +++ b/src/transforms/framer.js @@ -1,4 +1,4 @@ -const [readVarInt, writeVarInt, sizeOfVarInt] = require('protodef-compiler-fix').types.varint +const [readVarInt, writeVarInt, sizeOfVarInt] = require('protodef').types.varint const zlib = require('zlib') // Concatenates packets into one batch packet, and adds length prefixs. diff --git a/src/transforms/serializer.js b/src/transforms/serializer.js index 2900cf3..4a6102f 100644 --- a/src/transforms/serializer.js +++ b/src/transforms/serializer.js @@ -1,5 +1,5 @@ -const { ProtoDefCompiler, CompiledProtodef } = require('protodef-compiler-fix').Compiler -const { FullPacketParser, Serializer } = require('protodef-compiler-fix') +const { ProtoDefCompiler, CompiledProtodef } = require('protodef').Compiler +const { FullPacketParser, Serializer } = require('protodef') const { join } = require('path') class Parser extends FullPacketParser { @@ -43,7 +43,7 @@ function getProtocol (version) { compiler.addTypes(require(join(__dirname, '../datatypes/compiler-minecraft'))) compiler.addTypes(require('prismarine-nbt/compiler-zigzag')) - global.PartialReadError = require('protodef-compiler-fix/src/utils').PartialReadError + global.PartialReadError = require('protodef/src/utils').PartialReadError const compile = (compiler, file) => require(file)(compiler.native) return new CompiledProtodef( diff --git a/tools/compileProtocol.js b/tools/compileProtocol.js index c89cb28..bed7b2c 100644 --- a/tools/compileProtocol.js +++ b/tools/compileProtocol.js @@ -6,7 +6,7 @@ * */ const fs = require('fs') -const { ProtoDefCompiler } = require('protodef-compiler-fix').Compiler +const { ProtoDefCompiler } = require('protodef').Compiler const { Versions } = require('../src/options') const { join } = require('path')