From 8464f689ea214d3c30105ae58539885cf1268317 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 4 Feb 2014 10:59:05 -0800 Subject: Improved Type safety of eBlockFace May Fix #640 --- src/Protocol/Protocol125.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Protocol/Protocol125.cpp') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 323a13992..73d21161c 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1211,7 +1211,7 @@ int cProtocol125::ParseBlockDig(void) HANDLE_PACKET_READ(ReadByte, Byte, PosY); HANDLE_PACKET_READ(ReadBEInt, int, PosZ); HANDLE_PACKET_READ(ReadChar, char, BlockFace); - m_Client->HandleLeftClick(PosX, PosY, PosZ, BlockFace, Status); + m_Client->HandleLeftClick(PosX, PosY, PosZ, static_cast(BlockFace), Status); return PARSE_OK; } @@ -1234,7 +1234,7 @@ int cProtocol125::ParseBlockPlace(void) } // 1.2.5 didn't have any cursor position, so use 8, 8, 8, so that halfslabs and stairs work correctly and the special value is recognizable. - m_Client->HandleRightClick(PosX, PosY, PosZ, BlockFace, 8, 8, 8, HeldItem); + m_Client->HandleRightClick(PosX, PosY, PosZ, static_cast(BlockFace), 8, 8, 8, HeldItem); return PARSE_OK; } -- cgit v1.2.3 From 92e85cc96030285bba74837759925866c1be7235 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 13 Feb 2014 17:13:09 +0200 Subject: Implementation of in-game maps --- src/Protocol/Protocol125.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/Protocol/Protocol125.cpp') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 73d21161c..edb22fae6 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -95,6 +95,7 @@ enum PACKET_WINDOW_PROPERTY = 0x69, PACKET_CREATIVE_INVENTORY_ACTION = 0x6B, PACKET_UPDATE_SIGN = 0x82, + PACKET_ITEM_DATA = 0x83, PACKET_PLAYER_LIST_ITEM = 0xC9, PACKET_PLAYER_ABILITIES = 0xca, PACKET_PLUGIN_MESSAGE = 0xfa, @@ -576,6 +577,32 @@ void cProtocol125::SendLogin(const cPlayer & a_Player, const cWorld & a_World) +void cProtocol125::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colors, unsigned int a_Length) +{ + cCSLock Lock(m_CSPacket); + + WriteByte (PACKET_ITEM_DATA); + WriteShort(E_ITEM_MAP); + WriteShort(a_ID); + WriteShort(3 + a_Length); + + WriteByte(0); + WriteByte(a_X); + WriteByte(a_Y); + + for (unsigned int i = 0; i < a_Length; ++i) + { + WriteByte(a_Colors[i]); + } + + Flush(); +} + + + + + + void cProtocol125::SendPickupSpawn(const cPickup & a_Pickup) { cCSLock Lock(m_CSPacket); -- cgit v1.2.3 From 0f1f7583aeea65335b2ee051585a857b1142a927 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 15 Feb 2014 23:16:44 +0100 Subject: Implemented cCompositeChat. This allows plugins to send composite chat messages, containing URLs, commands to run and cmdline suggestions. Fixes #678. --- src/Protocol/Protocol125.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/Protocol/Protocol125.cpp') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 73d21161c..7020699d1 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -32,6 +32,8 @@ Documentation: #include "../Mobs/IncludeAllMonsters.h" +#include "../CompositeChat.h" + @@ -233,6 +235,42 @@ void cProtocol125::SendChat(const AString & a_Message) +void cProtocol125::SendChat(const cCompositeChat & a_Message) +{ + // This version doesn't support composite messages, just extract each part's text and use it: + AString Msg; + const cCompositeChat::cParts & Parts = a_Message.GetParts(); + for (cCompositeChat::cParts::const_iterator itr = Parts.begin(), end = Parts.end(); itr != end; ++itr) + { + switch ((*itr)->m_PartType) + { + case cCompositeChat::ptText: + case cCompositeChat::ptClientTranslated: + case cCompositeChat::ptRunCommand: + case cCompositeChat::ptSuggestCommand: + { + Msg.append((*itr)->m_Text); + break; + } + case cCompositeChat::ptUrl: + { + Msg.append(((cCompositeChat::cUrlPart *)(*itr))->m_Url); + break; + } + } // switch (PartType) + } // for itr - Parts[] + + // Send the message: + cCSLock Lock(m_CSPacket); + WriteByte (PACKET_CHAT); + WriteString(Msg); + Flush(); +} + + + + + void cProtocol125::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) { cCSLock Lock(m_CSPacket); -- cgit v1.2.3 From 393ca0221dfdb6dabadcf293fea86a830453c938 Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 18 Feb 2014 20:50:08 +0200 Subject: Map decorators; Map clients --- src/Protocol/Protocol125.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/Protocol/Protocol125.cpp') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index edb22fae6..220fa18cf 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -602,6 +602,31 @@ void cProtocol125::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colo +void cProtocol125::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decorators) +{ + cCSLock Lock(m_CSPacket); + + WriteByte (PACKET_ITEM_DATA); + WriteShort(E_ITEM_MAP); + WriteShort(a_ID); + WriteShort(1 + (3 * a_Decorators.size())); + + WriteByte(1); + + for (cMapDecoratorList::const_iterator it = a_Decorators.begin(); it != a_Decorators.end(); ++it) + { + WriteByte((it->GetType() << 4) | (it->GetRot() & 0xf)); + WriteByte(it->GetPixelX()); + WriteByte(it->GetPixelZ()); + } + + Flush(); +} + + + + + void cProtocol125::SendPickupSpawn(const cPickup & a_Pickup) { -- cgit v1.2.3 From d33d72f0dc9ef8969c6b57592fbce54165641591 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 7 Mar 2014 11:04:25 -0800 Subject: Warnings --- src/Protocol/Protocol125.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Protocol/Protocol125.cpp') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 3980350f5..e032e4050 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1186,7 +1186,7 @@ void cProtocol125::SendData(const char * a_Data, int a_Size) -void cProtocol125::DataReceived(const char * a_Data, int a_Size) +void cProtocol125::DataReceived(const char * a_Data, size_t a_Size) { if (!m_ReceivedData.Write(a_Data, a_Size)) { -- cgit v1.2.3 From 66970fe943ccc414c2f4fb722852f0461b8ddca2 Mon Sep 17 00:00:00 2001 From: Jan-Fabian Humann Date: Sat, 8 Mar 2014 17:55:53 +0100 Subject: Split cClientHandle::HandleEntityAction() into three seperate functions HandleEntityCrouch, HandleEntityLeaveBed and HandleEntitySprinting. --- src/Protocol/Protocol125.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/Protocol/Protocol125.cpp') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 3980350f5..556ed1d08 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1375,7 +1375,28 @@ int cProtocol125::ParseEntityAction(void) { HANDLE_PACKET_READ(ReadBEInt, int, EntityID); HANDLE_PACKET_READ(ReadChar, char, ActionID); - m_Client->HandleEntityAction(EntityID, ActionID); + + if (ActionID == 1) // Crouch + { + m_Client->HandleEntityCrouch(EntityID, true); + } + else if (ActionID == 2) // Uncrouch + { + m_Client->HandleEntityCrouch(EntityID, false); + } + else if (ActionID == 3) // Leave Bed + { + m_Client->HandleEntityLeaveBed(EntityID); + } + else if (ActionID == 4) // Start sprinting + { + m_Client->HandleEntitySprinting(EntityID, true); + } + else if (ActionID == 5) // Stop sprinting + { + m_Client->HandleEntitySprinting(EntityID, false); + } + return PARSE_OK; } -- cgit v1.2.3 From 72f9c8b06970cb351121ad1e02cccc268db8c56d Mon Sep 17 00:00:00 2001 From: Jan-Fabian Humann Date: Sat, 8 Mar 2014 19:26:32 +0100 Subject: Changed if-else to switch-case --- src/Protocol/Protocol125.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'src/Protocol/Protocol125.cpp') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 556ed1d08..169ab0c85 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1376,25 +1376,23 @@ int cProtocol125::ParseEntityAction(void) HANDLE_PACKET_READ(ReadBEInt, int, EntityID); HANDLE_PACKET_READ(ReadChar, char, ActionID); - if (ActionID == 1) // Crouch + switch (ActionID) { + case 1: // Crouch m_Client->HandleEntityCrouch(EntityID, true); - } - else if (ActionID == 2) // Uncrouch - { + break; + case 2: // Uncrouch m_Client->HandleEntityCrouch(EntityID, false); - } - else if (ActionID == 3) // Leave Bed - { + break; + case 3: // Leave Bed m_Client->HandleEntityLeaveBed(EntityID); - } - else if (ActionID == 4) // Start sprinting - { + break; + case 4: // Start sprinting m_Client->HandleEntitySprinting(EntityID, true); - } - else if (ActionID == 5) // Stop sprinting - { + break; + case 5: // Stop sprinting m_Client->HandleEntitySprinting(EntityID, false); + break; } return PARSE_OK; -- cgit v1.2.3 From f74ee8fb51c015f678438cc1dccf23d1d3c2cf6a Mon Sep 17 00:00:00 2001 From: Jan-Fabian Humann Date: Sun, 9 Mar 2014 10:55:06 +0100 Subject: Adjusted style of switch/case --- src/Protocol/Protocol125.cpp | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'src/Protocol/Protocol125.cpp') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 169ab0c85..ca286bafb 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1378,21 +1378,11 @@ int cProtocol125::ParseEntityAction(void) switch (ActionID) { - case 1: // Crouch - m_Client->HandleEntityCrouch(EntityID, true); - break; - case 2: // Uncrouch - m_Client->HandleEntityCrouch(EntityID, false); - break; - case 3: // Leave Bed - m_Client->HandleEntityLeaveBed(EntityID); - break; - case 4: // Start sprinting - m_Client->HandleEntitySprinting(EntityID, true); - break; - case 5: // Stop sprinting - m_Client->HandleEntitySprinting(EntityID, false); - break; + case 1: m_Client->HandleEntityCrouch(EntityID, true); break; // Crouch + case 2: m_Client->HandleEntityCrouch(EntityID, false); break; // Uncrouch + case 3: m_Client->HandleEntityLeaveBed(EntityID); break; // Leave Bed + case 4: m_Client->HandleEntitySprinting(EntityID, true); break; // Start sprinting + case 5: m_Client->HandleEntitySprinting(EntityID, false); break; // Stop sprinting } return PARSE_OK; -- cgit v1.2.3 From 7c974b27b1c334da3cd83769398fa9104a2e3253 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 10:42:52 -0700 Subject: Removed unused macro --- src/Protocol/Protocol125.cpp | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'src/Protocol/Protocol125.cpp') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 50ebb6d43..69f4934d8 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1269,19 +1269,6 @@ int cProtocol125::ParsePacket(unsigned char a_PacketType) -#define HANDLE_PACKET_PARSE(Packet) \ - { \ - int res = Packet.Parse(m_ReceivedData); \ - if (res < 0) \ - { \ - return res; \ - } \ - } - - - - - int cProtocol125::ParseArmAnim(void) { HANDLE_PACKET_READ(ReadBEInt, int, EntityID); -- cgit v1.2.3 From 0fe1e50ffc744d861744e4aa4905e1b4b15e10fd Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 25 Mar 2014 10:32:58 +0200 Subject: Protocol: Wither metadata --- src/Protocol/Protocol125.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/Protocol/Protocol125.cpp') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 69f4934d8..d8b340350 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -1972,6 +1972,14 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) WriteByte(((const cWitch &)a_Mob).IsAngry() ? 1 : 0); // Aggravated? Doesn't seem to do anything break; } + case cMonster::mtWither: + { + WriteByte(0x54); // Int at index 20 + WriteInt(((const cWither &)a_Mob).GetNumInvulnerableTicks()); + WriteByte(0x66); // Float at index 6 + WriteFloat((float)(a_Mob.GetHealth())); + break; + } case cMonster::mtSlime: case cMonster::mtMagmaCube: { -- cgit v1.2.3 From 8126d9e66ef1ac90db2660ae357c9aa1c14c7126 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 31 Mar 2014 22:51:14 +0200 Subject: Console logging supports cCompositeChat as its parameters. --- src/Protocol/Protocol125.cpp | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) (limited to 'src/Protocol/Protocol125.cpp') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 69f4934d8..ea844c044 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -239,32 +239,11 @@ void cProtocol125::SendChat(const AString & a_Message) void cProtocol125::SendChat(const cCompositeChat & a_Message) { // This version doesn't support composite messages, just extract each part's text and use it: - AString Msg; - const cCompositeChat::cParts & Parts = a_Message.GetParts(); - for (cCompositeChat::cParts::const_iterator itr = Parts.begin(), end = Parts.end(); itr != end; ++itr) - { - switch ((*itr)->m_PartType) - { - case cCompositeChat::ptText: - case cCompositeChat::ptClientTranslated: - case cCompositeChat::ptRunCommand: - case cCompositeChat::ptSuggestCommand: - { - Msg.append((*itr)->m_Text); - break; - } - case cCompositeChat::ptUrl: - { - Msg.append(((cCompositeChat::cUrlPart *)(*itr))->m_Url); - break; - } - } // switch (PartType) - } // for itr - Parts[] // Send the message: cCSLock Lock(m_CSPacket); WriteByte (PACKET_CHAT); - WriteString(Msg); + WriteString(a_Message.ExtractText()); Flush(); } -- cgit v1.2.3 From 8825d30aabbee8cb2e452dc5a17deb6f9b6892a7 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 10:13:25 +0200 Subject: Fixed some Clang warnings in protocols. --- src/Protocol/Protocol125.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Protocol/Protocol125.cpp') 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); } -- cgit v1.2.3 From 4be894f0601fcfa182fda045b07b196e5dcd9343 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 11:47:46 +0200 Subject: More Clang warning fixes in the protocols. --- src/Protocol/Protocol125.cpp | 139 ++++++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 69 deletions(-) (limited to 'src/Protocol/Protocol125.cpp') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 0fa5c6de7..231ae410f 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -161,8 +161,8 @@ void cProtocol125::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, cha WriteInt (a_BlockX); WriteShort((short)a_BlockY); WriteInt (a_BlockZ); - WriteByte (a_Byte1); - WriteByte (a_Byte2); + WriteChar (a_Byte1); + WriteChar (a_Byte2); Flush(); } @@ -209,12 +209,12 @@ void cProtocol125::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockV WriteByte (PACKET_MULTI_BLOCK); WriteInt (a_ChunkX); WriteInt (a_ChunkZ); - WriteShort((unsigned short)a_Changes.size()); - WriteUInt (sizeof(int) * a_Changes.size()); + WriteShort((short)a_Changes.size()); + WriteUInt ((UInt32)(sizeof(int) * a_Changes.size())); for (sSetBlockVector::const_iterator itr = a_Changes.begin(), end = a_Changes.end(); itr != end; ++itr) { - unsigned int Coords = itr->y | (itr->z << 8) | (itr->x << 12); - unsigned int Blocks = itr->BlockMeta | (itr->BlockType << 4); + UInt32 Coords = ((UInt32)itr->y) | ((UInt32)(itr->z << 8)) | ((UInt32)(itr->x << 12)); + UInt32 Blocks = ((UInt32)itr->BlockMeta) | ((UInt32)(itr->BlockType << 4)); WriteUInt(Coords << 16 | Blocks); } Flush(); @@ -325,8 +325,8 @@ void cProtocol125::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, in cCSLock Lock(m_CSPacket); WriteByte (PACKET_ENTITY_EFFECT); WriteInt (a_Entity.GetUniqueID()); - WriteByte (a_EffectID); - WriteByte (a_Amplifier); + WriteByte ((Byte)a_EffectID); + WriteByte ((Byte)a_Amplifier); WriteShort(a_Duration); Flush(); } @@ -357,7 +357,7 @@ void cProtocol125::SendEntityHeadLook(const cEntity & a_Entity) cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENT_HEAD_LOOK); WriteInt (a_Entity.GetUniqueID()); - WriteByte((char)((a_Entity.GetHeadYaw() / 360.f) * 256)); + WriteChar((char)((a_Entity.GetHeadYaw() / 360.f) * 256)); Flush(); } @@ -372,8 +372,8 @@ void cProtocol125::SendEntityLook(const cEntity & a_Entity) cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENT_LOOK); WriteInt (a_Entity.GetUniqueID()); - WriteByte((char)((a_Entity.GetYaw() / 360.f) * 256)); - WriteByte((char)((a_Entity.GetPitch() / 360.f) * 256)); + WriteChar((char)((a_Entity.GetYaw() / 360.f) * 256)); + WriteChar((char)((a_Entity.GetPitch() / 360.f) * 256)); Flush(); } @@ -421,9 +421,9 @@ void cProtocol125::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENT_REL_MOVE); WriteInt (a_Entity.GetUniqueID()); - WriteByte(a_RelX); - WriteByte(a_RelY); - WriteByte(a_RelZ); + WriteChar(a_RelX); + WriteChar(a_RelY); + WriteChar(a_RelZ); Flush(); } @@ -438,11 +438,11 @@ void cProtocol125::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENT_REL_MOVE_LOOK); WriteInt (a_Entity.GetUniqueID()); - WriteByte(a_RelX); - WriteByte(a_RelY); - WriteByte(a_RelZ); - WriteByte((char)((a_Entity.GetYaw() / 360.f) * 256)); - WriteByte((char)((a_Entity.GetPitch() / 360.f) * 256)); + WriteChar(a_RelX); + WriteChar(a_RelY); + WriteChar(a_RelZ); + WriteChar((char)((a_Entity.GetYaw() / 360.f) * 256)); + WriteChar((char)((a_Entity.GetPitch() / 360.f) * 256)); Flush(); } @@ -455,7 +455,7 @@ void cProtocol125::SendEntityStatus(const cEntity & a_Entity, char a_Status) cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENT_STATUS); WriteInt (a_Entity.GetUniqueID()); - WriteByte(a_Status); + WriteChar(a_Status); Flush(); } @@ -488,7 +488,7 @@ void cProtocol125::SendExplosion(double a_BlockX, double a_BlockY, double a_Bloc WriteDouble (a_BlockY); WriteDouble (a_BlockZ); WriteFloat (a_Radius); - WriteInt (a_BlocksAffected.size()); + WriteInt ((Int32)a_BlocksAffected.size()); int BlockX = (int)a_BlockX; int BlockY = (int)a_BlockY; int BlockZ = (int)a_BlockZ; @@ -513,7 +513,7 @@ void cProtocol125::SendGameMode(eGameMode a_GameMode) cCSLock Lock(m_CSPacket); WriteByte(PACKET_CHANGE_GAME_STATE); WriteByte(3); - WriteByte((char)a_GameMode); + WriteChar((char)a_GameMode); Flush(); } @@ -538,7 +538,7 @@ void cProtocol125::SendHealth(void) cCSLock Lock(m_CSPacket); WriteByte (PACKET_UPDATE_HEALTH); WriteShort((short)m_Client->GetPlayer()->GetHealth()); - WriteShort(m_Client->GetPlayer()->GetFoodLevel()); + WriteShort((short)m_Client->GetPlayer()->GetFoodLevel()); WriteFloat((float)m_Client->GetPlayer()->GetFoodSaturationLevel()); Flush(); } @@ -551,7 +551,7 @@ void cProtocol125::SendInventorySlot(char a_WindowID, short a_SlotNum, const cIt { cCSLock Lock(m_CSPacket); WriteByte (PACKET_INVENTORY_SLOT); - WriteByte (a_WindowID); + WriteChar (a_WindowID); WriteShort(a_SlotNum); WriteItem (a_Item); Flush(); @@ -600,17 +600,14 @@ void cProtocol125::SendMapColumn(int a_ID, int a_X, int a_Y, const Byte * a_Colo WriteByte (PACKET_ITEM_DATA); WriteShort(E_ITEM_MAP); - WriteShort(a_ID); - WriteShort(3 + a_Length); + WriteShort((short)a_ID); + WriteShort((short)(3 + a_Length)); WriteByte(0); - WriteByte(a_X); - WriteByte(a_Y); + WriteChar((char)a_X); + WriteChar((char)a_Y); - for (unsigned int i = 0; i < a_Length; ++i) - { - WriteByte(a_Colors[i]); - } + SendData((const char *)a_Colors, a_Length); Flush(); } @@ -625,16 +622,16 @@ void cProtocol125::SendMapDecorators(int a_ID, const cMapDecoratorList & a_Decor WriteByte (PACKET_ITEM_DATA); WriteShort(E_ITEM_MAP); - WriteShort(a_ID); - WriteShort(1 + (3 * a_Decorators.size())); + WriteShort((short)a_ID); + WriteShort((short)(1 + (3 * a_Decorators.size()))); WriteByte(1); for (cMapDecoratorList::const_iterator it = a_Decorators.begin(); it != a_Decorators.end(); ++it) { - WriteByte((it->GetType() << 4) | (it->GetRot() & 0xf)); - WriteByte(it->GetPixelX()); - WriteByte(it->GetPixelZ()); + WriteByte((Byte)(it->GetType() << 4) | (it->GetRot() & 0xf)); + WriteByte((Byte)it->GetPixelX()); + WriteByte((Byte)it->GetPixelZ()); } Flush(); @@ -651,7 +648,7 @@ void cProtocol125::SendPickupSpawn(const cPickup & a_Pickup) WriteByte (PACKET_PICKUP_SPAWN); WriteInt (a_Pickup.GetUniqueID()); WriteShort (a_Pickup.GetItem().m_ItemType); - WriteByte (a_Pickup.GetItem().m_ItemCount); + WriteChar (a_Pickup.GetItem().m_ItemCount); WriteShort (a_Pickup.GetItem().m_ItemDamage); WriteVectorI((Vector3i)(a_Pickup.GetPosition() * 32)); WriteByte ((char)(a_Pickup.GetSpeed().x * 8)); @@ -669,7 +666,7 @@ void cProtocol125::SendEntityAnimation(const cEntity & a_Entity, char a_Animatio cCSLock Lock(m_CSPacket); WriteByte(PACKET_ANIMATION); WriteInt (a_Entity.GetUniqueID()); - WriteByte(a_Animation); + WriteChar(a_Animation); Flush(); } @@ -763,8 +760,8 @@ void cProtocol125::SendPlayerSpawn(const cPlayer & a_Player) WriteInt ((int)(a_Player.GetPosX() * 32)); WriteInt ((int)(a_Player.GetPosY() * 32)); WriteInt ((int)(a_Player.GetPosZ() * 32)); - WriteByte ((char)((a_Player.GetYaw() / 360.f) * 256)); - WriteByte ((char)((a_Player.GetPitch() / 360.f) * 256)); + WriteChar ((char)((a_Player.GetYaw() / 360.f) * 256)); + WriteChar ((char)((a_Player.GetPitch() / 360.f) * 256)); WriteShort (HeldItem.IsEmpty() ? 0 : HeldItem.m_ItemType); Flush(); } @@ -790,9 +787,9 @@ void cProtocol125::SendPluginMessage(const AString & a_Channel, const AString & void cProtocol125::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID) { cCSLock Lock(m_CSPacket); - WriteByte (PACKET_REMOVE_ENTITY_EFFECT); - WriteInt (a_Entity.GetUniqueID()); - WriteByte (a_EffectID); + WriteByte(PACKET_REMOVE_ENTITY_EFFECT); + WriteInt (a_Entity.GetUniqueID()); + WriteChar((char)a_EffectID); Flush(); } @@ -806,7 +803,7 @@ void cProtocol125::SendRespawn(void) WriteByte (PACKET_RESPAWN); WriteInt ((int)(m_Client->GetPlayer()->GetWorld()->GetDimension())); WriteByte (2); // TODO: Difficulty; 2 = Normal - WriteByte ((char)m_Client->GetPlayer()->GetGameMode()); + WriteChar ((char)m_Client->GetPlayer()->GetGameMode()); WriteShort (256); // Current world height WriteString("default"); } @@ -837,7 +834,7 @@ void cProtocol125::SendExperienceOrb(const cExpOrb & a_ExpOrb) WriteInt((int) a_ExpOrb.GetPosX()); WriteInt((int) a_ExpOrb.GetPosY()); WriteInt((int) a_ExpOrb.GetPosZ()); - WriteShort(a_ExpOrb.GetReward()); + WriteShort((short)a_ExpOrb.GetReward()); Flush(); } @@ -878,7 +875,7 @@ void cProtocol125::SendSpawnMob(const cMonster & a_Mob) cCSLock Lock(m_CSPacket); WriteByte (PACKET_SPAWN_MOB); WriteInt (a_Mob.GetUniqueID()); - WriteByte (a_Mob.GetMobType()); + WriteByte ((Byte)a_Mob.GetMobType()); WriteVectorI((Vector3i)(a_Mob.GetPosition() * 32)); WriteByte (0); WriteByte (0); @@ -903,7 +900,7 @@ void cProtocol125::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)); @@ -928,7 +925,7 @@ void cProtocol125::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)); @@ -966,8 +963,8 @@ void cProtocol125::SendTeleportEntity(const cEntity & a_Entity) WriteInt ((int)(floor(a_Entity.GetPosX() * 32))); WriteInt ((int)(floor(a_Entity.GetPosY() * 32))); WriteInt ((int)(floor(a_Entity.GetPosZ() * 32))); - WriteByte ((char)((a_Entity.GetYaw() / 360.f) * 256)); - WriteByte ((char)((a_Entity.GetPitch() / 360.f) * 256)); + WriteChar ((char)((a_Entity.GetYaw() / 360.f) * 256)); + WriteChar ((char)((a_Entity.GetPitch() / 360.f) * 256)); Flush(); } @@ -1042,7 +1039,7 @@ void cProtocol125::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_Bloc WriteInt (a_Entity.GetUniqueID()); WriteByte(0); // Unknown byte only 0 has been observed WriteInt (a_BlockX); - WriteByte(a_BlockY); + WriteByte((Byte)a_BlockY); WriteInt (a_BlockZ); Flush(); } @@ -1086,7 +1083,7 @@ void cProtocol125::SendWholeInventory(const cWindow & a_Window) cCSLock Lock(m_CSPacket); cItems Slots; a_Window.GetSlots(*(m_Client->GetPlayer()), Slots); - SendWindowSlots(a_Window.GetWindowID(), Slots.size(), &(Slots[0])); + SendWindowSlots(a_Window.GetWindowID(), (int)Slots.size(), &(Slots[0])); } @@ -1103,7 +1100,7 @@ void cProtocol125::SendWindowClose(const cWindow & a_Window) cCSLock Lock(m_CSPacket); WriteByte(PACKET_WINDOW_CLOSE); - WriteByte(a_Window.GetWindowID()); + WriteChar(a_Window.GetWindowID()); Flush(); } @@ -1120,10 +1117,10 @@ void cProtocol125::SendWindowOpen(const cWindow & a_Window) } cCSLock Lock(m_CSPacket); WriteByte (PACKET_WINDOW_OPEN); - WriteByte (a_Window.GetWindowID()); - WriteByte (a_Window.GetWindowType()); + WriteChar (a_Window.GetWindowID()); + WriteByte ((Byte)a_Window.GetWindowType()); WriteString(a_Window.GetWindowTitle()); - WriteByte (a_Window.GetNumNonInventorySlots()); + WriteByte ((Byte)a_Window.GetNumNonInventorySlots()); Flush(); } @@ -1135,7 +1132,7 @@ void cProtocol125::SendWindowProperty(const cWindow & a_Window, short a_Property { cCSLock Lock(m_CSPacket); WriteByte (PACKET_WINDOW_PROPERTY); - WriteByte (a_Window.GetWindowID()); + WriteChar (a_Window.GetWindowID()); WriteShort(a_Property); WriteShort(a_Value); Flush(); @@ -1527,7 +1524,7 @@ int cProtocol125::ParsePluginMessage(void) HANDLE_PACKET_READ(ReadBEUTF16String16, AString, ChannelName); HANDLE_PACKET_READ(ReadBEShort, short, Length); AString Data; - if (!m_ReceivedData.ReadString(Data, Length)) + if (!m_ReceivedData.ReadString(Data, (size_t)Length)) { m_ReceivedData.CheckValid(); return PARSE_INCOMPLETE; @@ -1688,7 +1685,7 @@ void cProtocol125::SendPreChunk(int a_ChunkX, int a_ChunkZ, bool a_ShouldLoad) void cProtocol125::SendWindowSlots(char a_WindowID, int a_NumItems, const cItem * a_Items) { WriteByte (PACKET_INVENTORY_WHOLE); - WriteByte (a_WindowID); + WriteChar (a_WindowID); WriteShort((short)a_NumItems); for (int j = 0; j < a_NumItems; j++) @@ -1718,7 +1715,7 @@ void cProtocol125::WriteItem(const cItem & a_Item) return; } - WriteByte (a_Item.m_ItemCount); + WriteChar (a_Item.m_ItemCount); WriteShort(a_Item.m_ItemDamage); if (cItem::IsEnchantable(a_Item.m_ItemType)) @@ -1765,7 +1762,7 @@ int cProtocol125::ParseItem(cItem & a_Item) } // TODO: Enchantment not implemented yet! - if (!m_ReceivedData.SkipRead(EnchantNumBytes)) + if (!m_ReceivedData.SkipRead((size_t)EnchantNumBytes)) { return PARSE_INCOMPLETE; } @@ -1850,7 +1847,7 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) case cMonster::mtCreeper: { WriteByte(0x10); - WriteByte(((const cCreeper &)a_Mob).IsBlowing() ? 1 : -1); // Blowing up? + WriteChar(((const cCreeper &)a_Mob).IsBlowing() ? 1 : -1); // Blowing up? WriteByte(0x11); WriteByte(((const cCreeper &)a_Mob).IsCharged() ? 1 : 0); // Lightning-charged? break; @@ -1920,9 +1917,9 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) WriteByte(0x10); Byte SheepMetadata = 0; - SheepMetadata = ((const cSheep &)a_Mob).GetFurColor(); // Fur colour + SheepMetadata = (Byte)((const cSheep &)a_Mob).GetFurColor(); - if (((const cSheep &)a_Mob).IsSheared()) // Is sheared? + if (((const cSheep &)a_Mob).IsSheared()) { SheepMetadata |= 0x16; } @@ -1954,7 +1951,7 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) case cMonster::mtWither: { WriteByte(0x54); // Int at index 20 - WriteInt(((const cWither &)a_Mob).GetNumInvulnerableTicks()); + WriteInt((Int32)((const cWither &)a_Mob).GetNumInvulnerableTicks()); WriteByte(0x66); // Float at index 6 WriteFloat((float)(a_Mob.GetHealth())); break; @@ -1965,11 +1962,11 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) WriteByte(0x10); if (a_Mob.GetMobType() == cMonster::mtSlime) { - WriteByte(((const cSlime &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME + WriteByte((Byte)((const cSlime &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME } else { - WriteByte(((const cMagmaCube &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME + WriteByte((Byte)((const cMagmaCube &)a_Mob).GetSize()); // Size of slime - HEWGE, meh, cute BABBY SLIME } break; } @@ -2008,7 +2005,7 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) WriteInt(Flags); WriteByte(0x13); - WriteByte(((const cHorse &)a_Mob).GetHorseType()); // Type of horse (donkey, chestnut, etc.) + WriteByte((Byte)((const cHorse &)a_Mob).GetHorseType()); // Type of horse (donkey, chestnut, etc.) WriteByte(0x54); int Appearance = 0; @@ -2020,6 +2017,10 @@ void cProtocol125::WriteMobMetadata(const cMonster & a_Mob) WriteInt(((const cHorse &)a_Mob).GetHorseArmour()); // Horshey armour break; } + default: + { + break; + } } } -- cgit v1.2.3 From 87f39e9e287aa1a7e513036f5004ec24ac789f40 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 13:19:25 +0200 Subject: Explicit change record size. --- src/Protocol/Protocol125.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Protocol/Protocol125.cpp') diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index 231ae410f..bf946ef19 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -210,7 +210,7 @@ void cProtocol125::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockV WriteInt (a_ChunkX); WriteInt (a_ChunkZ); WriteShort((short)a_Changes.size()); - WriteUInt ((UInt32)(sizeof(int) * a_Changes.size())); + WriteUInt ((UInt32)(4 * a_Changes.size())); for (sSetBlockVector::const_iterator itr = a_Changes.begin(), end = a_Changes.end(); itr != end; ++itr) { UInt32 Coords = ((UInt32)itr->y) | ((UInt32)(itr->z << 8)) | ((UInt32)(itr->x << 12)); -- cgit v1.2.3