mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-04-22 12:47:46 +00:00
Added compression code to packet.
This commit is contained in:
parent
f30360f245
commit
0492bc4c59
1 changed files with 41 additions and 5 deletions
|
@ -242,6 +242,13 @@ namespace FFXIVClassic.Common
|
||||||
offset += (ushort)subpacketData.Length;
|
offset += (ushort)subpacketData.Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Compress this array into a new one if needed
|
||||||
|
if (isCompressed)
|
||||||
|
{
|
||||||
|
data = CompressData(data);
|
||||||
|
header.packetSize = (ushort)(BASEPACKET_SIZE + data.Length);
|
||||||
|
}
|
||||||
|
|
||||||
Debug.Assert(data != null && offset == data.Length && header.packetSize == 0x10 + offset);
|
Debug.Assert(data != null && offset == data.Length && header.packetSize == 0x10 + offset);
|
||||||
|
|
||||||
var packet = new BasePacket(header, data);
|
var packet = new BasePacket(header, data);
|
||||||
|
@ -266,7 +273,15 @@ namespace FFXIVClassic.Common
|
||||||
data = new byte[header.packetSize - 0x10];
|
data = new byte[header.packetSize - 0x10];
|
||||||
|
|
||||||
//Add Subpackets
|
//Add Subpackets
|
||||||
var subpacketData = subpacket.GetBytes();
|
byte[] subpacketData = subpacket.GetBytes();
|
||||||
|
|
||||||
|
//Compress this array into a new one if needed
|
||||||
|
if (isCompressed)
|
||||||
|
{
|
||||||
|
subpacketData = CompressData(subpacketData);
|
||||||
|
header.packetSize = (ushort)(BASEPACKET_SIZE + data.Length);
|
||||||
|
}
|
||||||
|
|
||||||
Array.Copy(subpacketData, 0, data, 0, subpacketData.Length);
|
Array.Copy(subpacketData, 0, data, 0, subpacketData.Length);
|
||||||
|
|
||||||
Debug.Assert(data != null);
|
Debug.Assert(data != null);
|
||||||
|
@ -291,6 +306,13 @@ namespace FFXIVClassic.Common
|
||||||
//Get packet size
|
//Get packet size
|
||||||
header.packetSize += (ushort) data.Length;
|
header.packetSize += (ushort) data.Length;
|
||||||
|
|
||||||
|
//Compress this array into a new one if needed
|
||||||
|
if (isCompressed)
|
||||||
|
{
|
||||||
|
data = CompressData(data);
|
||||||
|
header.packetSize = (ushort)(BASEPACKET_SIZE + data.Length);
|
||||||
|
}
|
||||||
|
|
||||||
var packet = new BasePacket(header, data);
|
var packet = new BasePacket(header, data);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
@ -390,17 +412,31 @@ namespace FFXIVClassic.Common
|
||||||
{
|
{
|
||||||
zipStream.CopyTo(resultStream);
|
zipStream.CopyTo(resultStream);
|
||||||
packet.data = resultStream.ToArray();
|
packet.data = resultStream.ToArray();
|
||||||
|
packet.header.isCompressed = 0;
|
||||||
|
packet.header.packetSize = (ushort)(BASEPACKET_SIZE + packet.data.Length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static unsafe void CompressPacket(ref BasePacket packet)
|
public static unsafe BasePacket CompressPacket(BasePacket uncompressedPacket)
|
||||||
{
|
{
|
||||||
using (var compressedStream = new MemoryStream(packet.data))
|
using (var compressedStream = new MemoryStream(uncompressedPacket.data))
|
||||||
using (var zipStream = new ZlibStream(compressedStream, Ionic.Zlib.CompressionMode.Compress))
|
using (var zipStream = new ZlibStream(compressedStream, Ionic.Zlib.CompressionMode.Compress))
|
||||||
using (var resultStream = new MemoryStream())
|
using (var resultStream = new MemoryStream())
|
||||||
{
|
{
|
||||||
zipStream.CopyTo(resultStream);
|
zipStream.CopyTo(resultStream);
|
||||||
packet.data = resultStream.ToArray();
|
BasePacket compressedPacket = BasePacket.CreatePacket(resultStream.ToArray(), uncompressedPacket.header.isAuthenticated == 1, true);
|
||||||
|
return compressedPacket;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static unsafe byte[] CompressData(byte[] data)
|
||||||
|
{
|
||||||
|
using (var compressedStream = new MemoryStream(data))
|
||||||
|
using (var zipStream = new ZlibStream(compressedStream, Ionic.Zlib.CompressionMode.Compress))
|
||||||
|
using (var resultStream = new MemoryStream())
|
||||||
|
{
|
||||||
|
zipStream.CopyTo(resultStream);
|
||||||
|
return resultStream.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue