Latest packet handling, parsing, enums, generators, etc..
This commit is contained in:
@@ -29,4 +29,76 @@ export class TransferInventoryPacket implements Packet
|
||||
return ((17) * this.InventoryBlock.length) + 54;
|
||||
}
|
||||
|
||||
writeToBuffer(buf: Buffer, pos: number): number
|
||||
{
|
||||
const startPos = pos;
|
||||
this.InfoBlock['SourceID'].writeToBuffer(buf, pos);
|
||||
pos += 16;
|
||||
this.InfoBlock['DestID'].writeToBuffer(buf, pos);
|
||||
pos += 16;
|
||||
this.InfoBlock['TransactionID'].writeToBuffer(buf, pos);
|
||||
pos += 16;
|
||||
const count = this.InventoryBlock.length;
|
||||
buf.writeUInt8(this.InventoryBlock.length, pos++);
|
||||
for (let i = 0; i < count; i++)
|
||||
{
|
||||
this.InventoryBlock[i]['InventoryID'].writeToBuffer(buf, pos);
|
||||
pos += 16;
|
||||
buf.writeInt8(this.InventoryBlock[i]['Type'], pos++);
|
||||
}
|
||||
buf.writeUInt8((this.ValidationBlock['NeedsValidation']) ? 1 : 0, pos++);
|
||||
buf.writeUInt32LE(this.ValidationBlock['EstateID'], pos);
|
||||
pos += 4;
|
||||
return pos - startPos;
|
||||
}
|
||||
|
||||
readFromBuffer(buf: Buffer, pos: number): number
|
||||
{
|
||||
const startPos = pos;
|
||||
const newObjInfoBlock: {
|
||||
SourceID: UUID,
|
||||
DestID: UUID,
|
||||
TransactionID: UUID
|
||||
} = {
|
||||
SourceID: UUID.zero(),
|
||||
DestID: UUID.zero(),
|
||||
TransactionID: UUID.zero()
|
||||
};
|
||||
newObjInfoBlock['SourceID'] = new UUID(buf, pos);
|
||||
pos += 16;
|
||||
newObjInfoBlock['DestID'] = new UUID(buf, pos);
|
||||
pos += 16;
|
||||
newObjInfoBlock['TransactionID'] = new UUID(buf, pos);
|
||||
pos += 16;
|
||||
this.InfoBlock = newObjInfoBlock;
|
||||
const count = buf.readUInt8(pos++);
|
||||
this.InventoryBlock = [];
|
||||
for (let i = 0; i < count; i++)
|
||||
{
|
||||
const newObjInventoryBlock: {
|
||||
InventoryID: UUID,
|
||||
Type: number
|
||||
} = {
|
||||
InventoryID: UUID.zero(),
|
||||
Type: 0
|
||||
};
|
||||
newObjInventoryBlock['InventoryID'] = new UUID(buf, pos);
|
||||
pos += 16;
|
||||
newObjInventoryBlock['Type'] = buf.readInt8(pos++);
|
||||
this.InventoryBlock.push(newObjInventoryBlock);
|
||||
}
|
||||
const newObjValidationBlock: {
|
||||
NeedsValidation: boolean,
|
||||
EstateID: number
|
||||
} = {
|
||||
NeedsValidation: false,
|
||||
EstateID: 0
|
||||
};
|
||||
newObjValidationBlock['NeedsValidation'] = (buf.readUInt8(pos++) === 1);
|
||||
newObjValidationBlock['EstateID'] = buf.readUInt32LE(pos);
|
||||
pos += 4;
|
||||
this.ValidationBlock = newObjValidationBlock;
|
||||
return pos - startPos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user