From 24e89bbb2c656224d06aed084b952bbc885e3914 Mon Sep 17 00:00:00 2001 From: Samuel Barney Date: Mon, 18 Jul 2016 14:39:11 -0600 Subject: Feature: Channel Management with Lua API Allows lua plugins to register handles for channel messages. * Only one handle can be registered for one channel at a time. * Plugins can also add and remove clients from channels, sending the appropriate packet to the client. --- src/Protocol/Protocol18x.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/Protocol/Protocol18x.cpp') diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index ae9571f03..efd9cd5a9 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -16,6 +16,7 @@ Implements the 1.8.x protocol classes: #include "Packetizer.h" #include "../ClientHandle.h" +#include "../ChannelManager.h" #include "../Root.h" #include "../Server.h" #include "../World.h" @@ -2483,10 +2484,24 @@ void cProtocol180::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer) return; } - // Read the plugin message and relay to clienthandle: + // Read the rest of the message + cByteBuffer Buffer = a_ByteBuffer; AString Data; VERIFY(a_ByteBuffer.ReadString(Data, a_ByteBuffer.GetReadableSpace() - 1)); // Always succeeds - m_Client->HandlePluginMessage(Channel, Data); + + auto manager = cRoot::Get()->GetServer()->GetChannelManager(); + // Register the client on the requested channels + if (Channel == "REGISTER") + { + manager->AddClientToChannels(*m_Client, Data); + } + else if (Channel == "UNREGISTER") + { + manager->RemoveClientFromChannels(*m_Client, Data); + } + + // Call the channel message handler + manager->HandleChannelMessage(*m_Client, Channel, Buffer); } @@ -2738,10 +2753,7 @@ void cProtocol180::HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const } LOG("Unhandled vanilla plugin channel: \"%s\".", a_Channel.c_str()); - // Read the payload and send it through to the clienthandle: - AString Message; - VERIFY(a_ByteBuffer.ReadString(Message, a_ByteBuffer.GetReadableSpace() - 1)); - m_Client->HandlePluginMessage(a_Channel, Message); + cRoot::Get()->GetServer()->GetChannelManager()->HandleChannelMessage(*m_Client, a_Channel, a_ByteBuffer); } @@ -3592,6 +3604,3 @@ void cProtocol180::WriteEntityProperties(cPacketizer & a_Pkt, const cEntity & a_ a_Pkt.WriteBEInt32(0); // NumProperties } - - - -- cgit v1.2.3