diff options
author | Samuel Barney <sbarney@instructure.com> | 2016-07-18 22:39:11 +0200 |
---|---|---|
committer | Samuel Barney <samjbarney@gmail.com> | 2016-08-15 19:13:03 +0200 |
commit | 24e89bbb2c656224d06aed084b952bbc885e3914 (patch) | |
tree | ba75a68cce6ea868acba60ae08efeeccf003736d /src/ClientHandle.cpp | |
parent | Switch out long download/compile links. (#3278) (diff) | |
download | cuberite-ChannelManagement.tar cuberite-ChannelManagement.tar.gz cuberite-ChannelManagement.tar.bz2 cuberite-ChannelManagement.tar.lz cuberite-ChannelManagement.tar.xz cuberite-ChannelManagement.tar.zst cuberite-ChannelManagement.zip |
Diffstat (limited to '')
-rw-r--r-- | src/ClientHandle.cpp | 61 |
1 files changed, 7 insertions, 54 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 997510684..b44f23abe 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -803,68 +803,25 @@ void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ, -void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString & a_Message) +void cClientHandle::RegisterChannel(const AString & a_Channel) { - if (a_Channel == "REGISTER") - { - if (HasPluginChannel(a_Channel)) - { - SendPluginMessage("UNREGISTER", a_Channel); - return; // Can't register again if already taken - kinda defeats the point of plugin messaging! - } - - RegisterPluginChannels(BreakApartPluginChannels(a_Message)); - } - else if (a_Channel == "UNREGISTER") - { - UnregisterPluginChannels(BreakApartPluginChannels(a_Message)); - } - else if (!HasPluginChannel(a_Channel)) - { - // Ignore if client sent something but didn't register the channel first - LOGD("Player %s sent a plugin message on channel \"%s\", but didn't REGISTER it first", GetUsername().c_str(), a_Channel.c_str()); - SendPluginMessage("UNREGISTER", a_Channel); - return; - } - - cPluginManager::Get()->CallHookPluginMessage(*this, a_Channel, a_Message); + m_PluginChannels.insert(a_Channel); } -AStringVector cClientHandle::BreakApartPluginChannels(const AString & a_PluginChannels) +void cClientHandle::UnregisterChannel(const AString & a_Channel) { - // Break the string on each NUL character. - // Note that StringSplit() doesn't work on this because NUL is a special char - string terminator - size_t len = a_PluginChannels.size(); - size_t first = 0; - AStringVector res; - for (size_t i = 0; i < len; i++) - { - if (a_PluginChannels[i] != 0) - { - continue; - } - if (i > first) - { - res.push_back(a_PluginChannels.substr(first, i - first)); - } - first = i + 1; - } // for i - a_PluginChannels[] - if (first < len) - { - res.push_back(a_PluginChannels.substr(first, len - first)); - } - return res; + m_PluginChannels.erase(a_Channel); } -void cClientHandle::RegisterPluginChannels(const AStringVector & a_ChannelList) +void cClientHandle::RegisterChannels(const AStringVector & a_ChannelList) { for (AStringVector::const_iterator itr = a_ChannelList.begin(), end = a_ChannelList.end(); itr != end; ++itr) { @@ -876,7 +833,7 @@ void cClientHandle::RegisterPluginChannels(const AStringVector & a_ChannelList) -void cClientHandle::UnregisterPluginChannels(const AStringVector & a_ChannelList) +void cClientHandle::UnregisterChannels(const AStringVector & a_ChannelList) { for (AStringVector::const_iterator itr = a_ChannelList.begin(), end = a_ChannelList.end(); itr != end; ++itr) { @@ -3026,7 +2983,7 @@ void cClientHandle::SetViewDistance(int a_ViewDistance) bool cClientHandle::HasPluginChannel(const AString & a_PluginChannel) { - return (m_PluginChannels.find(a_PluginChannel) != m_PluginChannels.end()); + return (m_PluginChannels.find(a_PluginChannel) != m_PluginChannels.end()) || (a_PluginChannel == "REGISTER") || (a_PluginChannel == "UNREGISTER"); } @@ -3185,7 +3142,3 @@ void cClientHandle::OnError(int a_ErrorCode, const AString & a_ErrorMsg) } SocketClosed(); } - - - - |