From 989312c4e7f517ae324e857cb255211e3fd8bb06 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 16 May 2014 22:04:19 +0200 Subject: Add more move checks - Invalid X/Y/Z/Stance check (std::isnan) - Illegal stance - Illegal position (32.000.000 is the world size) --- src/ClientHandle.cpp | 74 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 16 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 0c897374b..41b5d1626 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -582,16 +582,37 @@ void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ, return; } - /* - // TODO: Invalid stance check - if ((a_PosY >= a_Stance) || (a_Stance > a_PosY + 1.65)) + if (m_Player->GetHealth() <= 0) { - LOGD("Invalid stance"); - SendPlayerMoveLook(); + // The player is dead. He can't move :D return; } - */ - + + if (std::isnan(a_PosX) || std::isnan(a_PosY) || std::isnan(a_PosZ) || std::isnan(a_Stance)) + { + LOGWARN("%s was caught trying to crash the server with an invalid position.", m_Player->GetName().c_str()); + Kick("Nope!"); + return; + } + + // Invalid stance check + if (!m_Player->IsInBed()) + { + double Difference = a_Stance - a_PosY; + if ((Difference > 1.65) || (Difference < 1.0)) + { + Kick("Illegal stance!"); + LOGWARN("%s had an illegal stance: %f", m_Player->GetName().c_str(), a_Stance); + return; + } + } + + if ((std::abs(a_PosX) > 32000000.0) || (std::abs(a_PosZ) > 32000000.0)) + { + Kick("Illegal position!"); + return; + } + // If the player has moved too far, "repair" them: Vector3d Pos(a_PosX, a_PosY, a_PosZ); if ((m_Player->GetPosition() - Pos).SqrLength() > 100 * 100) @@ -1388,7 +1409,7 @@ void cClientHandle::HandlePlayerLook(float a_Rotation, float a_Pitch, bool a_IsO -void cClientHandle::HandlePlayerMoveLook(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, float a_Rotation, float a_Pitch, bool a_IsOnGround) +void cClientHandle::HandlePlayerMoveLook(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, float a_Yaw, float a_Pitch, bool a_IsOnGround) { if ((m_Player == NULL) || (m_State != csPlaying)) { @@ -1396,21 +1417,42 @@ void cClientHandle::HandlePlayerMoveLook(double a_PosX, double a_PosY, double a_ return; } - /* - // TODO: Invalid stance check - if ((a_PosY >= a_Stance) || (a_Stance > a_PosY + 1.65)) + if (m_Player->GetHealth() <= 0) { - LOGD("Invalid stance"); - SendPlayerMoveLook(); + // The player is dead. He can't move :D + return; + } + + if (std::isnan(a_PosX) || std::isnan(a_PosY) || std::isnan(a_PosZ) || std::isnan(a_Stance)) + { + LOGWARN("%s was caught trying to crash the server with an invalid position.", m_Player->GetName().c_str()); + Kick("Nope!"); + return; + } + + // Invalid stance check + if (!m_Player->IsInBed()) + { + double Difference = a_Stance - a_PosY; + if ((Difference > 1.65) || (Difference < 1.0)) + { + Kick("Illegal stance!"); + LOGWARN("%s had an illegal stance: %f", m_Player->GetName().c_str(), a_Stance); + return; + } + } + + if ((std::abs(a_PosX) > 32000000.0) || (std::abs(a_PosZ) > 32000000.0)) + { + Kick("Illegal position!"); return; } - */ m_Player->MoveTo(Vector3d(a_PosX, a_PosY, a_PosZ)); m_Player->SetStance (a_Stance); m_Player->SetTouchGround(a_IsOnGround); - m_Player->SetHeadYaw (a_Rotation); - m_Player->SetYaw (a_Rotation); + m_Player->SetHeadYaw (a_Yaw); + m_Player->SetYaw (a_Yaw); m_Player->SetPitch (a_Pitch); } -- cgit v1.2.3 From ee929793f09c431693e1bef7edd77213ba412f60 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 25 May 2014 13:46:34 +0100 Subject: Hopefully fixed piston duplication issues * Fixes #879 * Fixes #714 --- src/ClientHandle.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 83b21ae3c..433b7edf7 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -12,7 +12,6 @@ #include "BlockEntities/SignEntity.h" #include "UI/Window.h" #include "Item.h" -#include "Piston.h" #include "Mobs/Monster.h" #include "ChatColor.h" #include "OSSupport/Socket.h" -- cgit v1.2.3 From 6449b5d11b5a07183812189d5eead0734f9dc191 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 26 May 2014 16:38:14 +0200 Subject: Revert "Add more move checks" This reverts commit 989312c4e7f517ae324e857cb255211e3fd8bb06. --- src/ClientHandle.cpp | 74 ++++++++++++---------------------------------------- 1 file changed, 16 insertions(+), 58 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index e7537d74d..83b21ae3c 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -582,37 +582,16 @@ void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ, return; } - if (m_Player->GetHealth() <= 0) - { - // The player is dead. He can't move :D - return; - } - - if (std::isnan(a_PosX) || std::isnan(a_PosY) || std::isnan(a_PosZ) || std::isnan(a_Stance)) - { - LOGWARN("%s was caught trying to crash the server with an invalid position.", m_Player->GetName().c_str()); - Kick("Nope!"); - return; - } - - // Invalid stance check - if (!m_Player->IsInBed()) - { - double Difference = a_Stance - a_PosY; - if ((Difference > 1.65) || (Difference < 1.0)) - { - Kick("Illegal stance!"); - LOGWARN("%s had an illegal stance: %f", m_Player->GetName().c_str(), a_Stance); - return; - } - } - - if ((std::abs(a_PosX) > 32000000.0) || (std::abs(a_PosZ) > 32000000.0)) + /* + // TODO: Invalid stance check + if ((a_PosY >= a_Stance) || (a_Stance > a_PosY + 1.65)) { - Kick("Illegal position!"); + LOGD("Invalid stance"); + SendPlayerMoveLook(); return; } - + */ + // If the player has moved too far, "repair" them: Vector3d Pos(a_PosX, a_PosY, a_PosZ); if ((m_Player->GetPosition() - Pos).SqrLength() > 100 * 100) @@ -1410,7 +1389,7 @@ void cClientHandle::HandlePlayerLook(float a_Rotation, float a_Pitch, bool a_IsO -void cClientHandle::HandlePlayerMoveLook(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, float a_Yaw, float a_Pitch, bool a_IsOnGround) +void cClientHandle::HandlePlayerMoveLook(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, float a_Rotation, float a_Pitch, bool a_IsOnGround) { if ((m_Player == NULL) || (m_State != csPlaying)) { @@ -1418,42 +1397,21 @@ void cClientHandle::HandlePlayerMoveLook(double a_PosX, double a_PosY, double a_ return; } - if (m_Player->GetHealth() <= 0) - { - // The player is dead. He can't move :D - return; - } - - if (std::isnan(a_PosX) || std::isnan(a_PosY) || std::isnan(a_PosZ) || std::isnan(a_Stance)) - { - LOGWARN("%s was caught trying to crash the server with an invalid position.", m_Player->GetName().c_str()); - Kick("Nope!"); - return; - } - - // Invalid stance check - if (!m_Player->IsInBed()) - { - double Difference = a_Stance - a_PosY; - if ((Difference > 1.65) || (Difference < 1.0)) - { - Kick("Illegal stance!"); - LOGWARN("%s had an illegal stance: %f", m_Player->GetName().c_str(), a_Stance); - return; - } - } - - if ((std::abs(a_PosX) > 32000000.0) || (std::abs(a_PosZ) > 32000000.0)) + /* + // TODO: Invalid stance check + if ((a_PosY >= a_Stance) || (a_Stance > a_PosY + 1.65)) { - Kick("Illegal position!"); + LOGD("Invalid stance"); + SendPlayerMoveLook(); return; } + */ m_Player->MoveTo(Vector3d(a_PosX, a_PosY, a_PosZ)); m_Player->SetStance (a_Stance); m_Player->SetTouchGround(a_IsOnGround); - m_Player->SetHeadYaw (a_Yaw); - m_Player->SetYaw (a_Yaw); + m_Player->SetHeadYaw (a_Rotation); + m_Player->SetYaw (a_Rotation); m_Player->SetPitch (a_Pitch); } -- cgit v1.2.3 From 0a3570bc9daab9fb8772dee48aab1ba6bf4da92a Mon Sep 17 00:00:00 2001 From: archshift Date: Mon, 26 May 2014 14:13:40 -0700 Subject: ClientHandle.cpp: remove redundant code HandlePlayerMoveLook() calls HandlePlayerPos() and HandlePlayerLook() to reduce code redundancy. --- src/ClientHandle.cpp | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 83b21ae3c..4aa42a489 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1391,28 +1391,8 @@ void cClientHandle::HandlePlayerLook(float a_Rotation, float a_Pitch, bool a_IsO void cClientHandle::HandlePlayerMoveLook(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, float a_Rotation, float a_Pitch, bool a_IsOnGround) { - if ((m_Player == NULL) || (m_State != csPlaying)) - { - // The client hasn't been spawned yet and sends nonsense, we know better - return; - } - - /* - // TODO: Invalid stance check - if ((a_PosY >= a_Stance) || (a_Stance > a_PosY + 1.65)) - { - LOGD("Invalid stance"); - SendPlayerMoveLook(); - return; - } - */ - - m_Player->MoveTo(Vector3d(a_PosX, a_PosY, a_PosZ)); - m_Player->SetStance (a_Stance); - m_Player->SetTouchGround(a_IsOnGround); - m_Player->SetHeadYaw (a_Rotation); - m_Player->SetYaw (a_Rotation); - m_Player->SetPitch (a_Pitch); + HandlePlayerPos(a_PosX, a_PosY, a_PosZ, a_Stance, a_IsOnGround); + HandlePlayerLook(a_Rotation, a_Pitch, a_IsOnGround); } -- cgit v1.2.3 From c204735f3840d2199c48b13bd26e9b8d80394b83 Mon Sep 17 00:00:00 2001 From: archshift Date: Tue, 27 May 2014 00:28:46 -0700 Subject: ClientHandle.cpp: Process look before pos --- src/ClientHandle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 4aa42a489..9b03bead9 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1391,8 +1391,8 @@ void cClientHandle::HandlePlayerLook(float a_Rotation, float a_Pitch, bool a_IsO void cClientHandle::HandlePlayerMoveLook(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, float a_Rotation, float a_Pitch, bool a_IsOnGround) { - HandlePlayerPos(a_PosX, a_PosY, a_PosZ, a_Stance, a_IsOnGround); HandlePlayerLook(a_Rotation, a_Pitch, a_IsOnGround); + HandlePlayerPos(a_PosX, a_PosY, a_PosZ, a_Stance, a_IsOnGround); } -- cgit v1.2.3 From ae37dfec8d44f2a4adca0c47bf3e490f85f1ed0b Mon Sep 17 00:00:00 2001 From: worktycho Date: Wed, 4 Jun 2014 11:29:08 +0100 Subject: Fixed bad coordinate --- src/ClientHandle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 080e859d1..d47ceff0e 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1306,7 +1306,7 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e if (!a_ItemHandler.GetPlacementBlockTypeMeta(World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta)) { // Handler refused the placement, send that information back to the client: - World->SendBlockTo(a_BlockX, a_BlockY, a_BlockY, m_Player); + World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player); m_Player->GetInventory().SendEquippedSlot(); return; } -- cgit v1.2.3 From 28b82d5bbb4a0c7df901bea9e9f65a66186379ec Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 8 Jun 2014 11:32:52 +0200 Subject: Proper fix for long interaction. Fixes #1078 and #1038. --- src/ClientHandle.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index d47ceff0e..77f3b274a 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1089,18 +1089,25 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e cWorld * World = m_Player->GetWorld(); if ( - (Diff(m_Player->GetPosX(), (double)a_BlockX) > 6) || - (Diff(m_Player->GetPosY(), (double)a_BlockY) > 6) || - (Diff(m_Player->GetPosZ(), (double)a_BlockZ) > 6) + (a_BlockFace != BLOCK_FACE_NONE) && // The client is interacting with a specific block + ( + (Diff(m_Player->GetPosX(), (double)a_BlockX) > 6) || // The block is too far away + (Diff(m_Player->GetPosY(), (double)a_BlockY) > 6) || + (Diff(m_Player->GetPosZ(), (double)a_BlockZ) > 6) + ) ) { - if (a_BlockFace != BLOCK_FACE_NONE) + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); + World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player); + if (a_BlockY < cChunkDef::Height - 1) { - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); - World->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player); World->SendBlockTo(a_BlockX, a_BlockY + 1, a_BlockZ, m_Player); // 2 block high things - m_Player->GetInventory().SendEquippedSlot(); } + if (a_BlockY > 0) + { + World->SendBlockTo(a_BlockX, a_BlockY - 1, a_BlockZ, m_Player); // 2 block high things + } + m_Player->GetInventory().SendEquippedSlot(); return; } -- cgit v1.2.3 From af4a21ea0689107b377818574cb07dc4a2e8b755 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 8 Jun 2014 21:58:08 +0200 Subject: Fixed deadlock when moving players to other worlds. Fixes #1039, fixes #851 --- src/ClientHandle.cpp | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 77f3b274a..e4bb9d8e9 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -327,7 +327,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID) // Send experience m_Player->SendExperience(); - m_Player->Initialize(World); + m_Player->Initialize(*World); m_State = csAuthenticated; // Query player team @@ -356,7 +356,7 @@ void cClientHandle::StreamChunks(void) } ASSERT(m_Player != NULL); - + int ChunkPosX = FAST_FLOOR_DIV((int)m_Player->GetPosX(), cChunkDef::Width); int ChunkPosZ = FAST_FLOOR_DIV((int)m_Player->GetPosZ(), cChunkDef::Width); if ((ChunkPosX == m_LastStreamedChunkX) && (ChunkPosZ == m_LastStreamedChunkZ)) @@ -1753,18 +1753,8 @@ void cClientHandle::SendData(const char * a_Data, size_t a_Size) -void cClientHandle::MoveToWorld(cWorld & a_World, bool a_SendRespawnPacket) +void cClientHandle::RemoveFromWorld(void) { - UNUSED(a_World); - ASSERT(m_Player != NULL); - - if (a_SendRespawnPacket) - { - SendRespawn(); - } - - cWorld * World = m_Player->GetWorld(); - // Remove all associated chunks: cChunkCoordsList Chunks; { @@ -1774,7 +1764,6 @@ void cClientHandle::MoveToWorld(cWorld & a_World, bool a_SendRespawnPacket) } for (cChunkCoordsList::iterator itr = Chunks.begin(), end = Chunks.end(); itr != end; ++itr) { - World->RemoveChunkClient(itr->m_ChunkX, itr->m_ChunkZ, this); m_Protocol->SendUnloadChunk(itr->m_ChunkX, itr->m_ChunkZ); } // for itr - Chunks[] @@ -2379,9 +2368,9 @@ void cClientHandle::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Effec -void cClientHandle::SendRespawn(void) +void cClientHandle::SendRespawn(const cWorld & a_World) { - m_Protocol->SendRespawn(); + m_Protocol->SendRespawn(a_World); } -- cgit v1.2.3