From 89b1bbdc5fca5a51df1a5dd18ce91f27cb667c04 Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 30 Jul 2014 21:59:35 +0200 Subject: Added beacon. --- src/ClientHandle.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 30ec737be..849de2ce1 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -31,6 +31,7 @@ #include "Items/ItemSword.h" #include "polarssl/md5.h" +#include "BlockEntities/BeaconEntity.h" @@ -659,6 +660,10 @@ void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString // Client <-> Server branding exchange SendPluginMessage("MC|Brand", "MCServer"); } + else if (a_Channel == "MC|Beacon") + { + HandleBeaconSelection(a_Message.c_str(), a_Message.size()); + } else if (a_Channel == "MC|ItemName") { HandleAnvilItemName(a_Message.c_str(), a_Message.size()); @@ -746,6 +751,55 @@ void cClientHandle::UnregisterPluginChannels(const AStringVector & a_ChannelList +void cClientHandle::HandleBeaconSelection(const char * a_Data, size_t a_Length) +{ + if (a_Length < 14) + { + SendChat("Failure setting beacon selection; bad request", mtFailure); + LOGD("Malformed MC|Beacon packet."); + return; + } + + cWindow * Window = m_Player->GetWindow(); + if ((Window == NULL) || (Window->GetWindowType() != cWindow::wtBeacon)) + { + return; + } + cBeaconWindow * BeaconWindow = (cBeaconWindow *) Window; + + if (Window->GetSlot(*m_Player, 0)->IsEmpty()) + { + return; + } + + cByteBuffer Buffer(a_Length); + Buffer.Write(a_Data, a_Length); + + int PrimaryPotionID, SecondaryPotionID; + Buffer.ReadBEInt(PrimaryPotionID); + Buffer.ReadBEInt(SecondaryPotionID); + + cEntityEffect::eType PrimaryPotion = cEntityEffect::effNoEffect; + if ((PrimaryPotionID >= 0) && (PrimaryPotionID <= (int)cEntityEffect::effSaturation)) + { + PrimaryPotion = (cEntityEffect::eType)PrimaryPotionID; + } + + cEntityEffect::eType SecondaryPotion = cEntityEffect::effNoEffect; + if ((SecondaryPotionID >= 0) && (SecondaryPotionID <= (int)cEntityEffect::effSaturation)) + { + SecondaryPotion = (cEntityEffect::eType)SecondaryPotionID; + } + + Window->SetSlot(*m_Player, 0, cItem()); + BeaconWindow->GetBeaconEntity()->SelectPrimaryPotion(PrimaryPotion); + BeaconWindow->GetBeaconEntity()->SelectSecondaryPotion(SecondaryPotion); +} + + + + + void cClientHandle::HandleCommandBlockMessage(const char * a_Data, size_t a_Length) { if (a_Length < 14) -- cgit v1.2.3 From 556fc908aedcc36388e9d859487b140045e5e33e Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 31 Jul 2014 12:13:11 +0200 Subject: Renamed functions and added beacon json saving. --- src/ClientHandle.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 849de2ce1..e833f338a 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -7,6 +7,7 @@ #include "Bindings/PluginManager.h" #include "Entities/Player.h" #include "Inventory.h" +#include "BlockEntities/BeaconEntity.h" #include "BlockEntities/ChestEntity.h" #include "BlockEntities/CommandBlockEntity.h" #include "BlockEntities/SignEntity.h" @@ -31,7 +32,6 @@ #include "Items/ItemSword.h" #include "polarssl/md5.h" -#include "BlockEntities/BeaconEntity.h" @@ -775,25 +775,25 @@ void cClientHandle::HandleBeaconSelection(const char * a_Data, size_t a_Length) cByteBuffer Buffer(a_Length); Buffer.Write(a_Data, a_Length); - int PrimaryPotionID, SecondaryPotionID; - Buffer.ReadBEInt(PrimaryPotionID); - Buffer.ReadBEInt(SecondaryPotionID); + int PrimaryEffectID, SecondaryEffectID; + Buffer.ReadBEInt(PrimaryEffectID); + Buffer.ReadBEInt(SecondaryEffectID); - cEntityEffect::eType PrimaryPotion = cEntityEffect::effNoEffect; - if ((PrimaryPotionID >= 0) && (PrimaryPotionID <= (int)cEntityEffect::effSaturation)) + cEntityEffect::eType PrimaryEffect = cEntityEffect::effNoEffect; + if ((PrimaryEffectID >= 0) && (PrimaryEffectID <= (int)cEntityEffect::effSaturation)) { - PrimaryPotion = (cEntityEffect::eType)PrimaryPotionID; + PrimaryEffect = (cEntityEffect::eType)PrimaryEffectID; } - cEntityEffect::eType SecondaryPotion = cEntityEffect::effNoEffect; - if ((SecondaryPotionID >= 0) && (SecondaryPotionID <= (int)cEntityEffect::effSaturation)) + cEntityEffect::eType SecondaryEffect = cEntityEffect::effNoEffect; + if ((SecondaryEffectID >= 0) && (SecondaryEffectID <= (int)cEntityEffect::effSaturation)) { - SecondaryPotion = (cEntityEffect::eType)SecondaryPotionID; + SecondaryEffect = (cEntityEffect::eType)SecondaryEffectID; } Window->SetSlot(*m_Player, 0, cItem()); - BeaconWindow->GetBeaconEntity()->SelectPrimaryPotion(PrimaryPotion); - BeaconWindow->GetBeaconEntity()->SelectSecondaryPotion(SecondaryPotion); + BeaconWindow->GetBeaconEntity()->SelectPrimaryEffect(PrimaryEffect); + BeaconWindow->GetBeaconEntity()->SelectSecondaryEffect(SecondaryEffect); } -- cgit v1.2.3 From 6b1f7e7a45ebc04f39bb54edc85fbe9c9d0659e7 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 31 Jul 2014 18:15:39 +0200 Subject: Renamed "select..." methods to "set..." and better IsValidEffect() function. --- src/ClientHandle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index e833f338a..3ce506e1e 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -792,8 +792,8 @@ void cClientHandle::HandleBeaconSelection(const char * a_Data, size_t a_Length) } Window->SetSlot(*m_Player, 0, cItem()); - BeaconWindow->GetBeaconEntity()->SelectPrimaryEffect(PrimaryEffect); - BeaconWindow->GetBeaconEntity()->SelectSecondaryEffect(SecondaryEffect); + BeaconWindow->GetBeaconEntity()->SetPrimaryEffect(PrimaryEffect); + BeaconWindow->GetBeaconEntity()->SetSecondaryEffect(SecondaryEffect); } -- cgit v1.2.3