diff --git a/apps/openmw-mp/Cell.cpp b/apps/openmw-mp/Cell.cpp index 20f0e6eb1..6ffd67fc6 100644 --- a/apps/openmw-mp/Cell.cpp +++ b/apps/openmw-mp/Cell.cpp @@ -155,6 +155,16 @@ void Cell::removeActors(const mwmp::BaseActorList *newActorList) cellActorList.count = cellActorList.baseActors.size(); } +RakNet::RakNetGUID *Cell::getAuthority() +{ + return &authorityGuid; +} + +void Cell::setAuthority(const RakNet::RakNetGUID& guid) +{ + authorityGuid = guid; +} + mwmp::BaseActorList *Cell::getActorList() { return &cellActorList; diff --git a/apps/openmw-mp/Cell.hpp b/apps/openmw-mp/Cell.hpp index 7b0e8c7a3..4ad8eb428 100644 --- a/apps/openmw-mp/Cell.hpp +++ b/apps/openmw-mp/Cell.hpp @@ -34,6 +34,9 @@ public: bool containsActor(int refNumIndex, int mpNum); mwmp::BaseActor *getActor(int refNumIndex, int mpNum); void removeActors(const mwmp::BaseActorList *newActorList); + + RakNet::RakNetGUID *getAuthority(); + void setAuthority(const RakNet::RakNetGUID& guid); mwmp::BaseActorList *getActorList(); TPlayers getPlayers() const; @@ -47,6 +50,7 @@ private: TPlayers players; ESM::Cell cell; + RakNet::RakNetGUID authorityGuid; mwmp::BaseActorList cellActorList; }; diff --git a/apps/openmw-mp/Script/Functions/Actors.cpp b/apps/openmw-mp/Script/Functions/Actors.cpp index 319526784..09d00b88a 100644 --- a/apps/openmw-mp/Script/Functions/Actors.cpp +++ b/apps/openmw-mp/Script/Functions/Actors.cpp @@ -232,15 +232,19 @@ void ActorFunctions::SendActorList() noexcept void ActorFunctions::SendActorAuthority() noexcept { - mwmp::ActorPacket *authorityPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AUTHORITY); - authorityPacket->setActorList(&writeActorList); - authorityPacket->Send(writeActorList.guid); - - // Also send this to everyone else who has the cell loaded Cell *serverCell = CellController::get()->getCell(&writeActorList.cell); if (serverCell != nullptr) + { + serverCell->setAuthority(writeActorList.guid); + + mwmp::ActorPacket *authorityPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AUTHORITY); + authorityPacket->setActorList(&writeActorList); + authorityPacket->Send(writeActorList.guid); + + // Also send this to everyone else who has the cell loaded serverCell->sendToLoaded(authorityPacket, &writeActorList); + } } void ActorFunctions::SendActorPosition() noexcept diff --git a/apps/openmw-mp/processors/actor/ProcessorActorAnimFlags.hpp b/apps/openmw-mp/processors/actor/ProcessorActorAnimFlags.hpp index 0b0a8c10e..4bf6bee38 100644 --- a/apps/openmw-mp/processors/actor/ProcessorActorAnimFlags.hpp +++ b/apps/openmw-mp/processors/actor/ProcessorActorAnimFlags.hpp @@ -18,7 +18,7 @@ namespace mwmp // Send only to players who have the cell loaded Cell *serverCell = CellController::get()->getCell(&actorList.cell); - if (serverCell != nullptr) + if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid) serverCell->sendToLoaded(&packet, &actorList); } }; diff --git a/apps/openmw-mp/processors/actor/ProcessorActorAnimPlay.hpp b/apps/openmw-mp/processors/actor/ProcessorActorAnimPlay.hpp index 924f5df31..39fc3bccf 100644 --- a/apps/openmw-mp/processors/actor/ProcessorActorAnimPlay.hpp +++ b/apps/openmw-mp/processors/actor/ProcessorActorAnimPlay.hpp @@ -18,7 +18,7 @@ namespace mwmp // Send only to players who have the cell loaded Cell *serverCell = CellController::get()->getCell(&actorList.cell); - if (serverCell != nullptr) + if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid) serverCell->sendToLoaded(&packet, &actorList); } }; diff --git a/apps/openmw-mp/processors/actor/ProcessorActorAttack.hpp b/apps/openmw-mp/processors/actor/ProcessorActorAttack.hpp index 896370645..c2b17fe69 100644 --- a/apps/openmw-mp/processors/actor/ProcessorActorAttack.hpp +++ b/apps/openmw-mp/processors/actor/ProcessorActorAttack.hpp @@ -18,7 +18,7 @@ namespace mwmp // Send only to players who have the cell loaded Cell *serverCell = CellController::get()->getCell(&actorList.cell); - if (serverCell != nullptr) + if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid) serverCell->sendToLoaded(&packet, &actorList); } }; diff --git a/apps/openmw-mp/processors/actor/ProcessorActorCellChange.hpp b/apps/openmw-mp/processors/actor/ProcessorActorCellChange.hpp index 57c1255f0..6d2c98cf2 100644 --- a/apps/openmw-mp/processors/actor/ProcessorActorCellChange.hpp +++ b/apps/openmw-mp/processors/actor/ProcessorActorCellChange.hpp @@ -17,7 +17,7 @@ namespace mwmp { Cell *serverCell = CellController::get()->getCell(&actorList.cell); - if (serverCell != nullptr) + if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid) { serverCell->removeActors(&actorList); diff --git a/apps/openmw-mp/processors/actor/ProcessorActorPosition.hpp b/apps/openmw-mp/processors/actor/ProcessorActorPosition.hpp index f5600dcd9..238a66c66 100644 --- a/apps/openmw-mp/processors/actor/ProcessorActorPosition.hpp +++ b/apps/openmw-mp/processors/actor/ProcessorActorPosition.hpp @@ -18,7 +18,7 @@ namespace mwmp // Send only to players who have the cell loaded Cell *serverCell = CellController::get()->getCell(&actorList.cell); - if (serverCell != nullptr) + if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid) { serverCell->readActorList(packetID, &actorList); serverCell->sendToLoaded(&packet, &actorList); diff --git a/apps/openmw-mp/processors/actor/ProcessorActorSpeech.hpp b/apps/openmw-mp/processors/actor/ProcessorActorSpeech.hpp index f1e10ff39..386dc7a46 100644 --- a/apps/openmw-mp/processors/actor/ProcessorActorSpeech.hpp +++ b/apps/openmw-mp/processors/actor/ProcessorActorSpeech.hpp @@ -18,7 +18,7 @@ namespace mwmp // Send only to players who have the cell loaded Cell *serverCell = CellController::get()->getCell(&actorList.cell); - if (serverCell != nullptr) + if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid) serverCell->sendToLoaded(&packet, &actorList); } }; diff --git a/apps/openmw-mp/processors/actor/ProcessorActorStatsDynamic.hpp b/apps/openmw-mp/processors/actor/ProcessorActorStatsDynamic.hpp index 9d5dcc0c7..1523a4efc 100644 --- a/apps/openmw-mp/processors/actor/ProcessorActorStatsDynamic.hpp +++ b/apps/openmw-mp/processors/actor/ProcessorActorStatsDynamic.hpp @@ -18,7 +18,7 @@ namespace mwmp // Send only to players who have the cell loaded Cell *serverCell = CellController::get()->getCell(&actorList.cell); - if (serverCell != nullptr) + if (serverCell != nullptr && *serverCell->getAuthority() == actorList.guid) { serverCell->readActorList(packetID, &actorList); serverCell->sendToLoaded(&packet, &actorList);