Hey.

BattleNode.prototype.commandPacket = function (command) { var data = new Buffer(command.length + 3); data.writeUInt8(0xFF, 0); data.writeUInt8(BE_COMMAND_PACKET, 1); data.writeUInt8(this.sequence, 2); data.write(command, 3); this.sequence = (this.sequence >= 255) ? 0 : this.sequence + 1; var packet = this.createBEPacket(data); return packet; } BattleNode.prototype.createBEPacket = function(payload) { var packet = new Buffer(payload.length + 6); // payload + header var header = new Buffer([0x42, 0x45, 0x00, 0x00, 0x00, 0x00]); var crc = crc32(payload); header.writeInt32BE(crc.readInt32LE(0), 2); header.copy(packet); payload.copy(packet, 6); return packet; } 

// The command variable comes already in Windows-1252 encoding. And you need to create a buffer with the same encoding.

I tried through iconv-lite. Nothing intelligible came out. Any ideas?

  • What inside the command if you do console.log () ?? - pnp2000
  • #kick Live - LiveD
  • and typeof command - pnp2000
  • Why do you ask? =) The command contains String =) - LiveD
  • and if you do so on the second line var data = iconv.encode (command, 'win1251'); - pnp2000

1 answer 1

Let's start in order, I'm not a guru js but, Buffer has no encoding, it's just a set of bytes, as for iconv-lite, it perfectly converts strings between encodings, for example, this code converts string to Buffer with win1251

 var string = iconv.encode("Тут строка, большая строка", 'win1251'); 
  • Then the question is, how do I get the exact length of the command string, if it is a string in win1252 encoding? - LiveD
  • it is necessary to convert it to utf8, and then using standard JS methods - pnp2000
  • The fact is that the socket must send the string exactly in win1252 encoding to the server. - LiveD