2017-03-31 18:35:34 +00:00
|
|
|
//
|
|
|
|
// Created by koncord on 31.03.17.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "PlayerProcessor.hpp"
|
|
|
|
#include "Networking.hpp"
|
|
|
|
//#include <boost/foreach.hpp>
|
|
|
|
|
|
|
|
using namespace mwmp;
|
|
|
|
|
|
|
|
PlayerProcessor::processors_t PlayerProcessor::processors;
|
|
|
|
|
|
|
|
void PlayerProcessor::AddProcessor(PlayerProcessor *processor) noexcept
|
|
|
|
{
|
2017-04-04 00:05:37 +00:00
|
|
|
for (auto &p : processors)
|
2017-03-31 18:35:34 +00:00
|
|
|
{
|
2017-04-04 00:05:37 +00:00
|
|
|
if (processor->packetID == p.first)
|
2017-03-31 18:35:34 +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 PlayerProcessor::Process(RakNet::Packet &packet) noexcept
|
|
|
|
{
|
|
|
|
//BOOST_FOREACH(processors_t::value_type &processor, processors)
|
2017-04-04 00:05:37 +00:00
|
|
|
for (auto &processor : processors)
|
2017-03-31 18:35:34 +00:00
|
|
|
{
|
2017-04-04 00:05:37 +00:00
|
|
|
if (processor.first == packet.data[0])
|
2017-03-31 18:35:34 +00:00
|
|
|
{
|
|
|
|
Player *player = Players::getPlayer(packet.guid);
|
2017-04-09 05:51:28 +00:00
|
|
|
PlayerPacket *myPacket = Networking::get().getPlayerPacketController()->GetPacket(packet.data[0]);
|
2017-04-02 22:05:18 +00:00
|
|
|
myPacket->setPlayer(player);
|
2017-03-31 18:35:34 +00:00
|
|
|
|
2017-04-04 00:05:37 +00:00
|
|
|
if (!processor.second->avoidReading)
|
2017-04-02 22:13:56 +00:00
|
|
|
myPacket->Read();
|
|
|
|
|
2017-03-31 18:35:34 +00:00
|
|
|
processor.second->Do(*myPacket, *player);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2017-05-16 11:20:40 +00:00
|
|
|
}
|