From 0a1041bf5615f0f23d62ef841a1eec491d47a9b0 Mon Sep 17 00:00:00 2001 From: Koncord Date: Mon, 3 Apr 2017 05:32:49 +0800 Subject: [PATCH] [Server] Add WorldProcessor --- apps/openmw-mp/CMakeLists.txt | 1 + apps/openmw-mp/WorldProcessor.cpp | 45 +++++++++++++++++++++++++++++++ apps/openmw-mp/WorldProcessor.hpp | 38 ++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 apps/openmw-mp/WorldProcessor.cpp create mode 100644 apps/openmw-mp/WorldProcessor.hpp diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index 2f28792c3..2b85c288f 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -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 diff --git a/apps/openmw-mp/WorldProcessor.cpp b/apps/openmw-mp/WorldProcessor.cpp new file mode 100644 index 000000000..c389474e6 --- /dev/null +++ b/apps/openmw-mp/WorldProcessor.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; +} diff --git a/apps/openmw-mp/WorldProcessor.hpp b/apps/openmw-mp/WorldProcessor.hpp new file mode 100644 index 000000000..2ecd0f768 --- /dev/null +++ b/apps/openmw-mp/WorldProcessor.hpp @@ -0,0 +1,38 @@ +// +// Created by koncord on 03.04.17. +// + +#ifndef OPENMW_WORLDPROCESSOR_HPP +#define OPENMW_WORLDPROCESSOR_HPP + + +#include +#include +#include +#include +#include +#include +#include "Script/Script.hpp" +#include "Player.hpp" +//#include +//#include + +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 > processors_t; + typedef std::unordered_map > processors_t; + private: + static processors_t processors; + }; +} + +#endif //OPENMW_WORLDPROCESSOR_HPP