Core/Conversations: Added validation for conversation_template.FirstLineId

Port From (https://github.com/TrinityCore/TrinityCore/commit/1b6695e51c75da8ac0ac80c1225d2dd9d0242843)
This commit is contained in:
hondacrx
2022-10-31 13:46:30 -04:00
parent 77bb4dec2e
commit 1ccc903f2b
@@ -113,6 +113,21 @@ namespace Game.DataStorage
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 Conversation actors. DB table `conversation_actors` is empty.");
}
// Validate FirstLineId
Dictionary<uint, uint> 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);