1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 20:53:50 +00:00
openmw-tes3mp/components/openmw-mp/Packets/World/PacketContainer.cpp

53 lines
1.4 KiB
C++
Raw Normal View History

#include <components/openmw-mp/NetworkMessages.hpp>
#include <components/openmw-mp/Log.hpp>
#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;
}
void PacketContainer::Packet(RakNet::BitStream *bs, bool send)
{
2017-06-08 20:34:56 +00:00
if (!PacketHeader(bs, send))
return;
2017-06-02 19:10:47 +00:00
RW(event->action, send);
for (auto &&worldObject : event->worldObjects)
{
Object(worldObject, send);
if (send)
{
2017-06-02 19:10:47 +00:00
worldObject.containerItemCount = (unsigned int) (worldObject.containerItems.size());
}
2017-06-02 19:10:47 +00:00
RW(worldObject.containerItemCount, send);
2017-11-29 11:00:22 +00:00
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;
}
2017-11-29 11:00:22 +00:00
for (auto &&containerItem: worldObject.containerItems)
{
RW(containerItem.refId, send);
RW(containerItem.count, send);
RW(containerItem.charge, send);
RW(containerItem.actionCount, send);
}
}
}