mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-15 22:49:55 +00:00
53 lines
No EOL
1.7 KiB
C++
53 lines
No EOL
1.7 KiB
C++
//
|
|
// Created by koncord on 18.04.17.
|
|
//
|
|
|
|
#include <boost/foreach.hpp>
|
|
#include "ActorProcessor.hpp"
|
|
#include "Networking.hpp"
|
|
#include "Main.hpp"
|
|
|
|
using namespace mwmp;
|
|
|
|
ActorProcessor::processors_t ActorProcessor::processors;
|
|
|
|
bool ActorProcessor::Process(RakNet::Packet &packet, ActorList &actorList)
|
|
{
|
|
RakNet::BitStream bsIn(&packet.data[1], packet.length, false);
|
|
bsIn.Read(guid);
|
|
|
|
ActorPacket *myPacket = Main::get().getNetworking()->getActorPacket(packet.data[0]);
|
|
|
|
myPacket->setActorList(&actorList);
|
|
myPacket->SetReadStream(&bsIn);
|
|
|
|
BOOST_FOREACH(processors_t::value_type &processor, processors)
|
|
{
|
|
if (processor.first == packet.data[0])
|
|
{
|
|
myGuid = Main::get().getLocalPlayer()->guid;
|
|
request = packet.length == myPacket->headerSize();
|
|
|
|
if (!request && !processor.second->avoidReading)
|
|
{
|
|
myPacket->Read();
|
|
}
|
|
|
|
processor.second->Do(*myPacket, actorList);
|
|
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void ActorProcessor::AddProcessor(mwmp::ActorProcessor *processor)
|
|
{
|
|
BOOST_FOREACH(processors_t::value_type &p, processors)
|
|
{
|
|
if (processor->packetID == p.first)
|
|
throw std::logic_error("processor " + p.second->strPacketID + " already registered. Check " +
|
|
processor->className + " and " + p.second->className);
|
|
}
|
|
processors.insert(processors_t::value_type(processor->GetPacketID(), boost::shared_ptr<ActorProcessor>(processor)));
|
|
} |