[General] Move AddProcessor to BasePacketProcessor

pull/249/merge
Koncord 8 years ago
parent d9e98ec771
commit 0cf09adb44

@ -3,24 +3,14 @@
using namespace mwmp;
ActorProcessor::processors_t ActorProcessor::processors;
template<class T>
typename BasePacketProcessor<T>::processors_t BasePacketProcessor<T>::processors;
void ActorProcessor::Do(ActorPacket &packet, Player &player, BaseActorList &actorList)
{
packet.Send(true);
}
void ActorProcessor::AddProcessor(mwmp::ActorProcessor *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 ActorProcessor::Process(RakNet::Packet &packet, BaseActorList &actorList) noexcept
{
// Clear our BaseActorList before loading new data in it

@ -6,25 +6,18 @@
#include <components/openmw-mp/Packets/BasePacket.hpp>
#include <components/openmw-mp/Packets/Actor/ActorPacket.hpp>
#include <components/openmw-mp/NetworkMessages.hpp>
#include <unordered_map>
#include <memory>
#include "Script/Script.hpp"
#include "Player.hpp"
namespace mwmp
{
class ActorProcessor : public BasePacketProcessor
class ActorProcessor : public BasePacketProcessor<ActorProcessor>
{
public:
virtual void Do(ActorPacket &packet, Player &player, BaseActorList &actorList);
static bool Process(RakNet::Packet &packet, BaseActorList &actorList) noexcept;
static void AddProcessor(ActorProcessor *processor) noexcept;
typedef std::unordered_map<unsigned char, std::unique_ptr<ActorProcessor> > processors_t;
private:
static processors_t processors;
};
}

@ -4,22 +4,11 @@
#include "PlayerProcessor.hpp"
#include "Networking.hpp"
//#include <boost/foreach.hpp>
using namespace mwmp;
PlayerProcessor::processors_t PlayerProcessor::processors;
void PlayerProcessor::AddProcessor(PlayerProcessor *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));
}
template<class T>
typename BasePacketProcessor<T>::processors_t BasePacketProcessor<T>::processors;
bool PlayerProcessor::Process(RakNet::Packet &packet) noexcept
{

@ -8,24 +8,17 @@
#include <components/openmw-mp/Base/BasePacketProcessor.hpp>
#include <components/openmw-mp/Packets/BasePacket.hpp>
#include <components/openmw-mp/NetworkMessages.hpp>
#include <unordered_map>
#include <memory>
#include "Player.hpp"
namespace mwmp
{
class PlayerProcessor : public BasePacketProcessor
class PlayerProcessor : public BasePacketProcessor<PlayerProcessor>
{
public:
virtual void Do(PlayerPacket &packet, Player &player) = 0;
static bool Process(RakNet::Packet &packet) noexcept;
static void AddProcessor(PlayerProcessor *processor) noexcept;
typedef std::unordered_map<unsigned char, std::unique_ptr<PlayerProcessor> > processors_t;
private:
static processors_t processors;
};
}

@ -7,24 +7,14 @@
using namespace mwmp;
WorldProcessor::processors_t WorldProcessor::processors;
template<class T>
typename BasePacketProcessor<T>::processors_t BasePacketProcessor<T>::processors;
void WorldProcessor::Do(WorldPacket &packet, Player &player, BaseEvent &event)
{
packet.Send(true);
}
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, BaseEvent &event) noexcept
{
// Clear our BaseEvent before loading new data in it

@ -10,25 +10,18 @@
#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"
namespace mwmp
{
class WorldProcessor : public BasePacketProcessor
class WorldProcessor : public BasePacketProcessor<WorldProcessor>
{
public:
virtual void Do(WorldPacket &packet, Player &player, BaseEvent &event);
static bool Process(RakNet::Packet &packet, BaseEvent &event) noexcept;
static void AddProcessor(WorldProcessor *processor) noexcept;
typedef std::unordered_map<unsigned char, std::unique_ptr<WorldProcessor> > processors_t;
private:
static processors_t processors;
};
}

@ -8,7 +8,8 @@
using namespace mwmp;
ActorProcessor::processors_t ActorProcessor::processors;
template<class T>
typename BasePacketProcessor<T>::processors_t BasePacketProcessor<T>::processors;
bool ActorProcessor::Process(RakNet::Packet &packet, ActorList &actorList)
{
@ -44,14 +45,3 @@ bool ActorProcessor::Process(RakNet::Packet &packet, ActorList &actorList)
}
return false;
}
void ActorProcessor::AddProcessor(mwmp::ActorProcessor *processor)
{
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));
}

