From 654c34705c1745f2bf5eb6b6266b8cd0df05caea Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 20 Aug 2013 21:13:28 +0200 Subject: Fixed player spawning. Now the player is spawned only after the chunk they're in is sent to the client. Hopefully no more falling-through-terrain-while-loggin-in. --- source/ClientHandle.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source/ClientHandle.cpp') diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index 57830f63c..319640eea 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -1522,6 +1522,16 @@ void cClientHandle::SendChat(const AString & a_Message) void cClientHandle::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) { + ASSERT(m_Player != NULL); + + if ((m_State == csAuthenticated) || (m_State == csDownloadingWorld)) + { + if ((a_ChunkX == m_Player->GetChunkX()) && (a_ChunkZ == m_Player->GetChunkZ())) + { + m_Protocol->SendPlayerMoveLook(); + } + } + // Check chunks being sent, erase them from m_ChunksToSend: bool Found = false; { -- cgit v1.2.3 From 69dc9b4c9aea58ebd95e2dbd0205701dfc4ce54e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 20 Aug 2013 22:27:29 +0200 Subject: Added a delay between the kick packet and socket close. This should have helped #31, but the client disagrees. --- source/ClientHandle.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'source/ClientHandle.cpp') diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index 319640eea..dda6a6ed2 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -51,6 +51,9 @@ static const int MAX_EXPLOSIONS_PER_TICK = 100; /// How many explosions in the recent history are allowed static const int MAX_RUNNING_SUM_EXPLOSIONS = cClientHandle::NUM_CHECK_EXPLOSIONS_TICKS * MAX_EXPLOSIONS_PER_TICK / 8; +/// How many ticks before the socket is closed after the client is destroyed (#31) +static const int TICKS_BEFORE_CLOSE = 20; + @@ -84,6 +87,7 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) , m_bKeepThreadGoing(true) , m_Ping(1000) , m_PingID(1) + , m_TicksSinceDestruction(0) , m_State(csConnected) , m_LastStreamedChunkX(0x7fffffff) // bogus chunk coords to force streaming upon login , m_LastStreamedChunkZ(0x7fffffff) @@ -111,7 +115,7 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) cClientHandle::~cClientHandle() { - ASSERT(m_State == csDestroyed); // Has Destroy() been called? + ASSERT(m_State >= csDestroyedWaiting); // Has Destroy() been called? LOGD("Deleting client \"%s\" at %p", GetUsername().c_str(), this); @@ -189,7 +193,7 @@ void cClientHandle::Destroy(void) RemoveFromAllChunks(); m_Player->GetWorld()->RemoveClientFromChunkSender(this); } - m_State = csDestroyed; + m_State = csDestroyedWaiting; } @@ -1397,6 +1401,17 @@ bool cClientHandle::CheckBlockInteractionsRate(void) void cClientHandle::Tick(float a_Dt) { + // Handle clients that are waiting for final close while destroyed: + if (m_State == csDestroyedWaiting) + { + m_TicksSinceDestruction += 1; // This field is misused for the timeout counting + if (m_TicksSinceDestruction > TICKS_BEFORE_CLOSE) + { + m_State = csDestroyed; + } + return; + } + // Process received network data: AString IncomingData; { -- cgit v1.2.3 From 16e3242456249508c16a025fa4fc95d1a73a4e7f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 22 Aug 2013 08:17:26 +0200 Subject: Another fix for #31. This seems to have done it, no more crashes for me. --- source/ClientHandle.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source/ClientHandle.cpp') diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index dda6a6ed2..ed76ee086 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -1287,6 +1287,12 @@ void cClientHandle::HandleTabCompletion(const AString & a_Text) void cClientHandle::SendData(const char * a_Data, int a_Size) { + if (m_HasSentDC) + { + // This could crash the client, because they've already unloaded the world etc., and suddenly a wild packet appears (#31) + return; + } + { cCSLock Lock(m_CSOutgoingData); -- cgit v1.2.3 From 259f08aac88c5e5ac49e5ec06f13c8b4759766c3 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 24 Aug 2013 21:25:36 +0200 Subject: Client can no longer place blocks outside the Y range of the world. Fixes #128. --- source/ClientHandle.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source/ClientHandle.cpp') diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index ed76ee086..8125fc127 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -871,7 +871,12 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, c return; } - + if ((a_BlockY < 0) || (a_BlockY >= cChunkDef::Height)) + { + // The block is being placed outside the world, ignore this packet altogether (#128) + return; + } + BLOCKTYPE PlaceBlock = World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); if (!BlockHandler(PlaceBlock)->DoesIgnoreBuildCollision()) { -- cgit v1.2.3 From 17ad4c2610f2c33d5b4a8b42b7d4b8fbda9ade32 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 30 Aug 2013 14:24:03 +0200 Subject: Shooting a bow kinda works. The arrow is released, but sometimes hits wrong blocks or disappears completely. --- source/ClientHandle.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/ClientHandle.cpp') diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index bed9fab92..555ecb952 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -576,8 +576,8 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, ch // A plugin doesn't agree with the action. The plugin itself is responsible for handling the consequences (possible inventory mismatch) return; } + ItemHandler->OnItemShoot(m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); } - LOGINFO("%s: Status SHOOT not implemented", __FUNCTION__); return; } @@ -790,16 +790,16 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, c BLOCKTYPE BlockType; NIBBLETYPE BlockMeta; World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta); - cBlockHandler * Handler = cBlockHandler::GetBlockHandler(BlockType); + cBlockHandler * BlockHandler = cBlockHandler::GetBlockHandler(BlockType); - if (Handler->IsUseable() && !m_Player->IsCrouched()) + if (BlockHandler->IsUseable() && !m_Player->IsCrouched()) { if (PlgMgr->CallHookPlayerUsingBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta)) { // A plugin doesn't agree with using the block, abort return; } - Handler->OnUse(World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ); + BlockHandler->OnUse(World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ); PlgMgr->CallHookPlayerUsedBlock(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta); return; } -- cgit v1.2.3