From 1ccc903f2b5c7b609a9c331b0102bc3e2cb15cec Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 31 Oct 2022 13:46:30 -0400 Subject: [PATCH] Core/Conversations: Added validation for conversation_template.FirstLineId Port From (https://github.com/TrinityCore/TrinityCore/commit/1b6695e51c75da8ac0ac80c1225d2dd9d0242843) --- .../DataStorage/ConversationDataStorage.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Source/Game/DataStorage/ConversationDataStorage.cs b/Source/Game/DataStorage/ConversationDataStorage.cs index 442ad2826..13da98827 100644 --- a/Source/Game/DataStorage/ConversationDataStorage.cs +++ b/Source/Game/DataStorage/ConversationDataStorage.cs @@ -113,6 +113,21 @@ namespace Game.DataStorage Log.outInfo(LogFilter.ServerLoading, "Loaded 0 Conversation actors. DB table `conversation_actors` is empty."); } + // Validate FirstLineId + Dictionary prevConversationLineIds = new(); + foreach (var conversationLine in CliDB.ConversationLineStorage.Values) + if (conversationLine.NextConversationLineID != 0) + prevConversationLineIds[conversationLine.NextConversationLineID] = conversationLine.Id; + + uint getFirstLineIdFromAnyLineId(uint lineId) + { + uint prevLineId; + while ((prevLineId = prevConversationLineIds.LookupByKey(lineId)) != 0) + lineId = prevLineId; + + return lineId; + } + SQLResult templateResult = DB.World.Query("SELECT Id, FirstLineId, TextureKitId, ScriptName FROM conversation_template"); if (!templateResult.IsEmpty()) { @@ -128,6 +143,13 @@ namespace Game.DataStorage conversationTemplate.Actors = actorsByConversation.TryGetValue(conversationTemplate.Id, out var actors) ? actors.ToList() : null; + uint correctedFirstLineId = getFirstLineIdFromAnyLineId(conversationTemplate.FirstLineId); + if (conversationTemplate.FirstLineId != correctedFirstLineId) + { + Log.outError(LogFilter.Sql, $"Table `conversation_template` has incorrect FirstLineId {conversationTemplate.FirstLineId}, it should be {correctedFirstLineId} for Conversation {conversationTemplate.Id}, corrected"); + conversationTemplate.FirstLineId = correctedFirstLineId; + } + ConversationLineRecord currentConversationLine = CliDB.ConversationLineStorage.LookupByKey(conversationTemplate.FirstLineId); if (currentConversationLine == null) Log.outError(LogFilter.Sql, "Table `conversation_template` references an invalid line (ID: {0}) for Conversation {1}, skipped", conversationTemplate.FirstLineId, conversationTemplate.Id);