From 6a3fbf4e98b2fb0781bf40d50f13e60a51057485 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 7 Jul 2018 18:29:31 +0300 Subject: [PATCH] [Server] Use consistent arguments for script functions that send packets Previously, there was a confusing separation between script functions that had a "broadcast" argument and script functions that had a "toOthers" argument. Those with broadcast sent the packet to all players on the server when broadcast was true. Those with toOthers sent the packet to all players other than the packet's attached player. The former was based on the pattern of the original SendMessage() script function. The latter more closely resembled RakNet's own broadcast argument as seen here: https://github.com/TES3MP/CrabNet/blob/master/include/raknet/RakPeer.h#L219 This commit makes it so all sending functions have a sendToOtherPlayers argument that is false by default and a sendToAttachedPlayer that is true by default. This should simultaneously allow sending to be more intuitive, while not breaking previous existing scripts to a significant degree. Additionally, this commit also reduces some code repetition for all instances of packet-fetching in script functions. --- apps/openmw-mp/Script/Functions/Books.cpp | 12 ++- apps/openmw-mp/Script/Functions/Books.hpp | 8 +- apps/openmw-mp/Script/Functions/Cells.cpp | 6 +- apps/openmw-mp/Script/Functions/CharClass.cpp | 6 +- apps/openmw-mp/Script/Functions/Chat.cpp | 28 +++--- apps/openmw-mp/Script/Functions/Dialogue.cpp | 13 ++- apps/openmw-mp/Script/Functions/Dialogue.hpp | 8 +- apps/openmw-mp/Script/Functions/Factions.cpp | 11 ++- apps/openmw-mp/Script/Functions/Factions.hpp | 8 +- apps/openmw-mp/Script/Functions/GUI.cpp | 30 ++++-- apps/openmw-mp/Script/Functions/Items.cpp | 19 ++-- apps/openmw-mp/Script/Functions/Items.hpp | 8 +- apps/openmw-mp/Script/Functions/Mechanics.cpp | 26 +++-- apps/openmw-mp/Script/Functions/Objects.cpp | 86 +++++++++-------- apps/openmw-mp/Script/Functions/Objects.hpp | 94 ++++++++++--------- apps/openmw-mp/Script/Functions/Positions.cpp | 12 ++- apps/openmw-mp/Script/Functions/Quests.cpp | 33 +++++-- apps/openmw-mp/Script/Functions/Quests.hpp | 24 +++-- apps/openmw-mp/Script/Functions/Settings.cpp | 6 +- .../openmw-mp/Script/Functions/Shapeshift.cpp | 8 +- apps/openmw-mp/Script/Functions/Spells.cpp | 11 ++- apps/openmw-mp/Script/Functions/Spells.hpp | 8 +- apps/openmw-mp/Script/Functions/Stats.cpp | 54 +++++++---- .../openmw-mp/Script/Functions/Worldstate.cpp | 38 ++++---- .../openmw-mp/Script/Functions/Worldstate.hpp | 18 ++-- apps/openmw-mp/Script/ScriptFunctions.hpp | 7 +- 26 files changed, 361 insertions(+), 221 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Books.cpp b/apps/openmw-mp/Script/Functions/Books.cpp index 62e49bb2b..18d0e1671 100644 --- a/apps/openmw-mp/Script/Functions/Books.cpp +++ b/apps/openmw-mp/Script/Functions/Books.cpp @@ -45,11 +45,17 @@ const char *BookFunctions::GetBookId(unsigned short pid, unsigned int i) noexcep return player->bookChanges.books.at(i).bookId.c_str(); } -void BookFunctions::SendBookChanges(unsigned short pid, bool toOthers) noexcept +void BookFunctions::SendBookChanges(unsigned short pid, bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BOOK)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BOOK)->Send(toOthers); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BOOK); + + packet->setPlayer(player); + + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) + packet->Send(true); } diff --git a/apps/openmw-mp/Script/Functions/Books.hpp b/apps/openmw-mp/Script/Functions/Books.hpp index 3c1b7e89d..35f47d0c6 100644 --- a/apps/openmw-mp/Script/Functions/Books.hpp +++ b/apps/openmw-mp/Script/Functions/Books.hpp @@ -56,11 +56,13 @@ public: * \brief Send a PlayerBook packet with a player's recorded book changes. * * \param pid The player ID whose book changes should be used. - * \param toOthers Whether this packet should be sent only to other players or - * only to the player it is about. + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendBookChanges(unsigned short pid, bool toOthers = false) noexcept; + static void SendBookChanges(unsigned short pid, bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; private: diff --git a/apps/openmw-mp/Script/Functions/Cells.cpp b/apps/openmw-mp/Script/Functions/Cells.cpp index b82bff541..99b1e6491 100644 --- a/apps/openmw-mp/Script/Functions/Cells.cpp +++ b/apps/openmw-mp/Script/Functions/Cells.cpp @@ -120,6 +120,8 @@ void CellFunctions::SendCell(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CELL_CHANGE)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CELL_CHANGE)->Send(false); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CELL_CHANGE); + packet->setPlayer(player); + + packet->Send(false); } diff --git a/apps/openmw-mp/Script/Functions/CharClass.cpp b/apps/openmw-mp/Script/Functions/CharClass.cpp index e361c2d92..f981d1c8b 100644 --- a/apps/openmw-mp/Script/Functions/CharClass.cpp +++ b/apps/openmw-mp/Script/Functions/CharClass.cpp @@ -151,6 +151,8 @@ void CharClassFunctions::SendClass(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CHARCLASS)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CHARCLASS)->Send(false); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CHARCLASS); + packet->setPlayer(player); + + packet->Send(false); } diff --git a/apps/openmw-mp/Script/Functions/Chat.cpp b/apps/openmw-mp/Script/Functions/Chat.cpp index 80d0306ee..a94e1248e 100644 --- a/apps/openmw-mp/Script/Functions/Chat.cpp +++ b/apps/openmw-mp/Script/Functions/Chat.cpp @@ -1,12 +1,8 @@ -// -// Created by koncord on 29.04.16. -// - #include #include #include -void ScriptFunctions::SendMessage(unsigned short pid, const char *message, bool broadcast) noexcept +void ScriptFunctions::SendMessage(unsigned short pid, const char *message, bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { Player *player; GET_PLAYER(pid, player,); @@ -15,12 +11,13 @@ void ScriptFunctions::SendMessage(unsigned short pid, const char *message, bool LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "System: %s", message); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE)->setPlayer(player); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE); + packet->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE)->Send(false); - - if (broadcast) - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE)->Send(true); + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) + packet->Send(true); } void ScriptFunctions::CleanChatForPid(unsigned short pid) @@ -30,9 +27,10 @@ void ScriptFunctions::CleanChatForPid(unsigned short pid) player->chatMessage.clear(); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE)->setPlayer(player); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE); + packet->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE)->Send(false); + packet->Send(false); } void ScriptFunctions::CleanChat() @@ -40,8 +38,10 @@ void ScriptFunctions::CleanChat() for (auto player : *Players::getPlayers()) { player.second->chatMessage.clear(); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE)->setPlayer(player.second); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE)->Send(false); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE); + packet->setPlayer(player.second); + + packet->Send(false); } } diff --git a/apps/openmw-mp/Script/Functions/Dialogue.cpp b/apps/openmw-mp/Script/Functions/Dialogue.cpp index fe0380f46..b3e90b794 100644 --- a/apps/openmw-mp/Script/Functions/Dialogue.cpp +++ b/apps/openmw-mp/Script/Functions/Dialogue.cpp @@ -45,13 +45,18 @@ const char *DialogueFunctions::GetTopicId(unsigned short pid, unsigned int i) no return player->topicChanges.topics.at(i).topicId.c_str(); } -void DialogueFunctions::SendTopicChanges(unsigned short pid, bool toOthers) noexcept +void DialogueFunctions::SendTopicChanges(unsigned short pid, bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_TOPIC)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_TOPIC)->Send(toOthers); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_TOPIC); + packet->setPlayer(player); + + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) + packet->Send(true); } void DialogueFunctions::PlayAnimation(unsigned short pid, const char* groupname, int mode, int count, bool persist) noexcept @@ -66,6 +71,7 @@ void DialogueFunctions::PlayAnimation(unsigned short pid, const char* groupname, mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_ANIM_PLAY); packet->setPlayer(player); + packet->Send(false); player->sendToLoaded(packet); } @@ -79,6 +85,7 @@ void DialogueFunctions::PlaySpeech(unsigned short pid, const char* sound) noexce mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SPEECH); packet->setPlayer(player); + packet->Send(false); player->sendToLoaded(packet); } diff --git a/apps/openmw-mp/Script/Functions/Dialogue.hpp b/apps/openmw-mp/Script/Functions/Dialogue.hpp index fe135e5a5..e1cdae481 100644 --- a/apps/openmw-mp/Script/Functions/Dialogue.hpp +++ b/apps/openmw-mp/Script/Functions/Dialogue.hpp @@ -59,11 +59,13 @@ public: * \brief Send a PlayerTopic packet with a player's recorded topic changes. * * \param pid The player ID whose topic changes should be used. - * \param toOthers Whether this packet should be sent only to other players or - * only to the player it is about. + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendTopicChanges(unsigned short pid, bool toOthers = false) noexcept; + static void SendTopicChanges(unsigned short pid, bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; static void PlayAnimation(unsigned short pid, const char* groupname, int mode = 0, int count = 1, bool persist = false) noexcept; static void PlaySpeech(unsigned short pid, const char* sound) noexcept; diff --git a/apps/openmw-mp/Script/Functions/Factions.cpp b/apps/openmw-mp/Script/Functions/Factions.cpp index 41200d677..0fc1121a5 100644 --- a/apps/openmw-mp/Script/Functions/Factions.cpp +++ b/apps/openmw-mp/Script/Functions/Factions.cpp @@ -108,11 +108,16 @@ void FactionFunctions::AddFaction(unsigned short pid) noexcept tempFaction = emptyFaction; } -void FactionFunctions::SendFactionChanges(unsigned short pid, bool toOthers) noexcept +void FactionFunctions::SendFactionChanges(unsigned short pid, bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_FACTION)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_FACTION)->Send(toOthers); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_FACTION); + packet->setPlayer(player); + + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) + packet->Send(true); } diff --git a/apps/openmw-mp/Script/Functions/Factions.hpp b/apps/openmw-mp/Script/Functions/Factions.hpp index d29b9cea8..a5983159b 100644 --- a/apps/openmw-mp/Script/Functions/Factions.hpp +++ b/apps/openmw-mp/Script/Functions/Factions.hpp @@ -144,11 +144,13 @@ public: * \brief Send a PlayerFaction packet with a player's recorded faction changes. * * \param pid The player ID whose faction changes should be used. - * \param toOthers Whether this packet should be sent only to other players or - * only to the player it is about. + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendFactionChanges(unsigned short pid, bool toOthers = false) noexcept; + static void SendFactionChanges(unsigned short pid, bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; private: }; diff --git a/apps/openmw-mp/Script/Functions/GUI.cpp b/apps/openmw-mp/Script/Functions/GUI.cpp index 26f54a50c..3f06ecc3b 100644 --- a/apps/openmw-mp/Script/Functions/GUI.cpp +++ b/apps/openmw-mp/Script/Functions/GUI.cpp @@ -18,8 +18,10 @@ void GUIFunctions::_MessageBox(unsigned short pid, int id, const char *label) no player->guiMessageBox.label = label; player->guiMessageBox.type = Player::GUIMessageBox::MessageBox; - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(false); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX); + packet->setPlayer(player); + + packet->Send(false); } void GUIFunctions::CustomMessageBox(unsigned short pid, int id, const char *label, const char *buttons) noexcept @@ -32,8 +34,10 @@ void GUIFunctions::CustomMessageBox(unsigned short pid, int id, const char *labe player->guiMessageBox.buttons = buttons; player->guiMessageBox.type = Player::GUIMessageBox::CustomMessageBox; - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(false); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX); + packet->setPlayer(player); + + packet->Send(false); } void GUIFunctions::InputDialog(unsigned short pid, int id, const char *label, const char *note) noexcept @@ -46,8 +50,10 @@ void GUIFunctions::InputDialog(unsigned short pid, int id, const char *label, co player->guiMessageBox.note = note; player->guiMessageBox.type = Player::GUIMessageBox::InputDialog; - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(false); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX); + packet->setPlayer(player); + + packet->Send(false); } void GUIFunctions::PasswordDialog(unsigned short pid, int id, const char *label, const char *note) noexcept @@ -60,8 +66,10 @@ void GUIFunctions::PasswordDialog(unsigned short pid, int id, const char *label, player->guiMessageBox.note = note; player->guiMessageBox.type = Player::GUIMessageBox::PasswordDialog; - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(false); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX); + packet->setPlayer(player); + + packet->Send(false); } void GUIFunctions::ListBox(unsigned short pid, int id, const char *label, const char *items) @@ -74,8 +82,10 @@ void GUIFunctions::ListBox(unsigned short pid, int id, const char *label, const player->guiMessageBox.data = items; player->guiMessageBox.type = Player::GUIMessageBox::ListBox; - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(false); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX); + packet->setPlayer(player); + + packet->Send(false); } void GUIFunctions::InitializeQuickKeyChanges(unsigned short pid) noexcept diff --git a/apps/openmw-mp/Script/Functions/Items.cpp b/apps/openmw-mp/Script/Functions/Items.cpp index bc41a3e87..7b2b35b95 100644 --- a/apps/openmw-mp/Script/Functions/Items.cpp +++ b/apps/openmw-mp/Script/Functions/Items.cpp @@ -168,18 +168,25 @@ void ItemFunctions::SendEquipment(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_EQUIPMENT)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_EQUIPMENT)->Send(false); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_EQUIPMENT)->Send(true); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_EQUIPMENT); + packet->setPlayer(player); + + packet->Send(false); + packet->Send(true); player->equipmentIndexChanges.clear(); } -void ItemFunctions::SendInventoryChanges(unsigned short pid, bool toOthers) noexcept +void ItemFunctions::SendInventoryChanges(unsigned short pid, bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_INVENTORY)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_INVENTORY)->Send(toOthers); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_INVENTORY); + packet->setPlayer(player); + + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) + packet->Send(true); } diff --git a/apps/openmw-mp/Script/Functions/Items.hpp b/apps/openmw-mp/Script/Functions/Items.hpp index 05fdfddee..e297ebcaf 100644 --- a/apps/openmw-mp/Script/Functions/Items.hpp +++ b/apps/openmw-mp/Script/Functions/Items.hpp @@ -211,11 +211,13 @@ public: * \brief Send a PlayerInventory packet with a player's recorded inventory changes. * * \param pid The player ID whose inventory changes should be used. - * \param toOthers Whether this packet should be sent only to other players or - * only to the player it is about. + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendInventoryChanges(unsigned short pid, bool toOthers = false) noexcept; + static void SendInventoryChanges(unsigned short pid, bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; private: }; diff --git a/apps/openmw-mp/Script/Functions/Mechanics.cpp b/apps/openmw-mp/Script/Functions/Mechanics.cpp index 178dae2c4..1fe4de09b 100644 --- a/apps/openmw-mp/Script/Functions/Mechanics.cpp +++ b/apps/openmw-mp/Script/Functions/Mechanics.cpp @@ -171,8 +171,10 @@ void MechanicsFunctions::SendMarkLocation(unsigned short pid) player->miscellaneousChangeType = mwmp::MISCELLANEOUS_CHANGE_TYPE::MARK_LOCATION; - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MISCELLANEOUS)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MISCELLANEOUS)->Send(false); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MISCELLANEOUS); + packet->setPlayer(player); + + packet->Send(false); } void MechanicsFunctions::SendSelectedSpell(unsigned short pid) @@ -182,8 +184,10 @@ void MechanicsFunctions::SendSelectedSpell(unsigned short pid) player->miscellaneousChangeType = mwmp::MISCELLANEOUS_CHANGE_TYPE::SELECTED_SPELL; - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MISCELLANEOUS)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MISCELLANEOUS)->Send(false); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MISCELLANEOUS); + packet->setPlayer(player); + + packet->Send(false); } void MechanicsFunctions::Jail(unsigned short pid, int jailDays, bool ignoreJailTeleportation, bool ignoreJailSkillIncreases, @@ -198,8 +202,10 @@ void MechanicsFunctions::Jail(unsigned short pid, int jailDays, bool ignoreJailT player->jailProgressText = jailProgressText; player->jailEndText = jailEndText; - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_JAIL)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_JAIL)->Send(false); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_JAIL); + packet->setPlayer(player); + + packet->Send(false); } void MechanicsFunctions::Resurrect(unsigned short pid, unsigned int type) noexcept @@ -209,9 +215,11 @@ void MechanicsFunctions::Resurrect(unsigned short pid, unsigned int type) noexce player->resurrectType = type; - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_RESURRECT)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_RESURRECT)->Send(false); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_RESURRECT)->Send(true); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_RESURRECT); + packet->setPlayer(player); + + packet->Send(false); + packet->Send(true); } // All methods below are deprecated versions of methods from above diff --git a/apps/openmw-mp/Script/Functions/Objects.cpp b/apps/openmw-mp/Script/Functions/Objects.cpp index d9d570d20..f6b037c3a 100644 --- a/apps/openmw-mp/Script/Functions/Objects.cpp +++ b/apps/openmw-mp/Script/Functions/Objects.cpp @@ -399,123 +399,135 @@ void ObjectFunctions::AddContainerItem() noexcept tempContainerItem = emptyContainerItem; } -void ObjectFunctions::SendObjectPlace(bool broadcast) noexcept +void ObjectFunctions::SendObjectPlace(bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_OBJECT_PLACE); packet->setObjectList(&writeObjectList); - packet->Send(false); - if (broadcast) + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) packet->Send(true); } -void ObjectFunctions::SendObjectSpawn(bool broadcast) noexcept +void ObjectFunctions::SendObjectSpawn(bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_OBJECT_SPAWN); packet->setObjectList(&writeObjectList); - packet->Send(false); - if (broadcast) + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) packet->Send(true); } -void ObjectFunctions::SendObjectDelete(bool broadcast) noexcept +void ObjectFunctions::SendObjectDelete(bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_OBJECT_DELETE); packet->setObjectList(&writeObjectList); - packet->Send(false); - - if (broadcast) + + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) packet->Send(true); } -void ObjectFunctions::SendObjectLock(bool broadcast) noexcept +void ObjectFunctions::SendObjectLock(bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_OBJECT_LOCK); packet->setObjectList(&writeObjectList); - packet->Send(false); - if (broadcast) + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) packet->Send(true); } -void ObjectFunctions::SendObjectTrap(bool broadcast) noexcept +void ObjectFunctions::SendObjectTrap(bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_OBJECT_TRAP); packet->setObjectList(&writeObjectList); - packet->Send(false); - if (broadcast) + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) packet->Send(true); } -void ObjectFunctions::SendObjectScale(bool broadcast) noexcept +void ObjectFunctions::SendObjectScale(bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_OBJECT_SCALE); packet->setObjectList(&writeObjectList); - packet->Send(false); - if (broadcast) + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) packet->Send(true); } -void ObjectFunctions::SendObjectState(bool broadcast) noexcept +void ObjectFunctions::SendObjectState(bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_OBJECT_STATE); packet->setObjectList(&writeObjectList); - packet->Send(false); - if (broadcast) + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) packet->Send(true); } -void ObjectFunctions::SendDoorState(bool broadcast) noexcept +void ObjectFunctions::SendDoorState(bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_DOOR_STATE); packet->setObjectList(&writeObjectList); - packet->Send(false); - if (broadcast) + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) packet->Send(true); } -void ObjectFunctions::SendDoorDestination(bool broadcast) noexcept +void ObjectFunctions::SendDoorDestination(bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_DOOR_DESTINATION); packet->setObjectList(&writeObjectList); - packet->Send(false); - if (broadcast) + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) packet->Send(true); } -void ObjectFunctions::SendContainer(bool broadcast) noexcept +void ObjectFunctions::SendContainer(bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_CONTAINER); packet->setObjectList(&writeObjectList); - packet->Send(false); - if (broadcast) + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) packet->Send(true); } -void ObjectFunctions::SendVideoPlay(bool broadcast) noexcept +void ObjectFunctions::SendVideoPlay(bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_VIDEO_PLAY); packet->setObjectList(&writeObjectList); - packet->Send(false); - if (broadcast) + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) packet->Send(true); } -void ObjectFunctions::SendConsoleCommand(bool broadcast) noexcept +void ObjectFunctions::SendConsoleCommand(bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_CONSOLE_COMMAND); packet->setObjectList(&writeObjectList); - packet->Send(false); - if (broadcast) + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) packet->Send(true); } diff --git a/apps/openmw-mp/Script/Functions/Objects.hpp b/apps/openmw-mp/Script/Functions/Objects.hpp index 1c33800c4..6e7948f6b 100644 --- a/apps/openmw-mp/Script/Functions/Objects.hpp +++ b/apps/openmw-mp/Script/Functions/Objects.hpp @@ -779,22 +779,24 @@ public: /** * \brief Send an ObjectPlace packet. * - * \param broadcast Whether this packet should be sent only to the player for whom the current - * object list was initialized or to everyone on the server. - * + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendObjectPlace(bool broadcast = false) noexcept; + static void SendObjectPlace(bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; /** * \brief Send an ObjectSpawn packet. * - * \param broadcast Whether this packet should be sent only to the player for whom the current - * object list was initialized or to everyone on the server. - * + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendObjectSpawn(bool broadcast = false) noexcept; + static void SendObjectSpawn(bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; /** * \brief Send an ObjectDelete packet. @@ -804,17 +806,18 @@ public: * * \return void */ - static void SendObjectDelete(bool broadcast = false) noexcept; + static void SendObjectDelete(bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; /** * \brief Send an ObjectLock packet. * - * \param broadcast Whether this packet should be sent only to the player for whom the current - * object list was initialized or to everyone on the server. - * + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendObjectLock(bool broadcast = false) noexcept; + static void SendObjectLock(bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; /** * \brief Send an ObjectTrap packet. @@ -824,77 +827,84 @@ public: * * \return void */ - static void SendObjectTrap(bool broadcast = false) noexcept; + static void SendObjectTrap(bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; /** * \brief Send an ObjectScale packet. * - * \param broadcast Whether this packet should be sent only to the player for whom the current - * object list was initialized or to everyone on the server. - * + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendObjectScale(bool broadcast = false) noexcept; + static void SendObjectScale(bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; /** * \brief Send an ObjectState packet. * - * \param broadcast Whether this packet should be sent only to the player for whom the current - * object list was initialized or to everyone on the server. - * + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendObjectState(bool broadcast = false) noexcept; + static void SendObjectState(bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; /** * \brief Send a DoorState packet. * - * \param broadcast Whether this packet should be sent only to the player for whom the current - * object list was initialized or to everyone on the server. - * + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendDoorState(bool broadcast = false) noexcept; + static void SendDoorState(bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; /** * \brief Send a DoorDestination packet. * - * \param broadcast Whether this packet should be sent only to the player for whom the current - * object list was initialized or to everyone on the server. - * + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendDoorDestination(bool broadcast = false) noexcept; + static void SendDoorDestination(bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; /** * \brief Send a Container packet. * - * \param broadcast Whether this packet should be sent only to the player for whom the current - * object list was initialized or to everyone on the server. - * + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendContainer(bool broadcast = false) noexcept; + static void SendContainer(bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; /** * \brief Send a VideoPlay packet. * - * \param broadcast Whether this packet should be sent only to the player for whom the current - * object list was initialized or to everyone on the server. - * + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendVideoPlay(bool broadcast = false) noexcept; + static void SendVideoPlay(bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; /** * \brief Send a ConsoleCommand packet. * - * \param broadcast Whether this packet should be sent only to the player for whom the current - * object list was initialized or to everyone on the server. - * + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendConsoleCommand(bool broadcast = false) noexcept; + static void SendConsoleCommand(bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; // All methods below are deprecated versions of methods from above diff --git a/apps/openmw-mp/Script/Functions/Positions.cpp b/apps/openmw-mp/Script/Functions/Positions.cpp index 58a569bc1..75e8e482d 100644 --- a/apps/openmw-mp/Script/Functions/Positions.cpp +++ b/apps/openmw-mp/Script/Functions/Positions.cpp @@ -133,8 +133,10 @@ void PositionFunctions::SendPos(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_POSITION)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_POSITION)->Send(false); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_POSITION); + packet->setPlayer(player); + + packet->Send(false); } void PositionFunctions::SendMomentum(unsigned short pid) noexcept @@ -142,6 +144,8 @@ void PositionFunctions::SendMomentum(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MOMENTUM)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MOMENTUM)->Send(false); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MOMENTUM); + packet->setPlayer(player); + + packet->Send(false); } diff --git a/apps/openmw-mp/Script/Functions/Quests.cpp b/apps/openmw-mp/Script/Functions/Quests.cpp index d9d3606f9..1a8ce11e3 100644 --- a/apps/openmw-mp/Script/Functions/Quests.cpp +++ b/apps/openmw-mp/Script/Functions/Quests.cpp @@ -149,29 +149,44 @@ int QuestFunctions::GetReputation(unsigned short pid) noexcept return player->npcStats.mReputation; } -void QuestFunctions::SendJournalChanges(unsigned short pid, bool toOthers) noexcept +void QuestFunctions::SendJournalChanges(unsigned short pid, bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_JOURNAL)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_JOURNAL)->Send(toOthers); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_JOURNAL); + packet->setPlayer(player); + + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) + packet->Send(true); } -void QuestFunctions::SendKillChanges(unsigned short pid, bool toOthers) noexcept +void QuestFunctions::SendKillChanges(unsigned short pid, bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_KILL_COUNT)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_KILL_COUNT)->Send(toOthers); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_KILL_COUNT); + packet->setPlayer(player); + + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) + packet->Send(true); } -void QuestFunctions::SendReputation(unsigned short pid, bool toOthers) noexcept +void QuestFunctions::SendReputation(unsigned short pid, bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_REPUTATION)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_REPUTATION)->Send(toOthers); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_REPUTATION); + packet->setPlayer(player); + + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) + packet->Send(true); } diff --git a/apps/openmw-mp/Script/Functions/Quests.hpp b/apps/openmw-mp/Script/Functions/Quests.hpp index d140137de..c3ec29583 100644 --- a/apps/openmw-mp/Script/Functions/Quests.hpp +++ b/apps/openmw-mp/Script/Functions/Quests.hpp @@ -175,31 +175,37 @@ public: * \brief Send a PlayerJournal packet with a player's recorded journal changes. * * \param pid The player ID whose journal changes should be used. - * \param toOthers Whether this packet should be sent only to other players or - * only to the player it is about. + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendJournalChanges(unsigned short pid, bool toOthers = false) noexcept; + static void SendJournalChanges(unsigned short pid, bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; /** * \brief Send a PlayerKillCount packet with a player's recorded kill count changes. * * \param pid The player ID whose kill count changes should be used. - * \param toOthers Whether this packet should be sent only to other players or - * only to the player it is about. + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendKillChanges(unsigned short pid, bool toOthers = false) noexcept; + static void SendKillChanges(unsigned short pid, bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; /** * \brief Send a PlayerReputation packet with a player's recorded reputation. * * \param pid The player ID whose reputation should be used. - * \param toOthers Whether this packet should be sent only to other players or - * only to the player it is about. + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendReputation(unsigned short pid, bool toOthers) noexcept; + static void SendReputation(unsigned short pid, bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; private: diff --git a/apps/openmw-mp/Script/Functions/Settings.cpp b/apps/openmw-mp/Script/Functions/Settings.cpp index f021e7338..711a72ec3 100644 --- a/apps/openmw-mp/Script/Functions/Settings.cpp +++ b/apps/openmw-mp/Script/Functions/Settings.cpp @@ -70,6 +70,8 @@ void SettingFunctions::SendSettings(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player,); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_SETTINGS)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_SETTINGS)->Send(false); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_SETTINGS); + packet->setPlayer(player); + + packet->Send(false); } diff --git a/apps/openmw-mp/Script/Functions/Shapeshift.cpp b/apps/openmw-mp/Script/Functions/Shapeshift.cpp index 2ac33c701..2c6a36034 100644 --- a/apps/openmw-mp/Script/Functions/Shapeshift.cpp +++ b/apps/openmw-mp/Script/Functions/Shapeshift.cpp @@ -78,7 +78,9 @@ void ShapeshiftFunctions::SendShapeshift(unsigned short pid) Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SHAPESHIFT)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SHAPESHIFT)->Send(false); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SHAPESHIFT)->Send(true); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SHAPESHIFT); + packet->setPlayer(player); + + packet->Send(false); + packet->Send(true); } diff --git a/apps/openmw-mp/Script/Functions/Spells.cpp b/apps/openmw-mp/Script/Functions/Spells.cpp index 00c242529..e76613f71 100644 --- a/apps/openmw-mp/Script/Functions/Spells.cpp +++ b/apps/openmw-mp/Script/Functions/Spells.cpp @@ -269,11 +269,16 @@ int SpellFunctions::GetSpellEffectMagnMax(unsigned short pid, unsigned int i, un return player->spellbookChanges.spells.at(i).mEffects.mList.at(j).mMagnMax; } -void SpellFunctions::SendSpellbookChanges(unsigned short pid, bool toOthers) noexcept +void SpellFunctions::SendSpellbookChanges(unsigned short pid, bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SPELLBOOK)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SPELLBOOK)->Send(toOthers); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SPELLBOOK); + packet->setPlayer(player); + + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) + packet->Send(true); } diff --git a/apps/openmw-mp/Script/Functions/Spells.hpp b/apps/openmw-mp/Script/Functions/Spells.hpp index f1d8ecbed..ab59a7ccf 100644 --- a/apps/openmw-mp/Script/Functions/Spells.hpp +++ b/apps/openmw-mp/Script/Functions/Spells.hpp @@ -255,11 +255,13 @@ public: * \brief Send a PlayerSpellbook packet with a player's recorded spellbook changes. * * \param pid The player ID whose spellbook changes should be used. - * \param toOthers Whether this packet should be sent only to other players or - * only to the player it is about. + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendSpellbookChanges(unsigned short pid, bool toOthers = false) noexcept; + static void SendSpellbookChanges(unsigned short pid, bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; private: diff --git a/apps/openmw-mp/Script/Functions/Stats.cpp b/apps/openmw-mp/Script/Functions/Stats.cpp index 56908dcba..5bfd2eade 100644 --- a/apps/openmw-mp/Script/Functions/Stats.cpp +++ b/apps/openmw-mp/Script/Functions/Stats.cpp @@ -510,8 +510,10 @@ void StatsFunctions::SetCharGenStage(unsigned short pid, int currentStage, int e player->charGenState.endStage = endStage; player->charGenState.isFinished = false; - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CHARGEN)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CHARGEN)->Send(false); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CHARGEN); + packet->setPlayer(player); + + packet->Send(false); } void StatsFunctions::SendBaseInfo(unsigned short pid) noexcept @@ -519,9 +521,11 @@ void StatsFunctions::SendBaseInfo(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player,); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BASEINFO)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BASEINFO)->Send(false); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BASEINFO)->Send(true); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BASEINFO); + packet->setPlayer(player); + + packet->Send(false); + packet->Send(true); } void StatsFunctions::SendStatsDynamic(unsigned short pid) noexcept @@ -529,9 +533,11 @@ void StatsFunctions::SendStatsDynamic(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_STATS_DYNAMIC)->Send(false); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_STATS_DYNAMIC)->Send(true); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_STATS_DYNAMIC); + packet->setPlayer(player); + + packet->Send(false); + packet->Send(true); player->statsDynamicIndexChanges.clear(); } @@ -541,9 +547,11 @@ void StatsFunctions::SendAttributes(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player,); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_ATTRIBUTE)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_ATTRIBUTE)->Send(false); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_ATTRIBUTE)->Send(true); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_ATTRIBUTE); + packet->setPlayer(player); + + packet->Send(false); + packet->Send(true); player->attributeIndexChanges.clear(); } @@ -553,9 +561,11 @@ void StatsFunctions::SendSkills(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player,); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SKILL)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SKILL)->Send(false); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SKILL)->Send(true); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SKILL); + packet->setPlayer(player); + + packet->Send(false); + packet->Send(true); player->skillIndexChanges.clear(); } @@ -565,9 +575,11 @@ void StatsFunctions::SendLevel(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_LEVEL)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_LEVEL)->Send(false); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_LEVEL)->Send(true); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_LEVEL); + packet->setPlayer(player); + + packet->Send(false); + packet->Send(true); } void StatsFunctions::SendBounty(unsigned short pid) noexcept @@ -575,7 +587,9 @@ void StatsFunctions::SendBounty(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, ); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BOUNTY)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BOUNTY)->Send(false); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BOUNTY)->Send(true); + mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BOUNTY); + packet->setPlayer(player); + + packet->Send(false); + packet->Send(true); } diff --git a/apps/openmw-mp/Script/Functions/Worldstate.cpp b/apps/openmw-mp/Script/Functions/Worldstate.cpp index 7204c07df..214b7aa9d 100644 --- a/apps/openmw-mp/Script/Functions/Worldstate.cpp +++ b/apps/openmw-mp/Script/Functions/Worldstate.cpp @@ -137,44 +137,50 @@ void WorldstateFunctions::LoadMapTileImageFile(int cellX, int cellY, const char* } } -void WorldstateFunctions::SendWorldMap(unsigned short pid, bool broadcast) noexcept +void WorldstateFunctions::SendWorldMap(unsigned short pid, bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { Player *player; GET_PLAYER(pid, player, ); writeWorldstate.guid = player->guid; - mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_MAP)->setWorldstate(&writeWorldstate); - mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_MAP)->Send(false); + mwmp::WorldstatePacket *packet = mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_MAP); + packet->setWorldstate(&writeWorldstate); - if (broadcast) - mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_MAP)->Send(true); + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) + packet->Send(true); } -void WorldstateFunctions::SendWorldTime(unsigned short pid, bool broadcast) noexcept +void WorldstateFunctions::SendWorldTime(unsigned short pid, bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { Player *player; GET_PLAYER(pid, player, ); writeWorldstate.guid = player->guid; - mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->setWorldstate(&writeWorldstate); - mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->Send(false); - - if (broadcast) - mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME)->Send(true); + mwmp::WorldstatePacket *packet = mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_TIME); + packet->setWorldstate(&writeWorldstate); + + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) + packet->Send(true); } -void WorldstateFunctions::SendWorldCollisionOverride(unsigned short pid, bool broadcast) noexcept +void WorldstateFunctions::SendWorldCollisionOverride(unsigned short pid, bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept { Player *player; GET_PLAYER(pid, player, ); writeWorldstate.guid = player->guid; - mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_COLLISION_OVERRIDE)->setWorldstate(&writeWorldstate); - mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_COLLISION_OVERRIDE)->Send(false); + mwmp::WorldstatePacket *packet = mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_COLLISION_OVERRIDE); + packet->setWorldstate(&writeWorldstate); - if (broadcast) - mwmp::Networking::get().getWorldstatePacketController()->GetPacket(ID_WORLD_COLLISION_OVERRIDE)->Send(true); + if (sendToAttachedPlayer) + packet->Send(false); + if (sendToOtherPlayers) + packet->Send(true); } diff --git a/apps/openmw-mp/Script/Functions/Worldstate.hpp b/apps/openmw-mp/Script/Functions/Worldstate.hpp index 640d1b711..58e2eb180 100644 --- a/apps/openmw-mp/Script/Functions/Worldstate.hpp +++ b/apps/openmw-mp/Script/Functions/Worldstate.hpp @@ -223,29 +223,33 @@ public: * or to all players on the server. * \return void */ - static void SendWorldMap(unsigned short pid, bool broadcast = false) noexcept; + static void SendWorldMap(unsigned short pid, bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; /** * \brief Send a WorldTime packet with the current time and time scale in the write-only * worldstate. * * \param pid The player ID attached to the packet. - * \param broadcast Whether this packet should be sent only to the attached player - * or to all players on the server. + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendWorldTime(unsigned short pid, bool broadcast = false) noexcept; + static void SendWorldTime(unsigned short pid, bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; /** * \brief Send a WorldCollisionOverride packet with the current collision overrides in * the write-only worldstate. * * \param pid The player ID attached to the packet. - * \param broadcast Whether this packet should be sent only to the attached player - * or to all players on the server. + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendWorldCollisionOverride(unsigned short pid, bool broadcast = false) noexcept; + static void SendWorldCollisionOverride(unsigned short pid, bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; }; diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index 52296e532..1a3780adb 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -61,10 +61,13 @@ public: * * \param pid The player ID. * \param message The contents of the message. - * \param broadcast Whether the message should also be sent to other players. + * \param sendToOtherPlayers Whether this packet should be sent to players other than the + * player attached to the packet (false by default). + * \param sendToAttachedPlayer Whether the packet should be sent to the player attached + * to the packet (true by default). * \return void */ - static void SendMessage(unsigned short pid, const char *message, bool broadcast) noexcept; + static void SendMessage(unsigned short pid, const char *message, bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept; /** * \brief Remove all messages from chat for a certain player.