From a1699494d5cd191ed3212649ed766a5c4a9be285 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 12 May 2020 17:13:36 -0400 Subject: [PATCH] Core/Creature: fix integer overflow in Creature.Update leading to endless thrashing of characters database Port From (https://github.com/TrinityCore/TrinityCore/commit/0d8c1b49b82081eac42ca68ec0d9ee199bb1eda3) --- Source/Game/Entities/Creature/Creature.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Source/Game/Entities/Creature/Creature.cs b/Source/Game/Entities/Creature/Creature.cs index cfaaca192..df2ac9753 100644 --- a/Source/Game/Entities/Creature/Creature.cs +++ b/Source/Game/Entities/Creature/Creature.cs @@ -396,7 +396,18 @@ namespace Game.Entities if (targetGuid == dbtableHighGuid) // if linking self, never respawn (check delayed to next day) SetRespawnTime(Time.Day); else - m_respawnTime = (now > linkedRespawntime ? now : linkedRespawntime) + RandomHelper.IRand(5, Time.Minute); // else copy time from master and add a little + { + // else copy time from master and add a little + long baseRespawnTime = Math.Max(linkedRespawntime, now); + long offset = RandomHelper.URand(5, Time.Minute); + + // linked guid can be a boss, uses std::numeric_limits::max to never respawn in that instance + // we shall inherit it instead of adding and causing an overflow + if (baseRespawnTime <= long.MaxValue - offset) + m_respawnTime = baseRespawnTime + offset; + else + m_respawnTime = long.MaxValue; + } SaveRespawnTime(); // also save to DB immediately } }