1
0

Fixed some Clang warnings in protocols.

This commit is contained in:
madmaxoft 2014-04-04 10:13:25 +02:00
parent 402d85d896
commit 8825d30aab
13 changed files with 51 additions and 43 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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());
}
} ;

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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;

View File

@ -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));

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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