From b1d4b3bb96629b3624e8328d7b1a0bce5333bb7d Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 21 Mar 2015 13:00:20 +0100 Subject: Unified cByteBuffer types. cByteBuffer now reads and writes any of the [U]Int types. --- src/Protocol/Protocol17x.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/Protocol/Protocol17x.h') diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index f939bfb5e..2ee247330 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -161,22 +161,22 @@ protected: void WriteByte(Byte a_Value) { - m_Out.WriteByte(a_Value); + m_Out.WriteBEUInt8(a_Value); } void WriteChar(char a_Value) { - m_Out.WriteChar(a_Value); + m_Out.WriteBEInt8(a_Value); } void WriteShort(short a_Value) { - m_Out.WriteBEShort(a_Value); + m_Out.WriteBEInt16(a_Value); } - void WriteInt(int a_Value) + void WriteInt(Int32 a_Value) { - m_Out.WriteBEInt(a_Value); + m_Out.WriteBEInt32(a_Value); } void WriteInt64(Int64 a_Value) @@ -297,7 +297,7 @@ protected: /** Parses Vanilla plugin messages into specific ClientHandle calls. The message payload is still in the bytebuffer, to be read by this function. */ - void HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const AString & a_Channel, short a_PayloadLength); + void HandleVanillaPluginMessage(cByteBuffer & a_ByteBuffer, const AString & a_Channel, UInt16 a_PayloadLength); /** Sends the data to the client, encrypting them if needed. */ virtual void SendData(const char * a_Data, size_t a_Size) override; @@ -312,6 +312,9 @@ protected: void StartEncryption(const Byte * a_Key); + /** Converts the BlockFace received by the protocol into eBlockFace constants. + If the received value doesn't match any of our eBlockFace constants, BLOCK_FACE_NONE is returned. */ + eBlockFace FaceIntToBlockFace(Int8 a_FaceInt); } ; -- cgit v1.2.3 From 3923e3e37a60f7d51b9d527840cd1b93cde04578 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 21 Mar 2015 15:40:56 +0100 Subject: Fixed signedness issues in protocols. --- src/Protocol/Protocol17x.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/Protocol/Protocol17x.h') diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 2ee247330..8ff4bd158 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -179,6 +179,11 @@ protected: m_Out.WriteBEInt32(a_Value); } + void WriteUInt32(UInt32 a_Value) + { + m_Out.WriteBEUInt32(a_Value); + } + void WriteInt64(Int64 a_Value) { m_Out.WriteBEInt64(a_Value); -- cgit v1.2.3 From c3c29577a52a2e820cd389b88d52119e8136a7d8 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 21 Mar 2015 16:11:57 +0100 Subject: Fixed signedness warnings in Protocol. --- src/Protocol/Protocol17x.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Protocol/Protocol17x.h') diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 8ff4bd158..543ae6ee3 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -63,7 +63,7 @@ public: /** Sending stuff to clients (alphabetically sorted): */ virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle) override; virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) override; - virtual void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override; + virtual void SendBlockBreakAnim (UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override; virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override; virtual void SendChat (const AString & a_Message) override; -- cgit v1.2.3 From c6268483934eb2bfdcb76ae621a0be40f76209f5 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 22 Mar 2015 19:46:08 +0100 Subject: Unified cPacketizer across all protocols. --- src/Protocol/Protocol17x.h | 112 ++++++++------------------------------------- 1 file changed, 18 insertions(+), 94 deletions(-) (limited to 'src/Protocol/Protocol17x.h') diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 543ae6ee3..1212cc325 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -140,94 +140,6 @@ public: protected: - /** Composes individual packets in the protocol's m_OutPacketBuffer; sends them upon being destructed */ - class cPacketizer - { - public: - cPacketizer(cProtocol172 & a_Protocol, UInt32 a_PacketType) : - m_Protocol(a_Protocol), - m_Out(a_Protocol.m_OutPacketBuffer), - m_Lock(a_Protocol.m_CSPacket) - { - m_Out.WriteVarInt(a_PacketType); - } - - ~cPacketizer(); - - void WriteBool(bool a_Value) - { - m_Out.WriteBool(a_Value); - } - - void WriteByte(Byte a_Value) - { - m_Out.WriteBEUInt8(a_Value); - } - - void WriteChar(char a_Value) - { - m_Out.WriteBEInt8(a_Value); - } - - void WriteShort(short a_Value) - { - m_Out.WriteBEInt16(a_Value); - } - - void WriteInt(Int32 a_Value) - { - m_Out.WriteBEInt32(a_Value); - } - - void WriteUInt32(UInt32 a_Value) - { - m_Out.WriteBEUInt32(a_Value); - } - - void WriteInt64(Int64 a_Value) - { - m_Out.WriteBEInt64(a_Value); - } - - void WriteFloat(float a_Value) - { - m_Out.WriteBEFloat(a_Value); - } - - void WriteDouble(double a_Value) - { - m_Out.WriteBEDouble(a_Value); - } - - void WriteVarInt(UInt32 a_Value) - { - m_Out.WriteVarInt(a_Value); - } - - void WriteString(const AString & a_Value) - { - m_Out.WriteVarUTF8String(a_Value); - } - - void WriteBuf(const char * a_Data, size_t a_Size) - { - m_Out.Write(a_Data, a_Size); - } - - void WriteItem(const cItem & a_Item); - void WriteByteAngle(double a_Angle); // Writes the specified angle using a single byte - void WriteFPInt(double a_Value); // Writes the double value as a 27:5 fixed-point integer - void WriteEntityMetadata(const cEntity & a_Entity); // Writes the metadata for the specified entity, not including the terminating 0x7f - void WriteMobMetadata(const cMonster & a_Mob); // Writes the mob-specific metadata for the specified mob - void WriteEntityProperties(const cEntity & a_Entity); // Writes the entity properties for the specified entity, including the Count field - void WriteBlockEntity(const cBlockEntity & a_BlockEntity); - - protected: - cProtocol172 & m_Protocol; - cByteBuffer & m_Out; - cCSLock m_Lock; - } ; - AString m_ServerAddress; UInt16 m_ServerPort; @@ -240,12 +152,6 @@ protected: /** Buffer for the received data */ cByteBuffer m_ReceivedData; - /** Buffer for composing the outgoing packets, through cPacketizer */ - cByteBuffer m_OutPacketBuffer; - - /** Buffer for composing packet length (so that each cPacketizer instance doesn't allocate a new cPacketBuffer) */ - cByteBuffer m_OutPacketLenBuffer; - bool m_IsEncrypted; cAesCfb128Decryptor m_Decryptor; @@ -307,6 +213,9 @@ protected: /** Sends the data to the client, encrypting them if needed. */ virtual void SendData(const char * a_Data, size_t a_Size) override; + /** Sends the packet to the client. Called by the cPacketizer's destructor. */ + virtual void SendPacket(cPacketizer & a_Packet) override; + void SendCompass(const cWorld & a_World); /** Reads an item out of the received data, sets a_Item to the values read. Returns false if not enough received data */ @@ -320,6 +229,21 @@ protected: /** Converts the BlockFace received by the protocol into eBlockFace constants. If the received value doesn't match any of our eBlockFace constants, BLOCK_FACE_NONE is returned. */ eBlockFace FaceIntToBlockFace(Int8 a_FaceInt); + + /** Writes the item data into a packet. */ + void WriteItem(cPacketizer & a_Pkt, const cItem & a_Item); + + /** Writes the metadata for the specified entity, not including the terminating 0x7f. */ + void WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_Entity); + + /** Writes the mob-specific metadata for the specified mob */ + void WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob); + + /** Writes the entity properties for the specified entity, including the Count field. */ + void WriteEntityProperties(cPacketizer & a_Pkt, const cEntity & a_Entity); + + /** Writes the block entity data for the specified block entity into the packet. */ + void WriteBlockEntity(cPacketizer & a_Pkt, const cBlockEntity & a_BlockEntity); } ; -- cgit v1.2.3