17 #include "json/json.h" 20 #include "../mbedTLS++/Sha1Checksum.h" 23 #include "../ClientHandle.h" 25 #include "../Server.h" 27 #include "../StringCompression.h" 28 #include "../CompositeChat.h" 29 #include "../Statistics.h" 31 #include "../WorldStorage/FastNBT.h" 33 #include "../Entities/ExpOrb.h" 34 #include "../Entities/Minecart.h" 35 #include "../Entities/FallingBlock.h" 36 #include "../Entities/Painting.h" 37 #include "../Entities/Pickup.h" 38 #include "../Entities/Player.h" 39 #include "../Entities/ItemFrame.h" 40 #include "../Entities/ArrowEntity.h" 41 #include "../Entities/FireworkEntity.h" 42 #include "../Entities/SplashPotionEntity.h" 44 #include "../Items/ItemSpawnEgg.h" 46 #include "../Mobs/IncludeAllMonsters.h" 47 #include "../UI/HorseWindow.h" 49 #include "../BlockEntities/BeaconEntity.h" 50 #include "../BlockEntities/CommandBlockEntity.h" 51 #include "../BlockEntities/MobHeadEntity.h" 52 #include "../BlockEntities/MobSpawnerEntity.h" 53 #include "../BlockEntities/FlowerPotEntity.h" 54 #include "../Bindings/PluginManager.h" 71 #define HANDLE_READ(ByteBuf, Proc, Type, Var) \ 74 if (!ByteBuf.Proc(Var))\ 84 #define HANDLE_PACKET_READ(ByteBuf, Proc, Type, Var) \ 88 if (!ByteBuf.Proc(Var)) \ 90 ByteBuf.CheckValid(); \ 93 ByteBuf.CheckValid(); \ 120 m_ServerAddress(a_ServerAddress),
121 m_ServerPort(a_ServerPort),
123 m_IsTeleportIdConfirmed(true),
124 m_OutstandingTeleportId(0),
125 m_ReceivedData(32
KiB),
132 if (Params.size() >= 2)
136 if (Params[1] ==
"FML")
138 LOGD(
"Forge client connected!");
141 else if (Params.size() == 4)
149 LOGD(
"Player at %s connected via BungeeCord", Params[1].c_str());
159 if (!reader.parse(Params[3], root))
161 LOGERROR(
"Unable to parse player properties: '%s'", Params[3]);
170 LOG(
"BungeeCord is disabled, but client sent additional data, set AllowBungeeCord=1 if you want to allow it");
175 LOG(
"Unknown additional data sent in server address (BungeeCord/FML?): %zu parameters", Params.size());
183 static int sCounter = 0;
188 static_cast<unsigned>(time(
nullptr)),
194 LOG(
"Cannot log communication to file, the log file \"%s\" cannot be opened for writing.", FileName.c_str());
210 size_t NumBytes = (a_Size >
sizeof(Decrypted)) ?
sizeof(Decrypted) : a_Size;
275 Pkt.
WriteVarInt32((static_cast<UInt32>(a_BlockType) << 4) | (static_cast<UInt32>(a_BlockMeta) & 15));
290 for (sSetBlockVector::const_iterator itr = a_Changes.begin(), end = a_Changes.end(); itr != end; ++itr)
292 Int16 Coords =
static_cast<Int16>(itr->m_RelY | (itr->m_RelZ << 8) | (itr->m_RelX << 12));
294 Pkt.
WriteVarInt32(static_cast<UInt32>(itr->m_BlockType & 0xFFF) << 4 | (itr->m_BlockMeta & 0xF));
357 SendData(ChunkData.data(), ChunkData.size());
635 Pkt.
WriteBEUInt32(static_cast<UInt32>(a_BlocksAffected.size()));
636 for (cVector3iArray::const_iterator itr = a_BlocksAffected.begin(), end = a_BlocksAffected.end(); itr != end; ++itr)
681 ASSERT((a_ItemIndex >= 0) && (a_ItemIndex <= 8));
723 LOG(
"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);
820 double PosX = a_Painting.
GetPosX();
821 double PosY = a_Painting.
GetPosY();
822 double PosZ = a_Painting.
GetPosZ();
830 Pkt.
WritePosition64(static_cast<Int32>(PosX), static_cast<Int32>(PosY), static_cast<Int32>(PosZ));
850 Pkt.
WriteBEUInt8(static_cast<Byte>((static_cast<Int32>(Decorator.GetType()) << 4) | (Decorator.GetRot() & 0xF)));
851 Pkt.
WriteBEUInt8(static_cast<UInt8>(Decorator.GetPixelX()));
852 Pkt.
WriteBEUInt8(static_cast<UInt8>(Decorator.GetPixelZ()));
860 for (
auto itr = a_Map.
GetData().cbegin(); itr != a_Map.
GetData().cend(); ++itr)
1019 for (
auto & Node : Properties)
1022 Pkt.
WriteString(Node.get(
"value",
"").asString());
1023 AString Signature = Node.get(
"signature",
"").asString();
1024 if (Signature.empty())
1078 if (ClientHandle !=
nullptr)
1084 Pkt.
WriteVarInt32(static_cast<UInt32>(ClientHandle->GetPing()));
1101 if (a_CustomName.empty())
1203 Pkt.
WriteBuf(a_Message.data(), a_Message.size());
1256 if ((a_Mode == 0) || (a_Mode == 2))
1433 double PosX = a_Entity.
GetPosX();
1434 double PosZ = a_Entity.
GetPosZ();
1435 double Yaw = a_Entity.
GetYaw();
1436 if (a_ObjectType == 71)
1495 size_t Count =
static_cast<size_t>(
statCount);
1496 for (
size_t i = 0; i < Count; ++i)
1517 for (AStringVector::const_iterator itr = a_Results.begin(), end = a_Results.end(); itr != end; ++itr)
1579 if (!a_DoDaylightCycle)
1582 a_TimeOfDay = std::min(-a_TimeOfDay, -1LL);
1622 default:
ASSERT(!
"Unhandled or unimplemented BlockEntity update request!");
break;
1640 Json::StyledWriter JsonWriter;
1641 AString Lines[] = { a_Line1, a_Line2, a_Line3, a_Line4 };
1642 for (
size_t i = 0; i <
ARRAYCOUNT(Lines); i++)
1644 Json::Value RootValue;
1645 RootValue[
"text"] = Lines[i];
1646 Pkt.
WriteString(JsonWriter.write(RootValue).c_str());
1693 for (cItems::const_iterator itr = Slots.begin(), end = Slots.end(); itr != end; ++itr)
1776 uLongf CompressedSize = compressBound(static_cast<uLongf>(a_Packet.size()));
1779 ASSERT(!
"Too high packet size.");
1783 int Status = compress2(
1784 reinterpret_cast<Bytef *>(CompressedData), &CompressedSize,
1785 reinterpret_cast<const Bytef *>(a_Packet.data()), static_cast<uLongf>(a_Packet.size()), Z_DEFAULT_COMPRESSION
1798 Buffer.
WriteVarInt32(static_cast<UInt32>(CompressedSize + LengthData.size()));
1803 a_CompressedData.clear();
1804 a_CompressedData.reserve(LengthData.size() + CompressedSize);
1805 a_CompressedData.append(LengthData.data(), LengthData.size());
1806 a_CompressedData.append(CompressedData, CompressedSize);
1816 static std::map<AString, int> ParticleMap;
1817 if (ParticleMap.empty())
1820 ParticleMap[
"explode"] = 0;
1821 ParticleMap[
"largeexplode"] = 1;
1822 ParticleMap[
"hugeexplosion"] = 2;
1823 ParticleMap[
"fireworksspark"] = 3;
1824 ParticleMap[
"bubble"] = 4;
1825 ParticleMap[
"splash"] = 5;
1826 ParticleMap[
"wake"] = 6;
1827 ParticleMap[
"suspended"] = 7;
1828 ParticleMap[
"depthsuspend"] = 8;
1829 ParticleMap[
"crit"] = 9;
1830 ParticleMap[
"magiccrit"] = 10;
1831 ParticleMap[
"smoke"] = 11;
1832 ParticleMap[
"largesmoke"] = 12;
1833 ParticleMap[
"spell"] = 13;
1834 ParticleMap[
"instantspell"] = 14;
1835 ParticleMap[
"mobspell"] = 15;
1836 ParticleMap[
"mobspellambient"] = 16;
1837 ParticleMap[
"witchmagic"] = 17;
1838 ParticleMap[
"dripwater"] = 18;
1839 ParticleMap[
"driplava"] = 19;
1840 ParticleMap[
"angryvillager"] = 20;
1841 ParticleMap[
"happyvillager"] = 21;
1842 ParticleMap[
"townaura"] = 22;
1843 ParticleMap[
"note"] = 23;
1844 ParticleMap[
"portal"] = 24;
1845 ParticleMap[
"enchantmenttable"] = 25;
1846 ParticleMap[
"flame"] = 26;
1847 ParticleMap[
"lava"] = 27;
1848 ParticleMap[
"footstep"] = 28;
1849 ParticleMap[
"cloud"] = 29;
1850 ParticleMap[
"reddust"] = 30;
1851 ParticleMap[
"snowballpoof"] = 31;
1852 ParticleMap[
"snowshovel"] = 32;
1853 ParticleMap[
"slime"] = 33;
1854 ParticleMap[
"heart"] = 34;
1855 ParticleMap[
"barrier"] = 35;
1856 ParticleMap[
"iconcrack"] = 36;
1857 ParticleMap[
"blockcrack"] = 37;
1858 ParticleMap[
"blockdust"] = 38;
1859 ParticleMap[
"droplet"] = 39;
1860 ParticleMap[
"take"] = 40;
1861 ParticleMap[
"mobappearance"] = 41;
1862 ParticleMap[
"dragonbreath"] = 42;
1863 ParticleMap[
"endrod"] = 43;
1864 ParticleMap[
"damageindicator"] = 44;
1865 ParticleMap[
"sweepattack"] = 45;
1866 ParticleMap[
"fallingdust"] = 46;
1867 ParticleMap[
"totem"] = 47;
1868 ParticleMap[
"spit"] = 48;
1872 if (ParticleMap.find(ParticleName) == ParticleMap.end())
1874 LOGWARNING(
"Unknown particle: %s", a_ParticleName.c_str());
1875 ASSERT(!
"Unknown particle");
1879 return ParticleMap[ParticleName];
1888 switch (a_ObjectData)
1936 m_CommLogFile.
Printf(
"Incoming data, %zu (0x%zx) unparsed bytes already present in buffer:\n%s\n",
1937 AllData.size(), AllData.size(), Hex.c_str()
1943 static_cast<unsigned>(a_Size), static_cast<unsigned>(a_Size), Hex.c_str()
1973 UInt32 UncompressedSize = 0;
1986 ASSERT(PacketLen > NumBytesRead);
1987 PacketLen -= NumBytesRead;
1989 if (UncompressedSize > 0)
1994 if (
InflateString(CompressedData.data(), PacketLen, UncompressedData) != Z_OK)
1999 PacketLen =
static_cast<UInt32>(UncompressedData.size());
2000 if (PacketLen != UncompressedSize)
2002 m_Client->
Kick(
"Wrong uncompressed packet size given");
2010 if (UncompressedSize == 0)
2018 VERIFY(bb.
Write(UncompressedData.data(), UncompressedData.size()));
2039 ASSERT(PacketData.size() > 0);
2040 PacketData.resize(PacketData.size() - 1);
2042 CreateHexDump(PacketDataHex, PacketData.data(), PacketData.size(), 16);
2043 m_CommLogFile.
Printf(
"Next incoming packet is type %u (0x%x), length %u (0x%x) at state %d. Payload:\n%s\n",
2044 PacketType, PacketType, PacketLen, PacketLen,
m_State, PacketDataHex.c_str()
2051 LOGWARNING(
"Protocol 1.9: Unhandled packet: type 0x%x, state %d, length %u", PacketType,
m_State, PacketLen);
2058 Packet.resize(Packet.size() - 1);
2061 LOGD(
"Packet contents:\n%s", Out.c_str());
2077 LOGWARNING(
"Protocol 1.9: Wrong number of bytes read for packet 0x%x, state %d. Read %zu bytes, packet contained %u bytes",
2084 m_CommLogFile.
Printf(
"^^^^^^ Wrong number of bytes read for this packet (exp %d left, got %zu left) ^^^^^^\n\n\n",
2090 ASSERT(!
"Read wrong number of bytes!");
2106 m_CommLogFile.
Printf(
"Protocol 1.9: There are %zu (0x%zx) bytes of non-parse-able data left in the buffer:\n%s",
2209 switch (a_PacketType)
2220 switch (a_PacketType)
2231 switch (a_PacketType)
2269 LOGWARNING(
"Received a packet in an unknown protocol state %d. Ignoring further packets.",
m_State);
2310 auto NumPlayers =
static_cast<signed>(Server->
GetNumPlayers());
2311 auto MaxPlayers =
static_cast<signed>(Server->
GetMaxPlayers());
2316 Json::Value Version;
2317 Version[
"name"] =
"Cuberite 1.9";
2318 Version[
"protocol"] = 107;
2321 Json::Value Players;
2322 Players[
"online"] = NumPlayers;
2323 Players[
"max"] = MaxPlayers;
2327 Json::Value Description;
2328 Description[
"text"] = ServerDescription.c_str();
2331 Json::Value ResponseValue;
2332 ResponseValue[
"version"] = Version;
2333 ResponseValue[
"players"] = Players;
2334 ResponseValue[
"description"] = Description;
2336 if (!Favicon.empty())
2338 ResponseValue[
"favicon"] =
Printf(
"data:image/png;base64,%s", Favicon.c_str());
2341 Json::FastWriter Writer;
2342 AString Response = Writer.write(ResponseValue);
2354 UInt32 EncKeyLength, EncNonceLength;
2360 if (!a_ByteBuffer.
ReadString(EncKey, EncKeyLength))
2364 if (!a_ByteBuffer.
ReadVarInt(EncNonceLength))
2369 if (!a_ByteBuffer.
ReadString(EncNonce, EncNonceLength))
2375 LOGD(
"Too long encryption");
2383 int res = rsaDecryptor.
Decrypt(reinterpret_cast<const Byte *>(EncNonce.data()), EncNonce.size(),
reinterpret_cast<Byte *
>(DecryptedNonce),
sizeof(DecryptedNonce));
2386 LOGD(
"Bad nonce length: got %d, exp %d", res, 4);
2390 if (ntohl(DecryptedNonce[0]) != static_cast<unsigned>(reinterpret_cast<uintptr_t>(
this)))
2392 LOGD(
"Bad nonce value");
2399 res = rsaDecryptor.
Decrypt(reinterpret_cast<const Byte *>(EncKey.data()), EncKey.size(), DecryptedKey,
sizeof(DecryptedKey));
2402 LOGD(
"Bad key length");
2438 Pkt.
WriteBuf(PubKeyDer.data(), PubKeyDer.size());
2440 Pkt.
WriteBEInt32(static_cast<int>(reinterpret_cast<intptr_t>(
this)));
2467 int BlockX, BlockY, BlockZ;
2483 int BlockX, BlockY, BlockZ;
2503 HANDLE_READ(a_ByteBuffer, ReadBool,
bool, RightPaddle);
2504 HANDLE_READ(a_ByteBuffer, ReadBool,
bool, LeftPaddle);
2514 auto * Boat =
static_cast<cBoat *
>(Vehicle);
2539 HANDLE_READ(a_ByteBuffer, ReadBool,
bool, ChatColors);
2649 HANDLE_READ(a_ByteBuffer, ReadBool,
bool, IsOnGround);
2660 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, FlyingSpeed);
2661 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, WalkingSpeed);
2664 bool IsFlying =
false, CanFly =
false;
2665 if ((Flags & 2) != 0)
2669 if ((Flags & 4) != 0)
2683 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, Yaw);
2684 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, Pitch);
2685 HANDLE_READ(a_ByteBuffer, ReadBool,
bool, IsOnGround);
2695 HANDLE_READ(a_ByteBuffer, ReadBEDouble,
double, PosX);
2696 HANDLE_READ(a_ByteBuffer, ReadBEDouble,
double, PosY);
2697 HANDLE_READ(a_ByteBuffer, ReadBEDouble,
double, PosZ);
2698 HANDLE_READ(a_ByteBuffer, ReadBool,
bool, IsOnGround);
2712 HANDLE_READ(a_ByteBuffer, ReadBEDouble,
double, PosX);
2713 HANDLE_READ(a_ByteBuffer, ReadBEDouble,
double, PosY);
2714 HANDLE_READ(a_ByteBuffer, ReadBEDouble,
double, PosZ);
2715 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, Yaw);
2716 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, Pitch);
2717 HANDLE_READ(a_ByteBuffer, ReadBool,
bool, IsOnGround);
2734 if (Channel.substr(0, 3) ==
"MC|")
2741 LOGD(
"Protocol 1.8: Skipping garbage data at the end of a vanilla PluginMessage packet, %u bytes",
2773 if (!a_ByteBuffer.
ReadUUID(playerUUID))
2787 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, Sideways);
2788 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, Forward);
2791 if ((Flags & 0x2) != 0)
2795 else if ((Flags & 0x1) != 0)
2812 HANDLE_READ(a_ByteBuffer, ReadBool,
bool, AssumeCommand);
2813 HANDLE_READ(a_ByteBuffer, ReadBool,
bool, HasPosition);
2829 int BlockX, BlockY, BlockZ;
2836 for (
int i = 0; i < 4; i++)
2872 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, TargetX);
2873 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, TargetY);
2874 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, TargetZ);
2882 ASSERT(!
"Unhandled use entity type!");
2918 HANDLE_READ(a_ByteBuffer, ReadBEDouble,
double, xPos);
2919 HANDLE_READ(a_ByteBuffer, ReadBEDouble,
double, yPos);
2920 HANDLE_READ(a_ByteBuffer, ReadBEDouble,
double, zPos);
2921 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, yaw);
2922 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, pitch);
2953 switch ((Mode << 8) | Button)
2983 LOGWARNING(
"Unhandled window click mode / button combination: %d (0x%x)", (Mode << 8) | Button, (Mode << 8) | Button);
3008 if (a_Channel ==
"MC|AdvCdm")
3026 LOG(
"Unhandled MC|AdvCdm packet mode.");
3032 else if (a_Channel ==
"MC|Brand")
3040 else if (a_Channel ==
"MC|Beacon")
3047 else if (a_Channel ==
"MC|ItemName")
3053 else if (a_Channel ==
"MC|TrSel")
3059 LOG(
"Unhandled vanilla plugin channel: \"%s\".", a_Channel.c_str());
3075 Byte Encrypted[8192];
3078 size_t NumBytes = (a_Size >
sizeof(Encrypted)) ?
sizeof(Encrypted) : a_Size;
3116 if (!a_ByteBuffer.
ReadString(Metadata, a_ByteBuffer.
GetReadableSpace() - a_KeepRemainingBytes - 1) || (Metadata.size() == 0) || (Metadata[0] == 0))
3133 cParsedNBT NBT(a_Metadata.data(), a_Metadata.size());
3137 CreateHexDump(HexDump, a_Metadata.data(), std::max<size_t>(a_Metadata.size(), 1024), 16);
3138 LOGWARNING(
"Cannot parse NBT item metadata: %s at (%zu / %zu bytes)\n%s",
3139 NBT.GetErrorCode().message().c_str(), NBT.GetErrorPos(), a_Metadata.size(), HexDump.c_str()
3145 for (
int tag = NBT.GetFirstChild(NBT.GetRoot()); tag >= 0; tag = NBT.GetNextSibling(tag))
3147 AString TagName = NBT.GetName(tag);
3148 switch (NBT.GetType(tag))
3152 if ((TagName ==
"ench") || (TagName ==
"StoredEnchantments"))
3160 if (TagName ==
"display")
3162 for (
int displaytag = NBT.GetFirstChild(tag); displaytag >= 0; displaytag = NBT.GetNextSibling(displaytag))
3164 if ((NBT.GetType(displaytag) ==
TAG_String) && (NBT.GetName(displaytag) ==
"Name"))
3168 else if ((NBT.GetType(displaytag) ==
TAG_List) && (NBT.GetName(displaytag) ==
"Lore"))
3171 for (
int loretag = NBT.GetFirstChild(displaytag); loretag >= 0; loretag = NBT.GetNextSibling(loretag))
3173 a_Item.
m_LoreTable.push_back(NBT.GetString(loretag));
3176 else if ((NBT.GetType(displaytag) ==
TAG_Int) && (NBT.GetName(displaytag) ==
"color"))
3182 else if ((TagName ==
"Fireworks") || (TagName ==
"Explosion"))
3186 else if (TagName ==
"EntityTag")
3188 for (
int entitytag = NBT.GetFirstChild(tag); entitytag >= 0; entitytag = NBT.GetNextSibling(entitytag))
3190 if ((NBT.GetType(entitytag) ==
TAG_String) && (NBT.GetName(entitytag) ==
"id"))
3192 AString NBTName = NBT.GetString(entitytag);
3204 if (TagName ==
"RepairCost")
3212 if (TagName ==
"Potion")
3214 AString PotionEffect = NBT.GetString(tag);
3215 if (PotionEffect.find(
"minecraft:") == AString::npos)
3217 LOGD(
"Unknown or missing domain on potion effect name %s!", PotionEffect.c_str());
3221 if (PotionEffect.find(
"water") != AString::npos)
3227 if (PotionEffect.find(
"empty") != AString::npos)
3231 else if (PotionEffect.find(
"mundane") != AString::npos)
3235 else if (PotionEffect.find(
"thick") != AString::npos)
3239 else if (PotionEffect.find(
"awkward") != AString::npos)
3243 else if (PotionEffect.find(
"regeneration") != AString::npos)
3247 else if (PotionEffect.find(
"swiftness") != AString::npos)
3251 else if (PotionEffect.find(
"fire_resistance") != AString::npos)
3255 else if (PotionEffect.find(
"poison") != AString::npos)
3259 else if (PotionEffect.find(
"healing") != AString::npos)
3263 else if (PotionEffect.find(
"night_vision") != AString::npos)
3267 else if (PotionEffect.find(
"weakness") != AString::npos)
3271 else if (PotionEffect.find(
"strength") != AString::npos)
3275 else if (PotionEffect.find(
"slowness") != AString::npos)
3279 else if (PotionEffect.find(
"leaping") != AString::npos)
3283 else if (PotionEffect.find(
"harming") != AString::npos)
3287 else if (PotionEffect.find(
"water_breathing") != AString::npos)
3291 else if (PotionEffect.find(
"invisibility") != AString::npos)
3298 LOGD(
"Unknown potion type for effect name %s!", PotionEffect.c_str());
3302 if (PotionEffect.find(
"strong") != AString::npos)
3306 if (PotionEffect.find(
"long") != AString::npos)
3325 default:
LOGD(
"Unimplemented NBT data when parsing!");
break;
3344 Checksum.
Update(reinterpret_cast<const Byte *>(ServerID.c_str()), ServerID.length());
3345 Checksum.
Update(a_Key, 16);
3360 switch (a_BlockFace)
3385 ASSERT(!
"Unknown hand value");
3398 AString PacketData, CompressedPacket;
3402 if ((
m_State == 3) && (PacketLen >= 256))
3417 SendData(LengthData.data(), LengthData.size());
3425 SendData(LengthData.data(), LengthData.size());
3429 if (CompressedPacket.empty())
3432 SendData(PacketData.data(), PacketData.size());
3436 SendData(CompressedPacket.data(), CompressedPacket.size());
3443 ASSERT(PacketData.size() > 0);
3444 CreateHexDump(Hex, PacketData.data(), PacketData.size(), 16);
3445 m_CommLogFile.
Printf(
"Outgoing packet: type %s (translated to 0x%02x), length %u (0x%04x), state %d. Payload (incl. type):\n%s\n",
3447 PacketLen, PacketLen,
m_State, Hex
3574 default:
ASSERT(!
"Unknown potion effect");
break;
3578 PotionID =
"strong_" + PotionID;
3583 PotionID =
"long_" + PotionID;
3598 case 0x00: PotionID =
"mundane";
break;
3599 case 0x10: PotionID =
"awkward";
break;
3600 case 0x20: PotionID =
"thick";
break;
3606 PotionID =
"minecraft:" + PotionID;
3608 Writer.
AddString(
"Potion", PotionID.c_str());
3625 if (Result.size() == 0)
3630 a_Pkt.
WriteBuf(Result.data(), Result.size());
3645 auto & BeaconEntity =
static_cast<const cBeaconEntity &
>(a_BlockEntity);
3646 Writer.
AddInt(
"x", BeaconEntity.GetPosX());
3647 Writer.
AddInt(
"y", BeaconEntity.GetPosY());
3648 Writer.
AddInt(
"z", BeaconEntity.GetPosZ());
3649 Writer.
AddInt(
"Primary", BeaconEntity.GetPrimaryEffect());
3650 Writer.
AddInt(
"Secondary", BeaconEntity.GetSecondaryEffect());
3651 Writer.
AddInt(
"Levels", BeaconEntity.GetBeaconLevel());
3659 Writer.
AddByte(
"TrackOutput", 1);
3660 Writer.
AddInt(
"SuccessCount", CommandBlockEntity.GetResult());
3661 Writer.
AddInt(
"x", CommandBlockEntity.GetPosX());
3662 Writer.
AddInt(
"y", CommandBlockEntity.GetPosY());
3663 Writer.
AddInt(
"z", CommandBlockEntity.GetPosZ());
3664 Writer.
AddString(
"Command", CommandBlockEntity.GetCommand().c_str());
3670 if (!CommandBlockEntity.GetLastOutput().empty())
3672 Writer.
AddString(
"LastOutput",
Printf(
"{\"text\":\"%s\"}", CommandBlockEntity.GetLastOutput().c_str()));
3679 auto & MobHeadEntity =
static_cast<const cMobHeadEntity &
>(a_BlockEntity);
3680 Writer.
AddInt(
"x", MobHeadEntity.GetPosX());
3681 Writer.
AddInt(
"y", MobHeadEntity.GetPosY());
3682 Writer.
AddInt(
"z", MobHeadEntity.GetPosZ());
3683 Writer.
AddByte(
"SkullType", MobHeadEntity.GetType() & 0xFF);
3684 Writer.
AddByte(
"Rot", MobHeadEntity.GetRotation() & 0xFF);
3689 Writer.
AddString(
"Id", MobHeadEntity.GetOwnerUUID().ToShortString());
3690 Writer.
AddString(
"Name", MobHeadEntity.GetOwnerName());
3694 Writer.
AddString(
"Signature", MobHeadEntity.GetOwnerTextureSignature());
3695 Writer.
AddString(
"Value", MobHeadEntity.GetOwnerTexture());
3705 auto & FlowerPotEntity =
static_cast<const cFlowerPotEntity &
>(a_BlockEntity);
3706 Writer.
AddInt(
"x", FlowerPotEntity.GetPosX());
3707 Writer.
AddInt(
"y", FlowerPotEntity.GetPosY());
3708 Writer.
AddInt(
"z", FlowerPotEntity.GetPosZ());
3709 Writer.
AddInt(
"Item", static_cast<Int32>(FlowerPotEntity.GetItem().m_ItemType));
3710 Writer.
AddInt(
"Data", static_cast<Int32>(FlowerPotEntity.GetItem().m_ItemDamage));
3717 auto & MobSpawnerEntity =
static_cast<const cMobSpawnerEntity &
>(a_BlockEntity);
3718 Writer.
AddInt(
"x", MobSpawnerEntity.GetPosX());
3719 Writer.
AddInt(
"y", MobSpawnerEntity.GetPosY());
3720 Writer.
AddInt(
"z", MobSpawnerEntity.GetPosZ());
3724 Writer.
AddShort(
"Delay", MobSpawnerEntity.GetSpawnDelay());
3775 auto & Player =
static_cast<const cPlayer &
>(a_Entity);
3786 a_Pkt.
WriteBEFloat(static_cast<float>(Player.GetHealth()));
3790 a_Pkt.
WriteBEUInt8(static_cast<UInt8>(Player.GetSkinParts()));
3794 a_Pkt.
WriteBEUInt8(static_cast<UInt8>(Player.GetMainHand()));
3801 WriteItem(a_Pkt, static_cast<const cPickup &>(a_Entity).GetItem());
3810 auto & Minecart =
static_cast<const cMinecart &
>(a_Entity);
3813 a_Pkt.
WriteVarInt32(static_cast<UInt32>((maxHealth - curHealth) * Minecart.LastDamage() * 4));
3821 a_Pkt.
WriteBEFloat(static_cast<float>(Minecart.LastDamage() + 10));
3826 const cItem & MinecartContent = RideableMinecart.GetContent();
3827 if (!MinecartContent.
IsEmpty())
3837 a_Pkt.
WriteVarInt32(static_cast<UInt32>(RideableMinecart.GetBlockHeight()));
3848 a_Pkt.
WriteBool(static_cast<const cMinecartWithFurnace &>(Minecart).IsFueled());
3856 switch (Projectile.GetProjectileKind())
3862 a_Pkt.
WriteBEInt8(static_cast<const cArrowEntity &>(Projectile).IsCritical() ? 1 : 0);
3869 WriteItem(a_Pkt, static_cast<const cFireworkEntity &>(Projectile).GetItem());
3876 WriteItem(a_Pkt, static_cast<const cSplashPotionEntity &>(Projectile).GetItem());
3894 auto & Boat =
static_cast<const cBoat &
>(a_Entity);
3898 a_Pkt.
WriteVarInt32(static_cast<UInt32>(Boat.GetLastDamage()));
3902 a_Pkt.
WriteVarInt32(static_cast<UInt32>(Boat.GetForwardDirection()));
3910 a_Pkt.
WriteVarInt32(static_cast<UInt32>(Boat.GetMaterial()));
3914 a_Pkt.
WriteBool(Boat.IsRightPaddleUsed());
3918 a_Pkt.
WriteBool(Boat.IsLeftPaddleUsed());
3925 auto & Frame =
static_cast<const cItemFrame &
>(a_Entity);
3969 auto & Bat =
static_cast<const cBat &
>(a_Mob);
3978 auto & Chicken =
static_cast<const cChicken &
>(a_Mob);
3988 auto & Cow =
static_cast<const cCow &
>(a_Mob);
3998 auto & Creeper =
static_cast<const cCreeper &
>(a_Mob);
4009 a_Pkt.
WriteBool(Creeper.IsBurnedWithFlintAndSteel());
4015 auto & Enderman =
static_cast<const cEnderman &
>(a_Mob);
4019 Carried |=
static_cast<UInt32>(Enderman.GetCarriedBlock() << 4);
4020 Carried |= Enderman.GetCarriedMeta();
4025 a_Pkt.
WriteBool(Enderman.IsScreaming());
4031 auto & Ghast =
static_cast<const cGhast &
>(a_Mob);
4040 auto & Horse =
static_cast<const cHorse &
>(a_Mob);
4046 if (Horse.IsSaddled())
4050 if (Horse.IsChested())
4054 if (Horse.IsEating())
4058 if (Horse.IsRearing())
4062 if (Horse.IsMthOpen())
4072 a_Pkt.
WriteVarInt32(static_cast<UInt32>(Horse.GetHorseType()));
4077 Appearance = Horse.GetHorseColor();
4078 Appearance |= Horse.GetHorseStyle() << 8;
4083 a_Pkt.
WriteVarInt32(static_cast<UInt32>(Horse.GetHorseArmour()));
4093 auto & MagmaCube =
static_cast<const cMagmaCube &
>(a_Mob);
4096 a_Pkt.
WriteVarInt32(static_cast<UInt32>(MagmaCube.GetSize()));
4102 auto & Ocelot =
static_cast<const cOcelot &
>(a_Mob);
4112 auto & Pig =
static_cast<const cPig &
>(a_Mob);
4127 auto & Rabbit =
static_cast<const cRabbit &
>(a_Mob);
4134 a_Pkt.
WriteVarInt32(static_cast<UInt32>(Rabbit.GetRabbitType()));
4140 auto & Sheep =
static_cast<const cSheep &
>(a_Mob);
4148 Int8 SheepMetadata = 0;
4149 SheepMetadata =
static_cast<Int8>(Sheep.GetFurColor());
4150 if (Sheep.IsSheared())
4152 SheepMetadata |= 0x10;
4160 auto & Skeleton =
static_cast<const cSkeleton &
>(a_Mob);
4169 auto & Slime =
static_cast<const cSlime &
>(a_Mob);
4178 auto & Villager =
static_cast<const cVillager &
>(a_Mob);
4185 a_Pkt.
WriteVarInt32(static_cast<UInt32>(Villager.GetVilType()));
4191 auto & Witch =
static_cast<const cWitch &
>(a_Mob);
4200 auto & Wither =
static_cast<const cWither &
>(a_Mob);
4211 auto & Wolf =
static_cast<const cWolf &
>(a_Mob);
4216 Int8 WolfStatus = 0;
4217 if (Wolf.IsSitting())
4243 a_Pkt.
WriteVarInt32(static_cast<UInt32>(Wolf.GetCollarColor()));
4249 auto & Zombie =
static_cast<const cZombie &
>(a_Mob);
4266 auto & ZombiePigman =
static_cast<const cZombiePigman &
>(a_Mob);
4283 if (!a_Entity.
IsMob())
4305 Super(a_Client, a_ServerAddress, a_ServerPort, a_State)
4352 auto NumPlayers =
static_cast<signed>(Server->
GetNumPlayers());
4353 auto MaxPlayers =
static_cast<signed>(Server->
GetMaxPlayers());
4358 Json::Value Version;
4359 Version[
"name"] =
"Cuberite 1.9.1";
4360 Version[
"protocol"] = 108;
4363 Json::Value Players;
4364 Players[
"online"] = NumPlayers;
4365 Players[
"max"] = MaxPlayers;
4369 Json::Value Description;
4370 Description[
"text"] = ServerDescription.c_str();
4373 Json::Value ResponseValue;
4374 ResponseValue[
"version"] = Version;
4375 ResponseValue[
"players"] = Players;
4376 ResponseValue[
"description"] = Description;
4378 if (!Favicon.empty())
4380 ResponseValue[
"favicon"] =
Printf(
"data:image/png;base64,%s", Favicon.c_str());
4383 Json::FastWriter Writer;
4384 AString Response = Writer.write(ResponseValue);
4398 Super(a_Client, a_ServerAddress, a_ServerPort, a_State)
4410 auto NumPlayers =
static_cast<signed>(Server->
GetNumPlayers());
4411 auto MaxPlayers =
static_cast<signed>(Server->
GetMaxPlayers());
4416 Json::Value Version;
4417 Version[
"name"] =
"Cuberite 1.9.2";
4418 Version[
"protocol"] = 109;
4421 Json::Value Players;
4422 Players[
"online"] = NumPlayers;
4423 Players[
"max"] = MaxPlayers;
4427 Json::Value Description;
4428 Description[
"text"] = ServerDescription.c_str();
4431 Json::Value ResponseValue;
4432 ResponseValue[
"version"] = Version;
4433 ResponseValue[
"players"] = Players;
4434 ResponseValue[
"description"] = Description;
4436 if (!Favicon.empty())
4438 ResponseValue[
"favicon"] =
Printf(
"data:image/png;base64,%s", Favicon.c_str());
4441 Json::FastWriter Writer;
4442 AString Response = Writer.write(ResponseValue);
4456 Super(a_Client, a_ServerAddress, a_ServerPort, a_State)
4468 auto NumPlayers =
static_cast<signed>(Server->
GetNumPlayers());
4469 auto MaxPlayers =
static_cast<signed>(Server->
GetMaxPlayers());
4474 Json::Value Version;
4475 Version[
"name"] =
"Cuberite 1.9.4";
4476 Version[
"protocol"] = 110;
4479 Json::Value Players;
4480 Players[
"online"] = NumPlayers;
4481 Players[
"max"] = MaxPlayers;
4485 Json::Value Description;
4486 Description[
"text"] = ServerDescription.c_str();
4489 Json::Value ResponseValue;
4490 ResponseValue[
"version"] = Version;
4491 ResponseValue[
"players"] = Players;
4492 ResponseValue[
"description"] = Description;
4494 if (!Favicon.empty())
4496 ResponseValue[
"favicon"] =
Printf(
"data:image/png;base64,%s", Favicon.c_str());
4499 Json::FastWriter Writer;
4500 AString Response = Writer.write(ResponseValue);
4519 SendData(ChunkData.data(), ChunkData.size());
4536 Writer.
AddInt(
"x", a_BlockX);
4537 Writer.
AddInt(
"y", a_BlockY);
4538 Writer.
AddInt(
"z", a_BlockZ);
4541 Json::StyledWriter JsonWriter;
4543 Line1[
"text"] = a_Line1;
4544 Writer.
AddString(
"Text1", JsonWriter.write(Line1));
4546 Line2[
"text"] = a_Line2;
4547 Writer.
AddString(
"Text2", JsonWriter.write(Line2));
4549 Line3[
"text"] = a_Line3;
4550 Writer.
AddString(
"Text3", JsonWriter.write(Line3));
4552 Line4[
"text"] = a_Line4;
4553 Writer.
AddString(
"Text4", JsonWriter.write(Line4));
eType
All types of entity effects (numbers correspond to protocol / storage types)
cProtocol::ePacketType GetPacketType() const
static int GetParticleID(const AString &a_ParticleName)
The 1.8 protocol use a particle id instead of a string.
AString ToLongString() const
Converts the UUID to a long form string (i.e.
double GetPosY(void) const
virtual void HandlePacketEnchantItem(cByteBuffer &a_ByteBuffer)
virtual void SendScoreUpdate(const AString &a_Objective, const AString &a_Player, cObjective::Score a_Score, Byte a_Mode) override
virtual void SendSpawnVehicle(const cEntity &a_Vehicle, char a_VehicleType, char a_VehicleSubType) override
virtual void HandlePacketPlayerLook(cByteBuffer &a_ByteBuffer)
void Finalize(Checksum &a_Output)
Calculates and returns the final checksum.
virtual void SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ) override
Request the client to open up the sign editor for the sign (1.6+)
bool WriteVarInt32(UInt32 a_Value)
void HandleCreativeInventory(Int16 a_SlotNum, const cItem &a_HeldItem, eClickAction a_ClickAction)
Called when the client clicks the creative inventory window.
void HandleWindowClick(UInt8 a_WindowID, Int16 a_SlotNum, eClickAction a_ClickAction, const cItem &a_HeldItem)
virtual void HandlePacketPlayer(cByteBuffer &a_ByteBuffer)
#define HANDLE_PACKET_READ(ByteBuf, Proc, Type, Var)
void ReadAll(AString &a_Data)
Reads all available data into a_Data.
void WriteToNBTCompound(const cEnchantments &a_Enchantments, cFastNBTWriter &a_Writer, const AString &a_ListTagName)
Writes the enchantments into the specified NBT writer; begins with the LIST tag of the specified name...
virtual void HandlePacketKeepAlive(cByteBuffer &a_ByteBuffer)
bool m_IsTeleportIdConfirmed
The current teleport ID, and whether it has been confirmed by the client.
UInt32 m_State
State of the protocol.
double GetPitch(void) const
Byte GetProtocolFacing() const
Returns the direction in which the entity is facing.
virtual void SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) override
virtual void HandlePacketUpdateSign(cByteBuffer &a_ByteBuffer)
virtual void WriteEntityMetadata(cPacketizer &a_Pkt, const cEntity &a_Entity)
Writes the metadata for the specified entity, not including the terminating 0xff. ...
void WriteBEInt8(Int8 a_Value)
double GetPosX(void) const
eDimension
Dimension of a world.
StatValue GetValue(const eStatistic a_Stat) const
Return the value of the specified stat.
void Init(const Byte a_Key[16], const Byte a_IV[16])
Initializes the decryptor with the specified Key / IV.
eEntityType GetEntityType(void) const
void HandleEnchantItem(UInt8 a_WindowID, UInt8 a_Enchantment)
Called when the player enchants an Item in the Enchanting table UI.
eMonsterType GetMobType(void) const
void HandleKeepAlive(UInt32 a_KeepAliveID)
int GetXpLevel(void)
Gets the current level - XpLevel.
bool IsBothNameAndLoreEmpty(void) const
static cEntityEffect::eType GetPotionEffectType(short a_ItemDamage)
Translates the potion's damage value into the entity effect that the potion gives.
virtual bool IsCrouched(void) const override
virtual void HandlePacketStatusRequest(cByteBuffer &a_ByteBuffer)
void ParseItemMetadata(cItem &a_Item, const AString &a_Metadata)
Parses item metadata as read by ReadItem(), into the item enchantments.
void HandleAnimation(int a_Animation)
size_t GetReadableSpace(void) const
Returns the number of bytes that are currently available for reading (may be less than UsedSpace due ...
const Json::Value & GetProperties(void) const
virtual void SendPluginMessage(const AString &a_Channel, const AString &a_Message) override
virtual void SendData(const char *a_Data, size_t a_Size) override
Sends the data to the client, encrypting them if needed.
virtual void SendEntityEffect(const cEntity &a_Entity, int a_EffectID, int a_Amplifier, int a_Duration) override
virtual bool CanFly(void) const
Returns wheter the player can fly or not.
void HandlePlayerAbilities(bool a_CanFly, bool a_IsFlying, float FlyingSpeed, float WalkingSpeed)
BLOCKTYPE GetBlockType() const
Class that manages the statistics and achievements of a single player.
const AString & GetWindowTitle() const
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
cProtocol_1_9_2(cClientHandle *a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State)
int GetEquippedSlotNum(void)
Returns slot number of equiped item.
virtual void SendEntityVelocity(const cEntity &a_Entity) override
void WriteUUID(const cUUID &a_UUID)
Writes the specified UUID as a 128-bit BigEndian integer.
const AString GetWindowTypeName(void) const
Returns the textual representation of the window's type, such as "minecraft:chest".
void HandleOpenHorseInventory(UInt32 a_EntityID)
Handles a player opening their inventory while riding a horse.
cClientHandlePtr GetClientHandlePtr(void) const
Returns the SharedPtr to client handle associated with the player.
unsigned int AwardAchievement(const eStatistic a_Ach)
Awards the player an achievement.
eBlockFace FaceIntToBlockFace(Int32 a_FaceInt)
Converts the BlockFace received by the protocol into eBlockFace constants.
virtual void HandlePacketBlockDig(cByteBuffer &a_ByteBuffer)
bool ReadVarUTF8String(AString &a_Value)
virtual void SendSoundParticleEffect(const EffectID a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override
int GetWindowType(void) const
unsigned char BLOCKTYPE
The datatype used by blockdata.
virtual void SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, const AString &a_Line1, const AString &a_Line2, const AString &a_Line3, const AString &a_Line4) override
virtual void SendSetRawTitle(const AString &a_Title) override
void Init(const Byte a_Key[16], const Byte a_IV[16])
Initializes the decryptor with the specified Key / IV.
cAesCfb128Encryptor m_Encryptor
virtual void SendSoundEffect(const AString &a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override
virtual void HandlePacketPlayerPosLook(cByteBuffer &a_ByteBuffer)
Encapsulates an in-game world map.
void UpdatePaddles(bool rightPaddleUsed, bool leftPaddleUsed)
virtual void SendPlayerListUpdateDisplayName(const cPlayer &a_Player, const AString &a_CustomName) override
bool FromString(const AString &a_StringUUID)
Tries to interpret the string as a short or long form UUID and assign from it.
virtual void HandlePacketStatusPing(cByteBuffer &a_ByteBuffer)
void WriteBuf(const char *a_Data, size_t a_Size)
virtual void SendUpdateBlockEntity(cBlockEntity &a_BlockEntity) override
static void WriteToNBTCompound(const cFireworkItem &a_FireworkItem, cFastNBTWriter &a_Writer, const ENUM_ITEM_ID a_Type)
Writes firework NBT data to a Writer object.
virtual void SendDestroyEntity(const cEntity &a_Entity) override
void ProcessData(Byte *a_EncryptedOut, const Byte *a_PlainIn, size_t a_Length)
Encrypts a_Length bytes of the plain data; produces a_Length output bytes.
static AString PacketTypeToStr(cProtocol::ePacketType a_PacketType)
Returns the human-readable representation of the packet type.
cProtocol_1_9_0(cClientHandle *a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State)
virtual void SendHealth(void) override
static bool CreateFolder(const AString &a_FolderPath)
Creates a new folder with the specified name.
virtual void WriteItem(cPacketizer &a_Pkt, const cItem &a_Item)
Writes the item data into a packet.
virtual void SendHeldItemChange(int a_ItemIndex) override
Parses and contains the parsed data Also implements data accessor functions for tree traversal and va...
void AddShort(const AString &a_Name, Int16 a_Value)
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)
AString GetPlayerListName(void) const
Returns the name that is used in the playerlist.
void GetSlots(cPlayer &a_Player, cItems &a_Slots) const
Fills a_Slots with the slots read from m_SlotAreas[], for the specified player.
virtual void SendPlayerListRemovePlayer(const cPlayer &a_Player) override
virtual UInt32 GetPacketID(ePacketType a_Packet) override
Get the packet ID for a given packet.
cCriticalSection m_CSPacket
Provides synchronization for sending the entire packet at once.
static const Int16 SLOT_NUM_OUTSIDE
The slot number that the client uses to indicate "outside the window".
virtual void HandlePacketClientStatus(cByteBuffer &a_ByteBuffer)
bool ReadString(AString &a_String, size_t a_Count)
Reads a_Count bytes into a_String; returns true if successful.
void SetSkinParts(int a_Parts)
virtual void SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) override
virtual void SendChatRaw(const AString &a_MessageRaw, eChatType a_Type) override
const AString & GetPublicKeyDER(void) const
cFireworkItem m_FireworkItem
bool ReadUUID(cUUID &a_Value)
virtual void SendStatistics(const cStatManager &a_Manager) override
virtual void HandlePacketWindowClick(cByteBuffer &a_ByteBuffer)
int Printf(const char *a_Fmt, fmt::ArgList)
virtual void SendSetTitle(const cCompositeChat &a_Title) override
void WriteBEInt16(Int16 a_Value)
virtual void HandlePacketPlayerAbilities(cByteBuffer &a_ByteBuffer)
int GetFoodLevel(void) const
virtual bool IsOnFire(void) const
virtual void HandlePacketClientSettings(cByteBuffer &a_ByteBuffer)
void PacketUnknown(UInt32 a_PacketType)
void HandleSteerVehicle(float Forward, float Sideways)
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.
bool IsValid() const
Returns whether the color is a valid color.
#define HANDLE_READ(ByteBuf, Proc, Type, Var)
void AddByte(const AString &a_Name, unsigned char a_Value)
virtual void SendWholeInventory(const cWindow &a_Window) override
virtual bool HandlePacket(cByteBuffer &a_ByteBuffer, UInt32 a_PacketType)
Reads and handles the packet.
bool ShouldAuthenticate(void) const
Returns true if authentication has been turned on in server settings.
void HandleWindowClose(UInt8 a_WindowID)
virtual void HandlePacketUseItem(cByteBuffer &a_ByteBuffer)
int Decrypt(const Byte *a_EncryptedData, size_t a_EncryptedLength, Byte *a_DecryptedData, size_t a_DecryptedMaxLength)
Decrypts the data using RSAES-PKCS#1 algorithm.
virtual void SendPlayerPosition(void) override
void WriteBEUInt8(UInt8 a_Value)
BLOCKTYPE GetBlockType(void) const
virtual bool IsCrouched(void) const
void SetPitch(double a_Pitch)
const AString & GetDescription(void) const
virtual void SendRespawn(eDimension a_Dimension) override
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
void WriteString(const AString &a_Value)
int GetNumNonInventorySlots(void) const
Returns the number of slots, excluding the player's inventory (used for network protocols) ...
virtual void SendDisconnect(const AString &a_Reason) override
virtual void SendPaintingSpawn(const cPainting &a_Painting) override
std::vector< Vector3i > cVector3iArray
void HandleNPCTrade(int a_SlotNum)
Called when the protocol receives a MC|TrSel packet, indicating that the player used a trade in the N...
double GetSpeedZ(void) const
void ReplaceString(AString &iHayStack, const AString &iNeedle, const AString &iReplaceWith)
Replaces each occurence of iNeedle in iHayStack with iReplaceWith.
virtual void HandlePacketStatusRequest(cByteBuffer &a_ByteBuffer) override
bool HandleHandshake(const AString &a_Username)
Called when the protocol handshake has been received (for protocol versions that support it; otherwis...
virtual void SendTabCompletionResults(const AStringVector &a_Results) override
void HandleCommandBlockBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, const AString &a_NewCommand)
Called when the protocol receives a MC|AdvCdm plugin message, indicating that the player set a new co...
void AddReceivedData(const char *a_Data, size_t a_Size)
Adds the received (unencrypted) data to m_ReceivedData, parses complete packets.
void HandleTabCompletion(const AString &a_Text)
const AString & GetFaviconData(void) const
Returns base64 encoded favicon data (obtained from favicon.png)
void WriteBEInt32(Int32 a_Value)
void HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, bool a_IsOnGround)
Verifies and sets player position, performing relevant checks Calls relevant methods to process movem...
virtual void SendMapData(const cMap &a_Map, int a_DataStartX, int a_DataStartY) override
virtual void SendExperience(void) override
virtual void SendAttachEntity(const cEntity &a_Entity, const cEntity &a_Vehicle) override
Sending stuff to clients (alphabetically sorted):
cByteBuffer m_ReceivedData
Buffer for the received data.
virtual void HandlePacketVehicleMove(cByteBuffer &a_ByteBuffer)
void LOGERROR(const char *a_Format, fmt::ArgList a_ArgList)
void PacketError(UInt32 a_PacketType)
virtual void WriteMobMetadata(cPacketizer &a_Pkt, const cMonster &a_Mob)
Writes the mob-specific metadata for the specified mob.
virtual bool IsInvisible(void) const
virtual void HandlePacketBlockPlace(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketSteerVehicle(cByteBuffer &a_ByteBuffer)
virtual void WriteBlockEntity(cPacketizer &a_Pkt, const cBlockEntity &a_BlockEntity)
Writes the block entity data for the specified block entity into the packet.
void HandlePlayerMoveLook(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, float a_Rotation, float a_Pitch, bool a_IsOnGround)
void SetPosY(double a_PosY)
void HandlePlayerLook(float a_Rotation, float a_Pitch, bool a_IsOnGround)
void SendData(const char *a_Data, size_t a_Size)
AString EscapeString(const AString &a_Message)
Returns a copy of a_Message with all quotes and backslashes escaped by a backslash.
virtual void SendSetSubTitle(const cCompositeChat &a_SubTitle) override
eMonsterType
Identifies individual monster type, as well as their network type-ID.
virtual void SendEntityAnimation(const cEntity &a_Entity, char a_Animation) override
virtual void SendScoreboardObjective(const AString &a_Name, const AString &a_DisplayName, Byte a_Mode) override
static eMonsterType ItemDamageToMonsterType(short a_ItemDamage)
Converts the Spawn egg item damage to the monster type to spawn.
bool Write(const void *a_Bytes, size_t a_Count)
Writes the bytes specified to the ringbuffer.
virtual void SendEntityHeadLook(const cEntity &a_Entity) override
virtual void HandlePacketTabComplete(cByteBuffer &a_ByteBuffer)
virtual void SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) override
virtual void SendChat(const AString &a_Message, eChatType a_Type) override
unsigned int GetScale(void) const
static void ParseFromNBT(cFireworkItem &a_FireworkItem, const cParsedNBT &a_NBT, int a_TagIdx, const ENUM_ITEM_ID a_Type)
Reads NBT data from a NBT object and populates a FireworkItem with it.
virtual void HandlePacketPluginMessage(cByteBuffer &a_ByteBuffer)
virtual void SendGameMode(eGameMode a_GameMode) override
void SetMainHand(eMainHand a_Hand)
unsigned int GetID(void) const
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 SendDisplayObjective(const AString &a_Objective, cScoreboard::eDisplaySlot a_Display) override
eClickAction
Individual actions sent in the WindowClick packet.
void Kick(const AString &a_Reason)
std::vector< AString > AStringVector
virtual void HandlePacketChatMessage(cByteBuffer &a_ByteBuffer)
cStatManager & GetStatManager()
Return the associated statistic and achievement manager.
cProtocol_1_9_1(cClientHandle *a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State)
cEnchantments m_Enchantments
void CommitRead(void)
Removes the bytes that have been read from the ringbuffer.
const cColorList & GetData(void) const
const AString & GetServerID(void) const
size_t GetMaxPlayers(void) const
virtual void SendEntityRelMove(const cEntity &a_Entity, char a_RelX, char a_RelY, char a_RelZ) override
cProtocol_1_9_4(cClientHandle *a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State)
void WriteEntityProperties(cPacketizer &a_Pkt, const cEntity &a_Entity)
Writes the entity properties for the specified entity, including the Count field. ...
Container for a single chat message composed of multiple functional parts.
virtual void HandleConfirmTeleport(cByteBuffer &a_ByteBuffer)
virtual void SendResetTitle(void) override
void WriteBEUInt32(UInt32 a_Value)
virtual void SendUnloadChunk(int a_ChunkX, int a_ChunkZ) override
void Update(const Byte *a_Data, size_t a_Length)
Adds the specified data to the checksum.
cAesCfb128Decryptor m_Decryptor
static short GetPotionEffectIntensity(short a_ItemDamage)
Retrieves the intensity level from the potion's damage value.
void WriteByteAngle(double a_Angle)
Writes the specified angle using a single byte.
void SetProperties(const Json::Value &a_Properties)
Sets the player's properties, such as skin image and signature.
virtual bool IsOnGround(void) const
Returns whether the entity is on ground or not.
virtual void SendCollectEntity(const cEntity &a_Entity, const cPlayer &a_Player, int a_Count) override
virtual void HandlePacketSpectate(cByteBuffer &a_ByteBuffer)
int InflateString(const char *a_Data, size_t a_Length, AString &a_Uncompressed)
Uncompresses a_Data into a_Uncompressed using Inflate; returns Z_OK for success or Z_XXX error consta...
double GetSpawnY(void) const
virtual void SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) override
void SetUUID(const cUUID &a_UUID)
Sets the player's UUID, as used by the protocol.
virtual void SendPlayerAbilities(void) override
bool IsLoreEmpty(void) const
virtual void SendBlockBreakAnim(UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override
virtual void SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem &a_Item) override
cPlayer * GetPlayer(void)
bool IsFlying(void) const
Returns true if the player is currently flying.
short GetPing(void) const
bool ReadToByteBuffer(cByteBuffer &a_Dst, size_t a_NumBytes)
Reads the specified number of bytes and writes it into the destinatio bytebuffer. ...
virtual void SendPickupSpawn(const cPickup &a_Pickup) override
cFile m_CommLogFile
The logfile where the comm is logged, when g_ShouldLogComm is true.
virtual void SendLeashEntity(const cEntity &a_Entity, const cEntity &a_EntityLeashedTo) override
bool Open(const AString &iFileName, eMode iMode)
double GetNormalMaxSpeed(void) const
Gets the normal relative maximum speed.
const cUUID & GetUUID(void) const
Returns the player's UUID, as used by the protocol.
virtual void SendPlayerMaxSpeed(void) override
Informs the client of the maximum player speed (1.6.1+)
void HandleUseItem(eHand a_Hand)
Serializes one chunk's data to (possibly multiple) protocol versions.
bool ShouldAllowBungeeCord(void) const
Returns true if BungeeCord logins (that specify the player's UUID) are allowed.
float GetXpPercentage(void)
Gets the experience bar percentage - XpP.
virtual void HandlePacketAnimation(cByteBuffer &a_ByteBuffer)
virtual void SendUseBed(const cEntity &a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) override
bool CanReadBytes(size_t a_Count) const
Returns true if the specified amount of bytes are available for reading.
virtual void SendKeepAlive(UInt32 a_PingID) override
AString & Printf(AString &str, const char *format, fmt::ArgList args)
Output the formatted text into the string.
void SetClientBrand(const AString &a_ClientBrand)
Called by the protocol when it receives the MC|Brand plugin message.
virtual void SendDetachEntity(const cEntity &a_Entity, const cEntity &a_PreviousVehicle) override
void SetViewDistance(int a_ViewDistance)
Sets the maximal view distance.
float GetHealth(void) const
Returns the health of this entity.
void HandleEntitySprinting(UInt32 a_EntityID, bool a_IsSprinting)
virtual void HandlePacketLoginEncryptionResponse(cByteBuffer &a_ByteBuffer)
cRsaPrivateKey & GetPrivateKey(void)
void LOGWARNING(const char *a_Format, fmt::ArgList a_ArgList)
void HandleChat(const AString &a_Message)
Called when the protocol detects a chat packet.
static AString MobTypeToVanillaNBT(eMonsterType a_MobType)
Translates the MobType enum to the vanilla nbt name.
UInt32 m_OutstandingTeleportId
cByteBuffer m_OutPacketBuffer
Buffer for composing the outgoing packets, through cPacketizer.
virtual void SendWeather(eWeather a_Weather) override
Vector3d GetLastSentPos(void) const
Returns the last position we sent to all the clients.
virtual eDimension GetDimension(void) const override
void ResetRead(void)
Restarts next reading operation at the start of the ringbuffer.
size_t GetNumPlayers(void) const
An object that can store incoming bytes and lets its clients read the bytes sequentially The bytes ar...
void HandleEntityLeaveBed(UInt32 a_EntityID)
void HandlePluginMessage(const AString &a_Channel, const AString &a_Message)
int GetCurrentXp(void)
Gets the current experience.
virtual void SendEntityMetadata(const cEntity &a_Entity) override
void WriteBEDouble(double a_Value)
virtual void SendExperienceOrb(const cExpOrb &a_ExpOrb) override
virtual void HandlePacketStatusRequest(cByteBuffer &a_ByteBuffer) override
#define KiB
Allows arithmetic expressions like "32 KiB" (but consider using parenthesis around it...
void HandleSpectate(const cUUID &a_PlayerUUID)
float GetMaxHealth(void) const
const uLongf MAX_COMPRESSED_PACKET_LEN
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
void SendChat(const AString &a_Message, eMessageType a_ChatPrefix, const AString &a_AdditionalData="")
int GetNumSlots(void) const
Returns the total number of slots.
double GetSpawnZ(void) const
bool SkipRead(size_t a_Count)
Skips reading by a_Count bytes; returns false if not enough bytes in the ringbuffer.
virtual void SendLoginSuccess(void) override
virtual void SendPlayerMoveLook(void) override
bool ReadVarInt(T &a_Value)
Reads VarInt, assigns it to anything that can be assigned from an UInt64 (unsigned short...
virtual void SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override
double GetFoodSaturationLevel(void) const
const AString & Serialize(int a_Version, int a_ChunkX, int a_ChunkZ, const std::map< UInt32, UInt32 > &a_BlockTypeMap)
Serializes the contained chunk data into the specified protocol version.
virtual void SendEntityProperties(const cEntity &a_Entity) override
void StartEncryption(const Byte *a_Key)
virtual void SendHideTitle(void) override
double GetYaw(void) const
virtual void HandlePacketStatusRequest(cByteBuffer &a_ByteBuffer) override
const AString & GetResult(void) const
virtual bool IsSprinting(void) const
void HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, UInt8 a_Status)
NIBBLETYPE GetBlockMeta(void) const
virtual void SendWindowOpen(const cWindow &a_Window) override
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
void SetIsForgeClient()
Mark a client connection as using Forge.
Calculates a SHA1 checksum for data stream.
static eMonsterType StringToMobType(const AString &a_MobTypeName)
Translates MobType string to the enum, mtInvalidType if not recognized.
cEntity * GetAttached()
Gets entity (vehicle) attached to this entity.
size_t GetUsedSpace(void) const
Returns the number of bytes that are currently in the ringbuffer.
virtual void SendEntityRelMoveLook(const cEntity &a_Entity, char a_RelX, char a_RelY, char a_RelZ) override
cServer * GetServer(void)
static const UInt32 OFF_HAND
double GetSpeedY(void) const
double GetSprintingMaxSpeed(void) const
Gets the sprinting relative maximum speed.
Encapsulates an RSA private key used in PKI cryptography.
virtual void SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, const AString &a_Line1, const AString &a_Line2, const AString &a_Line3, const AString &a_Line4) override
virtual void HandlePacketUseEntity(cByteBuffer &a_ByteBuffer)
virtual void SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer &a_Serializer) override
static void FixItemFramePositions(int a_ObjectData, double &a_PosX, double &a_PosZ, double &a_Yaw)
Minecraft 1.8 use other locations to spawn the item frame.
void ProcessData(Byte *a_DecryptedOut, const Byte *a_EncryptedIn, size_t a_Length)
Decrypts a_Length bytes of the encrypted data; produces a_Length output bytes.
virtual void SendPlayerListUpdatePing(const cPlayer &a_Player) override
cByteBuffer m_OutPacketLenBuffer
Buffer for composing packet length (so that each cPacketizer instance doesn't allocate a new cPacketB...
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.
void AddString(const AString &a_Name, const AString &a_Value)
void LOG(const char *a_Format, fmt::ArgList a_ArgList)
const AString & GetUsername(void) const
AString & CreateHexDump(AString &a_Out, const void *a_Data, size_t a_Size, size_t a_BytesPerLine)
format binary data this way: 00001234: 31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 1234567890abcd...
void WritePosition64(int a_BlockX, int a_BlockY, int a_BlockZ)
Writes the specified block position as a single encoded 64-bit BigEndian integer. ...
double GetFlyingMaxSpeed(void) const
Gets the flying relative maximum speed.
void WriteVarInt32(UInt32 a_Value)
virtual void SendPacket(cPacketizer &a_Packet) override
Sends the packet to the client.
bool HandleLogin(const AString &a_Username)
Called when the protocol has finished logging the user in.
virtual void SendPlayerListAddPlayer(const cPlayer &a_Player) override
virtual bool IsSprinting(void) const override
virtual void SendLogin(const cPlayer &a_Player, const cWorld &a_World) override
RAII for cCriticalSection - locks the CS on creation, unlocks on destruction.
void WriteBEFloat(float a_Value)
AString CreateJsonString(bool a_ShouldUseChatPrefixes=true) const
void PacketBufferFull(void)
virtual void SendRemoveEntityEffect(const cEntity &a_Entity, int a_EffectID) override
virtual void DataReceived(const char *a_Data, size_t a_Size) override
Called when client sends some data:
virtual void SendWindowProperty(const cWindow &a_Window, short a_Property, short a_Value) override
void Flush(void)
Flushes all the bufferef output into the file (only when writing)
virtual void SendUnleashEntity(const cEntity &a_Entity) override
static bool CompressPacket(const AString &a_Packet, AString &a_Compressed)
Compress the packet.
virtual void SendEntityLook(const cEntity &a_Entity) override
bool IsHardcore(void) const
virtual bool IsRclking(void) const
void AddInt(const AString &a_Name, Int32 a_Value)
virtual void HandlePacketPlayerPos(cByteBuffer &a_ByteBuffer)
virtual void SendCameraSetTo(const cEntity &a_Entity) override
virtual void SendPlayerListUpdateGameMode(const cPlayer &a_Player) override
void HandleBeaconSelection(int a_PrimaryEffect, int a_SecondaryEffect)
Called when the protocol receives a MC|Beacon plugin message, indicating that the player set an effec...
virtual void HandleVanillaPluginMessage(cByteBuffer &a_ByteBuffer, const AString &a_Channel)
Parses Vanilla plugin messages into specific ClientHandle calls.
double GetPosZ(void) const
AStringVector m_LoreTable
bool IsGameModeCreative(void) const
Returns true if the player is in Creative mode, either explicitly, or by inheriting from current worl...
void HandleEntityCrouch(UInt32 a_EntityID, bool a_IsCrouching)
char GetWindowID(void) const
virtual void SendEntityStatus(const cEntity &a_Entity, char a_Status) override
virtual void SendExplosion(double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray &a_BlocksAffected, const Vector3d &a_PlayerMotion) override
virtual void SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector &a_Changes) override
virtual void SendPlayerSpawn(const cPlayer &a_Player) override
const cMapDecoratorList GetDecorators(void) const
void WriteBool(bool a_Value)
virtual UInt32 GetPacketID(ePacketType a_Packet) override
Get the packet ID for a given packet.
const cUUID & GetUUID(void) const
Returns the UUID that has been read from the client, or nil if not available.
void SetYaw(double a_Yaw)
void HandleUseEntity(UInt32 a_TargetEntityID, bool a_IsLeftClick)
virtual void SendSpawnMob(const cMonster &a_Mob) override
void HandleSlotSelected(Int16 a_SlotNum)
void SetPosX(double a_PosX)
virtual void HandlePacketWindowClose(cByteBuffer &a_ByteBuffer)
eGameMode GetEffectiveGameMode(void) const
Returns the current effective gamemode (inherited gamemode is resolved before returning) ...
virtual void SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer &a_Serializer) override
void WriteBEUInt64(UInt64 a_Value)
virtual bool ReadItem(cByteBuffer &a_ByteBuffer, cItem &a_Item, size_t a_KeepRemainingBytes=0)
Reads an item out of the received data, sets a_Item to the values read.
AString StrToLower(const AString &s)
Returns a lower-cased copy of the string.
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)
cInventory & GetInventory(void)
bool ReadPosition64(int &a_BlockX, int &a_BlockY, int &a_BlockZ)
virtual void SendWindowClose(const cWindow &a_Window) override
virtual void SendSetRawSubTitle(const AString &a_SubTitle) override
void BeginList(const AString &a_Name, eTagType a_ChildrenType)
static AString MobTypeToVanillaName(eMonsterType a_MobType)
Translates MobType enum to the vanilla name of the mob, empty string if unknown.
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
void SetPosZ(double a_PosZ)
ePacketType
Logical types of outgoing packets.
void HandleAnvilItemName(const AString &a_ItemName)
Called when the protocol receives a MC|ItemName plugin message, indicating that the player named an i...
const AString & GetName(void) const
Returns the protocol name of the painting.
void BeginCompound(const AString &a_Name)
void SetUsername(const AString &a_Username)
static void DigestToJava(const Checksum &a_Digest, AString &a_JavaOut)
Converts a raw 160-bit SHA1 digest into a Java Hex representation According to http://wiki.vg/Protocol_Encryption.
#define UNREACHABLE(x)
Use to mark code that should be impossible to reach.
virtual void HandlePacketLoginStart(cByteBuffer &a_ByteBuffer)
void SetIPString(const AString &a_IPString)
Sets the IP string that the client is using.
virtual void SendTeleportEntity(const cEntity &a_Entity) override
bool IsCustomNameEmpty(void) const
bool IsEmpty(void) const
Returns true if there are no enchantments.
std::vector< sSetBlock > sSetBlockVector
virtual void SendEntityEquipment(const cEntity &a_Entity, short a_SlotNum, const cItem &a_Item) override
int GetReward(void) const
Get the exp amount.
void WriteBEInt64(Int64 a_Value)
UInt32 GetUniqueID(void) const
void ParseFromNBT(cEnchantments &a_Enchantments, const cParsedNBT &a_NBT, int a_EnchListTagIdx)
Reads the enchantments from the specified NBT list tag (ench or StoredEnchantments) ...
This class bridges a vector of cItem for safe access via Lua.
cClientHandle * GetClientHandle(void) const
Returns the raw client handle associated with the player.
static const UInt32 MAIN_HAND
Value for main hand in Hand parameter for Protocol 1.9.
virtual void HandlePacketSlotSelect(cByteBuffer &a_ByteBuffer)
cPluginManager * GetPluginManager(void)
const AString & GetIPString(void) const
virtual void SendLogin(const cPlayer &a_Player, const cWorld &a_World) override
virtual void HandlePacketCreativeInventoryAction(cByteBuffer &a_ByteBuffer)
virtual void SendSpawnFallingBlock(const cFallingBlock &a_FallingBlock) override
double GetSpawnX(void) const
static const AString & GetName(const eStatistic a_Type)
Type -> Name.
void HandleUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, const AString &a_Line1, const AString &a_Line2, const AString &a_Line3, const AString &a_Line4)
virtual void SendSpawnObject(const cEntity &a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) override
virtual void HandlePacketEntityAction(cByteBuffer &a_ByteBuffer)
void SetLocale(const AString &a_Locale)
bool SplitZeroTerminatedStrings(const AString &a_Strings, AStringVector &a_Output)
Splits a string that has embedded \0 characters, on those characters.