1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 02:49:55 +00:00
openmw-tes3mp/apps/openmw-mp/ActorProcessor.cpp

47 lines
1.4 KiB
C++

#include "ActorProcessor.hpp"
#include "Networking.hpp"
using namespace mwmp;
ActorProcessor::processors_t ActorProcessor::processors;
void ActorProcessor::Do(ActorPacket &packet, Player &player, BaseEvent &event)
{
packet.Send(true);
}
void ActorProcessor::AddProcessor(mwmp::ActorProcessor *processor) noexcept
{
for (auto &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(), processor));
}
bool ActorProcessor::Process(RakNet::Packet &packet, BaseEvent &event) noexcept
{
// Clear our BaseEvent before loading new data in it
event.cell.blank();
event.objectChanges.objects.clear();
event.guid = packet.guid;
for (auto &processor : processors)
{
if (processor.first == packet.data[0])
{
Player *player = Players::getPlayer(packet.guid);
ActorPacket *myPacket = Networking::get().getActorPacketController()->GetPacket(packet.data[0]);
myPacket->setEvent(&event);
if (!processor.second->avoidReading)
myPacket->Read();
processor.second->Do(*myPacket, *player, event);
return true;
}
}
return false;
}