From b1d05b0f57e03261eaf776c9bb9b81cfa05a13f5 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 7 Jul 2013 13:06:06 +0000 Subject: Improved function names for protocol packet sending; alpha-sorted the function lists git-svn-id: http://mc-server.googlecode.com/svn/trunk@1659 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Protocol/Protocol.h | 14 ++-- source/Protocol/Protocol125.cpp | 141 +++++++++++++++++++-------------- source/Protocol/Protocol125.h | 14 ++-- source/Protocol/ProtocolRecognizer.cpp | 61 +++++++++----- source/Protocol/ProtocolRecognizer.h | 14 ++-- 5 files changed, 145 insertions(+), 99 deletions(-) (limited to 'source/Protocol') diff --git a/source/Protocol/Protocol.h b/source/Protocol/Protocol.h index 2dd80fc5f..fe9d4d10e 100644 --- a/source/Protocol/Protocol.h +++ b/source/Protocol/Protocol.h @@ -60,13 +60,15 @@ public: 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 SendEntHeadLook (const cEntity & a_Entity) = 0; - virtual void SendEntLook (const cEntity & a_Entity) = 0; - virtual void SendEntVelocity (const cEntity & a_Entity) = 0; - virtual void SendEntRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) = 0; - virtual void SendEntRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) = 0; virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) = 0; + virtual void SendEntityHeadLook (const cEntity & a_Entity) = 0; + virtual void SendEntityLook (const cEntity & a_Entity) = 0; + virtual void SendEntityMetadata (const cEntity & a_Entity) = 0; + virtual void SendEntityProperties (const cEntity & a_Entity) = 0; + virtual void SendEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) = 0; + virtual void SendEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) = 0; virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) = 0; + virtual void SendEntityVelocity (const cEntity & a_Entity) = 0; virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) = 0; virtual void SendGameMode (eGameMode a_GameMode) = 0; virtual void SendHealth (void) = 0; @@ -74,10 +76,10 @@ public: virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) = 0; virtual void SendKeepAlive (int a_PingID) = 0; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) = 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 SendPlayerListItem (const cPlayer & a_Player, bool a_IsOnline) = 0; + virtual void SendPlayerMaxSpeed (void) = 0; ///< Informs the client of the maximum player speed (1.6.1+) virtual void SendPlayerMoveLook (void) = 0; virtual void SendPlayerPosition (void) = 0; virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0; diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp index bce24498a..f4976b9d8 100644 --- a/source/Protocol/Protocol125.cpp +++ b/source/Protocol/Protocol125.cpp @@ -277,23 +277,22 @@ void cProtocol125::SendDisconnect(const AString & a_Reason) -void cProtocol125::SendEntVelocity(const cEntity & a_Entity) +void cProtocol125::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) { - ASSERT(a_Entity.GetUniqueID() != m_Client->GetPlayer()->GetUniqueID()); // Must not send for self - cCSLock Lock(m_CSPacket); - WriteByte(PACKET_ENTITY_VELOCITY); - WriteInt (a_Entity.GetUniqueID()); - WriteShort((short) (a_Entity.GetSpeedX() * 400)); //400 = 8000 / 20 - WriteShort((short) (a_Entity.GetSpeedY() * 400)); - WriteShort((short) (a_Entity.GetSpeedZ() * 400)); + WriteByte (PACKET_ENTITY_EQUIPMENT); + WriteInt (a_Entity.GetUniqueID()); + WriteShort(a_SlotNum); + WriteShort(a_Item.m_ItemType); + WriteShort(a_Item.m_ItemDamage); Flush(); } -void cProtocol125::SendEntHeadLook(const cEntity & a_Entity) + +void cProtocol125::SendEntityHeadLook(const cEntity & a_Entity) { ASSERT(a_Entity.GetUniqueID() != m_Client->GetPlayer()->GetUniqueID()); // Must not send for self @@ -308,7 +307,7 @@ void cProtocol125::SendEntHeadLook(const cEntity & a_Entity) -void cProtocol125::SendEntLook(const cEntity & a_Entity) +void cProtocol125::SendEntityLook(const cEntity & a_Entity) { ASSERT(a_Entity.GetUniqueID() != m_Client->GetPlayer()->GetUniqueID()); // Must not send for self @@ -324,14 +323,13 @@ void cProtocol125::SendEntLook(const cEntity & a_Entity) -void cProtocol125::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) +void cProtocol125::SendEntityMetadata(const cEntity & a_Entity) { cCSLock Lock(m_CSPacket); - WriteByte (PACKET_ENTITY_EQUIPMENT); - WriteInt (a_Entity.GetUniqueID()); - WriteShort(a_SlotNum); - WriteShort(a_Item.m_ItemType); - WriteShort(a_Item.m_ItemDamage); + WriteByte(PACKET_METADATA); + WriteInt (a_Entity.GetUniqueID()); + AString MetaData = GetEntityMetaData(a_Entity); + SendData(MetaData.data(), MetaData.size()); Flush(); } @@ -339,37 +337,25 @@ void cProtocol125::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum -void cProtocol125::SendEntityStatus(const cEntity & a_Entity, char a_Status) +void cProtocol125::SendEntityProperties(const cEntity & a_Entity) { - cCSLock Lock(m_CSPacket); - WriteByte(PACKET_ENT_STATUS); - WriteInt (a_Entity.GetUniqueID()); - WriteByte(a_Status); - Flush(); + // Not supported in this protocol version } -void cProtocol125::SendExplosion(double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) +void cProtocol125::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) { + ASSERT(a_Entity.GetUniqueID() != m_Client->GetPlayer()->GetUniqueID()); // Must not send for self + cCSLock Lock(m_CSPacket); - WriteByte(PACKET_EXPLOSION); - WriteDouble (a_BlockX); - WriteDouble (a_BlockY); - WriteDouble (a_BlockZ); - WriteFloat (a_Radius); - WriteInt (a_BlocksAffected.size()); - for (cVector3iArray::const_iterator itr = a_BlocksAffected.begin(); itr != a_BlocksAffected.end(); ++itr) - { - WriteByte ((Byte)(itr->x - a_BlockX)); - WriteByte ((Byte)(itr->y - a_BlockY)); - WriteByte ((Byte)(itr->z - a_BlockZ)); - } - WriteFloat ((float)a_PlayerMotion.x); - WriteFloat ((float)a_PlayerMotion.y); - WriteFloat ((float)a_PlayerMotion.z); + WriteByte(PACKET_ENT_REL_MOVE); + WriteInt (a_Entity.GetUniqueID()); + WriteByte(a_RelX); + WriteByte(a_RelY); + WriteByte(a_RelZ); Flush(); } @@ -377,16 +363,31 @@ void cProtocol125::SendExplosion(double a_BlockX, double a_BlockY, double a_Bloc -void cProtocol125::SendEntRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) +void cProtocol125::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) { ASSERT(a_Entity.GetUniqueID() != m_Client->GetPlayer()->GetUniqueID()); // Must not send for self cCSLock Lock(m_CSPacket); - WriteByte(PACKET_ENT_REL_MOVE); + WriteByte(PACKET_ENT_REL_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(); +} + + + + + +void cProtocol125::SendEntityStatus(const cEntity & a_Entity, char a_Status) +{ + cCSLock Lock(m_CSPacket); + WriteByte(PACKET_ENT_STATUS); + WriteInt (a_Entity.GetUniqueID()); + WriteByte(a_Status); Flush(); } @@ -394,18 +395,41 @@ void cProtocol125::SendEntRelMove(const cEntity & a_Entity, char a_RelX, char a_ -void cProtocol125::SendEntRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) +void cProtocol125::SendEntityVelocity(const cEntity & a_Entity) { ASSERT(a_Entity.GetUniqueID() != m_Client->GetPlayer()->GetUniqueID()); // Must not send for self cCSLock Lock(m_CSPacket); - WriteByte(PACKET_ENT_REL_MOVE_LOOK); + WriteByte(PACKET_ENTITY_VELOCITY); 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)); + WriteShort((short) (a_Entity.GetSpeedX() * 400)); //400 = 8000 / 20 + WriteShort((short) (a_Entity.GetSpeedY() * 400)); + WriteShort((short) (a_Entity.GetSpeedZ() * 400)); + Flush(); +} + + + + + +void cProtocol125::SendExplosion(double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) +{ + cCSLock Lock(m_CSPacket); + WriteByte(PACKET_EXPLOSION); + WriteDouble (a_BlockX); + WriteDouble (a_BlockY); + WriteDouble (a_BlockZ); + WriteFloat (a_Radius); + WriteInt (a_BlocksAffected.size()); + for (cVector3iArray::const_iterator itr = a_BlocksAffected.begin(); itr != a_BlocksAffected.end(); ++itr) + { + WriteByte ((Byte)(itr->x - a_BlockX)); + WriteByte ((Byte)(itr->y - a_BlockY)); + WriteByte ((Byte)(itr->z - a_BlockZ)); + } + WriteFloat ((float)a_PlayerMotion.x); + WriteFloat ((float)a_PlayerMotion.y); + WriteFloat ((float)a_PlayerMotion.z); Flush(); } @@ -513,20 +537,6 @@ void cProtocol125::SendLogin(const cPlayer & a_Player, const cWorld & a_World) -void cProtocol125::SendMetadata(const cEntity & a_Entity) -{ - cCSLock Lock(m_CSPacket); - WriteByte(PACKET_METADATA); - WriteInt (a_Entity.GetUniqueID()); - AString MetaData = GetEntityMetaData(a_Entity); - SendData(MetaData.data(), MetaData.size()); - Flush(); -} - - - - - void cProtocol125::SendPickupSpawn(const cPickup & a_Pickup) { cCSLock Lock(m_CSPacket); @@ -581,6 +591,15 @@ void cProtocol125::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline) +void cProtocol125::SendPlayerMaxSpeed(void) +{ + // Not supported by this protocol version +} + + + + + void cProtocol125::SendPlayerMoveLook(void) { cCSLock Lock(m_CSPacket); diff --git a/source/Protocol/Protocol125.h b/source/Protocol/Protocol125.h index 2e0c04212..07eab3e7a 100644 --- a/source/Protocol/Protocol125.h +++ b/source/Protocol/Protocol125.h @@ -37,13 +37,15 @@ public: virtual void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player) override; virtual void SendDestroyEntity (const cEntity & a_Entity) override; virtual void SendDisconnect (const AString & a_Reason) override; - virtual void SendEntHeadLook (const cEntity & a_Entity) override; - virtual void SendEntLook (const cEntity & a_Entity) override; - virtual void SendEntVelocity (const cEntity & a_Entity) override; - virtual void SendEntRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override; - virtual void SendEntRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override; virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) override; + virtual void SendEntityHeadLook (const cEntity & a_Entity) override; + virtual void SendEntityLook (const cEntity & a_Entity) override; + virtual void SendEntityMetadata (const cEntity & a_Entity) override; + virtual void SendEntityProperties (const cEntity & a_Entity) override; + virtual void SendEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override; + virtual void SendEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override; virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override; + virtual void SendEntityVelocity (const cEntity & a_Entity) override; virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override; virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; @@ -51,10 +53,10 @@ public: virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) 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; + virtual void SendPlayerMaxSpeed (void) override; virtual void SendPlayerMoveLook (void) override; virtual void SendPlayerPosition (void) override; virtual void SendPlayerSpawn (const cPlayer & a_Player) override; diff --git a/source/Protocol/ProtocolRecognizer.cpp b/source/Protocol/ProtocolRecognizer.cpp index f7c3a1670..0b7887f5c 100644 --- a/source/Protocol/ProtocolRecognizer.cpp +++ b/source/Protocol/ProtocolRecognizer.cpp @@ -200,59 +200,70 @@ void cProtocolRecognizer::SendDisconnect(const AString & a_Reason) -void cProtocolRecognizer::SendEntVelocity(const cEntity & a_Entity) +void cProtocolRecognizer::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) { ASSERT(m_Protocol != NULL); - m_Protocol->SendEntVelocity(a_Entity); + m_Protocol->SendEntityEquipment(a_Entity, a_SlotNum, a_Item); } -void cProtocolRecognizer::SendEntHeadLook(const cEntity & a_Entity) + +void cProtocolRecognizer::SendEntityHeadLook(const cEntity & a_Entity) { ASSERT(m_Protocol != NULL); - m_Protocol->SendEntHeadLook(a_Entity); + m_Protocol->SendEntityHeadLook(a_Entity); } -void cProtocolRecognizer::SendEntLook(const cEntity & a_Entity) +void cProtocolRecognizer::SendEntityLook(const cEntity & a_Entity) { ASSERT(m_Protocol != NULL); - m_Protocol->SendEntLook(a_Entity); + m_Protocol->SendEntityLook(a_Entity); } -void cProtocolRecognizer::SendEntRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) +void cProtocolRecognizer::SendEntityMetadata(const cEntity & a_Entity) { ASSERT(m_Protocol != NULL); - m_Protocol->SendEntRelMove(a_Entity, a_RelX, a_RelY, a_RelZ); + m_Protocol->SendEntityMetadata(a_Entity); } -void cProtocolRecognizer::SendEntRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) +void cProtocolRecognizer::SendEntityProperties(const cEntity & a_Entity) { ASSERT(m_Protocol != NULL); - m_Protocol->SendEntRelMoveLook(a_Entity, a_RelX, a_RelY, a_RelZ); + m_Protocol->SendEntityProperties(a_Entity); } -void cProtocolRecognizer::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) +void cProtocolRecognizer::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) { ASSERT(m_Protocol != NULL); - m_Protocol->SendEntityEquipment(a_Entity, a_SlotNum, a_Item); + m_Protocol->SendEntityRelMove(a_Entity, a_RelX, a_RelY, a_RelZ); +} + + + + + +void cProtocolRecognizer::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) +{ + ASSERT(m_Protocol != NULL); + m_Protocol->SendEntityRelMoveLook(a_Entity, a_RelX, a_RelY, a_RelZ); } @@ -269,6 +280,16 @@ void cProtocolRecognizer::SendEntityStatus(const cEntity & a_Entity, char a_Stat +void cProtocolRecognizer::SendEntityVelocity(const cEntity & a_Entity) +{ + ASSERT(m_Protocol != NULL); + m_Protocol->SendEntityVelocity(a_Entity); +} + + + + + void cProtocolRecognizer::SendExplosion(double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) { ASSERT(m_Protocol != NULL); @@ -339,40 +360,40 @@ void cProtocolRecognizer::SendLogin(const cPlayer & a_Player, const cWorld & a_W -void cProtocolRecognizer::SendMetadata(const cEntity & a_Entity) +void cProtocolRecognizer::SendPickupSpawn(const cPickup & a_Pickup) { ASSERT(m_Protocol != NULL); - m_Protocol->SendMetadata(a_Entity); + m_Protocol->SendPickupSpawn(a_Pickup); } -void cProtocolRecognizer::SendPickupSpawn(const cPickup & a_Pickup) +void cProtocolRecognizer::SendPlayerAnimation(const cPlayer & a_Player, char a_Animation) { ASSERT(m_Protocol != NULL); - m_Protocol->SendPickupSpawn(a_Pickup); + m_Protocol->SendPlayerAnimation(a_Player, a_Animation); } -void cProtocolRecognizer::SendPlayerAnimation(const cPlayer & a_Player, char a_Animation) +void cProtocolRecognizer::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline) { ASSERT(m_Protocol != NULL); - m_Protocol->SendPlayerAnimation(a_Player, a_Animation); + m_Protocol->SendPlayerListItem(a_Player, a_IsOnline); } -void cProtocolRecognizer::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline) +void cProtocolRecognizer::SendPlayerMaxSpeed(void) { ASSERT(m_Protocol != NULL); - m_Protocol->SendPlayerListItem(a_Player, a_IsOnline); + m_Protocol->SendPlayerMaxSpeed(); } diff --git a/source/Protocol/ProtocolRecognizer.h b/source/Protocol/ProtocolRecognizer.h index 38dc3b03e..682ac4b1d 100644 --- a/source/Protocol/ProtocolRecognizer.h +++ b/source/Protocol/ProtocolRecognizer.h @@ -66,13 +66,15 @@ public: virtual void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player) override; virtual void SendDestroyEntity (const cEntity & a_Entity) override; virtual void SendDisconnect (const AString & a_Reason) override; - virtual void SendEntHeadLook (const cEntity & a_Entity) override; - virtual void SendEntLook (const cEntity & a_Entity) override; - virtual void SendEntVelocity (const cEntity & a_Entity) override; - virtual void SendEntRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override; - virtual void SendEntRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override; virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) override; + virtual void SendEntityHeadLook (const cEntity & a_Entity) override; + virtual void SendEntityLook (const cEntity & a_Entity) override; + virtual void SendEntityMetadata (const cEntity & a_Entity) override; + virtual void SendEntityProperties (const cEntity & a_Entity) override; + virtual void SendEntityRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override; + virtual void SendEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) override; virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override; + virtual void SendEntityVelocity (const cEntity & a_Entity) override; virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override; virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; @@ -80,10 +82,10 @@ public: virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) 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; + virtual void SendPlayerMaxSpeed (void) override; virtual void SendPlayerMoveLook (void) override; virtual void SendPlayerPosition (void) override; virtual void SendPlayerSpawn (const cPlayer & a_Player) override; -- cgit v1.2.3