From 5bb442bbd396e1346e93268258d9331e56383cc0 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 11 Jul 2018 22:17:00 +0300 Subject: [PATCH] [Server] Add sendToOtherVisitors boolean to SendActorAI() Additionally, avoid repetition in functions that send Actor packets. --- apps/openmw-mp/Script/Functions/Actors.cpp | 51 ++++++++++++++-------- apps/openmw-mp/Script/Functions/Actors.hpp | 5 ++- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Actors.cpp b/apps/openmw-mp/Script/Functions/Actors.cpp index 3b37770ad..82f0b81e2 100644 --- a/apps/openmw-mp/Script/Functions/Actors.cpp +++ b/apps/openmw-mp/Script/Functions/Actors.cpp @@ -371,8 +371,9 @@ void ActorFunctions::AddActor() noexcept void ActorFunctions::SendActorList() noexcept { - mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_LIST)->setActorList(&writeActorList); - mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_LIST)->Send(writeActorList.guid); + mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_LIST); + actorPacket->setActorList(&writeActorList); + actorPacket->Send(writeActorList.guid); } void ActorFunctions::SendActorAuthority() noexcept @@ -383,42 +384,58 @@ void ActorFunctions::SendActorAuthority() noexcept { serverCell->setAuthority(writeActorList.guid); - mwmp::ActorPacket *authorityPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AUTHORITY); - authorityPacket->setActorList(&writeActorList); - authorityPacket->Send(writeActorList.guid); + mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AUTHORITY); + actorPacket->setActorList(&writeActorList); + actorPacket->Send(writeActorList.guid); // Also send this to everyone else who has the cell loaded - serverCell->sendToLoaded(authorityPacket, &writeActorList); + serverCell->sendToLoaded(actorPacket, &writeActorList); } } void ActorFunctions::SendActorPosition() noexcept { - mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_POSITION)->setActorList(&writeActorList); - mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_POSITION)->Send(writeActorList.guid); + mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_POSITION); + actorPacket->setActorList(&writeActorList); + actorPacket->Send(writeActorList.guid); } void ActorFunctions::SendActorStatsDynamic() noexcept { - mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_STATS_DYNAMIC)->setActorList(&writeActorList); - mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_STATS_DYNAMIC)->Send(writeActorList.guid); + mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_STATS_DYNAMIC); + actorPacket->setActorList(&writeActorList); + actorPacket->Send(writeActorList.guid); } void ActorFunctions::SendActorEquipment() noexcept { - mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_EQUIPMENT)->setActorList(&writeActorList); - mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_EQUIPMENT)->Send(writeActorList.guid); + mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_EQUIPMENT); + actorPacket->setActorList(&writeActorList); + actorPacket->Send(writeActorList.guid); } -void ActorFunctions::SendActorAI() noexcept +void ActorFunctions::SendActorAI(bool sendToOtherVisitors) noexcept { - mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AI)->setActorList(&writeActorList); - mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AI)->Send(writeActorList.guid); + mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AI); + actorPacket->setActorList(&writeActorList); + actorPacket->Send(writeActorList.guid); + + if (sendToOtherVisitors) + { + Cell *serverCell = CellController::get()->getCell(&writeActorList.cell); + + if (serverCell != nullptr) + { + // Also send this to everyone else who has the cell loaded + serverCell->sendToLoaded(actorPacket, &writeActorList); + } + } } void ActorFunctions::SendActorCellChange() noexcept { - mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_CELL_CHANGE)->setActorList(&writeActorList); - mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_CELL_CHANGE)->Send(writeActorList.guid); + mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_CELL_CHANGE); + actorPacket->setActorList(&writeActorList); + actorPacket->Send(writeActorList.guid); } diff --git a/apps/openmw-mp/Script/Functions/Actors.hpp b/apps/openmw-mp/Script/Functions/Actors.hpp index 03527feb2..eb3904b4a 100644 --- a/apps/openmw-mp/Script/Functions/Actors.hpp +++ b/apps/openmw-mp/Script/Functions/Actors.hpp @@ -689,11 +689,12 @@ public: /** * \brief Send an ActorAI packet. * - * It is sent only to the player for whom the current actor list was initialized. + * \param sendToOtherVisitors Whether this packet should be sent to cell visitors other + * than the player attached to the packet (false by default). * * \return void */ - static void SendActorAI() noexcept; + static void SendActorAI(bool sendToOtherVisitors) noexcept; /** * \brief Send an ActorCellChange packet.