From 787382caf8d3f7f8df4598b29586b44b7b071c53 Mon Sep 17 00:00:00 2001 From: faketruth Date: Wed, 7 Mar 2012 13:36:30 +0000 Subject: Fixed bug where cPlayer's cClientHandle was used after cPlayer was destroyed http://forum.mc-server.org/showthread.php?tid=380 Also removed the SetClientHandle() function from cPlayer Added a Destroyed() function to cEntity that is called ONLY ONCE after an entity has been 'destroyed' Cleaned up some code, using enums for GameMode and Weather and replaced some 'const char *' with 'const AString &' Exposed some more functions to Lua git-svn-id: http://mc-server.googlecode.com/svn/trunk@382 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cPlayer.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'source/cPlayer.cpp') diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp index 673d0b41a..c6893b076 100644 --- a/source/cPlayer.cpp +++ b/source/cPlayer.cpp @@ -65,7 +65,7 @@ struct cPlayer::sPlayerState }; cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) - : m_GameMode( 0 ) + : m_GameMode( eGameMode_Survival ) , m_IP("") , m_LastBlockActionTime( 0 ) , m_LastBlockActionCnt( 0 ) @@ -132,7 +132,6 @@ cPlayer::~cPlayer(void) m_ClientHandle = NULL; - CloseWindow(-1); delete m_Inventory; m_Inventory = NULL; @@ -147,6 +146,16 @@ cPlayer::~cPlayer(void) +void cPlayer::Destroyed() +{ + CloseWindow(-1); + m_ClientHandle = NULL; +} + + + + + cPacket * cPlayer::GetSpawnPacket(void) const { LOGD("cPlayer::GetSpawnPacket for \"%s\" at pos {%.2f, %.2f, %.2f}", @@ -431,6 +440,7 @@ void cPlayer::CloseWindow(char a_WindowType) } if (m_CurrentWindow) { + // FIXME: If the player entity is destroyed while having a chest window open, the chest will not close if (a_WindowType == 1 && strcmp(m_CurrentWindow->GetWindowTitle().c_str(), "UberChest") == 0) { // Chest cBlockEntity *block = m_CurrentWindow->GetOwner()->GetEntity(); cPacket_BlockAction ChestClose; @@ -469,14 +479,14 @@ void cPlayer::SetLastBlockActionCnt( int a_LastBlockActionCnt ) -void cPlayer::SetGameMode( int a_GameMode ) +void cPlayer::SetGameMode( eGameMode a_GameMode ) { if ( (a_GameMode < 2) && (a_GameMode >= 0) ) { if (m_GameMode != a_GameMode) { cInventory *OldInventory = 0; - if(m_GameMode == 0) + if(m_GameMode == eGameMode_Survival) OldInventory = m_Inventory; else OldInventory = m_CreativeInventory; @@ -497,7 +507,7 @@ void cPlayer::SetGameMode( int a_GameMode ) -void cPlayer::LoginSetGameMode( int a_GameMode ) +void cPlayer::LoginSetGameMode( eGameMode a_GameMode ) { m_GameMode = a_GameMode; } @@ -998,9 +1008,9 @@ cPlayer::StringList cPlayer::GetResolvedPermissions() -const char* cPlayer::GetLoadedWorldName() +const AString & cPlayer::GetLoadedWorldName() { - return m_pState->LoadedWorldName.c_str(); + return m_pState->LoadedWorldName; } -- cgit v1.2.3