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

@@ -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;
}
}