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
|
|
|
|
2017-11-28 14:05:10 +00:00
|
|
|
for (auto &&worldObject : event->worldObjects)
|
2017-02-04 18:14:39 +00:00
|
|
|
{
|
2017-11-28 14:05:10 +00:00
|
|
|
Object(worldObject, send);
|
|
|
|
|
2017-02-04 18:14:39 +00:00
|
|
|
if (send)
|
|
|
|
{
|
2017-06-02 19:10:47 +00:00
|
|
|
worldObject.containerItemCount = (unsigned int) (worldObject.containerItems.size());
|
2017-02-15 18:14:25 +00:00
|
|
|
}
|
2017-06-02 19:10:47 +00:00
|
|
|
|
2017-05-06 18:57:14 +00:00
|
|
|
RW(worldObject.containerItemCount, send);
|
2017-02-04 18:14:39 +00:00
|
|
|
|
2017-11-29 11:00:22 +00:00
|
|
|
if (!send)
|
2017-11-28 14:05:10 +00:00
|
|
|
{
|
|
|
|
worldObject.containerItems.clear();
|
|
|
|
worldObject.containerItems.resize(worldObject.containerItemCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-11-29 11:00:22 +00:00
|
|
|
for (auto &&containerItem: worldObject.containerItems)
|
2017-02-04 18:14:39 +00:00
|
|
|
{
|
2017-02-15 18:14:25 +00:00
|
|
|
RW(containerItem.refId, send);
|
|
|
|
RW(containerItem.count, send);
|
|
|
|
RW(containerItem.charge, send);
|
|
|
|
RW(containerItem.actionCount, send);
|
2017-02-04 18:14:39 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-04 11:14:37 +00:00
|
|
|
}
|