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

61 lines
1.7 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);
WorldObject worldObject;
for (unsigned int i = 0; i < event->worldObjectCount; i++)
{
if (send)
{
worldObject = event->worldObjects.at(i);
2017-06-02 19:10:47 +00:00
worldObject.containerItemCount = (unsigned int) (worldObject.containerItems.size());
}
else
worldObject.containerItems.clear();
2017-06-02 19:10:47 +00:00
Object(worldObject, send);
RW(worldObject.containerItemCount, send);
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++)
{
if (send)
containerItem = worldObject.containerItems.at(j);
RW(containerItem.refId, send);
RW(containerItem.count, send);
RW(containerItem.charge, send);
RW(containerItem.enchantmentCharge, send);
RW(containerItem.actionCount, send);
if (!send)
worldObject.containerItems.push_back(containerItem);
}
if (!send)
event->worldObjects.push_back(worldObject);
}
}