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

@ -615,6 +615,31 @@ namespace MinecraftClient.Protocol.Handlers
return false; //Only supported since MC 1.7
}
/// <summary>
/// Send a plugin channel packet to the server.
/// </summary>
/// <param name="channel">Channel to send packet on</param>
/// <param name="data">packet Data</param>
public bool SendPluginChannelPacket(string channel, byte[] data)
{
try {
byte[] channelLength = BitConverter.GetBytes((short)channel.Length);
Array.Reverse(channelLength);
byte[] channelData = Encoding.BigEndianUnicode.GetBytes(channel);
byte[] dataLength = BitConverter.GetBytes((short)data.Length);
Array.Reverse(dataLength);
Send(concatBytes(new byte[] { 0xFA }, channelLength, channelData, dataLength, data));
return true;
}
catch (SocketException) { return false; }
catch (System.IO.IOException) { return false; }
}
public string AutoComplete(string BehindCursor)
{
if (String.IsNullOrEmpty(BehindCursor))

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; }

View file

@ -51,5 +51,16 @@ namespace MinecraftClient.Protocol
/// <returns>True if brand info was successfully sent</returns>
bool SendBrandInfo(string brandInfo);
/// <summary>
/// Send a plugin channel packet to the server.
///
/// http://dinnerbone.com/blog/2012/01/13/minecraft-plugin-channels-messaging/
/// </summary>
/// <param name="channel">Channel to send packet on</param>
/// <param name="data">packet Data</param>
/// <returns>True if message was successfully sent</returns>
bool SendPluginChannelPacket(string channel, byte[] data);
}
}