2017-04-09 05:51:28 +00:00
|
|
|
#include "ActorProcessor.hpp"
|
|
|
|
#include "Networking.hpp"
|
|
|
|
|
|
|
|
using namespace mwmp;
|
|
|
|
|
|
|
|
ActorProcessor::processors_t ActorProcessor::processors;
|
|
|
|
|
2017-04-09 13:32:44 +00:00
|
|
|
void ActorProcessor::Do(ActorPacket &packet, Player &player, BaseActorList &actorList)
|
2017-04-09 05:51:28 +00:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2017-04-09 13:32:44 +00:00
|
|
|
bool ActorProcessor::Process(RakNet::Packet &packet, BaseActorList &actorList) noexcept
|
2017-04-09 05:51:28 +00:00
|
|
|
{
|
2017-04-09 13:32:44 +00:00
|
|
|
// Clear our BaseActorList before loading new data in it
|
|
|
|
actorList.cell.blank();
|
|
|
|
actorList.baseActors.clear();
|
|
|
|
actorList.guid = packet.guid;
|
2017-04-30 00:32:04 +00:00
|
|
|
|
2017-04-09 05:51:28 +00:00
|
|
|
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]);
|
|
|
|
|
2017-04-09 13:32:44 +00:00
|
|
|
myPacket->setActorList(&actorList);
|
2017-05-16 11:20:40 +00:00
|
|
|
actorList.isValid = true;
|
2017-04-09 05:51:28 +00:00
|
|
|
|
|
|
|
if (!processor.second->avoidReading)
|
|
|
|
myPacket->Read();
|
|
|
|
|
2017-05-16 11:20:40 +00:00
|
|
|
if (actorList.isValid)
|
|
|
|
processor.second->Do(*myPacket, *player, actorList);
|
|
|
|
else
|
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Received %s that failed integrity check and was ignored!", processor.second->strPacketID.c_str());
|
|
|
|
|
2017-04-09 05:51:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|