Add SendPluginChannelPacket to the IMinecraftCom interface.

This commit is contained in:
Pokechu22 2015-10-24 22:26:45 -07:00
parent 7c8e856392
commit 77277bcf84
3 changed files with 62 additions and 24 deletions

View file

@ -642,29 +642,6 @@ namespace MinecraftClient.Protocol.Handlers
SendPluginChannelPacket("FML|HS", concatBytes(new byte[] { (byte)discriminator }, data));
}
/// <summary>
/// Send a plugin channel packet (0x3F) to the server, compression and encryption will be handled automatically
/// </summary>
/// <param name="channel">Channel to send packet on</param>
/// <param name="data">packet Data</param>
private void SendPluginChannelPacket(string channel, byte[] data)
{
// In 1.7, length needs to be included.
// In 1.8, it must not be.
if (protocolversion < MC18Version)
{
byte[] length = BitConverter.GetBytes((short)data.Length);
Array.Reverse(length);
SendPacket(0x17, concatBytes(getString(channel), length, data));
}
else
{
SendPacket(0x17, concatBytes(getString(channel), data));
}
}
/// <summary>
/// Send a packet to the server, compression and encryption will be handled automatically
/// </summary>
@ -861,9 +838,34 @@ namespace MinecraftClient.Protocol.Handlers
{
if (String.IsNullOrEmpty(brandInfo))
return false;
return SendPluginChannelPacket("MC|Brand", getString(brandInfo));
}
/// <summary>
/// Send a plugin channel packet (0x17) to the server, compression and encryption will be handled automatically
/// </summary>
/// <param name="channel">Channel to send packet on</param>
/// <param name="data">packet Data</param>
public bool SendPluginChannelPacket(string channel, byte[] data)
{
try
{
SendPluginChannelPacket("MC|Brand", getString(brandInfo));
// In 1.7, length needs to be included.
// In 1.8, it must not be.
if (protocolversion < MC18Version)
{
byte[] length = BitConverter.GetBytes((short)data.Length);
Array.Reverse(length);
SendPacket(0x17, concatBytes(getString(channel), length, data));
}
else
{
SendPacket(0x17, concatBytes(getString(channel), data));
}
return true;
}
catch (SocketException) { return false; }