2016-10-19 17:36:11 +00:00
|
|
|
#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;
|
2016-10-19 17:36:11 +00:00
|
|
|
packetID = 0;
|
|
|
|
priority = HIGH_PRIORITY;
|
|
|
|
reliability = RELIABLE_ORDERED;
|
2017-05-08 16:38:48 +00:00
|
|
|
orderChannel = CHANNEL_WORLDEVENT;
|
2016-10-19 17:36:11 +00:00
|
|
|
this->peer = peer;
|
|
|
|
}
|
|
|
|
|
|
|
|
WorldPacket::~WorldPacket()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-03-06 09:44:08 +00:00
|
|
|
void WorldPacket::setEvent(BaseEvent *event)
|
2016-10-19 17:36:11 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
this->event = event;
|
|
|
|
guid = event->guid;
|
2016-10-19 17:36:11 +00:00
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
WorldObject worldObject;
|
|
|
|
for (unsigned int i = 0; i < event->worldObjectCount; i++)
|
|
|
|
{
|
|
|
|
if (send)
|
|
|
|
worldObject = event->worldObjects.at(i);
|
|
|
|
|
|
|
|
Object(worldObject, send);
|
|
|
|
|
|
|
|
if (!send)
|
|
|
|
event->worldObjects.push_back(worldObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WorldPacket::PacketHeader(RakNet::BitStream *bs, bool send)
|
|
|
|
{
|
|
|
|
BasePacket::Packet(bs, send);
|
|
|
|
|
|
|
|
if (send)
|
|
|
|
event->worldObjectCount = (unsigned int)(event->worldObjects.size());
|
|
|
|
else
|
|
|
|
event->worldObjects.clear();
|
|
|
|
|
|
|
|
RW(event->worldObjectCount, send);
|
|
|
|
|
|
|
|
if (event->worldObjectCount > maxObjects)
|
|
|
|
{
|
|
|
|
event->isValid = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-08 20:34:56 +00:00
|
|
|
if (hasCellData)
|
2017-06-02 19:10:47 +00:00
|
|
|
{
|
|
|
|
RW(event->cell.mData, send, 1);
|
|
|
|
RW(event->cell.mName, send, 1);
|
|
|
|
}
|
2017-06-08 20:28:58 +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);
|
|
|
|
}
|