summaryrefslogtreecommitdiffstats
path: root/source/Protocol/Protocol.h
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-10-30 23:24:46 +0100
committermadmaxoft <github@xoft.cz>2013-10-30 23:24:46 +0100
commitdab398d5d663332527e57a7e239d223f33f4eb77 (patch)
tree9a55f84c516e1dc4dce6c02ad5c0755a9dd73e60 /source/Protocol/Protocol.h
parentProtoProxy: Working 1.7 protocol. (diff)
downloadcuberite-dab398d5d663332527e57a7e239d223f33f4eb77.tar
cuberite-dab398d5d663332527e57a7e239d223f33f4eb77.tar.gz
cuberite-dab398d5d663332527e57a7e239d223f33f4eb77.tar.bz2
cuberite-dab398d5d663332527e57a7e239d223f33f4eb77.tar.lz
cuberite-dab398d5d663332527e57a7e239d223f33f4eb77.tar.xz
cuberite-dab398d5d663332527e57a7e239d223f33f4eb77.tar.zst
cuberite-dab398d5d663332527e57a7e239d223f33f4eb77.zip
Diffstat (limited to 'source/Protocol/Protocol.h')
-rw-r--r--source/Protocol/Protocol.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/source/Protocol/Protocol.h b/source/Protocol/Protocol.h
index 5071f5961..466cf874b 100644
--- a/source/Protocol/Protocol.h
+++ b/source/Protocol/Protocol.h
@@ -186,6 +186,27 @@ protected:
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];
+ int 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(a_String.size());
+ SendData(a_String.data(), a_String.size());
+ }
} ;