1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-22 15:53:52 +00:00
openmw-tes3mp/components/openmw-mp/Packets/World/WorldPacket.cpp

73 lines
1.5 KiB
C++
Raw Normal View History

#include <components/openmw-mp/NetworkMessages.hpp>
#include <PacketPriority.h>
#include <RakPeer.h>
#include "WorldPacket.hpp"
using namespace mwmp;
WorldPacket::WorldPacket(RakNet::RakPeerInterface *peer) : BasePacket(peer)
{
2017-06-02 19:10:47 +00:00
hasCellData = false;
packetID = 0;
priority = HIGH_PRIORITY;
reliability = RELIABLE_ORDERED;
orderChannel = CHANNEL_WORLDEVENT;
this->peer = peer;
}
void WorldPacket::setEvent(BaseEvent *event)
{
this->event = event;
guid = event->guid;
}
2017-06-02 19:10:47 +00:00
void WorldPacket::Packet(RakNet::BitStream *bs, bool send)
{
2017-06-08 20:34:56 +00:00
if (!PacketHeader(bs, send))
2017-06-02 19:10:47 +00:00
return;
for (auto &&worldObject : event->worldObjects)
2017-06-02 19:10:47 +00:00
{
Object(worldObject, send);
}
}
bool WorldPacket::PacketHeader(RakNet::BitStream *bs, bool send)
{
BasePacket::Packet(bs, send);
uint32_t worldObjectCount;
2017-06-02 19:10:47 +00:00
if (send)
worldObjectCount = (uint32_t) (event->worldObjects.size());
2017-06-02 19:10:47 +00:00
RW(worldObjectCount, send);
2017-06-02 19:10:47 +00:00
if (worldObjectCount > maxObjects)
2017-06-02 19:10:47 +00:00
{
event->isValid = false;
return false;
}
2017-11-29 11:00:22 +00:00
if (!send)
{
event->worldObjects.clear();
event->worldObjects.resize(worldObjectCount);
}
2017-06-08 20:34:56 +00:00
if (hasCellData)
2017-06-02 19:10:47 +00:00
{
RW(event->cell.mData, send, true);
RW(event->cell.mName, send, true);
2017-06-02 19:10:47 +00:00
}
2017-06-02 19:10:47 +00:00
return true;
}
void WorldPacket::Object(WorldObject &worldObject, bool send)
{
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.mpNum, send);
}