summaryrefslogtreecommitdiffstats
path: root/src/Protocol/Protocol.h
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-09-29 14:37:01 +0200
committerHowaner <franzi.moos@googlemail.com>2014-09-29 14:37:01 +0200
commit347402d20d7ecaab3daad691eb178c5a04447d44 (patch)
tree4a3188eef6087a3029b348cbbe8c93e5d365d158 /src/Protocol/Protocol.h
parentFixed SetDefaultRank() return value. (diff)
parentMerge pull request #1479 from SphinxC0re/master (diff)
downloadcuberite-347402d20d7ecaab3daad691eb178c5a04447d44.tar
cuberite-347402d20d7ecaab3daad691eb178c5a04447d44.tar.gz
cuberite-347402d20d7ecaab3daad691eb178c5a04447d44.tar.bz2
cuberite-347402d20d7ecaab3daad691eb178c5a04447d44.tar.lz
cuberite-347402d20d7ecaab3daad691eb178c5a04447d44.tar.xz
cuberite-347402d20d7ecaab3daad691eb178c5a04447d44.tar.zst
cuberite-347402d20d7ecaab3daad691eb178c5a04447d44.zip
Diffstat (limited to 'src/Protocol/Protocol.h')
-rw-r--r--src/Protocol/Protocol.h101
1 files changed, 1 insertions, 100 deletions
diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h
index b2ee92918..7225f663d 100644
--- a/src/Protocol/Protocol.h
+++ b/src/Protocol/Protocol.h
@@ -138,108 +138,9 @@ public:
protected:
cClientHandle * m_Client;
cCriticalSection m_CSPacket; // Each SendXYZ() function must acquire this CS in order to send the whole packet at once
-
+
/// A generic data-sending routine, all outgoing packet data needs to be routed through this so that descendants may override it
virtual void SendData(const char * a_Data, size_t a_Size) = 0;
-
- /// Called after writing each packet, enables descendants to flush their buffers
- virtual void Flush(void) {}
-
- // Helpers for writing partial packet data, write using SendData()
- void WriteByte(Byte a_Value)
- {
- SendData((const char *)&a_Value, 1);
- }
-
- void WriteChar(char a_Value)
- {
- SendData(&a_Value, 1);
- }
-
- void WriteShort(short a_Value)
- {
- u_short Value = htons((u_short)a_Value);
- SendData((const char *)&Value, 2);
- }
-
- /*
- void WriteShort(unsigned short a_Value)
- {
- a_Value = htons(a_Value);
- SendData((const char *)&a_Value, 2);
- }
- */
-
- void WriteInt(int a_Value)
- {
- u_long Value = htonl((u_long)a_Value);
- SendData((const char *)&Value, 4);
- }
-
- void WriteUInt(unsigned int a_Value)
- {
- a_Value = htonl(a_Value);
- SendData((const char *)&a_Value, 4);
- }
-
- void WriteInt64 (Int64 a_Value)
- {
- UInt64 Value = HostToNetwork8(&a_Value);
- SendData((const char *)&Value, 8);
- }
-
- void WriteFloat (float a_Value)
- {
- UInt32 val = HostToNetwork4(&a_Value);
- SendData((const char *)&val, 4);
- }
-
- void WriteDouble(double a_Value)
- {
- UInt64 val = HostToNetwork8(&a_Value);
- SendData((const char *)&val, 8);
- }
-
- void WriteString(const AString & a_Value)
- {
- AString UTF16;
- UTF8ToRawBEUTF16(a_Value.c_str(), a_Value.length(), UTF16);
- WriteShort((short)(UTF16.size() / 2));
- SendData(UTF16.data(), UTF16.size());
- }
-
- void WriteBool(bool a_Value)
- {
- WriteByte(a_Value ? 1 : 0);
- }
-
- void WriteVectorI(const Vector3i & a_Vector)
- {
- WriteInt(a_Vector.x);
- WriteInt(a_Vector.y);
- WriteInt(a_Vector.z);
- }
-
- void WriteVarInt(UInt32 a_Value)
- {
- // A 32-bit integer can be encoded by at most 5 bytes:
- unsigned char b[5];
- size_t idx = 0;
- do
- {
- b[idx] = (a_Value & 0x7f) | ((a_Value > 0x7f) ? 0x80 : 0x00);
- a_Value = a_Value >> 7;
- idx++;
- } while (a_Value > 0);
-
- SendData((const char *)b, idx);
- }
-
- void WriteVarUTF8String(const AString & a_String)
- {
- WriteVarInt((UInt32)a_String.size());
- SendData(a_String.data(), a_String.size());
- }
} ;