[General] Minor cleanup of the World Packets

new-script-api
Koncord 7 years ago
parent 744b8cf168
commit 1841562553

@ -58,7 +58,7 @@ mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *pee
mwmp::WorldPacket *mwmp::WorldPacketController::GetPacket(RakNet::MessageID id)
{
return packets[(unsigned char)id].get();
return packets[(RakNet::MessageID)id].get();
}
void mwmp::WorldPacketController::SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream)

@ -18,7 +18,7 @@ namespace mwmp
bool ContainsPacket(RakNet::MessageID id);
typedef std::unordered_map<unsigned char, std::unique_ptr<WorldPacket> > packets_t;
typedef std::unordered_map<RakNet::MessageID, std::unique_ptr<WorldPacket> > packets_t;
private:
packets_t packets;
};

@ -17,43 +17,36 @@ void PacketContainer::Packet(RakNet::BitStream *bs, bool send)
RW(event->action, send);
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
for (auto &&worldObject : event->worldObjects)
{
Object(worldObject, send);
if (send)
{
worldObject = event->worldObjects.at(i);
worldObject.containerItemCount = (unsigned int) (worldObject.containerItems.size());
}
else
worldObject.containerItems.clear();
Object(worldObject, send);
RW(worldObject.containerItemCount, send);
if (worldObject.containerItemCount > maxObjects || worldObject.refId.empty() || (worldObject.refNumIndex != 0 && worldObject.mpNum != 0))
if(!send)
{
worldObject.containerItems.clear();
worldObject.containerItems.resize(worldObject.containerItemCount);
}
if (worldObject.containerItemCount > maxObjects || worldObject.refId.empty()
|| (worldObject.refNumIndex != 0 && worldObject.mpNum != 0))
{
event->isValid = false;
return;
}
ContainerItem containerItem;
for (unsigned int j = 0; j < worldObject.containerItemCount; j++)
for(auto &&containerItem: worldObject.containerItems)
{
if (send)
containerItem = worldObject.containerItems.at(j);
RW(containerItem.refId, send);
RW(containerItem.count, send);
RW(containerItem.charge, send);
RW(containerItem.actionCount, send);
if (!send)
worldObject.containerItems.push_back(containerItem);
}
if (!send)
event->worldObjects.push_back(worldObject);
}
}

@ -31,16 +31,9 @@ void WorldPacket::Packet(RakNet::BitStream *bs, bool send)
if (!PacketHeader(bs, send))
return;
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
for (auto &&worldObject : event->worldObjects)
{
if (send)
worldObject = event->worldObjects.at(i);
Object(worldObject, send);
if (!send)
event->worldObjects.push_back(worldObject);
}
}
@ -61,10 +54,15 @@ bool WorldPacket::PacketHeader(RakNet::BitStream *bs, bool send)
return false;
}
if(!send)
{
event->worldObjects.resize(event->worldObjectCount);
}
if (hasCellData)
{
RW(event->cell.mData, send, 1);
RW(event->cell.mName, send, 1);
RW(event->cell.mData, send, true);
RW(event->cell.mName, send, true);
}
return true;

Loading…
Cancel
Save