[Server] Fix script crashes by reusing BaseEvent in WorldProcessor

pull/199/head
David Cernat 8 years ago
parent 5ff40c5563
commit d8712ee1ea

@ -158,12 +158,7 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
if (!player->isHandshaked() || player->getLoadState() != Player::POSTLOADED) if (!player->isHandshaked() || player->getLoadState() != Player::POSTLOADED)
return; return;
// Clear our baseEvent before loading new data in it if (!WorldProcessor::Process(*packet, baseEvent))
baseEvent.cell.blank();
baseEvent.objectChanges.objects.clear();
baseEvent.guid = packet->guid;
if (!WorldProcessor::Process(*packet))
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Unhandled WorldPacket with identifier %i has arrived", packet->data[0]); LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Unhandled WorldPacket with identifier %i has arrived", packet->data[0]);
} }

@ -25,12 +25,12 @@ void WorldProcessor::AddProcessor(mwmp::WorldProcessor *processor) noexcept
processors.insert(processors_t::value_type(processor->GetPacketID(), processor)); processors.insert(processors_t::value_type(processor->GetPacketID(), processor));
} }
bool WorldProcessor::Process(RakNet::Packet &packet) noexcept bool WorldProcessor::Process(RakNet::Packet &packet, BaseEvent &event) noexcept
{ {
BaseEvent baseEvent; // Clear our BaseEvent before loading new data in it
baseEvent.cell.blank(); event.cell.blank();
baseEvent.objectChanges.objects.clear(); event.objectChanges.objects.clear();
baseEvent.guid = packet.guid; event.guid = packet.guid;
for (auto &processor : processors) for (auto &processor : processors)
{ {
if (processor.first == packet.data[0]) if (processor.first == packet.data[0])
@ -40,12 +40,12 @@ bool WorldProcessor::Process(RakNet::Packet &packet) noexcept
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received %s from %s", processor.second->strPacketID.c_str(), LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received %s from %s", processor.second->strPacketID.c_str(),
player->npc.mName.c_str()); player->npc.mName.c_str());
myPacket->setEvent(&baseEvent); myPacket->setEvent(&event);
if (!processor.second->avoidReading) if (!processor.second->avoidReading)
myPacket->Read(); myPacket->Read();
processor.second->Do(*myPacket, *player, baseEvent); processor.second->Do(*myPacket, *player, event);
return true; return true;
} }
} }

@ -25,7 +25,7 @@ namespace mwmp
virtual void Do(WorldPacket &packet, Player &player, BaseEvent &event); virtual void Do(WorldPacket &packet, Player &player, BaseEvent &event);
static bool Process(RakNet::Packet &packet) noexcept; static bool Process(RakNet::Packet &packet, BaseEvent &event) noexcept;
static void AddProcessor(WorldProcessor *processor) noexcept; static void AddProcessor(WorldProcessor *processor) noexcept;
//typedef boost::unordered_map<unsigned char, boost::shared_ptr<WorldProcessor> > processors_t; //typedef boost::unordered_map<unsigned char, boost::shared_ptr<WorldProcessor> > processors_t;

Loading…
Cancel
Save