From f7b8a301f8a705cec6df17c7051164169cf619a6 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Wed, 3 Jul 2013 07:47:35 +0000 Subject: Fixed player moving between worlds. Fixes FS #407. Also fixes a few possible deadlocks between SocketThreads and TickThread git-svn-id: http://mc-server.googlecode.com/svn/trunk@1641 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Player.cpp | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) (limited to 'source/Player.cpp') diff --git a/source/Player.cpp b/source/Player.cpp index 84d38f13b..865ff24d6 100644 --- a/source/Player.cpp +++ b/source/Player.cpp @@ -117,9 +117,9 @@ cPlayer::~cPlayer(void) -void cPlayer::Initialize( cWorld* a_World ) +void cPlayer::Initialize(cWorld * a_World) { - cPawn::Initialize( a_World ); + super::Initialize(a_World); GetWorld()->AddPlayer(this); } @@ -891,26 +891,37 @@ void cPlayer::TossItem( -bool cPlayer::MoveToWorld( const char* a_WorldName ) +bool cPlayer::MoveToWorld(const char * a_WorldName) { - cWorld * World = cRoot::Get()->GetWorld( a_WorldName ); - if ( World ) + cWorld * World = cRoot::Get()->GetWorld(a_WorldName); + if (World == NULL) { - /* Remove all links to the old world */ - m_World->RemovePlayer( this ); - m_ClientHandle->RemoveFromAllChunks(); - m_World->RemoveEntity(this); - - /* Add player to all the necessary parts of the new world */ - SetWorld( World ); - GetWorld()->AddPlayer(this); - - m_ClientHandle->HandleRespawn(); - m_ClientHandle->StreamChunks(); - return true; + LOG("%s: Couldn't find world \"%s\".", a_WorldName); + return false; } - - return false; + + eDimension OldDimension = m_World->GetDimension(); + + // Remove all links to the old world + m_World->RemovePlayer(this); + m_ClientHandle->RemoveFromAllChunks(); + m_World->RemoveEntity(this); + + // Add player to all the necessary parts of the new world + SetWorld(World); + World->AddEntity(this); + World->AddPlayer(this); + + // If the dimension is different, we can send the respawn packet + // http://wiki.vg/Protocol#0x09 says "don't send if dimension is the same" as of 2013_07_02 + if (OldDimension != World->GetDimension()) + { + m_ClientHandle->SendRespawn(); + } + + // Stream the new chunks: + m_ClientHandle->StreamChunks(); + return true; } -- cgit v1.2.3