diff --git a/client/src/Packet.ts b/client/src/Packet.ts index a332234..3fb6abf 100644 --- a/client/src/Packet.ts +++ b/client/src/Packet.ts @@ -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((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((region).toByteArray()); - else if(region instanceof Uint8Array) - this._regions.push(region); + this.addRegion(region); }); } diff --git a/server/Socks/Packet.cs b/server/Socks/Packet.cs index 9a841e5..df3304f 100644 --- a/server/Socks/Packet.cs +++ b/server/Socks/Packet.cs @@ -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(); - header.Add((byte)Id); - header.Add((byte)RegionCount); + var header = new List { + (byte)Id, + (byte)RegionCount + }; IEnumerable body = new byte[0]; foreach(var region in Regions) { if(region.Length < 0xFE)