From 7dfeb67f016135c6da8373b96c32d447e8bf027e Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 24 Jan 2015 20:17:00 +0100 Subject: Converted cServer to use the cNetwork API. --- src/Entities/Player.cpp | 24 +++++++++++++++++------- src/Entities/Player.h | 18 +++++++++++++++--- 2 files changed, 32 insertions(+), 10 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 1ca131375..527380761 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -47,7 +47,7 @@ const int cPlayer::EATING_TICKS = 30; -cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) : +cPlayer::cPlayer(cClientHandlePtr a_Client, const AString & a_PlayerName) : super(etPlayer, 0.6, 1.8), m_bVisible(true), m_FoodLevel(MAX_FOOD_LEVEL), @@ -174,7 +174,7 @@ void cPlayer::Destroyed() void cPlayer::SpawnOn(cClientHandle & a_Client) { - if (!m_bVisible || (m_ClientHandle == (&a_Client))) + if (!m_bVisible || (m_ClientHandle.get() == (&a_Client))) { return; } @@ -246,7 +246,7 @@ void cPlayer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) if (CanMove) { - BroadcastMovementUpdate(m_ClientHandle); + BroadcastMovementUpdate(m_ClientHandle.get()); } if (m_Health > 0) // make sure player is alive @@ -419,7 +419,7 @@ void cPlayer::StartChargingBow(void) LOGD("Player \"%s\" started charging their bow", GetName().c_str()); m_IsChargingBow = true; m_BowCharge = 0; - m_World->BroadcastEntityMetadata(*this, m_ClientHandle); + m_World->BroadcastEntityMetadata(*this, m_ClientHandle.get()); } @@ -432,7 +432,7 @@ int cPlayer::FinishChargingBow(void) int res = m_BowCharge; m_IsChargingBow = false; m_BowCharge = 0; - m_World->BroadcastEntityMetadata(*this, m_ClientHandle); + m_World->BroadcastEntityMetadata(*this, m_ClientHandle.get()); return res; } @@ -446,7 +446,7 @@ void cPlayer::CancelChargingBow(void) LOGD("Player \"%s\" cancelled charging their bow at a charge of %d", GetName().c_str(), m_BowCharge); m_IsChargingBow = false; m_BowCharge = 0; - m_World->BroadcastEntityMetadata(*this, m_ClientHandle); + m_World->BroadcastEntityMetadata(*this, m_ClientHandle.get()); } @@ -1391,7 +1391,7 @@ void cPlayer::SetVisible(bool a_bVisible) if (!a_bVisible && m_bVisible) { m_bVisible = false; - m_World->BroadcastDestroyEntity(*this, m_ClientHandle); // Destroy on all clients + m_World->BroadcastDestroyEntity(*this, m_ClientHandle.get()); // Destroy on all clients } } @@ -2294,6 +2294,16 @@ void cPlayer::Detach() +void cPlayer::RemoveClientHandle(void) +{ + ASSERT(m_ClientHandle != nullptr); + m_ClientHandle.reset(); +} + + + + + AString cPlayer::GetUUIDFileName(const AString & a_UUID) { AString UUID = cMojangAPI::MakeUUIDDashed(a_UUID); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index d3ed46db6..fa9ac7cad 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -40,7 +40,7 @@ public: CLASS_PROTODEF(cPlayer) - cPlayer(cClientHandle * a_Client, const AString & a_PlayerName); + cPlayer(cClientHandlePtr a_Client, const AString & a_PlayerName); virtual ~cPlayer(); @@ -222,7 +222,15 @@ public: /** Closes the current window if it matches the specified ID, resets current window to m_InventoryWindow */ void CloseWindowIfID(char a_WindowID, bool a_CanRefuse = true); - cClientHandle * GetClientHandle(void) const { return m_ClientHandle; } + /** Returns the raw client handle associated with the player. */ + cClientHandle * GetClientHandle(void) const { return m_ClientHandle.get(); } + + // tolua_end + + /** Returns the SharedPtr to client handle associated with the player. */ + cClientHandlePtr GetClientHandlePtr(void) const { return m_ClientHandle; } + + // tolua_begin void SendMessage (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtCustom); } void SendMessageInfo (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtInformation); } @@ -467,6 +475,10 @@ public: virtual bool IsRclking (void) const { return IsEating() || IsChargingBow(); } virtual void Detach(void); + + /** Called by cClientHandle when the client is being destroyed. + The player removes its m_ClientHandle ownership so that the ClientHandle gets deleted. */ + void RemoveClientHandle(void); protected: @@ -537,7 +549,7 @@ protected: std::chrono::steady_clock::time_point m_LastPlayerListTime; - cClientHandle * m_ClientHandle; + cClientHandlePtr m_ClientHandle; cSlotNums m_InventoryPaintSlots; -- cgit v1.2.3