From 1651fcd9807f1033a5fc76e60cb17922e687a7b1 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Tue, 28 Aug 2012 21:59:49 +0000 Subject: Moved all packet-serializing code into cProtocol125; half the packet classes aren't needed anymore. git-svn-id: http://mc-server.googlecode.com/svn/trunk@800 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Protocol.h | 132 +++- source/Protocol125.cpp | 737 ++++++++++++--------- source/Protocol125.h | 57 +- source/StringUtils.cpp | 159 +++++ source/StringUtils.h | 3 + source/cChatColor.cpp | 2 +- source/cClientHandle.cpp | 74 +-- source/cClientHandle.h | 3 - source/cEntity.cpp | 2 + source/cEntity.h | 10 + source/cPawn.cpp | 2 - source/cPawn.h | 4 - source/cPlayer.cpp | 8 +- source/cPlayer.h | 2 +- source/packets/cPacket.h | 9 - source/packets/cPacket_AddToInventory.cpp | 20 - source/packets/cPacket_AddToInventory.h | 26 - source/packets/cPacket_ArmAnim.cpp | 11 - source/packets/cPacket_ArmAnim.h | 19 +- source/packets/cPacket_BlockAction.cpp | 36 - source/packets/cPacket_BlockAction.h | 38 -- source/packets/cPacket_BlockChange.cpp | 22 - source/packets/cPacket_BlockChange.h | 27 - source/packets/cPacket_BlockDig.cpp | 13 - source/packets/cPacket_BlockDig.h | 1 - source/packets/cPacket_Chat.cpp | 10 - source/packets/cPacket_Chat.h | 10 +- source/packets/cPacket_CollectItem.cpp | 19 - source/packets/cPacket_CollectItem.h | 27 - source/packets/cPacket_CreativeInventoryAction.cpp | 11 - source/packets/cPacket_CreativeInventoryAction.h | 1 - source/packets/cPacket_DestroyEntity.cpp | 30 - source/packets/cPacket_DestroyEntity.h | 33 - source/packets/cPacket_Disconnect.cpp | 9 - source/packets/cPacket_Disconnect.h | 1 - source/packets/cPacket_EntityEquipment.cpp | 48 -- source/packets/cPacket_EntityEquipment.h | 35 - source/packets/cPacket_EntityLook.cpp | 64 -- source/packets/cPacket_EntityLook.h | 62 -- source/packets/cPacket_EntityStatus.cpp | 19 - source/packets/cPacket_EntityStatus.h | 31 - source/packets/cPacket_Explosion.h | 2 +- source/packets/cPacket_Handshake.cpp | 10 - source/packets/cPacket_Handshake.h | 1 - source/packets/cPacket_InventoryProgressBar.cpp | 20 - source/packets/cPacket_InventoryProgressBar.h | 32 - source/packets/cPacket_InventorySlot.cpp | 23 - source/packets/cPacket_InventorySlot.h | 44 -- source/packets/cPacket_ItemSwitch.cpp | 10 - source/packets/cPacket_ItemSwitch.h | 3 - source/packets/cPacket_KeepAlive.cpp | 10 - source/packets/cPacket_KeepAlive.h | 3 +- source/packets/cPacket_Login.cpp | 17 - source/packets/cPacket_Login.h | 1 - source/packets/cPacket_MapChunk.cpp | 34 - source/packets/cPacket_MapChunk.h | 34 - source/packets/cPacket_Metadata.cpp | 110 --- source/packets/cPacket_Metadata.h | 35 - source/packets/cPacket_NamedEntitySpawn.cpp | 34 - source/packets/cPacket_NamedEntitySpawn.h | 40 -- source/packets/cPacket_NewInvalidState.cpp | 42 -- source/packets/cPacket_NewInvalidState.h | 31 - source/packets/cPacket_PickupSpawn.cpp | 47 -- source/packets/cPacket_PickupSpawn.h | 47 -- source/packets/cPacket_Player.cpp | 87 --- source/packets/cPacket_Player.h | 7 +- source/packets/cPacket_PreChunk.cpp | 20 - source/packets/cPacket_PreChunk.h | 36 - source/packets/cPacket_RelativeEntityMove.cpp | 21 - source/packets/cPacket_RelativeEntityMove.h | 33 - source/packets/cPacket_RelativeEntityMoveLook.cpp | 24 - source/packets/cPacket_RelativeEntityMoveLook.h | 37 -- source/packets/cPacket_Respawn.cpp | 15 - source/packets/cPacket_Respawn.h | 4 +- source/packets/cPacket_SpawnMob.cpp | 71 -- source/packets/cPacket_SpawnMob.h | 35 - source/packets/cPacket_TeleportEntity.cpp | 41 -- source/packets/cPacket_TeleportEntity.h | 42 -- source/packets/cPacket_Thunderbolt.cpp | 36 - source/packets/cPacket_Thunderbolt.h | 36 - source/packets/cPacket_TimeUpdate.cpp | 29 - source/packets/cPacket_TimeUpdate.h | 29 - source/packets/cPacket_UpdateHealth.cpp | 20 - source/packets/cPacket_UpdateHealth.h | 32 - source/packets/cPacket_UpdateSign.cpp | 16 - source/packets/cPacket_UpdateSign.h | 1 - source/packets/cPacket_WholeInventory.cpp | 80 --- source/packets/cPacket_WholeInventory.h | 47 -- source/packets/cPacket_WindowClick.cpp | 1 - source/packets/cPacket_WindowClose.cpp | 10 - source/packets/cPacket_WindowClose.h | 3 +- source/packets/cPacket_WindowOpen.cpp | 21 - source/packets/cPacket_WindowOpen.h | 32 - 93 files changed, 812 insertions(+), 2511 deletions(-) delete mode 100644 source/packets/cPacket_AddToInventory.cpp delete mode 100644 source/packets/cPacket_AddToInventory.h delete mode 100644 source/packets/cPacket_BlockAction.cpp delete mode 100644 source/packets/cPacket_BlockAction.h delete mode 100644 source/packets/cPacket_BlockChange.cpp delete mode 100644 source/packets/cPacket_BlockChange.h delete mode 100644 source/packets/cPacket_CollectItem.cpp delete mode 100644 source/packets/cPacket_CollectItem.h delete mode 100644 source/packets/cPacket_DestroyEntity.cpp delete mode 100644 source/packets/cPacket_DestroyEntity.h delete mode 100644 source/packets/cPacket_EntityEquipment.cpp delete mode 100644 source/packets/cPacket_EntityEquipment.h delete mode 100644 source/packets/cPacket_EntityLook.cpp delete mode 100644 source/packets/cPacket_EntityLook.h delete mode 100644 source/packets/cPacket_EntityStatus.cpp delete mode 100644 source/packets/cPacket_EntityStatus.h delete mode 100644 source/packets/cPacket_InventoryProgressBar.cpp delete mode 100644 source/packets/cPacket_InventoryProgressBar.h delete mode 100644 source/packets/cPacket_InventorySlot.cpp delete mode 100644 source/packets/cPacket_InventorySlot.h delete mode 100644 source/packets/cPacket_MapChunk.cpp delete mode 100644 source/packets/cPacket_MapChunk.h delete mode 100644 source/packets/cPacket_Metadata.cpp delete mode 100644 source/packets/cPacket_Metadata.h delete mode 100644 source/packets/cPacket_NamedEntitySpawn.cpp delete mode 100644 source/packets/cPacket_NamedEntitySpawn.h delete mode 100644 source/packets/cPacket_NewInvalidState.cpp delete mode 100644 source/packets/cPacket_NewInvalidState.h delete mode 100644 source/packets/cPacket_PickupSpawn.cpp delete mode 100644 source/packets/cPacket_PickupSpawn.h delete mode 100644 source/packets/cPacket_PreChunk.cpp delete mode 100644 source/packets/cPacket_PreChunk.h delete mode 100644 source/packets/cPacket_RelativeEntityMove.cpp delete mode 100644 source/packets/cPacket_RelativeEntityMove.h delete mode 100644 source/packets/cPacket_RelativeEntityMoveLook.cpp delete mode 100644 source/packets/cPacket_RelativeEntityMoveLook.h delete mode 100644 source/packets/cPacket_SpawnMob.cpp delete mode 100644 source/packets/cPacket_SpawnMob.h delete mode 100644 source/packets/cPacket_TeleportEntity.cpp delete mode 100644 source/packets/cPacket_TeleportEntity.h delete mode 100644 source/packets/cPacket_Thunderbolt.cpp delete mode 100644 source/packets/cPacket_Thunderbolt.h delete mode 100644 source/packets/cPacket_TimeUpdate.cpp delete mode 100644 source/packets/cPacket_TimeUpdate.h delete mode 100644 source/packets/cPacket_UpdateHealth.cpp delete mode 100644 source/packets/cPacket_UpdateHealth.h delete mode 100644 source/packets/cPacket_WholeInventory.cpp delete mode 100644 source/packets/cPacket_WholeInventory.h delete mode 100644 source/packets/cPacket_WindowOpen.cpp delete mode 100644 source/packets/cPacket_WindowOpen.h (limited to 'source') diff --git a/source/Protocol.h b/source/Protocol.h index 4422b45ba..ee0ccddfd 100644 --- a/source/Protocol.h +++ b/source/Protocol.h @@ -11,6 +11,7 @@ #pragma once #include "Defines.h" +#include "Endianness.h" @@ -40,46 +41,46 @@ public: virtual void DataReceived(const char * a_Data, int a_Size) = 0; // Sending stuff to clients: + virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2) = 0; + virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; + virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) = 0; + virtual void SendChat (const AString & a_Message) = 0; + virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) = 0; + virtual void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player) = 0; + virtual void SendDestroyEntity (const cEntity & a_Entity) = 0; virtual void SendDisconnect (const AString & a_Reason) = 0; - virtual void SendLogin (const cPlayer & a_Player) = 0; + virtual void SendEntHeadLook (const cEntity & a_Entity) = 0; + virtual void SendEntLook (const cEntity & a_Entity) = 0; + virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) = 0; + virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) = 0; + virtual void SendGameMode (eGameMode a_GameMode) = 0; virtual void SendHandshake (const AString & a_ServerName) = 0; + virtual void SendHealth (void) = 0; + virtual void SendInventoryProgress(char a_WindowID, short a_Progressbar, short a_Value) = 0; virtual void SendInventorySlot (int a_WindowID, short a_SlotNum, const cItem & a_Item) = 0; - virtual void SendChat (const AString & a_Message) = 0; + virtual void SendKeepAlive (int a_PingID) = 0; + virtual void SendLogin (const cPlayer & a_Player) = 0; + virtual void SendMetadata (const cEntity & a_Entity) = 0; + virtual void SendPickupSpawn (const cPickup & a_Pickup) = 0; virtual void SendPlayerAnimation (const cPlayer & a_Player, char a_Animation) = 0; - virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) = 0; - virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) = 0; - virtual void SendWindowClose (char a_WindowID) = 0; - virtual void SendWholeInventory (const cInventory & a_Inventory) = 0; - virtual void SendWholeInventory (const cWindow & a_Window) = 0; - virtual void SendTeleportEntity (const cEntity & a_Entity) = 0; virtual void SendPlayerListItem (const cPlayer & a_Player, bool a_IsOnline) = 0; + virtual void SendPlayerMoveLook (void) = 0; virtual void SendPlayerPosition (void) = 0; - virtual void SendRelEntMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) = 0; + virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0; virtual void SendRelEntMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) = 0; - virtual void SendEntLook (const cEntity & a_Entity) = 0; - virtual void SendEntHeadLook (const cEntity & a_Entity) = 0; - virtual void SendBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2) = 0; - virtual void SendHealth (void) = 0; + virtual void SendRelEntMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) = 0; virtual void SendRespawn (void) = 0; - virtual void SendGameMode (eGameMode a_GameMode) = 0; - virtual void SendDestroyEntity (const cEntity & a_Entity) = 0; - virtual void SendPlayerMoveLook (void) = 0; - virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) = 0; - virtual void SendMetadata (const cPawn & a_Entity) = 0; - virtual void SendInventoryProgress(char a_WindowID, short a_Progressbar, short a_Value) = 0; - virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0; - virtual void SendPickupSpawn (const cPickup & a_Pickup) = 0; virtual void SendSpawnMob (const cMonster & a_Mob) = 0; - virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) = 0; - virtual void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player) = 0; - virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; - virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) = 0; + virtual void SendTeleportEntity (const cEntity & a_Entity) = 0; + virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) = 0; + virtual void SendTimeUpdate (Int64 a_WorldTime) = 0; virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) = 0; + virtual void SendUpdateSign (int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) = 0; virtual void SendWeather (eWeather a_Weather) = 0; - virtual void SendTimeUpdate (Int64 a_WorldTime) = 0; - virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) = 0; - virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) = 0; - virtual void SendKeepAlive (int a_PingID) = 0; + virtual void SendWholeInventory (const cInventory & a_Inventory) = 0; + virtual void SendWholeInventory (const cWindow & a_Window) = 0; + virtual void SendWindowClose (char a_WindowID) = 0; + virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) = 0; protected: cClientHandle * m_Client; @@ -87,6 +88,79 @@ protected: /// 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; + + /// Called after writing each packet, enables descendants to flush their buffers + virtual void Flush(void) {}; + + // Helpers for writing partial packet data, write using SendData() + void WriteByte(char a_Value) + { + SendData((const char *)&a_Value, 1); + } + + void WriteShort(short a_Value) + { + a_Value = htons(a_Value); + SendData((const char *)&a_Value, 2); + } + + /* + void WriteShort(unsigned short a_Value) + { + a_Value = htons(a_Value); + SendData((const char *)&a_Value, 2); + } + */ + + void WriteInt(int a_Value) + { + a_Value = htonl(a_Value); + SendData((const char *)&a_Value, 4); + } + + void WriteInt(unsigned int a_Value) + { + a_Value = htonl(a_Value); + SendData((const char *)&a_Value, 4); + } + + void WriteInt64 (Int64 a_Value) + { + a_Value = HostToNetwork8(&a_Value); + SendData((const char *)&a_Value, 8); + } + + void WriteFloat (float a_Value) + { + unsigned int val = HostToNetwork4(&a_Value); + SendData((const char *)&val, 4); + } + + void WriteDouble(double a_Value) + { + unsigned long long val = HostToNetwork8(&a_Value); + SendData((const char *)&val, 8); + } + + void WriteString(const AString & a_Value) + { + AString UTF16; + UTF8ToRawBEUTF16(a_Value.c_str(), a_Value.length(), UTF16); + WriteShort((unsigned short)(UTF16.size() / 2)); + SendData(UTF16.data(), UTF16.size()); + } + + void WriteBool(bool a_Value) + { + WriteByte(a_Value ? 1 : 0); + } + + void WriteVectorI(const Vector3i & a_Vector) + { + WriteInt(a_Vector.x); + WriteInt(a_Vector.y); + WriteInt(a_Vector.z); + } } ; diff --git a/source/Protocol125.cpp b/source/Protocol125.cpp index 73d9ab672..5b16e5728 100644 --- a/source/Protocol125.cpp +++ b/source/Protocol125.cpp @@ -10,48 +10,23 @@ #include "packets/cPacket.h" #include "packets/cPacket_13.h" #include "packets/cPacket_ArmAnim.h" -#include "packets/cPacket_BlockAction.h" -#include "packets/cPacket_BlockChange.h" #include "packets/cPacket_BlockDig.h" #include "packets/cPacket_BlockPlace.h" #include "packets/cPacket_Chat.h" -#include "packets/cPacket_CollectItem.h" #include "packets/cPacket_CreativeInventoryAction.h" -#include "packets/cPacket_DestroyEntity.h" #include "packets/cPacket_Disconnect.h" -#include "packets/cPacket_EntityEquipment.h" -#include "packets/cPacket_EntityLook.h" -#include "packets/cPacket_EntityStatus.h" #include "packets/cPacket_Flying.h" #include "packets/cPacket_Handshake.h" -#include "packets/cPacket_InventoryProgressBar.h" -#include "packets/cPacket_InventorySlot.h" #include "packets/cPacket_ItemSwitch.h" #include "packets/cPacket_KeepAlive.h" #include "packets/cPacket_Login.h" -#include "packets/cPacket_MapChunk.h" -#include "packets/cPacket_Metadata.h" -#include "packets/cPacket_MultiBlock.h" -#include "packets/cPacket_NamedEntitySpawn.h" -#include "packets/cPacket_NewInvalidState.h" -#include "packets/cPacket_PickupSpawn.h" #include "packets/cPacket_Ping.h" #include "packets/cPacket_Player.h" -#include "packets/cPacket_PreChunk.h" -#include "packets/cPacket_RelativeEntityMove.h" -#include "packets/cPacket_RelativeEntityMoveLook.h" #include "packets/cPacket_Respawn.h" -#include "packets/cPacket_SpawnMob.h" -#include "packets/cPacket_TeleportEntity.h" -#include "packets/cPacket_Thunderbolt.h" -#include "packets/cPacket_TimeUpdate.h" -#include "packets/cPacket_UpdateHealth.h" #include "packets/cPacket_UpdateSign.h" #include "packets/cPacket_UseEntity.h" -#include "packets/cPacket_WholeInventory.h" #include "packets/cPacket_WindowClick.h" #include "packets/cPacket_WindowClose.h" -#include "packets/cPacket_WindowOpen.h" #include "cClientHandle.h" #include "ChunkDataSerializer.h" @@ -59,6 +34,70 @@ #include "cMonster.h" #include "cPickup.h" #include "cPlayer.h" +#include "cChatColor.h" +#include "cWindow.h" + + + + + +enum +{ + PACKET_KEEP_ALIVE = 0x00, + PACKET_LOGIN = 0x01, + PACKET_HANDSHAKE = 0x02, + PACKET_CHAT = 0x03, + PACKET_UPDATE_TIME = 0x04, + PACKET_ENTITY_EQUIPMENT = 0x05, + PACKET_USE_ENTITY = 0x07, + PACKET_UPDATE_HEALTH = 0x08, + PACKET_RESPAWN = 0x09, + PACKET_FLYING = 0x0a, + PACKET_PLAYERPOS = 0x0b, + PACKET_PLAYERLOOK = 0x0c, + PACKET_PLAYERMOVELOOK = 0x0d, + PACKET_BLOCK_DIG = 0x0e, + PACKET_BLOCK_PLACE = 0x0f, + PACKET_SLOT_SELECTED = 0x10, + PACKET_ADD_TO_INV = 0x11, // TODO: Sure this is not Use Bed?? + PACKET_ANIMATION = 0x12, + PACKET_PACKET_ENTITY_ACTION = 0x13, + PACKET_PLAYER_SPAWN = 0x14, + PACKET_PICKUP_SPAWN = 0x15, + PACKET_COLLECT_PICKUP = 0x16, + PACKET_ADD_VEHICLE = 0x17, + PACKET_SPAWN_MOB = 0x18, + PACKET_DESTROY_ENTITY = 0x1d, + PACKET_ENTITY = 0x1e, + PACKET_REL_ENT_MOVE = 0x1f, + PACKET_ENT_LOOK = 0x20, + PACKET_REL_ENT_MOVE_LOOK = 0x21, + PACKET_ENT_TELEPORT = 0x22, + PACKET_ENT_HEAD_LOOK = 0x23, + PACKET_ENT_STATUS = 0x26, + PACKET_METADATA = 0x28, + PACKET_PRE_CHUNK = 0x32, + PACKET_MAP_CHUNK = 0x33, + PACKET_MULTI_BLOCK = 0x34, + PACKET_BLOCK_CHANGE = 0x35, + PACKET_BLOCK_ACTION = 0x36, + PACKET_EXPLOSION = 0x3C, + PACKET_SOUND_EFFECT = 0x3D, + PACKET_CHANGE_GAME_STATE = 0x46, + PACKET_THUNDERBOLT = 0x47, + PACKET_WINDOW_OPEN = 0x64, + PACKET_WINDOW_CLOSE = 0x65, + PACKET_WINDOW_CLICK = 0x66, + PACKET_INVENTORY_SLOT = 0x67, + PACKET_INVENTORY_WHOLE = 0x68, + PACKET_INVENTORY_PROGRESS = 0x69, + PACKET_CREATIVE_INVENTORY_ACTION = 0x6B, + PACKET_UPDATE_SIGN = 0x82, + PACKET_PLAYER_LIST_ITEM = 0xC9, + PACKET_PLAYER_ABILITIES = 0xca, + PACKET_PING = 0xfe, + PACKET_DISCONNECT = 0xff +} ; @@ -77,13 +116,13 @@ cProtocol125::cProtocol125(cClientHandle * a_Client) : void cProtocol125::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2) { cCSLock Lock(m_CSPacket); - cPacket_BlockAction ba; - ba.m_BlockX = a_BlockX; - ba.m_BlockY = (short)a_BlockY; - ba.m_BlockZ = a_BlockZ; - ba.m_Byte1 = a_Byte1; - ba.m_Byte2 = a_Byte2; - Send(ba); + WriteByte (PACKET_BLOCK_ACTION); + WriteInt (a_BlockX); + WriteShort((short)a_BlockY); + WriteInt (a_BlockZ); + WriteByte (a_Byte1); + WriteByte (a_Byte2); + Flush(); } @@ -93,13 +132,13 @@ void cProtocol125::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, cha void cProtocol125::SendBlockChange(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { cCSLock Lock(m_CSPacket); - cPacket_BlockChange BlockChange; - BlockChange.m_PosX = a_BlockX; - BlockChange.m_PosY = (unsigned char)a_BlockY; - BlockChange.m_PosZ = a_BlockZ; - BlockChange.m_BlockType = a_BlockType; - BlockChange.m_BlockMeta = a_BlockMeta; - Send(BlockChange); + WriteByte(PACKET_BLOCK_CHANGE); + WriteInt (a_BlockX); + WriteByte(a_BlockY); + WriteInt (a_BlockZ); + WriteByte(a_BlockType); + WriteByte(a_BlockMeta); + Flush(); } @@ -117,19 +156,18 @@ void cProtocol125::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockV return; } - cPacket_MultiBlock MultiBlock; - MultiBlock.m_ChunkX = a_ChunkX; - MultiBlock.m_ChunkZ = a_ChunkZ; - MultiBlock.m_NumBlocks = (short)a_Changes.size(); - MultiBlock.m_Data = new cPacket_MultiBlock::sBlockChange[a_Changes.size()]; - int i = 0; - for (sSetBlockVector::const_iterator itr = a_Changes.begin(), end = a_Changes.end(); itr != end; ++itr, i++) + WriteByte (PACKET_MULTI_BLOCK); + WriteInt (a_ChunkX); + WriteInt (a_ChunkZ); + WriteShort((unsigned short)a_Changes.size()); + WriteInt (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); - MultiBlock.m_Data[i].Data = Coords << 16 | Blocks; + WriteInt(Coords << 16 | Blocks); } - Send(MultiBlock); + Flush(); } @@ -139,8 +177,9 @@ void cProtocol125::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockV void cProtocol125::SendChat(const AString & a_Message) { cCSLock Lock(m_CSPacket); - cPacket_Chat Chat(a_Message); - Send(Chat); + WriteByte (PACKET_CHAT); + WriteString(a_Message); + Flush(); } @@ -152,12 +191,15 @@ void cProtocol125::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerialize cCSLock Lock(m_CSPacket); // Send the pre-chunk: - cPacket_PreChunk pre(a_ChunkX, a_ChunkZ, true); - Send(pre); + SendPreChunk(a_ChunkX, a_ChunkZ, true); - // Send the data: - cPacket_MapChunk mc(a_ChunkX, a_ChunkZ, a_Serializer.Serialize(cChunkDataSerializer::RELEASE_1_2_5)); - Send(mc); + // Send the chunk data: + AString Serialized = a_Serializer.Serialize(cChunkDataSerializer::RELEASE_1_2_5); + WriteByte(PACKET_MAP_CHUNK); + WriteInt (a_ChunkX); + WriteInt (a_ChunkZ); + SendData(Serialized.data(), Serialized.size()); + Flush(); } @@ -167,10 +209,10 @@ void cProtocol125::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerialize void cProtocol125::SendCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player) { cCSLock Lock(m_CSPacket); - cPacket_CollectItem ci; - ci.m_CollectedID = a_Pickup.GetUniqueID(); - ci.m_CollectorID = a_Player.GetUniqueID(); - Send(ci); + WriteByte(PACKET_COLLECT_PICKUP); + WriteInt (a_Pickup.GetUniqueID()); + WriteInt (a_Player.GetUniqueID()); + Flush(); } @@ -180,9 +222,9 @@ void cProtocol125::SendCollectPickup(const cPickup & a_Pickup, const cPlayer & a void cProtocol125::SendDestroyEntity(const cEntity & a_Entity) { cCSLock Lock(m_CSPacket); - cPacket_DestroyEntity de; - de.m_UniqueID = a_Entity.GetUniqueID(); - Send(de); + WriteByte(PACKET_DESTROY_ENTITY); + WriteInt (a_Entity.GetUniqueID()); + Flush(); } @@ -192,8 +234,9 @@ void cProtocol125::SendDestroyEntity(const cEntity & a_Entity) void cProtocol125::SendDisconnect(const AString & a_Reason) { cCSLock Lock(m_CSPacket); - cPacket_Disconnect DC(a_Reason); - Send(DC); // TODO: Send it immediately to the socket, bypassing any packet buffers (? is it safe? packet boundaries...) + WriteByte ((unsigned char)PACKET_DISCONNECT); + WriteString(a_Reason); + Flush(); } @@ -205,8 +248,10 @@ void cProtocol125::SendEntHeadLook(const cEntity & a_Entity) ASSERT(a_Entity.GetUniqueID() != m_Client->GetPlayer()->GetUniqueID()); // Must not send for self cCSLock Lock(m_CSPacket); - cPacket_EntityHeadLook ehl(a_Entity); - Send(ehl); + WriteByte(PACKET_ENT_HEAD_LOOK); + WriteInt (a_Entity.GetUniqueID()); + WriteByte((char)((a_Entity.GetRotation() / 360.f) * 256)); + Flush(); } @@ -218,11 +263,11 @@ void cProtocol125::SendEntLook(const cEntity & a_Entity) ASSERT(a_Entity.GetUniqueID() != m_Client->GetPlayer()->GetUniqueID()); // Must not send for self cCSLock Lock(m_CSPacket); - cPacket_EntityLook el; - el.m_UniqueID = a_Entity.GetUniqueID(); - el.m_Rotation = (char)((a_Entity.GetRotation() / 360.f) * 256); - el.m_Pitch = (char)((a_Entity.GetPitch() / 360.f) * 256); - Send(el); + WriteByte(PACKET_ENT_LOOK); + WriteInt (a_Entity.GetUniqueID()); + WriteByte((char)((a_Entity.GetRotation() / 360.f) * 256)); + WriteByte((char)((a_Entity.GetPitch() / 360.f) * 256)); + Flush(); } @@ -232,12 +277,12 @@ void cProtocol125::SendEntLook(const cEntity & a_Entity) void cProtocol125::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) { cCSLock Lock(m_CSPacket); - 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); + WriteByte (PACKET_ENTITY_EQUIPMENT); + WriteInt (a_Entity.GetUniqueID()); + WriteShort(a_SlotNum); + WriteShort(a_Item.m_ItemType); + WriteShort(a_Item.m_ItemDamage); + Flush(); } @@ -247,10 +292,10 @@ void cProtocol125::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum void cProtocol125::SendEntityStatus(const cEntity & a_Entity, char a_Status) { cCSLock Lock(m_CSPacket); - cPacket_EntityStatus es; - es.m_Status = a_Status; - es.m_UniqueID = a_Entity.GetUniqueID(); - Send(es); + WriteByte(PACKET_ENT_STATUS); + WriteInt (a_Entity.GetUniqueID()); + WriteByte(a_Status); + Flush(); } @@ -260,22 +305,22 @@ void cProtocol125::SendEntityStatus(const cEntity & a_Entity, char a_Status) void cProtocol125::SendGameMode(eGameMode a_GameMode) { cCSLock Lock(m_CSPacket); - cPacket_NewInvalidState nis; - nis.m_Reason = 3; - nis.m_GameMode = (char)a_GameMode; - Send(nis); + WriteByte(PACKET_CHANGE_GAME_STATE); + WriteByte(3); + WriteByte((char)a_GameMode); + Flush(); } -void cProtocol125::SendHandshake(const AString & a_ServerName) +void cProtocol125::SendHandshake(const AString & a_ConnectionHash) { cCSLock Lock(m_CSPacket); - cPacket_Handshake Handshake; - Handshake.m_Username = a_ServerName; - Send(Handshake); + WriteByte (PACKET_HANDSHAKE); + WriteString(a_ConnectionHash); + Flush(); } @@ -285,11 +330,11 @@ void cProtocol125::SendHandshake(const AString & a_ServerName) void cProtocol125::SendHealth(void) { cCSLock Lock(m_CSPacket); - cPacket_UpdateHealth Health; - Health.m_Health = (short)m_Client->GetPlayer()->GetHealth(); - Health.m_Food = m_Client->GetPlayer()->GetFoodLevel(); - Health.m_Saturation = m_Client->GetPlayer()->GetFoodSaturationLevel(); - Send(Health); + WriteByte (PACKET_UPDATE_HEALTH); + WriteShort((short)m_Client->GetPlayer()->GetHealth()); + WriteShort(m_Client->GetPlayer()->GetFoodLevel()); + WriteFloat(m_Client->GetPlayer()->GetFoodSaturationLevel()); + Flush(); } @@ -299,12 +344,11 @@ void cProtocol125::SendHealth(void) void cProtocol125::SendInventoryProgress(char a_WindowID, short a_ProgressBar, short a_Value) { cCSLock Lock(m_CSPacket); - cPacket_InventoryProgressBar Progress; - Progress.m_WindowID = a_WindowID; - Progress.m_ProgressBar = a_ProgressBar; - Progress.m_Value = a_Value; - Progress.m_WindowID = a_WindowID; - Send(Progress); + WriteByte (PACKET_INVENTORY_PROGRESS); + WriteByte (a_WindowID); + WriteShort(a_ProgressBar); + WriteShort(a_Value); + Flush(); } @@ -314,13 +358,11 @@ void cProtocol125::SendInventoryProgress(char a_WindowID, short a_ProgressBar, s void cProtocol125::SendInventorySlot(int a_WindowID, short a_SlotNum, const cItem & a_Item) { cCSLock Lock(m_CSPacket); - cPacket_InventorySlot Packet; - Packet.m_WindowID = (char)a_WindowID; - Packet.m_SlotNum = a_SlotNum; - Packet.m_ItemID = (short)(a_Item.m_ItemID); - Packet.m_ItemCount = a_Item.m_ItemCount; - Packet.m_ItemUses = a_Item.m_ItemHealth; - Send(Packet); + WriteByte (PACKET_INVENTORY_SLOT); + WriteByte (a_WindowID); + WriteShort(a_SlotNum); + WriteItem (a_Item); + Flush(); } @@ -330,8 +372,8 @@ void cProtocol125::SendInventorySlot(int a_WindowID, short a_SlotNum, const cIte void cProtocol125::SendKeepAlive(int a_PingID) { cCSLock Lock(m_CSPacket); - cPacket_KeepAlive ka(a_PingID); - Send(ka); + WriteByte(PACKET_KEEP_ALIVE); + WriteInt (a_PingID); } @@ -341,25 +383,31 @@ void cProtocol125::SendKeepAlive(int a_PingID) void cProtocol125::SendLogin(const cPlayer & a_Player) { cCSLock Lock(m_CSPacket); - cPacket_Login LoginResponse; - LoginResponse.m_ProtocolVersion = a_Player.GetUniqueID(); - LoginResponse.m_Username = ""; // Not used - LoginResponse.m_ServerMode = a_Player.GetGameMode(); // set gamemode from player. - LoginResponse.m_Dimension = 0; // TODO: Dimension (Nether / Overworld / End) - LoginResponse.m_MaxPlayers = 60; // Client list width or something - LoginResponse.m_Difficulty = 2; // TODO: Difficulty - Send(LoginResponse); + + WriteByte (E_LOGIN); + WriteInt (a_Player.GetUniqueID()); // EntityID of the player + WriteString(""); // Username, not used + WriteString("DEFAULT"); // Level type + WriteInt ((int)a_Player.GetGameMode()); + WriteInt (0); // TODO: Dimension (Nether / Overworld / End) + WriteByte (2); // TODO: Difficulty + WriteByte (0); // Unused + WriteByte (60); // Client list width or something + Flush(); } -void cProtocol125::SendMetadata(const cPawn & a_Pawn) +void cProtocol125::SendMetadata(const cEntity & a_Entity) { cCSLock Lock(m_CSPacket); - cPacket_Metadata md(a_Pawn.GetMetaData(), a_Pawn.GetUniqueID()); - Send(md); + WriteByte(PACKET_METADATA); + WriteInt (a_Entity.GetUniqueID()); + AString MetaData = GetEntityMetaData(a_Entity); + SendData(MetaData.data(), MetaData.size()); + Flush(); } @@ -369,18 +417,18 @@ void cProtocol125::SendMetadata(const cPawn & a_Pawn) void cProtocol125::SendPickupSpawn(const cPickup & a_Pickup) { cCSLock Lock(m_CSPacket); - cPacket_PickupSpawn PickupSpawn; - PickupSpawn.m_UniqueID = a_Pickup.GetUniqueID(); - PickupSpawn.m_ItemType = a_Pickup.GetItem()->m_ItemType; - PickupSpawn.m_ItemCount = a_Pickup.GetItem()->m_ItemCount; - PickupSpawn.m_ItemDamage = a_Pickup.GetItem()->m_ItemHealth; - PickupSpawn.m_PosX = (int) (a_Pickup.GetPosX() * 32); - PickupSpawn.m_PosY = (int) (a_Pickup.GetPosY() * 32); - PickupSpawn.m_PosZ = (int) (a_Pickup.GetPosZ() * 32); - PickupSpawn.m_Rotation = (char)(a_Pickup.GetSpeed().x * 8); - PickupSpawn.m_Pitch = (char)(a_Pickup.GetSpeed().y * 8); - PickupSpawn.m_Roll = (char)(a_Pickup.GetSpeed().z * 8); - Send(PickupSpawn); + WriteByte (PACKET_PICKUP_SPAWN); + WriteInt (a_Pickup.GetUniqueID()); + WriteShort(a_Pickup.GetItem()->m_ItemType); + WriteByte (a_Pickup.GetItem()->m_ItemCount); + WriteShort(a_Pickup.GetItem()->m_ItemDamage); + WriteInt ((int)(a_Pickup.GetPosX() * 32)); + WriteInt ((int)(a_Pickup.GetPosY() * 32)); + WriteInt ((int)(a_Pickup.GetPosZ() * 32)); + WriteByte ((char)(a_Pickup.GetSpeed().x * 8)); + WriteByte ((char)(a_Pickup.GetSpeed().y * 8)); + WriteByte ((char)(a_Pickup.GetSpeed().z * 8)); + Flush(); } @@ -390,10 +438,10 @@ void cProtocol125::SendPickupSpawn(const cPickup & a_Pickup) void cProtocol125::SendPlayerAnimation(const cPlayer & a_Player, char a_Animation) { cCSLock Lock(m_CSPacket); - cPacket_ArmAnim Anim; - Anim.m_EntityID = a_Player.GetUniqueID(); - Anim.m_Animation = a_Animation; - Send(Anim); + WriteByte(PACKET_ANIMATION); + WriteInt (a_Player.GetUniqueID()); + WriteByte(a_Animation); + Flush(); } @@ -403,8 +451,19 @@ void cProtocol125::SendPlayerAnimation(const cPlayer & a_Player, char a_Animatio void cProtocol125::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline) { cCSLock Lock(m_CSPacket); - cPacket_PlayerListItem pli(a_Player.GetColor() + a_Player.GetName(), a_IsOnline, a_Player.GetClientHandle()->GetPing()); - Send(pli); + AString PlayerName(a_Player.GetColor()); + PlayerName.append(a_Player.GetName()); + if (PlayerName.length() > 14) + { + PlayerName.erase(14); + } + PlayerName += cChatColor::White; + + WriteByte ((unsigned char)PACKET_PLAYER_LIST_ITEM); + WriteString(PlayerName); + WriteBool (a_IsOnline); + WriteShort (a_Player.GetClientHandle()->GetPing()); + Flush(); } @@ -414,13 +473,23 @@ void cProtocol125::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline) void cProtocol125::SendPlayerMoveLook(void) { cCSLock Lock(m_CSPacket); - cPacket_PlayerMoveLook pml(*m_Client->GetPlayer()); + /* LOGD("Sending PlayerMoveLook: {%0.2f, %0.2f, %0.2f}, stance %0.2f, OnGround: %d", m_Player->GetPosX(), m_Player->GetPosY(), m_Player->GetPosZ(), m_Player->GetStance(), m_Player->IsOnGround() ? 1 : 0 ); */ - Send(pml); + + WriteByte (PACKET_PLAYERMOVELOOK); + cPlayer * Player = m_Client->GetPlayer(); + WriteDouble(Player->GetPosX()); + WriteDouble(Player->GetStance() + 0.03); // Add a small amount so that the player doesn't start inside a block + WriteDouble(Player->GetPosY() + 0.03); // Add a small amount so that the player doesn't start inside a block + WriteDouble(Player->GetPosZ()); + WriteFloat (Player->GetRotation()); + WriteFloat (Player->GetPitch()); + WriteBool (Player->IsOnGround()); + Flush(); } @@ -430,8 +499,7 @@ void cProtocol125::SendPlayerMoveLook(void) void cProtocol125::SendPlayerPosition(void) { cCSLock Lock(m_CSPacket); - cPacket_PlayerPosition pp(*(m_Client->GetPlayer())); - Send(pp); + LOGD("Ignore send PlayerPos"); // PlayerPos is a C->S packet only now } @@ -440,18 +508,18 @@ void cProtocol125::SendPlayerPosition(void) void cProtocol125::SendPlayerSpawn(const cPlayer & a_Player) { + const cItem & HeldItem = a_Player.GetEquippedItem(); cCSLock Lock(m_CSPacket); - cPacket_NamedEntitySpawn SpawnPacket; - SpawnPacket.m_UniqueID = a_Player.GetUniqueID(); - SpawnPacket.m_PlayerName = a_Player.GetName(); - SpawnPacket.m_PosX = (int)(a_Player.GetPosX() * 32); - SpawnPacket.m_PosY = (int)(a_Player.GetPosY() * 32); - SpawnPacket.m_PosZ = (int)(a_Player.GetPosZ() * 32); - SpawnPacket.m_Rotation = (char)((a_Player.GetRot().x / 360.f) * 256); - SpawnPacket.m_Pitch = (char)((a_Player.GetRot().y / 360.f) * 256); - const cItem & HeldItem = a_Player.GetEquippedItem(); - SpawnPacket.m_CurrentItem = HeldItem.IsEmpty() ? 0 : HeldItem.m_ItemType; // Unlike -1 in inventory, the named entity packet uses 0 for "empty" - Send(SpawnPacket); + WriteByte (PACKET_PLAYER_SPAWN); + WriteInt (a_Player.GetUniqueID()); + WriteString(a_Player.GetName()); + WriteInt ((int)(a_Player.GetPosX() * 32)); + WriteInt ((int)(a_Player.GetPosY() * 32)); + WriteInt ((int)(a_Player.GetPosZ() * 32)); + WriteByte ((char)((a_Player.GetRot().x / 360.f) * 256)); + WriteByte ((char)((a_Player.GetRot().y / 360.f) * 256)); + WriteShort (HeldItem.IsEmpty() ? 0 : HeldItem.m_ItemType); + Flush(); } @@ -463,12 +531,12 @@ void cProtocol125::SendRelEntMove(const cEntity & a_Entity, char a_RelX, char a_ ASSERT(a_Entity.GetUniqueID() != m_Client->GetPlayer()->GetUniqueID()); // Must not send for self cCSLock Lock(m_CSPacket); - cPacket_RelativeEntityMove rem; - rem.m_UniqueID = a_Entity.GetUniqueID(); - rem.m_MoveX = a_RelX; - rem.m_MoveY = a_RelY; - rem.m_MoveZ = a_RelZ; - Send(rem); + WriteByte(PACKET_REL_ENT_MOVE); + WriteInt (a_Entity.GetUniqueID()); + WriteByte(a_RelX); + WriteByte(a_RelY); + WriteByte(a_RelZ); + Flush(); } @@ -480,14 +548,14 @@ void cProtocol125::SendRelEntMoveLook(const cEntity & a_Entity, char a_RelX, cha ASSERT(a_Entity.GetUniqueID() != m_Client->GetPlayer()->GetUniqueID()); // Must not send for self cCSLock Lock(m_CSPacket); - cPacket_RelativeEntityMoveLook reml; - reml.m_UniqueID = a_Entity.GetUniqueID(); - reml.m_MoveX = a_RelX; - reml.m_MoveY = a_RelY; - reml.m_MoveZ = a_RelZ; - reml.m_Yaw = (char)((a_Entity.GetRotation() / 360.f) * 256); - reml.m_Pitch = (char)((a_Entity.GetPitch() / 360.f) * 256); - Send(reml); + WriteByte(PACKET_REL_ENT_MOVE_LOOK); + WriteInt (a_Entity.GetUniqueID()); + WriteByte(a_RelX); + WriteByte(a_RelY); + WriteByte(a_RelZ); + WriteByte((char)((a_Entity.GetRotation() / 360.f) * 256)); + WriteByte((char)((a_Entity.GetPitch() / 360.f) * 256)); + Flush(); } @@ -497,9 +565,12 @@ void cProtocol125::SendRelEntMoveLook(const cEntity & a_Entity, char a_RelX, cha void cProtocol125::SendRespawn(void) { cCSLock Lock(m_CSPacket); - cPacket_Respawn Packet; - Packet.m_CreativeMode = (char)m_Client->GetPlayer()->GetGameMode(); // Set GameMode packet based on Player's GameMode; - Send(Packet); + WriteByte (PACKET_RESPAWN); + WriteInt (0); // TODO: Dimension; 0 = Overworld + WriteByte (2); // TODO: Difficulty; 2 = Normal + WriteByte ((char)m_Client->GetPlayer()->GetGameMode()); + WriteShort (256); // Current world height + WriteString("DEFAULT"); } @@ -509,16 +580,19 @@ void cProtocol125::SendRespawn(void) void cProtocol125::SendSpawnMob(const cMonster & a_Mob) { cCSLock Lock(m_CSPacket); - cPacket_SpawnMob Spawn; - Spawn.m_UniqueID = a_Mob.GetUniqueID(); - Spawn.m_Type = a_Mob.GetMobType(); - Spawn.m_Pos = ((Vector3i)(a_Mob.GetPosition())) * 32; - Spawn.m_Yaw = 0; - Spawn.m_Pitch = 0; - Spawn.m_MetaDataSize = 1; - Spawn.m_MetaData = new char[Spawn.m_MetaDataSize]; - Spawn.m_MetaData[0] = 0x7f; // not on fire/crouching/riding - Send(Spawn); + Vector3i Pos = (Vector3i)(a_Mob.GetPosition() * 32); + WriteByte(PACKET_SPAWN_MOB); + WriteInt (a_Mob.GetUniqueID()); + WriteByte(a_Mob.GetMobType()); + WriteInt (Pos.x); + WriteInt (Pos.y); + WriteInt (Pos.z); + WriteByte(0); + WriteByte(0); + WriteByte(0); + AString MetaData = GetEntityMetaData(a_Mob); + SendData (MetaData.data(), MetaData.size()); + Flush(); } @@ -528,8 +602,12 @@ void cProtocol125::SendSpawnMob(const cMonster & a_Mob) void cProtocol125::SendTeleportEntity(const cEntity & a_Entity) { cCSLock Lock(m_CSPacket); - cPacket_TeleportEntity te(a_Entity); - Send(te); + WriteByte (PACKET_ENT_TELEPORT); + WriteInt (a_Entity.GetUniqueID()); + WriteVectorI((Vector3i)(a_Entity.GetPosition() * 32)); + WriteByte ((char)((a_Entity.GetRotation() / 360.f) * 256)); + WriteByte ((char)((a_Entity.GetPitch() / 360.f) * 256)); + Flush(); } @@ -539,11 +617,13 @@ void cProtocol125::SendTeleportEntity(const cEntity & a_Entity) void cProtocol125::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) { cCSLock Lock(m_CSPacket); - cPacket_Thunderbolt ThunderboltPacket; - ThunderboltPacket.m_xLBPos = a_BlockX; - ThunderboltPacket.m_yLBPos = a_BlockY; - ThunderboltPacket.m_zLBPos = a_BlockZ; - Send(ThunderboltPacket); + WriteByte(PACKET_THUNDERBOLT); + WriteInt (0x7fffffff); // Entity ID of the thunderbolt; we use a constant one + WriteBool(true); // Unknown bool + WriteInt (a_BlockX * 32); + WriteInt (a_BlockY * 32); + WriteInt (a_BlockZ * 32); + Flush(); } @@ -553,9 +633,9 @@ void cProtocol125::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) void cProtocol125::SendTimeUpdate(Int64 a_WorldTime) { cCSLock Lock(m_CSPacket); - cPacket_TimeUpdate tu; - tu.m_Time = a_WorldTime; - Send(tu); + WriteByte (PACKET_UPDATE_TIME); + WriteInt64(a_WorldTime); + Flush(); } @@ -565,11 +645,7 @@ void cProtocol125::SendTimeUpdate(Int64 a_WorldTime) void cProtocol125::SendUnloadChunk(int a_ChunkX, int a_ChunkZ) { cCSLock Lock(m_CSPacket); - cPacket_PreChunk UnloadPacket; - UnloadPacket.m_PosX = a_ChunkX; - UnloadPacket.m_PosZ = a_ChunkZ; - UnloadPacket.m_bLoad = false; // Unload - Send(UnloadPacket); + SendPreChunk(a_ChunkX, a_ChunkZ, false); } @@ -582,15 +658,15 @@ void cProtocol125::SendUpdateSign( ) { cCSLock Lock(m_CSPacket); - cPacket_UpdateSign us; - us.m_BlockX = a_BlockX; - us.m_BlockY = (short)a_BlockY; - us.m_BlockZ = a_BlockZ; - us.m_Line1 = a_Line1; - us.m_Line2 = a_Line2; - us.m_Line3 = a_Line3; - us.m_Line4 = a_Line4; - Send(us); + WriteByte ((unsigned char)PACKET_UPDATE_SIGN); + WriteInt (a_BlockX); + WriteShort ((short)a_BlockY); + WriteInt (a_BlockZ); + WriteString(a_Line1); + WriteString(a_Line2); + WriteString(a_Line3); + WriteString(a_Line4); + Flush(); } @@ -604,25 +680,20 @@ void cProtocol125::SendWeather(eWeather a_Weather) { case eWeather_Sunny: { - cPacket_NewInvalidState WeatherPacket; - WeatherPacket.m_Reason = 2; // stop rain - Send(WeatherPacket); + WriteByte(PACKET_CHANGE_GAME_STATE); + WriteByte(2); // Stop rain + WriteByte(0); // Unused + Flush(); break; } case eWeather_Rain: - { - cPacket_NewInvalidState WeatherPacket; - WeatherPacket.m_Reason = 1; // begin rain - Send(WeatherPacket); - break; - } - case eWeather_ThunderStorm: { - cPacket_NewInvalidState WeatherPacket; - WeatherPacket.m_Reason = 1; // begin rain - Send(WeatherPacket); + WriteByte(PACKET_CHANGE_GAME_STATE); + WriteByte(1); // Begin rain + WriteByte(0); // Unused + Flush(); break; } } @@ -635,8 +706,7 @@ void cProtocol125::SendWeather(eWeather a_Weather) void cProtocol125::SendWholeInventory(const cInventory & a_Inventory) { cCSLock Lock(m_CSPacket); - cPacket_WholeInventory wi(a_Inventory); - Send(wi); + SendWholeInventory(0, a_Inventory.c_NumSlots, a_Inventory.GetSlots()); } @@ -646,8 +716,11 @@ void cProtocol125::SendWholeInventory(const cInventory & a_Inventory) void cProtocol125::SendWholeInventory(const cWindow & a_Window) { cCSLock Lock(m_CSPacket); - cPacket_WholeInventory wi(a_Window); - Send(wi); + SendWholeInventory( + a_Window.GetWindowID(), + a_Window.GetNumSlots(), + a_Window.GetSlots() + ); } @@ -657,9 +730,9 @@ void cProtocol125::SendWholeInventory(const cWindow & a_Window) void cProtocol125::SendWindowClose(char a_WindowID) { cCSLock Lock(m_CSPacket); - cPacket_WindowClose wc; - wc.m_WindowID = a_WindowID; - Send(wc); + WriteByte(PACKET_WINDOW_CLOSE); + WriteByte(a_WindowID); + Flush(); } @@ -669,23 +742,12 @@ void cProtocol125::SendWindowClose(char a_WindowID) void cProtocol125::SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) { cCSLock Lock(m_CSPacket); - 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 cProtocol125::Send(const cPacket & a_Packet) -{ - AString str; - a_Packet.Serialize(str); - SendData(str.data(), str.size()); + WriteByte (PACKET_WINDOW_OPEN); + WriteByte (a_WindowID); + WriteByte (a_WindowType); + WriteString(a_WindowTitle); + WriteByte (a_NumSlots); + Flush(); } @@ -754,31 +816,28 @@ int cProtocol125::ParsePacket(unsigned char a_PacketType) switch (a_PacketType) { default: return PACKET_UNKNOWN; - case E_KEEP_ALIVE: return ParseKeepAlive(); - case E_HANDSHAKE: return ParseHandshake(); - case E_LOGIN: return ParseLogin(); - case E_PLAYERPOS: return ParsePlayerPosition(); - case E_PLAYERLOOK: return ParsePlayerLook(); - case E_PLAYERMOVELOOK: return ParsePlayerMoveLook(); - case E_PLAYER_ABILITIES: return ParsePlayerAbilities(); - case E_CHAT: return ParseChat(); - case E_ANIMATION: return ParseArmAnim(); - case E_FLYING: return ParseFlying(); - case E_BLOCK_DIG: return ParseBlockDig(); - case E_BLOCK_PLACE: return ParseBlockPlace(); - case E_DISCONNECT: return ParseDisconnect(); - case E_ITEM_SWITCH: return ParseItemSwitch(); - case E_ENTITY_EQUIPMENT: return ParseEntityEquipment(); - case E_CREATIVE_INVENTORY_ACTION: return ParseCreativeInventoryAction(); - case E_NEW_INVALID_STATE: return ParseNewInvalidState(); - case E_PICKUP_SPAWN: return ParsePickupSpawn(); - case E_USE_ENTITY: return ParseUseEntity(); - case E_WINDOW_CLOSE: return ParseWindowClose(); - case E_WINDOW_CLICK: return ParseWindowClick(); - case E_PACKET_ENTITY_ACTION: return ParseEntityAction(); - case E_UPDATE_SIGN: return ParseUpdateSign(); - case E_RESPAWN: return ParseRespawn(); - case E_PING: return ParsePing(); + case PACKET_ANIMATION: return ParseArmAnim(); + case PACKET_BLOCK_DIG: return ParseBlockDig(); + case PACKET_BLOCK_PLACE: return ParseBlockPlace(); + case PACKET_CHAT: return ParseChat(); + case PACKET_CREATIVE_INVENTORY_ACTION: return ParseCreativeInventoryAction(); + case PACKET_DISCONNECT: return ParseDisconnect(); + case PACKET_FLYING: return ParseFlying(); + case PACKET_HANDSHAKE: return ParseHandshake(); + case PACKET_KEEP_ALIVE: return ParseKeepAlive(); + case PACKET_LOGIN: return ParseLogin(); + case PACKET_PACKET_ENTITY_ACTION: return ParseEntityAction(); + case PACKET_PING: return ParsePing(); + case PACKET_PLAYERLOOK: return ParsePlayerLook(); + case PACKET_PLAYERMOVELOOK: return ParsePlayerMoveLook(); + case PACKET_PLAYERPOS: return ParsePlayerPosition(); + case PACKET_PLAYER_ABILITIES: return ParsePlayerAbilities(); + case PACKET_RESPAWN: return ParseRespawn(); + case PACKET_SLOT_SELECTED: return ParseSlotSelected(); + case PACKET_UPDATE_SIGN: return ParseUpdateSign(); + case PACKET_USE_ENTITY: return ParseUseEntity(); + case PACKET_WINDOW_CLICK: return ParseWindowClick(); + case PACKET_WINDOW_CLOSE: return ParseWindowClose(); } } @@ -955,7 +1014,7 @@ int cProtocol125::ParseDisconnect(void) -int cProtocol125::ParseItemSwitch(void) +int cProtocol125::ParseSlotSelected(void) { cPacket_ItemSwitch its; HANDLE_PACKET_PARSE(its); @@ -967,18 +1026,6 @@ int cProtocol125::ParseItemSwitch(void) -int cProtocol125::ParseEntityEquipment(void) -{ - cPacket_EntityEquipment ee; - HANDLE_PACKET_PARSE(ee); - // TODO: m_Client->HandleEntityEquipment(...); - return PACKET_OK; -} - - - - - int cProtocol125::ParseCreativeInventoryAction(void) { cPacket_CreativeInventoryAction cia; @@ -991,30 +1038,6 @@ int cProtocol125::ParseCreativeInventoryAction(void) -int cProtocol125::ParseNewInvalidState(void) -{ - cPacket_NewInvalidState nis; - HANDLE_PACKET_PARSE(nis); - // TODO: m_Client->Handle(...); - return PACKET_OK; -} - - - - - -int cProtocol125::ParsePickupSpawn(void) -{ - cPacket_PickupSpawn ps; - HANDLE_PACKET_PARSE(ps); - // TODO: m_Client->HandlePickupSpawn(...); - return PACKET_OK; -} - - - - - int cProtocol125::ParseUseEntity(void) { cPacket_UseEntity ue; @@ -1102,3 +1125,111 @@ int cProtocol125::ParsePing(void) + +void cProtocol125::SendPreChunk(int a_ChunkX, int a_ChunkZ, bool a_ShouldLoad) +{ + WriteByte(E_PRE_CHUNK); + WriteInt (a_ChunkX); + WriteInt (a_ChunkZ); + WriteBool(a_ShouldLoad); + Flush(); +} + + + + + +void cProtocol125::SendWholeInventory(char a_WindowID, int a_NumItems, const cItem * a_Items) +{ + WriteByte (PACKET_INVENTORY_WHOLE); + WriteByte (a_WindowID); + WriteShort((short)a_NumItems); + + for (int j = 0; j < a_NumItems; j++) + { + WriteItem(a_Items[j]); + } + Flush(); +} + + + + + +void cProtocol125::WriteItem(const cItem & a_Item) +{ + short ItemType = a_Item.m_ItemType; + ASSERT(ItemType >= -1); // Check validity of packets in debug runtime + if (ItemType <= 0) + { + // Fix, to make sure no invalid values are sent. + ItemType = -1; + } + + WriteShort(ItemType); + if (a_Item.IsEmpty()) + { + return; + } + + WriteByte (a_Item.m_ItemCount); + WriteShort(a_Item.m_ItemDamage); + + if (cItem::IsEnchantable(a_Item.m_ItemType)) + { + // TODO: Implement enchantments + WriteShort(-1); + } +} + + + + + +AString cProtocol125::GetEntityMetaData(const cEntity & a_Entity) +{ + // We should send all the metadata here + AString MetaData; + // Common metadata (index 0, byte): + MetaData.push_back(0); + MetaData.push_back(GetEntityMetadataFlags(a_Entity)); + + // TODO: Add more entity-specific metadata + + MetaData.push_back(0x7f); // End metadata + return MetaData; +} + + + + + +char cProtocol125::GetEntityMetadataFlags(const cEntity & a_Entity) +{ + char Flags = 0; + if (a_Entity.IsOnFire()) + { + Flags |= 1; + } + if (a_Entity.IsCrouched()) + { + Flags |= 2; + } + if (a_Entity.IsRiding()) + { + Flags |= 4; + } + if (a_Entity.IsSprinting()) + { + Flags |= 8; + } + if (a_Entity.IsRclking()) + { + Flags |= 16; + } + return Flags; +} + + + + diff --git a/source/Protocol125.h b/source/Protocol125.h index cfa5c1ecd..de1be4fd7 100644 --- a/source/Protocol125.h +++ b/source/Protocol125.h @@ -47,13 +47,13 @@ public: virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) override; virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override; virtual void SendGameMode (eGameMode a_GameMode) override; - virtual void SendHandshake (const AString & a_ServerName) override; + virtual void SendHandshake (const AString & a_ConnectionHash) override; virtual void SendHealth (void) override; virtual void SendInventoryProgress(char a_WindowID, short a_Progressbar, short a_Value) override; virtual void SendInventorySlot (int a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player) override; - virtual void SendMetadata (const cPawn & a_Entity) override; + virtual void SendMetadata (const cEntity & a_Entity) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; virtual void SendPlayerAnimation (const cPlayer & a_Player, char a_Animation) override; virtual void SendPlayerListItem (const cPlayer & a_Player, bool a_IsOnline) override; @@ -86,39 +86,50 @@ protected: cByteBuffer m_ReceivedData; //< Buffer for the received data - void Send(const cPacket & a_Packet); - virtual void SendData(const char * a_Data, int a_Size) override; /// Parse the packet of the specified type from m_ReceivedData (switch into ParseXYZ() ) virtual int ParsePacket(unsigned char a_PacketType); // Specific packet parsers: - virtual int ParseKeepAlive (void); - virtual int ParseHandshake (void); - virtual int ParseLogin (void); - virtual int ParsePlayerPosition (void); - virtual int ParsePlayerLook (void); - virtual int ParsePlayerMoveLook (void); - virtual int ParsePlayerAbilities (void); - virtual int ParseChat (void); virtual int ParseArmAnim (void); - virtual int ParseFlying (void); virtual int ParseBlockDig (void); virtual int ParseBlockPlace (void); - virtual int ParseDisconnect (void); - virtual int ParseItemSwitch (void); - virtual int ParseEntityEquipment (void); + virtual int ParseChat (void); virtual int ParseCreativeInventoryAction(void); - virtual int ParseNewInvalidState (void); - virtual int ParsePickupSpawn (void); - virtual int ParseUseEntity (void); - virtual int ParseWindowClose (void); - virtual int ParseWindowClick (void); + virtual int ParseDisconnect (void); virtual int ParseEntityAction (void); - virtual int ParseUpdateSign (void); - virtual int ParseRespawn (void); + virtual int ParseFlying (void); + virtual int ParseHandshake (void); + virtual int ParseSlotSelected (void); + virtual int ParseKeepAlive (void); + virtual int ParseLogin (void); virtual int ParsePing (void); + virtual int ParsePlayerAbilities (void); + virtual int ParsePlayerLook (void); + virtual int ParsePlayerMoveLook (void); + virtual int ParsePlayerPosition (void); + virtual int ParseRespawn (void); + virtual int ParseUpdateSign (void); + virtual int ParseUseEntity (void); + virtual int ParseWindowClick (void); + virtual int ParseWindowClose (void); + + // Utility functions: + /// Writes a "pre-chunk" packet + void SendPreChunk(int a_ChunkX, int a_ChunkZ, bool a_ShouldLoad); + + /// Writes a "whole inventory" packet with the specified params + void SendWholeInventory(char a_WindowID, int a_NumItems, const cItem * a_Items); + + /// Writes one item, "slot" as the protocol wiki calls it + virtual void WriteItem(const cItem & a_Item); + + /// Returns the entity metadata representation + AString GetEntityMetaData(const cEntity & a_Entity); + + /// Returns the entity common metadata, index 0 (generic flags) + char GetEntityMetadataFlags(const cEntity & a_Entity); } ; diff --git a/source/StringUtils.cpp b/source/StringUtils.cpp index e3eb95a6e..2ec68550b 100644 --- a/source/StringUtils.cpp +++ b/source/StringUtils.cpp @@ -306,3 +306,162 @@ AString & RawBEToUTF8(short * a_RawData, int a_NumShorts, AString & a_UTF8) +// UTF-8 conversion code adapted from: +// http://stackoverflow.com/questions/2867123/convert-utf-16-to-utf-8-under-windows-and-linux-in-c + +#define UNI_MAX_BMP 0x0000FFFF +#define UNI_MAX_UTF16 0x0010FFFF +#define UNI_MAX_UTF32 0x7FFFFFFF +#define UNI_MAX_LEGAL_UTF32 0x0010FFFF +#define UNI_SUR_HIGH_START 0xD800 +#define UNI_SUR_HIGH_END 0xDBFF +#define UNI_SUR_LOW_START 0xDC00 +#define UNI_SUR_LOW_END 0xDFFF + + + + + +static const char trailingBytesForUTF8[256] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 +}; + + + + + +static const unsigned int offsetsFromUTF8[6] = +{ + 0x00000000UL, 0x00003080UL, 0x000E2080UL, + 0x03C82080UL, 0xFA082080UL, 0x82082080UL +}; + + + + + +static bool isLegalUTF8(const unsigned char * source, int length) +{ + unsigned char a; + const unsigned char * srcptr = source + length; + switch (length) + { + default: return false; + // Everything else falls through when "true"... + case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false; + case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false; + case 2: + { + if ((a = (*--srcptr)) > 0xBF) return false; + switch (*source) + { + // no fall-through in this inner switch + case 0xE0: if (a < 0xA0) return false; break; + case 0xED: if (a > 0x9F) return false; break; + case 0xF0: if (a < 0x90) return false; break; + case 0xF4: if (a > 0x8F) return false; break; + default: if (a < 0x80) return false; + } + } + case 1: if (*source >= 0x80 && *source < 0xC2) return false; + } + if (*source > 0xF4) return false; + return true; +} + + + + + +AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16) +{ + a_UTF16.clear(); + a_UTF16.reserve(a_UTF8Length * 3); + + const unsigned char * source = (const unsigned char*)a_UTF8; + const unsigned char * sourceEnd = source + a_UTF8Length; + const int halfShift = 10; // used for shifting by 10 bits + const unsigned int halfBase = 0x0010000UL; + const unsigned int halfMask = 0x3FFUL; + + while (source < sourceEnd) + { + unsigned int ch = 0; + unsigned short extraBytesToRead = trailingBytesForUTF8[*source]; + if (source + extraBytesToRead >= sourceEnd) + { + return a_UTF16; + } + // Do this check whether lenient or strict + if (!isLegalUTF8(source, extraBytesToRead + 1)) + { + return a_UTF16; + break; + } + + // The cases all fall through. See "Note A" below. + switch (extraBytesToRead) + { + case 5: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */ + case 4: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */ + case 3: ch += *source++; ch <<= 6; + case 2: ch += *source++; ch <<= 6; + case 1: ch += *source++; ch <<= 6; + case 0: ch += *source++; + } + ch -= offsetsFromUTF8[extraBytesToRead]; + + if (ch <= UNI_MAX_BMP) + { + // Target is a character <= 0xFFFF + if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) + { + // UTF-16 surrogate values are illegal in UTF-32 + ch = ' '; + } + unsigned short v = htons((unsigned short)ch); + a_UTF16.append((const char *)&v, 2); + } + else if (ch > UNI_MAX_UTF16) + { + // Invalid value, replace with a space + unsigned short v = htons(' '); + a_UTF16.append((const char *)&v, 2); + } + else + { + // target is a character in range 0xFFFF - 0x10FFFF. + ch -= halfBase; + unsigned short v1 = htons((ch >> halfShift) + UNI_SUR_HIGH_START); + unsigned short v2 = htons((ch & halfMask) + UNI_SUR_LOW_START); + a_UTF16.append((const char *)&v1, 2); + a_UTF16.append((const char *)&v2, 2); + } + } + return a_UTF16; +} + +/* --------------------------------------------------------------------- + + Note A. + The fall-through switches in UTF-8 reading code save a + temp variable, some decrements & conditionals. The switches + are equivalent to the following loop: + { + int tmpBytesToRead = extraBytesToRead+1; + do { + ch += *source++; + --tmpBytesToRead; + if (tmpBytesToRead) ch <<= 6; + } while (tmpBytesToRead > 0); + } + + --------------------------------------------------------------------- */ \ No newline at end of file diff --git a/source/StringUtils.h b/source/StringUtils.h index 6ab95880a..9dcb456c6 100644 --- a/source/StringUtils.h +++ b/source/StringUtils.h @@ -54,6 +54,9 @@ extern AStringList GetDirectoryContents(const char * a_Directory); /// Converts a stream of BE shorts into UTF-8 string; returns a ref to a_UTF8 extern AString & RawBEToUTF8(short * a_RawData, int a_NumShorts, AString & a_UTF8); +/// Converts a UTF-8 string into a UTF-16 BE string, packing that back into AString; return a ref to a_UTF16 +extern AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16); + // If you have any other string helper functions, declare them here diff --git a/source/cChatColor.cpp b/source/cChatColor.cpp index 228dc7a38..cad04676e 100644 --- a/source/cChatColor.cpp +++ b/source/cChatColor.cpp @@ -3,7 +3,7 @@ #include "cChatColor.h" -const std::string cChatColor::Color = "\xa7"; // Old color was "\xc2\xa7" or in other words: "§" +const std::string cChatColor::Color = "\xc2\xa7"; // or in other words: "§" const std::string cChatColor::Delimiter = "\xa7"; const std::string cChatColor::Black = cChatColor::Color + "0"; const std::string cChatColor::Navy = cChatColor::Color + "1"; diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index a939dc786..d966831b9 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -508,34 +508,6 @@ void cClientHandle::HandleUnexpectedPacket(int a_PacketType) -void cClientHandle::HandleMoveLookConfirm(double a_PosX, double a_PosY, double a_PosZ) -{ - Vector3d ReceivedPosition = Vector3d(a_PosX, a_PosY, a_PosZ); - // LOGD("Received MoveLook confirmation: {%0.2f %0.2f %0.2f}", a_PosX, a_PosY, a_PosZ); - - // Test the distance between points with a small/large enough value instead of comparing directly. Floating point inaccuracies might screw stuff up - double Dist = (ReceivedPosition - m_ConfirmPosition).SqrLength(); - if (Dist < 1.0) - { - // Test - if (ReceivedPosition.Equals(m_ConfirmPosition)) - { - LOGINFO("Exact position confirmed by client!"); - } - m_State = csPlaying; - } - else - { - LOGWARNING("Player \"%s\" sent a weird position confirmation %.2f blocks away, retrying", m_Username.c_str(), Dist); - m_ConfirmPosition = m_Player->GetPosition(); - SendPlayerMoveLook(); - } -} - - - - - void cClientHandle::HandleCreativeInventory(short a_SlotNum, const cItem & a_HeldItem) { // This is for creative Inventory changes @@ -827,18 +799,44 @@ void cClientHandle::HandlePlayerMoveLook(double a_PosX, double a_PosY, double a_ return; } */ - if (m_State != csPlaying) + switch (m_State) { - // Ignore this packet unles the player is fully in: - return; + case csPlaying: + { + 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(); + break; + } + + case csDownloadingWorld: + { + Vector3d ReceivedPosition = Vector3d(a_PosX, a_PosY, a_PosZ); + // LOGD("Received MoveLook confirmation: {%0.2f %0.2f %0.2f}", a_PosX, a_PosY, a_PosZ); + + // Test the distance between points with a small/large enough value instead of comparing directly. Floating point inaccuracies might screw stuff up + double Dist = (ReceivedPosition - m_ConfirmPosition).SqrLength(); + if (Dist < 1.0) + { + // Test + if (ReceivedPosition.Equals(m_ConfirmPosition)) + { + LOGINFO("Exact position confirmed by client!"); + } + m_State = csPlaying; + } + else + { + LOGWARNING("Player \"%s\" sent a weird position confirmation %.2f blocks away, retrying", m_Username.c_str(), Dist); + m_ConfirmPosition = m_Player->GetPosition(); + SendPlayerMoveLook(); + } + break; + } } - - 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(); } diff --git a/source/cClientHandle.h b/source/cClientHandle.h index c2e5fa83c..ee3e8b1ee 100644 --- a/source/cClientHandle.h +++ b/source/cClientHandle.h @@ -148,9 +148,6 @@ public: void HandleLogin (int a_ProtocolVersion, const AString & a_Username); void HandleUnexpectedPacket(int a_PacketType); // the default case -> kick - // Packets handled while in csConfirmingPos: - void HandleMoveLookConfirm(double a_PosX, double a_PosY, double a_PosZ); // While !m_bPositionConfirmed - // Packets handled while in csPlaying: void HandleCreativeInventory(short a_SlotNum, const cItem & a_HeldItem); void HandlePlayerPos (double a_PosX, double a_PosY, double a_PosZ, double a_Stance, bool a_IsOnGround); diff --git a/source/cEntity.cpp b/source/cEntity.cpp index 12af1c0b7..e6ed2baaa 100644 --- a/source/cEntity.cpp +++ b/source/cEntity.cpp @@ -36,6 +36,8 @@ cEntity::cEntity(const double & a_X, const double & a_Y, const double & a_Z) , m_EntityType( eEntityType_Entity ) , m_World( 0 ) , m_bRemovedFromChunk( false ) + , m_FireDamageInterval(0.f) + , m_BurnPeriod(0.f) { cCSLock Lock(m_CSCount); m_EntityCount++; diff --git a/source/cEntity.h b/source/cEntity.h index 50955f9ce..a34b7518f 100644 --- a/source/cEntity.h +++ b/source/cEntity.h @@ -121,6 +121,13 @@ public: virtual void SpawnOn(cClientHandle & a_Client) {ASSERT(!"SpawnOn() unimplemented!"); } // tolua_export void WrapRotation(); + + // Metadata flags; descendants may override the defaults: + virtual bool IsOnFire (void) const {return (m_BurnPeriod > 0); } + virtual bool IsCrouched (void) const {return false; } + virtual bool IsRiding (void) const {return false; } + virtual bool IsSprinting(void) const {return false; } + virtual bool IsRclking (void) const {return false; } protected: virtual void Destroyed() {} // Called after the entity has been destroyed @@ -154,6 +161,9 @@ protected: eEntityType m_EntityType; cWorld* m_World; + + float m_FireDamageInterval; + float m_BurnPeriod; }; //tolua_export typedef std::list cEntityList; diff --git a/source/cPawn.cpp b/source/cPawn.cpp index d8a9d03be..cecc19522 100644 --- a/source/cPawn.cpp +++ b/source/cPawn.cpp @@ -29,8 +29,6 @@ cPawn::cPawn() , m_TimeLastTeleportPacket( 0.f ) , m_bBurnable(true) , m_MetaData(NORMAL) - , m_FireDamageInterval(0.f) - , m_BurnPeriod(0.f) { SetMaxHealth(20); } diff --git a/source/cPawn.h b/source/cPawn.h index 3b1a566f5..b48ce94ab 100644 --- a/source/cPawn.h +++ b/source/cPawn.h @@ -59,10 +59,6 @@ protected: double m_LastPosX, m_LastPosY, m_LastPosZ; float m_TimeLastTeleportPacket; - - float m_FireDamageInterval; - float m_BurnPeriod; - }; //tolua_export diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp index 2a52d7da8..b7c05b402 100644 --- a/source/cPlayer.cpp +++ b/source/cPlayer.cpp @@ -769,16 +769,16 @@ AString cPlayer::GetColor(void) const void cPlayer::TossItem( bool a_bDraggingItem, - int a_Amount /* = 1 */, - int a_CreateType /* = 0 */, - int a_CreateHealth /* = 0 */ + char a_Amount /* = 1 */, + short a_CreateType /* = 0 */, + short a_CreateHealth /* = 0 */ ) { cItems Drops; if (a_CreateType) { // Just create item without touching the inventory (used in creative mode) - Drops.push_back(cItem((ENUM_ITEM_ID)a_CreateType, (char)a_Amount, a_CreateHealth)); + Drops.push_back(cItem(a_CreateType, a_Amount, a_CreateHealth)); } else { diff --git a/source/cPlayer.h b/source/cPlayer.h index 91aa9c831..8d652120a 100644 --- a/source/cPlayer.h +++ b/source/cPlayer.h @@ -85,7 +85,7 @@ public: AString GetColor(void) const; //tolua_export - void TossItem(bool a_bDraggingItem, int a_Amount = 1, int a_CreateType = 0, int a_CreateHealth = 0); //tolua_export + void TossItem(bool a_bDraggingItem, char a_Amount = 1, short a_CreateType = 0, short a_CreateHealth = 0); //tolua_export void Heal( int a_Health ); //tolua_export diff --git a/source/packets/cPacket.h b/source/packets/cPacket.h index bc0f052e8..580cd6771 100644 --- a/source/packets/cPacket.h +++ b/source/packets/cPacket.h @@ -52,15 +52,6 @@ public: return PACKET_ERROR; } - /// Called to serialize the packet into a string. Append all packet data to a_Data, including the packet type! - virtual void Serialize(AString & a_Data) const - { - // There are packets that are sent C->S only, those don't have a serializing function - UNUSED(a_Data); - LOGERROR("Packet type 0x%02x has no serializer defined!", m_PacketID); - ASSERT(!"Unserialized packet"); - } - virtual cPacket * Clone() const = 0; unsigned char m_PacketID; diff --git a/source/packets/cPacket_AddToInventory.cpp b/source/packets/cPacket_AddToInventory.cpp deleted file mode 100644 index b9231112c..000000000 --- a/source/packets/cPacket_AddToInventory.cpp +++ /dev/null @@ -1,20 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_AddToInventory.h" -#include "cPacket_WholeInventory.h" -#include "cPacket_ItemData.h" - - - - - -void cPacket_AddToInventory::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - cPacket_ItemData::AppendItem(a_Data, m_ItemType, m_Count, m_Life); -} - - - - diff --git a/source/packets/cPacket_AddToInventory.h b/source/packets/cPacket_AddToInventory.h deleted file mode 100644 index f7e1a084b..000000000 --- a/source/packets/cPacket_AddToInventory.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "cPacket.h" - -#include "../BlockID.h" - -class cPacket_AddToInventory : public cPacket -{ -public: - cPacket_AddToInventory() - : m_ItemType( E_ITEM_EMPTY ) - , m_Count( 0 ) - , m_Life( 0 ) - { m_PacketID = E_ADD_TO_INV; } - virtual cPacket* Clone() const { return new cPacket_AddToInventory(*this); } - - // _X: This was unimplemented, do we need it?: - // bool Parse( cSocket & a_Socket ); - - virtual void Serialize(AString & a_Data) const override; - - ENUM_ITEM_ID m_ItemType; - char m_Count; - short m_Life; - static const unsigned int c_Size = 1; -}; diff --git a/source/packets/cPacket_ArmAnim.cpp b/source/packets/cPacket_ArmAnim.cpp index 6f7a261d4..8d46da39f 100644 --- a/source/packets/cPacket_ArmAnim.cpp +++ b/source/packets/cPacket_ArmAnim.cpp @@ -18,14 +18,3 @@ int cPacket_ArmAnim::Parse(cByteBuffer & a_Buffer) - -void cPacket_ArmAnim::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_EntityID); - AppendByte (a_Data, m_Animation); -} - - - - diff --git a/source/packets/cPacket_ArmAnim.h b/source/packets/cPacket_ArmAnim.h index 2fa613b83..c4f4694ce 100644 --- a/source/packets/cPacket_ArmAnim.h +++ b/source/packets/cPacket_ArmAnim.h @@ -1,21 +1,30 @@ + #pragma once #include "cPacket.h" -class cPacket_ArmAnim : public cPacket + + + +class cPacket_ArmAnim : + public cPacket { public: cPacket_ArmAnim() : m_EntityID( 0 ) , m_Animation( 0 ) - { m_PacketID = E_ANIMATION; } + { + m_PacketID = E_ANIMATION; + } virtual cPacket* Clone() const { return new cPacket_ArmAnim(*this); } virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; int m_EntityID; char m_Animation; - static const unsigned int c_Size = 1 + 4 + 1; -}; \ No newline at end of file +}; + + + + diff --git a/source/packets/cPacket_BlockAction.cpp b/source/packets/cPacket_BlockAction.cpp deleted file mode 100644 index a4eb01ad8..000000000 --- a/source/packets/cPacket_BlockAction.cpp +++ /dev/null @@ -1,36 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_BlockAction.h" - - - - - -cPacket_BlockAction::cPacket_BlockAction( const cPacket_BlockAction & a_Copy ) -{ - m_PacketID = E_BLOCK_ACTION; - m_BlockX = a_Copy.m_BlockX; - m_BlockY = a_Copy.m_BlockY; - m_BlockZ = a_Copy.m_BlockZ; - m_Byte1 = a_Copy.m_Byte1; - m_Byte2 = a_Copy.m_Byte2; -} - - - - - -void cPacket_BlockAction::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_BlockX); - AppendShort (a_Data, m_BlockY); - AppendInteger(a_Data, m_BlockZ); - AppendByte (a_Data, m_Byte1); - AppendByte (a_Data, m_Byte2); -} - - - - diff --git a/source/packets/cPacket_BlockAction.h b/source/packets/cPacket_BlockAction.h deleted file mode 100644 index df473801f..000000000 --- a/source/packets/cPacket_BlockAction.h +++ /dev/null @@ -1,38 +0,0 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_BlockAction : - public cPacket -{ -public: - cPacket_BlockAction() - : m_BlockX( 0 ) - , m_BlockY( 0 ) - , m_BlockZ( 0 ) - , m_Byte1( 0 ) - , m_Byte2( 0 ) - { - m_PacketID = E_BLOCK_ACTION; - } - - cPacket_BlockAction( const cPacket_BlockAction & a_Copy ); - virtual cPacket * Clone() const { return new cPacket_BlockAction(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_BlockX; - short m_BlockY; - int m_BlockZ; - char m_Byte1; // Varies - char m_Byte2; // Varies -}; - - - - diff --git a/source/packets/cPacket_BlockChange.cpp b/source/packets/cPacket_BlockChange.cpp deleted file mode 100644 index e0ef5c001..000000000 --- a/source/packets/cPacket_BlockChange.cpp +++ /dev/null @@ -1,22 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_BlockChange.h" - - - - - -void cPacket_BlockChange::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_PosX); - AppendByte (a_Data, m_PosY); - AppendInteger(a_Data, m_PosZ); - AppendByte (a_Data, m_BlockType); - AppendByte (a_Data, m_BlockMeta); -} - - - - diff --git a/source/packets/cPacket_BlockChange.h b/source/packets/cPacket_BlockChange.h deleted file mode 100644 index 039043cf0..000000000 --- a/source/packets/cPacket_BlockChange.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "cPacket.h" - - -class cPacket_BlockChange : public cPacket -{ -public: - cPacket_BlockChange() - : m_PosX( 0 ) - , m_PosY( 0 ) - , m_PosZ( 0 ) - , m_BlockType( 0 ) - , m_BlockMeta( 0 ) - { m_PacketID = E_BLOCK_CHANGE; } - virtual cPacket* Clone() const { return new cPacket_BlockChange(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_PosX; - unsigned char m_PosY; - int m_PosZ; - char m_BlockType; - char m_BlockMeta; - - static const unsigned int c_Size = 1 + 4 + 1 + 4 + 1 + 1; -}; \ No newline at end of file diff --git a/source/packets/cPacket_BlockDig.cpp b/source/packets/cPacket_BlockDig.cpp index 0c90436dd..8c7cc5955 100644 --- a/source/packets/cPacket_BlockDig.cpp +++ b/source/packets/cPacket_BlockDig.cpp @@ -7,19 +7,6 @@ -void cPacket_BlockDig::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_PosX); - AppendByte (a_Data, m_PosY); - AppendInteger(a_Data, m_PosZ); - AppendByte (a_Data, m_Direction); -} - - - - - int cPacket_BlockDig::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; diff --git a/source/packets/cPacket_BlockDig.h b/source/packets/cPacket_BlockDig.h index 01eb54377..1678dcaf3 100644 --- a/source/packets/cPacket_BlockDig.h +++ b/source/packets/cPacket_BlockDig.h @@ -24,7 +24,6 @@ public: virtual cPacket* Clone() const { return new cPacket_BlockDig(*this); } virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; char m_Status; int m_PosX; diff --git a/source/packets/cPacket_Chat.cpp b/source/packets/cPacket_Chat.cpp index da00c0aae..b475848b0 100644 --- a/source/packets/cPacket_Chat.cpp +++ b/source/packets/cPacket_Chat.cpp @@ -17,13 +17,3 @@ int cPacket_Chat::Parse(cByteBuffer & a_Buffer) - -void cPacket_Chat::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendString16(a_Data, m_Message); -} - - - - diff --git a/source/packets/cPacket_Chat.h b/source/packets/cPacket_Chat.h index cb154f732..ff5c70b5b 100644 --- a/source/packets/cPacket_Chat.h +++ b/source/packets/cPacket_Chat.h @@ -1,20 +1,22 @@ + #pragma once #include "cPacket.h" -class cPacket_Chat : public cPacket + + + +class cPacket_Chat : + public cPacket { public: cPacket_Chat() { m_PacketID = E_CHAT; } - cPacket_Chat( const std::string & a_Message ) : m_Message( a_Message) { m_PacketID = E_CHAT; } virtual cPacket* Clone() const { return new cPacket_Chat(*this); } virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; AString m_Message; - static const unsigned int c_Size = 3; // Minimum size }; diff --git a/source/packets/cPacket_CollectItem.cpp b/source/packets/cPacket_CollectItem.cpp deleted file mode 100644 index 39f4cdde2..000000000 --- a/source/packets/cPacket_CollectItem.cpp +++ /dev/null @@ -1,19 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_CollectItem.h" - - - - - -void cPacket_CollectItem::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_CollectedID); - AppendInteger(a_Data, m_CollectorID); -} - - - - diff --git a/source/packets/cPacket_CollectItem.h b/source/packets/cPacket_CollectItem.h deleted file mode 100644 index 29ab78ff8..000000000 --- a/source/packets/cPacket_CollectItem.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_CollectItem : public cPacket -{ -public: - cPacket_CollectItem() - : m_CollectedID( 0 ) - , m_CollectorID( 0 ) - { m_PacketID = E_COLLECT_ITEM; } - virtual cPacket* Clone() const { return new cPacket_CollectItem(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_CollectedID; - int m_CollectorID; - static const unsigned int c_Size = 1 + 4 + 4; -}; - - - - diff --git a/source/packets/cPacket_CreativeInventoryAction.cpp b/source/packets/cPacket_CreativeInventoryAction.cpp index 85291da3e..41a45125b 100644 --- a/source/packets/cPacket_CreativeInventoryAction.cpp +++ b/source/packets/cPacket_CreativeInventoryAction.cpp @@ -38,14 +38,3 @@ int cPacket_CreativeInventoryAction::Parse(cByteBuffer & a_Buffer) -void cPacket_CreativeInventoryAction::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendShort(a_Data, m_SlotNum); - - cPacket_ItemData::AppendItem(a_Data, m_ClickedItem); -} - - - - diff --git a/source/packets/cPacket_CreativeInventoryAction.h b/source/packets/cPacket_CreativeInventoryAction.h index ae438a7a8..885478496 100644 --- a/source/packets/cPacket_CreativeInventoryAction.h +++ b/source/packets/cPacket_CreativeInventoryAction.h @@ -22,7 +22,6 @@ public: virtual cPacket* Clone() const { return new cPacket_CreativeInventoryAction(*this); } virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; short m_SlotNum; cItem m_ClickedItem; diff --git a/source/packets/cPacket_DestroyEntity.cpp b/source/packets/cPacket_DestroyEntity.cpp deleted file mode 100644 index d7e1d085b..000000000 --- a/source/packets/cPacket_DestroyEntity.cpp +++ /dev/null @@ -1,30 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_DestroyEntity.h" -#include "../cEntity.h" - - - - - -cPacket_DestroyEntity::cPacket_DestroyEntity(cEntity* a_Entity) -{ - m_PacketID = E_DESTROY_ENT; - - m_UniqueID = a_Entity->GetUniqueID(); -} - - - - - -void cPacket_DestroyEntity::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); -} - - - - diff --git a/source/packets/cPacket_DestroyEntity.h b/source/packets/cPacket_DestroyEntity.h deleted file mode 100644 index b4146e971..000000000 --- a/source/packets/cPacket_DestroyEntity.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include "cPacket.h" - - - - - -class cEntity; - - - - - -class cPacket_DestroyEntity : public cPacket -{ -public: - cPacket_DestroyEntity() - : m_UniqueID( 0 ) - { m_PacketID = E_DESTROY_ENT; } - cPacket_DestroyEntity(cEntity* a_Entity); - virtual cPacket* Clone() const { return new cPacket_DestroyEntity(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - - static const unsigned int c_Size = 1 + 4; -}; - - - - diff --git a/source/packets/cPacket_Disconnect.cpp b/source/packets/cPacket_Disconnect.cpp index 19eecd365..d1d433475 100644 --- a/source/packets/cPacket_Disconnect.cpp +++ b/source/packets/cPacket_Disconnect.cpp @@ -18,12 +18,3 @@ int cPacket_Disconnect::Parse(cByteBuffer & a_Buffer) -void cPacket_Disconnect::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendString16(a_Data, m_Reason); -} - - - - diff --git a/source/packets/cPacket_Disconnect.h b/source/packets/cPacket_Disconnect.h index f2a820607..77b6cf615 100644 --- a/source/packets/cPacket_Disconnect.h +++ b/source/packets/cPacket_Disconnect.h @@ -15,7 +15,6 @@ public: virtual cPacket* Clone() const { return new cPacket_Disconnect(*this); } virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; AString m_Reason; static const unsigned int c_Size = 3; // Minimum size diff --git a/source/packets/cPacket_EntityEquipment.cpp b/source/packets/cPacket_EntityEquipment.cpp deleted file mode 100644 index 6358c4a1f..000000000 --- a/source/packets/cPacket_EntityEquipment.cpp +++ /dev/null @@ -1,48 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_EntityEquipment.h" - - - - - -cPacket_EntityEquipment::cPacket_EntityEquipment( const cPacket_EntityEquipment & a_Copy ) -{ - 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; -} - - - - - -int cPacket_EntityEquipment::Parse(cByteBuffer & a_Buffer) -{ - int TotalBytes = 0; - 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; -} - - - - - -void cPacket_EntityEquipment::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); - 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 deleted file mode 100644 index 69260fae4..000000000 --- a/source/packets/cPacket_EntityEquipment.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_EntityEquipment : public cPacket -{ -public: - cPacket_EntityEquipment() - : m_UniqueID( 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 int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - short m_SlotNum; // 0 = hold 1-4 = armor - short m_ItemType; - short m_ItemDamage; -}; - - - - diff --git a/source/packets/cPacket_EntityLook.cpp b/source/packets/cPacket_EntityLook.cpp deleted file mode 100644 index 04fc46d4d..000000000 --- a/source/packets/cPacket_EntityLook.cpp +++ /dev/null @@ -1,64 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_EntityLook.h" - -#include "../cEntity.h" - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cPacket_EntityLook: - -cPacket_EntityLook::cPacket_EntityLook(const cEntity & a_Entity) -{ - m_PacketID = E_ENT_LOOK; - - m_UniqueID = a_Entity.GetUniqueID(); - m_Rotation = (char)((a_Entity.GetRotation() / 360.f) * 256); - m_Pitch = (char)((a_Entity.GetPitch() / 360.f) * 256); -} - - - - - -void cPacket_EntityLook::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); - AppendByte (a_Data, m_Rotation); - AppendByte (a_Data, m_Pitch); -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// cPacket_EntityHeadLook: - -cPacket_EntityHeadLook::cPacket_EntityHeadLook(const cEntity & a_Entity) -{ - m_PacketID = E_ENT_HEAD_LOOK; - - m_UniqueID = a_Entity.GetUniqueID(); - m_HeadYaw = (char)((a_Entity.GetRotation() / 360.f) * 256); -} - - - - - -void cPacket_EntityHeadLook::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); - AppendByte (a_Data, m_HeadYaw); -} - - - - diff --git a/source/packets/cPacket_EntityLook.h b/source/packets/cPacket_EntityLook.h deleted file mode 100644 index 463faccda..000000000 --- a/source/packets/cPacket_EntityLook.h +++ /dev/null @@ -1,62 +0,0 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cEntity; - - - - - -class cPacket_EntityLook : - public cPacket -{ -public: - cPacket_EntityLook(void) - : m_UniqueID( 0 ) - , m_Rotation( 0 ) - , m_Pitch( 0 ) - { m_PacketID = E_ENT_LOOK; } - cPacket_EntityLook(const cEntity & a_Entity); - virtual cPacket* Clone(void) const { return new cPacket_EntityLook(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - char m_Rotation; - char m_Pitch; -}; - - - - - -class cPacket_EntityHeadLook : - public cPacket -{ -public: - cPacket_EntityHeadLook(void) - : m_UniqueID( 0 ) - , m_HeadYaw( 0 ) - { - m_PacketID = E_ENT_LOOK; - } - - cPacket_EntityHeadLook(const cEntity & a_Entity); - - virtual cPacket * Clone(void) const { return new cPacket_EntityHeadLook(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - char m_HeadYaw; -}; - - - - diff --git a/source/packets/cPacket_EntityStatus.cpp b/source/packets/cPacket_EntityStatus.cpp deleted file mode 100644 index 1ea468a51..000000000 --- a/source/packets/cPacket_EntityStatus.cpp +++ /dev/null @@ -1,19 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_EntityStatus.h" - - - - - -void cPacket_EntityStatus::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); - AppendByte (a_Data, m_Status); -} - - - - diff --git a/source/packets/cPacket_EntityStatus.h b/source/packets/cPacket_EntityStatus.h deleted file mode 100644 index ecacd03c5..000000000 --- a/source/packets/cPacket_EntityStatus.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_EntityStatus : public cPacket -{ -public: - cPacket_EntityStatus() - : m_UniqueID( 0 ) - , m_Status( 0 ) - { m_PacketID = E_ENT_STATUS; } - virtual cPacket* Clone() const { return new cPacket_EntityStatus( *this ); } - - virtual void Serialize(AString & a_Data) const override; - - static const char STATUS_TAKEDAMAGE = 2; - static const char STATUS_DIE = 3; - - int m_UniqueID; - char m_Status; - - static const unsigned int c_Size = 1 + 4 + 1; -}; - - - - diff --git a/source/packets/cPacket_Explosion.h b/source/packets/cPacket_Explosion.h index 5121c9175..468d72fe4 100644 --- a/source/packets/cPacket_Explosion.h +++ b/source/packets/cPacket_Explosion.h @@ -22,7 +22,7 @@ public: ~cPacket_Explosion(); virtual cPacket* Clone() const { return new cPacket_Explosion(*this); } - virtual void Serialize(AString & a_Data) const override; + virtual void Serialize(AString & a_Data) const; double m_PosX; // The entity ID of the thunderbolt double m_PosY; // Always true. Might have a meaning in the future... diff --git a/source/packets/cPacket_Handshake.cpp b/source/packets/cPacket_Handshake.cpp index 76d04883c..5229cdba3 100644 --- a/source/packets/cPacket_Handshake.cpp +++ b/source/packets/cPacket_Handshake.cpp @@ -17,13 +17,3 @@ int cPacket_Handshake::Parse(cByteBuffer & a_Buffer) - -void cPacket_Handshake::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendString16(a_Data, m_Username); -} - - - - diff --git a/source/packets/cPacket_Handshake.h b/source/packets/cPacket_Handshake.h index 0ddddb1c1..86bc8a286 100644 --- a/source/packets/cPacket_Handshake.h +++ b/source/packets/cPacket_Handshake.h @@ -14,7 +14,6 @@ public: virtual cPacket* Clone() const { return new cPacket_Handshake(*this); } virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; std::string m_Username; }; diff --git a/source/packets/cPacket_InventoryProgressBar.cpp b/source/packets/cPacket_InventoryProgressBar.cpp deleted file mode 100644 index 61541c8e9..000000000 --- a/source/packets/cPacket_InventoryProgressBar.cpp +++ /dev/null @@ -1,20 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_InventoryProgressBar.h" - - - - - -void cPacket_InventoryProgressBar::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendByte (a_Data, m_WindowID); - AppendShort(a_Data, m_ProgressBar); - AppendShort(a_Data, m_Value); -} - - - - diff --git a/source/packets/cPacket_InventoryProgressBar.h b/source/packets/cPacket_InventoryProgressBar.h deleted file mode 100644 index b78205efa..000000000 --- a/source/packets/cPacket_InventoryProgressBar.h +++ /dev/null @@ -1,32 +0,0 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_InventoryProgressBar : public cPacket -{ -public: - cPacket_InventoryProgressBar() - : m_WindowID( 0 ) - , m_ProgressBar( 0 ) - , m_Value( 0 ) - { - m_PacketID = E_INVENTORY_PROGRESS; - } - - virtual cPacket * Clone() const { return new cPacket_InventoryProgressBar(*this); } - - virtual void Serialize(AString & a_Data) const override; - - char m_WindowID; - short m_ProgressBar; - short m_Value; -}; - - - - diff --git a/source/packets/cPacket_InventorySlot.cpp b/source/packets/cPacket_InventorySlot.cpp deleted file mode 100644 index 5bf247541..000000000 --- a/source/packets/cPacket_InventorySlot.cpp +++ /dev/null @@ -1,23 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_InventorySlot.h" -#include "cPacket_WholeInventory.h" -#include "cPacket_ItemData.h" - - - - - -void cPacket_InventorySlot::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendByte (a_Data, m_WindowID); - AppendShort(a_Data, m_SlotNum); - - cPacket_ItemData::AppendItem(a_Data, m_ItemID, m_ItemCount, m_ItemUses); -} - - - - diff --git a/source/packets/cPacket_InventorySlot.h b/source/packets/cPacket_InventorySlot.h deleted file mode 100644 index 3f9fdc13f..000000000 --- a/source/packets/cPacket_InventorySlot.h +++ /dev/null @@ -1,44 +0,0 @@ - -#pragma once - -#include "cPacket.h" - -#include "../BlockID.h" - - - - - -class cPacket_InventorySlot : public cPacket // Set item [S -> C] ? -{ -public: - cPacket_InventorySlot() - : m_WindowID( 0 ) - , m_SlotNum( 0 ) - , m_ItemID( E_ITEM_EMPTY ) - , m_ItemCount( 0 ) - , m_ItemUses( 0 ) - { m_PacketID = E_INVENTORY_SLOT; } - virtual cPacket* Clone() const { return new cPacket_InventorySlot(*this); } - - virtual void Serialize(AString & a_Data) const override; - - char m_WindowID; - short m_SlotNum; // Slot - // 0 = craft result - // 1-4 = crafting table - // 5-8 = armor - // 9-35 = inventory - // 36-44 = Hot bar - - // Below = item - short m_ItemID; // if this is -1 the next stuff dont exist - char m_ItemCount; - short m_ItemUses; - - static const unsigned int c_Size = 1 + 1 + 2; // Minimal size ( +1+1 = max) -}; - - - - diff --git a/source/packets/cPacket_ItemSwitch.cpp b/source/packets/cPacket_ItemSwitch.cpp index 3ea9d26c2..864214a66 100644 --- a/source/packets/cPacket_ItemSwitch.cpp +++ b/source/packets/cPacket_ItemSwitch.cpp @@ -17,13 +17,3 @@ int cPacket_ItemSwitch::Parse(cByteBuffer & a_Buffer) - -void cPacket_ItemSwitch::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendShort(a_Data, m_SlotNum); -} - - - - diff --git a/source/packets/cPacket_ItemSwitch.h b/source/packets/cPacket_ItemSwitch.h index 1b0323ea6..667b24044 100644 --- a/source/packets/cPacket_ItemSwitch.h +++ b/source/packets/cPacket_ItemSwitch.h @@ -16,11 +16,8 @@ public: virtual cPacket* Clone() const { return new cPacket_ItemSwitch(*this); } virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; short m_SlotNum; - - static const unsigned int c_Size = 1 + 2; }; diff --git a/source/packets/cPacket_KeepAlive.cpp b/source/packets/cPacket_KeepAlive.cpp index 0dc9302b3..090e90671 100644 --- a/source/packets/cPacket_KeepAlive.cpp +++ b/source/packets/cPacket_KeepAlive.cpp @@ -7,16 +7,6 @@ -void cPacket_KeepAlive::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_KeepAliveID); -} - - - - - int cPacket_KeepAlive::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; diff --git a/source/packets/cPacket_KeepAlive.h b/source/packets/cPacket_KeepAlive.h index c3b9d0587..b68aa5691 100644 --- a/source/packets/cPacket_KeepAlive.h +++ b/source/packets/cPacket_KeepAlive.h @@ -14,8 +14,7 @@ public: cPacket_KeepAlive(int a_PingID) { m_KeepAliveID = a_PingID; } virtual cPacket * Clone() const { return new cPacket_KeepAlive(*this); } - virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; + virtual int Parse(cByteBuffer & a_Buffer) override; int m_KeepAliveID; }; diff --git a/source/packets/cPacket_Login.cpp b/source/packets/cPacket_Login.cpp index b19e389d1..017227071 100644 --- a/source/packets/cPacket_Login.cpp +++ b/source/packets/cPacket_Login.cpp @@ -32,20 +32,3 @@ int cPacket_Login::Parse(cByteBuffer & a_Buffer) - -void cPacket_Login::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger (a_Data, m_ProtocolVersion); - AppendString16(a_Data, m_Username); - AppendString16(a_Data, m_LevelType); - AppendInteger (a_Data, m_ServerMode); - AppendInteger (a_Data, m_Dimension); - AppendByte (a_Data, m_Difficulty); - AppendByte (a_Data, m_WorldHeight); - AppendByte (a_Data, m_MaxPlayers); -} - - - - diff --git a/source/packets/cPacket_Login.h b/source/packets/cPacket_Login.h index a93d2807e..df7545edd 100644 --- a/source/packets/cPacket_Login.h +++ b/source/packets/cPacket_Login.h @@ -22,7 +22,6 @@ public: virtual cPacket* Clone() const { return new cPacket_Login(*this); } virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; int m_ProtocolVersion; AString m_Username; diff --git a/source/packets/cPacket_MapChunk.cpp b/source/packets/cPacket_MapChunk.cpp deleted file mode 100644 index 17fbdba24..000000000 --- a/source/packets/cPacket_MapChunk.cpp +++ /dev/null @@ -1,34 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_MapChunk.h" -#include "../ChunkDef.h" - - - - - -cPacket_MapChunk::cPacket_MapChunk(int a_ChunkX, int a_ChunkZ, const AString & a_SerializedData) : - m_PosX(a_ChunkX), - m_PosZ(a_ChunkZ), - m_SerializedData(a_SerializedData) -{ - m_PacketID = E_MAP_CHUNK; -} - - - - - -void cPacket_MapChunk::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - - AppendInteger(a_Data, m_PosX); - AppendInteger(a_Data, m_PosZ); - a_Data.append(m_SerializedData); -} - - - - diff --git a/source/packets/cPacket_MapChunk.h b/source/packets/cPacket_MapChunk.h deleted file mode 100644 index 35b5de08f..000000000 --- a/source/packets/cPacket_MapChunk.h +++ /dev/null @@ -1,34 +0,0 @@ - -#pragma once - -#include "cPacket.h" -#include "../ChunkDef.h" - - - - - -class cPacket_MapChunk : - public cPacket -{ -public: - cPacket_MapChunk() - : m_PosX( 0 ) - , m_PosZ( 0 ) - { - m_PacketID = E_MAP_CHUNK; - } - - cPacket_MapChunk(int a_ChunkX, int a_ChunkZ, const AString & a_SerializedData); - virtual cPacket* Clone() const { return new cPacket_MapChunk(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_PosX; - int m_PosZ; - AString m_SerializedData; -}; - - - - diff --git a/source/packets/cPacket_Metadata.cpp b/source/packets/cPacket_Metadata.cpp deleted file mode 100644 index 595801b54..000000000 --- a/source/packets/cPacket_Metadata.cpp +++ /dev/null @@ -1,110 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_Metadata.h" - - - - - -cPacket_Metadata::cPacket_Metadata(int s, int id) - : m_EMetaData( (cPawn::MetaData)s ) - , m_UniqueID( id ) - , m_Type( 0 ) - , m_MetaData( 0 ) -{ - m_PacketID = E_METADATA; - FormPacket(); -} - - - - - -cPacket_Metadata::cPacket_Metadata() - : m_UniqueID( 0 ) - , m_Type( 0 ) - , m_MetaData( 0 ) -{ - m_PacketID = E_METADATA; - m_EMetaData = cPawn::NORMAL; - FormPacket(); -} - - - - - -cPacket_Metadata::cPacket_Metadata(const cPacket_Metadata & a_Other) - : m_EMetaData( a_Other.m_EMetaData ) - , m_UniqueID( a_Other.m_UniqueID ) - , m_Type( a_Other.m_Type ) - , m_MetaData( NULL ) -{ - m_PacketID = E_METADATA; - FormPacket(); -} - - - - - -cPacket_Metadata::~cPacket_Metadata() -{ - delete [] m_MetaData; -} - - - - - -void cPacket_Metadata::FormPacket() -{ - delete [] m_MetaData; - m_MetaData = new char[3]; - m_MetaDataSize = 3; - // m_UniqueID = GetUniqueID(); - m_MetaData[0] = 0x00; - - m_MetaData[2] = 0x7f; - switch(m_EMetaData) - { - case cPawn::NORMAL: - m_MetaData[1] = 0x00; - break; - case cPawn::BURNING: - m_MetaData[1] = 0x01; - break; - case cPawn::CROUCHED: - m_MetaData[1] = 0x02; - break; - case cPawn::RIDING: - m_MetaData[1] = 0x04; - break; - case cPawn::SPRINTING: - m_MetaData[1] = 0x08; - break; - case cPawn::EATING: - case cPawn::BLOCKING: - m_MetaData[1] = 0x10; - break; - default: - m_MetaData[1] = 0x00; - break; - } -} - - - - - -void cPacket_Metadata::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); - AppendData (a_Data, m_MetaData, m_MetaDataSize); -} - - - - diff --git a/source/packets/cPacket_Metadata.h b/source/packets/cPacket_Metadata.h deleted file mode 100644 index 24818e379..000000000 --- a/source/packets/cPacket_Metadata.h +++ /dev/null @@ -1,35 +0,0 @@ - -#pragma once -#include "cPacket.h" - -#include "../cPawn.h" - - - - - -class cPacket_Metadata : public cPacket -{ -public: - cPacket_Metadata(int s, int id); - cPacket_Metadata(); - cPacket_Metadata(const cPacket_Metadata & a_Other); - ~cPacket_Metadata(); - - virtual void Serialize(AString & a_Data) const override; - - void FormPacket(); - virtual cPacket* Clone() const { return new cPacket_Metadata( *this ); } - - cPawn::MetaData m_EMetaData; - - static const unsigned int c_Size = 4 + 1; - int m_UniqueID; - char m_Type; - unsigned int m_MetaDataSize; - char* m_MetaData; -}; - - - - diff --git a/source/packets/cPacket_NamedEntitySpawn.cpp b/source/packets/cPacket_NamedEntitySpawn.cpp deleted file mode 100644 index 798376372..000000000 --- a/source/packets/cPacket_NamedEntitySpawn.cpp +++ /dev/null @@ -1,34 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_NamedEntitySpawn.h" - - - - - -void cPacket_NamedEntitySpawn::Serialize(AString & a_Data) const -{ - short CurrentItem = m_CurrentItem; - ASSERT(CurrentItem >= 0); - if (CurrentItem <= 0) - { - CurrentItem = 0; - // Fix, to make sure no invalid values are sent. - // WARNING: HERE ITS 0, BUT IN EQUIP PACKET ITS -1 !! - } - - AppendByte (a_Data, m_PacketID); - AppendInteger (a_Data, m_UniqueID); - AppendString16(a_Data, m_PlayerName); - AppendInteger (a_Data, m_PosX); - AppendInteger (a_Data, m_PosY); - AppendInteger (a_Data, m_PosZ); - AppendByte (a_Data, m_Rotation); - AppendByte (a_Data, m_Pitch); - AppendShort (a_Data, CurrentItem); -} - - - - diff --git a/source/packets/cPacket_NamedEntitySpawn.h b/source/packets/cPacket_NamedEntitySpawn.h deleted file mode 100644 index 365d28c37..000000000 --- a/source/packets/cPacket_NamedEntitySpawn.h +++ /dev/null @@ -1,40 +0,0 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_NamedEntitySpawn : public cPacket -{ -public: - cPacket_NamedEntitySpawn() - : m_UniqueID( 0 ) - , m_PosX( 0 ) - , m_PosY( 0 ) - , m_PosZ( 0 ) - , m_Rotation( 0 ) - , m_Pitch( 0 ) - , m_CurrentItem( 0 ) - { m_PacketID = E_NAMED_ENTITY_SPAWN; } - virtual cPacket* Clone() const { return new cPacket_NamedEntitySpawn(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - AString m_PlayerName; - int m_PosX; // Pixel position, devide by 32 for block position - int m_PosY; - int m_PosZ; - char m_Rotation; - char m_Pitch; - short m_CurrentItem; - - static const unsigned int c_Size = 1 + 4 + 2 + 4 + 4 + 4 + 1 + 1 + 2; // Minimum size -}; - - - - diff --git a/source/packets/cPacket_NewInvalidState.cpp b/source/packets/cPacket_NewInvalidState.cpp deleted file mode 100644 index 3e44a4877..000000000 --- a/source/packets/cPacket_NewInvalidState.cpp +++ /dev/null @@ -1,42 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_NewInvalidState.h" - - - - - -cPacket_NewInvalidState::cPacket_NewInvalidState( const cPacket_NewInvalidState & a_Copy ) -{ - m_PacketID = E_NEW_INVALID_STATE; - m_Reason = a_Copy.m_Reason; - m_GameMode = a_Copy.m_GameMode; -} - - - - - -int cPacket_NewInvalidState::Parse(cByteBuffer & a_Buffer) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadChar, m_Reason, TotalBytes); - HANDLE_PACKET_READ(ReadChar, m_GameMode, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_NewInvalidState::Serialize(AString & a_Data) const -{ - AppendByte(a_Data, m_PacketID); - AppendByte(a_Data, m_Reason); - AppendByte(a_Data, m_GameMode); -} - - - - diff --git a/source/packets/cPacket_NewInvalidState.h b/source/packets/cPacket_NewInvalidState.h deleted file mode 100644 index 6bfacd17c..000000000 --- a/source/packets/cPacket_NewInvalidState.h +++ /dev/null @@ -1,31 +0,0 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_NewInvalidState : public cPacket -{ -public: - cPacket_NewInvalidState() - : m_Reason( 0 ) - , m_GameMode( 0 ) - { m_PacketID = E_NEW_INVALID_STATE;} - cPacket_NewInvalidState( const cPacket_NewInvalidState & a_Copy ); - virtual cPacket* Clone() const { return new cPacket_NewInvalidState(*this); } - - virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; - - char m_Reason; // 0 = Invalid Bed, 1 = Begin Raining, 2 End Raining, 3 = Change Gamemode - char m_GameMode; // Used only when reason = 3. 0 is survival, 1 is creative. - - static const unsigned int c_Size = 1 + 1 + 1; -}; - - - - diff --git a/source/packets/cPacket_PickupSpawn.cpp b/source/packets/cPacket_PickupSpawn.cpp deleted file mode 100644 index 1d937cd6c..000000000 --- a/source/packets/cPacket_PickupSpawn.cpp +++ /dev/null @@ -1,47 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_PickupSpawn.h" - - - - - -int cPacket_PickupSpawn::Parse(cByteBuffer & a_Buffer) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadBEInt, m_UniqueID, TotalBytes); - HANDLE_PACKET_READ(ReadBEShort, m_ItemType, TotalBytes); - HANDLE_PACKET_READ(ReadChar, m_ItemCount, TotalBytes); - HANDLE_PACKET_READ(ReadBEShort, m_ItemDamage, TotalBytes); - HANDLE_PACKET_READ(ReadBEInt, m_PosX, TotalBytes); - HANDLE_PACKET_READ(ReadBEInt, m_PosY, TotalBytes); - HANDLE_PACKET_READ(ReadBEInt, m_PosZ, TotalBytes); - HANDLE_PACKET_READ(ReadChar, m_Rotation, TotalBytes); - HANDLE_PACKET_READ(ReadChar, m_Pitch, TotalBytes); - HANDLE_PACKET_READ(ReadChar, m_Roll, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_PickupSpawn::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); - AppendShort (a_Data, m_ItemType); - AppendByte (a_Data, m_ItemCount); - AppendShort (a_Data, m_ItemDamage); - AppendInteger(a_Data, m_PosX); - AppendInteger(a_Data, m_PosY); - AppendInteger(a_Data, m_PosZ); - AppendByte (a_Data, m_Rotation); - AppendByte (a_Data, m_Pitch); - AppendByte (a_Data, m_Roll); -} - - - - diff --git a/source/packets/cPacket_PickupSpawn.h b/source/packets/cPacket_PickupSpawn.h deleted file mode 100644 index 91bbba65e..000000000 --- a/source/packets/cPacket_PickupSpawn.h +++ /dev/null @@ -1,47 +0,0 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_PickupSpawn : public cPacket -{ -public: - cPacket_PickupSpawn() - : m_UniqueID( 0 ) - , m_ItemType( 0 ) - , m_ItemCount( 0 ) - , m_ItemDamage( 0 ) - , m_PosX( 0 ) - , m_PosY( 0 ) - , m_PosZ( 0 ) - , m_Rotation( 0 ) - , m_Pitch( 0 ) - , m_Roll( 0 ) - { - m_PacketID = E_PICKUP_SPAWN; - } - - virtual cPacket* Clone() const { return new cPacket_PickupSpawn(*this); } - - virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - short m_ItemType; - char m_ItemCount; - short m_ItemDamage; - int m_PosX; - int m_PosY; - int m_PosZ; - char m_Rotation; - char m_Pitch; - char m_Roll; -}; - - - - diff --git a/source/packets/cPacket_Player.cpp b/source/packets/cPacket_Player.cpp index bcfcbfee6..d0acc17d0 100644 --- a/source/packets/cPacket_Player.cpp +++ b/source/packets/cPacket_Player.cpp @@ -36,21 +36,6 @@ int cPacket_PlayerAbilities::Parse(cByteBuffer & a_Buffer) -void cPacket_PlayerAbilities::Serialize(AString & a_Data) const -{ - char Data[5]; - Data[0] = m_PacketID; - Data[1] = (char)m_Invulnerable; - Data[2] = (char)m_IsFlying; - Data[3] = (char)m_CanFly; - Data[4] = (char)m_InstaMine; - a_Data.append(Data, 5); -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cPacket_PlayerListItem: @@ -79,28 +64,6 @@ int cPacket_PlayerListItem::Parse(cByteBuffer & a_Buffer) -void cPacket_PlayerListItem::Serialize(AString & a_Data) const -{ - AString PlayerName(m_PlayerName); - if (PlayerName.length() > 16) - { - PlayerName.erase(16); - } - else if (PlayerName.length() <= 14) - { - PlayerName += cChatColor::White; - } - - AppendByte (a_Data, m_PacketID); - AppendString16(a_Data, PlayerName); - AppendBool (a_Data, m_Online); - AppendShort (a_Data, m_Ping); -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cPacket_PlayerLook: @@ -129,17 +92,6 @@ int cPacket_PlayerLook::Parse(cByteBuffer & a_Buffer) -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_IsOnGround); -} - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cPacket_PlayerMoveLook: @@ -179,26 +131,6 @@ int cPacket_PlayerMoveLook::Parse(cByteBuffer & a_Buffer) -void cPacket_PlayerMoveLook::Serialize(AString & a_Data) const -{ - // NOTE that Stance and Y are swapped when sent C->S vs S->C - // This is the S->C case: - // LOGD("Send PML: {%0.2f, %0.2f, %0.2f}, Stance: %0.2f, Gnd: %d", m_PosX, m_PosY, m_PosZ, m_Stance, m_IsOnGround ? 1 : 0); - - AppendByte (a_Data, m_PacketID); - AppendDouble(a_Data, m_PosX); - AppendDouble(a_Data, m_Stance); - AppendDouble(a_Data, m_PosY); - AppendDouble(a_Data, m_PosZ); - AppendFloat (a_Data, m_Rotation); - AppendFloat (a_Data, m_Pitch); - AppendBool (a_Data, m_IsOnGround); -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cPacket_PlayerPosition: @@ -232,22 +164,3 @@ int cPacket_PlayerPosition::Parse(cByteBuffer & a_Buffer) - -void cPacket_PlayerPosition::Serialize(AString & a_Data) const -{ - LOGD("Ignore send PlayerPos"); - /* - LOGD("Send PlayerPos: {%0.2f %0.2f %0.2f}, Stance %0.2f, Gnd: %d", m_PosX, m_PosY, m_PosZ, m_Stance, m_IsOnGround ? 1 : 0); - // _X: This should not get sent to the client at all - http://wiki.vg/wiki/index.php?title=Protocol&oldid=2513#Player_Position_.280x0B.29 - AppendByte (a_Data, m_PacketID); - AppendDouble (a_Data, m_PosX); - AppendDouble (a_Data, m_PosY); - AppendDouble (a_Data, m_Stance); - AppendDouble (a_Data, m_PosZ); - AppendBool (a_Data, m_IsOnGround); - */ -} - - - - diff --git a/source/packets/cPacket_Player.h b/source/packets/cPacket_Player.h index 9d80eedc9..1a647a5fc 100644 --- a/source/packets/cPacket_Player.h +++ b/source/packets/cPacket_Player.h @@ -34,7 +34,6 @@ public: cPacket_PlayerAbilities(void) { m_PacketID = E_PLAYER_LIST_ITEM; } virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; virtual cPacket * Clone() const { return new cPacket_PlayerAbilities(*this); } @@ -55,7 +54,6 @@ public: cPacket_PlayerListItem(const AString & a_PlayerName, bool a_Online, short a_Ping); virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; virtual cPacket* Clone() const { return new cPacket_PlayerListItem(*this); } @@ -83,7 +81,6 @@ public: virtual cPacket* Clone() const { return new cPacket_PlayerLook(*this); } virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; float m_Rotation; float m_Pitch; @@ -112,8 +109,7 @@ public: cPacket_PlayerMoveLook(const cPlayer & a_Player); virtual cPacket * Clone() const { return new cPacket_PlayerMoveLook(*this); } - virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; + virtual int Parse(cByteBuffer & a_Buffer) override; double m_PosX; double m_PosY; @@ -142,7 +138,6 @@ public: virtual cPacket* Clone() const { return new cPacket_PlayerPosition(*this); } virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; double m_PosX; double m_PosY; diff --git a/source/packets/cPacket_PreChunk.cpp b/source/packets/cPacket_PreChunk.cpp deleted file mode 100644 index f7824bba2..000000000 --- a/source/packets/cPacket_PreChunk.cpp +++ /dev/null @@ -1,20 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_PreChunk.h" - - - - - -void cPacket_PreChunk::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_PosX); - AppendInteger(a_Data, m_PosZ); - AppendBool (a_Data, m_bLoad); -} - - - - diff --git a/source/packets/cPacket_PreChunk.h b/source/packets/cPacket_PreChunk.h deleted file mode 100644 index 902fa2a02..000000000 --- a/source/packets/cPacket_PreChunk.h +++ /dev/null @@ -1,36 +0,0 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_PreChunk: public cPacket -{ -public: - cPacket_PreChunk() - : m_PosX( 0 ) - , m_PosZ( 0 ) - , m_bLoad( false ) - { m_PacketID = E_PRE_CHUNK; } - cPacket_PreChunk( int a_PosX, int a_PosZ, bool a_bLoad ) - : m_PosX( a_PosX ) - , m_PosZ( a_PosZ ) - , m_bLoad( a_bLoad ) - { m_PacketID = E_PRE_CHUNK; } - virtual cPacket* Clone() const { return new cPacket_PreChunk(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_PosX; - int m_PosZ; - bool m_bLoad; - - static const unsigned int c_Size = 10; -}; - - - - diff --git a/source/packets/cPacket_RelativeEntityMove.cpp b/source/packets/cPacket_RelativeEntityMove.cpp deleted file mode 100644 index de3746024..000000000 --- a/source/packets/cPacket_RelativeEntityMove.cpp +++ /dev/null @@ -1,21 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_RelativeEntityMove.h" - - - - - -void cPacket_RelativeEntityMove::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); - AppendByte (a_Data, m_MoveX); - AppendByte (a_Data, m_MoveY); - AppendByte (a_Data, m_MoveZ); -} - - - - diff --git a/source/packets/cPacket_RelativeEntityMove.h b/source/packets/cPacket_RelativeEntityMove.h deleted file mode 100644 index 7dd2cbdbc..000000000 --- a/source/packets/cPacket_RelativeEntityMove.h +++ /dev/null @@ -1,33 +0,0 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_RelativeEntityMove : public cPacket -{ -public: - cPacket_RelativeEntityMove() - : m_UniqueID( 0 ) - , m_MoveX( 0 ) - , m_MoveY( 0 ) - , m_MoveZ( 0 ) - { m_PacketID = E_REL_ENT_MOVE; } - virtual cPacket* Clone() const { return new cPacket_RelativeEntityMove(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - char m_MoveX; // Pixels, devide by 32 for block - char m_MoveY; - char m_MoveZ; - - static const unsigned int c_Size = 1 + 4 + 1 + 1 + 1; -}; - - - - diff --git a/source/packets/cPacket_RelativeEntityMoveLook.cpp b/source/packets/cPacket_RelativeEntityMoveLook.cpp deleted file mode 100644 index fad2c0620..000000000 --- a/source/packets/cPacket_RelativeEntityMoveLook.cpp +++ /dev/null @@ -1,24 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_RelativeEntityMoveLook.h" - - - - - -void cPacket_RelativeEntityMoveLook::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); - AppendByte (a_Data, m_MoveX); - AppendByte (a_Data, m_MoveY); - AppendByte (a_Data, m_MoveZ); - AppendByte (a_Data, m_Yaw); - AppendByte (a_Data, m_Pitch); -} - - - - - diff --git a/source/packets/cPacket_RelativeEntityMoveLook.h b/source/packets/cPacket_RelativeEntityMoveLook.h deleted file mode 100644 index 8fa6bf015..000000000 --- a/source/packets/cPacket_RelativeEntityMoveLook.h +++ /dev/null @@ -1,37 +0,0 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_RelativeEntityMoveLook : public cPacket -{ -public: - cPacket_RelativeEntityMoveLook() - : m_UniqueID( 0 ) - , m_MoveX( 0 ) - , m_MoveY( 0 ) - , m_MoveZ( 0 ) - , m_Yaw( 0 ) - , m_Pitch( 0 ) - { m_PacketID = E_REL_ENT_MOVE_LOOK; } - virtual cPacket* Clone() const { return new cPacket_RelativeEntityMoveLook(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - char m_MoveX; // Pixels, divide by 32 for block - char m_MoveY; - char m_MoveZ; - char m_Yaw; - char m_Pitch; - - static const unsigned int c_Size = 1 + 4 + 1 + 1 + 1 + 1 + 1; -}; - - - - diff --git a/source/packets/cPacket_Respawn.cpp b/source/packets/cPacket_Respawn.cpp index 94c757003..0e46ea01e 100644 --- a/source/packets/cPacket_Respawn.cpp +++ b/source/packets/cPacket_Respawn.cpp @@ -7,21 +7,6 @@ -void cPacket_Respawn::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - - AppendInteger (a_Data, m_Dimension); - AppendByte (a_Data, m_Difficulty); - AppendByte (a_Data, m_CreativeMode); - AppendShort (a_Data, m_WorldHeight); - AppendString16(a_Data, m_LevelType); -} - - - - - int cPacket_Respawn::Parse(cByteBuffer & a_Buffer) { int TotalBytes = 0; diff --git a/source/packets/cPacket_Respawn.h b/source/packets/cPacket_Respawn.h index b05f84614..9292658e7 100644 --- a/source/packets/cPacket_Respawn.h +++ b/source/packets/cPacket_Respawn.h @@ -2,7 +2,6 @@ #pragma once #include "cPacket.h" - #include "cPacket_Login.h" @@ -25,8 +24,7 @@ public: virtual cPacket * Clone() const { return new cPacket_Respawn( *this ); } - virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; + virtual int Parse(cByteBuffer & a_Buffer) override; int m_Dimension; char m_Difficulty; diff --git a/source/packets/cPacket_SpawnMob.cpp b/source/packets/cPacket_SpawnMob.cpp deleted file mode 100644 index e00952561..000000000 --- a/source/packets/cPacket_SpawnMob.cpp +++ /dev/null @@ -1,71 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_SpawnMob.h" -#include "../Vector3i.h" - - - - - -cPacket_SpawnMob::~cPacket_SpawnMob() -{ - if( m_MetaData ) delete [] m_MetaData; -} - - - - - -cPacket_SpawnMob::cPacket_SpawnMob() - : m_UniqueID( 0 ) - , m_Type( 0 ) - , m_Yaw( 0 ) - , m_Pitch( 0 ) - , m_MetaDataSize( 0 ) - , m_MetaData( 0 ) - , m_HeadYaw(0) -{ - m_PacketID = E_SPAWN_MOB; -} - - - - - -cPacket_SpawnMob::cPacket_SpawnMob( const cPacket_SpawnMob & a_Clone ) -{ - m_PacketID = E_SPAWN_MOB; - m_UniqueID = a_Clone.m_UniqueID; - m_Type = a_Clone.m_Type; - m_Pos = a_Clone.m_Pos; - m_Yaw = a_Clone.m_Yaw; - m_Pitch = a_Clone.m_Pitch; - m_HeadYaw = a_Clone.m_HeadYaw; - - m_MetaDataSize = a_Clone.m_MetaDataSize; - m_MetaData = new char[m_MetaDataSize]; - memcpy( m_MetaData, a_Clone.m_MetaData, sizeof( char ) * m_MetaDataSize ); -} - - - - - -void cPacket_SpawnMob::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger (a_Data, m_UniqueID); - AppendByte (a_Data, m_Type); - AppendInteger (a_Data, m_Pos.x); - AppendInteger (a_Data, m_Pos.y); - AppendInteger (a_Data, m_Pos.z); - AppendByte (a_Data, m_Yaw); - AppendByte (a_Data, m_Pitch); - AppendByte (a_Data, m_HeadYaw); - AppendData (a_Data, m_MetaData, m_MetaDataSize); -} - - - - diff --git a/source/packets/cPacket_SpawnMob.h b/source/packets/cPacket_SpawnMob.h deleted file mode 100644 index 9661da771..000000000 --- a/source/packets/cPacket_SpawnMob.h +++ /dev/null @@ -1,35 +0,0 @@ - -#pragma once - -#include "cPacket.h" -#include "../Vector3i.h" - - - - - -class cPacket_SpawnMob : - public cPacket -{ -public: - cPacket_SpawnMob(); - cPacket_SpawnMob( const cPacket_SpawnMob & a_Clone ); - virtual cPacket* Clone() const { return new cPacket_SpawnMob( *this ); } - ~cPacket_SpawnMob(); - - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - char m_Type; - Vector3i m_Pos; - char m_Yaw; - char m_Pitch; - char m_HeadYaw; - - unsigned int m_MetaDataSize; - char * m_MetaData; -}; - - - - diff --git a/source/packets/cPacket_TeleportEntity.cpp b/source/packets/cPacket_TeleportEntity.cpp deleted file mode 100644 index 14905701a..000000000 --- a/source/packets/cPacket_TeleportEntity.cpp +++ /dev/null @@ -1,41 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_TeleportEntity.h" - -#include "../cEntity.h" - - - - - -cPacket_TeleportEntity::cPacket_TeleportEntity(const cEntity & a_Entity) -{ - m_PacketID = E_ENT_TELEPORT; - - m_UniqueID = a_Entity.GetUniqueID(); - m_PosX = (int)(a_Entity.GetPosX() * 32); - m_PosY = (int)(a_Entity.GetPosY() * 32); - m_PosZ = (int)(a_Entity.GetPosZ() * 32); - m_Rotation = (char)((a_Entity.GetRotation() / 360.f) * 256); - m_Pitch = (char)((a_Entity.GetPitch() / 360.f) * 256); -} - - - - - -void cPacket_TeleportEntity::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger(a_Data, m_UniqueID); - AppendInteger(a_Data, m_PosX); - AppendInteger(a_Data, m_PosY); - AppendInteger(a_Data, m_PosZ); - AppendByte (a_Data, m_Rotation); - AppendByte (a_Data, m_Pitch); -} - - - - diff --git a/source/packets/cPacket_TeleportEntity.h b/source/packets/cPacket_TeleportEntity.h deleted file mode 100644 index 5203badb6..000000000 --- a/source/packets/cPacket_TeleportEntity.h +++ /dev/null @@ -1,42 +0,0 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cEntity; -class cPacket_TeleportEntity : public cPacket -{ -public: - cPacket_TeleportEntity() - : m_UniqueID( 0 ) - , m_PosX( 0 ) - , m_PosY( 0 ) - , m_PosZ( 0 ) - , m_Rotation( 0 ) - , m_Pitch( 0 ) - { - m_PacketID = E_ENT_TELEPORT; - } - - virtual cPacket * Clone() const { return new cPacket_TeleportEntity(*this); } - cPacket_TeleportEntity(const cEntity & a_Entity); - - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; - int m_PosX; // Pixel position, divide by 32 for block position - int m_PosY; - int m_PosZ; - char m_Rotation; - char m_Pitch; - - static const unsigned int c_Size = 1 + 4 + 4 + 4 + 4 + 1 + 1; -}; - - - - diff --git a/source/packets/cPacket_Thunderbolt.cpp b/source/packets/cPacket_Thunderbolt.cpp deleted file mode 100644 index 81054ad8e..000000000 --- a/source/packets/cPacket_Thunderbolt.cpp +++ /dev/null @@ -1,36 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_Thunderbolt.h" - - - - - -cPacket_Thunderbolt::cPacket_Thunderbolt( const cPacket_Thunderbolt & a_Copy ) -{ - m_PacketID = E_THUNDERBOLT; - m_UniqueID = 237183; //just a random Ent ID. I don't think this matters at all. - m_Unknown = true; - m_xLBPos = a_Copy.m_xLBPos; - m_yLBPos = a_Copy.m_yLBPos; - m_zLBPos = a_Copy.m_zLBPos; -} - - - - - -void cPacket_Thunderbolt::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger (a_Data, m_UniqueID); - AppendBool (a_Data, m_Unknown); - AppendInteger (a_Data, m_xLBPos * 32); - AppendInteger (a_Data, m_yLBPos * 32); - AppendInteger (a_Data, m_zLBPos * 32); -} - - - - diff --git a/source/packets/cPacket_Thunderbolt.h b/source/packets/cPacket_Thunderbolt.h deleted file mode 100644 index c3c4e2c98..000000000 --- a/source/packets/cPacket_Thunderbolt.h +++ /dev/null @@ -1,36 +0,0 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_Thunderbolt : public cPacket -{ -public: - cPacket_Thunderbolt() - : m_UniqueID( 0 ) - , m_Unknown( 0 ) - , m_xLBPos( 0 ) - , m_yLBPos( 0 ) - , m_zLBPos( 0 ) - { m_PacketID = E_THUNDERBOLT; m_Unknown = true; } - cPacket_Thunderbolt( const cPacket_Thunderbolt & a_Copy ); - virtual cPacket* Clone() const { return new cPacket_Thunderbolt(*this); } - - virtual void Serialize(AString & a_Data) const override; - - int m_UniqueID; // The entity ID of the thunderbolt - bool m_Unknown; // Always true. Might have a meaning in the future... - int m_xLBPos; // Thunderbolt X as Absolute Integer - int m_yLBPos; // Thunderbolt Y as Absolute Integer - int m_zLBPos; // Thunderbolt Z as Absolute Integer - - static const unsigned int c_Size = 1 + 4 + 1 + 4 + 4 + 4; -}; - - - - diff --git a/source/packets/cPacket_TimeUpdate.cpp b/source/packets/cPacket_TimeUpdate.cpp deleted file mode 100644 index 1195305d4..000000000 --- a/source/packets/cPacket_TimeUpdate.cpp +++ /dev/null @@ -1,29 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_TimeUpdate.h" - - - - - -int cPacket_TimeUpdate::Parse(cByteBuffer & a_Buffer) -{ - int TotalBytes = 0; - HANDLE_PACKET_READ(ReadBEInt64, m_Time, TotalBytes); - return TotalBytes; -} - - - - - -void cPacket_TimeUpdate::Serialize(AString & a_Data) const -{ - AppendByte(a_Data, m_PacketID); - AppendLong(a_Data, m_Time); -} - - - - diff --git a/source/packets/cPacket_TimeUpdate.h b/source/packets/cPacket_TimeUpdate.h deleted file mode 100644 index 9aaa02cae..000000000 --- a/source/packets/cPacket_TimeUpdate.h +++ /dev/null @@ -1,29 +0,0 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_TimeUpdate : public cPacket -{ -public: - cPacket_TimeUpdate() - : m_Time( 0 ) - { m_PacketID = E_UPDATE_TIME; } - cPacket_TimeUpdate( long long a_Time ) { m_PacketID = E_UPDATE_TIME; m_Time = a_Time; } - virtual cPacket* Clone() const { return new cPacket_TimeUpdate(*this); } - - virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; - - long long m_Time; - - static const unsigned int c_Size = 1 + 8; -}; - - - - diff --git a/source/packets/cPacket_UpdateHealth.cpp b/source/packets/cPacket_UpdateHealth.cpp deleted file mode 100644 index ff54b6530..000000000 --- a/source/packets/cPacket_UpdateHealth.cpp +++ /dev/null @@ -1,20 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_UpdateHealth.h" - - - - - -void cPacket_UpdateHealth::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendShort(a_Data, m_Health); - AppendShort(a_Data, m_Food); - AppendFloat(a_Data, m_Saturation); -} - - - - diff --git a/source/packets/cPacket_UpdateHealth.h b/source/packets/cPacket_UpdateHealth.h deleted file mode 100644 index 67fd32399..000000000 --- a/source/packets/cPacket_UpdateHealth.h +++ /dev/null @@ -1,32 +0,0 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_UpdateHealth : public cPacket -{ -public: - cPacket_UpdateHealth() - : m_Health( 0 ) - , m_Food( 0 ) - , m_Saturation( 0.f ) - { m_PacketID = E_UPDATE_HEALTH; } - cPacket_UpdateHealth( short a_Health ) { m_Health = a_Health; m_PacketID = E_UPDATE_HEALTH; } - virtual cPacket* Clone() const { return new cPacket_UpdateHealth( *this ); } - - virtual void Serialize(AString & a_Data) const override; - - short m_Health; - short m_Food; - float m_Saturation; - - static const unsigned int c_Size = 1 + 2 + 2 + 4; -}; - - - - diff --git a/source/packets/cPacket_UpdateSign.cpp b/source/packets/cPacket_UpdateSign.cpp index 564debf01..b258fc9c3 100644 --- a/source/packets/cPacket_UpdateSign.cpp +++ b/source/packets/cPacket_UpdateSign.cpp @@ -23,19 +23,3 @@ int cPacket_UpdateSign::Parse(cByteBuffer & a_Buffer) - -void cPacket_UpdateSign::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendInteger (a_Data, m_BlockX); - AppendShort (a_Data, m_BlockY); - AppendInteger (a_Data, m_BlockZ); - AppendString16(a_Data, m_Line1); - AppendString16(a_Data, m_Line2); - AppendString16(a_Data, m_Line3); - AppendString16(a_Data, m_Line4); -} - - - - diff --git a/source/packets/cPacket_UpdateSign.h b/source/packets/cPacket_UpdateSign.h index 0704a926a..e7b4977b2 100644 --- a/source/packets/cPacket_UpdateSign.h +++ b/source/packets/cPacket_UpdateSign.h @@ -21,7 +21,6 @@ public: virtual cPacket * Clone() const { return new cPacket_UpdateSign( *this); } virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; int m_BlockX; short m_BlockY; diff --git a/source/packets/cPacket_WholeInventory.cpp b/source/packets/cPacket_WholeInventory.cpp deleted file mode 100644 index 69ea33580..000000000 --- a/source/packets/cPacket_WholeInventory.cpp +++ /dev/null @@ -1,80 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_WholeInventory.h" -#include "../cItem.h" -#include "../cInventory.h" -#include "../cWindow.h" -#include "cPacket_ItemData.h" - - - - - -cPacket_WholeInventory::cPacket_WholeInventory( const cPacket_WholeInventory & a_Clone ) -{ - m_PacketID = E_INVENTORY_WHOLE; - m_WindowID = a_Clone.m_WindowID; - m_Count = a_Clone.m_Count; - 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_Clone.m_Items, sizeof(cItem) * m_Count); -} - - - - - -cPacket_WholeInventory::cPacket_WholeInventory(const cInventory & a_Inventory) -{ - m_PacketID = E_INVENTORY_WHOLE; - 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); -} - - - - - -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]; - // 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); -} - - - - - -cPacket_WholeInventory::~cPacket_WholeInventory() -{ - delete [] m_Items; -} - - - - - -void cPacket_WholeInventory::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendByte (a_Data, m_WindowID); - AppendShort(a_Data, m_Count); - - for (int j = 0; j < m_Count; j++) - { - cPacket_ItemData::AppendItem(a_Data, m_Items[j]); - } -} - - - - - \ No newline at end of file diff --git a/source/packets/cPacket_WholeInventory.h b/source/packets/cPacket_WholeInventory.h deleted file mode 100644 index 6582fe6fe..000000000 --- a/source/packets/cPacket_WholeInventory.h +++ /dev/null @@ -1,47 +0,0 @@ - -#pragma once - -#include "cPacket.h" - -#include "../BlockID.h" - - - - - -class cInventory; -class cWindow; -class cItem; - - - - - -class cPacket_WholeInventory : - public cPacket // full inventory [S -> C] ? -{ -public: - 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; - } - - virtual cPacket * Clone() const { return new cPacket_WholeInventory(*this); } - - virtual void Serialize(AString & a_Data) const override; - - char m_WindowID; - short m_Count; - cItem * m_Items; -}; - - - - diff --git a/source/packets/cPacket_WindowClick.cpp b/source/packets/cPacket_WindowClick.cpp index 1d4304917..a0a7afbda 100644 --- a/source/packets/cPacket_WindowClick.cpp +++ b/source/packets/cPacket_WindowClick.cpp @@ -2,7 +2,6 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "cPacket_WindowClick.h" -#include "cPacket_WholeInventory.h" #include "cPacket_ItemData.h" diff --git a/source/packets/cPacket_WindowClose.cpp b/source/packets/cPacket_WindowClose.cpp index 9991ab500..f1280ae28 100644 --- a/source/packets/cPacket_WindowClose.cpp +++ b/source/packets/cPacket_WindowClose.cpp @@ -17,13 +17,3 @@ int cPacket_WindowClose::Parse(cByteBuffer & a_Buffer) - -void cPacket_WindowClose::Serialize(AString & a_Data) const -{ - AppendByte(a_Data, m_PacketID); - AppendByte(a_Data, m_WindowID); -} - - - - diff --git a/source/packets/cPacket_WindowClose.h b/source/packets/cPacket_WindowClose.h index de40ab446..0851fa20d 100644 --- a/source/packets/cPacket_WindowClose.h +++ b/source/packets/cPacket_WindowClose.h @@ -18,8 +18,7 @@ public: virtual cPacket* Clone() const { return new cPacket_WindowClose(*this); } - virtual int Parse(cByteBuffer & a_Buffer) override; - virtual void Serialize(AString & a_Data) const override; + virtual int Parse(cByteBuffer & a_Buffer) override; char m_WindowID; }; diff --git a/source/packets/cPacket_WindowOpen.cpp b/source/packets/cPacket_WindowOpen.cpp deleted file mode 100644 index 8c4402139..000000000 --- a/source/packets/cPacket_WindowOpen.cpp +++ /dev/null @@ -1,21 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cPacket_WindowOpen.h" - - - - - -void cPacket_WindowOpen::Serialize(AString & a_Data) const -{ - AppendByte (a_Data, m_PacketID); - AppendByte (a_Data, m_WindowID); - AppendByte (a_Data, m_InventoryType); - AppendString16(a_Data, m_WindowTitle); - AppendByte (a_Data, m_NumSlots); -} - - - - diff --git a/source/packets/cPacket_WindowOpen.h b/source/packets/cPacket_WindowOpen.h deleted file mode 100644 index 3896f5f02..000000000 --- a/source/packets/cPacket_WindowOpen.h +++ /dev/null @@ -1,32 +0,0 @@ - -#pragma once - -#include "cPacket.h" - - - - - -class cPacket_WindowOpen : public cPacket -{ -public: - cPacket_WindowOpen() - : m_WindowID( 0 ) - , m_InventoryType( 0 ) - , m_NumSlots( 0 ) - { m_PacketID = E_WINDOW_OPEN; } - virtual cPacket* Clone() const { return new cPacket_WindowOpen(*this); } - - virtual void Serialize(AString & a_Data) const override; - - char m_WindowID; - char m_InventoryType; - AString m_WindowTitle; - char m_NumSlots; - - static const unsigned int c_Size = 1 + 1 + 1 + 2 + 1; // + sizeof(string) -}; - - - - -- cgit v1.2.3