summaryrefslogtreecommitdiffstats
path: root/source/Protocol/Protocol17x.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/Protocol/Protocol17x.h93
1 files changed, 86 insertions, 7 deletions
diff --git a/source/Protocol/Protocol17x.h b/source/Protocol/Protocol17x.h
index f11d8e2f9..4be166814 100644
--- a/source/Protocol/Protocol17x.h
+++ b/source/Protocol/Protocol17x.h
@@ -95,6 +95,85 @@ 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.WriteByte(a_Value);
+ }
+
+ void WriteChar(char a_Value)
+ {
+ m_Out.WriteChar(a_Value);
+ }
+
+ void WriteShort(short a_Value)
+ {
+ m_Out.WriteBEShort(a_Value);
+ }
+
+ void WriteInt(int a_Value)
+ {
+ m_Out.WriteBEInt(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, int 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
+
+ protected:
+ cProtocol172 & m_Protocol;
+ cByteBuffer & m_Out;
+ cCSLock m_Lock;
+ } ;
+
AString m_ServerAddress;
UInt16 m_ServerPort;
@@ -107,13 +186,16 @@ 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;
CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption m_Decryptor;
CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption m_Encryptor;
- /// (Unencrypted) data to be sent to the client. Written by SendData, cleared by Flush()
- AString m_DataToSend;
-
/// Adds the received (unencrypted) data to m_ReceivedData, parses complete packets
void AddReceivedData(const char * a_Data, int a_Size);
@@ -157,12 +239,9 @@ protected:
/// Writes an entire packet into the output stream. a_Packet is expected to start with the packet type; data length is prepended here.
void WritePacket(cByteBuffer & a_Packet);
- /// Adds unencrypted data to the outgoing data buffer
+ /// Sends the data to the client, encrypting them if needed.
virtual void SendData(const char * a_Data, int a_Size) override;
- /// Flushes m_DataToSend through the optional encryption into the outgoing socket data
- virtual void Flush(void) override;
-
void SendCompass(const cWorld & a_World);
} ;