Give ChatBots access to plugin channels.

Chatbots may find it useful to send messages over plugin channels.  This allows REGISTERing, UNREGISTERing, and sending over plugin channels, with built-in checking if the server also registered the channel (which can be disabled by the bot if needed). Unused channels are UNREGISTERed when a bot is disabled.
This commit is contained in:
Pokechu22 2016-02-07 14:24:01 -08:00
parent bdbd8ab0b8
commit 1ea8f119d9
5 changed files with 215 additions and 3 deletions

View file

@ -164,7 +164,10 @@ namespace MinecraftClient.Protocol.Handlers
case 0xCF: if (protocolversion > 51) { readNextString(); readData(1); readNextString(); } readData(4); break;
case 0xD0: if (protocolversion > 51) { readData(1); readNextString(); } break;
case 0xD1: if (protocolversion > 51) { readNextTeamData(); } break;
case 0xFA: readNextString(); nbr = readNextShort(); readData(nbr); break;
case 0xFA: string channel = readNextString();
byte[] payload = readNextByteArray();
handler.OnPluginChannelMessage(channel, payload);
break;
case 0xFF: string reason = readNextString();
handler.OnConnectionLost(ChatBot.DisconnectReason.InGameKick, reason); break;
default: return false; //unknown packet!

View file

@ -303,6 +303,10 @@ namespace MinecraftClient.Protocol.Handlers
readNextVarShort(packetData);
}
}
// The remaining data in the array is the entire payload of the packet.
handler.OnPluginChannelMessage(channel, packetData.ToArray());
if (forgeInfo != null)
{
if (channel == "FML|HS")

View file

@ -14,7 +14,7 @@ namespace MinecraftClient.Protocol
public interface IMinecraftComHandler
{
/* The MinecraftCom Hanler must
/* The MinecraftCom Handler must
* provide these getters */
int GetServerPort();
@ -72,5 +72,40 @@ namespace MinecraftClient.Protocol
/// </summary>
void OnUpdate();
/// <summary>
/// Registers the given plugin channel for the given bot.
/// </summary>
/// <param name="channel">The channel to register.</param>
/// <param name="bot">The bot to register the channel for.</param>
void RegisterPluginChannel(string channel, ChatBot bot);
/// <summary>
/// Unregisters the given plugin channel for the given bot.
/// </summary>
/// <param name="channel">The channel to unregister.</param>
/// <param name="bot">The bot to unregister the channel for.</param>
void UnregisterPluginChannel(string channel, ChatBot bot);
/// <summary>
/// Sends a plugin channel packet to the server. See http://wiki.vg/Plugin_channel for more information
/// about plugin channels.
/// </summary>
/// <param name="channel">The channel to send the packet on.</param>
/// <param name="data">The payload for the packet.</param>
/// <param name="sendEvenIfNotRegistered">Whether the packet should be sent even if the server or the client hasn't registered it yet.</param>
/// <returns>Whether the packet was sent: true if it was sent, false if there was a connection error or it wasn't registered.</returns>
bool SendPluginChannelMessage(string channel, byte[] data, bool sendEvenIfNotRegistered = false);
/// <summary>
/// Called when a plugin channel message was sent from the server.
/// </summary>
/// <param name="channel">The channel the message was sent on</param>
/// <param name="data">The data from the channel</param>
void OnPluginChannelMessage(string channel, byte[] data);
}
}