summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2015-02-06 21:52:14 +0100
committerHowaner <franzi.moos@googlemail.com>2015-02-06 21:52:14 +0100
commit2c7925f0adc17d7680ff9791832ab2c349c2301f (patch)
treeef6233b0d9dece6f7520996f2a4d850470e2c2d3 /src/Entities
parentReadded old DistributeStackToAreas() comment. (diff)
parentSwitched LuaState to use sizeof... (diff)
downloadcuberite-2c7925f0adc17d7680ff9791832ab2c349c2301f.tar
cuberite-2c7925f0adc17d7680ff9791832ab2c349c2301f.tar.gz
cuberite-2c7925f0adc17d7680ff9791832ab2c349c2301f.tar.bz2
cuberite-2c7925f0adc17d7680ff9791832ab2c349c2301f.tar.lz
cuberite-2c7925f0adc17d7680ff9791832ab2c349c2301f.tar.xz
cuberite-2c7925f0adc17d7680ff9791832ab2c349c2301f.tar.zst
cuberite-2c7925f0adc17d7680ff9791832ab2c349c2301f.zip
Diffstat (limited to 'src/Entities')
-rw-r--r--src/Entities/Player.cpp24
-rw-r--r--src/Entities/Player.h18
2 files changed, 32 insertions, 10 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 67de2e23a..3e225f1ec 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;