From 20d1e7654cb0727a991310be130f474da0bac07a Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 9 Nov 2019 05:12:00 +0200 Subject: [PATCH] [General] Create SystemPacket category and move Handshake packet to it --- apps/openmw-mp/Networking.cpp | 31 +++++++++--- apps/openmw-mp/Networking.hpp | 5 ++ apps/openmw/CMakeLists.txt | 30 ++++++------ apps/openmw/mwmp/LocalSystem.cpp | 20 ++++++++ apps/openmw/mwmp/LocalSystem.hpp | 23 +++++++++ apps/openmw/mwmp/Main.cpp | 12 +++-- apps/openmw/mwmp/Main.hpp | 3 ++ apps/openmw/mwmp/Networking.cpp | 26 ++++++++-- apps/openmw/mwmp/Networking.hpp | 5 ++ .../mwmp/processors/ProcessorInitializer.cpp | 7 ++- .../mwmp/processors/SystemProcessor.cpp | 49 +++++++++++++++++++ .../mwmp/processors/SystemProcessor.hpp | 25 ++++++++++ .../processors/player/ProcessorHandshake.hpp | 24 --------- .../system/ProcessorSystemHandshake.hpp | 28 +++++++++++ components/CMakeLists.txt | 12 +++-- components/openmw-mp/Base/BasePlayer.hpp | 1 - components/openmw-mp/Base/BaseSystem.hpp | 31 ++++++++++++ .../Controllers/PlayerPacketController.cpp | 2 - .../Controllers/SystemPacketController.cpp | 38 ++++++++++++++ .../Controllers/SystemPacketController.hpp | 27 ++++++++++ components/openmw-mp/NetworkMessages.hpp | 2 +- .../Packets/Player/PacketHandshake.cpp | 22 --------- .../Packets/Player/PacketHandshake.hpp | 20 -------- .../Packets/System/PacketSystemHandshake.cpp | 22 +++++++++ .../Packets/System/PacketSystemHandshake.hpp | 20 ++++++++ .../openmw-mp/Packets/System/SystemPacket.cpp | 31 ++++++++++++ .../openmw-mp/Packets/System/SystemPacket.hpp | 30 ++++++++++++ 27 files changed, 442 insertions(+), 104 deletions(-) create mode 100644 apps/openmw/mwmp/LocalSystem.cpp create mode 100644 apps/openmw/mwmp/LocalSystem.hpp create mode 100644 apps/openmw/mwmp/processors/SystemProcessor.cpp create mode 100644 apps/openmw/mwmp/processors/SystemProcessor.hpp delete mode 100644 apps/openmw/mwmp/processors/player/ProcessorHandshake.hpp create mode 100644 apps/openmw/mwmp/processors/system/ProcessorSystemHandshake.hpp create mode 100644 components/openmw-mp/Base/BaseSystem.hpp create mode 100644 components/openmw-mp/Controllers/SystemPacketController.cpp create mode 100644 components/openmw-mp/Controllers/SystemPacketController.hpp delete mode 100644 components/openmw-mp/Packets/Player/PacketHandshake.cpp delete mode 100644 components/openmw-mp/Packets/Player/PacketHandshake.hpp create mode 100644 components/openmw-mp/Packets/System/PacketSystemHandshake.cpp create mode 100644 components/openmw-mp/Packets/System/PacketSystemHandshake.hpp create mode 100644 components/openmw-mp/Packets/System/SystemPacket.cpp create mode 100644 components/openmw-mp/Packets/System/SystemPacket.hpp diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 57b47edcb..64a8b9ea6 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -41,12 +41,14 @@ Networking::Networking(RakNet::RakPeerInterface *peer) : mclient(nullptr) CellController::create(); + systemPacketController = new SystemPacketController(peer); playerPacketController = new PlayerPacketController(peer); actorPacketController = new ActorPacketController(peer); objectPacketController = new ObjectPacketController(peer); worldstatePacketController = new WorldstatePacketController(peer); // Set send stream + systemPacketController->SetStream(0, &bsOut); playerPacketController->SetStream(0, &bsOut); actorPacketController->SetStream(0, &bsOut); objectPacketController->SetStream(0, &bsOut); @@ -69,6 +71,7 @@ Networking::~Networking() CellController::destroy(); sThis = 0; + delete systemPacketController; delete playerPacketController; delete actorPacketController; delete objectPacketController; @@ -85,15 +88,15 @@ bool Networking::isPassworded() const return serverPassword != TES3MP_DEFAULT_PASSW; } -void Networking::processPlayerPacket(RakNet::Packet *packet) +void Networking::processSystemPacket(RakNet::Packet *packet) { Player *player = Players::getPlayer(packet->guid); - PlayerPacket *myPacket = playerPacketController->GetPacket(packet->data[0]); + SystemPacket *myPacket = systemPacketController->GetPacket(packet->data[0]); - if (packet->data[0] == ID_HANDSHAKE) + if (packet->data[0] == ID_SYSTEM_HANDSHAKE) { - myPacket->setPlayer(player); + myPacket->setSystem(&baseSystem); myPacket->Read(); if (!myPacket->isPacketValid()) @@ -110,7 +113,7 @@ void Networking::processPlayerPacket(RakNet::Packet *packet) return; } - if (player->serverPassword != serverPassword) + if (baseSystem.serverPassword != serverPassword) { if (isPassworded()) { @@ -128,6 +131,13 @@ void Networking::processPlayerPacket(RakNet::Packet *packet) player->setHandshake(); return; } +} + +void Networking::processPlayerPacket(RakNet::Packet *packet) +{ + Player *player = Players::getPlayer(packet->guid); + + PlayerPacket *myPacket = playerPacketController->GetPacket(packet->data[0]); if (!player->isHandshaked()) { @@ -283,8 +293,8 @@ bool Networking::preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn) packetPreInit.setChecksums(&tmp); packetPreInit.Send(packet->systemAddress); Players::newPlayer(packet->guid); // create player if connection allowed - playerPacketController->SetStream(&bsIn, nullptr); // and request handshake - playerPacketController->GetPacket(ID_HANDSHAKE)->RequestData(packet->guid); + systemPacketController->SetStream(&bsIn, nullptr); // and request handshake + systemPacketController->GetPacket(ID_SYSTEM_HANDSHAKE)->RequestData(packet->guid); return true; } @@ -293,7 +303,12 @@ bool Networking::preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn) void Networking::update(RakNet::Packet *packet, RakNet::BitStream &bsIn) { - if (playerPacketController->ContainsPacket(packet->data[0])) + if (systemPacketController->ContainsPacket(packet->data[0])) + { + systemPacketController->SetStream(&bsIn, nullptr); + processSystemPacket(packet); + } + else if (playerPacketController->ContainsPacket(packet->data[0])) { playerPacketController->SetStream(&bsIn, nullptr); processPlayerPacket(packet); diff --git a/apps/openmw-mp/Networking.hpp b/apps/openmw-mp/Networking.hpp index 974003617..f88419f1d 100644 --- a/apps/openmw-mp/Networking.hpp +++ b/apps/openmw-mp/Networking.hpp @@ -1,6 +1,7 @@ #ifndef OPENMW_NETWORKING_HPP #define OPENMW_NETWORKING_HPP +#include #include #include #include @@ -25,6 +26,7 @@ namespace mwmp void unbanAddress(const char *ipAddress); RakNet::SystemAddress getSystemAddress(RakNet::RakNetGUID guid); + void processSystemPacket(RakNet::Packet *packet); void processPlayerPacket(RakNet::Packet *packet); void processActorPacket(RakNet::Packet *packet); void processObjectPacket(RakNet::Packet *packet); @@ -40,6 +42,7 @@ namespace mwmp void stopServer(int code); + SystemPacketController *getSystemPacketController() const; PlayerPacketController *getPlayerPacketController() const; ActorPacketController *getActorPacketController() const; ObjectPacketController *getObjectPacketController() const; @@ -80,10 +83,12 @@ namespace mwmp TPlayers *players; MasterClient *mclient; + BaseSystem baseSystem; BaseActorList baseActorList; BaseObjectList baseObjectList; BaseWorldstate baseWorldstate; + SystemPacketController *systemPacketController; PlayerPacketController *playerPacketController; ActorPacketController *actorPacketController; ObjectPacketController *objectPacketController; diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index e885fad61..00b1f8612 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -95,15 +95,18 @@ add_openmw_dir (mwbase inputmanager windowmanager statemanager ) -add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer PlayerList LocalActor DedicatedActor ActorList ObjectList - Worldstate Cell CellController GUIController MechanicsHelper RecordHelper ScriptController +add_openmw_dir (mwmp Main Networking LocalSystem LocalPlayer DedicatedPlayer PlayerList LocalActor DedicatedActor ActorList + ObjectList Worldstate Cell CellController GUIController MechanicsHelper RecordHelper ScriptController ) add_openmw_dir (mwmp/GUI GUIChat GUILogin PlayerMarkerCollection GUIDialogList TextInputDialog ) -add_openmw_dir(mwmp/processors BaseClientPacketProcessor PlayerProcessor ObjectProcessor ActorProcessor WorldstateProcessor - ProcessorInitializer +add_openmw_dir(mwmp/processors BaseClientPacketProcessor SystemProcessor PlayerProcessor ObjectProcessor ActorProcessor + WorldstateProcessor ProcessorInitializer + ) + +add_openmw_dir (mwmp/processors/system ProcessorSystemHandshake ) add_openmw_dir (mwmp/processors/actor ProcessorActorAI ProcessorActorAnimFlags ProcessorActorAnimPlay ProcessorActorAttack @@ -111,16 +114,15 @@ add_openmw_dir (mwmp/processors/actor ProcessorActorAI ProcessorActorAnimFlags P ProcessorActorList ProcessorActorPosition ProcessorActorSpeech ProcessorActorStatsDynamic ProcessorActorTest ) -add_openmw_dir (mwmp/processors/player ProcessorChatMessage ProcessorGUIMessageBox ProcessorHandshake - ProcessorUserDisconnected ProcessorUserMyID ProcessorGameSettings ProcessorPlayerAnimFlags ProcessorPlayerAnimPlay - ProcessorPlayerAttack ProcessorPlayerAttribute ProcessorPlayerBaseInfo ProcessorPlayerBehavior ProcessorPlayerBook - ProcessorPlayerBounty ProcessorPlayerCast ProcessorPlayerCellChange ProcessorPlayerCellState ProcessorPlayerCharClass - ProcessorPlayerCharGen ProcessorPlayerDeath ProcessorPlayerDisposition ProcessorPlayerEquipment ProcessorPlayerFaction - ProcessorPlayerInput ProcessorPlayerInventory ProcessorPlayerItemUse ProcessorPlayerJail ProcessorPlayerJournal - ProcessorPlayerLevel ProcessorPlayerMiscellaneous ProcessorPlayerMomentum ProcessorPlayerPosition ProcessorPlayerQuickKeys - ProcessorPlayerReputation ProcessorPlayerResurrect ProcessorPlayerShapeshift ProcessorPlayerSkill - ProcessorPlayerSpeech ProcessorPlayerSpellbook ProcessorPlayerStatsDynamic ProcessorPlayerTopic - ProcessorPlayerPlaceholder +add_openmw_dir (mwmp/processors/player ProcessorChatMessage ProcessorGUIMessageBox ProcessorUserDisconnected + ProcessorUserMyID ProcessorGameSettings ProcessorPlayerAnimFlags ProcessorPlayerAnimPlay ProcessorPlayerAttack + ProcessorPlayerAttribute ProcessorPlayerBaseInfo ProcessorPlayerBehavior ProcessorPlayerBook ProcessorPlayerBounty + ProcessorPlayerCast ProcessorPlayerCellChange ProcessorPlayerCellState ProcessorPlayerCharClass ProcessorPlayerCharGen + ProcessorPlayerDeath ProcessorPlayerDisposition ProcessorPlayerEquipment ProcessorPlayerFaction ProcessorPlayerInput + ProcessorPlayerInventory ProcessorPlayerItemUse ProcessorPlayerJail ProcessorPlayerJournal ProcessorPlayerLevel + ProcessorPlayerMiscellaneous ProcessorPlayerMomentum ProcessorPlayerPosition ProcessorPlayerQuickKeys ProcessorPlayerReputation + ProcessorPlayerResurrect ProcessorPlayerShapeshift ProcessorPlayerSkill ProcessorPlayerSpeech ProcessorPlayerSpellbook + ProcessorPlayerStatsDynamic ProcessorPlayerTopic ProcessorPlayerPlaceholder ) add_openmw_dir (mwmp/processors/object BaseObjectProcessor diff --git a/apps/openmw/mwmp/LocalSystem.cpp b/apps/openmw/mwmp/LocalSystem.cpp new file mode 100644 index 000000000..a527f23c5 --- /dev/null +++ b/apps/openmw/mwmp/LocalSystem.cpp @@ -0,0 +1,20 @@ +#include "LocalSystem.hpp" +#include "Main.hpp" +#include "Networking.hpp" + +using namespace mwmp; + +LocalSystem::LocalSystem() +{ + +} + +LocalSystem::~LocalSystem() +{ + +} + +Networking *LocalSystem::getNetworking() +{ + return mwmp::Main::get().getNetworking(); +} diff --git a/apps/openmw/mwmp/LocalSystem.hpp b/apps/openmw/mwmp/LocalSystem.hpp new file mode 100644 index 000000000..36c310464 --- /dev/null +++ b/apps/openmw/mwmp/LocalSystem.hpp @@ -0,0 +1,23 @@ +#ifndef OPENMW_LOCALSYSTEM_HPP +#define OPENMW_LOCALSYSTEM_HPP + +#include +#include + +namespace mwmp +{ + class Networking; + class LocalSystem : public BaseSystem + { + public: + + LocalSystem(); + virtual ~LocalSystem(); + + private: + Networking *getNetworking(); + + }; +} + +#endif //OPENMW_LOCALSYSTEM_HPP diff --git a/apps/openmw/mwmp/Main.cpp b/apps/openmw/mwmp/Main.cpp index 83359d92f..6ab9f905c 100644 --- a/apps/openmw/mwmp/Main.cpp +++ b/apps/openmw/mwmp/Main.cpp @@ -37,6 +37,7 @@ #include "Main.hpp" #include "Networking.hpp" +#include "LocalSystem.hpp" #include "LocalPlayer.hpp" #include "DedicatedPlayer.hpp" #include "PlayerList.hpp" @@ -84,6 +85,7 @@ Main::Main() { LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "tes3mp started"); mNetworking = new Networking(); + mLocalSystem = new LocalSystem(); mLocalPlayer = new LocalPlayer(); mGUIController = new GUIController(); mCellController = new CellController(); @@ -96,6 +98,7 @@ Main::~Main() { LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "tes3mp stopped"); delete mNetworking; + delete mLocalSystem; delete mLocalPlayer; delete mCellController; delete mGUIController; @@ -144,7 +147,7 @@ bool Main::init(std::vector &content, Files::Collections &collectio pMain->server = address.substr(0, delimPos); pMain->port = atoi(address.substr(delimPos + 1).c_str()); } - get().mLocalPlayer->serverPassword = serverPassword; + get().mLocalSystem->serverPassword = serverPassword; pMain->mNetworking->connect(pMain->server, pMain->port, content, collections); @@ -177,7 +180,6 @@ void Main::frame(float dt) get().updateWorld(dt); get().getGUIController()->update(dt); - } void Main::updateWorld(float dt) const @@ -216,12 +218,16 @@ Networking *Main::getNetworking() const return mNetworking; } +LocalSystem *Main::getLocalSystem() const +{ + return mLocalSystem; +} + LocalPlayer *Main::getLocalPlayer() const { return mLocalPlayer; } - GUIController *Main::getGUIController() const { return mGUIController; diff --git a/apps/openmw/mwmp/Main.hpp b/apps/openmw/mwmp/Main.hpp index 3111a1665..9d91c1af1 100644 --- a/apps/openmw/mwmp/Main.hpp +++ b/apps/openmw/mwmp/Main.hpp @@ -9,6 +9,7 @@ namespace mwmp { class GUIController; class CellController; + class LocalSystem; class LocalPlayer; class Networking; @@ -32,6 +33,7 @@ namespace mwmp static std::string getResDir(); Networking *getNetworking() const; + LocalSystem *getLocalSystem() const; LocalPlayer *getLocalPlayer() const; GUIController *getGUIController() const; CellController *getCellController() const; @@ -48,6 +50,7 @@ namespace mwmp ///< not implemented static Main *pMain; Networking *mNetworking; + LocalSystem *mLocalSystem; LocalPlayer *mLocalPlayer; GUIController *mGUIController; diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 6f9cf2fde..54893ed84 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -32,6 +32,7 @@ #include "Networking.hpp" #include "Main.hpp" #include "processors/ProcessorInitializer.hpp" +#include "processors/SystemProcessor.hpp" #include "processors/PlayerProcessor.hpp" #include "processors/ObjectProcessor.hpp" #include "processors/ActorProcessor.hpp" @@ -193,8 +194,9 @@ string listComparison(PacketPreInit::PluginContainer checksums, PacketPreInit::P return sstr.str(); } -Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), playerPacketController(peer), - actorPacketController(peer), objectPacketController(peer), worldstatePacketController(peer) +Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), systemPacketController(peer), + playerPacketController(peer), actorPacketController(peer), objectPacketController(peer), + worldstatePacketController(peer) { RakNet::SocketDescriptor sd; @@ -202,6 +204,7 @@ Networking::Networking(): peer(RakNet::RakPeerInterface::GetInstance()), playerP auto b = peer->Startup(1, &sd, 1); RakAssert(b==RakNet::CRABNET_STARTED); + systemPacketController.SetStream(0, &bsOut); playerPacketController.SetStream(0, &bsOut); actorPacketController.SetStream(0, &bsOut); objectPacketController.SetStream(0, &bsOut); @@ -344,7 +347,7 @@ void Networking::connect(const std::string &ip, unsigned short port, std::vector else preInit(content, collections); - getLocalPlayer()->guid = peer->GetMyGUID(); + getLocalPlayer()->guid = getLocalSystem()->guid = peer->GetMyGUID(); } void Networking::preInit(std::vector &content, Files::Collections &collections) @@ -423,7 +426,12 @@ void Networking::receiveMessage(RakNet::Packet *packet) if (packet->length < 2) return; - if (playerPacketController.ContainsPacket(packet->data[0])) + if (systemPacketController.ContainsPacket(packet->data[0])) + { + if (!SystemProcessor::Process(*packet)) + LOG_MESSAGE_SIMPLE(TimedLog::LOG_WARN, "Unhandled SystemPacket with identifier %i has arrived", packet->data[0]); + } + else if (playerPacketController.ContainsPacket(packet->data[0])) { if (!PlayerProcessor::Process(*packet)) LOG_MESSAGE_SIMPLE(TimedLog::LOG_WARN, "Unhandled PlayerPacket with identifier %i has arrived", packet->data[0]); @@ -445,6 +453,11 @@ void Networking::receiveMessage(RakNet::Packet *packet) } } +SystemPacket *Networking::getSystemPacket(RakNet::MessageID id) +{ + return systemPacketController.GetPacket(id); +} + PlayerPacket *Networking::getPlayerPacket(RakNet::MessageID id) { return playerPacketController.GetPacket(id); @@ -465,6 +478,11 @@ WorldstatePacket *Networking::getWorldstatePacket(RakNet::MessageID id) return worldstatePacketController.GetPacket(id); } +LocalSystem *Networking::getLocalSystem() +{ + return mwmp::Main::get().getLocalSystem(); +} + LocalPlayer *Networking::getLocalPlayer() { return mwmp::Main::get().getLocalPlayer(); diff --git a/apps/openmw/mwmp/Networking.hpp b/apps/openmw/mwmp/Networking.hpp index 0f0ce93ec..af8c93e7a 100644 --- a/apps/openmw/mwmp/Networking.hpp +++ b/apps/openmw/mwmp/Networking.hpp @@ -7,6 +7,7 @@ #include +#include #include #include #include @@ -14,6 +15,7 @@ #include +#include "LocalSystem.hpp" #include "ActorList.hpp" #include "ObjectList.hpp" #include "Worldstate.hpp" @@ -30,6 +32,7 @@ namespace mwmp void connect(const std::string& ip, unsigned short port, std::vector &content, Files::Collections &collections); void update(); + SystemPacket *getSystemPacket(RakNet::MessageID id); PlayerPacket *getPlayerPacket(RakNet::MessageID id); ActorPacket *getActorPacket(RakNet::MessageID id); ObjectPacket *getObjectPacket(RakNet::MessageID id); @@ -42,6 +45,7 @@ namespace mwmp bool isConnected(); + LocalSystem *getLocalSystem(); LocalPlayer *getLocalPlayer(); ActorList *getActorList(); ObjectList *getObjectList(); @@ -53,6 +57,7 @@ namespace mwmp RakNet::SystemAddress serverAddr; RakNet::BitStream bsOut; + SystemPacketController systemPacketController; PlayerPacketController playerPacketController; ActorPacketController actorPacketController; ObjectPacketController objectPacketController; diff --git a/apps/openmw/mwmp/processors/ProcessorInitializer.cpp b/apps/openmw/mwmp/processors/ProcessorInitializer.cpp index ec04cb807..964cfa435 100644 --- a/apps/openmw/mwmp/processors/ProcessorInitializer.cpp +++ b/apps/openmw/mwmp/processors/ProcessorInitializer.cpp @@ -1,9 +1,11 @@ #include "ProcessorInitializer.hpp" +#include "SystemProcessor.hpp" +#include "system/ProcessorSystemHandshake.hpp" + #include "PlayerProcessor.hpp" #include "player/ProcessorChatMessage.hpp" #include "player/ProcessorGUIMessageBox.hpp" -#include "player/ProcessorHandshake.hpp" #include "player/ProcessorUserDisconnected.hpp" #include "player/ProcessorGameSettings.hpp" #include "player/ProcessorPlayerAnimFlags.hpp" @@ -103,9 +105,10 @@ using namespace mwmp; void ProcessorInitializer() { + SystemProcessor::AddProcessor(new ProcessorSystemHandshake()); + PlayerProcessor::AddProcessor(new ProcessorChatMessage()); PlayerProcessor::AddProcessor(new ProcessorGUIMessageBox()); - PlayerProcessor::AddProcessor(new ProcessorHandshake()); PlayerProcessor::AddProcessor(new ProcessorUserDisconnected()); PlayerProcessor::AddProcessor(new ProcessorGameSettings()); PlayerProcessor::AddProcessor(new ProcessorPlayerAnimFlags()); diff --git a/apps/openmw/mwmp/processors/SystemProcessor.cpp b/apps/openmw/mwmp/processors/SystemProcessor.cpp new file mode 100644 index 000000000..668285bc0 --- /dev/null +++ b/apps/openmw/mwmp/processors/SystemProcessor.cpp @@ -0,0 +1,49 @@ +#include "../Networking.hpp" +#include "SystemProcessor.hpp" +#include "../Main.hpp" + +using namespace mwmp; + +template +typename BasePacketProcessor::processors_t BasePacketProcessor::processors; + +SystemProcessor::~SystemProcessor() +{ + +} + +bool SystemProcessor::Process(RakNet::Packet &packet) +{ + RakNet::BitStream bsIn(&packet.data[1], packet.length, false); + bsIn.Read(guid); + + SystemPacket *myPacket = Main::get().getNetworking()->getSystemPacket(packet.data[0]); + myPacket->SetReadStream(&bsIn); + + /*if (myPacket == 0) + { + // error: packet not found + }*/ + + for (auto &processor : processors) + { + if (processor.first == packet.data[0]) + { + myGuid = Main::get().getLocalSystem()->guid; + request = packet.length == myPacket->headerSize(); + + BaseSystem *system = 0; + system = Main::get().getLocalSystem(); + + if (!request && !processor.second->avoidReading && system != 0) + { + myPacket->setSystem(system); + myPacket->Read(); + } + + processor.second->Do(*myPacket, system); + return true; + } + } + return false; +} diff --git a/apps/openmw/mwmp/processors/SystemProcessor.hpp b/apps/openmw/mwmp/processors/SystemProcessor.hpp new file mode 100644 index 000000000..c3342dd35 --- /dev/null +++ b/apps/openmw/mwmp/processors/SystemProcessor.hpp @@ -0,0 +1,25 @@ +#ifndef OPENMW_SYSTEMPROCESSOR_HPP +#define OPENMW_SYSTEMPROCESSOR_HPP + +#include +#include +#include +#include "../LocalSystem.hpp" +#include "BaseClientPacketProcessor.hpp" + +namespace mwmp +{ + class SystemProcessor : public BasePacketProcessor, public BaseClientPacketProcessor + { + public: + virtual void Do(SystemPacket &packet, BaseSystem *system) = 0; + + static bool Process(RakNet::Packet &packet); + + virtual ~SystemProcessor(); + }; +} + + + +#endif //OPENMW_SYSTEMPROCESSOR_HPP diff --git a/apps/openmw/mwmp/processors/player/ProcessorHandshake.hpp b/apps/openmw/mwmp/processors/player/ProcessorHandshake.hpp deleted file mode 100644 index 7b862ca2c..000000000 --- a/apps/openmw/mwmp/processors/player/ProcessorHandshake.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef OPENMW_PROCESSORHANDSHAKE_HPP -#define OPENMW_PROCESSORHANDSHAKE_HPP - -#include "../PlayerProcessor.hpp" - -namespace mwmp -{ - class ProcessorHandshake final: public PlayerProcessor - { - public: - ProcessorHandshake() - { - BPP_INIT(ID_HANDSHAKE) - } - - virtual void Do(PlayerPacket &packet, BasePlayer *player) - { - packet.setPlayer(getLocalPlayer()); // player is 0 because myGuid will be set after ProcessUserMyID - packet.Send(serverAddr); - } - }; -} - -#endif //OPENMW_PROCESSORHANDSHAKE_HPP diff --git a/apps/openmw/mwmp/processors/system/ProcessorSystemHandshake.hpp b/apps/openmw/mwmp/processors/system/ProcessorSystemHandshake.hpp new file mode 100644 index 000000000..bf2236d53 --- /dev/null +++ b/apps/openmw/mwmp/processors/system/ProcessorSystemHandshake.hpp @@ -0,0 +1,28 @@ +#ifndef OPENMW_PROCESSORSYSTEMHANDSHAKE_HPP +#define OPENMW_PROCESSORSYSTEMHANDSHAKE_HPP + +#include + +#include "apps/openmw/mwmp/Main.hpp" + +#include "../SystemProcessor.hpp" + +namespace mwmp +{ + class ProcessorSystemHandshake final: public SystemProcessor + { + public: + ProcessorSystemHandshake() + { + BPP_INIT(ID_SYSTEM_HANDSHAKE) + } + + virtual void Do(SystemPacket &packet, BaseSystem *system) + { + packet.setSystem(Main::get().getLocalSystem()); + packet.Send(serverAddr); + } + }; +} + +#endif //OPENMW_PROCESSORSYSTEMHANDSHAKE_HPP diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index a075b8119..5ff6a56a1 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -155,11 +155,11 @@ add_component_dir (openmw-mp ) add_component_dir (openmw-mp/Base - BaseActor BaseObject BasePacketProcessor BasePlayer BaseStructs BaseWorldstate + BaseActor BaseObject BasePacketProcessor BasePlayer BaseStructs BaseSystem BaseWorldstate ) add_component_dir (openmw-mp/Controllers - PlayerPacketController ActorPacketController ObjectPacketController WorldstatePacketController + SystemPacketController PlayerPacketController ActorPacketController ObjectPacketController WorldstatePacketController ) add_component_dir(openmw-mp/Master @@ -178,10 +178,16 @@ add_component_dir (openmw-mp/Packets/Actor PacketActorSpeech PacketActorStatsDynamic ) +add_component_dir (openmw-mp/Packets/System + SystemPacket + + PacketSystemHandshake + ) + add_component_dir (openmw-mp/Packets/Player PlayerPacket - PacketHandshake PacketChatMessage PacketGUIBoxes PacketGameSettings + PacketChatMessage PacketGUIBoxes PacketGameSettings PacketPlayerBaseInfo PacketPlayerCharGen PacketPlayerActiveSkills PacketPlayerAnimFlags PacketPlayerAnimPlay PacketPlayerAttack PacketPlayerAttribute PacketPlayerBehavior PacketPlayerBook PacketPlayerBounty diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 5e1b1184d..bf7554977 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -185,7 +185,6 @@ namespace mwmp } RakNet::RakNetGUID guid; - std::string serverPassword; GUIMessageBox guiMessageBox; diff --git a/components/openmw-mp/Base/BaseSystem.hpp b/components/openmw-mp/Base/BaseSystem.hpp new file mode 100644 index 000000000..2fd0e4e3f --- /dev/null +++ b/components/openmw-mp/Base/BaseSystem.hpp @@ -0,0 +1,31 @@ +#ifndef OPENMW_BASESYSTEM_HPP +#define OPENMW_BASESYSTEM_HPP + +#include + +#include + +namespace mwmp +{ + class BaseSystem + { + public: + + BaseSystem(RakNet::RakNetGUID guid) : guid(guid) + { + + } + + BaseSystem() + { + + } + + RakNet::RakNetGUID guid; + std::string playerName; + std::string serverPassword; + + }; +} + +#endif //OPENMW_BASESYSTEM_HPP diff --git a/components/openmw-mp/Controllers/PlayerPacketController.cpp b/components/openmw-mp/Controllers/PlayerPacketController.cpp index a289d21d6..7bcb6315d 100644 --- a/components/openmw-mp/Controllers/PlayerPacketController.cpp +++ b/components/openmw-mp/Controllers/PlayerPacketController.cpp @@ -1,7 +1,6 @@ #include "../Packets/Player/PacketDisconnect.hpp" #include "../Packets/Player/PacketChatMessage.hpp" #include "../Packets/Player/PacketPlayerCharGen.hpp" -#include "../Packets/Player/PacketHandshake.hpp" #include "../Packets/Player/PacketGUIBoxes.hpp" #include "../Packets/Player/PacketLoaded.hpp" #include "../Packets/Player/PacketGameSettings.hpp" @@ -56,7 +55,6 @@ mwmp::PlayerPacketController::PlayerPacketController(RakNet::RakPeerInterface *p { AddPacket(&packets, peer); AddPacket(&packets, peer); - AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); diff --git a/components/openmw-mp/Controllers/SystemPacketController.cpp b/components/openmw-mp/Controllers/SystemPacketController.cpp new file mode 100644 index 000000000..cacbfddbe --- /dev/null +++ b/components/openmw-mp/Controllers/SystemPacketController.cpp @@ -0,0 +1,38 @@ +#include "../Packets/System/PacketSystemHandshake.hpp" + +#include "SystemPacketController.hpp" + +template +inline void AddPacket(mwmp::SystemPacketController::packets_t *packets, RakNet::RakPeerInterface *peer) +{ + T *packet = new T(peer); + typedef mwmp::SystemPacketController::packets_t::value_type value_t; + packets->insert(value_t(packet->GetPacketID(), value_t::second_type(packet))); +} + +mwmp::SystemPacketController::SystemPacketController(RakNet::RakPeerInterface *peer) +{ + AddPacket(&packets, peer); +} + + +mwmp::SystemPacket *mwmp::SystemPacketController::GetPacket(RakNet::MessageID id) +{ + return packets[(unsigned char)id].get(); +} + +void mwmp::SystemPacketController::SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream) +{ + for(const auto &packet : packets) + packet.second->SetStreams(inStream, outStream); +} + +bool mwmp::SystemPacketController::ContainsPacket(RakNet::MessageID id) +{ + for(const auto &packet : packets) + { + if (packet.first == id) + return true; + } + return false; +} diff --git a/components/openmw-mp/Controllers/SystemPacketController.hpp b/components/openmw-mp/Controllers/SystemPacketController.hpp new file mode 100644 index 000000000..bfd5efde3 --- /dev/null +++ b/components/openmw-mp/Controllers/SystemPacketController.hpp @@ -0,0 +1,27 @@ +#ifndef OPENMW_SYSTEMPACKETCONTROLLER_HPP +#define OPENMW_SYSTEMPACKETCONTROLLER_HPP + + +#include +#include "../Packets/System/SystemPacket.hpp" +#include +#include + +namespace mwmp +{ + class SystemPacketController + { + public: + SystemPacketController(RakNet::RakPeerInterface *peer); + SystemPacket *GetPacket(RakNet::MessageID id); + void SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream); + + bool ContainsPacket(RakNet::MessageID id); + + typedef std::unordered_map > packets_t; + private: + packets_t packets; + }; +} + +#endif //OPENMW_SYSTEMPACKETCONTROLLER_HPP diff --git a/components/openmw-mp/NetworkMessages.hpp b/components/openmw-mp/NetworkMessages.hpp index af3867fd6..01f088ac1 100644 --- a/components/openmw-mp/NetworkMessages.hpp +++ b/components/openmw-mp/NetworkMessages.hpp @@ -10,7 +10,7 @@ enum GameMessages ID_USER_DISCONNECTED, ID_CHAT_MESSAGE, - ID_HANDSHAKE, + ID_SYSTEM_HANDSHAKE, ID_LOADED, ID_GUI_MESSAGEBOX, diff --git a/components/openmw-mp/Packets/Player/PacketHandshake.cpp b/components/openmw-mp/Packets/Player/PacketHandshake.cpp deleted file mode 100644 index ccf946cbb..000000000 --- a/components/openmw-mp/Packets/Player/PacketHandshake.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include "PacketHandshake.hpp" - -using namespace mwmp; - -PacketHandshake::PacketHandshake(RakNet::RakPeerInterface *peer) : PlayerPacket(peer) -{ - packetID = ID_HANDSHAKE; - orderChannel = CHANNEL_SYSTEM; -} - -void PacketHandshake::Packet(RakNet::BitStream *bs, bool send) -{ - PlayerPacket::Packet(bs, send); - - if (!RW(player->npc.mName, send, true, maxNameLength) || - !RW(player->serverPassword, send, true, maxPasswordLength)) - { - packetValid = false; - return; - } -} diff --git a/components/openmw-mp/Packets/Player/PacketHandshake.hpp b/components/openmw-mp/Packets/Player/PacketHandshake.hpp deleted file mode 100644 index b7d82a221..000000000 --- a/components/openmw-mp/Packets/Player/PacketHandshake.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef OPENMW_PACKETHANDSHAKE_HPP -#define OPENMW_PACKETHANDSHAKE_HPP - -#include - -namespace mwmp -{ - class PacketHandshake : public PlayerPacket - { - public: - PacketHandshake(RakNet::RakPeerInterface *peer); - - virtual void Packet(RakNet::BitStream *bs, bool send); - - const static uint32_t maxNameLength = 256; - const static uint32_t maxPasswordLength = 256; - }; -} - -#endif //OPENMW_PACKETHANDSHAKE_HPP diff --git a/components/openmw-mp/Packets/System/PacketSystemHandshake.cpp b/components/openmw-mp/Packets/System/PacketSystemHandshake.cpp new file mode 100644 index 000000000..207956095 --- /dev/null +++ b/components/openmw-mp/Packets/System/PacketSystemHandshake.cpp @@ -0,0 +1,22 @@ +#include +#include "PacketSystemHandshake.hpp" + +using namespace mwmp; + +PacketSystemHandshake::PacketSystemHandshake(RakNet::RakPeerInterface *peer) : SystemPacket(peer) +{ + packetID = ID_SYSTEM_HANDSHAKE; + orderChannel = CHANNEL_SYSTEM; +} + +void PacketSystemHandshake::Packet(RakNet::BitStream *bs, bool send) +{ + SystemPacket::Packet(bs, send); + + if (!RW(system->playerName, send, true, maxNameLength) || + !RW(system->serverPassword, send, true, maxPasswordLength)) + { + packetValid = false; + return; + } +} diff --git a/components/openmw-mp/Packets/System/PacketSystemHandshake.hpp b/components/openmw-mp/Packets/System/PacketSystemHandshake.hpp new file mode 100644 index 000000000..a23a833cd --- /dev/null +++ b/components/openmw-mp/Packets/System/PacketSystemHandshake.hpp @@ -0,0 +1,20 @@ +#ifndef OPENMW_PACKETSYSTEMHANDSHAKE_HPP +#define OPENMW_PACKETSYSTEMHANDSHAKE_HPP + +#include + +namespace mwmp +{ + class PacketSystemHandshake : public SystemPacket + { + public: + PacketSystemHandshake(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, bool send); + + const static uint32_t maxNameLength = 256; + const static uint32_t maxPasswordLength = 256; + }; +} + +#endif //OPENMW_PACKETSYSTEMHANDSHAKE_HPP diff --git a/components/openmw-mp/Packets/System/SystemPacket.cpp b/components/openmw-mp/Packets/System/SystemPacket.cpp new file mode 100644 index 000000000..c7ec697b3 --- /dev/null +++ b/components/openmw-mp/Packets/System/SystemPacket.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include "SystemPacket.hpp" + +using namespace mwmp; + +SystemPacket::SystemPacket(RakNet::RakPeerInterface *peer) : BasePacket(peer) +{ + packetID = 0; + priority = HIGH_PRIORITY; + reliability = RELIABLE_ORDERED; + orderChannel = CHANNEL_SYSTEM; + this->peer = peer; +} + +SystemPacket::~SystemPacket() +{ + +} + +void SystemPacket::setSystem(BaseSystem *system) +{ + this->system = system; + guid = system->guid; +} + +BaseSystem *SystemPacket::getSystem() +{ + return system; +} diff --git a/components/openmw-mp/Packets/System/SystemPacket.hpp b/components/openmw-mp/Packets/System/SystemPacket.hpp new file mode 100644 index 000000000..1d92c50c6 --- /dev/null +++ b/components/openmw-mp/Packets/System/SystemPacket.hpp @@ -0,0 +1,30 @@ +#ifndef OPENMW_SYSTEMPACKET_HPP +#define OPENMW_SYSTEMPACKET_HPP + +#include +#include +#include +#include +#include + +#include + +namespace mwmp +{ + class SystemPacket : public BasePacket + { + public: + SystemPacket(RakNet::RakPeerInterface *peer); + + ~SystemPacket(); + + void setSystem(BaseSystem *system); + BaseSystem *getSystem(); + + protected: + BaseSystem *system; + + }; +} + +#endif //OPENMW_SYSTEMPACKET_HPP