1
0

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
This commit is contained in:
faketruth
2012-03-07 13:36:30 +00:00
parent d63b092e02
commit 787382caf8
13 changed files with 306 additions and 107 deletions

View File

@@ -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;
}