summaryrefslogtreecommitdiffstats
path: root/source/cClientHandle.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-25 19:52:08 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-25 19:52:08 +0200
commitbb25ba4977198728b6ee30b61fcc6f48d1d94d4d (patch)
treecd56d34bafc04ba7b2f7d2e0e5634eda540c246e /source/cClientHandle.cpp
parentRemoved packet includes where they're not needed (diff)
downloadcuberite-bb25ba4977198728b6ee30b61fcc6f48d1d94d4d.tar
cuberite-bb25ba4977198728b6ee30b61fcc6f48d1d94d4d.tar.gz
cuberite-bb25ba4977198728b6ee30b61fcc6f48d1d94d4d.tar.bz2
cuberite-bb25ba4977198728b6ee30b61fcc6f48d1d94d4d.tar.lz
cuberite-bb25ba4977198728b6ee30b61fcc6f48d1d94d4d.tar.xz
cuberite-bb25ba4977198728b6ee30b61fcc6f48d1d94d4d.tar.zst
cuberite-bb25ba4977198728b6ee30b61fcc6f48d1d94d4d.zip
Diffstat (limited to 'source/cClientHandle.cpp')
-rw-r--r--source/cClientHandle.cpp71
1 files changed, 69 insertions, 2 deletions
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp
index 90672a1ec..a0ec88f80 100644
--- a/source/cClientHandle.cpp
+++ b/source/cClientHandle.cpp
@@ -1400,7 +1400,11 @@ void cClientHandle::Send(const cPacket & a_Packet, ENUM_PRIORITY a_Priority /* =
if ((itr->m_ChunkX == ChunkX) && (itr->m_ChunkZ == ChunkZ))
{
m_ChunksToSend.erase(itr);
+
+ // TODO: _X: Decouple this from packet sending, it creates a deadlock possibility
+ // -- postpone till Tick() instead, using a bool flag
CheckIfWorldDownloaded();
+
Found = true;
break;
}
@@ -1908,14 +1912,77 @@ void cClientHandle::SendCollectPickup(const cPickup & a_Pickup, const cPlayer &
+void cClientHandle::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
+{
+ cPacket_BlockChange BlockChange;
+ BlockChange.m_PosX = a_BlockX;
+ BlockChange.m_PosY = (unsigned char)a_BlockY;
+ BlockChange.m_PosZ = a_BlockZ;
+ BlockChange.m_BlockType = a_BlockType;
+ BlockChange.m_BlockMeta = a_BlockMeta;
+ Send(BlockChange);
+}
+
+
+
+
+
+void cClientHandle::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes)
+{
+ if (a_Changes.size() == 1)
+ {
+ // Special packet for single-block changes
+ const sSetBlock & blk = a_Changes.front();
+ SendBlockChange(a_ChunkX * cChunkDef::Width + blk.x, blk.y, a_ChunkZ * cChunkDef::Height + blk.z, blk.BlockType, blk.BlockMeta);
+ return;
+ }
+
+ cPacket_MultiBlock MultiBlock;
+ MultiBlock.m_ChunkX = a_ChunkX;
+ MultiBlock.m_ChunkZ = a_ChunkZ;
+ MultiBlock.m_NumBlocks = (short)a_Changes.size();
+ MultiBlock.m_Data = new cPacket_MultiBlock::sBlockChange[a_Changes.size()];
+ int i = 0;
+ for (sSetBlockVector::const_iterator itr = a_Changes.begin(), end = a_Changes.end(); itr != end; ++itr, i++)
+ {
+ unsigned int Coords = itr->y | (itr->z << 8) | (itr->x << 12);
+ unsigned int Blocks = itr->BlockMeta | (itr->BlockType << 4);
+ MultiBlock.m_Data[i].Data = Coords << 16 | Blocks;
+ }
+ Send(MultiBlock);
+}
+
+
+
+
+
+void cClientHandle::SendUnloadChunk(int a_ChunkX, int a_ChunkZ)
+{
+ cPacket_PreChunk UnloadPacket;
+ UnloadPacket.m_PosX = a_ChunkX;
+ UnloadPacket.m_PosZ = a_ChunkZ;
+ UnloadPacket.m_bLoad = false; // Unload
+ Send(UnloadPacket);
+}
+
+
+
+
+
void cClientHandle::CheckIfWorldDownloaded(void)
{
if (m_State != csDownloadingWorld)
{
return;
}
- cCSLock Lock(m_CSChunkLists);
- if (m_ChunksToSend.empty())
+
+ bool ShouldSendConfirm = false;
+ {
+ cCSLock Lock(m_CSChunkLists);
+ ShouldSendConfirm = m_ChunksToSend.empty();
+ }
+
+ if (ShouldSendConfirm)
{
SendConfirmPosition();
}