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

@@ -26,4 +26,60 @@ export class ScriptQuestionPacket implements Packet
return (this.Data['ObjectName'].length + 1 + this.Data['ObjectOwner'].length + 1) + 52;
}
writeToBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
this.Data['TaskID'].writeToBuffer(buf, pos);
pos += 16;
this.Data['ItemID'].writeToBuffer(buf, pos);
pos += 16;
buf.write(this.Data['ObjectName'], pos);
pos += this.Data['ObjectName'].length;
buf.write(this.Data['ObjectOwner'], pos);
pos += this.Data['ObjectOwner'].length;
buf.writeInt32LE(this.Data['Questions'], pos);
pos += 4;
this.Experience['ExperienceID'].writeToBuffer(buf, pos);
pos += 16;
return pos - startPos;
}
readFromBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
const newObjData: {
TaskID: UUID,
ItemID: UUID,
ObjectName: string,
ObjectOwner: string,
Questions: number
} = {
TaskID: UUID.zero(),
ItemID: UUID.zero(),
ObjectName: '',
ObjectOwner: '',
Questions: 0
};
newObjData['TaskID'] = new UUID(buf, pos);
pos += 16;
newObjData['ItemID'] = new UUID(buf, pos);
pos += 16;
newObjData['ObjectName'] = buf.toString('utf8', pos, length);
pos += length;
newObjData['ObjectOwner'] = buf.toString('utf8', pos, length);
pos += length;
newObjData['Questions'] = buf.readInt32LE(pos);
pos += 4;
this.Data = newObjData;
const newObjExperience: {
ExperienceID: UUID
} = {
ExperienceID: UUID.zero()
};
newObjExperience['ExperienceID'] = new UUID(buf, pos);
pos += 16;
this.Experience = newObjExperience;
return pos - startPos;
}
}