From 9af5ed43fd7f85c3b2813485d0a37a559589d694 Mon Sep 17 00:00:00 2001 From: faketruth Date: Sat, 31 Dec 2011 21:08:23 +0000 Subject: Made a couple of functions in cChunk inline, this should speed up several block operations on chunks Players should not spawn in the ground anymore. When an entity was added to cWorld twice (which shouldn't happen actually), the server would crash when the entity is destroyed, this should be fixed now. git-svn-id: http://mc-server.googlecode.com/svn/trunk@158 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cClientHandle.cpp | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'source/cClientHandle.cpp') diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index 6badd5ae1..6f38a1f27 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -516,25 +516,19 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) cPacket_Chat Joined( m_pState->Username + " joined the game!"); cRoot::Get()->GetServer()->Broadcast( Joined, this ); } - int posx = (int) m_Player->GetPosX(); - int posy = (int) m_Player->GetPosY(); - int posz = (int) m_Player->GetPosZ(); + // Now initialize player (adds to entity list etc.) cWorld* PlayerWorld = cRoot::Get()->GetWorld( m_Player->GetLoadedWorldName() ); if( !PlayerWorld ) PlayerWorld = cRoot::Get()->GetDefaultWorld(); - m_Player->Initialize( PlayerWorld ); // TODO - Get correct world for player - - // Broadcasts to all but this ( this is actually handled in cChunk.cpp, after entity is added to the chunk ) - //m_Player->SpawnOn( 0 ); - - // Send all already connected players to new player - //cRoot::Get()->GetServer()->SendAllEntitiesTo( this ); + m_Player->Initialize( PlayerWorld ); // Then we can start doing more stuffs! :D m_bLoggedIn = true; LOG("%s completely logged in", GetUsername() ); - m_Player->TeleportTo( posx, posy, posz ); StreamChunks(); + + // Send position + Send( cPacket_PlayerMoveLook( m_Player ) ); } break; case E_KEEP_ALIVE: @@ -1268,7 +1262,7 @@ void cClientHandle::Tick(float a_Dt) // Spawn player (only serversided, so data is loaded) m_Player = new cPlayer( this, GetUsername() ); // !!DO NOT INITIALIZE!! <- is done after receiving MoveLook Packet - cWorld* World = cRoot::Get()->GetWorld( m_Player->GetLoadedWorldName() ); // TODO - Get the correct world or better yet, move this to the main thread so we don't have to lock anything + cWorld* World = cRoot::Get()->GetWorld( m_Player->GetLoadedWorldName() ); if( !World ) World = cRoot::Get()->GetDefaultWorld(); World->LockEntities(); m_Player->LoginSetGameMode ( World->GetGameMode() ); //set player's gamemode to server's gamemode at login. TODO: set to last player's gamemode at logout @@ -1295,9 +1289,6 @@ void cClientHandle::Tick(float a_Dt) Send( RainPacket ); } - // Send position - Send( cPacket_PlayerMoveLook( m_Player ) ); - // Send time Send( cPacket_TimeUpdate( World->GetWorldTime() ) ); @@ -1310,7 +1301,6 @@ void cClientHandle::Tick(float a_Dt) Health.m_Food = m_Player->GetFood(); Health.m_Saturation = m_Player->GetFoodSaturation(); Send(Health); - //Send( cPacket_UpdateHealth( (short)m_Player->GetHealth() ) ); World->UnlockEntities(); } -- cgit v1.2.3