aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2022-10-29 21:22:40 +0200
committerShauren <shauren.trinity@gmail.com>2022-10-29 21:22:40 +0200
commit1b6695e51c75da8ac0ac80c1225d2dd9d0242843 (patch)
treeb16a963fde54a331a48437764a3d0c5c23d0cbb4
parent734babc6e9c5b9e742934fd5465c4064c9a0f4e8 (diff)
Core/Conversations: Added validation for conversation_template.FirstLineId
-rw-r--r--src/server/game/Globals/ConversationDataStore.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/server/game/Globals/ConversationDataStore.cpp b/src/server/game/Globals/ConversationDataStore.cpp
index d445827eaf8..97aa928256a 100644
--- a/src/server/game/Globals/ConversationDataStore.cpp
+++ b/src/server/game/Globals/ConversationDataStore.cpp
@@ -197,6 +197,20 @@ void ConversationDataStore::LoadConversationTemplates()
TC_LOG_INFO("server.loading", ">> Loaded 0 Conversation actors. DB table `conversation_actors` is empty.");
}
+ // Validate FirstLineId
+ std::unordered_map<uint32, uint32> prevConversationLineIds;
+ for (ConversationLineEntry const* conversationLine : sConversationLineStore)
+ if (conversationLine->NextConversationLineID)
+ prevConversationLineIds[conversationLine->NextConversationLineID] = conversationLine->ID;
+
+ auto getFirstLineIdFromAnyLineId = [&](uint32 lineId)
+ {
+ while (uint32 const* prevLineId = Trinity::Containers::MapGetValuePtr(prevConversationLineIds, lineId))
+ lineId = *prevLineId;
+
+ return lineId;
+ };
+
if (QueryResult templates = WorldDatabase.Query("SELECT Id, FirstLineId, TextureKitId, ScriptName FROM conversation_template"))
{
uint32 oldMSTime = getMSTime();
@@ -213,6 +227,14 @@ void ConversationDataStore::LoadConversationTemplates()
conversationTemplate.Actors = std::move(actorsByConversation[conversationTemplate.Id]);
+ uint32 correctedFirstLineId = getFirstLineIdFromAnyLineId(conversationTemplate.FirstLineId);
+ if (conversationTemplate.FirstLineId != correctedFirstLineId)
+ {
+ TC_LOG_ERROR("sql.sql", "Table `conversation_template` has incorrect FirstLineId %u, it should be %u for Conversation %u, corrected",
+ conversationTemplate.FirstLineId, correctedFirstLineId, conversationTemplate.Id);
+ conversationTemplate.FirstLineId = correctedFirstLineId;
+ }
+
ConversationLineEntry const* currentConversationLine = sConversationLineStore.LookupEntry(conversationTemplate.FirstLineId);
if (!currentConversationLine)
TC_LOG_ERROR("sql.sql", "Table `conversation_template` references an invalid line (ID: %u) for Conversation %u, skipped", conversationTemplate.FirstLineId, conversationTemplate.Id);