Latest packet handling, parsing, enums, generators, etc..

This commit is contained in:
Casper Warden
2017-11-24 17:45:34 +00:00
parent ec300e33ac
commit 261f28698a
496 changed files with 30448 additions and 57 deletions

View File

@@ -30,4 +30,44 @@ export class ScriptDataReplyPacket implements Packet
return size;
}
writeToBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
const count = this.DataBlock.length;
buf.writeUInt8(this.DataBlock.length, pos++);
for (let i = 0; i < count; i++)
{
buf.writeInt32LE(this.DataBlock[i]['Hash'].low, pos);
pos += 4;
buf.writeInt32LE(this.DataBlock[i]['Hash'].high, pos);
pos += 4;
buf.write(this.DataBlock[i]['Reply'], pos);
pos += this.DataBlock[i]['Reply'].length;
}
return pos - startPos;
}
readFromBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
const count = buf.readUInt8(pos++);
this.DataBlock = [];
for (let i = 0; i < count; i++)
{
const newObjDataBlock: {
Hash: Long,
Reply: string
} = {
Hash: Long.ZERO,
Reply: ''
};
newObjDataBlock['Hash'] = new Long(buf.readInt32LE(pos), buf.readInt32LE(pos+4));
pos += 8;
newObjDataBlock['Reply'] = buf.toString('utf8', pos, length);
pos += length;
this.DataBlock.push(newObjDataBlock);
}
return pos - startPos;
}
}