summaryrefslogtreecommitdiffstats
path: root/source/packets/cPacket_MapChunk.cpp
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-10-03 20:41:19 +0200
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-10-03 20:41:19 +0200
commit386d58b5862d8b76925c6523721594887606e82a (patch)
treeef073e7a843f4b75a4008d4b7383f7cdf08ceee5 /source/packets/cPacket_MapChunk.cpp
parentVisual Studio 2010 solution and project files (diff)
downloadcuberite-386d58b5862d8b76925c6523721594887606e82a.tar
cuberite-386d58b5862d8b76925c6523721594887606e82a.tar.gz
cuberite-386d58b5862d8b76925c6523721594887606e82a.tar.bz2
cuberite-386d58b5862d8b76925c6523721594887606e82a.tar.lz
cuberite-386d58b5862d8b76925c6523721594887606e82a.tar.xz
cuberite-386d58b5862d8b76925c6523721594887606e82a.tar.zst
cuberite-386d58b5862d8b76925c6523721594887606e82a.zip
Diffstat (limited to 'source/packets/cPacket_MapChunk.cpp')
-rw-r--r--source/packets/cPacket_MapChunk.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/source/packets/cPacket_MapChunk.cpp b/source/packets/cPacket_MapChunk.cpp
new file mode 100644
index 000000000..08681494c
--- /dev/null
+++ b/source/packets/cPacket_MapChunk.cpp
@@ -0,0 +1,69 @@
+#include "cPacket_MapChunk.h"
+#include "../cChunk.h"
+
+#include "zlib.h"
+
+cPacket_MapChunk::~cPacket_MapChunk()
+{
+ if( m_CompressedData )
+ {
+ delete [] m_CompressedData;
+ }
+}
+
+cPacket_MapChunk::cPacket_MapChunk(cChunk* a_Chunk)
+{
+ m_PacketID = E_MAP_CHUNK;
+
+ m_PosX = a_Chunk->GetPosX() * 16; // It has to be block coordinates
+ m_PosY = (short)(a_Chunk->GetPosY() * 128);
+ m_PosZ = a_Chunk->GetPosZ() * 16;
+
+ m_SizeX = 15;
+ m_SizeY = 127;
+ m_SizeZ = 15;
+
+ uLongf CompressedSize = compressBound( cChunk::c_BlockDataSize );
+ char* CompressedBlockData = new char[CompressedSize];
+
+ compress2( (Bytef*)CompressedBlockData, &CompressedSize, (const Bytef*)a_Chunk->pGetBlockData(), cChunk::c_BlockDataSize, Z_DEFAULT_COMPRESSION);
+
+ m_CompressedData = CompressedBlockData;
+ m_CompressedSize = CompressedSize;
+}
+
+cPacket_MapChunk::cPacket_MapChunk( const cPacket_MapChunk & a_Copy )
+{
+ m_PacketID = E_MAP_CHUNK;
+ m_PosX = a_Copy.m_PosX;
+ m_PosY = a_Copy.m_PosY;
+ m_PosZ = a_Copy.m_PosZ;
+ m_SizeX = a_Copy.m_SizeX;
+ m_SizeY = a_Copy.m_SizeY;
+ m_SizeZ = a_Copy.m_SizeZ;
+
+ m_CompressedSize = a_Copy.m_CompressedSize;
+ m_CompressedData = new char[m_CompressedSize];
+ memcpy( m_CompressedData, a_Copy.m_CompressedData, m_CompressedSize );
+}
+
+bool cPacket_MapChunk::Send(cSocket & a_Socket)
+{
+ unsigned int TotalSize = c_Size + m_CompressedSize;
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte ( (char)m_PacketID, Message, i );
+ AppendInteger ( m_PosX, Message, i );
+ AppendShort ( m_PosY, Message, i );
+ AppendInteger ( m_PosZ, Message, i );
+ AppendByte ( m_SizeX, Message, i );
+ AppendByte ( m_SizeY, Message, i );
+ AppendByte ( m_SizeZ, Message, i );
+ AppendInteger ( m_CompressedSize, Message, i );
+ AppendData ( m_CompressedData, m_CompressedSize, Message, i );
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+} \ No newline at end of file