2018-05-15 19:07:06 +00:00
|
|
|
#include "ObjectProcessor.hpp"
|
2017-04-02 21:32:49 +00:00
|
|
|
#include "Networking.hpp"
|
|
|
|
|
|
|
|
using namespace mwmp;
|
|
|
|
|
2017-06-30 12:09:05 +00:00
|
|
|
template<class T>
|
|
|
|
typename BasePacketProcessor<T>::processors_t BasePacketProcessor<T>::processors;
|
2017-04-02 21:32:49 +00:00
|
|
|
|
2018-05-15 19:07:06 +00:00
|
|
|
void ObjectProcessor::Do(ObjectPacket &packet, Player &player, BaseObjectList &objectList)
|
2017-04-02 21:56:29 +00:00
|
|
|
{
|
|
|
|
packet.Send(true);
|
|
|
|
}
|
|
|
|
|
2018-05-15 19:07:06 +00:00
|
|
|
bool ObjectProcessor::Process(RakNet::Packet &packet, BaseObjectList &objectList) noexcept
|
2017-04-02 21:32:49 +00:00
|
|
|
{
|
2018-05-12 21:42:24 +00:00
|
|
|
// Clear our BaseObjectList before loading new data in it
|
|
|
|
objectList.cell.blank();
|
|
|
|
objectList.baseObjects.clear();
|
|
|
|
objectList.guid = packet.guid;
|
2017-04-30 00:32:04 +00:00
|
|
|
|
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);
|
2018-05-12 16:40:00 +00:00
|
|
|
ObjectPacket *myPacket = Networking::get().getObjectPacketController()->GetPacket(packet.data[0]);
|
2017-04-02 21:32:49 +00:00
|
|
|
|
2018-05-12 21:42:24 +00:00
|
|
|
myPacket->setObjectList(&objectList);
|
|
|
|
objectList.isValid = true;
|
2017-04-02 22:44:14 +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-04-02 22:44:14 +00:00
|
|
|
|
2018-05-12 21:42:24 +00:00
|
|
|
if (objectList.isValid)
|
|
|
|
processor.second->Do(*myPacket, *player, objectList);
|
2017-05-14 17:24:06 +00:00
|
|
|
else
|
2019-08-19 18:39:33 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(TimedLog::LOG_ERROR, "Received %s that failed integrity check and was ignored!", processor.second->strPacketID.c_str());
|
2017-05-14 17:24:06 +00:00
|
|
|
|
2017-04-02 21:32:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|