14 #include "../Entities/Boat.h" 15 #include "../Entities/Minecart.h" 16 #include "../Entities/Pickup.h" 17 #include "../Entities/Player.h" 18 #include "../Entities/ItemFrame.h" 19 #include "../Entities/ArrowEntity.h" 20 #include "../Entities/FireworkEntity.h" 21 #include "../Entities/SplashPotionEntity.h" 23 #include "../Mobs/IncludeAllMonsters.h" 26 #include "../Server.h" 27 #include "../ClientHandle.h" 28 #include "../Bindings/PluginManager.h" 41 #pragma clang diagnostic push 42 #pragma clang diagnostic ignored "-Wduplicate-enum" 92 _FIREBALL_NEXT = _ENTITY_NEXT,
102 _HANGING_NEXT = _ENTITY_NEXT,
139 _AMBIENT_NEXT = _INSENTIENT_NEXT,
145 _CREATURE_NEXT = _INSENTIENT_NEXT,
155 _ANIMAL_NEXT = _AGEABLE_NEXT,
160 _ABSTRACT_HORSE_NEXT,
202 _GOLEM_NEXT = _CREATURE_NEXT,
213 _MONSTER_NEXT = _CREATURE_NEXT,
269 _FLYING_NEXT = _INSENTIENT_NEXT,
299 #pragma clang diagnostic pop // Restore ignored clang errors 306 #define HANDLE_READ(ByteBuf, Proc, Type, Var) \ 309 if (!ByteBuf.Proc(Var))\ 320 Super(a_Client, a_ServerAddress, a_ServerPort, a_State)
357 int BlockX, BlockY, BlockZ;
365 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, CursorX);
366 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, CursorY);
367 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, CursorZ);
379 auto NumPlayers =
static_cast<signed>(Server->
GetNumPlayers());
380 auto MaxPlayers =
static_cast<signed>(Server->
GetMaxPlayers());
386 Version[
"name"] =
"Cuberite 1.12";
391 Players[
"online"] = NumPlayers;
392 Players[
"max"] = MaxPlayers;
396 Json::Value Description;
397 Description[
"text"] = ServerDescription.c_str();
400 Json::Value ResponseValue;
401 ResponseValue[
"version"] = Version;
402 ResponseValue[
"players"] = Players;
403 ResponseValue[
"description"] = Description;
405 if (!Favicon.empty())
407 ResponseValue[
"favicon"] =
Printf(
"data:image/png;base64,%s", Favicon.c_str());
411 Json::FastWriter Writer;
454 auto & Player =
static_cast<const cPlayer &
>(a_Entity);
465 a_Pkt.
WriteBEFloat(static_cast<float>(Player.GetHealth()));
469 a_Pkt.
WriteBEUInt8(static_cast<UInt8>(Player.GetSkinParts()));
473 a_Pkt.
WriteBEUInt8(static_cast<UInt8>(Player.GetMainHand()));
480 WriteItem(a_Pkt, static_cast<const cPickup &>(a_Entity).GetItem());
489 auto & Minecart =
static_cast<const cMinecart &
>(a_Entity);
492 a_Pkt.
WriteVarInt32(static_cast<UInt32>((maxHealth - curHealth) * Minecart.LastDamage() * 4));
500 a_Pkt.
WriteBEFloat(static_cast<float>(Minecart.LastDamage() + 10));
505 const cItem & MinecartContent = RideableMinecart.GetContent();
506 if (!MinecartContent.
IsEmpty())
516 a_Pkt.
WriteVarInt32(static_cast<UInt32>(RideableMinecart.GetBlockHeight()));
527 a_Pkt.
WriteBool(static_cast<const cMinecartWithFurnace &>(Minecart).IsFueled());
535 switch (Projectile.GetProjectileKind())
541 a_Pkt.
WriteBEInt8(static_cast<const cArrowEntity &>(Projectile).IsCritical() ? 1 : 0);
548 WriteItem(a_Pkt, static_cast<const cFireworkEntity &>(Projectile).GetItem());
557 WriteItem(a_Pkt, static_cast<const cSplashPotionEntity &>(Projectile).GetItem());
575 auto & Boat =
static_cast<const cBoat &
>(a_Entity);
579 a_Pkt.
WriteVarInt32(static_cast<UInt32>(Boat.GetLastDamage()));
583 a_Pkt.
WriteVarInt32(static_cast<UInt32>(Boat.GetForwardDirection()));
591 a_Pkt.
WriteVarInt32(static_cast<UInt32>(Boat.GetMaterial()));
595 a_Pkt.
WriteBool(Boat.IsRightPaddleUsed());
599 a_Pkt.
WriteBool(Boat.IsLeftPaddleUsed());
606 auto & Frame =
static_cast<const cItemFrame &
>(a_Entity);
652 auto & Bat =
static_cast<const cBat &
>(a_Mob);
661 auto & Chicken =
static_cast<const cChicken &
>(a_Mob);
671 auto & Cow =
static_cast<const cCow &
>(a_Mob);
681 auto & Creeper =
static_cast<const cCreeper &
>(a_Mob);
692 a_Pkt.
WriteBool(Creeper.IsBurnedWithFlintAndSteel());
698 auto & Enderman =
static_cast<const cEnderman &
>(a_Mob);
702 Carried |=
static_cast<UInt32>(Enderman.GetCarriedBlock() << 4);
703 Carried |= Enderman.GetCarriedMeta();
714 auto & Ghast =
static_cast<const cGhast &
>(a_Mob);
726 auto & Horse =
static_cast<const cHorse &
>(a_Mob);
732 if (Horse.IsSaddled())
736 if (Horse.IsChested())
740 if (Horse.IsEating())
744 if (Horse.IsRearing())
748 if (Horse.IsMthOpen())
765 Appearance = Horse.GetHorseColor();
766 Appearance |= Horse.GetHorseStyle() << 8;
771 a_Pkt.
WriteVarInt32(static_cast<UInt32>(Horse.GetHorseArmour()));
781 auto & MagmaCube =
static_cast<const cMagmaCube &
>(a_Mob);
784 a_Pkt.
WriteVarInt32(static_cast<UInt32>(MagmaCube.GetSize()));
790 auto & Ocelot =
static_cast<const cOcelot &
>(a_Mob);
796 Int8 OcelotStatus = 0;
797 if (Ocelot.IsSitting())
811 a_Pkt.
WriteVarInt32(static_cast<UInt32>(Ocelot.GetOcelotType()));
818 auto & Pig =
static_cast<const cPig &
>(a_Mob);
834 auto & Rabbit =
static_cast<const cRabbit &
>(a_Mob);
841 a_Pkt.
WriteVarInt32(static_cast<UInt32>(Rabbit.GetRabbitType()));
847 auto & Sheep =
static_cast<const cSheep &
>(a_Mob);
855 Int8 SheepMetadata = 0;
856 SheepMetadata =
static_cast<Int8>(Sheep.GetFurColor());
857 if (Sheep.IsSheared())
859 SheepMetadata |= 0x10;
878 auto & Slime =
static_cast<const cSlime &
>(a_Mob);
887 auto & Villager =
static_cast<const cVillager &
>(a_Mob);
894 a_Pkt.
WriteVarInt32(static_cast<UInt32>(Villager.GetVilType()));
900 auto & Witch =
static_cast<const cWitch &
>(a_Mob);
909 auto & Wither =
static_cast<const cWither &
>(a_Mob);
920 auto & Wolf =
static_cast<const cWolf &
>(a_Mob);
926 if (Wolf.IsSitting())
952 a_Pkt.
WriteVarInt32(static_cast<UInt32>(Wolf.GetCollarColor()));
959 auto & Zombie =
static_cast<const cZombie &
>(a_Mob);
977 auto & ZombiePigman =
static_cast<const cZombiePigman &
>(a_Mob);
1012 ASSERT(!
"cProtocol_1_12::WriteMobMetadata: Recieved mob of invalid type");
1143 switch (a_PacketType)
1154 switch (a_PacketType)
1165 switch (a_PacketType)
1206 LOGWARNING(
"Received a packet in an unknown protocol state %d. Ignoring further packets.",
m_State);
1232 Super(a_Client, a_ServerAddress, a_ServerPort, a_State)
1285 auto NumPlayers =
static_cast<signed>(Server->
GetNumPlayers());
1286 auto MaxPlayers =
static_cast<signed>(Server->
GetMaxPlayers());
1291 Json::Value Version;
1292 Version[
"name"] =
"Cuberite 1.12.1";
1296 Json::Value Players;
1297 Players[
"online"] = NumPlayers;
1298 Players[
"max"] = MaxPlayers;
1302 Json::Value Description;
1303 Description[
"text"] = ServerDescription.c_str();
1306 Json::Value ResponseValue;
1307 ResponseValue[
"version"] = Version;
1308 ResponseValue[
"players"] = Players;
1309 ResponseValue[
"description"] = Description;
1310 if (!Favicon.empty())
1312 ResponseValue[
"favicon"] =
Printf(
"data:image/png;base64,%s", Favicon.c_str());
1316 Json::FastWriter Writer;
1332 switch (a_PacketType)
1343 switch (a_PacketType)
1354 switch (a_PacketType)
1395 LOGWARNING(
"Received a packet in an unknown protocol state %d. Ignoring further packets.",
m_State);
1426 (KeepAliveID <= std::numeric_limits<UInt32>::max()) &&
1443 auto NumPlayers =
static_cast<signed>(Server->
GetNumPlayers());
1444 auto MaxPlayers =
static_cast<signed>(Server->
GetMaxPlayers());
1449 Json::Value Version;
1450 Version[
"name"] =
"Cuberite 1.12.2";
1454 Json::Value Players;
1455 Players[
"online"] = NumPlayers;
1456 Players[
"max"] = MaxPlayers;
1460 Json::Value Description;
1461 Description[
"text"] = ServerDescription.c_str();
1464 Json::Value ResponseValue;
1465 ResponseValue[
"version"] = Version;
1466 ResponseValue[
"players"] = Players;
1467 ResponseValue[
"description"] = Description;
1468 if (!Favicon.empty())
1470 ResponseValue[
"favicon"] =
Printf(
"data:image/png;base64,%s", Favicon.c_str());
1474 Json::FastWriter Writer;
1488 LOGWARNING(
"Trying to send a KeepAlive packet to a player who's not yet fully logged in (%d). The protocol class prevented the packet.",
m_State);
virtual bool HandlePacket(cByteBuffer &a_ByteBuffer, UInt32 a_PacketType) override
Reads and handles the packet.
virtual void WriteMobMetadata(cPacketizer &a_Pkt, const cMonster &a_Mob) override
Writes the mob-specific metadata for the specified mob.
double GetPosY(void) const
virtual void HandlePacketEnchantItem(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketPlayerLook(cByteBuffer &a_ByteBuffer)
#define HANDLE_READ(ByteBuf, Proc, Type, Var)
virtual void HandlePacketPlayer(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketKeepAlive(cByteBuffer &a_ByteBuffer)
UInt32 m_State
State of the protocol.
double GetPitch(void) const
virtual void HandlePacketUpdateSign(cByteBuffer &a_ByteBuffer)
void WriteBEInt8(Int8 a_Value)
double GetPosX(void) const
eEntityType GetEntityType(void) const
eMonsterType GetMobType(void) const
void HandleKeepAlive(UInt32 a_KeepAliveID)
virtual void SendSpawnMob(const cMonster &a_Mob) override
size_t GetReadableSpace(void) const
Returns the number of bytes that are currently available for reading (may be less than UsedSpace due ...
void SendMessageInfo(const AString &a_Message)
double GetHeadYaw(void) const
const AString & GetCustomName(void) const
Gets the custom name of the monster.
eHand HandIntToEnum(Int32 a_Hand)
Converts the hand parameter received by the protocol into eHand constants.
double GetSpeedX(void) const
virtual UInt32 GetPacketID(ePacketType a_Packet) override
Get the packet ID for a given packet.
eBlockFace FaceIntToBlockFace(Int32 a_FaceInt)
Converts the BlockFace received by the protocol into eBlockFace constants.
virtual void HandlePacketBlockDig(cByteBuffer &a_ByteBuffer)
virtual void WriteEntityMetadata(cPacketizer &a_Pkt, const cEntity &a_Entity) override
Writes the metadata for the specified entity, not including the terminating 0xff. ...
virtual void HandlePacketPlayerPosLook(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketStatusPing(cByteBuffer &a_ByteBuffer)
virtual void WriteItem(cPacketizer &a_Pkt, const cItem &a_Item)
Writes the item data into a packet.
virtual void HandlePacketBoatSteer(cByteBuffer &a_ByteBuffer)
void HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, eHand a_Hand)
virtual void HandlePacketClientStatus(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketWindowClick(cByteBuffer &a_ByteBuffer)
void WriteBEInt16(Int16 a_Value)
virtual void HandlePacketPlayerAbilities(cByteBuffer &a_ByteBuffer)
virtual bool IsOnFire(void) const
virtual void HandlePacketClientSettings(cByteBuffer &a_ByteBuffer)
void PacketUnknown(UInt32 a_PacketType)
bool CallHookServerPing(cClientHandle &a_ClientHandle, AString &a_ServerDescription, int &a_OnlinePlayersCount, int &a_MaxPlayersCount, AString &a_Favicon)
bool HasCustomName(void) const
Returns true if the monster has a custom name.
virtual void SendResetTitle(void) override
virtual void HandlePacketUseItem(cByteBuffer &a_ByteBuffer)
void WriteBEUInt8(UInt8 a_Value)
virtual bool IsCrouched(void) const
const AString & GetDescription(void) const
void WriteString(const AString &a_Value)
double GetSpeedZ(void) const
The version 110 protocol, used by 1.9.3 and 1.9.4.
const AString & GetFaviconData(void) const
Returns base64 encoded favicon data (obtained from favicon.png)
void WriteBEInt32(Int32 a_Value)
virtual void HandlePacketVehicleMove(cByteBuffer &a_ByteBuffer)
virtual bool IsInvisible(void) const
virtual void HandlePacketSteerVehicle(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketTabComplete(cByteBuffer &a_ByteBuffer)
virtual void SendCollectEntity(const cEntity &a_Entity, const cPlayer &a_Player, int a_Count) override
virtual void HandlePacketPluginMessage(cByteBuffer &a_ByteBuffer)
bool IsCustomNameAlwaysVisible(void) const
Is the custom name of this monster always visible? If not, you only see the name when you sight the m...
virtual void HandlePacketChatMessage(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketBlockPlace(cByteBuffer &a_ByteBuffer) override
size_t GetMaxPlayers(void) const
virtual void HandlePacketStatusRequest(cByteBuffer &a_ByteBuffer) override
virtual void HandleConfirmTeleport(cByteBuffer &a_ByteBuffer)
void WriteByteAngle(double a_Angle)
Writes the specified angle using a single byte.
virtual void HandlePacketSpectate(cByteBuffer &a_ByteBuffer)
cPlayer * GetPlayer(void)
virtual void SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) override
virtual void HandlePacketAnimation(cByteBuffer &a_ByteBuffer)
AString & Printf(AString &str, const char *format, fmt::ArgList args)
Output the formatted text into the string.
virtual void SendHideTitle(void) override
float GetHealth(void) const
Returns the health of this entity.
virtual void HandlePacketLoginEncryptionResponse(cByteBuffer &a_ByteBuffer)
void LOGWARNING(const char *a_Format, fmt::ArgList a_ArgList)
size_t GetNumPlayers(void) const
An object that can store incoming bytes and lets its clients read the bytes sequentially The bytes ar...
void WriteBEDouble(double a_Value)
float GetMaxHealth(void) const
bool SkipRead(size_t a_Count)
Skips reading by a_Count bytes; returns false if not enough bytes in the ringbuffer.
virtual UInt32 GetPacketID(ePacketType a_Packet) override
Get the packet ID for a given packet.
double GetYaw(void) const
virtual bool IsSprinting(void) const
virtual void HandlePacketStatusRequest(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketCraftingBookData(cByteBuffer &a_ByteBuffer)
cServer * GetServer(void)
double GetSpeedY(void) const
virtual void SendKeepAlive(UInt32 a_PingID) override
virtual bool HandlePacket(cByteBuffer &a_ByteBuffer, UInt32 a_PacketType) override
Reads and handles the packet.
virtual void HandlePacketUseEntity(cByteBuffer &a_ByteBuffer)
Composes an individual packet in the protocol's m_OutPacketBuffer; sends it just before being destruc...
void ForgeAugmentServerListPing(Json::Value &a_Response)
Add the Forge mod list to the server ping response.
cProtocol_1_12(cClientHandle *a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State)
void WriteVarInt32(UInt32 a_Value)
void WriteBEFloat(float a_Value)
virtual bool IsRclking(void) const
virtual void HandlePacketPlayerPos(cByteBuffer &a_ByteBuffer)
cProtocol_1_12_1(cClientHandle *a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State)
double GetPosZ(void) const
void WriteBool(bool a_Value)
virtual UInt32 GetPacketID(ePacketType a_Packet) override
Get the packet ID for a given packet.
virtual void HandlePacketWindowClose(cByteBuffer &a_ByteBuffer)
void WriteBEUInt64(UInt64 a_Value)
std::enable_if< std::is_arithmetic< T >::value, C >::type FloorC(T a_Value)
Floors a value, then casts it to C (an int by default)
virtual void HandlePacketStatusRequest(cByteBuffer &a_ByteBuffer) override
bool ReadPosition64(int &a_BlockX, int &a_BlockY, int &a_BlockZ)
ePacketType
Logical types of outgoing packets.
virtual void HandlePacketKeepAlive(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketLoginStart(cByteBuffer &a_ByteBuffer)
void WriteBEInt64(Int64 a_Value)
UInt32 GetUniqueID(void) const
virtual void HandlePacketSlotSelect(cByteBuffer &a_ByteBuffer)
cPluginManager * GetPluginManager(void)
virtual void HandlePacketAdvancementTab(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketCreativeInventoryAction(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketEntityAction(cByteBuffer &a_ByteBuffer)