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.
openmw-tes3mp/apps/openmw/mwmp/processors/PlayerProcessor.cpp

53 lines
1.3 KiB
C++

#include "../Networking.hpp"
#include "PlayerProcessor.hpp"
#include "../Main.hpp"
using namespace mwmp;
template<class T>
typename BasePacketProcessor<T>::processors_t BasePacketProcessor<T>::processors;
PlayerProcessor::~PlayerProcessor()
{
}
bool PlayerProcessor::Process(RakNet::Packet &packet)
{
RakNet::BitStream bsIn(&packet.data[1], packet.length, false);
bsIn.Read(guid);
PlayerPacket *myPacket = Main::get().getNetworking()->getPlayerPacket(packet.data[0]);
myPacket->SetReadStream(&bsIn);
/*if (myPacket == 0)
{
// error: packet not found
}*/
for (auto &processor : processors)
{
if (processor.first == packet.data[0])
{
myGuid = Main::get().getLocalPlayer()->guid;
request = packet.length == myPacket->headerSize();
BasePlayer *player = 0;
if (guid != myGuid)
player = PlayerList::getPlayer(guid);
else
player = Main::get().getLocalPlayer();
if (!request && !processor.second->avoidReading && player != 0)
{
myPacket->setPlayer(player);
myPacket->Read();
}
processor.second->Do(*myPacket, player);
return true;
}
}
return false;
}