diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index f5adb95d3..c9f36691d 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -98,7 +98,7 @@ add_openmw_dir (mwbase 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) + BaseClientPacketProcessor PlayerProcessor WorldProcessor ActorProcessor ProcessorInitializer) # Main executable diff --git a/apps/openmw/mwmp/ActorProcessor.cpp b/apps/openmw/mwmp/ActorProcessor.cpp index 35bca9b27..4400aae22 100644 --- a/apps/openmw/mwmp/ActorProcessor.cpp +++ b/apps/openmw/mwmp/ActorProcessor.cpp @@ -10,9 +10,6 @@ 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) { @@ -28,6 +25,7 @@ bool ActorProcessor::Process(RakNet::Packet &packet, ActorList &actorList) { if(processor.first == packet.data[0]) { + myGuid = Main::get().getLocalPlayer()->guid; request = packet.length == myPacket->headerSize(); if(!request && !processor.second->avoidReading) @@ -52,9 +50,4 @@ void ActorProcessor::AddProcessor(mwmp::ActorProcessor *processor) 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(); -} +} \ No newline at end of file diff --git a/apps/openmw/mwmp/ActorProcessor.hpp b/apps/openmw/mwmp/ActorProcessor.hpp index 66e18b3d3..920bbb1e8 100644 --- a/apps/openmw/mwmp/ActorProcessor.hpp +++ b/apps/openmw/mwmp/ActorProcessor.hpp @@ -10,41 +10,25 @@ #include #include -#include #include #include "WorldEvent.hpp" -#include "LocalPlayer.hpp" -#include "DedicatedPlayer.hpp" #include "ActorList.hpp" +#include "BaseClientPacketProcessor.hpp" namespace mwmp { - class ActorProcessor : public BasePacketProcessor + class 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); - 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; }; } diff --git a/apps/openmw/mwmp/BaseClientPacketProcessor.cpp b/apps/openmw/mwmp/BaseClientPacketProcessor.cpp new file mode 100644 index 000000000..a16ba9d24 --- /dev/null +++ b/apps/openmw/mwmp/BaseClientPacketProcessor.cpp @@ -0,0 +1,18 @@ +// +// Created by koncord on 18.04.17. +// + +#include "BaseClientPacketProcessor.hpp" +#include "Main.hpp" + +using namespace mwmp; + +RakNet::RakNetGUID BaseClientPacketProcessor::guid; +RakNet::RakNetGUID BaseClientPacketProcessor::myGuid; +RakNet::SystemAddress BaseClientPacketProcessor::serverAddr; +bool BaseClientPacketProcessor::request; + +LocalPlayer *BaseClientPacketProcessor::getLocalPlayer() +{ + return Main::get().getLocalPlayer(); +} diff --git a/apps/openmw/mwmp/BaseClientPacketProcessor.hpp b/apps/openmw/mwmp/BaseClientPacketProcessor.hpp new file mode 100644 index 000000000..5cd8553d2 --- /dev/null +++ b/apps/openmw/mwmp/BaseClientPacketProcessor.hpp @@ -0,0 +1,43 @@ +// +// Created by koncord on 18.04.17. +// + +#ifndef OPENMW_BASECLIENTPACKETPROCESSOR_HPP +#define OPENMW_BASECLIENTPACKETPROCESSOR_HPP + +#include +#include "LocalPlayer.hpp" +#include "DedicatedPlayer.hpp" + +namespace mwmp +{ + class BaseClientPacketProcessor : public BasePacketProcessor + { + public: + static void SetServerAddr(RakNet::SystemAddress addr) + { + serverAddr = addr; + } + + protected: + inline bool isRequest() + { + return request; + } + + inline bool isLocal() + { + return guid == myGuid; + } + + LocalPlayer *getLocalPlayer(); + + protected: + static RakNet::RakNetGUID guid, myGuid; + static RakNet::SystemAddress serverAddr; + + static bool request; + }; +} + +#endif //OPENMW_BASECLIENTPACKETPROCESSOR_HPP diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 7fdbed316..883d39ead 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -153,9 +153,7 @@ void Networking::connect(const std::string &ip, unsigned short port, std::vector case ID_CONNECTION_REQUEST_ACCEPTED: { serverAddr = packet->systemAddress; - PlayerProcessor::SetServerAddr(packet->systemAddress); - WorldProcessor::SetServerAddr(packet->systemAddress); - ActorProcessor::SetServerAddr(packet->systemAddress); + BaseClientPacketProcessor::SetServerAddr(packet->systemAddress); connected = true; queue = false; diff --git a/apps/openmw/mwmp/PlayerProcessor.cpp b/apps/openmw/mwmp/PlayerProcessor.cpp index 209b473cc..f4f5cbab3 100644 --- a/apps/openmw/mwmp/PlayerProcessor.cpp +++ b/apps/openmw/mwmp/PlayerProcessor.cpp @@ -12,10 +12,6 @@ using namespace mwmp; PlayerProcessor::processors_t PlayerProcessor::processors; -RakNet::RakNetGUID PlayerProcessor::myGuid; -RakNet::RakNetGUID PlayerProcessor::guid; -RakNet::SystemAddress PlayerProcessor::serverAddr; -bool PlayerProcessor::request; void PlayerProcessor::AddProcessor(PlayerProcessor *processor) { @@ -66,8 +62,3 @@ bool PlayerProcessor::Process(RakNet::Packet &packet) } return false; } - -LocalPlayer *PlayerProcessor::getLocalPlayer() -{ - return Main::get().getLocalPlayer(); -} \ No newline at end of file diff --git a/apps/openmw/mwmp/PlayerProcessor.hpp b/apps/openmw/mwmp/PlayerProcessor.hpp index c7d257789..22443a800 100644 --- a/apps/openmw/mwmp/PlayerProcessor.hpp +++ b/apps/openmw/mwmp/PlayerProcessor.hpp @@ -10,46 +10,25 @@ #include #include -#include #include #include "LocalPlayer.hpp" #include "DedicatedPlayer.hpp" +#include "BaseClientPacketProcessor.hpp" namespace mwmp { - class PlayerProcessor : public BasePacketProcessor + class PlayerProcessor : public BaseClientPacketProcessor { public: virtual void Do(PlayerPacket &packet, BasePlayer *player) = 0; static bool Process(RakNet::Packet &packet); static void AddProcessor(PlayerProcessor *processor); - static void SetServerAddr(RakNet::SystemAddress addr) - { - serverAddr = addr; - } typedef boost::unordered_map > processors_t; //typedef std::unordered_map > processors_t; private: static processors_t processors; - static bool request; - protected: - inline bool isRequest() - { - return request; - } - - inline bool isLocal() - { - return guid == myGuid; - } - - LocalPlayer *getLocalPlayer(); - protected: - static RakNet::RakNetGUID myGuid; - static RakNet::RakNetGUID guid; - static RakNet::SystemAddress serverAddr; }; } diff --git a/apps/openmw/mwmp/WorldProcessor.cpp b/apps/openmw/mwmp/WorldProcessor.cpp index a70a89e1e..8050e1a6e 100644 --- a/apps/openmw/mwmp/WorldProcessor.cpp +++ b/apps/openmw/mwmp/WorldProcessor.cpp @@ -10,9 +10,6 @@ using namespace mwmp; WorldProcessor::processors_t WorldProcessor::processors; -RakNet::RakNetGUID WorldProcessor::guid; -RakNet::SystemAddress WorldProcessor::serverAddr; -bool WorldProcessor::request; bool WorldProcessor::Process(RakNet::Packet &packet, WorldEvent &event) { @@ -28,6 +25,7 @@ bool WorldProcessor::Process(RakNet::Packet &packet, WorldEvent &event) { if(processor.first == packet.data[0]) { + myGuid = Main::get().getLocalPlayer()->guid; request = packet.length == myPacket->headerSize(); if(!request && !processor.second->avoidReading) @@ -52,9 +50,4 @@ void WorldProcessor::AddProcessor(mwmp::WorldProcessor *processor) processor->className + " and " + p.second->className); } processors.insert(processors_t::value_type(processor->GetPacketID(), boost::shared_ptr(processor))); -} - -LocalPlayer *WorldProcessor::getLocalPlayer() -{ - return Main::get().getLocalPlayer(); -} +} \ No newline at end of file diff --git a/apps/openmw/mwmp/WorldProcessor.hpp b/apps/openmw/mwmp/WorldProcessor.hpp index 8a2f0ae55..2acf351c9 100644 --- a/apps/openmw/mwmp/WorldProcessor.hpp +++ b/apps/openmw/mwmp/WorldProcessor.hpp @@ -10,40 +10,26 @@ #include #include -#include #include #include "WorldEvent.hpp" #include "LocalPlayer.hpp" #include "DedicatedPlayer.hpp" +#include "BaseClientPacketProcessor.hpp" namespace mwmp { - class WorldProcessor : public BasePacketProcessor + class 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); - 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; }; }