[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)
return;
// Clear our baseEvent before loading new data in it
baseEvent.cell.blank();
baseEvent.objectChanges.objects.clear();
baseEvent.guid = packet->guid;
if (!WorldProcessor::Process(*packet))
if (!WorldProcessor::Process(*packet, baseEvent))
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));
}
bool WorldProcessor::Process(RakNet::Packet &packet) noexcept
bool WorldProcessor::Process(RakNet::Packet &packet, BaseEvent &event) noexcept
{
BaseEvent baseEvent;
baseEvent.cell.blank();
baseEvent.objectChanges.objects.clear();
baseEvent.guid = packet.guid;
// Clear our BaseEvent before loading new data in it
event.cell.blank();
event.objectChanges.objects.clear();
event.guid = packet.guid;
for (auto &processor : processors)
{
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(),
player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->setEvent(&event);
if (!processor.second->avoidReading)
myPacket->Read();
processor.second->Do(*myPacket, *player, baseEvent);
processor.second->Do(*myPacket, *player, event);
return true;
}
}

@ -25,7 +25,7 @@ namespace mwmp
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;
//typedef boost::unordered_map<unsigned char, boost::shared_ptr<WorldProcessor> > processors_t;

Loading…
Cancel
Save