diff options
Diffstat (limited to 'src/Protocol/Protocol18x.cpp')
-rw-r--r-- | src/Protocol/Protocol18x.cpp | 232 |
1 files changed, 202 insertions, 30 deletions
diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index 17faca27e..4708d67c9 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -51,7 +51,7 @@ Implements the 1.8.x protocol classes: /** The slot number that the client uses to indicate "outside the window". */ -static const Int16 SLOT_NUM_OUTSIDE = -1; +static const Int16 SLOT_NUM_OUTSIDE = -999; @@ -234,18 +234,72 @@ void cProtocol180::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockV void cProtocol180::SendChat(const AString & a_Message) { + this->SendChatType(a_Message, ctChatBox); +} + + + + + +void cProtocol180::SendChat(const cCompositeChat & a_Message) +{ + this->SendChatType(a_Message, ctChatBox); +} + + + + + +void cProtocol180::SendChatSystem(const AString & a_Message) +{ + this->SendChatType(a_Message, ctSystem); +} + + + + + +void cProtocol180::SendChatSystem(const cCompositeChat & a_Message) +{ + this->SendChatType(a_Message, ctSystem); +} + + + + + +void cProtocol180::SendChatAboveActionBar(const AString & a_Message) +{ + this->SendChatType(a_Message, ctAboveActionBar); +} + + + + + +void cProtocol180::SendChatAboveActionBar(const cCompositeChat & a_Message) +{ + this->SendChatType(a_Message, ctAboveActionBar); +} + + + + + +void cProtocol180::SendChatType(const AString & a_Message, eChatType type) +{ ASSERT(m_State == 3); // In game mode? cPacketizer Pkt(*this, 0x02); // Chat Message packet Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Message).c_str())); - Pkt.WriteBEInt8(0); + Pkt.WriteBEInt8(type); } -void cProtocol180::SendChat(const cCompositeChat & a_Message) +void cProtocol180::SendChatType(const cCompositeChat & a_Message, eChatType type) { ASSERT(m_State == 3); // In game mode? @@ -255,7 +309,7 @@ void cProtocol180::SendChat(const cCompositeChat & a_Message) // Send the message to the client: cPacketizer Pkt(*this, 0x02); Pkt.WriteString(a_Message.CreateJsonString(ShouldUseChatPrefixes)); - Pkt.WriteBEInt8(0); + Pkt.WriteBEInt8(type); } @@ -542,6 +596,18 @@ void cProtocol180::SendHealth(void) +void cProtocol180::SendHideTitle(void) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x45); // Title packet + Pkt.WriteVarInt32(3); // Hide title +} + + + + + void cProtocol180::SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item) { ASSERT(m_State == 3); // In game mode? @@ -681,7 +747,7 @@ void cProtocol180::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decor cPacketizer Pkt(*this, 0x34); Pkt.WriteVarInt32(a_ID); Pkt.WriteBEUInt8(m_Scale); - Pkt.WriteVarInt32(a_Decorators.size()); + Pkt.WriteVarInt32(static_cast<UInt32>(a_Decorators.size())); for (cMapDecoratorList::const_iterator it = a_Decorators.begin(); it != a_Decorators.end(); ++it) { @@ -1065,6 +1131,18 @@ void cProtocol180::SendRemoveEntityEffect(const cEntity & a_Entity, int a_Effect +void cProtocol180::SendResetTitle(void) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x45); // Title packet + Pkt.WriteVarInt32(4); // Reset title +} + + + + + void cProtocol180::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) { if ((m_LastSentDimension == a_Dimension) && !a_ShouldIgnoreDimensionChecks) @@ -1167,6 +1245,52 @@ void cProtocol180::SendDisplayObjective(const AString & a_Objective, cScoreboard +void cProtocol180::SendSetSubTitle(const cCompositeChat & a_SubTitle) +{ + SendSetRawSubTitle(a_SubTitle.CreateJsonString(false)); +} + + + + + +void cProtocol180::SendSetRawSubTitle(const AString & a_SubTitle) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x45); // Title packet + Pkt.WriteVarInt32(1); // Set subtitle + + Pkt.WriteString(a_SubTitle); +} + + + + + +void cProtocol180::SendSetTitle(const cCompositeChat & a_Title) +{ + SendSetRawTitle(a_Title.CreateJsonString(false)); +} + + + + + +void cProtocol180::SendSetRawTitle(const AString & a_Title) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x45); // Title packet + Pkt.WriteVarInt32(0); // Set title + + Pkt.WriteString(a_Title); +} + + + + + void cProtocol180::SendSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) { ASSERT(m_State == 3); // In game mode? @@ -1374,6 +1498,22 @@ void cProtocol180::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) +void cProtocol180::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) +{ + ASSERT(m_State == 3); // In game mode? + + cPacketizer Pkt(*this, 0x45); // Title packet + Pkt.WriteVarInt32(2); // Set title display times + + Pkt.WriteBEInt32(a_FadeInTicks); + Pkt.WriteBEInt32(a_DisplayTicks); + Pkt.WriteBEInt32(a_FadeOutTicks); +} + + + + + void cProtocol180::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) { ASSERT(m_State == 3); // In game mode? @@ -1575,7 +1715,7 @@ bool cProtocol180::CompressPacket(const AString & a_Packet, AString & a_Compress // Compress the data: char CompressedData[MAX_COMPRESSED_PACKET_LEN]; - uLongf CompressedSize = compressBound(a_Packet.size()); + uLongf CompressedSize = compressBound(static_cast<uLongf>(a_Packet.size())); if (CompressedSize >= MAX_COMPRESSED_PACKET_LEN) { ASSERT(!"Too high packet size."); @@ -1584,7 +1724,7 @@ bool cProtocol180::CompressPacket(const AString & a_Packet, AString & a_Compress int Status = compress2( reinterpret_cast<Bytef *>(CompressedData), &CompressedSize, - reinterpret_cast<const Bytef *>(a_Packet.data()), a_Packet.size(), Z_DEFAULT_COMPRESSION + reinterpret_cast<const Bytef *>(a_Packet.data()), static_cast<uLongf>(a_Packet.size()), Z_DEFAULT_COMPRESSION ); if (Status != Z_OK) { @@ -1597,7 +1737,7 @@ bool cProtocol180::CompressPacket(const AString & a_Packet, AString & a_Compress Buffer.ReadAll(LengthData); Buffer.CommitRead(); - Buffer.WriteVarInt32(CompressedSize + LengthData.size()); + Buffer.WriteVarInt32(static_cast<UInt32>(CompressedSize + LengthData.size())); Buffer.WriteVarInt32(static_cast<UInt32>(a_Packet.size())); Buffer.ReadAll(LengthData); Buffer.CommitRead(); @@ -1770,7 +1910,7 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size) AString UncompressedData; if (m_State == 3) { - UInt32 NumBytesRead = m_ReceivedData.GetReadableSpace(); + UInt32 NumBytesRead = static_cast<UInt32>(m_ReceivedData.GetReadableSpace()); m_ReceivedData.ReadVarInt(CompressedSize); if (CompressedSize > PacketLen) { @@ -1781,17 +1921,16 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size) { // Decompress the data: AString CompressedData; - if (!m_ReceivedData.ReadString(CompressedData, CompressedSize)) + if (!m_ReceivedData.ReadString(CompressedData, CompressedSize) || (InflateString(CompressedData.data(), CompressedSize, UncompressedData) != Z_OK)) { m_Client->Kick("Compression failure"); return; } - InflateString(CompressedData.data(), CompressedSize, UncompressedData); - PacketLen = UncompressedData.size(); + PacketLen = static_cast<UInt32>(UncompressedData.size()); } else { - NumBytesRead -= m_ReceivedData.GetReadableSpace(); // How many bytes has the CompressedSize taken up? + NumBytesRead -= static_cast<UInt32>(m_ReceivedData.GetReadableSpace()); // How many bytes has the CompressedSize taken up? ASSERT(PacketLen > NumBytesRead); PacketLen -= NumBytesRead; } @@ -2265,7 +2404,7 @@ void cProtocol180::HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffe { return; } - m_Client->HandleCreativeInventory(SlotNum, Item, (SlotNum == SLOT_NUM_OUTSIDE) ? caLeftClickOutside : caLeftClick); + m_Client->HandleCreativeInventory(SlotNum, Item, (SlotNum == -1) ? caLeftClickOutside : caLeftClick); } @@ -2553,7 +2692,7 @@ void cProtocol180::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer) case 0x0206: Action = caNumber7; break; case 0x0207: Action = caNumber8; break; case 0x0208: Action = caNumber9; break; - case 0x0300: Action = caMiddleClick; break; + case 0x0302: Action = caMiddleClick; break; case 0x0400: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caLeftClickOutsideHoldNothing : caDropKey; break; case 0x0401: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightClickOutsideHoldNothing : caCtrlDropKey; break; case 0x0500: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caLeftPaintBegin : caUnknown; break; @@ -3202,7 +3341,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(Bat.IsHanging() ? 1 : 0); break; } // case mtBat - + case mtCreeper: { auto & Creeper = reinterpret_cast<const cCreeper &>(a_Mob); @@ -3212,7 +3351,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(Creeper.IsCharged() ? 1 : 0); break; } // case mtCreeper - + case mtEnderman: { auto & Enderman = reinterpret_cast<const cEnderman &>(a_Mob); @@ -3224,7 +3363,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(Enderman.IsScreaming() ? 1 : 0); break; } // case mtEnderman - + case mtGhast: { auto & Ghast = reinterpret_cast<const cGhast &>(a_Mob); @@ -3232,7 +3371,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(Ghast.IsCharging()); break; } // case mtGhast - + case mtHorse: { auto & Horse = reinterpret_cast<const cHorse &>(a_Mob); @@ -3249,10 +3388,6 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) { Flags |= 0x08; } - if (Horse.IsBaby()) - { - Flags |= 0x10; - } if (Horse.IsEating()) { Flags |= 0x20; @@ -3276,6 +3411,9 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEInt32(Appearance); a_Pkt.WriteBEUInt8(0x56); // Int at index 22 a_Pkt.WriteBEInt32(Horse.GetHorseArmour()); + + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(Horse.GetAge()); break; } // case mtHorse @@ -3287,17 +3425,38 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) break; } // case mtMagmaCube + case mtOcelot: + { + auto & Ocelot = reinterpret_cast<const cOcelot &>(a_Mob); + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(Ocelot.GetAge()); + break; + } // case mtOcelot + case mtPig: { auto & Pig = reinterpret_cast<const cPig &>(a_Mob); + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(Pig.GetAge()); a_Pkt.WriteBEUInt8(0x10); a_Pkt.WriteBEUInt8(Pig.IsSaddled() ? 1 : 0); break; } // case mtPig - + + case mtRabbit: + { + auto & Rabbit = reinterpret_cast<const cRabbit &>(a_Mob); + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(Rabbit.GetAge()); + break; + } // case mtRabbit + case mtSheep: { auto & Sheep = reinterpret_cast<const cSheep &>(a_Mob); + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(Sheep.GetAge()); + a_Pkt.WriteBEUInt8(0x10); Byte SheepMetadata = 0; SheepMetadata = Sheep.GetFurColor(); @@ -3308,7 +3467,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(SheepMetadata); break; } // case mtSheep - + case mtSkeleton: { auto & Skeleton = reinterpret_cast<const cSkeleton &>(a_Mob); @@ -3316,7 +3475,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(Skeleton.IsWither() ? 1 : 0); break; } // case mtSkeleton - + case mtSlime: { auto & Slime = reinterpret_cast<const cSlime &>(a_Mob); @@ -3330,9 +3489,11 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) auto & Villager = reinterpret_cast<const cVillager &>(a_Mob); a_Pkt.WriteBEUInt8(0x50); a_Pkt.WriteBEInt32(Villager.GetVilType()); + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(Villager.GetAge()); break; } // case mtVillager - + case mtWitch: { auto & Witch = reinterpret_cast<const cWitch &>(a_Mob); @@ -3350,7 +3511,7 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEFloat(static_cast<float>(a_Mob.GetHealth())); break; } // case mtWither - + case mtWolf: { auto & Wolf = reinterpret_cast<const cWolf &>(a_Mob); @@ -3376,20 +3537,31 @@ void cProtocol180::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) a_Pkt.WriteBEUInt8(Wolf.IsBegging() ? 1 : 0); a_Pkt.WriteBEUInt8(0x14); a_Pkt.WriteBEUInt8(Wolf.GetCollarColor()); + + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(Wolf.GetAge()); break; } // case mtWolf - + case mtZombie: { auto & Zombie = reinterpret_cast<const cZombie &>(a_Mob); a_Pkt.WriteBEUInt8(0x0c); - a_Pkt.WriteBEUInt8(Zombie.IsBaby() ? 1 : 0); + a_Pkt.WriteBEInt8(Zombie.IsBaby() ? 1 : -1); a_Pkt.WriteBEUInt8(0x0d); a_Pkt.WriteBEUInt8(Zombie.IsVillagerZombie() ? 1 : 0); a_Pkt.WriteBEUInt8(0x0e); a_Pkt.WriteBEUInt8(Zombie.IsConverting() ? 1 : 0); break; } // case mtZombie + + case mtZombiePigman: + { + auto & ZombiePigman = reinterpret_cast<const cZombiePigman &>(a_Mob); + a_Pkt.WriteBEUInt8(0x0c); + a_Pkt.WriteBEInt8(ZombiePigman.IsBaby() ? 1 : -1); + break; + } // case mtZombiePigman } // switch (a_Mob.GetType()) } |