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/ChannelManager.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/ChannelManager.h (limited to 'src/ChannelManager.h') diff --git a/src/ChannelManager.h b/src/ChannelManager.h new file mode 100644 index 000000000..874588d29 --- /dev/null +++ b/src/ChannelManager.h @@ -0,0 +1,66 @@ +#pragma once + +#include +#include + +#include "StringUtils.h" + + +class cClientHandle; +class cCriticalSection; +class cPluginLua; +class cWorld; +class cChannelCallback; +class cByteBuffer; + +// tolua_begin +class cChannelManager +{ +// tolua_end +public: + typedef SharedPtr cChannelCallbackPtr; + typedef std::unordered_map CallbackMap; + + /** Adds a client to a specific channel. */ + void AddClientToChannel (cClientHandle & a_Client, const AString & a_Channel); // tolua_export + + /** Adds a client to multiple channels at once. */ + void AddClientToChannels (cClientHandle & a_Client, const AString & a_Channels); + + /** Removes a client from a specific channel. */ + void RemoveClientFromChannel (cClientHandle & a_Client, const AString & a_Channel); // tolua_export + + /** Removes a client from multiple channels at once. */ + void RemoveClientFromChannels(cClientHandle & a_Client, const AString & a_Channels); + + /** Returns true if the client is registered for the specified channel. */ + bool ClientHasChannel (cClientHandle & a_Client, const AString & a_Channel); + + /** Broadcasts a channel message to all clients. + If a_World is provided, broadcast is limited to that world. */ + void BroadcastChannelMessage (const AString & a_Channel, cByteBuffer & a_Data, cWorld * a_World = nullptr); // tolua_export + + /** Registers a handler for a specific channel. + Returns true if registration was successful. */ + bool RegisterChannel (const AString & a_Channel, cChannelCallbackPtr a_Callback); // Exported in manual bindings + + /** Removes the handler for the specified channel. + Returns true if the handler was removed. */ + bool RemoveChannel (const AString & a_Channel); // tolua_export + + + void HandleChannelMessage (cClientHandle & a_Client, const AString & a_Channel, cByteBuffer & a_Data); + + + void HandlePluginUnloading (const cPluginLua * a_Plugin); + +private: + + AStringVector BreakApartChannels(const AString & a_Channels); + + /** This protects m_ChannelCallbacks */ + cCriticalSection m_CSCallbacks; + + CallbackMap m_ChannelCallbacks; + +}; // tolua_export -- cgit v1.2.3