summaryrefslogtreecommitdiffstats
path: root/src/ClientHandle.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-02-20 23:24:39 +0100
committermadmaxoft <github@xoft.cz>2014-02-20 23:24:39 +0100
commit27e77a28fa434805905dc49f49800f8987d0957d (patch)
treeafaf7bc915370f88dc91968d7b27d3b25e293e33 /src/ClientHandle.cpp
parentRemoved problematic utf8. (diff)
downloadcuberite-27e77a28fa434805905dc49f49800f8987d0957d.tar
cuberite-27e77a28fa434805905dc49f49800f8987d0957d.tar.gz
cuberite-27e77a28fa434805905dc49f49800f8987d0957d.tar.bz2
cuberite-27e77a28fa434805905dc49f49800f8987d0957d.tar.lz
cuberite-27e77a28fa434805905dc49f49800f8987d0957d.tar.xz
cuberite-27e77a28fa434805905dc49f49800f8987d0957d.tar.zst
cuberite-27e77a28fa434805905dc49f49800f8987d0957d.zip
Diffstat (limited to '')
-rw-r--r--src/ClientHandle.cpp87
1 files changed, 77 insertions, 10 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 84286fc41..3711262b6 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -542,19 +542,23 @@ void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ,
void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString & a_Message)
{
- if (a_Channel == "MC|AdvCdm") // Command block, set text, Client -> Server
+ if (a_Channel == "MC|AdvCdm")
{
- const char* Data = a_Message.c_str();
- HandleCommandBlockMessage(Data, a_Message.size());
- return;
+ // Command block, set text, Client -> Server
+ HandleCommandBlockMessage(a_Message.c_str(), a_Message.size());
}
- else if (a_Channel == "MC|Brand") // Client <-> Server branding exchange
+ else if (a_Channel == "MC|Brand")
{
- // We are custom,
- // We are awesome,
- // We are MCServer.
+ // Client <-> Server branding exchange
SendPluginMessage("MC|Brand", "MCServer");
- return;
+ }
+ else if (a_Channel == "REGISTER")
+ {
+ RegisterPluginChannels(BreakApartPluginChannels(a_Message));
+ }
+ else if (a_Channel == "UNREGISTER")
+ {
+ UnregisterPluginChannels(BreakApartPluginChannels(a_Message));
}
cPluginManager::Get()->CallHookPluginMessage(*this, a_Channel, a_Message);
@@ -564,7 +568,61 @@ void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString
-void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a_Length)
+AStringVector cClientHandle::BreakApartPluginChannels(const AString & a_PluginChannels)
+{
+ // 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;
+}
+
+
+
+
+
+void cClientHandle::RegisterPluginChannels(const AStringVector & a_ChannelList)
+{
+ for (AStringVector::const_iterator itr = a_ChannelList.begin(), end = a_ChannelList.end(); itr != end; ++itr)
+ {
+ m_PluginChannels.insert(*itr);
+ } // for itr - a_ChannelList[]
+}
+
+
+
+
+
+void cClientHandle::UnregisterPluginChannels(const AStringVector & a_ChannelList)
+{
+ for (AStringVector::const_iterator itr = a_ChannelList.begin(), end = a_ChannelList.end(); itr != end; ++itr)
+ {
+ m_PluginChannels.erase(*itr);
+ } // for itr - a_ChannelList[]
+}
+
+
+
+
+
+void cClientHandle::HandleCommandBlockMessage(const char * a_Data, unsigned int a_Length)
{
if (a_Length < 14)
{
@@ -2463,6 +2521,15 @@ void cClientHandle::SetViewDistance(int a_ViewDistance)
+bool cClientHandle::HasPluginChannel(const AString & a_PluginChannel)
+{
+ return (m_PluginChannels.find(a_PluginChannel) != m_PluginChannels.end());
+}
+
+
+
+
+
bool cClientHandle::WantsSendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
{
if (m_State >= csDestroying)