there's nothing here don't look

woom
This commit is contained in:
Malloc of Kuzkycyziklistan 2017-05-24 16:03:57 -05:00
parent 085378b7dc
commit 769fbc315f
2 changed files with 19 additions and 15 deletions

View file

@ -23,17 +23,17 @@ class Packet {
public getRegionString(region: number): string { public getRegionString(region: number): string {
return this.getRegion(region).toString(); return this.getRegion(region).toString();
} }
public addRegion(data: Uint8Array): void { public addRegion(region: object): void {
this._regions.push(data); if(typeof region == "string")
this._regions.push((<string>region).toByteArray());
else if(region instanceof Uint8Array)
this._regions.push(region);
} }
public Packet(id: kPacketId, regions: any[]) { public Packet(id: kPacketId, regions: any[]) {
this._id = id; this._id = id;
regions.forEach(region => { regions.forEach(region => {
if(typeof region == "string") this.addRegion(region);
this._regions.push((<string>region).toByteArray());
else if(region instanceof Uint8Array)
this._regions.push(region);
}); });
} }

View file

@ -74,25 +74,29 @@ namespace Server {
public Packet(kId id, params object[] regions) { public Packet(kId id, params object[] regions) {
Id = id; Id = id;
foreach(var region in regions) { foreach(var region in regions)
if(region.GetType() == typeof(byte[])) AddRegion(region);
Regions.Add((byte[])region);
else if(region.GetType() == typeof(string))
Regions.Add(((string)region).GetBytes());
}
} }
public Region this[int i] { public Region this[int i] {
get => new Region(Regions[i]); get => new Region(Regions[i]);
} }
public void AddRegion(object region) {
if(region.GetType() == typeof(byte[]))
Regions.Add((byte[])region);
else if(region.GetType() == typeof(string))
Regions.Add(((string)region).GetBytes());
}
public byte[] GetBytes() { public byte[] GetBytes() {
if(!IsLegal) if(!IsLegal)
return null; return null;
var header = new List<byte>(); var header = new List<byte> {
header.Add((byte)Id); (byte)Id,
header.Add((byte)RegionCount); (byte)RegionCount
};
IEnumerable<byte> body = new byte[0]; IEnumerable<byte> body = new byte[0];
foreach(var region in Regions) { foreach(var region in Regions) {
if(region.Length < 0xFE) if(region.Length < 0xFE)