2017-02-04 11:14:37 +00:00
|
|
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
2017-05-14 17:24:06 +00:00
|
|
|
#include <components/openmw-mp/Log.hpp>
|
2017-02-04 11:14:37 +00:00
|
|
|
#include "PacketContainer.hpp"
|
|
|
|
|
|
|
|
using namespace mwmp;
|
|
|
|
|
|
|
|
PacketContainer::PacketContainer(RakNet::RakPeerInterface *peer) : WorldPacket(peer)
|
|
|
|
{
|
|
|
|
packetID = ID_CONTAINER;
|
2017-06-02 19:10:47 +00:00
|
|
|
hasCellData = true;
|
2017-02-04 11:14:37 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 09:44:08 +00:00
|
|
|
void PacketContainer::Packet(RakNet::BitStream *bs, bool send)
|
2017-02-04 11:14:37 +00:00
|
|
|
{
|
2017-06-08 20:34:56 +00:00
|
|
|
if (!PacketHeader(bs, send))
|
2017-06-01 22:35:32 +00:00
|
|
|
return;
|
|
|
|
|
2017-06-02 19:10:47 +00:00
|
|
|
RW(event->action, send);
|
2017-02-04 18:14:39 +00:00
|
|
|
|
|
|
|
WorldObject worldObject;
|
2017-05-06 18:57:14 +00:00
|
|
|
for (unsigned int i = 0; i < event->worldObjectCount; i++)
|
2017-02-04 18:14:39 +00:00
|
|
|
{
|
|
|
|
if (send)
|
|
|
|
{
|
2017-05-06 18:57:14 +00:00
|
|
|
worldObject = event->worldObjects.at(i);
|
2017-06-02 19:10:47 +00:00
|
|
|
worldObject.containerItemCount = (unsigned int) (worldObject.containerItems.size());
|
2017-02-15 18:14:25 +00:00
|
|
|
}
|
|
|
|
else
|
2017-05-06 18:57:14 +00:00
|
|
|
worldObject.containerItems.clear();
|
2017-02-04 18:14:39 +00:00
|
|
|
|
2017-06-02 19:10:47 +00:00
|
|
|
Object(worldObject, send);
|
|
|
|
|
2017-05-06 18:57:14 +00:00
|
|
|
RW(worldObject.containerItemCount, send);
|
2017-02-04 18:14:39 +00:00
|
|
|
|
2017-06-01 22:35:32 +00:00
|
|
|
if (worldObject.containerItemCount > maxObjects || worldObject.refId.empty() || (worldObject.refNumIndex != 0 && worldObject.mpNum != 0))
|
2017-05-14 17:24:06 +00:00
|
|
|
{
|
|
|
|
event->isValid = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-15 18:14:25 +00:00
|
|
|
ContainerItem containerItem;
|
2017-02-04 18:14:39 +00:00
|
|
|
|
2017-05-14 17:24:06 +00:00
|
|
|
for (unsigned int j = 0; j < worldObject.containerItemCount; j++)
|
2017-02-04 18:14:39 +00:00
|
|
|
{
|
2017-02-15 18:14:25 +00:00
|
|
|
if (send)
|
2017-05-14 17:24:06 +00:00
|
|
|
containerItem = worldObject.containerItems.at(j);
|
2017-02-15 18:14:25 +00:00
|
|
|
|
|
|
|
RW(containerItem.refId, send);
|
|
|
|
RW(containerItem.count, send);
|
|
|
|
RW(containerItem.charge, send);
|
2017-12-23 11:16:38 +00:00
|
|
|
RW(containerItem.enchantmentCharge, send);
|
2017-02-15 18:14:25 +00:00
|
|
|
RW(containerItem.actionCount, send);
|
|
|
|
|
|
|
|
if (!send)
|
2017-05-06 18:57:14 +00:00
|
|
|
worldObject.containerItems.push_back(containerItem);
|
2017-02-04 18:14:39 +00:00
|
|
|
}
|
|
|
|
if (!send)
|
2017-05-06 18:57:14 +00:00
|
|
|
event->worldObjects.push_back(worldObject);
|
2017-02-04 18:14:39 +00:00
|
|
|
}
|
2017-02-04 11:14:37 +00:00
|
|
|
}
|