there's nothing here don't look
woom
This commit is contained in:
parent
085378b7dc
commit
769fbc315f
2 changed files with 19 additions and 15 deletions
|
@ -23,17 +23,17 @@ class Packet {
|
|||
public getRegionString(region: number): string {
|
||||
return this.getRegion(region).toString();
|
||||
}
|
||||
public addRegion(data: Uint8Array): void {
|
||||
this._regions.push(data);
|
||||
public addRegion(region: object): void {
|
||||
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[]) {
|
||||
this._id = id;
|
||||
regions.forEach(region => {
|
||||
if(typeof region == "string")
|
||||
this._regions.push((<string>region).toByteArray());
|
||||
else if(region instanceof Uint8Array)
|
||||
this._regions.push(region);
|
||||
this.addRegion(region);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -74,25 +74,29 @@ namespace Server {
|
|||
public Packet(kId id, params object[] regions) {
|
||||
Id = id;
|
||||
|
||||
foreach(var region in regions) {
|
||||
if(region.GetType() == typeof(byte[]))
|
||||
Regions.Add((byte[])region);
|
||||
else if(region.GetType() == typeof(string))
|
||||
Regions.Add(((string)region).GetBytes());
|
||||
}
|
||||
foreach(var region in regions)
|
||||
AddRegion(region);
|
||||
}
|
||||
|
||||
public Region this[int 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() {
|
||||
if(!IsLegal)
|
||||
return null;
|
||||
|
||||
var header = new List<byte>();
|
||||
header.Add((byte)Id);
|
||||
header.Add((byte)RegionCount);
|
||||
var header = new List<byte> {
|
||||
(byte)Id,
|
||||
(byte)RegionCount
|
||||
};
|
||||
IEnumerable<byte> body = new byte[0];
|
||||
foreach(var region in Regions) {
|
||||
if(region.Length < 0xFE)
|
||||
|
|
Loading…
Reference in a new issue