[Server] Add WorldProcessor

0.6.1
Koncord 8 years ago
parent e7b5097c13
commit 0a1041bf56

@ -80,6 +80,7 @@ set(SERVER
Script/Functions/Cells.cpp Script/Functions/World.cpp Script/Functions/Miscellaneous.cpp
PlayerProcessor.cpp
WorldProcessor.cpp
ProcessorInitializer.cpp
Script/API/TimerAPI.cpp Script/API/PublicFnAPI.cpp

@ -0,0 +1,45 @@
//
// Created by koncord on 03.04.17.
//
#include "WorldProcessor.hpp"
#include "Networking.hpp"
using namespace mwmp;
WorldProcessor::processors_t WorldProcessor::processors;
void WorldProcessor::AddProcessor(mwmp::WorldProcessor *processor) noexcept
{
for(auto &p : processors)
{
if(processor->packetID == p.first)
throw std::logic_error("processor " + p.second->strPacketID + " already registered. Check " +
processor->className + " and " + p.second->className);
}
processors.insert(processors_t::value_type(processor->GetPacketID(), processor));
}
bool WorldProcessor::Process(RakNet::Packet &packet) noexcept
{
BaseEvent baseEvent;
baseEvent.cell.blank();
baseEvent.objectChanges.objects.clear();
baseEvent.guid = packet.guid;
for(auto &processor : processors)
{
if(processor.first == packet.data[0])
{
Player *player = Players::getPlayer(packet.guid);
WorldPacket *myPacket = Networking::get().getWorldController()->GetPacket(packet.data[0]);
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received %s from %s", processor.second->strPacketID.c_str(),
player->npc.mName.c_str());
myPacket->setEvent(&baseEvent);
myPacket->Read();
processor.second->Do(*myPacket, *player, baseEvent);
return true;
}
}
return false;
}

@ -0,0 +1,38 @@
//
// Created by koncord on 03.04.17.
//
#ifndef OPENMW_WORLDPROCESSOR_HPP
#define OPENMW_WORLDPROCESSOR_HPP
#include <components/openmw-mp/Base/BasePacketProcessor.hpp>
#include <components/openmw-mp/Packets/BasePacket.hpp>
#include <components/openmw-mp/Packets/World/WorldPacket.hpp>
#include <components/openmw-mp/NetworkMessages.hpp>
#include <unordered_map>
#include <memory>
#include "Script/Script.hpp"
#include "Player.hpp"
//#include <boost/unordered_map.hpp>
//#include <boost/shared_ptr.hpp>
namespace mwmp
{
class WorldProcessor : public BasePacketProcessor
{
public:
virtual void Do(WorldPacket &packet, Player &player, BaseEvent &event) = 0;
static bool Process(RakNet::Packet &packet) noexcept;
static void AddProcessor(WorldProcessor *processor) noexcept;
//typedef boost::unordered_map<unsigned char, boost::shared_ptr<WorldProcessor> > processors_t;
typedef std::unordered_map<unsigned char, std::unique_ptr<WorldProcessor> > processors_t;
private:
static processors_t processors;
};
}
#endif //OPENMW_WORLDPROCESSOR_HPP
Loading…
Cancel
Save