You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
#include "../Main.hpp"
|
|
#include "../Networking.hpp"
|
|
|
|
#include "WorldstateProcessor.hpp"
|
|
|
|
using namespace mwmp;
|
|
|
|
template<class T>
|
|
typename BasePacketProcessor<T>::processors_t BasePacketProcessor<T>::processors;
|
|
|
|
WorldstateProcessor::~WorldstateProcessor()
|
|
{
|
|
|
|
}
|
|
|
|
bool WorldstateProcessor::Process(RakNet::Packet &packet, Worldstate &worldstate)
|
|
{
|
|
RakNet::BitStream bsIn(&packet.data[1], packet.length, false);
|
|
bsIn.Read(guid);
|
|
worldstate.guid = guid;
|
|
|
|
WorldstatePacket *myPacket = Main::get().getNetworking()->getWorldstatePacket(packet.data[0]);
|
|
|
|
myPacket->setWorldstate(&worldstate);
|
|
myPacket->SetReadStream(&bsIn);
|
|
|
|
for (auto &processor : processors)
|
|
{
|
|
if (processor.first == packet.data[0])
|
|
{
|
|
myGuid = Main::get().getLocalPlayer()->guid;
|
|
request = packet.length == myPacket->headerSize();
|
|
|
|
worldstate.isValid = true;
|
|
|
|
if (!request && !processor.second->avoidReading)
|
|
myPacket->Read();
|
|
|
|
if (worldstate.isValid)
|
|
processor.second->Do(*myPacket, worldstate);
|
|
else
|
|
LOG_MESSAGE_SIMPLE(TimedLog::LOG_ERROR, "Received %s that failed integrity check and was ignored!", processor.second->strPacketID.c_str());
|
|
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|