From 285f89573d0b884f67fa1c896ab9f7ff672b57ab Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 19 Oct 2016 20:36:11 +0300 Subject: [PATCH] Create placeholders for WorldPacket classes --- components/CMakeLists.txt | 9 ++- .../Controllers/WorldPacketController.cpp | 32 ++++++++++ .../Controllers/WorldPacketController.hpp | 25 ++++++++ components/openmw-mp/NetworkMessages.hpp | 4 +- .../Packets/World/PacketObjectRemoval.cpp | 14 +++++ .../Packets/World/PacketObjectRemoval.hpp | 17 ++++++ .../openmw-mp/Packets/World/WorldPacket.cpp | 58 +++++++++++++++++++ .../openmw-mp/Packets/World/WorldPacket.hpp | 46 +++++++++++++++ 8 files changed, 201 insertions(+), 4 deletions(-) create mode 100644 components/openmw-mp/Controllers/WorldPacketController.cpp create mode 100644 components/openmw-mp/Controllers/WorldPacketController.hpp create mode 100644 components/openmw-mp/Packets/World/PacketObjectRemoval.cpp create mode 100644 components/openmw-mp/Packets/World/PacketObjectRemoval.hpp create mode 100644 components/openmw-mp/Packets/World/WorldPacket.cpp create mode 100644 components/openmw-mp/Packets/World/WorldPacket.hpp diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 0260e9cb5..417528d23 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -147,14 +147,17 @@ add_component_dir (version add_component_dir (openmw-mp Log - Controllers/PlayerPacketController - Packets/BasePacket Packets/Player/PlayerPacket + Controllers/PlayerPacketController Controllers/WorldPacketController + Packets/BasePacket Packets/Player/PlayerPacket Packets/World/WorldPacket + Packets/Player/PacketBaseInfo Packets/Player/PacketPosition Packets/Player/PacketEquipment Packets/Player/PacketAttack Packets/Player/PacketDynamicStats Packets/Player/PacketCell Packets/Player/PacketDrawState Packets/Player/PacketChatMessage Packets/Player/PacketCharGen Packets/Player/PacketAttribute Packets/Player/PacketSkill Packets/Player/PacketLevel Packets/Player/PacketHandshake Packets/Player/PacketGUIBoxes Packets/Player/PacketClass - Packets/Player/PacketTime) + Packets/Player/PacketTime + + Packets/World/PacketObjectRemoval) add_component_dir (fallback fallback validate diff --git a/components/openmw-mp/Controllers/WorldPacketController.cpp b/components/openmw-mp/Controllers/WorldPacketController.cpp new file mode 100644 index 000000000..3a077892e --- /dev/null +++ b/components/openmw-mp/Controllers/WorldPacketController.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +#include "../Packets/World/PacketObjectRemoval.hpp" + +#include "WorldPacketController.hpp" + +template +inline void AddPacket(mwmp::WorldPacketController::packets_t *packets, RakNet::RakPeerInterface *peer) +{ + T *packet = new T(peer); + typedef mwmp::WorldPacketController::packets_t::value_type value_t; + packets->insert(value_t(packet->GetPacketID(), value_t::second_type(packet))); +} + +mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *peer) +{ + AddPacket(&packets, peer); +} + + +mwmp::WorldPacket *mwmp::WorldPacketController::GetPacket(RakNet::MessageID id) +{ + return packets[(unsigned char)id].get(); +} + +void mwmp::WorldPacketController::SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream) +{ + BOOST_FOREACH( packets_t::value_type &packet, packets ) + packet.second->SetStreams(inStream, outStream); +} \ No newline at end of file diff --git a/components/openmw-mp/Controllers/WorldPacketController.hpp b/components/openmw-mp/Controllers/WorldPacketController.hpp new file mode 100644 index 000000000..8831a2e66 --- /dev/null +++ b/components/openmw-mp/Controllers/WorldPacketController.hpp @@ -0,0 +1,25 @@ +#ifndef OPENMW_WORLDPACKETCONTROLLER_HPP +#define OPENMW_WORLDPACKETCONTROLLER_HPP + + +#include +#include "../Packets/World/WorldPacket.hpp" +#include +#include + +namespace mwmp +{ + class WorldPacketController + { + public: + WorldPacketController(RakNet::RakPeerInterface *peer); + WorldPacket *GetPacket(RakNet::MessageID id); + void SetStream(RakNet::BitStream *inStream, RakNet::BitStream *outStream); + + typedef std::map > packets_t; + private: + packets_t packets; + }; +} + +#endif //OPENMW_WORLDPACKETCONTROLLER_HPP diff --git a/components/openmw-mp/NetworkMessages.hpp b/components/openmw-mp/NetworkMessages.hpp index d6177a7d2..1bcd02b08 100644 --- a/components/openmw-mp/NetworkMessages.hpp +++ b/components/openmw-mp/NetworkMessages.hpp @@ -30,7 +30,9 @@ enum GameMessages ID_HANDSHAKE, ID_LOADED, ID_GUI_MESSAGEBOX, - ID_GAME_TIME + ID_GAME_TIME, + + ID_WORLD_OBJECT_REMOVAL }; diff --git a/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp b/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp new file mode 100644 index 000000000..a13dc548b --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketObjectRemoval.cpp @@ -0,0 +1,14 @@ +#include +#include "PacketObjectRemoval.hpp" + +using namespace mwmp; + +PacketObjectRemoval::PacketObjectRemoval(RakNet::RakPeerInterface *peer) : WorldPacket(peer) +{ + packetID = ID_WORLD_OBJECT_REMOVAL; +} + +void PacketObjectRemoval::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send) +{ + WorldPacket::Packet(bs, player, send); +} diff --git a/components/openmw-mp/Packets/World/PacketObjectRemoval.hpp b/components/openmw-mp/Packets/World/PacketObjectRemoval.hpp new file mode 100644 index 000000000..2469dee37 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketObjectRemoval.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_PACKETOBJECTREMOVAL_HPP +#define OPENMW_PACKETOBJECTREMOVAL_HPP + +#include + +namespace mwmp +{ + class PacketObjectRemoval : public WorldPacket + { + public: + PacketObjectRemoval(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send); + }; +} + +#endif //OPENMW_PACKETOBJECTREMOVAL_HPP diff --git a/components/openmw-mp/Packets/World/WorldPacket.cpp b/components/openmw-mp/Packets/World/WorldPacket.cpp new file mode 100644 index 000000000..7bc634d83 --- /dev/null +++ b/components/openmw-mp/Packets/World/WorldPacket.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include "WorldPacket.hpp" + +using namespace mwmp; + +void WorldPacket::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send) +{ + this->player = player; + this->bs = bs; + + if (send) + { + bs->Write(packetID); + bs->Write(player->guid); + } +} + +WorldPacket::WorldPacket(RakNet::RakPeerInterface *peer) : BasePacket(peer) +{ + packetID = 0; + priority = HIGH_PRIORITY; + reliability = RELIABLE_ORDERED; + this->peer = peer; +} + +WorldPacket::~WorldPacket() +{ + +} + +void WorldPacket::Send(BasePlayer *player, RakNet::AddressOrGUID destination) +{ + bsSend->ResetWritePointer(); + Packet(bsSend, player, true); + peer->Send(bsSend, priority, reliability, 0, destination, false); +} + +void WorldPacket::Send(BasePlayer *player, bool toOther) +{ + bsSend->ResetWritePointer(); + Packet(bsSend, player, true); + peer->Send(bsSend, priority, reliability, 0, player->guid, toOther); +} + +void WorldPacket::Read(BasePlayer *player) +{ + Packet(bsRead, player, false); +} + +void WorldPacket::RequestData(RakNet::RakNetGUID guid) +{ + bsSend->ResetWritePointer(); + bsSend->Write(packetID); + bsSend->Write(guid); + peer->Send(bsSend, HIGH_PRIORITY, RELIABLE_ORDERED, 0, guid, false); +} diff --git a/components/openmw-mp/Packets/World/WorldPacket.hpp b/components/openmw-mp/Packets/World/WorldPacket.hpp new file mode 100644 index 000000000..9dc0fe8f8 --- /dev/null +++ b/components/openmw-mp/Packets/World/WorldPacket.hpp @@ -0,0 +1,46 @@ +#ifndef OPENMW_WORLDPACKET_HPP +#define OPENMW_WORLDPACKET_HPP + +#include +#include +#include +#include +#include + +#include + + +namespace mwmp +{ + class WorldPacket : public BasePacket + { + public: + WorldPacket(RakNet::RakPeerInterface *peer); + + ~WorldPacket(); + + virtual void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send); + + virtual void Send(BasePlayer *player, bool toOtherPlayers = true); + virtual void Send(BasePlayer *player, RakNet::AddressOrGUID destination); + virtual void Read(BasePlayer *player); + + virtual void RequestData(RakNet::RakNetGUID player); + + static size_t headerSize() + { + return (size_t)(1 + RakNet::RakNetGUID::size()); // packetID + RakNetGUID (uint64_t) + } + + unsigned char GetPacketID() + { + return packetID; + } + + protected: + BasePlayer *player; + + }; +} + +#endif //OPENMW_WORLDPACKET_HPP