minecraft: Split vanilla string by bytes instead of characters (#436)
The received string length from server is expected to be a byte length whereas if we parse to string first javascript will treat our length as a character length (accounts for UTF multi-byte characters). This should hopefully fix #434
This commit is contained in:
parent
ec33bc2ca2
commit
dcc69a36b2
|
@ -39,7 +39,9 @@ export default class minecraftvanilla extends Core {
|
||||||
const strLen = reader.varint()
|
const strLen = reader.varint()
|
||||||
this.logger.debug('String Length: ' + strLen)
|
this.logger.debug('String Length: ' + strLen)
|
||||||
|
|
||||||
const str = reader.rest().toString('utf8')
|
const rest = reader.rest()
|
||||||
|
|
||||||
|
const str = rest.toString('utf8', 0, strLen)
|
||||||
this.logger.debug(str)
|
this.logger.debug(str)
|
||||||
|
|
||||||
const json = JSON.parse(str.substring(0, strLen))
|
const json = JSON.parse(str.substring(0, strLen))
|
||||||
|
@ -61,8 +63,8 @@ export default class minecraftvanilla extends Core {
|
||||||
// Better Compatibility Checker mod support
|
// Better Compatibility Checker mod support
|
||||||
let bccJson = {}
|
let bccJson = {}
|
||||||
|
|
||||||
if (str.length > strLen) {
|
if (rest.length > strLen) {
|
||||||
const bccStr = str.substring(strLen + 1)
|
const bccStr = rest.toString('utf8', strLen + 1)
|
||||||
bccJson = JSON.parse(bccStr)
|
bccJson = JSON.parse(bccStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue