Add support for MC 1.8 protocol

Lots of changes in 1.8 protocol so a new protocol handler was necessary
Packet (de)compression done with dotNetZip Zlib compression engine
1.4.6-1.7.10 support is still there thanks to app refactoring
This commit is contained in:
ORelio 2014-09-04 13:58:49 +02:00
parent 2a8a6fadd3
commit 88b8399c5c
16 changed files with 9885 additions and 2 deletions

View file

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ionic.Zlib;
namespace MinecraftClient.Protocol.Handlers
{
/// <summary>
/// Quick Zlib compression handling for network packet compression.
/// Note: Underlying compression handling is taken from the DotNetZip Library.
/// This library is open source and provided under the Microsoft Public License.
/// More info about DotNetZip at dotnetzip.codeplex.com.
/// </summary>
public static class ZlibUtils
{
/// <summary>
/// Compress a byte array into another bytes array using Zlib compression
/// </summary>
/// <param name="to_compress">Data to compress</param>
/// <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)
{
int read = stream.Read(b, 0, 1);
if (read > 0) { temp_compression_list.Add(b[0]); }
else break;
}
stream.Close();
return temp_compression_list.ToArray();
}
/// <summary>
/// Decompress a byte array into another byte array of the specified size
/// </summary>
/// <param name="to_decompress">Data to decompress</param>
/// <param name="size_uncompressed">Size of the data once decompressed</param>
/// <returns>Decompressed data as a byte array</returns>
public static byte[] Decompress(byte[] to_decompress, int size_uncompressed)
{
ZlibStream stream = new ZlibStream(new System.IO.MemoryStream(to_decompress, false), CompressionMode.Decompress);
byte[] packetData_decompressed = new byte[size_uncompressed];
stream.Read(packetData_decompressed, 0, size_uncompressed);
stream.Close();
return packetData_decompressed;
}
}
}