diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index de33bb2bb..f5adb95d3 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -96,8 +96,9 @@ add_openmw_dir (mwbase inputmanager windowmanager statemanager ) -add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer LocalActor DedicatedActor ActorList WorldEvent Cell CellController MechanicsHelper GUIChat GUILogin - GUIController PlayerMarkerCollection GUIDialogList WorldController PlayerProcessor WorldProcessor ProcessorInitializer) +add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer LocalActor DedicatedActor ActorList WorldEvent Cell + CellController MechanicsHelper GUIChat GUILogin GUIController PlayerMarkerCollection GUIDialogList WorldController + PlayerProcessor WorldProcessor ActorProcessor ProcessorInitializer) # Main executable diff --git a/apps/openmw/mwmp/ActorProcessor.cpp b/apps/openmw/mwmp/ActorProcessor.cpp new file mode 100644 index 000000000..35bca9b27 --- /dev/null +++ b/apps/openmw/mwmp/ActorProcessor.cpp @@ -0,0 +1,60 @@ +// +// Created by koncord on 18.04.17. +// + +#include +#include "ActorProcessor.hpp" +#include "Networking.hpp" +#include "Main.hpp" + +using namespace mwmp; + +ActorProcessor::processors_t ActorProcessor::processors; +RakNet::RakNetGUID ActorProcessor::guid; +RakNet::SystemAddress ActorProcessor::serverAddr; +bool ActorProcessor::request; + +bool ActorProcessor::Process(RakNet::Packet &packet, ActorList &actorList) +{ + RakNet::BitStream bsIn(&packet.data[1], packet.length, false); + bsIn.Read(guid); + + ActorPacket *myPacket = Main::get().getNetworking()->getActorPacket(packet.data[0]); + + myPacket->setActorList(&actorList); + myPacket->SetReadStream(&bsIn); + + BOOST_FOREACH(processors_t::value_type &processor, processors) + { + if(processor.first == packet.data[0]) + { + request = packet.length == myPacket->headerSize(); + + if(!request && !processor.second->avoidReading) + { + myPacket->Read(); + } + + processor.second->Do(*myPacket, actorList); + + return true; + } + } + return false; +} + +void ActorProcessor::AddProcessor(mwmp::ActorProcessor *processor) +{ + BOOST_FOREACH(processors_t::value_type &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(), boost::shared_ptr(processor))); +} + +LocalPlayer *ActorProcessor::getLocalPlayer() +{ + return Main::get().getLocalPlayer(); +} diff --git a/apps/openmw/mwmp/ActorProcessor.hpp b/apps/openmw/mwmp/ActorProcessor.hpp new file mode 100644 index 000000000..66e18b3d3 --- /dev/null +++ b/apps/openmw/mwmp/ActorProcessor.hpp @@ -0,0 +1,52 @@ +// +// Created by koncord on 18.04.17. +// + +#ifndef OPENMW_ACTORPROCESSOR_HPP +#define OPENMW_ACTORPROCESSOR_HPP + +#include +#include + +#include +#include +#include +#include +#include "WorldEvent.hpp" +#include "LocalPlayer.hpp" +#include "DedicatedPlayer.hpp" +#include "ActorList.hpp" + +namespace mwmp +{ + class ActorProcessor : public BasePacketProcessor + { + public: + virtual void Do(ActorPacket &packet, ActorList &actorList) = 0; + + static bool Process(RakNet::Packet &packet, ActorList &actorList); + static void AddProcessor(ActorProcessor *processor); + static void SetServerAddr(RakNet::SystemAddress addr) + { + serverAddr = addr; + } + + typedef boost::unordered_map > processors_t; + + protected: + inline bool isRequest() + { + return request; + } + LocalPlayer *getLocalPlayer(); + protected: + static RakNet::RakNetGUID guid; + static RakNet::SystemAddress serverAddr; + private: + static processors_t processors; + static bool request; + }; +} + + +#endif //OPENMW_ACTORPROCESSOR_HPP