From 72c087cfd335b015139cb73ae78f74105d855cf0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 27 Sep 2014 14:28:14 +0100 Subject: Dropped support for <1.7.x --- src/ClientHandle.cpp | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 878d309c9..9858aa991 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1741,20 +1741,6 @@ void cClientHandle::HandleRespawn(void) -void cClientHandle::HandleDisconnect(const AString & a_Reason) -{ - LOGD("Received d/c packet from %s with reason \"%s\"", m_Username.c_str(), a_Reason.c_str()); - - cRoot::Get()->GetPluginManager()->CallHookDisconnect(*this, a_Reason); - - m_HasSentDC = true; - Destroy(); -} - - - - - void cClientHandle::HandleKeepAlive(int a_KeepAliveID) { if (a_KeepAliveID == m_PingID) -- cgit v1.2.3 From fc22ba0ce89b12b13bca00f5005f96528d1c91ae Mon Sep 17 00:00:00 2001 From: Masy98 Date: Sat, 27 Sep 2014 21:07:52 +0200 Subject: Added barriers correctly --- src/ClientHandle.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 878d309c9..52ea59884 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1153,6 +1153,11 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo Kick("You can't break a bedrock!"); return; } + if (!m_Player->IsGameModeCreative() && (a_OldBlock == E_BLOCK_BARRIER)) + { + Kick("You can't break a barrier!"); + return; + } cWorld * World = m_Player->GetWorld(); cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem()); -- cgit v1.2.3 From 79110b29dbdfafae13ae4448b1672b129ebf7128 Mon Sep 17 00:00:00 2001 From: Masy98 Date: Sat, 27 Sep 2014 21:49:03 +0200 Subject: Combined conditions --- src/ClientHandle.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 52ea59884..3bd48eb3d 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1148,15 +1148,18 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo FinishDigAnimation(); - if (!m_Player->IsGameModeCreative() && (a_OldBlock == E_BLOCK_BEDROCK)) - { - Kick("You can't break a bedrock!"); - return; - } - if (!m_Player->IsGameModeCreative() && (a_OldBlock == E_BLOCK_BARRIER)) + if (!m_Player->IsGameModeCreative()) { - Kick("You can't break a barrier!"); - return; + if (a_OldBlock == E_BLOCK_BEDROCK) + { + Kick("You can't break a bedrock!"); + return; + } + if (a_OldBlock == E_BLOCK_BARRIER) + { + Kick("You can't break a barrier!"); + return; + } } cWorld * World = m_Player->GetWorld(); -- cgit v1.2.3 From 5a44be13b7facbc3718b8cbc4eb76bbd50de085e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 28 Sep 2014 22:17:29 +0200 Subject: Fixed trailing whitespace. --- 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 bd00c0b9e..20e219309 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1153,7 +1153,7 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo if (a_OldBlock == E_BLOCK_BEDROCK) { Kick("You can't break a bedrock!"); - return; + return; } if (a_OldBlock == E_BLOCK_BARRIER) { -- cgit v1.2.3 From d7066f43d3fd592457e69a46f0fed098c80b3190 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 30 Sep 2014 13:33:57 +0200 Subject: Rewritten plugin messages, vanilla are being parsed directly. This should finally fix the compatibility problems between 1.7 and 1.8 protocols with the changes in the vanilla plugin messages. --- src/ClientHandle.cpp | 120 +++++++++++++-------------------------------------- 1 file changed, 30 insertions(+), 90 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 20e219309..a29bef0c0 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -551,6 +551,16 @@ void cClientHandle::RemoveFromAllChunks() +void cClientHandle::HandleNPCTrade(int a_SlotNum) +{ + // TODO + LOGWARNING("%s: Not implemented yet", __FUNCTION__); +} + + + + + void cClientHandle::HandlePing(void) { // Somebody tries to retrieve information about the server @@ -573,7 +583,6 @@ void cClientHandle::HandlePing(void) bool cClientHandle::HandleLogin(int a_ProtocolVersion, const AString & a_Username) { - LOGD("LOGIN %s", a_Username.c_str()); m_Username = a_Username; if (cRoot::Get()->GetPluginManager()->CallHookLogin(this, a_ProtocolVersion, a_Username)) @@ -676,25 +685,7 @@ void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ, void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString & a_Message) { - if (a_Channel == "MC|AdvCdm") - { - // Command block, set text, Client -> Server - HandleCommandBlockMessage(a_Message.c_str(), a_Message.size()); - } - else if (a_Channel == "MC|Brand") - { - // Client <-> Server branding exchange - SendPluginMessage("MC|Brand", "MCServer"); - } - else if (a_Channel == "MC|Beacon") - { - HandleBeaconSelection(a_Message.c_str(), a_Message.size()); - } - else if (a_Channel == "MC|ItemName") - { - HandleAnvilItemName(a_Message.c_str(), a_Message.size()); - } - else if (a_Channel == "REGISTER") + if (a_Channel == "REGISTER") { if (HasPluginChannel(a_Channel)) { @@ -777,15 +768,8 @@ void cClientHandle::UnregisterPluginChannels(const AStringVector & a_ChannelList -void cClientHandle::HandleBeaconSelection(const char * a_Data, size_t a_Length) +void cClientHandle::HandleBeaconSelection(int a_PrimaryEffect, int a_SecondaryEffect) { - if (a_Length < 14) - { - SendChat("Failure setting beacon selection; bad request", mtFailure); - LOGD("Malformed MC|Beacon packet."); - return; - } - cWindow * Window = m_Player->GetWindow(); if ((Window == NULL) || (Window->GetWindowType() != cWindow::wtBeacon)) { @@ -798,23 +782,15 @@ void cClientHandle::HandleBeaconSelection(const char * a_Data, size_t a_Length) return; } - cByteBuffer Buffer(a_Length); - Buffer.Write(a_Data, a_Length); - - int PrimaryEffectID, SecondaryEffectID; - Buffer.ReadBEInt(PrimaryEffectID); - Buffer.ReadBEInt(SecondaryEffectID); - cEntityEffect::eType PrimaryEffect = cEntityEffect::effNoEffect; - if ((PrimaryEffectID >= 0) && (PrimaryEffectID <= (int)cEntityEffect::effSaturation)) + if ((a_PrimaryEffect >= 0) && (a_PrimaryEffect <= (int)cEntityEffect::effSaturation)) { - PrimaryEffect = (cEntityEffect::eType)PrimaryEffectID; + PrimaryEffect = (cEntityEffect::eType)a_PrimaryEffect; } - cEntityEffect::eType SecondaryEffect = cEntityEffect::effNoEffect; - if ((SecondaryEffectID >= 0) && (SecondaryEffectID <= (int)cEntityEffect::effSaturation)) + if ((a_SecondaryEffect >= 0) && (a_SecondaryEffect <= (int)cEntityEffect::effSaturation)) { - SecondaryEffect = (cEntityEffect::eType)SecondaryEffectID; + SecondaryEffect = (cEntityEffect::eType)a_SecondaryEffect; } Window->SetSlot(*m_Player, 0, cItem()); @@ -841,52 +817,12 @@ void cClientHandle::HandleBeaconSelection(const char * a_Data, size_t a_Length) -void cClientHandle::HandleCommandBlockMessage(const char * a_Data, size_t a_Length) +void cClientHandle::HandleCommandBlockBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_NewCommand) { - if (a_Length < 14) - { - SendChat("Failure setting command block command; bad request", mtFailure); - LOGD("Malformed MC|AdvCdm packet."); - return; - } - - cByteBuffer Buffer(a_Length); - Buffer.Write(a_Data, a_Length); - - int BlockX, BlockY, BlockZ; - - AString Command; - - char Mode; - - Buffer.ReadChar(Mode); - - switch (Mode) - { - case 0x00: - { - Buffer.ReadBEInt(BlockX); - Buffer.ReadBEInt(BlockY); - Buffer.ReadBEInt(BlockZ); - - Buffer.ReadVarUTF8String(Command); - break; - } - - default: - { - SendChat("Failure setting command block command; unhandled mode", mtFailure); - LOGD("Unhandled MC|AdvCdm packet mode."); - return; - } - } - cWorld * World = m_Player->GetWorld(); - if (World->AreCommandBlocksEnabled()) { - World->SetCommandBlockCommand(BlockX, BlockY, BlockZ, Command); - + World->SetCommandBlockCommand(a_BlockX, a_BlockY, a_BlockZ, a_NewCommand); SendChat("Successfully set command block command", mtSuccess); } else @@ -899,22 +835,26 @@ void cClientHandle::HandleCommandBlockMessage(const char * a_Data, size_t a_Leng -void cClientHandle::HandleAnvilItemName(const char * a_Data, size_t a_Length) +void cClientHandle::HandleCommandBlockEntityChange(int a_EntityID, const AString & a_NewCommand) { - if (a_Length < 1) - { - return; - } + // TODO + LOGWARNING("%s: Not implemented yet", __FUNCTION__); +} + + + + +void cClientHandle::HandleAnvilItemName(const AString & a_ItemName) +{ if ((m_Player->GetWindow() == NULL) || (m_Player->GetWindow()->GetWindowType() != cWindow::wtAnvil)) { return; } - AString Name(a_Data, a_Length); - if (Name.length() <= 30) + if (a_ItemName.length() <= 30) { - ((cAnvilWindow *)m_Player->GetWindow())->SetRepairedItemName(Name, m_Player); + ((cAnvilWindow *)m_Player->GetWindow())->SetRepairedItemName(a_ItemName, m_Player); } } -- cgit v1.2.3 From 382e014ebcd44a72788bea8cdcec7f64861b063f Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 2 Oct 2014 23:50:41 +0200 Subject: Optimized chunk loader --- src/ClientHandle.cpp | 163 ++++++++++++++++++++++++--------------------------- 1 file changed, 77 insertions(+), 86 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index a29bef0c0..27d41da1b 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -70,8 +70,6 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) : m_OutgoingData(64 KiB), m_Player(NULL), m_HasSentDC(false), - m_LastStreamedChunkX(0x7fffffff), // bogus chunk coords to force streaming upon login - m_LastStreamedChunkZ(0x7fffffff), m_TimeSinceLastPacket(0), m_Ping(1000), m_PingID(1), @@ -401,53 +399,84 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, -void cClientHandle::StreamChunks(void) +void cClientHandle::StreamNextChunk(void) { if ((m_State < csAuthenticated) || (m_State >= csDestroying)) { return; } - ASSERT(m_Player != NULL); + Vector3d LookVector = m_Player->GetLookVector(); + LookVector.Normalize(); - 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)) + Vector3d Position = m_Player->GetEyePosition(); + for (size_t Range = 0; Range < (size_t)m_ViewDistance; Range++) { - // Already streamed for this position - return; + Vector3d Vector = Position + LookVector * cChunkDef::Width * Range; + + int RangeX, RangeZ = 0; + cChunkDef::BlockToChunk((int)std::floor(Vector.x), (int)std::floor(Vector.z), RangeX, RangeZ); + + for (size_t X = 0; X < 6; X++) + { + for (size_t Z = 0; Z < 6; Z++) + { + int ChunkX = RangeX + ((X >= 3) ? (2 - X) : X); + int ChunkZ = RangeZ + ((Z >= 3) ? (2 - Z) : Z); + cChunkCoords Coords(ChunkX, ChunkZ); + + // If the chunk already loading/loaded -> skip + { + cCSLock Lock(m_CSChunkLists); + if ( + (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), Coords) != m_ChunksToSend.end()) || + (std::find(m_LoadedChunks.begin(), m_LoadedChunks.end(), Coords) != m_LoadedChunks.end()) + ) + { + continue; + } + } + + // Unloaded chunk found -> Send it to the client. + StreamChunk(ChunkX, ChunkZ); + return; + } + } } - m_LastStreamedChunkX = ChunkPosX; - m_LastStreamedChunkZ = ChunkPosZ; - - LOGD("Streaming chunks centered on [%d, %d], view distance %d", ChunkPosX, ChunkPosZ, m_ViewDistance); - - cWorld * World = m_Player->GetWorld(); - ASSERT(World != NULL); +} + + - // Remove all loaded chunks that are no longer in range; deferred to out-of-CS: - cChunkCoordsList RemoveChunks; + + +void cClientHandle::UnloadOutOfRangeChunks(void) +{ + int ChunkPosX = FAST_FLOOR_DIV((int)m_Player->GetPosX(), cChunkDef::Width); + int ChunkPosZ = FAST_FLOOR_DIV((int)m_Player->GetPosZ(), cChunkDef::Width); + + cChunkCoordsList ChunksToRemove; { cCSLock Lock(m_CSChunkLists); for (cChunkCoordsList::iterator itr = m_LoadedChunks.begin(); itr != m_LoadedChunks.end();) { - int RelX = (*itr).m_ChunkX - ChunkPosX; - int RelZ = (*itr).m_ChunkZ - ChunkPosZ; - if ((RelX > m_ViewDistance) || (RelX < -m_ViewDistance) || (RelZ > m_ViewDistance) || (RelZ < -m_ViewDistance)) + int DiffX = Diff((*itr).m_ChunkX, ChunkPosX); + int DiffZ = Diff((*itr).m_ChunkZ, ChunkPosZ); + if ((DiffX > m_ViewDistance) || (DiffZ > m_ViewDistance)) { - RemoveChunks.push_back(*itr); + ChunksToRemove.push_back(*itr); itr = m_LoadedChunks.erase(itr); } else { ++itr; } - } // for itr - m_LoadedChunks[] + } + for (cChunkCoordsList::iterator itr = m_ChunksToSend.begin(); itr != m_ChunksToSend.end();) { - int RelX = (*itr).m_ChunkX - ChunkPosX; - int RelZ = (*itr).m_ChunkZ - ChunkPosZ; - if ((RelX > m_ViewDistance) || (RelX < -m_ViewDistance) || (RelZ > m_ViewDistance) || (RelZ < -m_ViewDistance)) + int DiffX = Diff((*itr).m_ChunkX, ChunkPosX); + int DiffZ = Diff((*itr).m_ChunkZ, ChunkPosZ); + if ((DiffX > m_ViewDistance) || (DiffZ > m_ViewDistance)) { itr = m_ChunksToSend.erase(itr); } @@ -455,51 +484,20 @@ void cClientHandle::StreamChunks(void) { ++itr; } - } // for itr - m_ChunksToSend[] + } } - for (cChunkCoordsList::iterator itr = RemoveChunks.begin(); itr != RemoveChunks.end(); ++itr) + + for (cChunkCoordsList::iterator itr = ChunksToRemove.begin(); itr != ChunksToRemove.end(); ++itr) { - World->RemoveChunkClient(itr->m_ChunkX, itr->m_ChunkZ, this); + m_Player->GetWorld()->RemoveChunkClient(itr->m_ChunkX, itr->m_ChunkZ, this); m_Protocol->SendUnloadChunk(itr->m_ChunkX, itr->m_ChunkZ); - } // for itr - RemoveChunks[] - - // Add all chunks that are in range and not yet in m_LoadedChunks: - // Queue these smartly - from the center out to the edge - for (int d = 0; d <= m_ViewDistance; ++d) // cycle through (square) distance, from nearest to furthest - { - // For each distance add chunks in a hollow square centered around current position: - for (int i = -d; i <= d; ++i) - { - StreamChunk(ChunkPosX + d, ChunkPosZ + i); - StreamChunk(ChunkPosX - d, ChunkPosZ + i); - } // for i - for (int i = -d + 1; i < d; ++i) - { - StreamChunk(ChunkPosX + i, ChunkPosZ + d); - StreamChunk(ChunkPosX + i, ChunkPosZ - d); - } // for i - } // for d - - // Touch chunks GENERATEDISTANCE ahead to let them generate: - for (int d = m_ViewDistance + 1; d <= m_ViewDistance + GENERATEDISTANCE; ++d) // cycle through (square) distance, from nearest to furthest - { - // For each distance touch chunks in a hollow square centered around current position: - for (int i = -d; i <= d; ++i) - { - World->TouchChunk(ChunkPosX + d, ChunkPosZ + i); - World->TouchChunk(ChunkPosX - d, ChunkPosZ + i); - } // for i - for (int i = -d + 1; i < d; ++i) - { - World->TouchChunk(ChunkPosX + i, ChunkPosZ + d); - World->TouchChunk(ChunkPosX + i, ChunkPosZ - d); - } // for i - } // for d + } } + void cClientHandle::StreamChunk(int a_ChunkX, int a_ChunkZ) { if (m_State >= csDestroying) @@ -539,11 +537,6 @@ void cClientHandle::RemoveFromAllChunks() cCSLock Lock(m_CSChunkLists); m_LoadedChunks.clear(); m_ChunksToSend.clear(); - - // Also reset the LastStreamedChunk coords to bogus coords, - // so that all chunks are streamed in subsequent StreamChunks() call (FS #407) - m_LastStreamedChunkX = 0x7fffffff; - m_LastStreamedChunkZ = 0x7fffffff; } } @@ -1858,10 +1851,7 @@ void cClientHandle::RemoveFromWorld(void) { m_Protocol->SendUnloadChunk(itr->m_ChunkX, itr->m_ChunkZ); } // for itr - Chunks[] - - // Here, we set last streamed values to bogus ones so everything is resent - m_LastStreamedChunkX = 0x7fffffff; - m_LastStreamedChunkZ = 0x7fffffff; + m_HasSentPlayerChunk = false; } @@ -1907,7 +1897,7 @@ void cClientHandle::Tick(float a_Dt) { return; } - + // If the chunk the player's in was just sent, spawn the player: if (m_HasSentPlayerChunk && (m_State == csDownloadingWorld)) { @@ -1928,6 +1918,17 @@ void cClientHandle::Tick(float a_Dt) } } + if ((m_State >= csAuthenticated) && (m_State < csDestroying)) + { + StreamNextChunk(); // Streams the next chunk + + // Unload all chunks that are out of the view distance (all 2 seconds) + if ((m_Player->GetWorld()->GetWorldAge() % 40) == 0) + { + UnloadOutOfRangeChunks(); + } + } + // Handle block break animation: if (m_BlockDigAnimStage > -1) { @@ -1964,7 +1965,7 @@ void cClientHandle::ServerTick(float a_Dt) if (m_State == csAuthenticated) { - StreamChunks(); + StreamNextChunk(); // Remove the client handle from the server, it will be ticked from its cPlayer object from now on cRoot::Get()->GetServer()->ClientMovedToWorld(this); @@ -2723,18 +2724,8 @@ void cClientHandle::SetUsername( const AString & a_Username) void cClientHandle::SetViewDistance(int a_ViewDistance) { - if (a_ViewDistance < MIN_VIEW_DISTANCE) - { - a_ViewDistance = MIN_VIEW_DISTANCE; - } - if (a_ViewDistance > MAX_VIEW_DISTANCE) - { - a_ViewDistance = MAX_VIEW_DISTANCE; - } - m_ViewDistance = a_ViewDistance; - - // Need to re-stream chunks for the change to become apparent: - StreamChunks(); + m_ViewDistance = Clamp(a_ViewDistance, MIN_VIEW_DISTANCE, MAX_VIEW_DISTANCE); + LOGD("Setted %s's view distance to %i", GetUsername().c_str(), m_ViewDistance); } -- cgit v1.2.3 From b5a2c6667ac0845d17a709cc436afb570079a9a7 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 3 Oct 2014 21:32:41 +0100 Subject: Improved furnaces * Fixed progress bar on 1.8 * Fixed bugs * Improved code * Fixes #1068 * Fixes #1070 --- 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 a29bef0c0..359255a3e 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2694,7 +2694,7 @@ void cClientHandle::SendWindowOpen(const cWindow & a_Window) -void cClientHandle::SendWindowProperty(const cWindow & a_Window, int a_Property, int a_Value) +void cClientHandle::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value) { m_Protocol->SendWindowProperty(a_Window, a_Property, a_Value); } -- cgit v1.2.3 From a8aeceab9d6e5e5e36ef7bd58783b65aca4d8be7 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 5 Oct 2014 20:19:21 +0200 Subject: cClientHandle: Added protocol version knowledge. --- src/ClientHandle.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index a29bef0c0..3b677460b 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -92,7 +92,8 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) : m_NumBlockChangeInteractionsThisTick(0), m_UniqueID(0), m_HasSentPlayerChunk(false), - m_Locale("en_GB") + m_Locale("en_GB"), + m_ProtocolVersion(0) { m_Protocol = new cProtocolRecognizer(this); @@ -583,15 +584,22 @@ void cClientHandle::HandlePing(void) bool cClientHandle::HandleLogin(int a_ProtocolVersion, const AString & a_Username) { + // If the protocol version hasn't been set yet, set it now: + if (m_ProtocolVersion == 0) + { + m_ProtocolVersion = a_ProtocolVersion; + } + m_Username = a_Username; + // Let the plugins know about this event, they may refuse the player: if (cRoot::Get()->GetPluginManager()->CallHookLogin(this, a_ProtocolVersion, a_Username)) { Destroy(); return false; } - // Schedule for authentication; until then, let them wait (but do not block) + // Schedule for authentication; until then, let the player wait (but do not block) m_State = csAuthenticating; cRoot::Get()->GetAuthenticator().Authenticate(GetUniqueID(), GetUsername(), m_Protocol->GetAuthServerID()); return true; -- cgit v1.2.3 From 5a6b86180e0144a5671c747b838d14992c21afae Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 6 Oct 2014 17:38:17 +0200 Subject: Better StreamNextChunk() method --- src/ClientHandle.cpp | 131 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 116 insertions(+), 15 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 27d41da1b..3c73296a4 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -70,6 +70,8 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) : m_OutgoingData(64 KiB), m_Player(NULL), m_HasSentDC(false), + m_LastStreamedChunkX(0x7fffffff), // bogus chunk coords to force streaming upon login + m_LastStreamedChunkZ(0x7fffffff), m_TimeSinceLastPacket(0), m_Ping(1000), m_PingID(1), @@ -405,44 +407,133 @@ void cClientHandle::StreamNextChunk(void) { return; } + ASSERT(m_Player != NULL); + int ChunkPosX = m_Player->GetChunkX(); + int ChunkPosZ = m_Player->GetChunkZ(); + if ((m_LastStreamedChunkX == ChunkPosX) && (m_LastStreamedChunkZ == ChunkPosZ)) + { + // All chunks are already loaded. Abort loading. + return; + } + + // Get the look vector and normalize it. + Vector3d Position = m_Player->GetEyePosition(); Vector3d LookVector = m_Player->GetLookVector(); LookVector.Normalize(); - Vector3d Position = m_Player->GetEyePosition(); + // Lock the list + cCSLock Lock(m_CSChunkLists); + + // High priority: Load the chunks that are in the view-direction of the player (with a radius of 3) for (size_t Range = 0; Range < (size_t)m_ViewDistance; Range++) { Vector3d Vector = Position + LookVector * cChunkDef::Width * Range; + // Get the chunk from the x/z coords. int RangeX, RangeZ = 0; cChunkDef::BlockToChunk((int)std::floor(Vector.x), (int)std::floor(Vector.z), RangeX, RangeZ); - for (size_t X = 0; X < 6; X++) + for (size_t X = 0; X < 7; X++) { - for (size_t Z = 0; Z < 6; Z++) + for (size_t Z = 0; Z < 7; Z++) { - int ChunkX = RangeX + ((X >= 3) ? (2 - X) : X); - int ChunkZ = RangeZ + ((Z >= 3) ? (2 - Z) : Z); + int ChunkX = RangeX + ((X >= 4) ? (3 - X) : X); + int ChunkZ = RangeZ + ((Z >= 4) ? (3 - Z) : Z); cChunkCoords Coords(ChunkX, ChunkZ); // If the chunk already loading/loaded -> skip + if ( + (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), Coords) != m_ChunksToSend.end()) || + (std::find(m_LoadedChunks.begin(), m_LoadedChunks.end(), Coords) != m_LoadedChunks.end()) + ) { - cCSLock Lock(m_CSChunkLists); - if ( - (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), Coords) != m_ChunksToSend.end()) || - (std::find(m_LoadedChunks.begin(), m_LoadedChunks.end(), Coords) != m_LoadedChunks.end()) - ) - { - continue; - } + continue; } // Unloaded chunk found -> Send it to the client. + Lock.Unlock(); StreamChunk(ChunkX, ChunkZ); return; } } } + + // Medium priority: Load the chunks that are behind the player + LookVector = m_Player->GetLookVector() * -1; + for (size_t Range = 0; Range < 3; Range++) + { + Vector3d Vector = Position + LookVector * cChunkDef::Width * Range; + + // Get the chunk from the x/z coords. + int RangeX, RangeZ = 0; + cChunkDef::BlockToChunk((int)std::floor(Vector.x), (int)std::floor(Vector.z), RangeX, RangeZ); + + for (size_t X = 0; X < 7; X++) + { + for (size_t Z = 0; Z < 7; Z++) + { + int ChunkX = RangeX + ((X >= 4) ? (3 - X) : X); + int ChunkZ = RangeZ + ((Z >= 4) ? (3 - Z) : Z); + cChunkCoords Coords(ChunkX, ChunkZ); + + // If the chunk already loading/loaded -> skip + if ( + (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), Coords) != m_ChunksToSend.end()) || + (std::find(m_LoadedChunks.begin(), m_LoadedChunks.end(), Coords) != m_LoadedChunks.end()) + ) + { + continue; + } + + // Unloaded chunk found -> Send it to the client. + Lock.Unlock(); + StreamChunk(ChunkX, ChunkZ); + return; + } + } + } + + // Low priority: Add all chunks that are in range. (From the center out to the edge) + for (int d = 0; d <= m_ViewDistance; ++d) // cycle through (square) distance, from nearest to furthest + { + // For each distance add chunks in a hollow square centered around current position: + cChunkCoordsList CurcleChunks; + for (int i = -d; i <= d; ++i) + { + CurcleChunks.push_back(cChunkCoords(ChunkPosX + d, ChunkPosZ + i)); + CurcleChunks.push_back(cChunkCoords(ChunkPosX - d, ChunkPosZ + i)); + } + for (int i = -d + 1; i < d; ++i) + { + CurcleChunks.push_back(cChunkCoords(ChunkPosX + i, ChunkPosZ + d)); + CurcleChunks.push_back(cChunkCoords(ChunkPosX + i, ChunkPosZ - d)); + } + + // For each the CurcleChunks list and send the first unloaded chunk: + for (cChunkCoordsList::iterator itr = CurcleChunks.begin(), end = CurcleChunks.end(); itr != end; ++itr) + { + cChunkCoords Coords = *itr; + + // If the chunk already loading/loaded -> skip + if ( + (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), Coords) != m_ChunksToSend.end()) || + (std::find(m_LoadedChunks.begin(), m_LoadedChunks.end(), Coords) != m_LoadedChunks.end()) + ) + { + continue; + } + + // Unloaded chunk found -> Send it to the client. + Lock.Unlock(); + StreamChunk(Coords.m_ChunkX, Coords.m_ChunkZ); + return; + } + } + + // All chunks are loaded -> Sets the last loaded chunk coordinates to current coordinates + m_LastStreamedChunkX = ChunkPosX; + m_LastStreamedChunkZ = ChunkPosZ; } @@ -537,6 +628,11 @@ void cClientHandle::RemoveFromAllChunks() cCSLock Lock(m_CSChunkLists); m_LoadedChunks.clear(); m_ChunksToSend.clear(); + + // Also reset the LastStreamedChunk coords to bogus coords, + // so that all chunks are streamed in subsequent StreamChunks() call (FS #407) + m_LastStreamedChunkX = 0x7fffffff; + m_LastStreamedChunkZ = 0x7fffffff; } } @@ -1852,6 +1948,10 @@ void cClientHandle::RemoveFromWorld(void) m_Protocol->SendUnloadChunk(itr->m_ChunkX, itr->m_ChunkZ); } // for itr - Chunks[] + // Here, we set last streamed values to bogus ones so everything is resent + m_LastStreamedChunkX = 0x7fffffff; + m_LastStreamedChunkZ = 0x7fffffff; + m_HasSentPlayerChunk = false; } @@ -1920,10 +2020,11 @@ void cClientHandle::Tick(float a_Dt) if ((m_State >= csAuthenticated) && (m_State < csDestroying)) { + StreamNextChunk(); // Streams the next chunk - // Unload all chunks that are out of the view distance (all 2 seconds) - if ((m_Player->GetWorld()->GetWorldAge() % 40) == 0) + // Unload all chunks that are out of the view distance (all 5 seconds) + if ((m_Player->GetWorld()->GetWorldAge() % 100) == 0) { UnloadOutOfRangeChunks(); } -- cgit v1.2.3 From b493beb3bbac05d0402a6e388a61bf446c6c00ff Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 6 Oct 2014 21:27:53 +0200 Subject: Stream 4 chunks per tick. Added priority. --- src/ClientHandle.cpp | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 535f9d386..588a1caba 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -402,11 +402,11 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, -void cClientHandle::StreamNextChunk(void) +bool cClientHandle::StreamNextChunk(void) { if ((m_State < csAuthenticated) || (m_State >= csDestroying)) { - return; + return true; } ASSERT(m_Player != NULL); @@ -415,7 +415,7 @@ void cClientHandle::StreamNextChunk(void) if ((m_LastStreamedChunkX == ChunkPosX) && (m_LastStreamedChunkZ == ChunkPosZ)) { // All chunks are already loaded. Abort loading. - return; + return true; } // Get the look vector and normalize it. @@ -454,8 +454,8 @@ void cClientHandle::StreamNextChunk(void) // Unloaded chunk found -> Send it to the client. Lock.Unlock(); - StreamChunk(ChunkX, ChunkZ); - return; + StreamChunk(ChunkX, ChunkZ, cChunkSender::E_CHUNK_PRIORITY_HIGH); + return false; } } } @@ -489,8 +489,8 @@ void cClientHandle::StreamNextChunk(void) // Unloaded chunk found -> Send it to the client. Lock.Unlock(); - StreamChunk(ChunkX, ChunkZ); - return; + StreamChunk(ChunkX, ChunkZ, cChunkSender::E_CHUNK_PRIORITY_MEDIUM); + return false; } } } @@ -527,14 +527,15 @@ void cClientHandle::StreamNextChunk(void) // Unloaded chunk found -> Send it to the client. Lock.Unlock(); - StreamChunk(Coords.m_ChunkX, Coords.m_ChunkZ); - return; + StreamChunk(Coords.m_ChunkX, Coords.m_ChunkZ, cChunkSender::E_CHUNK_PRIORITY_LOW); + return false; } } // All chunks are loaded -> Sets the last loaded chunk coordinates to current coordinates m_LastStreamedChunkX = ChunkPosX; m_LastStreamedChunkZ = ChunkPosZ; + return true; } @@ -590,7 +591,7 @@ void cClientHandle::UnloadOutOfRangeChunks(void) -void cClientHandle::StreamChunk(int a_ChunkX, int a_ChunkZ) +void cClientHandle::StreamChunk(int a_ChunkX, int a_ChunkZ, cChunkSender::eChunkPriority a_Priority) { if (m_State >= csDestroying) { @@ -608,7 +609,7 @@ void cClientHandle::StreamChunk(int a_ChunkX, int a_ChunkZ) m_LoadedChunks.push_back(cChunkCoords(a_ChunkX, a_ChunkZ)); m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, a_ChunkZ)); } - World->SendChunkTo(a_ChunkX, a_ChunkZ, this); + World->SendChunkTo(a_ChunkX, a_ChunkZ, a_Priority, this); } } @@ -2028,8 +2029,16 @@ void cClientHandle::Tick(float a_Dt) if ((m_State >= csAuthenticated) && (m_State < csDestroying)) { - - StreamNextChunk(); // Streams the next chunk + // Stream 4 chunks per tick + for (int i = 0; i < 4; i++) + { + // Stream the next chunk + if (StreamNextChunk()) + { + // Streaming finished. All chunks are loaded. + break; + } + } // Unload all chunks that are out of the view distance (all 5 seconds) if ((m_Player->GetWorld()->GetWorldAge() % 100) == 0) -- cgit v1.2.3 From 97623fc634263eeff99e25b7527fde318108ea0d Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 7 Oct 2014 21:36:01 +0200 Subject: Added distance check. --- src/ClientHandle.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 588a1caba..897ee9e9e 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -443,6 +443,12 @@ bool cClientHandle::StreamNextChunk(void) int ChunkZ = RangeZ + ((Z >= 4) ? (3 - Z) : Z); cChunkCoords Coords(ChunkX, ChunkZ); + // Checks if the chunk is in distance + if ((Diff(ChunkX, ChunkPosX) > m_ViewDistance) || (Diff(ChunkZ, ChunkPosZ) > m_ViewDistance)) + { + continue; + } + // If the chunk already loading/loaded -> skip if ( (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), Coords) != m_ChunksToSend.end()) || @@ -478,6 +484,12 @@ bool cClientHandle::StreamNextChunk(void) int ChunkZ = RangeZ + ((Z >= 4) ? (3 - Z) : Z); cChunkCoords Coords(ChunkX, ChunkZ); + // Checks if the chunk is in distance + if ((Diff(ChunkX, ChunkPosX) > m_ViewDistance) || (Diff(ChunkZ, ChunkPosZ) > m_ViewDistance)) + { + continue; + } + // If the chunk already loading/loaded -> skip if ( (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), Coords) != m_ChunksToSend.end()) || -- cgit v1.2.3 From c6725f8d284c77b16f7e047e1c1b64d2e8f8a007 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 15 Oct 2014 13:41:23 +0200 Subject: Usernames are lowercased before generating offline UUID. This breaks previous offline UUIDs, but it guarantees that future offline UUIDs will be the same even for usernames with wrong capitalization. --- src/ClientHandle.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 3b677460b..b9adcc828 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -248,9 +248,12 @@ AString cClientHandle::GenerateOfflineUUID(const AString & a_Username) // xxxxxxxx-xxxx-3xxx-yxxx-xxxxxxxxxxxx where x is any hexadecimal digit and y is one of 8, 9, A, or B // Note that we generate a short UUID (without the dashes) + // First make the username lowercase: + AString lcUsername = StrToLower(a_Username); + // Generate an md5 checksum, and use it as base for the ID: unsigned char MD5[16]; - md5((const unsigned char *)a_Username.c_str(), a_Username.length(), MD5); + md5((const unsigned char *)lcUsername.c_str(), lcUsername.length(), MD5); MD5[6] &= 0x0f; // Need to trim to 4 bits only... MD5[8] &= 0x0f; // ... otherwise %01x overflows into two chars return Printf("%02x%02x%02x%02x%02x%02x3%01x%02x8%01x%02x%02x%02x%02x%02x%02x%02x", -- cgit v1.2.3 From eeb580a74e48829908c303f8145802bfa1805c68 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 15 Oct 2014 19:01:55 +0200 Subject: Functions in cPluginManager get references instead of pointers. --- src/ClientHandle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index b9adcc828..344b2f2c2 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -596,7 +596,7 @@ bool cClientHandle::HandleLogin(int a_ProtocolVersion, const AString & a_Usernam m_Username = a_Username; // Let the plugins know about this event, they may refuse the player: - if (cRoot::Get()->GetPluginManager()->CallHookLogin(this, a_ProtocolVersion, a_Username)) + if (cRoot::Get()->GetPluginManager()->CallHookLogin(*this, a_ProtocolVersion, a_Username)) { Destroy(); return false; @@ -1715,7 +1715,7 @@ void cClientHandle::HandleKeepAlive(int a_KeepAliveID) bool cClientHandle::HandleHandshake(const AString & a_Username) { - if (!cRoot::Get()->GetPluginManager()->CallHookHandshake(this, a_Username)) + if (!cRoot::Get()->GetPluginManager()->CallHookHandshake(*this, a_Username)) { if (cRoot::Get()->GetServer()->GetNumPlayers() >= cRoot::Get()->GetServer()->GetMaxPlayers()) { -- cgit v1.2.3 From 8c2a99711e98ccfc2f6f31777a8b4e74e40c616c Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 16 Oct 2014 21:12:26 +0200 Subject: Merged branch 'fix_chunks'. --- src/ClientHandle.cpp | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 344b2f2c2..f244e8fea 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -540,9 +540,11 @@ void cClientHandle::RemoveFromAllChunks() } { + // Reset all chunk lists: cCSLock Lock(m_CSChunkLists); m_LoadedChunks.clear(); m_ChunksToSend.clear(); + m_SentChunks.clear(); // Also reset the LastStreamedChunk coords to bogus coords, // so that all chunks are streamed in subsequent StreamChunks() call (FS #407) @@ -2027,7 +2029,17 @@ void cClientHandle::SendBlockBreakAnim(int a_EntityID, int a_BlockX, int a_Block void cClientHandle::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { - m_Protocol->SendBlockChange(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); + int ChunkX, ChunkZ = 0; + cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); + cChunkCoords ChunkCoords = cChunkCoords(ChunkX, ChunkZ); + + // Do not send block changes in chunks that weren't sent to the client yet: + cCSLock Lock(m_CSChunkLists); + if (std::find(m_SentChunks.begin(), m_SentChunks.end(), ChunkCoords) != m_SentChunks.end()) + { + Lock.Unlock(); + m_Protocol->SendBlockChange(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta); + } } @@ -2037,8 +2049,15 @@ void cClientHandle::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BL void cClientHandle::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) { ASSERT(!a_Changes.empty()); // We don't want to be sending empty change packets! - - m_Protocol->SendBlockChanges(a_ChunkX, a_ChunkZ, a_Changes); + + // Do not send block changes in chunks that weren't sent to the client yet: + cChunkCoords ChunkCoords = cChunkCoords(a_ChunkX, a_ChunkZ); + cCSLock Lock(m_CSChunkLists); + if (std::find(m_SentChunks.begin(), m_SentChunks.end(), ChunkCoords) != m_SentChunks.end()) + { + Lock.Unlock(); + m_Protocol->SendBlockChanges(a_ChunkX, a_ChunkZ, a_Changes); + } } @@ -2102,6 +2121,12 @@ void cClientHandle::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializ m_Protocol->SendChunkData(a_ChunkX, a_ChunkZ, a_Serializer); + // Add the chunk to the list of chunks sent to the player: + { + cCSLock Lock(m_CSChunkLists); + m_SentChunks.push_back(cChunkCoords(a_ChunkX, a_ChunkZ)); + } + // If it is the chunk the player's in, make them spawn (in the tick thread): if ((m_State == csAuthenticated) || (m_State == csDownloadingWorld)) { @@ -2631,6 +2656,12 @@ void cClientHandle::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_D void cClientHandle::SendUnloadChunk(int a_ChunkX, int a_ChunkZ) { + // Remove the chunk from the list of chunks sent to the client: + { + cCSLock Lock(m_CSChunkLists); + m_SentChunks.remove(cChunkCoords(a_ChunkX, a_ChunkZ)); + } + m_Protocol->SendUnloadChunk(a_ChunkX, a_ChunkZ); } -- cgit v1.2.3 From a07456d7126d61d903eb7c14f88d436d20546474 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 21 Oct 2014 17:00:41 +0200 Subject: New c++11 stuff. --- src/ClientHandle.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index ec1bebe8d..28fcb0d37 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -430,13 +430,13 @@ bool cClientHandle::StreamNextChunk(void) cCSLock Lock(m_CSChunkLists); // High priority: Load the chunks that are in the view-direction of the player (with a radius of 3) - for (size_t Range = 0; Range < (size_t)m_ViewDistance; Range++) + for (int Range = 0; Range < m_ViewDistance; Range++) { Vector3d Vector = Position + LookVector * cChunkDef::Width * Range; // Get the chunk from the x/z coords. int RangeX, RangeZ = 0; - cChunkDef::BlockToChunk((int)std::floor(Vector.x), (int)std::floor(Vector.z), RangeX, RangeZ); + cChunkDef::BlockToChunk(FloorC(Vector.x), FloorC(Vector.z), RangeX, RangeZ); for (size_t X = 0; X < 7; X++) { @@ -471,13 +471,13 @@ bool cClientHandle::StreamNextChunk(void) // Medium priority: Load the chunks that are behind the player LookVector = m_Player->GetLookVector() * -1; - for (size_t Range = 0; Range < 3; Range++) + for (int Range = 0; Range < 3; Range++) { Vector3d Vector = Position + LookVector * cChunkDef::Width * Range; // Get the chunk from the x/z coords. int RangeX, RangeZ = 0; - cChunkDef::BlockToChunk((int)std::floor(Vector.x), (int)std::floor(Vector.z), RangeX, RangeZ); + cChunkDef::BlockToChunk(FloorC(Vector.x), FloorC(Vector.z), RangeX, RangeZ); for (size_t X = 0; X < 7; X++) { -- cgit v1.2.3 From b0988e65aadc1a9d33065cf6afefc05dbf768ef8 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 21 Oct 2014 17:35:23 +0200 Subject: Use two lists and 2 chunk send prioritys. --- src/ClientHandle.cpp | 41 ----------------------------------------- 1 file changed, 41 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 28fcb0d37..ce5056f30 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -469,47 +469,6 @@ bool cClientHandle::StreamNextChunk(void) } } - // Medium priority: Load the chunks that are behind the player - LookVector = m_Player->GetLookVector() * -1; - for (int Range = 0; Range < 3; Range++) - { - Vector3d Vector = Position + LookVector * cChunkDef::Width * Range; - - // Get the chunk from the x/z coords. - int RangeX, RangeZ = 0; - cChunkDef::BlockToChunk(FloorC(Vector.x), FloorC(Vector.z), RangeX, RangeZ); - - for (size_t X = 0; X < 7; X++) - { - for (size_t Z = 0; Z < 7; Z++) - { - int ChunkX = RangeX + ((X >= 4) ? (3 - X) : X); - int ChunkZ = RangeZ + ((Z >= 4) ? (3 - Z) : Z); - cChunkCoords Coords(ChunkX, ChunkZ); - - // Checks if the chunk is in distance - if ((Diff(ChunkX, ChunkPosX) > m_ViewDistance) || (Diff(ChunkZ, ChunkPosZ) > m_ViewDistance)) - { - continue; - } - - // If the chunk already loading/loaded -> skip - if ( - (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), Coords) != m_ChunksToSend.end()) || - (std::find(m_LoadedChunks.begin(), m_LoadedChunks.end(), Coords) != m_LoadedChunks.end()) - ) - { - continue; - } - - // Unloaded chunk found -> Send it to the client. - Lock.Unlock(); - StreamChunk(ChunkX, ChunkZ, cChunkSender::E_CHUNK_PRIORITY_MEDIUM); - return false; - } - } - } - // Low priority: Add all chunks that are in range. (From the center out to the edge) for (int d = 0; d <= m_ViewDistance; ++d) // cycle through (square) distance, from nearest to furthest { -- cgit v1.2.3 From a26541a7c3ced0569098edd0aae61c097c2912f4 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 20 Oct 2014 21:55:07 +0100 Subject: En masse NULL -> nullptr replace --- src/ClientHandle.cpp | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index f15d845ef..a83561838 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -68,7 +68,7 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) : m_ViewDistance(a_ViewDistance), m_IPString(a_Socket->GetIPString()), m_OutgoingData(64 KiB), - m_Player(NULL), + m_Player(nullptr), m_HasSentDC(false), m_LastStreamedChunkX(0x7fffffff), // bogus chunk coords to force streaming upon login m_LastStreamedChunkZ(0x7fffffff), @@ -122,10 +122,10 @@ cClientHandle::~cClientHandle() m_ChunksToSend.clear(); } - if (m_Player != NULL) + if (m_Player != nullptr) { cWorld * World = m_Player->GetWorld(); - if (World != NULL) + if (World != nullptr) { if (!m_Username.empty()) { @@ -137,7 +137,7 @@ cClientHandle::~cClientHandle() m_Player->Destroy(); } delete m_Player; - m_Player = NULL; + m_Player = nullptr; } if (!m_HasSentDC) @@ -149,7 +149,7 @@ cClientHandle::~cClientHandle() cRoot::Get()->GetServer()->RemoveClient(this); delete m_Protocol; - m_Protocol = NULL; + m_Protocol = nullptr; LOGD("ClientHandle at %p deleted", this); } @@ -173,7 +173,7 @@ void cClientHandle::Destroy(void) // DEBUG: LOGD("%s: client %p, \"%s\"", __FUNCTION__, this, m_Username.c_str()); - if ((m_Player != NULL) && (m_Player->GetWorld() != NULL)) + if ((m_Player != nullptr) && (m_Player->GetWorld() != nullptr)) { RemoveFromAllChunks(); m_Player->GetWorld()->RemoveClientFromChunkSender(this); @@ -314,7 +314,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, return; } - ASSERT(m_Player == NULL); + ASSERT(m_Player == nullptr); m_Username = a_Name; @@ -335,7 +335,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, m_Player = new cPlayer(this, GetUsername()); cWorld * World = cRoot::Get()->GetWorld(m_Player->GetLoadedWorldName()); - if (World == NULL) + if (World == nullptr) { World = cRoot::Get()->GetDefaultWorld(); } @@ -412,7 +412,7 @@ void cClientHandle::StreamChunks(void) return; } - ASSERT(m_Player != NULL); + ASSERT(m_Player != nullptr); int ChunkPosX = FAST_FLOOR_DIV((int)m_Player->GetPosX(), cChunkDef::Width); int ChunkPosZ = FAST_FLOOR_DIV((int)m_Player->GetPosZ(), cChunkDef::Width); @@ -427,7 +427,7 @@ void cClientHandle::StreamChunks(void) LOGD("Streaming chunks centered on [%d, %d], view distance %d", ChunkPosX, ChunkPosZ, m_ViewDistance); cWorld * World = m_Player->GetWorld(); - ASSERT(World != NULL); + ASSERT(World != nullptr); // Remove all loaded chunks that are no longer in range; deferred to out-of-CS: cChunkCoordsList RemoveChunks; @@ -513,7 +513,7 @@ void cClientHandle::StreamChunk(int a_ChunkX, int a_ChunkZ) } cWorld * World = m_Player->GetWorld(); - ASSERT(World != NULL); + ASSERT(World != nullptr); if (World->AddChunkClient(a_ChunkX, a_ChunkZ, this)) { @@ -534,7 +534,7 @@ void cClientHandle::StreamChunk(int a_ChunkX, int a_ChunkZ) void cClientHandle::RemoveFromAllChunks() { cWorld * World = m_Player->GetWorld(); - if (World != NULL) + if (World != nullptr) { World->RemoveClientFromChunks(this); } @@ -650,7 +650,7 @@ void cClientHandle::HandlePlayerAbilities(bool a_CanFly, bool a_IsFlying, float void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, bool a_IsOnGround) { - if ((m_Player == NULL) || (m_State != csPlaying)) + if ((m_Player == nullptr) || (m_State != csPlaying)) { // The client hasn't been spawned yet and sends nonsense, we know better return; @@ -784,7 +784,7 @@ void cClientHandle::UnregisterPluginChannels(const AStringVector & a_ChannelList void cClientHandle::HandleBeaconSelection(int a_PrimaryEffect, int a_SecondaryEffect) { cWindow * Window = m_Player->GetWindow(); - if ((Window == NULL) || (Window->GetWindowType() != cWindow::wtBeacon)) + if ((Window == nullptr) || (Window->GetWindowType() != cWindow::wtBeacon)) { return; } @@ -860,7 +860,7 @@ void cClientHandle::HandleCommandBlockEntityChange(int a_EntityID, const AString void cClientHandle::HandleAnvilItemName(const AString & a_ItemName) { - if ((m_Player->GetWindow() == NULL) || (m_Player->GetWindow()->GetWindowType() != cWindow::wtAnvil)) + if ((m_Player->GetWindow() == nullptr) || (m_Player->GetWindow()->GetWindowType() != cWindow::wtAnvil)) { return; } @@ -1497,7 +1497,7 @@ void cClientHandle::HandleChat(const AString & a_Message) void cClientHandle::HandlePlayerLook(float a_Rotation, float a_Pitch, bool a_IsOnGround) { - if ((m_Player == NULL) || (m_State != csPlaying)) + if ((m_Player == nullptr) || (m_State != csPlaying)) { return; } @@ -1597,7 +1597,7 @@ void cClientHandle::HandleWindowClick(char a_WindowID, short a_SlotNum, eClickAc ); cWindow * Window = m_Player->GetWindow(); - if (Window == NULL) + if (Window == nullptr) { LOGWARNING("Player \"%s\" clicked in a non-existent window. Ignoring", m_Username.c_str()); return; @@ -1689,7 +1689,7 @@ void cClientHandle::HandleUseEntity(int a_TargetEntityID, bool a_IsLeftClick) void cClientHandle::HandleRespawn(void) { - if (m_Player == NULL) + if (m_Player == nullptr) { Destroy(); return; @@ -1779,7 +1779,7 @@ void cClientHandle::HandleEntitySprinting(int a_EntityID, bool a_IsSprinting) void cClientHandle::HandleUnmount(void) { - if (m_Player == NULL) + if (m_Player == nullptr) { return; } @@ -1884,8 +1884,8 @@ void cClientHandle::RemoveFromWorld(void) bool cClientHandle::CheckBlockInteractionsRate(void) { - ASSERT(m_Player != NULL); - ASSERT(m_Player->GetWorld() != NULL); + ASSERT(m_Player != nullptr); + ASSERT(m_Player->GetWorld() != nullptr); if (m_NumBlockChangeInteractionsThisTick > MAX_BLOCK_CHANGE_INTERACTIONS) { @@ -1916,7 +1916,7 @@ void cClientHandle::Tick(float a_Dt) Destroy(); } - if (m_Player == NULL) + if (m_Player == nullptr) { return; } @@ -2067,10 +2067,10 @@ void cClientHandle::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlock void cClientHandle::SendChat(const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData) { cWorld * World = GetPlayer()->GetWorld(); - if (World == NULL) + if (World == nullptr) { World = cRoot::Get()->GetWorld(GetPlayer()->GetLoadedWorldName()); - if (World == NULL) + if (World == nullptr) { World = cRoot::Get()->GetDefaultWorld(); } @@ -2095,7 +2095,7 @@ void cClientHandle::SendChat(const cCompositeChat & a_Message) void cClientHandle::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) { - ASSERT(m_Player != NULL); + ASSERT(m_Player != nullptr); // Check chunks being sent, erase them from m_ChunksToSend: bool Found = false; @@ -2926,7 +2926,7 @@ void cClientHandle::HandleEnchantItem(Byte & a_WindowID, Byte & a_Enchantment) } if ( - (m_Player->GetWindow() == NULL) || + (m_Player->GetWindow() == nullptr) || (m_Player->GetWindow()->GetWindowID() != a_WindowID) || (m_Player->GetWindow()->GetWindowType() != cWindow::wtEnchantment) ) -- cgit v1.2.3 From 9af58a81d6467829b72801169c8e80a2bab01804 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 23 Oct 2014 21:19:43 +0200 Subject: Use 3 priorities. --- 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 dc360861e..faee05450 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -463,7 +463,7 @@ bool cClientHandle::StreamNextChunk(void) // Unloaded chunk found -> Send it to the client. Lock.Unlock(); - StreamChunk(ChunkX, ChunkZ, cChunkSender::E_CHUNK_PRIORITY_HIGH); + StreamChunk(ChunkX, ChunkZ, ((Range <= 2) ? cChunkSender::E_CHUNK_PRIORITY_HIGH : cChunkSender::E_CHUNK_PRIORITY_MEDIUM)); return false; } } -- cgit v1.2.3 From 9c7661f50f82fe265836f3279bf20b15aebba5b3 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 30 Oct 2014 21:24:10 +0100 Subject: Added a MaxViewDistance option. --- src/ClientHandle.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index faee05450..9b3bd9545 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2847,7 +2847,9 @@ void cClientHandle::SetUsername( const AString & a_Username) void cClientHandle::SetViewDistance(int a_ViewDistance) { - m_ViewDistance = Clamp(a_ViewDistance, MIN_VIEW_DISTANCE, MAX_VIEW_DISTANCE); + ASSERT(m_Player->GetWorld() == NULL); + + m_ViewDistance = Clamp(a_ViewDistance, cClientHandle::MIN_VIEW_DISTANCE, m_Player->GetWorld()->GetMaxViewDistance()); LOGD("Setted %s's view distance to %i", GetUsername().c_str(), m_ViewDistance); } -- cgit v1.2.3 From d93acb841f5d78a25ced74e01c984c1604459e5e Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 30 Oct 2014 22:04:04 +0100 Subject: Fixed m_SentChunks list chunk removing. --- 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 faee05450..94bace43a 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -557,7 +557,7 @@ void cClientHandle::UnloadOutOfRangeChunks(void) for (cChunkCoordsList::iterator itr = ChunksToRemove.begin(); itr != ChunksToRemove.end(); ++itr) { m_Player->GetWorld()->RemoveChunkClient(itr->m_ChunkX, itr->m_ChunkZ, this); - m_Protocol->SendUnloadChunk(itr->m_ChunkX, itr->m_ChunkZ); + SendUnloadChunk(itr->m_ChunkX, itr->m_ChunkZ); } } -- cgit v1.2.3 From 83d3f3347b5c812b06be87804b7582a92d0294d3 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 14 Nov 2014 22:53:12 +0100 Subject: Use m_UsedViewDistance and m_SetViewDistance. --- src/ClientHandle.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index d7d97c6c4..d5882da06 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -65,7 +65,8 @@ int cClientHandle::s_ClientCount = 0; // cClientHandle: cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) : - m_ViewDistance(a_ViewDistance), + m_UsedViewDistance(a_ViewDistance), + m_SetViewDistance(a_ViewDistance), m_IPString(a_Socket->GetIPString()), m_OutgoingData(64 KiB), m_Player(nullptr), @@ -430,7 +431,7 @@ bool cClientHandle::StreamNextChunk(void) cCSLock Lock(m_CSChunkLists); // High priority: Load the chunks that are in the view-direction of the player (with a radius of 3) - for (int Range = 0; Range < m_ViewDistance; Range++) + for (int Range = 0; Range < m_UsedViewDistance; Range++) { Vector3d Vector = Position + LookVector * cChunkDef::Width * Range; @@ -447,7 +448,7 @@ bool cClientHandle::StreamNextChunk(void) cChunkCoords Coords(ChunkX, ChunkZ); // Checks if the chunk is in distance - if ((Diff(ChunkX, ChunkPosX) > m_ViewDistance) || (Diff(ChunkZ, ChunkPosZ) > m_ViewDistance)) + if ((Diff(ChunkX, ChunkPosX) > m_UsedViewDistance) || (Diff(ChunkZ, ChunkPosZ) > m_UsedViewDistance)) { continue; } @@ -470,7 +471,7 @@ bool cClientHandle::StreamNextChunk(void) } // Low priority: Add all chunks that are in range. (From the center out to the edge) - for (int d = 0; d <= m_ViewDistance; ++d) // cycle through (square) distance, from nearest to furthest + for (int d = 0; d <= m_UsedViewDistance; ++d) // cycle through (square) distance, from nearest to furthest { // For each distance add chunks in a hollow square centered around current position: cChunkCoordsList CurcleChunks; @@ -528,7 +529,7 @@ void cClientHandle::UnloadOutOfRangeChunks(void) { int DiffX = Diff((*itr).m_ChunkX, ChunkPosX); int DiffZ = Diff((*itr).m_ChunkZ, ChunkPosZ); - if ((DiffX > m_ViewDistance) || (DiffZ > m_ViewDistance)) + if ((DiffX > m_UsedViewDistance) || (DiffZ > m_UsedViewDistance)) { ChunksToRemove.push_back(*itr); itr = m_LoadedChunks.erase(itr); @@ -543,7 +544,7 @@ void cClientHandle::UnloadOutOfRangeChunks(void) { int DiffX = Diff((*itr).m_ChunkX, ChunkPosX); int DiffZ = Diff((*itr).m_ChunkZ, ChunkPosZ); - if ((DiffX > m_ViewDistance) || (DiffZ > m_ViewDistance)) + if ((DiffX > m_UsedViewDistance) || (DiffZ > m_UsedViewDistance)) { itr = m_ChunksToSend.erase(itr); } @@ -2849,8 +2850,9 @@ void cClientHandle::SetViewDistance(int a_ViewDistance) { ASSERT(m_Player->GetWorld() == NULL); - m_ViewDistance = Clamp(a_ViewDistance, cClientHandle::MIN_VIEW_DISTANCE, m_Player->GetWorld()->GetMaxViewDistance()); - LOGD("Setted %s's view distance to %i", GetUsername().c_str(), m_ViewDistance); + m_SetViewDistance = a_ViewDistance; + m_UsedViewDistance = Clamp(m_SetViewDistance, cClientHandle::MIN_VIEW_DISTANCE, m_Player->GetWorld()->GetMaxViewDistance()); + LOGD("Setted view distance from %s to %i!", GetUsername().c_str(), m_UsedViewDistance); } -- cgit v1.2.3 From 78fb7896313f2074fa814309901e30d4a4f218e2 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 15 Nov 2014 15:16:52 +0100 Subject: Fixed a security problem with signs. --- src/ClientHandle.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 94bace43a..9bf4875e2 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -93,6 +93,7 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) : m_UniqueID(0), m_HasSentPlayerChunk(false), m_Locale("en_GB"), + m_LastPlacedBlock(0, -1, 0), m_ProtocolVersion(0) { m_Protocol = new cProtocolRecognizer(this); @@ -1500,6 +1501,8 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e { m_Player->GetInventory().RemoveOneEquippedItem(); } + m_LastPlacedBlock.Set(a_BlockX, a_BlockY, a_BlockZ); + cChunkInterface ChunkInterface(World->GetChunkMap()); NewBlock->OnPlacedByPlayer(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta); @@ -1677,8 +1680,10 @@ void cClientHandle::HandleUpdateSign( const AString & a_Line3, const AString & a_Line4 ) { - cWorld * World = m_Player->GetWorld(); - World->UpdateSign(a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, m_Player); + if (m_LastPlacedBlock.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + m_Player->GetWorld()->SetSignLines(a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, m_Player); + } } -- cgit v1.2.3 From 927d8d7702b71baa64dc70593ea71e1081c33a9c Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 15 Nov 2014 15:33:42 +0100 Subject: Renamed m_SetViewDistance to m_RequestedViewDistance --- src/ClientHandle.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index d5882da06..3feb4c596 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -66,7 +66,7 @@ int cClientHandle::s_ClientCount = 0; cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) : m_UsedViewDistance(a_ViewDistance), - m_SetViewDistance(a_ViewDistance), + m_RequestedViewDistance(a_ViewDistance), m_IPString(a_Socket->GetIPString()), m_OutgoingData(64 KiB), m_Player(nullptr), @@ -2850,9 +2850,9 @@ void cClientHandle::SetViewDistance(int a_ViewDistance) { ASSERT(m_Player->GetWorld() == NULL); - m_SetViewDistance = a_ViewDistance; - m_UsedViewDistance = Clamp(m_SetViewDistance, cClientHandle::MIN_VIEW_DISTANCE, m_Player->GetWorld()->GetMaxViewDistance()); - LOGD("Setted view distance from %s to %i!", GetUsername().c_str(), m_UsedViewDistance); + m_RequestedViewDistance = a_ViewDistance; + m_UsedViewDistance = Clamp(a_ViewDistance, cClientHandle::MIN_VIEW_DISTANCE, m_Player->GetWorld()->GetMaxViewDistance()); + LOGD("Setted view distance from %s to %d!", GetUsername().c_str(), m_UsedViewDistance); } -- cgit v1.2.3 From 09cea625fcf2d1eb1fb37a57c5712d992c96e4fd Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 15 Nov 2014 22:26:54 +0100 Subject: Renamed m_UsedViewDistance to m_CurrentViewDistance --- src/ClientHandle.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 3feb4c596..0b9d84bf7 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -65,7 +65,7 @@ int cClientHandle::s_ClientCount = 0; // cClientHandle: cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) : - m_UsedViewDistance(a_ViewDistance), + m_CurrentViewDistance(a_ViewDistance), m_RequestedViewDistance(a_ViewDistance), m_IPString(a_Socket->GetIPString()), m_OutgoingData(64 KiB), @@ -431,7 +431,7 @@ bool cClientHandle::StreamNextChunk(void) cCSLock Lock(m_CSChunkLists); // High priority: Load the chunks that are in the view-direction of the player (with a radius of 3) - for (int Range = 0; Range < m_UsedViewDistance; Range++) + for (int Range = 0; Range < m_CurrentViewDistance; Range++) { Vector3d Vector = Position + LookVector * cChunkDef::Width * Range; @@ -448,7 +448,7 @@ bool cClientHandle::StreamNextChunk(void) cChunkCoords Coords(ChunkX, ChunkZ); // Checks if the chunk is in distance - if ((Diff(ChunkX, ChunkPosX) > m_UsedViewDistance) || (Diff(ChunkZ, ChunkPosZ) > m_UsedViewDistance)) + if ((Diff(ChunkX, ChunkPosX) > m_CurrentViewDistance) || (Diff(ChunkZ, ChunkPosZ) > m_CurrentViewDistance)) { continue; } @@ -471,7 +471,7 @@ bool cClientHandle::StreamNextChunk(void) } // Low priority: Add all chunks that are in range. (From the center out to the edge) - for (int d = 0; d <= m_UsedViewDistance; ++d) // cycle through (square) distance, from nearest to furthest + for (int d = 0; d <= m_CurrentViewDistance; ++d) // cycle through (square) distance, from nearest to furthest { // For each distance add chunks in a hollow square centered around current position: cChunkCoordsList CurcleChunks; @@ -529,7 +529,7 @@ void cClientHandle::UnloadOutOfRangeChunks(void) { int DiffX = Diff((*itr).m_ChunkX, ChunkPosX); int DiffZ = Diff((*itr).m_ChunkZ, ChunkPosZ); - if ((DiffX > m_UsedViewDistance) || (DiffZ > m_UsedViewDistance)) + if ((DiffX > m_CurrentViewDistance) || (DiffZ > m_CurrentViewDistance)) { ChunksToRemove.push_back(*itr); itr = m_LoadedChunks.erase(itr); @@ -544,7 +544,7 @@ void cClientHandle::UnloadOutOfRangeChunks(void) { int DiffX = Diff((*itr).m_ChunkX, ChunkPosX); int DiffZ = Diff((*itr).m_ChunkZ, ChunkPosZ); - if ((DiffX > m_UsedViewDistance) || (DiffZ > m_UsedViewDistance)) + if ((DiffX > m_CurrentViewDistance) || (DiffZ > m_CurrentViewDistance)) { itr = m_ChunksToSend.erase(itr); } @@ -2851,8 +2851,8 @@ void cClientHandle::SetViewDistance(int a_ViewDistance) ASSERT(m_Player->GetWorld() == NULL); m_RequestedViewDistance = a_ViewDistance; - m_UsedViewDistance = Clamp(a_ViewDistance, cClientHandle::MIN_VIEW_DISTANCE, m_Player->GetWorld()->GetMaxViewDistance()); - LOGD("Setted view distance from %s to %d!", GetUsername().c_str(), m_UsedViewDistance); + m_CurrentViewDistance = Clamp(a_ViewDistance, cClientHandle::MIN_VIEW_DISTANCE, m_Player->GetWorld()->GetMaxViewDistance()); + LOGD("Setted view distance from %s to %d!", GetUsername().c_str(), m_CurrentViewDistance); } -- cgit v1.2.3 From 277151582fbb0652dcf4e15f67d41f90e08bdeeb Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 15 Nov 2014 22:36:31 +0100 Subject: Use LastPlacedSign instead of LastPlacedBlock. --- src/ClientHandle.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 9bf4875e2..83fb283b6 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -93,7 +93,7 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) : m_UniqueID(0), m_HasSentPlayerChunk(false), m_Locale("en_GB"), - m_LastPlacedBlock(0, -1, 0), + m_LastPlacedSign(0, -1, 0), m_ProtocolVersion(0) { m_Protocol = new cProtocolRecognizer(this); @@ -1501,7 +1501,6 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e { m_Player->GetInventory().RemoveOneEquippedItem(); } - m_LastPlacedBlock.Set(a_BlockX, a_BlockY, a_BlockZ); cChunkInterface ChunkInterface(World->GetChunkMap()); NewBlock->OnPlacedByPlayer(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta); @@ -1680,8 +1679,9 @@ void cClientHandle::HandleUpdateSign( const AString & a_Line3, const AString & a_Line4 ) { - if (m_LastPlacedBlock.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + if (m_LastPlacedSign.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) { + m_LastPlacedSign.Set(0, -1, 0); m_Player->GetWorld()->SetSignLines(a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, m_Player); } } @@ -2262,6 +2262,7 @@ void cClientHandle::SendDisconnect(const AString & a_Reason) void cClientHandle::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ) { + m_LastPlacedSign.Set(a_BlockX, a_BlockY, a_BlockZ); m_Protocol->SendEditSign(a_BlockX, a_BlockY, a_BlockZ); } -- cgit v1.2.3 From ae15c2f78e85c8a6ee192d48d8befc5ee4b478b6 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Mon, 17 Nov 2014 12:34:14 +0100 Subject: Fixed a wrong assert in cClientHandle::SetViewDistance(). --- src/ClientHandle.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 0b9d84bf7..8b4d6d0cc 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -2848,11 +2848,15 @@ void cClientHandle::SetUsername( const AString & a_Username) void cClientHandle::SetViewDistance(int a_ViewDistance) { - ASSERT(m_Player->GetWorld() == NULL); - m_RequestedViewDistance = a_ViewDistance; - m_CurrentViewDistance = Clamp(a_ViewDistance, cClientHandle::MIN_VIEW_DISTANCE, m_Player->GetWorld()->GetMaxViewDistance()); - LOGD("Setted view distance from %s to %d!", GetUsername().c_str(), m_CurrentViewDistance); + LOGD("%s is requesting ViewDistance of %d!", GetUsername().c_str(), m_RequestedViewDistance); + + // Set the current view distance based on the requested VD and world max VD: + cWorld * world = m_Player->GetWorld(); + if (world != nullptr) + { + m_CurrentViewDistance = Clamp(a_ViewDistance, cClientHandle::MIN_VIEW_DISTANCE, world->GetMaxViewDistance()); + } } -- cgit v1.2.3