1
0

More Clang warning fixes in the protocols.

This commit is contained in:
madmaxoft 2014-04-04 10:31:50 +02:00
parent 396abb5db6
commit 5dee19648d
3 changed files with 39 additions and 30 deletions

View File

@ -115,7 +115,7 @@ void cProtocol132::DataReceived(const char * a_Data, size_t a_Size)
Byte Decrypted[512]; Byte Decrypted[512];
while (a_Size > 0) while (a_Size > 0)
{ {
int NumBytes = (a_Size > (int)sizeof(Decrypted)) ? (int)sizeof(Decrypted) : a_Size; size_t NumBytes = (a_Size > sizeof(Decrypted)) ? sizeof(Decrypted) : a_Size;
m_Decryptor.ProcessData(Decrypted, (Byte *)a_Data, NumBytes); m_Decryptor.ProcessData(Decrypted, (Byte *)a_Data, NumBytes);
super::DataReceived((const char *)Decrypted, NumBytes); super::DataReceived((const char *)Decrypted, NumBytes);
a_Size -= NumBytes; a_Size -= NumBytes;
@ -139,8 +139,8 @@ void cProtocol132::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, cha
WriteInt (a_BlockX); WriteInt (a_BlockX);
WriteShort((short)a_BlockY); WriteShort((short)a_BlockY);
WriteInt (a_BlockZ); WriteInt (a_BlockZ);
WriteByte (a_Byte1); WriteChar (a_Byte1);
WriteByte (a_Byte2); WriteChar (a_Byte2);
WriteShort(a_BlockType); WriteShort(a_BlockType);
Flush(); Flush();
} }
@ -157,7 +157,7 @@ void cProtocol132::SendBlockBreakAnim(int a_entityID, int a_BlockX, int a_BlockY
WriteInt (a_BlockX); WriteInt (a_BlockX);
WriteInt (a_BlockY); WriteInt (a_BlockY);
WriteInt (a_BlockZ); WriteInt (a_BlockZ);
WriteByte (stage); WriteChar (stage);
Flush(); Flush();
} }
@ -259,7 +259,7 @@ void cProtocol132::SendLogin(const cPlayer & a_Player, const cWorld & a_World)
WriteByte (PACKET_LOGIN); WriteByte (PACKET_LOGIN);
WriteInt (a_Player.GetUniqueID()); // EntityID of the player WriteInt (a_Player.GetUniqueID()); // EntityID of the player
WriteString("default"); // Level type WriteString("default"); // Level type
WriteByte ((int)a_Player.GetGameMode()); WriteByte ((Byte)a_Player.GetGameMode());
WriteByte ((Byte)(a_World.GetDimension())); WriteByte ((Byte)(a_World.GetDimension()));
WriteByte (2); // TODO: Difficulty WriteByte (2); // TODO: Difficulty
WriteByte (0); // Unused, used to be world height WriteByte (0); // Unused, used to be world height
@ -283,8 +283,8 @@ void cProtocol132::SendPlayerSpawn(const cPlayer & a_Player)
WriteInt ((int)(a_Player.GetPosX() * 32)); WriteInt ((int)(a_Player.GetPosX() * 32));
WriteInt ((int)(a_Player.GetPosY() * 32)); WriteInt ((int)(a_Player.GetPosY() * 32));
WriteInt ((int)(a_Player.GetPosZ() * 32)); WriteInt ((int)(a_Player.GetPosZ() * 32));
WriteByte ((char)((a_Player.GetYaw() / 360.f) * 256)); WriteChar ((char)((a_Player.GetYaw() / 360.f) * 256));
WriteByte ((char)((a_Player.GetPitch() / 360.f) * 256)); WriteChar ((char)((a_Player.GetPitch() / 360.f) * 256));
WriteShort (HeldItem.IsEmpty() ? 0 : HeldItem.m_ItemType); WriteShort (HeldItem.IsEmpty() ? 0 : HeldItem.m_ItemType);
// Player metadata: just use a default metadata value, since the client doesn't like starting without any metadata: // Player metadata: just use a default metadata value, since the client doesn't like starting without any metadata:
WriteByte (0); // Index 0, byte (flags) WriteByte (0); // Index 0, byte (flags)
@ -306,7 +306,7 @@ void cProtocol132::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int
WriteInt (a_SrcY); WriteInt (a_SrcY);
WriteInt (a_SrcZ); WriteInt (a_SrcZ);
WriteFloat (a_Volume); WriteFloat (a_Volume);
WriteByte ((char)(a_Pitch * 63.0f)); WriteChar ((char)(a_Pitch * 63.0f));
Flush(); Flush();
} }
@ -320,7 +320,7 @@ void cProtocol132::SendSoundParticleEffect(int a_EffectID, int a_SrcX, int a_Src
WriteByte(PACKET_SOUND_PARTICLE_EFFECT); WriteByte(PACKET_SOUND_PARTICLE_EFFECT);
WriteInt (a_EffectID); WriteInt (a_EffectID);
WriteInt (a_SrcX); WriteInt (a_SrcX);
WriteByte(a_SrcY); WriteByte((Byte)a_SrcY);
WriteInt (a_SrcZ); WriteInt (a_SrcZ);
WriteInt (a_Data); WriteInt (a_Data);
Flush(); Flush();
@ -335,7 +335,7 @@ void cProtocol132::SendSpawnMob(const cMonster & a_Mob)
cCSLock Lock(m_CSPacket); cCSLock Lock(m_CSPacket);
WriteByte (PACKET_SPAWN_MOB); WriteByte (PACKET_SPAWN_MOB);
WriteInt (a_Mob.GetUniqueID()); WriteInt (a_Mob.GetUniqueID());
WriteByte (a_Mob.GetMobType()); WriteByte ((Byte)a_Mob.GetMobType());
WriteVectorI((Vector3i)(a_Mob.GetPosition() * 32)); WriteVectorI((Vector3i)(a_Mob.GetPosition() * 32));
WriteByte ((Byte)((a_Mob.GetYaw() / 360.f) * 256)); WriteByte ((Byte)((a_Mob.GetYaw() / 360.f) * 256));
WriteByte ((Byte)((a_Mob.GetPitch() / 360.f) * 256)); WriteByte ((Byte)((a_Mob.GetPitch() / 360.f) * 256));
@ -411,12 +411,12 @@ void cProtocol132::SendWholeInventory(const cWindow & a_Window)
const cInventory & Inventory = m_Client->GetPlayer()->GetInventory(); const cInventory & Inventory = m_Client->GetPlayer()->GetInventory();
int BaseOffset = a_Window.GetNumSlots() - (cInventory::invNumSlots - cInventory::invInventoryOffset); // Number of non-inventory slots int BaseOffset = a_Window.GetNumSlots() - (cInventory::invNumSlots - cInventory::invInventoryOffset); // Number of non-inventory slots
char WindowID = a_Window.GetWindowID(); char WindowID = a_Window.GetWindowID();
for (int i = 0; i < cInventory::invInventoryCount; i++) for (short i = 0; i < cInventory::invInventoryCount; i++)
{ {
SendInventorySlot(WindowID, BaseOffset + i, Inventory.GetInventorySlot(i)); SendInventorySlot(WindowID, BaseOffset + i, Inventory.GetInventorySlot(i));
} // for i - Inventory[] } // for i - Inventory[]
BaseOffset += cInventory::invInventoryCount; BaseOffset += cInventory::invInventoryCount;
for (int i = 0; i < cInventory::invHotbarCount; i++) for (short i = 0; i < cInventory::invHotbarCount; i++)
{ {
SendInventorySlot(WindowID, BaseOffset + i, Inventory.GetHotbarSlot(i)); SendInventorySlot(WindowID, BaseOffset + i, Inventory.GetHotbarSlot(i));
} // for i - Hotbar[] } // for i - Hotbar[]
@ -527,21 +527,30 @@ int cProtocol132::ParseClientStatuses(void)
int cProtocol132::ParseEncryptionKeyResponse(void) int cProtocol132::ParseEncryptionKeyResponse(void)
{ {
// Read the encryption key:
HANDLE_PACKET_READ(ReadBEShort, short, EncKeyLength); HANDLE_PACKET_READ(ReadBEShort, short, EncKeyLength);
if (EncKeyLength > MAX_ENC_LEN)
{
LOGD("Too long encryption key");
m_Client->Kick("Hacked client");
return PARSE_OK;
}
AString EncKey; AString EncKey;
if (!m_ReceivedData.ReadString(EncKey, EncKeyLength)) if (!m_ReceivedData.ReadString(EncKey, (size_t)EncKeyLength))
{ {
return PARSE_INCOMPLETE; return PARSE_INCOMPLETE;
} }
// Read the encryption nonce:
HANDLE_PACKET_READ(ReadBEShort, short, EncNonceLength); HANDLE_PACKET_READ(ReadBEShort, short, EncNonceLength);
AString EncNonce; AString EncNonce;
if (!m_ReceivedData.ReadString(EncNonce, EncNonceLength)) if (!m_ReceivedData.ReadString(EncNonce, (size_t)EncNonceLength))
{ {
return PARSE_INCOMPLETE; return PARSE_INCOMPLETE;
} }
if ((EncKeyLength > MAX_ENC_LEN) || (EncNonceLength > MAX_ENC_LEN)) if (EncNonceLength > MAX_ENC_LEN)
{ {
LOGD("Too long encryption"); LOGD("Too long encryption nonce");
m_Client->Kick("Hacked client"); m_Client->Kick("Hacked client");
return PARSE_OK; return PARSE_OK;
} }
@ -623,23 +632,23 @@ void cProtocol132::Flush(void)
LOGD("Flushing empty"); LOGD("Flushing empty");
return; return;
} }
const char * a_Data = m_DataToSend.data(); const char * Data = m_DataToSend.data();
int a_Size = m_DataToSend.size(); size_t Size = m_DataToSend.size();
if (m_IsEncrypted) if (m_IsEncrypted)
{ {
Byte Encrypted[8192]; // Larger buffer, we may be sending lots of data (chunks) Byte Encrypted[8192]; // Larger buffer, we may be sending lots of data (chunks)
while (a_Size > 0) while (Size > 0)
{ {
int NumBytes = (a_Size > (int)sizeof(Encrypted)) ? (int)sizeof(Encrypted) : a_Size; size_t NumBytes = (Size > sizeof(Encrypted)) ? sizeof(Encrypted) : Size;
m_Encryptor.ProcessData(Encrypted, (Byte *)a_Data, NumBytes); m_Encryptor.ProcessData(Encrypted, (Byte *)Data, NumBytes);
super::SendData((const char *)Encrypted, NumBytes); super::SendData((const char *)Encrypted, NumBytes);
a_Size -= NumBytes; Size -= NumBytes;
a_Data += NumBytes; Data += NumBytes;
} }
} }
else else
{ {
super::SendData(a_Data, a_Size); super::SendData(Data, Size);
} }
m_DataToSend.clear(); m_DataToSend.clear();
} }
@ -665,7 +674,7 @@ void cProtocol132::WriteItem(const cItem & a_Item)
} }
WriteShort(ItemType); WriteShort(ItemType);
WriteByte (a_Item.m_ItemCount); WriteChar (a_Item.m_ItemCount);
WriteShort(a_Item.m_ItemDamage); WriteShort(a_Item.m_ItemDamage);
if (a_Item.m_Enchantments.IsEmpty()) if (a_Item.m_Enchantments.IsEmpty())
@ -681,7 +690,7 @@ void cProtocol132::WriteItem(const cItem & a_Item)
Writer.Finish(); Writer.Finish();
AString Compressed; AString Compressed;
CompressStringGZIP(Writer.GetResult().data(), Writer.GetResult().size(), Compressed); CompressStringGZIP(Writer.GetResult().data(), Writer.GetResult().size(), Compressed);
WriteShort(Compressed.size()); WriteShort((short)Compressed.size());
SendData(Compressed.data(), Compressed.size()); SendData(Compressed.data(), Compressed.size());
} }
@ -717,8 +726,8 @@ int cProtocol132::ParseItem(cItem & a_Item)
// Read the metadata // Read the metadata
AString Metadata; AString Metadata;
Metadata.resize(MetadataLength); Metadata.resize((size_t)MetadataLength);
if (!m_ReceivedData.ReadBuf((void *)Metadata.data(), MetadataLength)) if (!m_ReceivedData.ReadBuf((void *)Metadata.data(), (size_t)MetadataLength))
{ {
return PARSE_INCOMPLETE; return PARSE_INCOMPLETE;
} }

