From 47a3dc9ff244c916ecc6cf871c12e08ed45fadd9 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 30 Dec 2017 21:52:30 +0200 Subject: [PATCH] [Server] Add broadcast argument to functions for sending WorldPackets --- apps/openmw-mp/Script/Functions/Chat.cpp | 1 + apps/openmw-mp/Script/Functions/World.cpp | 100 +++++++++++++++------- apps/openmw-mp/Script/Functions/World.hpp | 50 ++++++----- 3 files changed, 101 insertions(+), 50 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Chat.cpp b/apps/openmw-mp/Script/Functions/Chat.cpp index 143421e5b..47a3a99fb 100644 --- a/apps/openmw-mp/Script/Functions/Chat.cpp +++ b/apps/openmw-mp/Script/Functions/Chat.cpp @@ -18,6 +18,7 @@ void ScriptFunctions::SendMessage(unsigned short pid, const char *message, bool mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE)->setPlayer(player); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE)->Send(false); + if (broadcast) mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE)->Send(true); } diff --git a/apps/openmw-mp/Script/Functions/World.cpp b/apps/openmw-mp/Script/Functions/World.cpp index 5c0f3cc5c..871582051 100644 --- a/apps/openmw-mp/Script/Functions/World.cpp +++ b/apps/openmw-mp/Script/Functions/World.cpp @@ -301,64 +301,104 @@ void WorldFunctions::AddContainerItem() noexcept tempContainerItem = emptyContainerItem; } -void WorldFunctions::SendObjectPlace() noexcept +void WorldFunctions::SendObjectPlace(bool broadcast) noexcept { - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_PLACE)->setEvent(&writeEvent); - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_PLACE)->Send(writeEvent.guid); + mwmp::WorldPacket *packet = mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_PLACE); + packet->setEvent(&writeEvent); + packet->Send(false); + + if (broadcast) + packet->Send(true); } -void WorldFunctions::SendObjectSpawn() noexcept +void WorldFunctions::SendObjectSpawn(bool broadcast) noexcept { - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_SPAWN)->setEvent(&writeEvent); - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_SPAWN)->Send(writeEvent.guid); + mwmp::WorldPacket *packet = mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_SPAWN); + packet->setEvent(&writeEvent); + packet->Send(false); + + if (broadcast) + packet->Send(true); } -void WorldFunctions::SendObjectDelete() noexcept +void WorldFunctions::SendObjectDelete(bool broadcast) noexcept { - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_DELETE)->setEvent(&writeEvent); - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_DELETE)->Send(writeEvent.guid); + mwmp::WorldPacket *packet = mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_DELETE); + packet->setEvent(&writeEvent); + packet->Send(false); + + if (broadcast) + packet->Send(true); } -void WorldFunctions::SendObjectLock() noexcept +void WorldFunctions::SendObjectLock(bool broadcast) noexcept { - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_LOCK)->setEvent(&writeEvent); - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_LOCK)->Send(writeEvent.guid); + mwmp::WorldPacket *packet = mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_LOCK); + packet->setEvent(&writeEvent); + packet->Send(false); + + if (broadcast) + packet->Send(true); } -void WorldFunctions::SendObjectTrap() noexcept +void WorldFunctions::SendObjectTrap(bool broadcast) noexcept { - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_TRAP)->setEvent(&writeEvent); - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_TRAP)->Send(writeEvent.guid); + mwmp::WorldPacket *packet = mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_TRAP); + packet->setEvent(&writeEvent); + packet->Send(false); + + if (broadcast) + packet->Send(true); } -void WorldFunctions::SendObjectScale() noexcept +void WorldFunctions::SendObjectScale(bool broadcast) noexcept { - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_SCALE)->setEvent(&writeEvent); - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_SCALE)->Send(writeEvent.guid); + mwmp::WorldPacket *packet = mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_SCALE); + packet->setEvent(&writeEvent); + packet->Send(false); + + if (broadcast) + packet->Send(true); } -void WorldFunctions::SendObjectState() noexcept +void WorldFunctions::SendObjectState(bool broadcast) noexcept { - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_STATE)->setEvent(&writeEvent); - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_STATE)->Send(writeEvent.guid); + mwmp::WorldPacket *packet = mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_STATE); + packet->setEvent(&writeEvent); + packet->Send(false); + + if (broadcast) + packet->Send(true); } -void WorldFunctions::SendDoorState() noexcept +void WorldFunctions::SendDoorState(bool broadcast) noexcept { - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_DOOR_STATE)->setEvent(&writeEvent); - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_DOOR_STATE)->Send(writeEvent.guid); + mwmp::WorldPacket *packet = mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_DOOR_STATE); + packet->setEvent(&writeEvent); + packet->Send(false); + + if (broadcast) + packet->Send(true); } -void WorldFunctions::SendContainer() noexcept +void WorldFunctions::SendContainer(bool broadcast) noexcept { - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_CONTAINER)->setEvent(&writeEvent); - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_CONTAINER)->Send(writeEvent.guid); + mwmp::WorldPacket *packet = mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_CONTAINER); + packet->setEvent(&writeEvent); + packet->Send(false); + + if (broadcast) + packet->Send(true); } -void WorldFunctions::SendConsoleCommand() noexcept +void WorldFunctions::SendConsoleCommand(bool broadcast) noexcept { - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_CONSOLE_COMMAND)->setEvent(&writeEvent); - mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_CONSOLE_COMMAND)->Send(writeEvent.guid); + mwmp::WorldPacket *packet = mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_CONSOLE_COMMAND); + packet->setEvent(&writeEvent); + packet->Send(false); + + if (broadcast) + packet->Send(true); } void WorldFunctions::SetHour(unsigned short pid, double hour) noexcept diff --git a/apps/openmw-mp/Script/Functions/World.hpp b/apps/openmw-mp/Script/Functions/World.hpp index c3f901bb5..485d3a365 100644 --- a/apps/openmw-mp/Script/Functions/World.hpp +++ b/apps/openmw-mp/Script/Functions/World.hpp @@ -568,92 +568,102 @@ public: /** * \brief Send an ObjectPlace packet. * - * It is sent only to the player for whom the current event was initialized. + * \param broadcast Whether this packet should be sent only to the player for whom the current + * event was initialized or to everyone on the server. * * \return void */ - static void SendObjectPlace() noexcept; + static void SendObjectPlace(bool broadcast = false) noexcept; /** * \brief Send an ObjectSpawn packet. * - * It is sent only to the player for whom the current event was initialized. + * \param broadcast Whether this packet should be sent only to the player for whom the current + * event was initialized or to everyone on the server. * * \return void */ - static void SendObjectSpawn() noexcept; + static void SendObjectSpawn(bool broadcast = false) noexcept; /** * \brief Send an ObjectDelete packet. * - * It is sent only to the player for whom the current event was initialized. + * \param broadcast Whether this packet should be sent only to the player for whom the current + * event was initialized or to everyone on the server. * * \return void */ - static void SendObjectDelete() noexcept; + static void SendObjectDelete(bool broadcast = false) noexcept; /** * \brief Send an ObjectLock packet. * - * It is sent only to the player for whom the current event was initialized. + * \param broadcast Whether this packet should be sent only to the player for whom the current + * event was initialized or to everyone on the server. * * \return void */ - static void SendObjectLock() noexcept; + static void SendObjectLock(bool broadcast = false) noexcept; /** * \brief Send an ObjectTrap packet. * - * It is sent only to the player for whom the current event was initialized. + * \param broadcast Whether this packet should be sent only to the player for whom the current + * event was initialized or to everyone on the server. * * \return void */ - static void SendObjectTrap() noexcept; + static void SendObjectTrap(bool broadcast = false) noexcept; /** * \brief Send an ObjectScale packet. * - * It is sent only to the player for whom the current event was initialized. + * \param broadcast Whether this packet should be sent only to the player for whom the current + * event was initialized or to everyone on the server. * * \return void */ - static void SendObjectScale() noexcept; + static void SendObjectScale(bool broadcast = false) noexcept; /** * \brief Send an ObjectState packet. * - * It is sent only to the player for whom the current event was initialized. + * \param broadcast Whether this packet should be sent only to the player for whom the current + * event was initialized or to everyone on the server. * * \return void */ - static void SendObjectState() noexcept; + static void SendObjectState(bool broadcast = false) noexcept; /** * \brief Send a DoorState packet. * - * It is sent only to the player for whom the current event was initialized. + * \param broadcast Whether this packet should be sent only to the player for whom the current + * event was initialized or to everyone on the server. * * \return void */ - static void SendDoorState() noexcept; + static void SendDoorState(bool broadcast = false) noexcept; /** * \brief Send a Container packet. * - * It is sent only to the player for whom the current event was initialized. + * \param broadcast Whether this packet should be sent only to the player for whom the current + * event was initialized or to everyone on the server. * * \return void */ - static void SendContainer() noexcept; + static void SendContainer(bool broadcast = false) noexcept; /** * \brief Send a ConsoleCommand packet. * - * It is sent only to the player for whom the current event was initialized. + * \param broadcast Whether this packet should be sent only to the player for whom the current + * event was initialized or to everyone on the server. * * \return void */ - static void SendConsoleCommand() noexcept; + static void SendConsoleCommand(bool broadcast = false) noexcept; /** * \brief Set the game hour for a player and send a GameTime packet to that player.