[Client] Prevent scripts from creating PlayerTopic packet spam

pull/272/head
David Cernat 7 years ago
parent 8f543fb34e
commit a883c8f8aa

@ -46,6 +46,17 @@ namespace MWBase
virtual void addTopic (const std::string& topic) = 0; 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 askQuestion (const std::string& question,int choice) = 0;
virtual void goodbye() = 0; virtual void goodbye() = 0;

@ -97,6 +97,20 @@ namespace MWDialogue
mKnownTopics.insert( Misc::StringUtils::lowerCase(topic) ); 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) void DialogueManager::parseText (const std::string& text)
{ {
std::vector<HyperTextParser::Token> hypertext = HyperTextParser::parseHyperText(text); std::vector<HyperTextParser::Token> hypertext = HyperTextParser::parseHyperText(text);
@ -120,7 +134,7 @@ namespace MWDialogue
Send an ID_PLAYER_TOPIC packet every time a new topic becomes known 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); mwmp::Main::get().getLocalPlayer()->sendTopic(topicId);
/* /*
End of tes3mp addition End of tes3mp addition

@ -68,6 +68,17 @@ namespace MWDialogue
virtual void addTopic (const std::string& topic); 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 askQuestion (const std::string& question,int choice);
virtual void goodbye(); virtual void goodbye();

@ -128,18 +128,19 @@ namespace MWScript
std::string topic = runtime.getStringLiteral (runtime[0].mInteger); std::string topic = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
MWBase::Environment::get().getDialogueManager()->addTopic(topic);
/* /*
Start of tes3mp addition 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 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 End of tes3mp addition
*/ */
MWBase::Environment::get().getDialogueManager()->addTopic(topic);
} }
}; };

Loading…
Cancel
Save