diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 4c9d37eb4..1dbf11417 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -410,6 +410,23 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) break; } + case ID_WORLD_OBJECT_LOCK: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_WORLD_OBJECT_LOCK from %s", + player->Npc()->mName.c_str()); + + myPacket->Read(event); + + LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s", + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum.mIndex, + event->cell.getDescription().c_str()); + + myPacket->Send(event, true); + + break; + } + case ID_WORLD_OBJECT_UNLOCK: { LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_WORLD_OBJECT_UNLOCK from %s", diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 1d2300b31..4a3f93d65 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -686,13 +686,9 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) MWWorld::CellStore *ptrCellStore; if (event->cell.isExterior()) - { ptrCellStore = MWBase::Environment::get().getWorld()->getExterior(event->cell.mData.mX, event->cell.mData.mY); - } else - { ptrCellStore = MWBase::Environment::get().getWorld()->getInterior(event->cell.mName); - } switch (packet->data[0]) { @@ -725,6 +721,27 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) break; } + case ID_WORLD_OBJECT_LOCK: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_WORLD_OBJECT_LOCK"); + LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s", + event->cellRef.mRefID.c_str(), + event->cellRef.mRefNum.mIndex, + event->cell.getDescription().c_str()); + + MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); + + if (ptrFound) + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i", + ptrFound.getCellRef().getRefId().c_str(), + ptrFound.getCellRef().getRefNum()); + + ptrFound.getClass().lock(ptrFound, event->lockLevel); + } + + break; + } case ID_WORLD_OBJECT_UNLOCK: { LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_WORLD_OBJECT_UNLOCK"); diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 8f66f782d..f2e8e559a 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -157,7 +157,8 @@ add_component_dir (openmw-mp Packets/Player/PacketHandshake Packets/Player/PacketGUIBoxes Packets/Player/PacketClass Packets/Player/PacketTime Packets/Player/PacketInventory - Packets/World/PacketObjectDelete Packets/World/PacketObjectPlace Packets/World/PacketObjectUnlock) + Packets/World/PacketObjectDelete Packets/World/PacketObjectPlace Packets/World/PacketObjectLock + Packets/World/PacketObjectUnlock) add_component_dir (fallback fallback validate diff --git a/components/openmw-mp/Base/WorldEvent.hpp b/components/openmw-mp/Base/WorldEvent.hpp index 0348f3500..c8bdb8504 100644 --- a/components/openmw-mp/Base/WorldEvent.hpp +++ b/components/openmw-mp/Base/WorldEvent.hpp @@ -25,6 +25,7 @@ namespace mwmp ESM::Cell cell; ESM::CellRef cellRef; + int lockLevel; }; } diff --git a/components/openmw-mp/Controllers/WorldPacketController.cpp b/components/openmw-mp/Controllers/WorldPacketController.cpp index effccde9f..3b35cfe7e 100644 --- a/components/openmw-mp/Controllers/WorldPacketController.cpp +++ b/components/openmw-mp/Controllers/WorldPacketController.cpp @@ -4,6 +4,7 @@ #include "../Packets/World/PacketObjectDelete.hpp" #include "../Packets/World/PacketObjectPlace.hpp" +#include "../Packets/World/PacketObjectLock.hpp" #include "../Packets/World/PacketObjectUnlock.hpp" #include "WorldPacketController.hpp" @@ -20,6 +21,7 @@ mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *pee { AddPacket(&packets, peer); AddPacket(&packets, peer); + AddPacket(&packets, peer); AddPacket(&packets, peer); } diff --git a/components/openmw-mp/NetworkMessages.hpp b/components/openmw-mp/NetworkMessages.hpp index 17a5e5d80..7ad46d8a8 100644 --- a/components/openmw-mp/NetworkMessages.hpp +++ b/components/openmw-mp/NetworkMessages.hpp @@ -35,6 +35,7 @@ enum GameMessages ID_WORLD_OBJECT_PLACE, ID_WORLD_OBJECT_DELETE, + ID_WORLD_OBJECT_LOCK, ID_WORLD_OBJECT_UNLOCK }; diff --git a/components/openmw-mp/Packets/World/PacketObjectLock.cpp b/components/openmw-mp/Packets/World/PacketObjectLock.cpp new file mode 100644 index 000000000..0b4524ca4 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketObjectLock.cpp @@ -0,0 +1,24 @@ +#include +#include "PacketObjectLock.hpp" + +using namespace mwmp; + +PacketObjectLock::PacketObjectLock(RakNet::RakPeerInterface *peer) : WorldPacket(peer) +{ + packetID = ID_WORLD_OBJECT_LOCK; +} + +void PacketObjectLock::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) +{ + WorldPacket::Packet(bs, event, send); + + RW(event->cellRef.mRefID, send); + RW(event->cellRef.mRefNum.mIndex, send); + + RW(event->cell.mData.mFlags, send); + RW(event->cell.mData.mX, send); + RW(event->cell.mData.mY, send); + RW(event->cell.mName, send); + + RW(event->lockLevel, send); +} diff --git a/components/openmw-mp/Packets/World/PacketObjectLock.hpp b/components/openmw-mp/Packets/World/PacketObjectLock.hpp new file mode 100644 index 000000000..1eb91149d --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketObjectLock.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_PACKETOBJECTLOCK_HPP +#define OPENMW_PACKETOBJECTLOCK_HPP + +#include + +namespace mwmp +{ + class PacketObjectLock : public WorldPacket + { + public: + PacketObjectLock(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); + }; +} + +#endif //OPENMW_PACKETOBJECTLOCK_HPP