summaryrefslogtreecommitdiffstats
path: root/src/Protocol/Protocol.h
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-04-06 21:43:23 +0200
committerHowaner <franzi.moos@googlemail.com>2014-04-06 21:43:23 +0200
commit7da308a7e158542fba0b28d3ad0e865b9e60bfc4 (patch)
tree84e11eab9c0608e71acedae999bbc3fba9c95d2a /src/Protocol/Protocol.h
parentAdd CanChangeDirtToGrass function to Block Handlers. (diff)
parentUpdated cWorld::CreateProjectile() documentation (diff)
downloadcuberite-7da308a7e158542fba0b28d3ad0e865b9e60bfc4.tar
cuberite-7da308a7e158542fba0b28d3ad0e865b9e60bfc4.tar.gz
cuberite-7da308a7e158542fba0b28d3ad0e865b9e60bfc4.tar.bz2
cuberite-7da308a7e158542fba0b28d3ad0e865b9e60bfc4.tar.lz
cuberite-7da308a7e158542fba0b28d3ad0e865b9e60bfc4.tar.xz
cuberite-7da308a7e158542fba0b28d3ad0e865b9e60bfc4.tar.zst
cuberite-7da308a7e158542fba0b28d3ad0e865b9e60bfc4.zip
Diffstat (limited to 'src/Protocol/Protocol.h')
-rw-r--r--src/Protocol/Protocol.h29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h
index d3383bf0d..ae06f2f9e 100644
--- a/src/Protocol/Protocol.h
+++ b/src/Protocol/Protocol.h
@@ -132,7 +132,7 @@ protected:
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, int a_Size) = 0;
+ 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) {};
@@ -143,10 +143,15 @@ protected:
SendData((const char *)&a_Value, 1);
}
+ void WriteChar(char a_Value)
+ {
+ SendData(&a_Value, 1);
+ }
+
void WriteShort(short a_Value)
{
- a_Value = htons(a_Value);
- SendData((const char *)&a_Value, 2);
+ u_short Value = htons((u_short)a_Value);
+ SendData((const char *)&Value, 2);
}
/*
@@ -159,8 +164,8 @@ protected:
void WriteInt(int a_Value)
{
- a_Value = htonl(a_Value);
- SendData((const char *)&a_Value, 4);
+ u_long Value = htonl((u_long)a_Value);
+ SendData((const char *)&Value, 4);
}
void WriteUInt(unsigned int a_Value)
@@ -171,19 +176,19 @@ protected:
void WriteInt64 (Int64 a_Value)
{
- a_Value = HostToNetwork8(&a_Value);
- SendData((const char *)&a_Value, 8);
+ UInt64 Value = HostToNetwork8(&a_Value);
+ SendData((const char *)Value, 8);
}
void WriteFloat (float a_Value)
{
- unsigned int val = HostToNetwork4(&a_Value);
+ UInt32 val = HostToNetwork4(&a_Value);
SendData((const char *)&val, 4);
}
void WriteDouble(double a_Value)
{
- unsigned long long val = HostToNetwork8(&a_Value);
+ UInt64 val = HostToNetwork8(&a_Value);
SendData((const char *)&val, 8);
}
@@ -191,7 +196,7 @@ protected:
{
AString UTF16;
UTF8ToRawBEUTF16(a_Value.c_str(), a_Value.length(), UTF16);
- WriteShort((unsigned short)(UTF16.size() / 2));
+ WriteShort((short)(UTF16.size() / 2));
SendData(UTF16.data(), UTF16.size());
}
@@ -211,7 +216,7 @@ protected:
{
// A 32-bit integer can be encoded by at most 5 bytes:
unsigned char b[5];
- int idx = 0;
+ size_t idx = 0;
do
{
b[idx] = (a_Value & 0x7f) | ((a_Value > 0x7f) ? 0x80 : 0x00);
@@ -224,7 +229,7 @@ protected:
void WriteVarUTF8String(const AString & a_String)
{
- WriteVarInt(a_String.size());
+ WriteVarInt((UInt32)a_String.size());
SendData(a_String.data(), a_String.size());
}
} ;