From ca92be14a5d037851bf8c56806874f9e516c774f Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 5 Apr 2017 05:54:25 +0300 Subject: [PATCH] [Client] Reply to ActorList request with list of NPCs --- apps/openmw/mwmp/Networking.cpp | 10 ++++++++++ apps/openmw/mwmp/WorldEvent.cpp | 25 +++++++++++++++++++++++++ apps/openmw/mwmp/WorldEvent.hpp | 1 + apps/openmw/mwworld/cellstore.cpp | 6 ++++++ apps/openmw/mwworld/cellstore.hpp | 3 +++ 5 files changed, 45 insertions(+) diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index a3019c8c8..2e49556ef 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -842,7 +842,17 @@ void Networking::processWorldPacket(RakNet::Packet *packet) { case ID_ACTOR_LIST: { + MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(worldEvent.cell); + + if (!ptrCellStore) return; + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received ID_ACTOR_LIST about %s", worldEvent.cell.getDescription().c_str()); + LOG_APPEND(Log::LOG_VERBOSE, "- action: %i", worldEvent.action); + + // If we've received a request for information, comply with it + if (worldEvent.action == mwmp::BaseEvent::REQUEST) + worldEvent.sendActors(ptrCellStore); + break; } case ID_ACTOR_AUTHORITY: diff --git a/apps/openmw/mwmp/WorldEvent.cpp b/apps/openmw/mwmp/WorldEvent.cpp index 85079119e..449db4c21 100644 --- a/apps/openmw/mwmp/WorldEvent.cpp +++ b/apps/openmw/mwmp/WorldEvent.cpp @@ -40,6 +40,31 @@ void WorldEvent::addObject(WorldObject worldObject) objectChanges.objects.push_back(worldObject); } +void WorldEvent::sendActors(MWWorld::CellStore* cellStore) +{ + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); + worldEvent->cell = *cellStore->getCell(); + worldEvent->action = BaseEvent::SET; + + MWWorld::CellRefList *npcList = cellStore->getNpcs(); + + for (typename MWWorld::CellRefList::List::iterator listIter(npcList->mList.begin()); + listIter != npcList->mList.end(); ++listIter) + { + MWWorld::Ptr npc(&*listIter, 0); + + mwmp::WorldObject worldObject; + worldObject.refId = npc.getCellRef().getRefId(); + worldObject.refNumIndex = npc.getCellRef().getRefNum().mIndex; + worldObject.mpNum = npc.getCellRef().getMpNum(); + + worldEvent->addObject(worldObject); + } + + mwmp::Main::get().getNetworking()->getWorldPacket(ID_ACTOR_LIST)->setEvent(worldEvent); + mwmp::Main::get().getNetworking()->getWorldPacket(ID_ACTOR_LIST)->Send(); +} + void WorldEvent::sendContainers(MWWorld::CellStore* cellStore) { mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); diff --git a/apps/openmw/mwmp/WorldEvent.hpp b/apps/openmw/mwmp/WorldEvent.hpp index 9db71fb57..0195689cd 100644 --- a/apps/openmw/mwmp/WorldEvent.hpp +++ b/apps/openmw/mwmp/WorldEvent.hpp @@ -17,6 +17,7 @@ namespace mwmp void addObject(WorldObject worldObject); + void sendActors(MWWorld::CellStore* cellStore); void sendContainers(MWWorld::CellStore* cellStore); void editContainers(MWWorld::CellStore* cellStore); diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 1b1abeed6..17023eb83 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -481,6 +481,12 @@ namespace MWWorld return searchVisitor.mFound; } + // Added by tes3mp and used to get all the NPCs in the cell + CellRefList *CellStore::getNpcs() + { + return &mNpcs; + } + // Added by tes3mp and used to get all the containers in the cell CellRefList *CellStore::getContainers() { diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 63c30688a..017467752 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -237,6 +237,9 @@ namespace MWWorld Ptr searchExact (const std::string& id, unsigned int refNumIndex, unsigned int mpNum); ///< Added by tes3mp and used to find an object by both its ID and its reference number + CellRefList *getNpcs(); + // Added by tes3mp and used to get all the NPCs in the cell + CellRefList *getContainers(); // Added by tes3mp and used to get all the containers in the cell