Latest packet handling, parsing, enums, generators, etc..
This commit is contained in:
@@ -31,4 +31,48 @@ export class ScriptDataRequestPacket 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.writeInt8(this.DataBlock[i]['RequestType'], pos++);
|
||||
buf.write(this.DataBlock[i]['Request'], pos);
|
||||
pos += this.DataBlock[i]['Request'].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,
|
||||
RequestType: number,
|
||||
Request: string
|
||||
} = {
|
||||
Hash: Long.ZERO,
|
||||
RequestType: 0,
|
||||
Request: ''
|
||||
};
|
||||
newObjDataBlock['Hash'] = new Long(buf.readInt32LE(pos), buf.readInt32LE(pos+4));
|
||||
pos += 8;
|
||||
newObjDataBlock['RequestType'] = buf.readInt8(pos++);
|
||||
newObjDataBlock['Request'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
this.DataBlock.push(newObjDataBlock);
|
||||
}
|
||||
return pos - startPos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user