diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2015-07-15 18:13:55 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2015-07-15 18:13:55 +0200 |
commit | c390604bc1343705ee17d6466da8dc53b5fa3b0e (patch) | |
tree | cbf9db66aae0fd8a85c88b0b1ef5ae9aea4d20ea /src/Protocol | |
parent | Merge pull request #2036 from cuberite/sign-metamirror (diff) | |
parent | Improved maps (diff) | |
download | cuberite-c390604bc1343705ee17d6466da8dc53b5fa3b0e.tar cuberite-c390604bc1343705ee17d6466da8dc53b5fa3b0e.tar.gz cuberite-c390604bc1343705ee17d6466da8dc53b5fa3b0e.tar.bz2 cuberite-c390604bc1343705ee17d6466da8dc53b5fa3b0e.tar.lz cuberite-c390604bc1343705ee17d6466da8dc53b5fa3b0e.tar.xz cuberite-c390604bc1343705ee17d6466da8dc53b5fa3b0e.tar.zst cuberite-c390604bc1343705ee17d6466da8dc53b5fa3b0e.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Protocol/Protocol.h | 4 | ||||
-rw-r--r-- | src/Protocol/Protocol17x.cpp | 79 | ||||
-rw-r--r-- | src/Protocol/Protocol17x.h | 4 | ||||
-rw-r--r-- | src/Protocol/Protocol18x.cpp | 59 | ||||
-rw-r--r-- | src/Protocol/Protocol18x.h | 4 | ||||
-rw-r--r-- | src/Protocol/ProtocolRecognizer.cpp | 24 | ||||
-rw-r--r-- | src/Protocol/ProtocolRecognizer.h | 4 |
7 files changed, 56 insertions, 122 deletions
diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index 1a19249bf..9e80f7bd5 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -99,9 +99,7 @@ public: virtual void SendKeepAlive (int a_PingID) = 0; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) = 0; virtual void SendLoginSuccess (void) = 0; - virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale) = 0; - virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale) = 0; - virtual void SendMapInfo (int a_ID, unsigned int a_Scale) = 0; + virtual void SendMapData (const cMap & a_Map, int a_DataStartX, int a_DataStartY) = 0; virtual void SendPaintingSpawn (const cPainting & a_Painting) = 0; virtual void SendPickupSpawn (const cPickup & a_Pickup) = 0; virtual void SendPlayerAbilities (void) = 0; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index c5c0f4a03..dc602ec6c 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -723,64 +723,55 @@ void cProtocol172::SendPaintingSpawn(const cPainting & a_Painting) -void cProtocol172::SendMapColumn(int a_MapID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale) +void cProtocol172::SendMapData(const cMap & a_Map, int a_DataStartX, int a_DataStartY) { ASSERT(m_State == 3); // In game mode? - ASSERT(a_Length + 3 <= USHRT_MAX); - ASSERT((a_X >= 0) && (a_X < 256)); - ASSERT((a_Y >= 0) && (a_Y < 256)); - - cPacketizer Pkt(*this, 0x34); - Pkt.WriteVarInt32(static_cast<UInt32>(a_MapID)); - Pkt.WriteBEUInt16(static_cast<UInt16>(3 + a_Length)); - Pkt.WriteBEUInt8(0); - Pkt.WriteBEUInt8(static_cast<Byte>(a_X)); - Pkt.WriteBEUInt8(static_cast<Byte>(a_Y)); - - Pkt.WriteBuf(reinterpret_cast<const char *>(a_Colors), a_Length); -} + { + ASSERT(a_Map.GetScale() < 256); + cPacketizer Pkt(*this, 0x34); + Pkt.WriteVarInt32(static_cast<UInt32>(a_Map.GetID())); + Pkt.WriteBEUInt16(2); + Pkt.WriteBEUInt8(2); + Pkt.WriteBEUInt8(static_cast<Byte>(a_Map.GetScale())); + } + { + ASSERT(a_Map.GetData().size() + 3 <= USHRT_MAX); + ASSERT((a_DataStartX >= 0) && (a_DataStartX < 256)); + ASSERT((a_DataStartY >= 0) && (a_DataStartY < 256)); + cPacketizer Pkt(*this, 0x34); + Pkt.WriteVarInt32(static_cast<UInt32>(a_Map.GetID())); + Pkt.WriteBEUInt16(static_cast<UInt16>(3 + a_Map.GetData().size())); -void cProtocol172::SendMapDecorators(int a_MapID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale) -{ - ASSERT(m_State == 3); // In game mode? - ASSERT(1 + 3 * a_Decorators.size() < USHRT_MAX); - - cPacketizer Pkt(*this, 0x34); - Pkt.WriteVarInt32(static_cast<UInt32>(a_MapID)); - Pkt.WriteBEUInt16(static_cast<UInt16>(1 + (3 * a_Decorators.size()))); + Pkt.WriteBEUInt8(0); + Pkt.WriteBEUInt8(static_cast<Byte>(a_DataStartX)); + Pkt.WriteBEUInt8(static_cast<Byte>(a_DataStartX)); - Pkt.WriteBEUInt8(1); - - for (cMapDecoratorList::const_iterator it = a_Decorators.begin(); it != a_Decorators.end(); ++it) - { - ASSERT(it->GetPixelX() < 256); - ASSERT(it->GetPixelZ() < 256); - Pkt.WriteBEUInt8(static_cast<Byte>((it->GetType() << 4) | static_cast<Byte>(it->GetRot() & 0xf))); - Pkt.WriteBEUInt8(static_cast<Byte>(it->GetPixelX())); - Pkt.WriteBEUInt8(static_cast<Byte>(it->GetPixelZ())); + Pkt.WriteBuf(reinterpret_cast<const char *>(a_Map.GetData().data()), a_Map.GetData().size()); } -} - + { + ASSERT(1 + 3 * a_Map.GetDecorators().size() < USHRT_MAX); + cPacketizer Pkt(*this, 0x34); + Pkt.WriteVarInt32(static_cast<UInt32>(a_Map.GetID())); + Pkt.WriteBEUInt16(static_cast<UInt16>(1 + (3 * a_Map.GetDecorators().size()))); + Pkt.WriteBEUInt8(1); -void cProtocol172::SendMapInfo(int a_MapID, unsigned int a_Scale) -{ - ASSERT(m_State == 3); // In game mode? - ASSERT(a_Scale < 256); - - cPacketizer Pkt(*this, 0x34); - Pkt.WriteVarInt32(static_cast<UInt32>(a_MapID)); - Pkt.WriteBEUInt16(2); - - Pkt.WriteBEUInt8(2); - Pkt.WriteBEUInt8(static_cast<Byte>(a_Scale)); + for (const auto & Decorator : a_Map.GetDecorators()) + { + ASSERT(Decorator.GetPixelX() < 256); + ASSERT(Decorator.GetPixelZ() < 256); + Pkt.WriteBEUInt8(static_cast<Byte>((Decorator.GetRot() << 4) | static_cast<int>(Decorator.GetType()))); + Pkt.WriteBEUInt8(static_cast<Byte>(Decorator.GetPixelX())); + Pkt.WriteBEUInt8(static_cast<Byte>(Decorator.GetPixelZ())); + } + } } diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index b07fa9ed9..c5625dd62 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -101,9 +101,7 @@ public: virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; virtual void SendLoginSuccess (void) override; - virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale) override; - virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale) override; - virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override; + virtual void SendMapData (const cMap & a_Map, int a_DataStartX, int a_DataStartY) override; virtual void SendPaintingSpawn (const cPainting & a_Painting) override; virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount) override; virtual void SendParticleEffect (const AString & a_ParticleName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array<int, 2> a_Data) override; diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index 4708d67c9..db510825e 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -715,60 +715,31 @@ void cProtocol180::SendPaintingSpawn(const cPainting & a_Painting) -void cProtocol180::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale) +void cProtocol180::SendMapData(const cMap & a_Map, int a_DataStartX, int a_DataStartY) { ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, 0x34); - Pkt.WriteVarInt32(a_ID); - Pkt.WriteBEUInt8(m_Scale); + Pkt.WriteVarInt32(a_Map.GetID()); + Pkt.WriteBEUInt8(a_Map.GetScale()); - Pkt.WriteVarInt32(0); - Pkt.WriteBEUInt8(1); - Pkt.WriteBEUInt8(a_Length); - Pkt.WriteBEUInt8(a_X); - Pkt.WriteBEUInt8(a_Y); - - Pkt.WriteVarInt32(a_Length); - for (unsigned int i = 0; i < a_Length; ++i) + Pkt.WriteVarInt32(static_cast<UInt32>(a_Map.GetDecorators().size())); + for (const auto Decorator : a_Map.GetDecorators()) { - Pkt.WriteBEUInt8(a_Colors[i]); + Pkt.WriteBEUInt8(static_cast<Byte>((static_cast<int>(Decorator.GetType()) << 4) | (Decorator.GetRot() & 0xF))); + Pkt.WriteBEUInt8(Decorator.GetPixelX()); + Pkt.WriteBEUInt8(Decorator.GetPixelZ()); } -} - - - - - -void cProtocol180::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x34); - Pkt.WriteVarInt32(a_ID); - Pkt.WriteBEUInt8(m_Scale); - Pkt.WriteVarInt32(static_cast<UInt32>(a_Decorators.size())); - for (cMapDecoratorList::const_iterator it = a_Decorators.begin(); it != a_Decorators.end(); ++it) + Pkt.WriteBEUInt8(128); + Pkt.WriteBEUInt8(128); + Pkt.WriteBEUInt8(a_DataStartX); + Pkt.WriteBEUInt8(a_DataStartY); + Pkt.WriteVarInt32(static_cast<UInt32>(a_Map.GetData().size())); + for (auto itr = a_Map.GetData().cbegin(); itr != a_Map.GetData().cend(); ++itr) { - Pkt.WriteBEUInt8((it->GetType() << 4) | (it->GetRot() & 0xf)); - Pkt.WriteBEUInt8(it->GetPixelX()); - Pkt.WriteBEUInt8(it->GetPixelZ()); + Pkt.WriteBEUInt8(*itr); } - - Pkt.WriteBEUInt8(0); -} - - - - - -void cProtocol180::SendMapInfo(int a_ID, unsigned int a_Scale) -{ - UNUSED(a_ID); - UNUSED(a_Scale); - - // This packet was removed in 1.8 } diff --git a/src/Protocol/Protocol18x.h b/src/Protocol/Protocol18x.h index 36ed251fe..99774d242 100644 --- a/src/Protocol/Protocol18x.h +++ b/src/Protocol/Protocol18x.h @@ -96,9 +96,7 @@ public: virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; virtual void SendLoginSuccess (void) override; - virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale) override; - virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale) override; - virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override; + virtual void SendMapData (const cMap & a_Map, int a_DataStartX, int a_DataStartY) override; virtual void SendPaintingSpawn (const cPainting & a_Painting) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; virtual void SendPlayerAbilities (void) override; diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index c89c745a4..574875831 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -470,30 +470,10 @@ void cProtocolRecognizer::SendLoginSuccess(void) -void cProtocolRecognizer::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale) +void cProtocolRecognizer::SendMapData(const cMap & a_Map, int a_DataStartX, int a_DataStartY) { ASSERT(m_Protocol != nullptr); - m_Protocol->SendMapColumn(a_ID, a_X, a_Y, a_Colors, a_Length, m_Scale); -} - - - - - -void cProtocolRecognizer::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale) -{ - ASSERT(m_Protocol != nullptr); - m_Protocol->SendMapDecorators(a_ID, a_Decorators, m_Scale); -} - - - - - -void cProtocolRecognizer::SendMapInfo(int a_ID, unsigned int a_Scale) -{ - ASSERT(m_Protocol != nullptr); - m_Protocol->SendMapInfo(a_ID, a_Scale); + m_Protocol->SendMapData(a_Map, a_DataStartX, a_DataStartY); } diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index 29eddcbc9..491645cff 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -84,9 +84,7 @@ public: virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; virtual void SendLoginSuccess (void) override; - virtual void SendMapColumn (int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length, unsigned int m_Scale) override; - virtual void SendMapDecorators (int a_ID, const cMapDecoratorList & a_Decorators, unsigned int m_Scale) override; - virtual void SendMapInfo (int a_ID, unsigned int a_Scale) override; + virtual void SendMapData (const cMap & a_Map, int a_DataStartX, int a_DataStartY) override; virtual void SendParticleEffect (const AString & a_ParticleName, float a_SrcX, float a_SrcY, float a_SrcZ, float a_OffsetX, float a_OffsetY, float a_OffsetZ, float a_ParticleData, int a_ParticleAmount) override; virtual void SendParticleEffect (const AString & a_ParticleName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array<int, 2> a_Data) override; virtual void SendPaintingSpawn (const cPainting & a_Painting) override; |