modify some packet variable name

fix chat problem with multi-byte characters
This commit is contained in:
DannyAAM 2014-02-22 18:38:39 +08:00
parent 4e48226c8c
commit aa0402979e

19
lib/protocol.js Normal file → Executable file
View file

@ -470,7 +470,7 @@ var packets = {
], ],
0x02: [ 0x02: [
{ name: "target", type: "int" }, { name: "target", type: "int" },
{ name: "leftClick", type: "byte" } { name: "mouse", type: "byte" }
], ],
0x03: [ 0x03: [
{ name: "onGround", type: "bool" } { name: "onGround", type: "bool" }
@ -1352,19 +1352,22 @@ function writeSlot(value, buffer, offset) {
} }
function sizeOfString(value) { function sizeOfString(value) {
assert.ok(value.length < STRING_MAX_LENGTH, "string greater than max length"); var length = Buffer.byteLength(value, 'utf8');
return sizeOfVarInt(value.length) + value.length; assert.ok(length < STRING_MAX_LENGTH, "string greater than max length");
return sizeOfVarInt(length) + length;
} }
function sizeOfUString(value) { function sizeOfUString(value) {
assert.ok(value.length < SRV_STRING_MAX_LENGTH, "string greater than max length"); var length = Buffer.byteLength(value, 'utf8');
return sizeOfVarInt(value.length) + value.length; assert.ok(length < SRV_STRING_MAX_LENGTH, "string greater than max length");
return sizeOfVarInt(length) + length;
} }
function writeString(value, buffer, offset) { function writeString(value, buffer, offset) {
offset = writeVarInt(value.length, buffer, offset); var length = Buffer.byteLength(value, 'utf8');
buffer.write(value, offset, value.length, 'utf8'); offset = writeVarInt(length, buffer, offset);
return offset + value.length; buffer.write(value, offset, length, 'utf8');
return offset + length;
} }
function sizeOfAscii(value) { function sizeOfAscii(value) {