diff options
-rw-r--r-- | source/Chunk.cpp | 16 | ||||
-rw-r--r-- | source/Chunk.h | 1 | ||||
-rw-r--r-- | source/ChunkMap.cpp | 16 | ||||
-rw-r--r-- | source/ChunkMap.h | 3 | ||||
-rw-r--r-- | source/ClientHandle.cpp | 11 | ||||
-rw-r--r-- | source/ClientHandle.h | 1 | ||||
-rw-r--r-- | source/Protocol/Protocol.h | 1 | ||||
-rw-r--r-- | source/Protocol/Protocol125.cpp | 16 | ||||
-rw-r--r-- | source/Protocol/Protocol125.h | 1 | ||||
-rw-r--r-- | source/Protocol/ProtocolRecognizer.cpp | 8 | ||||
-rw-r--r-- | source/Protocol/ProtocolRecognizer.h | 1 | ||||
-rw-r--r-- | source/World.cpp | 8 | ||||
-rw-r--r-- | source/World.h | 1 |
13 files changed, 84 insertions, 0 deletions
diff --git a/source/Chunk.cpp b/source/Chunk.cpp index d8dfb79f8..83d6f14e1 100644 --- a/source/Chunk.cpp +++ b/source/Chunk.cpp @@ -1990,6 +1990,22 @@ void cChunk::BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotNum, +void cChunk::BroadcastEntVelocity(const cEntity & a_Entity, const cClientHandle * a_Exclude) +{ + for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr ) + { + if (*itr == a_Exclude) + { + continue; + } + (*itr)->SendEntVelocity(a_Entity); + } // for itr - LoadedByClient[] +} + + + + + void cChunk::BroadcastEntRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude) { for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr ) diff --git a/source/Chunk.h b/source/Chunk.h index bf590ee7e..5e679ed12 100644 --- a/source/Chunk.h +++ b/source/Chunk.h @@ -211,6 +211,7 @@ public: void BroadcastAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle); void BroadcastPlayerAnimation (const cPlayer & a_Player, char a_Animation, const cClientHandle * a_Exclude = NULL); void BroadcastEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude = NULL); + void BroadcastEntVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); void BroadcastEntRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL); void BroadcastEntRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL); void BroadcastEntLook (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); diff --git a/source/ChunkMap.cpp b/source/ChunkMap.cpp index aad956aff..c7a341af2 100644 --- a/source/ChunkMap.cpp +++ b/source/ChunkMap.cpp @@ -322,6 +322,22 @@ void cChunkMap::BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotN +void cChunkMap::BroadcastEntVelocity(const cEntity & a_Entity, const cClientHandle * a_Exclude) +{ + cCSLock Lock(m_CSLayers); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkY(), a_Entity.GetChunkZ()); + if (Chunk == NULL) + { + return; + } + // It's perfectly legal to broadcast packets even to invalid chunks! + Chunk->BroadcastEntVelocity(a_Entity, a_Exclude); +} + + + + + void cChunkMap::BroadcastEntRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); diff --git a/source/ChunkMap.h b/source/ChunkMap.h index 1ddd7d637..809c735a9 100644 --- a/source/ChunkMap.h +++ b/source/ChunkMap.h @@ -53,6 +53,9 @@ public: /// Broadcasts an entity equipment change to all clients in the chunk where a_Entity is void BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude = NULL); + /// Broadcasts a EntVelocity packet to all clients in the chunk where a_Entity is. Velocity is measured in blocks/second + void BroadcastEntVelocity(const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); + /// Broadcasts a RelEntMoveLook packet to all clients in the chunk where a_Entity is void BroadcastEntRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL); diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index fde80a083..2cb508b81 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -1453,6 +1453,17 @@ void cClientHandle::SendEntLook(const cEntity & a_Entity) +void cClientHandle::SendEntVelocity(const cEntity & a_Entity) +{ + ASSERT(a_Entity.GetUniqueID() != m_Player->GetUniqueID()); // Must not send for self + + m_Protocol->SendEntVelocity(a_Entity); +} + + + + + void cClientHandle::SendEntHeadLook(const cEntity & a_Entity) { ASSERT(a_Entity.GetUniqueID() != m_Player->GetUniqueID()); // Must not send for self diff --git a/source/ClientHandle.h b/source/ClientHandle.h index 2eb778c91..0916ff82a 100644 --- a/source/ClientHandle.h +++ b/source/ClientHandle.h @@ -93,6 +93,7 @@ public: void SendDisconnect (const AString & a_Reason); void SendEntHeadLook (const cEntity & a_Entity); void SendEntLook (const cEntity & a_Entity); + void SendEntVelocity (const cEntity & a_Entity); void SendEntRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ); void SendEntRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ); void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item); diff --git a/source/Protocol/Protocol.h b/source/Protocol/Protocol.h index 7a3270541..97c80ce35 100644 --- a/source/Protocol/Protocol.h +++ b/source/Protocol/Protocol.h @@ -62,6 +62,7 @@ public: 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;
diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp index 9514fb278..d2f3add7f 100644 --- a/source/Protocol/Protocol125.cpp +++ b/source/Protocol/Protocol125.cpp @@ -55,6 +55,7 @@ enum PACKET_COLLECT_PICKUP = 0x16,
PACKET_SPAWN_OBJECT = 0x17,
PACKET_SPAWN_MOB = 0x18,
+ PACKET_ENTITY_VELOCITY = 0x1c,
PACKET_DESTROY_ENTITY = 0x1d,
PACKET_ENTITY = 0x1e,
PACKET_ENT_REL_MOVE = 0x1f,
@@ -276,6 +277,21 @@ void cProtocol125::SendDisconnect(const AString & a_Reason) +void cProtocol125::SendEntVelocity(const cEntity & a_Entity)
+{
+ 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));
+ Flush();
+}
+
+
+
void cProtocol125::SendEntHeadLook(const cEntity & a_Entity)
{
diff --git a/source/Protocol/Protocol125.h b/source/Protocol/Protocol125.h index b3dd79069..8b724e036 100644 --- a/source/Protocol/Protocol125.h +++ b/source/Protocol/Protocol125.h @@ -39,6 +39,7 @@ public: 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;
diff --git a/source/Protocol/ProtocolRecognizer.cpp b/source/Protocol/ProtocolRecognizer.cpp index 935d89b9e..787672286 100644 --- a/source/Protocol/ProtocolRecognizer.cpp +++ b/source/Protocol/ProtocolRecognizer.cpp @@ -197,6 +197,14 @@ void cProtocolRecognizer::SendDisconnect(const AString & a_Reason) +void cProtocolRecognizer::SendEntVelocity(const cEntity & a_Entity)
+{
+ ASSERT(m_Protocol != NULL);
+ m_Protocol->SendEntVelocity(a_Entity);
+}
+
+
+
void cProtocolRecognizer::SendEntHeadLook(const cEntity & a_Entity)
{
diff --git a/source/Protocol/ProtocolRecognizer.h b/source/Protocol/ProtocolRecognizer.h index 682e6fcf3..866a84eb0 100644 --- a/source/Protocol/ProtocolRecognizer.h +++ b/source/Protocol/ProtocolRecognizer.h @@ -66,6 +66,7 @@ public: 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;
diff --git a/source/World.cpp b/source/World.cpp index 936aad9a8..3f5e604bf 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -1307,6 +1307,14 @@ void cWorld::BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotNum, +void cWorld::BroadcastEntVelocity(const cEntity & a_Entity, const cClientHandle * a_Exclude) +{ + m_ChunkMap->BroadcastEntVelocity(a_Entity, a_Exclude); +} + + + + void cWorld::BroadcastTeleportEntity(const cEntity & a_Entity, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSPlayers); diff --git a/source/World.h b/source/World.h index 2e8572b00..5eab923b7 100644 --- a/source/World.h +++ b/source/World.h @@ -108,6 +108,7 @@ public: void BroadcastChat (const AString & a_Message, const cClientHandle * a_Exclude = NULL); void BroadcastPlayerAnimation (const cPlayer & a_Player, char a_Animation, const cClientHandle * a_Exclude = NULL); void BroadcastEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude = NULL); + void BroadcastEntVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); void BroadcastTeleportEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); void BroadcastEntRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL); void BroadcastEntRelMove (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL); |