openmw-tes3coop/components/openmw-mp/Packets/Actor/ActorPacket.cpp

63 lines
1.3 KiB
C++
Raw Normal View History

#include <components/openmw-mp/NetworkMessages.hpp>
#include <PacketPriority.h>
#include <RakPeer.h>
#include "ActorPacket.hpp"
using namespace mwmp;
ActorPacket::ActorPacket(RakNet::RakPeerInterface *peer) : BasePacket(peer)
{
packetID = 0;
priority = HIGH_PRIORITY;
reliability = RELIABLE_ORDERED;
orderChannel = CHANNEL_ACTOR;
this->peer = peer;
}
void ActorPacket::setActorList(BaseActorList *actorList)
{
this->actorList = actorList;
guid = actorList->guid;
}
2017-05-28 07:23:16 +00:00
void ActorPacket::Packet(RakNet::BitStream *bs, bool send)
2017-06-02 19:42:10 +00:00
{
2017-06-08 20:34:56 +00:00
if (!PacketHeader(bs, send))
2017-06-02 19:42:10 +00:00
return;
for(auto &actor : actorList->baseActors)
2017-06-02 19:42:10 +00:00
{
RW(actor->refNumIndex, send);
RW(actor->mpNum, send);
Actor(*actor, send);
2017-06-02 19:42:10 +00:00
}
2017-06-02 19:42:10 +00:00
}
bool ActorPacket::PacketHeader(RakNet::BitStream *bs, bool send)
2017-05-28 07:23:16 +00:00
{
BasePacket::Packet(bs, send);
RW(actorList->cell.mData, send, true);
RW(actorList->cell.mName, send, true);
2017-06-02 19:42:10 +00:00
uint32_t actorCount;
2017-06-02 19:42:10 +00:00
if (send)
actorCount = (uint32_t)(actorList->baseActors.size());
RW(actorCount, send);
2017-06-02 19:42:10 +00:00
if(!send)
{
actorList->baseActors.clear();
actorList->baseActors.resize(actorCount, std::make_shared<BaseActor>());
}
2017-06-02 19:42:10 +00:00
if (actorCount > maxActors)
{
2017-06-02 19:42:10 +00:00
actorList->isValid = false;
return false;
}
2017-06-02 19:42:10 +00:00
return true;
}