From eb3ed1aec1fb9e4468a7829cabd42572b7554d70 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 19 Aug 2012 11:51:17 +0000 Subject: Another handful of packets rewritten. Also changed cItem::m_ItemID into m_ItemType of type short. Easier handling. m_ItemID kept for compatibility reasons (Lua-interface etc.) git-svn-id: http://mc-server.googlecode.com/svn/trunk@756 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Bindings.cpp | 33 ++++--- source/Bindings.h | 2 +- source/Defines.h | 20 ++-- source/PacketID.h | 5 +- source/cChunk.cpp | 32 ++++++ source/cChunk.h | 3 + source/cChunkMap.cpp | 32 ++++++ source/cChunkMap.h | 6 ++ source/cClientHandle.cpp | 154 +++++++++++++++++++++++------ source/cClientHandle.h | 20 ++-- source/cInventory.cpp | 7 +- source/cInventory.h | 6 +- source/cItem.h | 17 ++-- source/cWindow.cpp | 20 +--- source/cWindow.h | 6 +- source/cWorld.cpp | 18 ++++ source/cWorld.h | 2 + source/packets/cPacket_EntityEquipment.cpp | 24 ++--- source/packets/cPacket_EntityEquipment.h | 23 ++--- source/packets/cPacket_Player.cpp | 48 ++++----- source/packets/cPacket_Player.h | 20 ++-- source/packets/cPacket_WholeInventory.cpp | 20 ++-- source/packets/cPacket_WholeInventory.h | 24 ++--- source/packets/cPacket_WindowClose.cpp | 4 +- source/packets/cPacket_WindowClose.h | 13 +-- 25 files changed, 376 insertions(+), 183 deletions(-) diff --git a/source/Bindings.cpp b/source/Bindings.cpp index f48077d68..b1a7867b3 100644 --- a/source/Bindings.cpp +++ b/source/Bindings.cpp @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 08/18/12 12:40:25. +** Generated automatically by tolua++-1.0.92 on 08/19/12 13:48:32. */ #ifndef __cplusplus @@ -2890,7 +2890,7 @@ static int tolua_AllToLua_ItemCategory_IsPickaxe00(lua_State* tolua_S) else #endif { - ENUM_ITEM_ID a_ItemID = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,1,0)); + short a_ItemID = ((short) tolua_tonumber(tolua_S,1,0)); { bool tolua_ret = (bool) ItemCategory::IsPickaxe(a_ItemID); tolua_pushboolean(tolua_S,(bool)tolua_ret); @@ -2919,7 +2919,7 @@ static int tolua_AllToLua_ItemCategory_IsAxe00(lua_State* tolua_S) else #endif { - ENUM_ITEM_ID a_ItemID = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,1,0)); + short a_ItemID = ((short) tolua_tonumber(tolua_S,1,0)); { bool tolua_ret = (bool) ItemCategory::IsAxe(a_ItemID); tolua_pushboolean(tolua_S,(bool)tolua_ret); @@ -2948,7 +2948,7 @@ static int tolua_AllToLua_ItemCategory_IsSword00(lua_State* tolua_S) else #endif { - ENUM_ITEM_ID a_ItemID = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,1,0)); + short a_ItemID = ((short) tolua_tonumber(tolua_S,1,0)); { bool tolua_ret = (bool) ItemCategory::IsSword(a_ItemID); tolua_pushboolean(tolua_S,(bool)tolua_ret); @@ -2977,7 +2977,7 @@ static int tolua_AllToLua_ItemCategory_IsHoe00(lua_State* tolua_S) else #endif { - ENUM_ITEM_ID a_ItemID = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,1,0)); + short a_ItemID = ((short) tolua_tonumber(tolua_S,1,0)); { bool tolua_ret = (bool) ItemCategory::IsHoe(a_ItemID); tolua_pushboolean(tolua_S,(bool)tolua_ret); @@ -3006,7 +3006,7 @@ static int tolua_AllToLua_ItemCategory_IsShovel00(lua_State* tolua_S) else #endif { - ENUM_ITEM_ID a_ItemID = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,1,0)); + short a_ItemID = ((short) tolua_tonumber(tolua_S,1,0)); { bool tolua_ret = (bool) ItemCategory::IsShovel(a_ItemID); tolua_pushboolean(tolua_S,(bool)tolua_ret); @@ -3035,7 +3035,7 @@ static int tolua_AllToLua_ItemCategory_IsTool00(lua_State* tolua_S) else #endif { - ENUM_ITEM_ID a_ItemID = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,1,0)); + short a_ItemID = ((short) tolua_tonumber(tolua_S,1,0)); { bool tolua_ret = (bool) ItemCategory::IsTool(a_ItemID); tolua_pushboolean(tolua_S,(bool)tolua_ret); @@ -3064,7 +3064,7 @@ static int tolua_AllToLua_ItemCategory_IsHelmet00(lua_State* tolua_S) else #endif { - ENUM_ITEM_ID a_ItemType = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,1,0)); + short a_ItemType = ((short) tolua_tonumber(tolua_S,1,0)); { bool tolua_ret = (bool) ItemCategory::IsHelmet(a_ItemType); tolua_pushboolean(tolua_S,(bool)tolua_ret); @@ -3093,7 +3093,7 @@ static int tolua_AllToLua_ItemCategory_IsChestPlate00(lua_State* tolua_S) else #endif { - ENUM_ITEM_ID a_ItemType = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,1,0)); + short a_ItemType = ((short) tolua_tonumber(tolua_S,1,0)); { bool tolua_ret = (bool) ItemCategory::IsChestPlate(a_ItemType); tolua_pushboolean(tolua_S,(bool)tolua_ret); @@ -3122,7 +3122,7 @@ static int tolua_AllToLua_ItemCategory_IsLeggings00(lua_State* tolua_S) else #endif { - ENUM_ITEM_ID a_ItemType = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,1,0)); + short a_ItemType = ((short) tolua_tonumber(tolua_S,1,0)); { bool tolua_ret = (bool) ItemCategory::IsLeggings(a_ItemType); tolua_pushboolean(tolua_S,(bool)tolua_ret); @@ -3151,7 +3151,7 @@ static int tolua_AllToLua_ItemCategory_IsBoots00(lua_State* tolua_S) else #endif { - ENUM_ITEM_ID a_ItemType = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,1,0)); + short a_ItemType = ((short) tolua_tonumber(tolua_S,1,0)); { bool tolua_ret = (bool) ItemCategory::IsBoots(a_ItemType); tolua_pushboolean(tolua_S,(bool)tolua_ret); @@ -12661,11 +12661,11 @@ static int tolua_AllToLua_cItem_new00(lua_State* tolua_S) else #endif { - ENUM_ITEM_ID a_ItemID = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,2,E_ITEM_EMPTY)); + short a_ItemType = ((short) tolua_tonumber(tolua_S,2,E_ITEM_EMPTY)); char a_ItemCount = ((char) tolua_tonumber(tolua_S,3,0)); short a_ItemHealth = ((short) tolua_tonumber(tolua_S,4,0)); { - cItem* tolua_ret = (cItem*) Mtolua_new((cItem)(a_ItemID,a_ItemCount,a_ItemHealth)); + cItem* tolua_ret = (cItem*) Mtolua_new((cItem)(a_ItemType,a_ItemCount,a_ItemHealth)); tolua_pushusertype(tolua_S,(void*)tolua_ret,"cItem"); } } @@ -12695,11 +12695,11 @@ static int tolua_AllToLua_cItem_new00_local(lua_State* tolua_S) else #endif { - ENUM_ITEM_ID a_ItemID = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,2,E_ITEM_EMPTY)); + short a_ItemType = ((short) tolua_tonumber(tolua_S,2,E_ITEM_EMPTY)); char a_ItemCount = ((char) tolua_tonumber(tolua_S,3,0)); short a_ItemHealth = ((short) tolua_tonumber(tolua_S,4,0)); { - cItem* tolua_ret = (cItem*) Mtolua_new((cItem)(a_ItemID,a_ItemCount,a_ItemHealth)); + cItem* tolua_ret = (cItem*) Mtolua_new((cItem)(a_ItemType,a_ItemCount,a_ItemHealth)); tolua_pushusertype(tolua_S,(void*)tolua_ret,"cItem"); tolua_register_gc(tolua_S,lua_gettop(tolua_S)); } @@ -13059,7 +13059,7 @@ static int tolua_set_cItem_m_ItemID(lua_State* tolua_S) if (!tolua_isnumber(tolua_S,2,0,&tolua_err)) tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); #endif - self->m_ItemID = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,2,0)) + self->m_ItemID = ((short) tolua_tonumber(tolua_S,2,0)) ; return 0; } @@ -21282,6 +21282,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_constant(tolua_S,"E_PLAYERMOVELOOK",E_PLAYERMOVELOOK); tolua_constant(tolua_S,"E_BLOCK_DIG",E_BLOCK_DIG); tolua_constant(tolua_S,"E_BLOCK_PLACE",E_BLOCK_PLACE); + tolua_constant(tolua_S,"E_SLOT_SELECTED",E_SLOT_SELECTED); tolua_constant(tolua_S,"E_ITEM_SWITCH",E_ITEM_SWITCH); tolua_constant(tolua_S,"E_ADD_TO_INV",E_ADD_TO_INV); tolua_constant(tolua_S,"E_ANIMATION",E_ANIMATION); diff --git a/source/Bindings.h b/source/Bindings.h index 1468ba3a7..769910f51 100644 --- a/source/Bindings.h +++ b/source/Bindings.h @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 08/18/12 12:40:25. +** Generated automatically by tolua++-1.0.92 on 08/19/12 13:48:33. */ /* Exported function */ diff --git a/source/Defines.h b/source/Defines.h index 4f8473ac5..15c94c081 100644 --- a/source/Defines.h +++ b/source/Defines.h @@ -222,7 +222,7 @@ inline float GetSpecialSignf( float a_Val ) //tolua_begin namespace ItemCategory { - inline bool IsPickaxe(ENUM_ITEM_ID a_ItemID) + inline bool IsPickaxe(short a_ItemID) { return (a_ItemID == E_ITEM_WOODEN_PICKAXE) || (a_ItemID == E_ITEM_STONE_PICKAXE) @@ -233,7 +233,7 @@ namespace ItemCategory - inline bool IsAxe(ENUM_ITEM_ID a_ItemID) + inline bool IsAxe(short a_ItemID) { return (a_ItemID == E_ITEM_WOODEN_AXE) || (a_ItemID == E_ITEM_STONE_AXE) @@ -244,7 +244,7 @@ namespace ItemCategory - inline bool IsSword(ENUM_ITEM_ID a_ItemID) + inline bool IsSword(short a_ItemID) { return (a_ItemID == E_ITEM_WOODEN_SWORD) || (a_ItemID == E_ITEM_STONE_SWORD) @@ -255,7 +255,7 @@ namespace ItemCategory - inline bool IsHoe(ENUM_ITEM_ID a_ItemID) + inline bool IsHoe(short a_ItemID) { return (a_ItemID == E_ITEM_WOODEN_HOE) || (a_ItemID == E_ITEM_STONE_HOE) @@ -266,7 +266,7 @@ namespace ItemCategory - inline bool IsShovel(ENUM_ITEM_ID a_ItemID) + inline bool IsShovel(short a_ItemID) { return (a_ItemID == E_ITEM_WOODEN_SHOVEL) || (a_ItemID == E_ITEM_STONE_SHOVEL) @@ -277,7 +277,7 @@ namespace ItemCategory - inline bool IsTool(ENUM_ITEM_ID a_ItemID) + inline bool IsTool(short a_ItemID) { return IsPickaxe( a_ItemID ) || IsAxe ( a_ItemID ) @@ -288,7 +288,7 @@ namespace ItemCategory - inline bool IsHelmet(ENUM_ITEM_ID a_ItemType) + inline bool IsHelmet(short a_ItemType) { return ( (a_ItemType == E_ITEM_LEATHER_CAP) || @@ -301,7 +301,7 @@ namespace ItemCategory - inline bool IsChestPlate(ENUM_ITEM_ID a_ItemType) + inline bool IsChestPlate(short a_ItemType) { return ( (a_ItemType == E_ITEM_LEATHER_TUNIC) || @@ -314,7 +314,7 @@ namespace ItemCategory - inline bool IsLeggings(ENUM_ITEM_ID a_ItemType) + inline bool IsLeggings(short a_ItemType) { return ( (a_ItemType == E_ITEM_LEATHER_PANTS) || @@ -327,7 +327,7 @@ namespace ItemCategory - inline bool IsBoots(ENUM_ITEM_ID a_ItemType) + inline bool IsBoots(short a_ItemType) { return ( (a_ItemType == E_ITEM_LEATHER_BOOTS) || diff --git a/source/PacketID.h b/source/PacketID.h index 249760d3c..aa7fec4c0 100644 --- a/source/PacketID.h +++ b/source/PacketID.h @@ -23,8 +23,9 @@ enum ENUM_PACKET_ID E_PLAYERMOVELOOK = 0x0d, E_BLOCK_DIG = 0x0e, E_BLOCK_PLACE = 0x0f, - E_ITEM_SWITCH = 0x10, - E_ADD_TO_INV = 0x11, // TODO: Sure this is not Use Bed?? + E_SLOT_SELECTED = 0x10, + E_ITEM_SWITCH = 0x10, // OBSOLETE, use E_SLOT_SELECTED instead + E_ADD_TO_INV = 0x11, // TODO: Sure this is not Use Bed?? E_ANIMATION = 0x12, E_PACKET_13 = 0x13, E_NAMED_ENTITY_SPAWN = 0x14, diff --git a/source/cChunk.cpp b/source/cChunk.cpp index fc1b7de95..11995b176 100644 --- a/source/cChunk.cpp +++ b/source/cChunk.cpp @@ -1755,6 +1755,38 @@ void cChunk::Broadcast( const cPacket * a_Packet, cClientHandle* a_Exclude) +void cChunk::BroadcastPlayerAnimation(const cPlayer & a_Player, char a_Animation, const cClientHandle * a_Exclude) +{ + for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr ) + { + if (*itr == a_Exclude) + { + continue; + } + (*itr)->SendPlayerAnimation(a_Player, a_Animation); + } // for itr - LoadedByClient[] +} + + + + + +void cChunk::BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude) +{ + for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr ) + { + if (*itr == a_Exclude) + { + continue; + } + (*itr)->SendEntityEquipment(a_Entity, a_SlotNum, a_Item); + } // for itr - LoadedByClient[] +} + + + + + void cChunk::PositionToWorldPosition(int a_ChunkX, int a_ChunkY, int a_ChunkZ, int & a_X, int & a_Y, int & a_Z) { a_Y = a_ChunkY; diff --git a/source/cChunk.h b/source/cChunk.h index 898a05f86..375f9a17b 100644 --- a/source/cChunk.h +++ b/source/cChunk.h @@ -174,6 +174,9 @@ public: // Broadcasts to all clients that have loaded this chunk void Broadcast( const cPacket & a_Packet, cClientHandle * a_Exclude = NULL) {Broadcast(&a_Packet, a_Exclude); } void Broadcast( const cPacket * a_Packet, cClientHandle * a_Exclude = NULL); + + void BroadcastPlayerAnimation(const cPlayer & a_Player, char a_Animation, const cClientHandle * a_Exclude = NULL); + void BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude = NULL); void PositionToWorldPosition(int a_ChunkX, int a_ChunkY, int a_ChunkZ, int & a_X, int & a_Y, int & a_Z); Vector3i PositionToWorldPosition( const Vector3i & a_InChunkPos ) { return PositionToWorldPosition( a_InChunkPos.x, a_InChunkPos.y, a_InChunkPos.z ); } diff --git a/source/cChunkMap.cpp b/source/cChunkMap.cpp index a0f1e128c..5adc8f2c1 100644 --- a/source/cChunkMap.cpp +++ b/source/cChunkMap.cpp @@ -262,6 +262,38 @@ void cChunkMap::BroadcastToChunkOfBlock(int a_X, int a_Y, int a_Z, const cPacket +void cChunkMap::BroadcastPlayerAnimation(const cPlayer & a_Player, char a_Animation, const cClientHandle * a_Exclude) +{ + cCSLock Lock(m_CSLayers); + cChunkPtr Chunk = GetChunkNoGen(a_Player.GetChunkX(), a_Player.GetChunkY(), a_Player.GetChunkZ()); + if (Chunk == NULL) + { + return; + } + // It's perfectly legal to broadcast packets even to invalid chunks! + Chunk->BroadcastPlayerAnimation(a_Player, a_Animation, a_Exclude); +} + + + + + +void cChunkMap::BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude) +{ + cCSLock Lock(m_CSLayers); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkY(), a_Entity.GetChunkZ()); + if (Chunk == NULL) + { + return; + } + // It's perfectly legal to broadcast packets even to invalid chunks! + Chunk->BroadcastEntityEquipment(a_Entity, a_SlotNum, a_Item, a_Exclude); +} + + + + + void cChunkMap::UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) { // a_Player rclked block entity at the coords specified, handle it diff --git a/source/cChunkMap.h b/source/cChunkMap.h index 5baa32485..3cf0720d1 100644 --- a/source/cChunkMap.h +++ b/source/cChunkMap.h @@ -47,6 +47,12 @@ public: /// Broadcasts a_Packet to all clients in the chunk where block [x, y, z] is, except to client a_Exclude void BroadcastToChunkOfBlock(int a_X, int a_Y, int a_Z, const cPacket * a_Packet, cClientHandle * a_Exclude = NULL); + /// Broadcasts an a_Player's animation to all clients in the chunk where a_Player is + void BroadcastPlayerAnimation(const cPlayer & a_Player, char a_Animation, const cClientHandle * a_Exclude = NULL); + + /// Broadcasts an entity equipment change to all clients in the chunk where a_Entity is + void BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude = NULL); + /// a_Player rclked block entity at the coords specified, handle it void UseBlockEntity(cPlayer * a_Player, int a_X, int a_Y, int a_Z); diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index ad2fa7857..62c1a6ea5 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -45,7 +45,6 @@ #include "packets/cPacket_RelativeEntityMoveLook.h" #include "packets/cPacket_Chat.h" #include "packets/cPacket_Login.h" -#include "packets/cPacket_WindowClick.h" #include "packets/cPacket_TimeUpdate.h" #include "packets/cPacket_BlockDig.h" #include "packets/cPacket_Handshake.h" @@ -59,7 +58,10 @@ #include "packets/cPacket_CreativeInventoryAction.h" #include "packets/cPacket_NewInvalidState.h" #include "packets/cPacket_UseEntity.h" +#include "packets/cPacket_WindowClick.h" #include "packets/cPacket_WindowClose.h" +#include "packets/cPacket_WindowOpen.h" +#include "packets/cPacket_WholeInventory.h" #include "packets/cPacket_13.h" #include "packets/cPacket_UpdateSign.h" #include "packets/cPacket_Ping.h" @@ -640,11 +642,36 @@ void cClientHandle::HandlePacket(cPacket * a_Packet) HandleChat(ch->m_Message); break; } - case E_PLAYERLOOK: HandlePlayerLook (reinterpret_cast (a_Packet)); break; - case E_PLAYERMOVELOOK: HandlePlayerMoveLook (reinterpret_cast (a_Packet)); break; - case E_ANIMATION: HandleAnimation (reinterpret_cast (a_Packet)); break; - case E_ITEM_SWITCH: HandleItemSwitch (reinterpret_cast (a_Packet)); break; - case E_WINDOW_CLOSE: HandleWindowClose (reinterpret_cast (a_Packet)); break; + case E_PLAYERLOOK: + { + cPacket_PlayerLook * pl = reinterpret_cast(a_Packet); + HandlePlayerLook(pl->m_Rotation, pl->m_Pitch, pl->m_IsOnGround); + break; + } + case E_PLAYERMOVELOOK: + { + cPacket_PlayerMoveLook * pml = reinterpret_cast(a_Packet); + HandlePlayerMoveLook(pml->m_PosX, pml->m_PosY, pml->m_PosZ, pml->m_Stance, pml->m_Rotation, pml->m_Pitch, pml->m_IsOnGround); + break; + } + case E_ANIMATION: + { + cPacket_ArmAnim * aa = reinterpret_cast(a_Packet); + HandleAnimation(aa->m_Animation); + break; + } + case E_SLOT_SELECTED: + { + cPacket_ItemSwitch * isw = reinterpret_cast(a_Packet); + HandleSlotSelected(isw->m_SlotNum); + break; + } + case E_WINDOW_CLOSE: + { + cPacket_WindowClose * wc = reinterpret_cast(a_Packet); + HandleWindowClose(wc->m_WindowID); + break; + } case E_WINDOW_CLICK: { cPacket_WindowClick * wc = reinterpret_cast(a_Packet); @@ -910,7 +937,7 @@ void cClientHandle::HandleBlockPlace(int a_BlockX, int a_BlockY, int a_BlockZ, c cItem & Equipped = m_Player->GetInventory().GetEquippedItem(); - if ((Equipped.m_ItemID != a_HeldItem.m_ItemType)) // Not valid + if ((Equipped.m_ItemType != a_HeldItem.m_ItemType)) // Not valid { LOGWARN("Player %s tried to place a block that was not equipped (exp %d, got %d)", m_Username.c_str(), Equipped.m_ItemType, a_HeldItem.m_ItemType @@ -1045,11 +1072,11 @@ void cClientHandle::HandleChat(const AString & a_Message) -void cClientHandle::HandlePlayerLook(cPacket_PlayerLook * a_Packet) +void cClientHandle::HandlePlayerLook(float a_Rotation, float a_Pitch, bool a_IsOnGround) { - m_Player->SetRotation (a_Packet->m_Rotation); - m_Player->SetPitch (a_Packet->m_Pitch); - m_Player->SetTouchGround(a_Packet->m_bFlying); + m_Player->SetRotation (a_Rotation); + m_Player->SetPitch (a_Pitch); + m_Player->SetTouchGround(a_IsOnGround); m_Player->WrapRotation(); } @@ -1057,13 +1084,13 @@ void cClientHandle::HandlePlayerLook(cPacket_PlayerLook * a_Packet) -void cClientHandle::HandlePlayerMoveLook(cPacket_PlayerMoveLook * a_Packet) +void cClientHandle::HandlePlayerMoveLook(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, float a_Rotation, float a_Pitch, bool a_IsOnGround) { - m_Player->MoveTo(Vector3d(a_Packet->m_PosX, a_Packet->m_PosY, a_Packet->m_PosZ)); - m_Player->SetStance (a_Packet->m_Stance); - m_Player->SetTouchGround(a_Packet->m_bFlying); - m_Player->SetRotation (a_Packet->m_Rotation); - m_Player->SetPitch (a_Packet->m_Pitch); + m_Player->MoveTo(Vector3d(a_PosX, a_PosY, a_PosZ)); + m_Player->SetStance (a_Stance); + m_Player->SetTouchGround(a_IsOnGround); + m_Player->SetRotation (a_Rotation); + m_Player->SetPitch (a_Pitch); m_Player->WrapRotation(); } @@ -1071,41 +1098,35 @@ void cClientHandle::HandlePlayerMoveLook(cPacket_PlayerMoveLook * a_Packet) -void cClientHandle::HandleAnimation(cPacket_ArmAnim * a_Packet) +void cClientHandle::HandleAnimation(char a_Animation) { - a_Packet->m_EntityID = m_Player->GetUniqueID(); - cRoot::Get()->GetServer()->Broadcast(*a_Packet, this); + m_Player->GetWorld()->BroadcastPlayerAnimation(*m_Player, a_Animation, this); } -void cClientHandle::HandleItemSwitch(cPacket_ItemSwitch * a_Packet) +void cClientHandle::HandleSlotSelected(short a_SlotNum) { - m_Player->GetInventory().SetEquippedSlot(a_Packet->m_SlotNum); - - cPacket_EntityEquipment Equipment; - Equipment.m_ItemID = (short)m_Player->GetInventory().GetEquippedItem().m_ItemID; - Equipment.m_Slot = 0; - Equipment.m_UniqueID = m_Player->GetUniqueID(); - cRoot::Get()->GetServer()->Broadcast(Equipment, this); + m_Player->GetInventory().SetEquippedSlot(a_SlotNum); + m_Player->GetWorld()->BroadcastEntityEquipment(*m_Player, 0, m_Player->GetInventory().GetEquippedItem(), this); } -void cClientHandle::HandleWindowClose(cPacket_WindowClose * a_Packet) +void cClientHandle::HandleWindowClose(char a_WindowID) { - m_Player->CloseWindow(a_Packet->m_Close); + m_Player->CloseWindow(a_WindowID); } -void cClientHandle::HandleWindowClick(int a_WindowID, short a_SlotNum, bool a_IsRightClick, bool a_IsShiftPressed, const cItem & a_HeldItem) +void cClientHandle::HandleWindowClick(char a_WindowID, short a_SlotNum, bool a_IsRightClick, bool a_IsShiftPressed, const cItem & a_HeldItem) { if (a_WindowID == 0) { @@ -1451,6 +1472,77 @@ void cClientHandle::SendChat(const AString & a_Message) +void cClientHandle::SendPlayerAnimation(const cPlayer & a_Player, char a_Animation) +{ + cPacket_ArmAnim Anim; + Anim.m_EntityID = a_Player.GetUniqueID(); + Anim.m_Animation = a_Animation; + Send(Anim); +} + + + + + +void cClientHandle::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) +{ + cPacket_EntityEquipment ee; + ee.m_UniqueID = a_Entity.GetUniqueID(); + ee.m_SlotNum = a_SlotNum; + ee.m_ItemType = a_Item.m_ItemType; + ee.m_ItemDamage = a_Item.m_ItemDamage; + Send(ee); +} + + + + + +void cClientHandle::SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) +{ + cPacket_WindowOpen WindowOpen; + WindowOpen.m_WindowID = a_WindowID; + WindowOpen.m_InventoryType = a_WindowType; + WindowOpen.m_WindowTitle = a_WindowTitle; + WindowOpen.m_NumSlots = a_NumSlots; + Send(WindowOpen); +} + + + + + +void cClientHandle::SendWindowClose(char a_WindowID) +{ + cPacket_WindowClose wc; + wc.m_WindowID = a_WindowID; + Send(wc); +} + + + + + +void cClientHandle::SendWholeInventory(const cInventory & a_Inventory) +{ + cPacket_WholeInventory wi(a_Inventory); + Send(wi); +} + + + + + +void cClientHandle::SendWholeInventory(const cWindow & a_Window) +{ + cPacket_WholeInventory wi(a_Window); + Send(wi); +} + + + + + void cClientHandle::CheckIfWorldDownloaded(void) { if (m_State != csDownloadingWorld) diff --git a/source/cClientHandle.h b/source/cClientHandle.h index cf47dd720..f2f7e7595 100644 --- a/source/cClientHandle.h +++ b/source/cClientHandle.h @@ -54,6 +54,8 @@ class cPlayer; class cRedstone; +class cInventory; +class cWindow; @@ -106,6 +108,12 @@ public: void SendHandshake (const AString & a_ServerName); void SendInventorySlot(int a_WindowID, short a_SlotNum, const cItem & a_Item); void SendChat(const AString & a_Message); + void SendPlayerAnimation(const cPlayer & a_Player, char a_Animation); + void SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item); + void SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots); + void SendWindowClose(char a_WindowID); + void SendWholeInventory(const cInventory & a_Inventory); + void SendWholeInventory(const cWindow & a_Window); const AString & GetUsername(void) const; //tolua_export @@ -198,12 +206,12 @@ private: void HandleBlockDig (int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status); void HandleBlockPlace (int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, const cItem & a_HeldItem); void HandleChat (const AString & a_Message); - void HandlePlayerLook (cPacket_PlayerLook * a_Packet); - void HandlePlayerMoveLook (cPacket_PlayerMoveLook * a_Packet); // While m_bPositionConfirmed (normal gameplay) - void HandleAnimation (cPacket_ArmAnim * a_Packet); - void HandleItemSwitch (cPacket_ItemSwitch * a_Packet); - void HandleWindowClose (cPacket_WindowClose * a_Packet); - void HandleWindowClick (int a_WindowID, short a_SlotNum, bool a_IsRightClick, bool a_IsShiftPressed, const cItem & a_HeldItem); + void HandlePlayerLook (float a_Rotation, float a_Pitch, bool a_IsOnGround); + void HandlePlayerMoveLook (double a_PosX, double a_PosY, double a_PosZ, double a_Stance, float a_Rotation, float a_Pitch, bool a_IsOnGround); // While m_bPositionConfirmed (normal gameplay) + void HandleAnimation (char a_Animation); + void HandleSlotSelected (short a_SlotNum); + void HandleWindowClose (char a_WindowID); + void HandleWindowClick (char a_WindowID, short a_SlotNum, bool a_IsRightClick, bool a_IsShiftPressed, const cItem & a_HeldItem); void HandleUpdateSign (cPacket_UpdateSign * a_Packet); void HandleUseEntity (cPacket_UseEntity * a_Packet); void HandleRespawn (void); diff --git a/source/cInventory.cpp b/source/cInventory.cpp index d532ec7c9..7122a697c 100644 --- a/source/cInventory.cpp +++ b/source/cInventory.cpp @@ -256,8 +256,7 @@ cItem & cInventory::GetEquippedItem() void cInventory::SendWholeInventory(cClientHandle * a_Client) { - cPacket_WholeInventory Inventory(this); - a_Client->Send(Inventory); + a_Client->SendWholeInventory(*this); } @@ -314,7 +313,7 @@ void cInventory::SendSlot( int a_SlotNum ) -int cInventory::HowManyCanFit(ENUM_ITEM_ID a_ItemType, short a_ItemDamage, int a_BeginSlot, int a_EndSlot) +int cInventory::HowManyCanFit(short a_ItemType, short a_ItemDamage, int a_BeginSlot, int a_EndSlot) { int res = 0; for (int i = a_BeginSlot; i <= a_EndSlot; i++) @@ -336,7 +335,7 @@ int cInventory::HowManyCanFit(ENUM_ITEM_ID a_ItemType, short a_ItemDamage, int a -int cInventory::MoveItem(ENUM_ITEM_ID a_ItemType, short a_ItemDamage, int a_Count, int a_BeginSlot, int a_EndSlot) +int cInventory::MoveItem(short a_ItemType, short a_ItemDamage, int a_Count, int a_BeginSlot, int a_EndSlot) { int res = 0; for (int i = a_BeginSlot; i <= a_EndSlot; i++) diff --git a/source/cInventory.h b/source/cInventory.h index 8bf517769..7513df969 100644 --- a/source/cInventory.h +++ b/source/cInventory.h @@ -44,7 +44,7 @@ public: void SendWholeInventoryToAll(void); cItem* GetSlot( int a_SlotNum ); //tolua_export - cItem* GetSlots() { return m_Slots; } + cItem* GetSlots() const { return m_Slots; } cItem* GetFromHotBar( int a_SlotNum ); //tolua_export cItem & GetEquippedItem(); //tolua_export @@ -56,10 +56,10 @@ public: void SendSlot( int a_SlotNum ); //tolua_export /// Returns how many items of the specified type would fit into the slot range specified - int HowManyCanFit(ENUM_ITEM_ID a_ItemType, short a_ItemDamage, int a_BeginSlot, int a_EndSlot); + int HowManyCanFit(short a_ItemType, short a_ItemDamage, int a_BeginSlot, int a_EndSlot); /// Moves items, fitting them into the slot range specified, up to a_Count items. Returns the number of items moved - int MoveItem(ENUM_ITEM_ID a_ItemType, short a_ItemDamage, int a_Count, int a_BeginSlot, int a_EndSlot); + int MoveItem(short a_ItemType, short a_ItemDamage, int a_Count, int a_BeginSlot, int a_EndSlot); static const unsigned int c_NumSlots = 45; static const unsigned int c_MainSlots = 27; diff --git a/source/cItem.h b/source/cItem.h index 53764d06a..aa4b76bbc 100644 --- a/source/cItem.h +++ b/source/cItem.h @@ -16,25 +16,28 @@ namespace Json class cItem { public: - cItem( ENUM_ITEM_ID a_ItemID = E_ITEM_EMPTY, char a_ItemCount = 0, short a_ItemHealth = 0 ) - : m_ItemID ( a_ItemID ) - , m_ItemCount ( a_ItemCount ) - , m_ItemHealth ( a_ItemHealth ) + cItem(short a_ItemType = E_ITEM_EMPTY, char a_ItemCount = 0, short a_ItemHealth = 0) + : m_ItemType (a_ItemType) + , m_ItemCount (a_ItemCount) + , m_ItemHealth(a_ItemHealth) { - if(!IsValidItem( m_ItemID ) ) m_ItemID = E_ITEM_EMPTY; + if (!IsValidItem( m_ItemID ) ) m_ItemID = E_ITEM_EMPTY; } + void Empty() { m_ItemID = E_ITEM_EMPTY; m_ItemCount = 0; m_ItemHealth = 0; } + void Clear(void) { m_ItemID = E_ITEM_EMPTY; m_ItemCount = 0; m_ItemHealth = 0; } + bool IsEmpty(void) const { return (m_ItemID <= 0 || m_ItemCount <= 0); @@ -120,8 +123,8 @@ public: union { // tolua_begin - ENUM_ITEM_ID m_ItemID; // OBSOLETE, use m_ItemType instead - short m_ItemType; + short m_ItemID; // OBSOLETE, use m_ItemType instead + short m_ItemType; // tolua_end } ; char m_ItemCount; // tolua_export diff --git a/source/cWindow.cpp b/source/cWindow.cpp index f3b4bc883..2c4534742 100644 --- a/source/cWindow.cpp +++ b/source/cWindow.cpp @@ -10,10 +10,6 @@ #include "cWindowOwner.h" #include "items/Item.h" -#include "packets/cPacket_WholeInventory.h" -#include "packets/cPacket_WindowOpen.h" -#include "packets/cPacket_WindowClose.h" - @@ -239,12 +235,7 @@ void cWindow::Open( cPlayer & a_Player ) m_OpenedBy.push_back( &a_Player ); } - cPacket_WindowOpen WindowOpen; - WindowOpen.m_WindowID = (char)m_WindowID; - WindowOpen.m_InventoryType = (char)m_WindowType; - WindowOpen.m_WindowTitle = m_WindowTitle; - WindowOpen.m_NumSlots = (char)m_NumSlots; - a_Player.GetClientHandle()->Send( WindowOpen ); + a_Player.GetClientHandle()->SendWindowOpen(m_WindowID, m_WindowType, m_WindowTitle, m_NumSlots); } @@ -260,12 +251,10 @@ void cWindow::Close( cPlayer & a_Player ) a_Player.TossItem(true, m_DraggingItem->m_ItemCount); } - cPacket_WindowClose WindowClose; - WindowClose.m_Close = (char)m_WindowID; cClientHandle * ClientHandle = a_Player.GetClientHandle(); if (ClientHandle != NULL) { - ClientHandle->Send(WindowClose); + ClientHandle->SendWindowClose(m_WindowID); } { @@ -349,10 +338,9 @@ void cWindow::Destroy() -void cWindow::SendWholeWindow( cClientHandle* a_Client ) +void cWindow::SendWholeWindow(cClientHandle * a_Client ) { - cPacket_WholeInventory Inventory( this ); - a_Client->Send( Inventory ); + a_Client->SendWholeInventory(*this); } diff --git a/source/cWindow.h b/source/cWindow.h index cbb90b893..37ac5239d 100644 --- a/source/cWindow.h +++ b/source/cWindow.h @@ -46,11 +46,11 @@ public: cWindow(cWindowOwner * a_Owner, bool a_bInventoryVisible, WindowType a_WindowType, int a_WindowID); ~cWindow(); - int GetWindowID() { return m_WindowID; } + int GetWindowID(void) const { return m_WindowID; } int GetWindowType(void) const { return m_WindowType; } - cItem* GetSlots() { return m_Slots; } - int GetNumSlots() { return m_NumSlots; } + cItem* GetSlots(void) const { return m_Slots; } + int GetNumSlots(void) const { return m_NumSlots; } cItem* GetSlot( int a_Slot ); diff --git a/source/cWorld.cpp b/source/cWorld.cpp index 3c1da9945..6b2bb971d 100644 --- a/source/cWorld.cpp +++ b/source/cWorld.cpp @@ -1282,6 +1282,24 @@ void cWorld::BroadcastChat(const AString & a_Message, const cClientHandle * a_Ex +void cWorld::BroadcastPlayerAnimation(const cPlayer & a_Player, char a_Animation, const cClientHandle * a_Exclude) +{ + m_ChunkMap->BroadcastPlayerAnimation(a_Player, a_Animation, a_Exclude); +} + + + + + +void cWorld::BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude) +{ + m_ChunkMap->BroadcastEntityEquipment(a_Entity, a_SlotNum, a_Item, a_Exclude); +} + + + + + void cWorld::MarkChunkDirty (int a_ChunkX, int a_ChunkY, int a_ChunkZ) { m_ChunkMap->MarkChunkDirty (a_ChunkX, a_ChunkY, a_ChunkZ); diff --git a/source/cWorld.h b/source/cWorld.h index 9e865183c..5bf3a1390 100644 --- a/source/cWorld.h +++ b/source/cWorld.h @@ -79,6 +79,8 @@ public: void BroadcastToChunkOfBlock(int a_X, int a_Y, int a_Z, cPacket * a_Packet, cClientHandle * a_Exclude = NULL); void BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude = NULL); + void BroadcastPlayerAnimation(const cPlayer & a_Player, char a_Animation, const cClientHandle * a_Exclude = NULL); + void BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude = NULL); void MarkChunkDirty (int a_ChunkX, int a_ChunkY, int a_ChunkZ); void MarkChunkSaving(int a_ChunkX, int a_ChunkY, int a_ChunkZ); diff --git a/source/packets/cPacket_EntityEquipment.cpp b/source/packets/cPacket_EntityEquipment.cpp index c66b1b6b4..6358c4a1f 100644 --- a/source/packets/cPacket_EntityEquipment.cpp +++ b/source/packets/cPacket_EntityEquipment.cpp @@ -9,11 +9,11 @@ cPacket_EntityEquipment::cPacket_EntityEquipment( const cPacket_EntityEquipment & a_Copy ) { - m_PacketID = E_ENTITY_EQUIPMENT; - m_UniqueID = a_Copy.m_UniqueID; - m_Slot = a_Copy.m_Slot; - m_ItemID = a_Copy.m_ItemID; - m_Short = 0; + m_PacketID = E_ENTITY_EQUIPMENT; + m_UniqueID = a_Copy.m_UniqueID; + m_SlotNum = a_Copy.m_SlotNum; + m_ItemType = a_Copy.m_ItemType; + m_ItemDamage = a_Copy.m_ItemDamage; } @@ -23,10 +23,10 @@ cPacket_EntityEquipment::cPacket_EntityEquipment( const cPacket_EntityEquipment int cPacket_EntityEquipment::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadBEInt, m_UniqueID, TotalBytes); - HANDLE_PACKET_READ(ReadBEShort, m_Slot, TotalBytes); - HANDLE_PACKET_READ(ReadBEShort, m_ItemID, TotalBytes); - HANDLE_PACKET_READ(ReadBEShort, m_Short, TotalBytes); + HANDLE_PACKET_READ(ReadBEInt, m_UniqueID, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_SlotNum, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_ItemType, TotalBytes); + HANDLE_PACKET_READ(ReadBEShort, m_ItemDamage, TotalBytes); return TotalBytes; } @@ -38,9 +38,9 @@ void cPacket_EntityEquipment::Serialize(AString & a_Data) const { AppendByte (a_Data, m_PacketID); AppendInteger(a_Data, m_UniqueID); - AppendShort (a_Data, m_Slot); - AppendShort (a_Data, m_ItemID); - AppendShort (a_Data, m_Short); + AppendShort (a_Data, m_SlotNum); + AppendShort (a_Data, m_ItemType); + AppendShort (a_Data, m_ItemDamage); } diff --git a/source/packets/cPacket_EntityEquipment.h b/source/packets/cPacket_EntityEquipment.h index 3c6197f32..69260fae4 100644 --- a/source/packets/cPacket_EntityEquipment.h +++ b/source/packets/cPacket_EntityEquipment.h @@ -11,22 +11,23 @@ class cPacket_EntityEquipment : public cPacket public: cPacket_EntityEquipment() : m_UniqueID( 0 ) - , m_Slot( 0 ) - , m_ItemID( 0 ) - , m_Short( 0 ) - { m_PacketID = E_ENTITY_EQUIPMENT; m_Short = 0; } + , m_SlotNum( 0 ) + , m_ItemType( 0 ) + , m_ItemDamage( 0 ) + { + m_PacketID = E_ENTITY_EQUIPMENT; + } + cPacket_EntityEquipment( const cPacket_EntityEquipment & a_Copy ); - virtual cPacket* Clone() const { return new cPacket_EntityEquipment(*this); } + virtual cPacket * Clone() const { return new cPacket_EntityEquipment(*this); } - virtual int Parse(cByteBuffer & a_Buffer) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; int m_UniqueID; - short m_Slot; // 0 = hold 1-4 = armor - short m_ItemID; - short m_Short; - - static const unsigned int c_Size = 1 + 4 + 2 + 2 + 2; + short m_SlotNum; // 0 = hold 1-4 = armor + short m_ItemType; + short m_ItemDamage; }; diff --git a/source/packets/cPacket_Player.cpp b/source/packets/cPacket_Player.cpp index 3a897a1ea..c24905e15 100644 --- a/source/packets/cPacket_Player.cpp +++ b/source/packets/cPacket_Player.cpp @@ -106,10 +106,10 @@ void cPacket_PlayerListItem::Serialize(AString & a_Data) const cPacket_PlayerLook::cPacket_PlayerLook( cPlayer* a_Player ) { - m_PacketID = E_PLAYERLOOK; - m_Rotation = a_Player->GetRotation(); - m_Pitch = a_Player->GetPitch(); - m_bFlying = a_Player->GetFlying(); + m_PacketID = E_PLAYERLOOK; + m_Rotation = a_Player->GetRotation(); + m_Pitch = a_Player->GetPitch(); + m_IsOnGround = a_Player->IsOnGround(); } @@ -119,9 +119,9 @@ cPacket_PlayerLook::cPacket_PlayerLook( cPlayer* a_Player ) int cPacket_PlayerLook::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadBEFloat, m_Rotation, TotalBytes); - HANDLE_PACKET_READ(ReadBEFloat, m_Pitch, TotalBytes); - HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes); + HANDLE_PACKET_READ(ReadBEFloat, m_Rotation, TotalBytes); + HANDLE_PACKET_READ(ReadBEFloat, m_Pitch, TotalBytes); + HANDLE_PACKET_READ(ReadBool, m_IsOnGround, TotalBytes); return TotalBytes; } @@ -134,7 +134,7 @@ void cPacket_PlayerLook::Serialize(AString & a_Data) const AppendByte (a_Data, m_PacketID); AppendFloat (a_Data, m_Rotation); AppendFloat (a_Data, m_Pitch); - AppendBool (a_Data, m_bFlying); + AppendBool (a_Data, m_IsOnGround); } @@ -145,14 +145,14 @@ void cPacket_PlayerLook::Serialize(AString & a_Data) const cPacket_PlayerMoveLook::cPacket_PlayerMoveLook( cPlayer* a_Player ) { - m_PacketID = E_PLAYERMOVELOOK; - m_PosX = a_Player->GetPosX(); - m_PosY = a_Player->GetPosY() + 1.65; - m_PosZ = a_Player->GetPosZ(); - m_Stance = a_Player->GetStance(); - m_Rotation = a_Player->GetRotation(); - m_Pitch = a_Player->GetPitch(); - m_bFlying = a_Player->GetFlying(); + m_PacketID = E_PLAYERMOVELOOK; + m_PosX = a_Player->GetPosX(); + m_PosY = a_Player->GetPosY() + 1.65; + m_PosZ = a_Player->GetPosZ(); + m_Stance = a_Player->GetStance(); + m_Rotation = a_Player->GetRotation(); + m_Pitch = a_Player->GetPitch(); + m_IsOnGround = a_Player->IsOnGround(); } @@ -162,13 +162,13 @@ cPacket_PlayerMoveLook::cPacket_PlayerMoveLook( cPlayer* a_Player ) int cPacket_PlayerMoveLook::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadBEDouble, m_PosX, TotalBytes); - HANDLE_PACKET_READ(ReadBEDouble, m_PosY, TotalBytes); - HANDLE_PACKET_READ(ReadBEDouble, m_Stance, TotalBytes); - HANDLE_PACKET_READ(ReadBEDouble, m_PosZ, TotalBytes); - HANDLE_PACKET_READ(ReadBEFloat, m_Rotation, TotalBytes); - HANDLE_PACKET_READ(ReadBEFloat, m_Pitch, TotalBytes); - HANDLE_PACKET_READ(ReadBool, m_bFlying, TotalBytes); + HANDLE_PACKET_READ(ReadBEDouble, m_PosX, TotalBytes); + HANDLE_PACKET_READ(ReadBEDouble, m_PosY, TotalBytes); + HANDLE_PACKET_READ(ReadBEDouble, m_Stance, TotalBytes); + HANDLE_PACKET_READ(ReadBEDouble, m_PosZ, TotalBytes); + HANDLE_PACKET_READ(ReadBEFloat, m_Rotation, TotalBytes); + HANDLE_PACKET_READ(ReadBEFloat, m_Pitch, TotalBytes); + HANDLE_PACKET_READ(ReadBool, m_IsOnGround, TotalBytes); return TotalBytes; } @@ -185,7 +185,7 @@ void cPacket_PlayerMoveLook::Serialize(AString & a_Data) const AppendDouble(a_Data, m_PosZ); AppendFloat (a_Data, m_Rotation); AppendFloat (a_Data, m_Pitch); - AppendBool (a_Data, m_bFlying); + AppendBool (a_Data, m_IsOnGround); } diff --git a/source/packets/cPacket_Player.h b/source/packets/cPacket_Player.h index 05b75d9d1..d9f7c0057 100644 --- a/source/packets/cPacket_Player.h +++ b/source/packets/cPacket_Player.h @@ -74,8 +74,11 @@ public: cPacket_PlayerLook() : m_Rotation( 0 ) , m_Pitch( 0 ) - , m_bFlying( false ) - { m_PacketID = E_PLAYERLOOK; } + , m_IsOnGround( false ) + { + m_PacketID = E_PLAYERLOOK; + } + cPacket_PlayerLook( cPlayer* a_Player ); virtual cPacket* Clone() const { return new cPacket_PlayerLook(*this); } @@ -84,7 +87,7 @@ public: float m_Rotation; float m_Pitch; - bool m_bFlying; // Yeah.. wtf + bool m_IsOnGround; } ; @@ -101,12 +104,15 @@ public: , m_PosZ( 0.0 ) , m_Rotation( 0.f ) , m_Pitch( 0.f ) - , m_bFlying( false ) - { m_PacketID = E_PLAYERMOVELOOK; } + , m_IsOnGround( false ) + { + m_PacketID = E_PLAYERMOVELOOK; + } + cPacket_PlayerMoveLook( cPlayer* a_Player ); virtual cPacket* Clone() const { return new cPacket_PlayerMoveLook(*this); } - virtual int Parse(cByteBuffer & a_Buffer) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; double m_PosX; @@ -115,7 +121,7 @@ public: double m_PosZ; float m_Rotation; float m_Pitch; - bool m_bFlying; // Yeah.. wtf + bool m_IsOnGround; } ; diff --git a/source/packets/cPacket_WholeInventory.cpp b/source/packets/cPacket_WholeInventory.cpp index fd6a6b457..69ea33580 100644 --- a/source/packets/cPacket_WholeInventory.cpp +++ b/source/packets/cPacket_WholeInventory.cpp @@ -25,28 +25,28 @@ cPacket_WholeInventory::cPacket_WholeInventory( const cPacket_WholeInventory & a -cPacket_WholeInventory::cPacket_WholeInventory(cInventory * a_Inventory) +cPacket_WholeInventory::cPacket_WholeInventory(const cInventory & a_Inventory) { m_PacketID = E_INVENTORY_WHOLE; - m_WindowID = 0; - m_Count = a_Inventory->c_NumSlots; - m_Items = new cItem[m_Count]; + m_WindowID = 0; // Inventory window has a constant ID of 0 + m_Count = a_Inventory.c_NumSlots; + m_Items = new cItem[m_Count]; // TODO: copy items one by one, they may have some values that needn't be shallow-copiable - memcpy( m_Items, a_Inventory->GetSlots(), sizeof(cItem)*m_Count ); + memcpy( m_Items, a_Inventory.GetSlots(), sizeof(cItem) * m_Count); } -cPacket_WholeInventory::cPacket_WholeInventory(cWindow * a_Window) +cPacket_WholeInventory::cPacket_WholeInventory(const cWindow & a_Window) { m_PacketID = E_INVENTORY_WHOLE; - m_WindowID = (char)a_Window->GetWindowID(); - m_Count = (short)a_Window->GetNumSlots(); - m_Items = new cItem[m_Count]; + m_WindowID = (char)a_Window.GetWindowID(); + m_Count = (short)a_Window.GetNumSlots(); + m_Items = new cItem[m_Count]; // TODO: copy items one by one, they may have some values that needn't be shallow-copiable - memcpy( m_Items, a_Window->GetSlots(), sizeof(cItem) * m_Count); + memcpy( m_Items, a_Window.GetSlots(), sizeof(cItem) * m_Count); } diff --git a/source/packets/cPacket_WholeInventory.h b/source/packets/cPacket_WholeInventory.h index 3a9cc0a1b..6582fe6fe 100644 --- a/source/packets/cPacket_WholeInventory.h +++ b/source/packets/cPacket_WholeInventory.h @@ -17,29 +17,29 @@ class cItem; -class cPacket_WholeInventory : public cPacket // full inventory [S -> C] ? +class cPacket_WholeInventory : + public cPacket // full inventory [S -> C] ? { public: - cPacket_WholeInventory( const cPacket_WholeInventory & a_Clone ); - cPacket_WholeInventory( cInventory* a_Inventory ); - cPacket_WholeInventory( cWindow* a_Window ); + cPacket_WholeInventory(const cPacket_WholeInventory & a_Clone); + cPacket_WholeInventory(const cInventory & a_Inventory); + cPacket_WholeInventory(const cWindow & a_Window); ~cPacket_WholeInventory(); cPacket_WholeInventory() : m_WindowID( 0 ) , m_Count( 0 ) , m_Items( 0 ) - { m_PacketID = E_INVENTORY_WHOLE; } + { + m_PacketID = E_INVENTORY_WHOLE; + } - - virtual cPacket* Clone() const { return new cPacket_WholeInventory(*this); } + virtual cPacket * Clone() const { return new cPacket_WholeInventory(*this); } virtual void Serialize(AString & a_Data) const override; - char m_WindowID; // WTF? - short m_Count; // Number of items - cItem * m_Items; // Array of m_Count items - - static const unsigned int c_Size = 1 + 1 + 2; // Minimal size + char m_WindowID; + short m_Count; + cItem * m_Items; }; diff --git a/source/packets/cPacket_WindowClose.cpp b/source/packets/cPacket_WindowClose.cpp index c15e90d3d..9991ab500 100644 --- a/source/packets/cPacket_WindowClose.cpp +++ b/source/packets/cPacket_WindowClose.cpp @@ -10,7 +10,7 @@ int cPacket_WindowClose::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; - HANDLE_PACKET_READ(ReadChar, m_Close, TotalBytes); + HANDLE_PACKET_READ(ReadChar, m_WindowID, TotalBytes); return TotalBytes; } @@ -21,7 +21,7 @@ int cPacket_WindowClose::Parse(cByteBuffer & a_Buffer) void cPacket_WindowClose::Serialize(AString & a_Data) const { AppendByte(a_Data, m_PacketID); - AppendByte(a_Data, m_Close); + AppendByte(a_Data, m_WindowID); } diff --git a/source/packets/cPacket_WindowClose.h b/source/packets/cPacket_WindowClose.h index 3bf7b8240..de40ab446 100644 --- a/source/packets/cPacket_WindowClose.h +++ b/source/packets/cPacket_WindowClose.h @@ -11,16 +11,17 @@ class cPacket_WindowClose : public cPacket { public: cPacket_WindowClose() - : m_Close( 0 ) - { m_PacketID = E_WINDOW_CLOSE; } + : m_WindowID( 0 ) + { + m_PacketID = E_WINDOW_CLOSE; + } + virtual cPacket* Clone() const { return new cPacket_WindowClose(*this); } - virtual int Parse(cByteBuffer & a_Buffer) override; + virtual int Parse(cByteBuffer & a_Buffer) override; virtual void Serialize(AString & a_Data) const override; - char m_Close; // m_Close == cWindow WindowType number - - static const unsigned int c_Size = 1 + 1; + char m_WindowID; }; -- cgit v1.2.3