summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ClientHandle.cpp4
-rw-r--r--src/ClientHandle.h2
-rw-r--r--src/Endianness.h31
-rw-r--r--src/Protocol/Protocol.h27
-rw-r--r--src/Protocol/Protocol125.cpp2
-rw-r--r--src/Protocol/Protocol125.h2
-rw-r--r--src/Protocol/Protocol132.cpp2
-rw-r--r--src/Protocol/Protocol132.h2
-rw-r--r--src/Protocol/Protocol14x.cpp12
-rw-r--r--src/Protocol/Protocol17x.cpp4
-rw-r--r--src/Protocol/Protocol17x.h2
-rw-r--r--src/Protocol/ProtocolRecognizer.cpp2
-rw-r--r--src/Protocol/ProtocolRecognizer.h2
13 files changed, 51 insertions, 43 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 23ba4dbab..daf2c4da8 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -1532,7 +1532,7 @@ void cClientHandle::HandleTabCompletion(const AString & a_Text)
-void cClientHandle::SendData(const char * a_Data, int a_Size)
+void cClientHandle::SendData(const char * a_Data, size_t a_Size)
{
if (m_HasSentDC)
{
@@ -1547,7 +1547,7 @@ void cClientHandle::SendData(const char * a_Data, int a_Size)
if (m_OutgoingDataOverflow.empty())
{
// No queued overflow data; if this packet fits into the ringbuffer, put it in, otherwise put it in the overflow buffer:
- int CanFit = m_OutgoingData.GetFreeSpace();
+ size_t CanFit = m_OutgoingData.GetFreeSpace();
if (CanFit > a_Size)
{
CanFit = a_Size;
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 5496e61a7..d83a323f9 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -225,7 +225,7 @@ public:
*/
bool HandleLogin(int a_ProtocolVersion, const AString & a_Username);
- void SendData(const char * a_Data, int a_Size);
+ void SendData(const char * a_Data, size_t a_Size);
/** Called when the player moves into a different world; queues sreaming the new chunks */
void MoveToWorld(cWorld & a_World, bool a_SendRespawnPacket);
diff --git a/src/Endianness.h b/src/Endianness.h
index 86eb369f5..6a2593077 100644
--- a/src/Endianness.h
+++ b/src/Endianness.h
@@ -1,12 +1,14 @@
#pragma once
+#define ntohll(x) ((((UInt64)ntohl((u_long)x)) << 32) + ntohl(x >> 32))
+
// Changes endianness
-inline unsigned long long HostToNetwork8(const void* a_Value )
+inline UInt64 HostToNetwork8(const void * a_Value)
{
unsigned long long __HostToNetwork8;
memcpy( &__HostToNetwork8, a_Value, sizeof( __HostToNetwork8 ) );
@@ -18,7 +20,7 @@ inline unsigned long long HostToNetwork8(const void* a_Value )
-inline unsigned int HostToNetwork4(const void* a_Value )
+inline UInt32 HostToNetwork4(const void* a_Value )
{
unsigned int __HostToNetwork4;
memcpy( &__HostToNetwork4, a_Value, sizeof( __HostToNetwork4 ) );
@@ -30,11 +32,10 @@ inline unsigned int HostToNetwork4(const void* a_Value )
-inline double NetworkToHostDouble8(const void* a_Value )
+inline double NetworkToHostDouble8(const void * a_Value)
{
-#define ntohll(x) ((((unsigned long long)ntohl((u_long)x)) << 32) + ntohl(x >> 32))
- unsigned long long buf = 0;//(*(unsigned long long*)a_Value);
- memcpy( &buf, a_Value, 8 );
+ UInt64 buf = 0;
+ memcpy(&buf, a_Value, 8);
buf = ntohll(buf);
double x;
memcpy(&x, &buf, sizeof(double));
@@ -45,23 +46,25 @@ inline double NetworkToHostDouble8(const void* a_Value )
-inline long long NetworkToHostLong8(const void * a_Value )
+inline Int64 NetworkToHostLong8(const void * a_Value)
{
- unsigned long long buf = *(unsigned long long*)a_Value;
+ UInt64 buf;
+ memcpy(&buf, &a_Value, 8);
buf = ntohll(buf);
- return *reinterpret_cast<long long *>(&buf);
+ return *reinterpret_cast<Int64 *>(&buf);
}
-inline float NetworkToHostFloat4(const void* a_Value )
+inline float NetworkToHostFloat4(const void * a_Value)
{
- u_long buf = *(u_long*)a_Value;
- buf = ntohl( buf );
- float x = 0;
- memcpy( &x, &buf, sizeof(float) );
+ UInt32 buf;
+ float x;
+ memcpy(&buf, &a_Value, 4);
+ buf = ntohl(buf);
+ memcpy(&x, &buf, sizeof(float));
return x;
}
diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h
index d3383bf0d..8294fa8b7 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());
}
@@ -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());
}
} ;
diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp
index fe6280218..0fa5c6de7 100644
--- a/src/Protocol/Protocol125.cpp
+++ b/src/Protocol/Protocol125.cpp
@@ -1156,7 +1156,7 @@ AString cProtocol125::GetAuthServerID(void)
-void cProtocol125::SendData(const char * a_Data, int a_Size)
+void cProtocol125::SendData(const char * a_Data, size_t a_Size)
{
m_Client->SendData(a_Data, a_Size);
}
diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h
index aca24c03a..08d3ebbe9 100644
--- a/src/Protocol/Protocol125.h
+++ b/src/Protocol/Protocol125.h
@@ -125,7 +125,7 @@ protected:
AString m_Username; ///< Stored in ParseHandshake(), compared to Login username
- virtual void SendData(const char * a_Data, int a_Size) override;
+ virtual void SendData(const char * a_Data, size_t a_Size) override;
/// Sends the Handshake packet
void SendHandshake(const AString & a_ConnectionHash);
diff --git a/src/Protocol/Protocol132.cpp b/src/Protocol/Protocol132.cpp
index be9c503ed..ce5d134ea 100644
--- a/src/Protocol/Protocol132.cpp
+++ b/src/Protocol/Protocol132.cpp
@@ -605,7 +605,7 @@ int cProtocol132::ParseTabCompletion(void)
-void cProtocol132::SendData(const char * a_Data, int a_Size)
+void cProtocol132::SendData(const char * a_Data, size_t a_Size)
{
m_DataToSend.append(a_Data, a_Size);
}
diff --git a/src/Protocol/Protocol132.h b/src/Protocol/Protocol132.h
index 0702fbf5a..b280c8a41 100644
--- a/src/Protocol/Protocol132.h
+++ b/src/Protocol/Protocol132.h
@@ -87,7 +87,7 @@ protected:
/// The ServerID used for session authentication; set in StartEncryption(), used in GetAuthServerID()
AString m_AuthServerID;
- virtual void SendData(const char * a_Data, int a_Size) override;
+ virtual void SendData(const char * a_Data, size_t a_Size) override;
// DEBUG:
virtual void Flush(void) override;
diff --git a/src/Protocol/Protocol14x.cpp b/src/Protocol/Protocol14x.cpp
index 232b2718e..f694af1eb 100644
--- a/src/Protocol/Protocol14x.cpp
+++ b/src/Protocol/Protocol14x.cpp
@@ -103,9 +103,9 @@ void cProtocol142::SendPickupSpawn(const cPickup & a_Pickup)
WriteInt (a_Pickup.GetUniqueID());
WriteItem (a_Pickup.GetItem());
WriteVectorI((Vector3i)(a_Pickup.GetPosition() * 32));
- WriteByte ((char)(a_Pickup.GetSpeed().x * 8));
- WriteByte ((char)(a_Pickup.GetSpeed().y * 8));
- WriteByte ((char)(a_Pickup.GetSpeed().z * 8));
+ WriteChar ((char)(a_Pickup.GetSpeed().x * 8));
+ WriteChar ((char)(a_Pickup.GetSpeed().y * 8));
+ WriteChar ((char)(a_Pickup.GetSpeed().z * 8));
Flush();
}
@@ -119,7 +119,7 @@ void cProtocol142::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_Src
WriteByte(PACKET_SOUND_PARTICLE_EFFECT);
WriteInt (a_EffectID);
WriteInt (a_SrcX);
- WriteByte(a_SrcY);
+ WriteByte((Byte)a_SrcY);
WriteInt (a_SrcZ);
WriteInt (a_Data);
WriteBool(0);
@@ -218,7 +218,7 @@ void cProtocol146::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType,
cCSLock Lock(m_CSPacket);
WriteByte(PACKET_SPAWN_OBJECT);
WriteInt (a_Entity.GetUniqueID());
- WriteByte(a_ObjectType);
+ WriteChar(a_ObjectType);
WriteInt ((int)(a_Entity.GetPosX() * 32));
WriteInt ((int)(a_Entity.GetPosY() * 32));
WriteInt ((int)(a_Entity.GetPosZ() * 32));
@@ -243,7 +243,7 @@ void cProtocol146::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleTyp
cCSLock Lock(m_CSPacket);
WriteByte (PACKET_SPAWN_OBJECT);
WriteInt (a_Vehicle.GetUniqueID());
- WriteByte (a_VehicleType);
+ WriteChar (a_VehicleType);
WriteInt ((int)(a_Vehicle.GetPosX() * 32));
WriteInt ((int)(a_Vehicle.GetPosY() * 32));
WriteInt ((int)(a_Vehicle.GetPosZ() * 32));
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index c678fc9a0..b987294b0 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -1988,14 +1988,14 @@ void cProtocol172::WritePacket(cByteBuffer & a_Packet)
-void cProtocol172::SendData(const char * a_Data, int a_Size)
+void cProtocol172::SendData(const char * a_Data, size_t a_Size)
{
if (m_IsEncrypted)
{
Byte Encrypted[8192]; // Larger buffer, we may be sending lots of data (chunks)
while (a_Size > 0)
{
- size_t NumBytes = ((size_t)a_Size > sizeof(Encrypted)) ? sizeof(Encrypted) : (size_t)a_Size;
+ size_t NumBytes = (a_Size > sizeof(Encrypted)) ? sizeof(Encrypted) : a_Size;
m_Encryptor.ProcessData(Encrypted, (Byte *)a_Data, NumBytes);
m_Client->SendData((const char *)Encrypted, NumBytes);
a_Size -= NumBytes;
diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h
index 41163009e..bb6ee575a 100644
--- a/src/Protocol/Protocol17x.h
+++ b/src/Protocol/Protocol17x.h
@@ -287,7 +287,7 @@ protected:
void WritePacket(cByteBuffer & a_Packet);
/** Sends the data to the client, encrypting them if needed. */
- virtual void SendData(const char * a_Data, int a_Size) override;
+ virtual void SendData(const char * a_Data, size_t a_Size) override;
void SendCompass(const cWorld & a_World);
diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp
index 3b9003e60..81f146370 100644
--- a/src/Protocol/ProtocolRecognizer.cpp
+++ b/src/Protocol/ProtocolRecognizer.cpp
@@ -794,7 +794,7 @@ AString cProtocolRecognizer::GetAuthServerID(void)
-void cProtocolRecognizer::SendData(const char * a_Data, int a_Size)
+void cProtocolRecognizer::SendData(const char * a_Data, size_t a_Size)
{
// This is used only when handling the server ping
m_Client->SendData(a_Data, a_Size);
diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h
index d7fb8fad2..072d7c2d2 100644
--- a/src/Protocol/ProtocolRecognizer.h
+++ b/src/Protocol/ProtocolRecognizer.h
@@ -133,7 +133,7 @@ public:
virtual AString GetAuthServerID(void) override;
- virtual void SendData(const char * a_Data, int a_Size) override;
+ virtual void SendData(const char * a_Data, size_t a_Size) override;
protected:
cProtocol * m_Protocol; //< The recognized protocol