openmw-tes3coop/apps/openmw-mp/WorldProcessor.cpp

54 lines
1.6 KiB
C++
Raw Normal View History

2017-04-02 21:32:49 +00:00
//
// 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);
}
2017-04-02 21:32:49 +00:00
void WorldProcessor::AddProcessor(mwmp::WorldProcessor *processor) noexcept
{
2017-04-04 00:05:37 +00:00
for (auto &p : processors)
2017-04-02 21:32:49 +00:00
{
2017-04-04 00:05:37 +00:00
if (processor->packetID == p.first)
2017-04-02 21:32:49 +00:00
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) noexcept
{
BaseEvent baseEvent;
baseEvent.cell.blank();
baseEvent.objectChanges.objects.clear();
baseEvent.guid = packet.guid;
2017-04-04 00:05:37 +00:00
for (auto &processor : processors)
2017-04-02 21:32:49 +00:00
{
2017-04-04 00:05:37 +00:00
if (processor.first == packet.data[0])
2017-04-02 21:32:49 +00:00
{
Player *player = Players::getPlayer(packet.guid);
WorldPacket *myPacket = Networking::get().getWorldController()->GetPacket(packet.data[0]);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received %s from %s", processor.second->strPacketID.c_str(),
player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
2017-04-04 00:05:37 +00:00
if (!processor.second->avoidReading)
2017-04-02 22:13:56 +00:00
myPacket->Read();
2017-04-02 21:32:49 +00:00
processor.second->Do(*myPacket, *player, baseEvent);
return true;
}
}
return false;
}