Core/Creature: fix integer overflow in Creature.Update leading to endless thrashing of characters database

Port From (https://github.com/TrinityCore/TrinityCore/commit/0d8c1b49b82081eac42ca68ec0d9ee199bb1eda3)
This commit is contained in:
hondacrx
2020-05-12 17:13:36 -04:00
parent 1315f2c7f5
commit a1699494d5
+12 -1
View File
@@ -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<time_t>::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
}
}