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

@@ -40,4 +40,88 @@ export class MapBlockReplyPacket implements Packet
return size;
}
writeToBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
this.AgentData['AgentID'].writeToBuffer(buf, pos);
pos += 16;
buf.writeUInt32LE(this.AgentData['Flags'], pos);
pos += 4;
const count = this.Data.length;
buf.writeUInt8(this.Data.length, pos++);
for (let i = 0; i < count; i++)
{
buf.writeUInt16LE(this.Data[i]['X'], pos);
pos += 2;
buf.writeUInt16LE(this.Data[i]['Y'], pos);
pos += 2;
buf.write(this.Data[i]['Name'], pos);
pos += this.Data[i]['Name'].length;
buf.writeUInt8(this.Data[i]['Access'], pos++);
buf.writeUInt32LE(this.Data[i]['RegionFlags'], pos);
pos += 4;
buf.writeUInt8(this.Data[i]['WaterHeight'], pos++);
buf.writeUInt8(this.Data[i]['Agents'], pos++);
this.Data[i]['MapImageID'].writeToBuffer(buf, pos);
pos += 16;
}
return pos - startPos;
}
readFromBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
const newObjAgentData: {
AgentID: UUID,
Flags: number
} = {
AgentID: UUID.zero(),
Flags: 0
};
newObjAgentData['AgentID'] = new UUID(buf, pos);
pos += 16;
newObjAgentData['Flags'] = buf.readUInt32LE(pos);
pos += 4;
this.AgentData = newObjAgentData;
const count = buf.readUInt8(pos++);
this.Data = [];
for (let i = 0; i < count; i++)
{
const newObjData: {
X: number,
Y: number,
Name: string,
Access: number,
RegionFlags: number,
WaterHeight: number,
Agents: number,
MapImageID: UUID
} = {
X: 0,
Y: 0,
Name: '',
Access: 0,
RegionFlags: 0,
WaterHeight: 0,
Agents: 0,
MapImageID: UUID.zero()
};
newObjData['X'] = buf.readUInt16LE(pos);
pos += 2;
newObjData['Y'] = buf.readUInt16LE(pos);
pos += 2;
newObjData['Name'] = buf.toString('utf8', pos, length);
pos += length;
newObjData['Access'] = buf.readUInt8(pos++);
newObjData['RegionFlags'] = buf.readUInt32LE(pos);
pos += 4;
newObjData['WaterHeight'] = buf.readUInt8(pos++);
newObjData['Agents'] = buf.readUInt8(pos++);
newObjData['MapImageID'] = new UUID(buf, pos);
pos += 16;
this.Data.push(newObjData);
}
return pos - startPos;
}
}