Using references instead of pointers for sending packets
git-svn-id: http://mc-server.googlecode.com/svn/trunk@394 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
732b7349fa
commit
e7731242c1
@ -66,7 +66,7 @@ public:
|
|||||||
}
|
}
|
||||||
if ( a_Client != NULL )
|
if ( a_Client != NULL )
|
||||||
{
|
{
|
||||||
a_Client->Send(Packet.get());
|
a_Client->Send(*(Packet.get()));
|
||||||
}
|
}
|
||||||
else // broadcast to all chunk clients
|
else // broadcast to all chunk clients
|
||||||
{
|
{
|
||||||
|
@ -1373,7 +1373,7 @@ void cChunk::Broadcast( const cPacket * a_Packet, cClientHandle* a_Exclude)
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
(*itr)->Send( a_Packet );
|
(*itr)->Send(*a_Packet);
|
||||||
} // for itr - LoadedByClient[]
|
} // for itr - LoadedByClient[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1703,14 +1703,14 @@ void cClientHandle::Tick(float a_Dt)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cClientHandle::Send(const cPacket * a_Packet, ENUM_PRIORITY a_Priority /* = E_PRIORITY_NORMAL */)
|
void cClientHandle::Send(const cPacket & a_Packet, ENUM_PRIORITY a_Priority /* = E_PRIORITY_NORMAL */)
|
||||||
{
|
{
|
||||||
if (m_bKicking) return; // Don't add more packets if player is getting kicked anyway
|
if (m_bKicking) return; // Don't add more packets if player is getting kicked anyway
|
||||||
|
|
||||||
// If it is the packet spawning myself for myself, drop it silently:
|
// If it is the packet spawning myself for myself, drop it silently:
|
||||||
if (a_Packet->m_PacketID == E_NAMED_ENTITY_SPAWN)
|
if (a_Packet.m_PacketID == E_NAMED_ENTITY_SPAWN)
|
||||||
{
|
{
|
||||||
if (((cPacket_NamedEntitySpawn *)a_Packet)->m_UniqueID == m_Player->GetUniqueID())
|
if (((cPacket_NamedEntitySpawn &)a_Packet).m_UniqueID == m_Player->GetUniqueID())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1719,7 +1719,7 @@ void cClientHandle::Send(const cPacket * a_Packet, ENUM_PRIORITY a_Priority /* =
|
|||||||
// Filter out packets that don't belong to a csDownloadingWorld state:
|
// Filter out packets that don't belong to a csDownloadingWorld state:
|
||||||
if (m_State == csDownloadingWorld)
|
if (m_State == csDownloadingWorld)
|
||||||
{
|
{
|
||||||
switch (a_Packet->m_PacketID)
|
switch (a_Packet.m_PacketID)
|
||||||
{
|
{
|
||||||
case E_PLAYERMOVELOOK:
|
case E_PLAYERMOVELOOK:
|
||||||
case E_KEEP_ALIVE:
|
case E_KEEP_ALIVE:
|
||||||
@ -1734,14 +1734,14 @@ void cClientHandle::Send(const cPacket * a_Packet, ENUM_PRIORITY a_Priority /* =
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check chunks being sent, erase them from m_ChunksToSend:
|
// Check chunks being sent, erase them from m_ChunksToSend:
|
||||||
if (a_Packet->m_PacketID == E_MAP_CHUNK)
|
if (a_Packet.m_PacketID == E_MAP_CHUNK)
|
||||||
{
|
{
|
||||||
#if (MINECRAFT_1_2_2 == 1)
|
#if (MINECRAFT_1_2_2 == 1)
|
||||||
int ChunkX = ((cPacket_MapChunk *)a_Packet)->m_PosX;
|
int ChunkX = ((cPacket_MapChunk &)a_Packet).m_PosX;
|
||||||
int ChunkZ = ((cPacket_MapChunk *)a_Packet)->m_PosZ;
|
int ChunkZ = ((cPacket_MapChunk &)a_Packet).m_PosZ;
|
||||||
#else
|
#else
|
||||||
int ChunkX = ((cPacket_MapChunk *)a_Packet)->m_PosX / cChunk::c_ChunkWidth;
|
int ChunkX = ((cPacket_MapChunk &)a_Packet).m_PosX / cChunk::c_ChunkWidth;
|
||||||
int ChunkZ = ((cPacket_MapChunk *)a_Packet)->m_PosZ / cChunk::c_ChunkWidth;
|
int ChunkZ = ((cPacket_MapChunk &)a_Packet).m_PosZ / cChunk::c_ChunkWidth;
|
||||||
#endif
|
#endif
|
||||||
cCSLock Lock(m_CSChunkLists);
|
cCSLock Lock(m_CSChunkLists);
|
||||||
for (cChunkCoordsList::iterator itr = m_ChunksToSend.begin(); itr != m_ChunksToSend.end(); ++itr)
|
for (cChunkCoordsList::iterator itr = m_ChunksToSend.begin(); itr != m_ChunksToSend.end(); ++itr)
|
||||||
@ -1759,9 +1759,10 @@ void cClientHandle::Send(const cPacket * a_Packet, ENUM_PRIORITY a_Priority /* =
|
|||||||
cCSLock Lock(m_CSPackets);
|
cCSLock Lock(m_CSPackets);
|
||||||
if (a_Priority == E_PRIORITY_NORMAL)
|
if (a_Priority == E_PRIORITY_NORMAL)
|
||||||
{
|
{
|
||||||
if (a_Packet->m_PacketID == E_REL_ENT_MOVE_LOOK)
|
if (a_Packet.m_PacketID == E_REL_ENT_MOVE_LOOK)
|
||||||
{
|
{
|
||||||
PacketList & Packets = m_PendingNrmSendPackets;
|
PacketList & Packets = m_PendingNrmSendPackets;
|
||||||
|
const cPacket_RelativeEntityMoveLook & ThisPacketData = reinterpret_cast< const cPacket_RelativeEntityMoveLook &>(a_Packet);
|
||||||
for (PacketList::iterator itr = Packets.begin(); itr != Packets.end(); ++itr)
|
for (PacketList::iterator itr = Packets.begin(); itr != Packets.end(); ++itr)
|
||||||
{
|
{
|
||||||
bool bBreak = false;
|
bool bBreak = false;
|
||||||
@ -1769,9 +1770,8 @@ void cClientHandle::Send(const cPacket * a_Packet, ENUM_PRIORITY a_Priority /* =
|
|||||||
{
|
{
|
||||||
case E_REL_ENT_MOVE_LOOK:
|
case E_REL_ENT_MOVE_LOOK:
|
||||||
{
|
{
|
||||||
const cPacket_RelativeEntityMoveLook* ThisPacketData = reinterpret_cast< const cPacket_RelativeEntityMoveLook* >(a_Packet);
|
cPacket_RelativeEntityMoveLook * PacketData = reinterpret_cast< cPacket_RelativeEntityMoveLook *>(*itr);
|
||||||
cPacket_RelativeEntityMoveLook* PacketData = reinterpret_cast< cPacket_RelativeEntityMoveLook* >(*itr);
|
if (ThisPacketData.m_UniqueID == PacketData->m_UniqueID)
|
||||||
if (ThisPacketData->m_UniqueID == PacketData->m_UniqueID)
|
|
||||||
{
|
{
|
||||||
Packets.erase(itr);
|
Packets.erase(itr);
|
||||||
bBreak = true;
|
bBreak = true;
|
||||||
@ -1787,11 +1787,11 @@ void cClientHandle::Send(const cPacket * a_Packet, ENUM_PRIORITY a_Priority /* =
|
|||||||
}
|
}
|
||||||
} // for itr - Packets[]
|
} // for itr - Packets[]
|
||||||
} // if (E_REL_ENT_MOVE_LOOK
|
} // if (E_REL_ENT_MOVE_LOOK
|
||||||
m_PendingNrmSendPackets.push_back(a_Packet->Clone());
|
m_PendingNrmSendPackets.push_back(a_Packet.Clone());
|
||||||
}
|
}
|
||||||
else if (a_Priority == E_PRIORITY_LOW)
|
else if (a_Priority == E_PRIORITY_LOW)
|
||||||
{
|
{
|
||||||
m_PendingLowSendPackets.push_back(a_Packet->Clone());
|
m_PendingLowSendPackets.push_back(a_Packet.Clone());
|
||||||
}
|
}
|
||||||
Lock.Unlock();
|
Lock.Unlock();
|
||||||
|
|
||||||
|
@ -97,8 +97,7 @@ public:
|
|||||||
|
|
||||||
bool IsPlaying(void) const {return (m_State == csPlaying); }
|
bool IsPlaying(void) const {return (m_State == csPlaying); }
|
||||||
|
|
||||||
void Send(const cPacket & a_Packet, ENUM_PRIORITY a_Priority = E_PRIORITY_NORMAL) { Send(&a_Packet, a_Priority); }
|
void Send(const cPacket & a_Packet, ENUM_PRIORITY a_Priority = E_PRIORITY_NORMAL);
|
||||||
void Send(const cPacket * a_Packet, ENUM_PRIORITY a_Priority = E_PRIORITY_NORMAL);
|
|
||||||
|
|
||||||
const AString & GetUsername(void) const; //tolua_export
|
const AString & GetUsername(void) const; //tolua_export
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ void cEntity::MoveToCorrectChunk(bool a_bIgnoreOldChunk)
|
|||||||
{
|
{
|
||||||
m_Destroy = new cPacket_DestroyEntity(m_Entity);
|
m_Destroy = new cPacket_DestroyEntity(m_Entity);
|
||||||
}
|
}
|
||||||
a_Client->Send(m_Destroy);
|
a_Client->Send(*m_Destroy);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Added(cClientHandle * a_Client) override
|
virtual void Added(cClientHandle * a_Client) override
|
||||||
@ -131,7 +131,7 @@ void cEntity::MoveToCorrectChunk(bool a_bIgnoreOldChunk)
|
|||||||
}
|
}
|
||||||
if (m_Spawn != NULL)
|
if (m_Spawn != NULL)
|
||||||
{
|
{
|
||||||
a_Client->Send(m_Spawn);
|
a_Client->Send(*m_Spawn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ void cEntity::SpawnOn(cClientHandle * a_Client)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
a_Client->Send(SpawnPacket.get());
|
a_Client->Send(*(SpawnPacket.get()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ cPickup::cPickup(int a_X, int a_Y, int a_Z, const cItem & a_Item, float a_SpeedX
|
|||||||
std::auto_ptr<cPacket> PickupSpawn(GetSpawnPacket());
|
std::auto_ptr<cPacket> PickupSpawn(GetSpawnPacket());
|
||||||
if (PickupSpawn.get() != NULL)
|
if (PickupSpawn.get() != NULL)
|
||||||
{
|
{
|
||||||
cRoot::Get()->GetServer()->Broadcast( PickupSpawn.get() );
|
cRoot::Get()->GetServer()->Broadcast(*(PickupSpawn.get()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +285,7 @@ cServer::~cServer()
|
|||||||
|
|
||||||
|
|
||||||
// TODO - Need to modify this or something, so it broadcasts to all worlds? And move this to cWorld?
|
// TODO - Need to modify this or something, so it broadcasts to all worlds? And move this to cWorld?
|
||||||
void cServer::Broadcast( const cPacket * a_Packet, cClientHandle* a_Exclude /* = 0 */ )
|
void cServer::Broadcast( const cPacket & a_Packet, cClientHandle* a_Exclude /* = 0 */ )
|
||||||
{
|
{
|
||||||
cCSLock Lock(m_CSClients);
|
cCSLock Lock(m_CSClients);
|
||||||
for( ClientList::iterator itr = m_Clients.begin(); itr != m_Clients.end(); ++itr)
|
for( ClientList::iterator itr = m_Clients.begin(); itr != m_Clients.end(); ++itr)
|
||||||
|
@ -38,8 +38,7 @@ public: //tolua_export
|
|||||||
bool IsConnected(){return m_bIsConnected;} // returns connection status
|
bool IsConnected(){return m_bIsConnected;} // returns connection status
|
||||||
void StartListenClient(); // Listen to client
|
void StartListenClient(); // Listen to client
|
||||||
|
|
||||||
void Broadcast(const cPacket & a_Packet, cClientHandle* a_Exclude = NULL) { Broadcast(&a_Packet, a_Exclude); }
|
void Broadcast(const cPacket & a_Packet, cClientHandle* a_Exclude = NULL);
|
||||||
void Broadcast(const cPacket * a_Packet, cClientHandle* a_Exclude = NULL);
|
|
||||||
|
|
||||||
bool Tick(float a_Dt);
|
bool Tick(float a_Dt);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user