From c628ab03e9aae0b8e56f260ad02cfc7d51285a71 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 12 Aug 2013 08:35:13 +0200 Subject: Removed cServer::BroadcastChat() and cServer::SendMessage(). These two functions make it difficult to move to the new ticking system, and they aren't used anyway. If so required, they can be emulated by ForEachWorld / ForEachPlayer calls. --- source/Player.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'source/Player.cpp') diff --git a/source/Player.cpp b/source/Player.cpp index 03c871736..df7e1d539 100644 --- a/source/Player.cpp +++ b/source/Player.cpp @@ -129,6 +129,12 @@ bool cPlayer::Initialize(cWorld * a_World) { if (super::Initialize(a_World)) { + // Remove the client handle from the server, it will be ticked from this object from now on + if (m_ClientHandle != NULL) + { + cRoot::Get()->GetServer()->ClientMovedToWorld(m_ClientHandle); + } + GetWorld()->AddPlayer(this); return true; } @@ -175,18 +181,22 @@ void cPlayer::SpawnOn(cClientHandle & a_Client) void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) { - if (!m_ClientHandle->IsPlaying()) + if (m_ClientHandle != NULL) { - // We're not yet in the game, ignore everything - return; + if (!m_ClientHandle->IsPlaying()) + { + // We're not yet in the game, ignore everything + return; + } + m_ClientHandle->Tick(a_Dt); } super::Tick(a_Dt, a_Chunk); - // set player swimming state - SetSwimState( a_Chunk); + // Set player swimming state + SetSwimState(a_Chunk); - // handle air drowning stuff + // Handle air drowning stuff HandleAir(); if (m_bDirtyPosition) -- cgit v1.2.3 From 9020dc993241a4a90e8e98b3435d9b2576f313ea Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 13 Aug 2013 22:45:29 +0200 Subject: Clients are now ticked in cServer first, then in cWorld once they get assigned a world. --- source/Player.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'source/Player.cpp') diff --git a/source/Player.cpp b/source/Player.cpp index df7e1d539..9ca619cf7 100644 --- a/source/Player.cpp +++ b/source/Player.cpp @@ -127,6 +127,8 @@ cPlayer::~cPlayer(void) bool cPlayer::Initialize(cWorld * a_World) { + ASSERT(a_World != NULL); + if (super::Initialize(a_World)) { // Remove the client handle from the server, it will be ticked from this object from now on @@ -148,6 +150,7 @@ bool cPlayer::Initialize(cWorld * a_World) void cPlayer::Destroyed() { CloseWindow(false); + m_ClientHandle = NULL; } @@ -157,22 +160,17 @@ void cPlayer::Destroyed() void cPlayer::SpawnOn(cClientHandle & a_Client) { - /* - LOGD("cPlayer::SpawnOn(%s) for \"%s\" at pos {%.2f, %.2f, %.2f}", - a_Client.GetUsername().c_str(), m_PlayerName.c_str(), m_Pos.x, m_Pos.y, m_Pos.z - ); - */ - - if (m_bVisible && (m_ClientHandle != (&a_Client))) + if (!m_bVisible || (m_ClientHandle == (&a_Client))) { - a_Client.SendPlayerSpawn(*this); - a_Client.SendEntityHeadLook(*this); - a_Client.SendEntityEquipment(*this, 0, m_Inventory.GetEquippedItem() ); - a_Client.SendEntityEquipment(*this, 1, m_Inventory.GetEquippedBoots() ); - a_Client.SendEntityEquipment(*this, 2, m_Inventory.GetEquippedLeggings() ); - a_Client.SendEntityEquipment(*this, 3, m_Inventory.GetEquippedChestplate() ); - a_Client.SendEntityEquipment(*this, 4, m_Inventory.GetEquippedHelmet() ); + return; } + a_Client.SendPlayerSpawn(*this); + a_Client.SendEntityHeadLook(*this); + a_Client.SendEntityEquipment(*this, 0, m_Inventory.GetEquippedItem() ); + a_Client.SendEntityEquipment(*this, 1, m_Inventory.GetEquippedBoots() ); + a_Client.SendEntityEquipment(*this, 2, m_Inventory.GetEquippedLeggings() ); + a_Client.SendEntityEquipment(*this, 3, m_Inventory.GetEquippedChestplate() ); + a_Client.SendEntityEquipment(*this, 4, m_Inventory.GetEquippedHelmet() ); } @@ -183,12 +181,18 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) { if (m_ClientHandle != NULL) { + if (m_ClientHandle->IsDestroyed()) + { + // This should not happen, because destroying a client will remove it from the world, but just in case + m_ClientHandle = NULL; + return; + } + if (!m_ClientHandle->IsPlaying()) { // We're not yet in the game, ignore everything return; } - m_ClientHandle->Tick(a_Dt); } super::Tick(a_Dt, a_Chunk); -- cgit v1.2.3 From 8c3837987bd5f74563790c15a1d52755383135ae Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 14 Aug 2013 10:24:34 +0200 Subject: Player counts are now properly handled. Fixes #80 --- source/Player.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'source/Player.cpp') diff --git a/source/Player.cpp b/source/Player.cpp index 365a0396f..34980d2f6 100644 --- a/source/Player.cpp +++ b/source/Player.cpp @@ -100,6 +100,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) m_LastJumpHeight = (float)(GetPosY()); m_LastGroundHeight = (float)(GetPosY()); m_Stance = GetPosY() + 1.62; + + cRoot::Get()->GetServer()->PlayerCreated(this); } @@ -1120,20 +1122,15 @@ bool cPlayer::MoveToWorld(const char * a_WorldName) m_ClientHandle->RemoveFromAllChunks(); m_World->RemoveEntity(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 + m_ClientHandle->MoveToWorld(*World, (OldDimension != World->GetDimension())); + // 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 From 17b2353d71c405bc626de22e5467d13be792c317 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 14 Aug 2013 19:11:54 +0200 Subject: Server counts the players correctly. Was missing the PlayerDestroying() call, so players weren't removed from the playercount. --- source/Player.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source/Player.cpp') diff --git a/source/Player.cpp b/source/Player.cpp index 34980d2f6..a1ea631aa 100644 --- a/source/Player.cpp +++ b/source/Player.cpp @@ -112,6 +112,9 @@ cPlayer::~cPlayer(void) { LOGD("Deleting cPlayer \"%s\" at %p, ID %d", m_PlayerName.c_str(), this, GetUniqueID()); + // Notify the server that the player is being destroyed + cRoot::Get()->GetServer()->PlayerDestroying(this); + SaveToDisk(); m_World->RemovePlayer( this ); -- cgit v1.2.3