From a883c8f8aa24616066a0544c7c1a0820cd06d552 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 23 Aug 2017 07:14:45 +0300 Subject: [PATCH] [Client] Prevent scripts from creating PlayerTopic packet spam --- apps/openmw/mwbase/dialoguemanager.hpp | 11 +++++++++++ apps/openmw/mwdialogue/dialoguemanagerimp.cpp | 16 +++++++++++++++- apps/openmw/mwdialogue/dialoguemanagerimp.hpp | 11 +++++++++++ apps/openmw/mwscript/dialogueextensions.cpp | 9 +++++---- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwbase/dialoguemanager.hpp b/apps/openmw/mwbase/dialoguemanager.hpp index 3771f0a3d..2aedb48fc 100644 --- a/apps/openmw/mwbase/dialoguemanager.hpp +++ b/apps/openmw/mwbase/dialoguemanager.hpp @@ -46,6 +46,17 @@ namespace MWBase virtual void addTopic (const std::string& topic) = 0; + /* + Start of tes3mp addition + + Make it possible to check whether a topic is known by the player from elsewhere + in the code + */ + virtual bool isNewTopic(const std::string& topic) = 0; + /* + End of tes3mp addition + */ + virtual void askQuestion (const std::string& question,int choice) = 0; virtual void goodbye() = 0; diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index 7578bd9d7..abb6ebd89 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -97,6 +97,20 @@ namespace MWDialogue mKnownTopics.insert( Misc::StringUtils::lowerCase(topic) ); } + /* + Start of tes3mp addition + + Make it possible to check whether a topic is known by the player from elsewhere + in the code + */ + bool DialogueManager::isNewTopic(const std::string& topic) + { + return (!mKnownTopics.count(topic)); + } + /* + End of tes3mp addition + */ + void DialogueManager::parseText (const std::string& text) { std::vector hypertext = HyperTextParser::parseHyperText(text); @@ -120,7 +134,7 @@ namespace MWDialogue Send an ID_PLAYER_TOPIC packet every time a new topic becomes known */ - if (mActorKnownTopics.count(topicId) && !mKnownTopics.count(topicId)) + if (mActorKnownTopics.count(topicId) && isNewTopic(topicId)) mwmp::Main::get().getLocalPlayer()->sendTopic(topicId); /* End of tes3mp addition diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp index 40a24a1f8..00dbf5c05 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp @@ -68,6 +68,17 @@ namespace MWDialogue virtual void addTopic (const std::string& topic); + /* + Start of tes3mp addition + + Make it possible to check whether a topic is known by the player from elsewhere + in the code + */ + virtual bool isNewTopic(const std::string& topic); + /* + End of tes3mp addition + */ + virtual void askQuestion (const std::string& question,int choice); virtual void goodbye(); diff --git a/apps/openmw/mwscript/dialogueextensions.cpp b/apps/openmw/mwscript/dialogueextensions.cpp index 3380f6b7f..3295134e6 100644 --- a/apps/openmw/mwscript/dialogueextensions.cpp +++ b/apps/openmw/mwscript/dialogueextensions.cpp @@ -128,18 +128,19 @@ namespace MWScript std::string topic = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - MWBase::Environment::get().getDialogueManager()->addTopic(topic); - /* Start of tes3mp addition - Send an ID_PLAYER_TOPIC packet every time a topic is added + Send an ID_PLAYER_TOPIC packet every time a new topic is added through a script */ - mwmp::Main::get().getLocalPlayer()->sendTopic(topic); + if (MWBase::Environment::get().getDialogueManager()->isNewTopic(Misc::StringUtils::lowerCase(topic))) + mwmp::Main::get().getLocalPlayer()->sendTopic(Misc::StringUtils::lowerCase(topic)); /* End of tes3mp addition */ + + MWBase::Environment::get().getDialogueManager()->addTopic(topic); } };