From 77277bcf8418d859ff6de330a9c7103d0a6b3a43 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Sat, 24 Oct 2015 22:26:45 -0700 Subject: [PATCH] Add SendPluginChannelPacket to the IMinecraftCom interface. --- .../Protocol/Handlers/Protocol16.cs | 25 ++++++++++ .../Protocol/Handlers/Protocol18.cs | 50 ++++++++++--------- MinecraftClient/Protocol/IMinecraftCom.cs | 11 ++++ 3 files changed, 62 insertions(+), 24 deletions(-) diff --git a/MinecraftClient/Protocol/Handlers/Protocol16.cs b/MinecraftClient/Protocol/Handlers/Protocol16.cs index 1813b9af..89cedbe6 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol16.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol16.cs @@ -615,6 +615,31 @@ namespace MinecraftClient.Protocol.Handlers return false; //Only supported since MC 1.7 } + /// + /// Send a plugin channel packet to the server. + /// + /// Channel to send packet on + /// packet Data + + 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)) diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 70ef4766..8fc5eaae 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -642,29 +642,6 @@ namespace MinecraftClient.Protocol.Handlers SendPluginChannelPacket("FML|HS", concatBytes(new byte[] { (byte)discriminator }, data)); } - /// - /// Send a plugin channel packet (0x3F) to the server, compression and encryption will be handled automatically - /// - /// Channel to send packet on - /// packet Data - - 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)); - } - } - /// /// Send a packet to the server, compression and encryption will be handled automatically /// @@ -861,9 +838,34 @@ namespace MinecraftClient.Protocol.Handlers { if (String.IsNullOrEmpty(brandInfo)) return false; + + return SendPluginChannelPacket("MC|Brand", getString(brandInfo)); + } + + /// + /// Send a plugin channel packet (0x17) to the server, compression and encryption will be handled automatically + /// + /// Channel to send packet on + /// packet Data + + 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; } diff --git a/MinecraftClient/Protocol/IMinecraftCom.cs b/MinecraftClient/Protocol/IMinecraftCom.cs index 9c351ebc..218f49d4 100644 --- a/MinecraftClient/Protocol/IMinecraftCom.cs +++ b/MinecraftClient/Protocol/IMinecraftCom.cs @@ -51,5 +51,16 @@ namespace MinecraftClient.Protocol /// True if brand info was successfully sent bool SendBrandInfo(string brandInfo); + + /// + /// Send a plugin channel packet to the server. + /// + /// http://dinnerbone.com/blog/2012/01/13/minecraft-plugin-channels-messaging/ + /// + /// Channel to send packet on + /// packet Data + /// True if message was successfully sent + + bool SendPluginChannelPacket(string channel, byte[] data); } }