View File

@ -531,7 +531,7 @@ AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a
format binary data this way: format binary data this way:
00001234: 31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 1234567890abcdef 00001234: 31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 1234567890abcdef
*/ */
AString & CreateHexDump(AString & a_Out, const void * a_Data, int a_Size, int a_LineLength) AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, int a_LineLength)
{ {
ASSERT(a_LineLength <= 120); // Due to using a fixed size line buffer; increase line[]'s size to lift this max ASSERT(a_LineLength <= 120); // Due to using a fixed size line buffer; increase line[]'s size to lift this max
char line[512]; char line[512];

View File

@ -64,7 +64,7 @@ extern AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString &
extern AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16); extern AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16);
/// Creates a nicely formatted HEX dump of the given memory block. Max a_BytesPerLine is 120 /// Creates a nicely formatted HEX dump of the given memory block. Max a_BytesPerLine is 120
extern AString & CreateHexDump(AString & a_Out, const void * a_Data, int a_Size, int a_BytesPerLine); extern AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, int a_BytesPerLine);
/// Returns a copy of a_Message with all quotes and backslashes escaped by a backslash /// Returns a copy of a_Message with all quotes and backslashes escaped by a backslash
extern AString EscapeString(const AString & a_Message); // tolua_export extern AString EscapeString(const AString & a_Message); // tolua_export