mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Fix packet compression
This commit is contained in:
parent
7ba0c3c8fc
commit
c85352f819
2 changed files with 10 additions and 13 deletions
|
|
@ -1421,12 +1421,10 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
|
||||
if (compression_treshold > 0) //Compression enabled?
|
||||
{
|
||||
if (the_packet.Length > compression_treshold) //Packet long enough for compressing?
|
||||
if (the_packet.Length >= compression_treshold) //Packet long enough for compressing?
|
||||
{
|
||||
byte[] uncompressed_length = getVarInt(the_packet.Length);
|
||||
byte[] compressed_packet = ZlibUtils.Compress(the_packet);
|
||||
byte[] compressed_packet_length = getVarInt(compressed_packet.Length);
|
||||
the_packet = concatBytes(compressed_packet_length, compressed_packet);
|
||||
the_packet = concatBytes(getVarInt(the_packet.Length), compressed_packet);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,17 +21,16 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
/// <returns>Compressed data as a byte array</returns>
|
||||
public static byte[] Compress(byte[] to_compress)
|
||||
{
|
||||
ZlibStream stream = new ZlibStream(new System.IO.MemoryStream(to_compress, false), CompressionMode.Compress);
|
||||
List<byte> temp_compression_list = new List<byte>();
|
||||
byte[] b = new byte[1];
|
||||
while (true)
|
||||
byte[] data;
|
||||
using (System.IO.MemoryStream memstream = new System.IO.MemoryStream())
|
||||
{
|
||||
int read = stream.Read(b, 0, 1);
|
||||
if (read > 0) { temp_compression_list.Add(b[0]); }
|
||||
else break;
|
||||
using (ZlibStream stream = new ZlibStream(memstream, CompressionMode.Compress))
|
||||
{
|
||||
stream.Write(to_compress, 0, to_compress.Length);
|
||||
}
|
||||
data = memstream.ToArray();
|
||||
}
|
||||
stream.Close();
|
||||
return temp_compression_list.ToArray();
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue