From 11369f6513124bd16df0f9bf6f4fdcfbcb58d50c Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 24 May 2017 21:43:34 +0300 Subject: [PATCH] [General] Implement sending and reading of PlayerTopic packets --- apps/openmw/mwdialogue/dialoguemanagerimp.cpp | 12 ++++++++++ apps/openmw/mwmp/LocalPlayer.cpp | 23 +++++++++++++++++++ apps/openmw/mwmp/LocalPlayer.hpp | 2 ++ .../player/ProcessorPlayerTopic.hpp | 4 ++-- apps/openmw/mwscript/dialogueextensions.cpp | 11 +++++++++ components/openmw-mp/Base/BasePlayer.hpp | 12 ++++++++++ .../Packets/Player/PacketPlayerFaction.cpp | 6 ++--- .../Packets/Player/PacketPlayerTopic.cpp | 20 ++++++++++++++++ 8 files changed, 85 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index 1e2728240..569c665e3 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -28,6 +28,7 @@ */ #include "../mwmp/Main.hpp" #include "../mwmp/CellController.hpp" +#include "../mwmp/LocalPlayer.hpp" #include "../mwmp/LocalActor.hpp" /* End of tes3mp addition @@ -117,6 +118,17 @@ namespace MWDialogue if (tok->isImplicitKeyword() && mTranslationDataStorage.hasTranslation()) continue; + /* + Start of tes3mp addition + + Send an ID_PLAYER_TOPIC packet every time a new topic becomes known + */ + if (mActorKnownTopics.count(topicId) && !mKnownTopics.count(topicId)) + mwmp::Main::get().getLocalPlayer()->sendTopic(topicId); + /* + End of tes3mp addition + */ + if (mActorKnownTopics.count( topicId )) mKnownTopics.insert( topicId ); } diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index f16222a53..d550b7243 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -687,6 +687,16 @@ void LocalPlayer::addJournalItems() } } +void LocalPlayer::addTopics() +{ + for (unsigned int i = 0; i < topicChanges.count; i++) + { + mwmp::Topic topic = topicChanges.topics.at(i); + + MWBase::Environment::get().getDialogueManager()->addTopic(topic.topicId); + } +} + void LocalPlayer::removeItems() { MWWorld::Ptr ptrPlayer = getPlayerPtr(); @@ -1166,6 +1176,19 @@ void LocalPlayer::sendFaction(const std::string& factionId, int rank, bool isExp getNetworking()->getPlayerPacket(ID_PLAYER_FACTION)->Send(); } +void LocalPlayer::sendTopic(const std::string& topicId) +{ + topicChanges.topics.clear(); + + mwmp::Topic topic; + topic.topicId = topicId; + + topicChanges.topics.push_back(topic); + + getNetworking()->getPlayerPacket(ID_PLAYER_TOPIC)->setPlayer(this); + getNetworking()->getPlayerPacket(ID_PLAYER_TOPIC)->Send(); +} + void LocalPlayer::clearCellStates() { cellStateChanges.cellStates.clear(); diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index 948c975c5..afafef167 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -42,6 +42,7 @@ namespace mwmp void addItems(); void addSpells(); void addJournalItems(); + void addTopics(); void removeItems(); void removeSpells(); @@ -70,6 +71,7 @@ namespace mwmp void sendJournalEntry(const std::string& quest, int index, const MWWorld::Ptr& actor); void sendJournalIndex(const std::string& quest, int index); void sendFaction(const std::string& factionId, int rank, bool isExpelled); + void sendTopic(const std::string& topic); void clearCellStates(); void clearCurrentContainer(); diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerTopic.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerTopic.hpp index 320d87f62..5b7046885 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorPlayerTopic.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerTopic.hpp @@ -20,8 +20,8 @@ namespace mwmp { // Entire list of topics cannot currently be requested from players } - //else - //static_cast(player)->addTopics(); + else + static_cast(player)->addTopics(); } }; } diff --git a/apps/openmw/mwscript/dialogueextensions.cpp b/apps/openmw/mwscript/dialogueextensions.cpp index 0b4aa6d5c..480bfc03e 100644 --- a/apps/openmw/mwscript/dialogueextensions.cpp +++ b/apps/openmw/mwscript/dialogueextensions.cpp @@ -127,6 +127,17 @@ namespace MWScript runtime.pop(); MWBase::Environment::get().getDialogueManager()->addTopic(topic); + + /* + Start of tes3mp addition + + Send an ID_PLAYER_TOPIC packet every time a topic is added + through a script + */ + mwmp::Main::get().getLocalPlayer()->sendTopic(topic); + /* + End of tes3mp addition + */ } }; diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index e9afac9eb..627252c13 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -63,6 +63,11 @@ namespace mwmp bool isExpelled; }; + struct Topic + { + std::string topicId; + }; + struct CellState { ESM::Cell cell; @@ -88,6 +93,12 @@ namespace mwmp unsigned int count; }; + struct TopicChanges + { + std::vector topics; + unsigned int count; + }; + struct InventoryChanges { std::vector items; @@ -171,6 +182,7 @@ namespace mwmp SpellbookChanges spellbookChanges; JournalChanges journalChanges; FactionChanges factionChanges; + TopicChanges topicChanges; CellStateChanges cellStateChanges; ESM::ActiveSpells activeSpells; CurrentContainer currentContainer; diff --git a/components/openmw-mp/Packets/Player/PacketPlayerFaction.cpp b/components/openmw-mp/Packets/Player/PacketPlayerFaction.cpp index 3f6b0eeb9..3c5dba466 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerFaction.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerFaction.cpp @@ -13,10 +13,10 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); - if (!send) - player->factionChanges.factions.clear(); - else + if (send) player->factionChanges.count = (unsigned int)(player->factionChanges.factions.size()); + else + player->factionChanges.factions.clear(); RW(player->factionChanges.count, send); diff --git a/components/openmw-mp/Packets/Player/PacketPlayerTopic.cpp b/components/openmw-mp/Packets/Player/PacketPlayerTopic.cpp index f56c7ceae..b5612998f 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerTopic.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerTopic.cpp @@ -12,4 +12,24 @@ PacketPlayerTopic::PacketPlayerTopic(RakNet::RakPeerInterface *peer) : PlayerPac void PacketPlayerTopic::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); + + if (send) + player->topicChanges.count = (unsigned int)(player->topicChanges.topics.size()); + else + player->topicChanges.topics.clear(); + + RW(player->topicChanges.count, send); + + for (unsigned int i = 0; i < player->topicChanges.count; i++) + { + Topic topic; + + if (send) + topic = player->topicChanges.topics.at(i); + + RW(topic.topicId, send); + + if (!send) + player->topicChanges.topics.push_back(topic); + } }