[Talk] Disable ExtractAllItemIds for heavy regex

This commit is contained in:
Yunfan Li
2024-08-19 18:47:08 +08:00
parent 1700a20c89
commit 2c7cef0dc2
3 changed files with 40 additions and 32 deletions

View File

@@ -1002,23 +1002,26 @@ void PlayerbotAI::HandleBotOutgoingPacket(WorldPacket const& packet)
if (lang == LANG_ADDON) if (lang == LANG_ADDON)
return; return;
if (message.starts_with(sPlayerbotAIConfig->toxicLinksPrefix) // Disable since ExtractAllItemIds bad performance
&& (GetChatHelper()->ExtractAllItemIds(message).size() > 0 || GetChatHelper()->ExtractAllQuestIds(message).size() > 0) // if (message.starts_with(sPlayerbotAIConfig->toxicLinksPrefix) &&
&& sPlayerbotAIConfig->toxicLinksRepliesChance) // (GetChatHelper()->ExtractAllItemIds(message).size() > 0 ||
{ // GetChatHelper()->ExtractAllQuestIds(message).size() > 0) &&
if (urand(0, 50) > 0 || urand(1, 100) > sPlayerbotAIConfig->toxicLinksRepliesChance) // sPlayerbotAIConfig->toxicLinksRepliesChance)
{ // {
return; // if (urand(0, 50) > 0 || urand(1, 100) > sPlayerbotAIConfig->toxicLinksRepliesChance)
} // {
} // return;
else if ((GetChatHelper()->ExtractAllItemIds(message).count(19019) && sPlayerbotAIConfig->thunderfuryRepliesChance)) // }
{ // }
if (urand(0, 60) > 0 || urand(1, 100) > sPlayerbotAIConfig->thunderfuryRepliesChance) // else if ((GetChatHelper()->ExtractAllItemIds(message).count(19019) &&
{ // sPlayerbotAIConfig->thunderfuryRepliesChance))
return; // {
} // if (urand(0, 60) > 0 || urand(1, 100) > sPlayerbotAIConfig->thunderfuryRepliesChance)
} // {
else // return;
// }
// }
// else
{ {
if (isFromFreeBot && urand(0, 20)) if (isFromFreeBot && urand(0, 20))
return; return;
@@ -2782,7 +2785,7 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell,
// break; // break;
// } // }
// } // }
if (target->IsImmunedToSpell(spellInfo)) if (target->IsImmunedToSpell(spellInfo))
{ {
if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster())) if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))

View File

@@ -88,7 +88,7 @@ bool AcceptQuestAction::Execute(Event event)
std::stringstream ss; std::stringstream ss;
ss << "AcceptQuestAction {" << qInfo->GetTitle() << "} - {" << std::to_string(qInfo->GetQuestId()) << "}"; ss << "AcceptQuestAction {" << qInfo->GetTitle() << "} - {" << std::to_string(qInfo->GetQuestId()) << "}";
LOG_INFO("playerbots", "{}", ss.str().c_str()); LOG_INFO("playerbots", "{}", ss.str().c_str());
botAI->TellMaster(ss.str()); // botAI->TellMaster(ss.str());
} }
return hasAccept; return hasAccept;

View File

@@ -205,20 +205,21 @@ void ChatReplyAction::ChatReplyDo(Player* bot, uint32& type, uint32& guid1, uint
return; return;
} }
//toxic links // Disable since ExtractAllItemIds bad performance
if (msg.starts_with(sPlayerbotAIConfig->toxicLinksPrefix) // //toxic links
&& (GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllItemIds(msg).size() > 0 || GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllQuestIds(msg).size() > 0)) // if (msg.starts_with(sPlayerbotAIConfig->toxicLinksPrefix)
{ // && (GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllItemIds(msg).size() > 0 || GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllQuestIds(msg).size() > 0))
HandleToxicLinksReply(bot, chatChannelSource, msg, name); // {
return; // HandleToxicLinksReply(bot, chatChannelSource, msg, name);
} // return;
// }
//thunderfury // //thunderfury
if (GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllItemIds(msg).count(19019)) // if (GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllItemIds(msg).count(19019))
{ // {
HandleThunderfuryReply(bot, chatChannelSource, msg, name); // HandleThunderfuryReply(bot, chatChannelSource, msg, name);
return; // return;
} // }
auto messageRepy = GenerateReplyMessage(bot, msg, guid1, name); auto messageRepy = GenerateReplyMessage(bot, msg, guid1, name);
SendGeneralResponse(bot, chatChannelSource, messageRepy, name); SendGeneralResponse(bot, chatChannelSource, messageRepy, name);
@@ -316,6 +317,8 @@ bool ChatReplyAction::HandleToxicLinksReply(Player* bot, ChatChannelSource chatC
} }
bool ChatReplyAction::HandleWTBItemsReply(Player* bot, ChatChannelSource chatChannelSource, std::string& msg, std::string& name) bool ChatReplyAction::HandleWTBItemsReply(Player* bot, ChatChannelSource chatChannelSource, std::string& msg, std::string& name)
{ {
// Disable since ExtractAllItemIds bad performance
return false;
auto messageItemIds = GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllItemIds(msg); auto messageItemIds = GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllItemIds(msg);
if (messageItemIds.empty()) if (messageItemIds.empty())
@@ -409,6 +412,8 @@ bool ChatReplyAction::HandleWTBItemsReply(Player* bot, ChatChannelSource chatCha
} }
bool ChatReplyAction::HandleLFGQuestsReply(Player* bot, ChatChannelSource chatChannelSource, std::string& msg, std::string& name) bool ChatReplyAction::HandleLFGQuestsReply(Player* bot, ChatChannelSource chatChannelSource, std::string& msg, std::string& name)
{ {
// Disable since ExtractAllQuestIds bad performance
return false;
auto messageQuestIds = GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllQuestIds(msg); auto messageQuestIds = GET_PLAYERBOT_AI(bot)->GetChatHelper()->ExtractAllQuestIds(msg);
if (messageQuestIds.empty()) if (messageQuestIds.empty())