You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3mp/apps/openmw-mp/WorldProcessor.cpp

52 lines
1.5 KiB
C++

//
// Created by koncord on 03.04.17.
//
#include "WorldProcessor.hpp"
#include "Networking.hpp"
using namespace mwmp;
WorldProcessor::processors_t WorldProcessor::processors;
void WorldProcessor::Do(WorldPacket &packet, Player &player, BaseEvent &event)
{
packet.Send(true);
}
void WorldProcessor::AddProcessor(mwmp::WorldProcessor *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 WorldProcessor::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);
WorldPacket *myPacket = Networking::get().getWorldPacketController()->GetPacket(packet.data[0]);
myPacket->setEvent(&event);
if (!processor.second->avoidReading)
myPacket->Read();
processor.second->Do(*myPacket, *player, event);
return true;
}
}
return false;
}