@ -8,25 +8,18 @@
#include <components/openmw-mp/Log.hpp>
#include <components/openmw-mp/NetworkMessages.hpp>
#include <components/openmw-mp/Packets/Actor/ActorPacket.hpp>
#include <unordered_map>
#include "../WorldEvent.hpp"
#include "../ActorList.hpp"
#include "BaseClientPacketProcessor.hpp"
namespace mwmp
{
class ActorProcessor : public BaseClientPacketProcessor
class ActorProcessor : public BasePacketProcessor<ActorProcessor>, public BaseClientPacketProcessor
{
public:
virtual void Do(ActorPacket &packet, ActorList &actorList) = 0;
static bool Process(RakNet::Packet &packet, ActorList &actorList);
static void AddProcessor(ActorProcessor *processor);
typedef std::unordered_map<unsigned char, std::unique_ptr<ActorProcessor> > processors_t;
private:
static processors_t processors;
};
}

@ -11,7 +11,7 @@
namespace mwmp
{
class BaseClientPacketProcessor : public BasePacketProcessor
class BaseClientPacketProcessor
{
public:
static void SetServerAddr(RakNet::SystemAddress addr)

@ -8,18 +8,8 @@
using namespace mwmp;
PlayerProcessor::processors_t PlayerProcessor::processors;
void PlayerProcessor::AddProcessor(PlayerProcessor *processor)
{
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));
}
template<class T>
typename BasePacketProcessor<T>::processors_t BasePacketProcessor<T>::processors;
bool PlayerProcessor::Process(RakNet::Packet &packet)
{

@ -8,7 +8,6 @@
#include <components/openmw-mp/Log.hpp>
#include <components/openmw-mp/NetworkMessages.hpp>
#include <components/openmw-mp/Packets/Player/PlayerPacket.hpp>
#include <unordered_map>
#include "../LocalPlayer.hpp"
#include "../DedicatedPlayer.hpp"
#include "../PlayerList.hpp"
@ -16,17 +15,12 @@
namespace mwmp
{
class PlayerProcessor : public BaseClientPacketProcessor
class PlayerProcessor : public BasePacketProcessor<PlayerProcessor>, public BaseClientPacketProcessor
{
public:
virtual void Do(PlayerPacket &packet, BasePlayer *player) = 0;
static bool Process(RakNet::Packet &packet);
static void AddProcessor(PlayerProcessor *processor);
typedef std::unordered_map<unsigned char, std::unique_ptr<PlayerProcessor> > processors_t;
private:
static processors_t processors;
};
}

@ -8,7 +8,8 @@
using namespace mwmp;
WorldProcessor::processors_t WorldProcessor::processors;
template<class T>
typename BasePacketProcessor<T>::processors_t BasePacketProcessor<T>::processors;
bool WorldProcessor::Process(RakNet::Packet &packet, WorldEvent &event)
{
@ -42,14 +43,3 @@ bool WorldProcessor::Process(RakNet::Packet &packet, WorldEvent &event)
}
return false;
}
void WorldProcessor::AddProcessor(mwmp::WorldProcessor *processor)
{
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));
}

@ -8,7 +8,6 @@
#include <components/openmw-mp/Log.hpp>
#include <components/openmw-mp/NetworkMessages.hpp>
#include <components/openmw-mp/Packets/World/WorldPacket.hpp>
#include <unordered_map>
#include "../WorldEvent.hpp"
#include "../LocalPlayer.hpp"
#include "../DedicatedPlayer.hpp"
@ -16,18 +15,12 @@
namespace mwmp
{
class WorldProcessor : public BaseClientPacketProcessor
class WorldProcessor : public BasePacketProcessor<WorldProcessor>, public BaseClientPacketProcessor
{
public:
virtual void Do(WorldPacket &packet, WorldEvent &event) = 0;
static bool Process(RakNet::Packet &packet, WorldEvent &event);
static void AddProcessor(WorldProcessor *processor);
typedef std::unordered_map<unsigned char, std::unique_ptr<WorldProcessor> > processors_t;
private:
static processors_t processors;
};
}

@ -6,12 +6,16 @@
#define OPENMW_BASEPACKETPROCESSOR_HPP
#include <string>
#include <memory>
#include <unordered_map>
#define BPP_INIT(packet_id) packetID = packet_id; strPacketID = #packet_id; className = typeid(this).name(); avoidReading = false;
template<typename Proccessor>
class BasePacketProcessor
{
public:
typedef std::unordered_map<unsigned char, std::unique_ptr<Proccessor>> processors_t;
unsigned char GetPacketID()
{
return packetID;
@ -26,12 +30,22 @@ public:
return className;
}
static void AddProcessor(Proccessor *processor)
{
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(typename processors_t::value_type(processor->GetPacketID(), processor));
}
protected:
unsigned char packetID;
std::string strPacketID;
std::string className;
bool avoidReading;
static processors_t processors;
};
#endif //OPENMW_BASEPACKETPROCESSOR_HPP

Loading…
Cancel
Save