16 #include "../Entities/Boat.h" 17 #include "../Entities/Minecart.h" 18 #include "../Entities/Pickup.h" 19 #include "../Entities/Player.h" 20 #include "../Entities/ItemFrame.h" 21 #include "../Entities/ArrowEntity.h" 22 #include "../Entities/FireworkEntity.h" 23 #include "../Entities/SplashPotionEntity.h" 25 #include "../BlockTypePalette.h" 26 #include "../ClientHandle.h" 28 #include "../Server.h" 30 #include "../Bindings/PluginManager.h" 36 #define HANDLE_READ(ByteBuf, Proc, Type, Var) \ 39 if (!ByteBuf.Proc(Var))\ 49 #define HANDLE_PACKET_READ(ByteBuf, Proc, Type, Var) \ 53 if (!ByteBuf.Proc(Var)) \ 55 ByteBuf.CheckValid(); \ 58 ByteBuf.CheckValid(); \ 67 Super(a_Client, a_ServerAddress, a_ServerPort, a_State)
82 throw std::runtime_error(
Printf(
"This server doesn't support protocol %s.", paletteVersion));
174 switch (a_PacketType)
223 auto NumPlayers =
static_cast<signed>(Server->
GetNumPlayers());
224 auto MaxPlayers =
static_cast<signed>(Server->
GetMaxPlayers());
230 Version[
"name"] =
"Cuberite 1.13";
235 Players[
"online"] = NumPlayers;
236 Players[
"max"] = MaxPlayers;
240 Json::Value Description;
241 Description[
"text"] = ServerDescription.c_str();
244 Json::Value ResponseValue;
245 ResponseValue[
"version"] = Version;
246 ResponseValue[
"players"] = Players;
247 ResponseValue[
"description"] = Description;
249 if (!Favicon.empty())
251 ResponseValue[
"favicon"] =
Printf(
"data:image/png;base64,%s", Favicon.c_str());
255 Json::FastWriter Writer;
269 if (Channel.substr(0, 15) ==
"minecraft:brand")
310 for (sSetBlockVector::const_iterator itr = a_Changes.begin(), end = a_Changes.end(); itr != end; ++itr)
312 Int16 Coords =
static_cast<Int16>(itr->m_RelY | (itr->m_RelZ << 8) | (itr->m_RelX << 12));
328 SendData(ChunkData.data(), ChunkData.size());
445 if (!a_ByteBuffer.
ReadString(Metadata, a_ByteBuffer.
GetReadableSpace() - a_KeepRemainingBytes - 1) || (Metadata.size() == 0) || (Metadata[0] == 0))
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 SendMapData(const cMap &a_Map, int a_DataStartX, int a_DataStartY) override
virtual void WriteItem(cPacketizer &a_Pkt, const cItem &a_Item) override
Writes the item data into a packet.
virtual void HandlePacketEnchantItem(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketPlayerLook(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketPlayer(cByteBuffer &a_ByteBuffer)
UInt32 m_State
State of the protocol.
virtual void HandlePacketUpdateSign(cByteBuffer &a_ByteBuffer)
void WriteBEInt8(Int8 a_Value)
virtual void SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override
virtual void SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer &a_Serializer) override
void ParseItemMetadata(cItem &a_Item, const AString &a_Metadata)
Parses item metadata as read by ReadItem(), into the item enchantments.
size_t GetReadableSpace(void) const
Returns the number of bytes that are currently available for reading (may be less than UsedSpace due ...
virtual void SendData(const char *a_Data, size_t a_Size) override
Sends the data to the client, encrypting them if needed.
virtual UInt32 GetPacketID(ePacketType a_PacketType) override
Get the packet ID for a given packet.
virtual void HandlePacketPluginMessage(cByteBuffer &a_ByteBuffer) override
Class that manages the statistics and achievements of a single player.
cProtocol_1_13(cClientHandle *a_Client, const AString &a_ServerAddress, UInt16 a_ServerPort, UInt32 a_State)
virtual void Initialize(cClientHandle &a_Client) override
Called after construction so that the protocol class can initialize itself.
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 SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector &a_Changes) override
virtual void HandlePacketBlockDig(cByteBuffer &a_ByteBuffer)
unsigned char BLOCKTYPE
The datatype used by blockdata.
virtual void HandlePacketPlayerPosLook(cByteBuffer &a_ByteBuffer)
Encapsulates an in-game world map.
virtual void HandlePacketBoatSteer(cByteBuffer &a_ByteBuffer)
cCriticalSection m_CSPacket
Provides synchronization for sending the entire packet at once.
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.
virtual void HandlePacketWindowClick(cByteBuffer &a_ByteBuffer)
void WriteBEInt16(Int16 a_Value)
virtual void SendScoreboardObjective(const AString &a_Name, const AString &a_DisplayName, Byte a_Mode) override
virtual void HandlePacketPlayerAbilities(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketClientSettings(cByteBuffer &a_ByteBuffer)
bool CallHookServerPing(cClientHandle &a_ClientHandle, AString &a_ServerDescription, int &a_OnlinePlayersCount, int &a_MaxPlayersCount, AString &a_Favicon)
ProtocolPalettes & GetProtocolPalettes() const
Returns the per-protocol palettes manager.
virtual void HandlePacketUseItem(cByteBuffer &a_ByteBuffer)
const AString & GetDescription(void) const
virtual void SendPaintingSpawn(const cPainting &a_Painting) override
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
void WriteString(const AString &a_Value)
virtual void HandlePacketStatusRequest(cByteBuffer &a_ByteBuffer) override
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 SendTabCompletionResults(const AStringVector &a_Results) override
virtual void HandlePacketVehicleMove(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketSteerVehicle(cByteBuffer &a_ByteBuffer)
#define HANDLE_READ(ByteBuf, Proc, Type, Var)
std::shared_ptr< const BlockTypePalette > blockTypePalette(const AString &aProtocolVersion) const
Returns the BlockTypePalette for the specified protocol.
virtual void HandlePacketTabComplete(cByteBuffer &a_ByteBuffer)
#define HANDLE_PACKET_READ(ByteBuf, Proc, Type, Var)
std::vector< AString > AStringVector
virtual void HandlePacketChatMessage(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketBlockPlace(cByteBuffer &a_ByteBuffer) override
size_t GetMaxPlayers(void) const
virtual void HandleConfirmTeleport(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 HandlePacketSpectate(cByteBuffer &a_ByteBuffer)
const BlockTypePalette & GetUpgradeBlockTypePalette() const
Returns the block type palette used for upgrading blocks from pre-1.13 data.
Serializes one chunk's data to (possibly multiple) protocol versions.
virtual void HandlePacketAnimation(cByteBuffer &a_ByteBuffer)
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 SendStatistics(const cStatManager &a_Manager) override
size_t GetNumPlayers(void) const
An object that can store incoming bytes and lets its clients read the bytes sequentially The bytes ar...
void HandlePluginMessage(const AString &a_Channel, const AString &a_Message)
virtual void SendPluginMessage(const AString &a_Channel, const AString &a_Message) override
virtual UInt32 GetPacketID(ePacketType a_Packet) override
Get the packet ID for a given packet.
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.
std::shared_ptr< const BlockTypePalette > m_BlockTypePalette
The palette used to transform internal block type palette into the protocol-specific ID...
virtual void HandlePacketCraftingBookData(cByteBuffer &a_ByteBuffer)
virtual bool ReadItem(cByteBuffer &a_ByteBuffer, cItem &a_Item, size_t a_KeepRemainingBytes) override
Reads an item out of the received data, sets a_Item to the values read.
std::map< UInt32, UInt32 > m_BlockTypeMap
Temporary hack for initial 1.13+ support while keeping BLOCKTYPE data: Map of the BLOCKTYPE::META to ...
cServer * GetServer(void)
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.
void WritePosition64(int a_BlockX, int a_BlockY, int a_BlockZ)
Writes the specified block position as a single encoded 64-bit BigEndian integer. ...
void WriteVarInt32(UInt32 a_Value)
RAII for cCriticalSection - locks the CS on creation, unlocks on destruction.
virtual void HandlePacketPlayerPos(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketWindowClose(cByteBuffer &a_ByteBuffer)
virtual AString GetPaletteVersion() const
Returns the string identifying the palettes' version, such as "1.13" or "1.14.4". ...
virtual void SendUpdateBlockEntity(cBlockEntity &a_BlockEntity) override
ePacketType
Logical types of outgoing packets.
virtual void HandlePacketKeepAlive(cByteBuffer &a_ByteBuffer) override
virtual bool HandlePacket(cByteBuffer &a_ByteBuffer, UInt32 a_PacketType) override
Reads and handles the packet.
std::vector< sSetBlock > sSetBlockVector
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)