1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 13:19:54 +00:00
openmw-tes3mp/apps/openmw/mwmp/processors/WorldProcessor.cpp

56 lines
1.6 KiB
C++
Raw Normal View History

//
// Created by koncord on 16.04.17.
//
2017-04-18 03:35:50 +00:00
#include "WorldProcessor.hpp"
2017-06-06 16:06:10 +00:00
#include "../Main.hpp"
#include "../Networking.hpp"
using namespace mwmp;
2017-04-18 03:35:50 +00:00
WorldProcessor::processors_t WorldProcessor::processors;
2017-04-18 03:35:50 +00:00
bool WorldProcessor::Process(RakNet::Packet &packet, WorldEvent &event)
{
RakNet::BitStream bsIn(&packet.data[1], packet.length, false);
bsIn.Read(guid);
WorldPacket *myPacket = Main::get().getNetworking()->getWorldPacket(packet.data[0]);
myPacket->setEvent(&event);
myPacket->SetReadStream(&bsIn);
for (auto &processor: processors)
{
2017-05-02 19:47:58 +00:00
if (processor.first == packet.data[0])
{
2017-04-18 07:05:32 +00:00
myGuid = Main::get().getLocalPlayer()->guid;
request = packet.length == myPacket->headerSize();
event.isValid = true;
2017-05-02 19:47:58 +00:00
if (!request && !processor.second->avoidReading)
myPacket->Read();
if (event.isValid)
processor.second->Do(*myPacket, event);
else
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Received %s that failed integrity check and was ignored!", processor.second->strPacketID.c_str());
return true;
}
}
return false;
}
2017-04-18 03:35:50 +00:00
void WorldProcessor::AddProcessor(mwmp::WorldProcessor *processor)
{
for (auto &p : processors)
{
2017-05-02 19:47:58 +00:00
if (processor->packetID == p.first)
throw std::logic_error("processor " + p.second->strPacketID + " already registered. Check " +
processor->className + " and " + p.second->className);
}
2017-06-27 07:25:30 +00:00
processors.insert(processors_t::value_type(processor->GetPacketID(), processor));
}