summaryrefslogtreecommitdiffstats
path: root/src/Protocol/Protocol.h
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-09-27 15:28:14 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-09-27 15:28:14 +0200
commit72c087cfd335b015139cb73ae78f74105d855cf0 (patch)
treeec700e5083a60e03ad8374e12f4528de8c92491e /src/Protocol/Protocol.h
parentMerge pull request #1456 from Howaner/Fixes (diff)
downloadcuberite-72c087cfd335b015139cb73ae78f74105d855cf0.tar
cuberite-72c087cfd335b015139cb73ae78f74105d855cf0.tar.gz
cuberite-72c087cfd335b015139cb73ae78f74105d855cf0.tar.bz2
cuberite-72c087cfd335b015139cb73ae78f74105d855cf0.tar.lz
cuberite-72c087cfd335b015139cb73ae78f74105d855cf0.tar.xz
cuberite-72c087cfd335b015139cb73ae78f74105d855cf0.tar.zst
cuberite-72c087cfd335b015139cb73ae78f74105d855cf0.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());
- }
} ;