Ensure that all actions are compared to fixed point in time (ie. world update start)

Port From (https://github.com/TrinityCore/TrinityCore/commit/60663d1374beef3103f4787152654034fa4a8897)
This commit is contained in:
hondacrx
2019-09-01 10:37:14 -04:00
parent dccded6a96
commit 87d30caa49
38 changed files with 302 additions and 169 deletions
-2
View File
@@ -806,8 +806,6 @@ namespace Game
Values[WorldCfg.ShowKickInWorld] = GetDefaultValue("ShowKickInWorld", false);
Values[WorldCfg.ShowMuteInWorld] = GetDefaultValue("ShowMuteInWorld", false);
Values[WorldCfg.ShowBanInWorld] = GetDefaultValue("ShowBanInWorld", false);
Values[WorldCfg.IntervalLogUpdate] = GetDefaultValue("RecordUpdateTimeDiffInterval", 60000);
Values[WorldCfg.MinLogUpdate] = GetDefaultValue("MinRecordUpdateTimeDiff", 100);
Values[WorldCfg.Numthreads] = GetDefaultValue("MapUpdate.Threads", 1);
Values[WorldCfg.MaxResultsLookupCommands] = GetDefaultValue("Command.LookupMaxResults", 0);
+38 -81
View File
@@ -43,10 +43,10 @@ namespace Game
m_timers[timer] = new IntervalTimer();
m_allowedSecurityLevel = AccountTypes.Player;
m_gameTime = Time.UnixTime;
m_startTime = m_gameTime;
_realm = new Realm();
_worldUpdateTime = new WorldUpdateTime();
}
public Player FindPlayerInZone(uint zone)
@@ -841,10 +841,9 @@ namespace Game
// Initialize game time and timers
Log.outInfo(LogFilter.ServerLoading, "Initialize game time and timers");
m_gameTime = Time.UnixTime;
m_startTime = m_gameTime;
GameTime.UpdateGameTimers();
DB.Login.Execute("INSERT INTO uptime (realmid, starttime, uptime, revision) VALUES({0}, {1}, 0, '{2}')", _realm.Id.Realm, m_startTime, ""); // One-time query
DB.Login.Execute("INSERT INTO uptime (realmid, starttime, uptime, revision) VALUES({0}, {1}, 0, '{2}')", _realm.Id.Realm, GameTime.GetStartTime(), ""); // One-time query
m_timers[WorldTimers.Auctions].SetInterval(Time.Minute * Time.InMilliseconds);
m_timers[WorldTimers.AuctionsPending].SetInterval(250);
@@ -871,7 +870,7 @@ namespace Game
//mailtimer is increased when updating auctions
//one second is 1000 -(tested on win system)
// @todo Get rid of magic numbers
var localTime = Time.UnixTimeToDateTime(m_gameTime).ToLocalTime();
var localTime = Time.UnixTimeToDateTime(GameTime.GetGameTime()).ToLocalTime();
mail_timer = ((((localTime.Hour + 20) % 24) * Time.Hour * Time.InMilliseconds) / m_timers[WorldTimers.Auctions].GetInterval());
//1440
mail_timer_expires = ((Time.Day * Time.InMilliseconds) / (m_timers[(int)WorldTimers.Auctions].GetInterval()));
@@ -1091,28 +1090,6 @@ namespace Game
Log.outInfo(LogFilter.ServerLoading, @"VMap data directory is: {0}\vmaps", GetDataPath());
}
void ResetTimeDiffRecord()
{
if (m_updateTimeCount != 1)
return;
m_currentTime = Time.GetMSTime();
}
void RecordTimeDiff(string text)
{
if (m_updateTimeCount != 1)
return;
uint thisTime = Time.GetMSTime();
uint diff = Time.GetMSTimeDiff(m_currentTime, thisTime);
if (diff > WorldConfig.GetIntValue(WorldCfg.MinLogUpdate))
Log.outInfo(LogFilter.Server, "Difftime {0}: {1}.", text, diff);
m_currentTime = thisTime;
}
public void LoadAutobroadcasts()
{
uint oldMSTime = Time.GetMSTime();
@@ -1142,22 +1119,14 @@ namespace Game
public void Update(uint diff)
{
m_updateTime = diff;
///- Update the game time and check for shutdown time
_UpdateGameTime();
long currentGameTime = GameTime.GetGameTime();
if (diff > 100)
{
if (m_updateTimeSum > 60000)
{
Log.outDebug(LogFilter.Server, "Update time diff: {0}. Players online: {1}.", m_updateTimeSum / m_updateTimeCount, GetActiveSessionCount());
m_updateTimeSum = m_updateTime;
m_updateTimeCount = 1;
}
else
{
m_updateTimeSum += m_updateTime;
++m_updateTimeCount;
}
}
_worldUpdateTime.UpdateWithDiff(diff);
// Record update if recording set in log and diff is greater then minimum set in log
_worldUpdateTime.RecordUpdateTime(GameTime.GetGameTimeMS(), diff, (uint)GetActiveSessionCount());
// Update the different timers
for (WorldTimers i = 0; i < WorldTimers.Max; ++i)
@@ -1175,31 +1144,28 @@ namespace Game
Global.WhoListStorageMgr.Update();
}
// Update the game time and check for shutdown time
_UpdateGameTime();
// Handle daily quests reset time
if (m_gameTime > m_NextDailyQuestReset)
if (currentGameTime > m_NextDailyQuestReset)
{
DailyReset();
InitDailyQuestResetTime(false);
}
// Handle weekly quests reset time
if (m_gameTime > m_NextWeeklyQuestReset)
if (currentGameTime > m_NextWeeklyQuestReset)
ResetWeeklyQuests();
// Handle monthly quests reset time
if (m_gameTime > m_NextMonthlyQuestReset)
if (currentGameTime > m_NextMonthlyQuestReset)
ResetMonthlyQuests();
if (m_gameTime > m_NextRandomBGReset)
if (currentGameTime > m_NextRandomBGReset)
ResetRandomBG();
if (m_gameTime > m_NextGuildReset)
if (currentGameTime > m_NextGuildReset)
ResetGuildCap();
if (m_gameTime > m_NextCurrencyReset)
if (currentGameTime > m_NextCurrencyReset)
ResetCurrencyWeekCap();
//Handle auctions when the timer has passed
@@ -1243,14 +1209,14 @@ namespace Game
}
//Handle session updates when the timer has passed
ResetTimeDiffRecord();
_worldUpdateTime.RecordUpdateTimeReset();
UpdateSessions(diff);
RecordTimeDiff("UpdateSessions");
_worldUpdateTime.RecordUpdateTimeDuration("UpdateSessions");
// <li> Update uptime table
if (m_timers[WorldTimers.UpTime].Passed())
{
uint tmpDiff = (uint)(m_gameTime - m_startTime);
uint tmpDiff = GameTime.GetUptime();
uint maxOnlinePlayers = GetMaxPlayerCount();
m_timers[WorldTimers.UpTime].Reset();
@@ -1260,7 +1226,7 @@ namespace Game
stmt.AddValue(0, tmpDiff);
stmt.AddValue(1, maxOnlinePlayers);
stmt.AddValue(2, _realm.Id.Realm);
stmt.AddValue(3, m_startTime);
stmt.AddValue(3, (uint)GameTime.GetStartTime());
DB.Login.Execute(stmt);
}
@@ -1281,9 +1247,9 @@ namespace Game
}
}
ResetTimeDiffRecord();
_worldUpdateTime.RecordUpdateTimeReset();
Global.MapMgr.Update(diff);
RecordTimeDiff("UpdateMapMgr");
_worldUpdateTime.RecordUpdateTimeDuration("UpdateMapMgr");
if (WorldConfig.GetBoolValue(WorldCfg.AutoBroadcast))
{
@@ -1295,13 +1261,13 @@ namespace Game
}
Global.BattlegroundMgr.Update(diff);
RecordTimeDiff("UpdateBattlegroundMgr");
_worldUpdateTime.RecordUpdateTimeDuration("UpdateBattlegroundMgr");
Global.OutdoorPvPMgr.Update(diff);
RecordTimeDiff("UpdateOutdoorPvPMgr");
_worldUpdateTime.RecordUpdateTimeDuration("UpdateOutdoorPvPMgr");
Global.BattleFieldMgr.Update(diff);
RecordTimeDiff("BattlefieldMgr");
_worldUpdateTime.RecordUpdateTimeDuration("BattlefieldMgr");
//- Delete all characters which have been deleted X days before
if (m_timers[WorldTimers.DeleteChars].Passed())
@@ -1311,14 +1277,14 @@ namespace Game
}
Global.LFGMgr.Update(diff);
RecordTimeDiff("UpdateLFGMgr");
_worldUpdateTime.RecordUpdateTimeDuration("UpdateLFGMgr");
Global.GroupMgr.Update(diff);
RecordTimeDiff("GroupMgr");
_worldUpdateTime.RecordUpdateTimeDuration("GroupMgr");
// execute callbacks from sql queries that were queued recently
ProcessQueryCallbacks();
RecordTimeDiff("ProcessQueryCallbacks");
_worldUpdateTime.RecordUpdateTimeDuration("ProcessQueryCallbacks");
// Erase corpses once every 20 minutes
if (m_timers[WorldTimers.Corpses].Passed())
@@ -1647,9 +1613,10 @@ namespace Game
void _UpdateGameTime()
{
// update the time
long thisTime = Time.UnixTime;
uint elapsed = (uint)(thisTime - m_gameTime);
m_gameTime = thisTime;
long lastGameTime = GameTime.GetGameTime();
GameTime.UpdateGameTimers();
uint elapsed = (uint)(GameTime.GetGameTime() - lastGameTime);
//- if there is a shutdown timer
if (!IsStopped && m_ShutdownTimer > 0 && elapsed > 0)
@@ -2218,15 +2185,6 @@ namespace Game
public void SetDataPath(string path) { _dataPath = path; }
// When server started?
long GetStartTime() { return m_startTime; }
// What time is it?
public long GetGameTime() { return m_gameTime; }
// Uptime (in secs)
public uint GetUptime() { return (uint)(m_gameTime - m_startTime); }
// Update time
public uint GetUpdateTime() { return m_updateTime; }
public long GetNextDailyQuestsResetTime() { return m_NextDailyQuestReset; }
public long GetNextWeeklyQuestsResetTime() { return m_NextWeeklyQuestReset; }
long GetNextRandomBGResetTime() { return m_NextRandomBGReset; }
@@ -2310,6 +2268,8 @@ namespace Game
public CleaningFlags GetCleaningFlags() { return m_CleaningFlags; }
public void SetCleaningFlags(CleaningFlags flags) { m_CleaningFlags = flags; }
public WorldUpdateTime GetWorldUpdateTime() { return _worldUpdateTime; }
#region Fields
uint m_ShutdownTimer;
ShutdownMask m_ShutdownMask;
@@ -2330,15 +2290,10 @@ namespace Game
bool m_isClosed;
long m_startTime;
long m_gameTime;
Dictionary<WorldTimers, IntervalTimer> m_timers = new Dictionary<WorldTimers, IntervalTimer>();
long mail_timer;
long mail_timer_expires;
long blackmarket_timer;
uint m_updateTime, m_updateTimeSum;
uint m_updateTimeCount;
uint m_currentTime;
ConcurrentDictionary<uint, WorldSession> m_sessions = new ConcurrentDictionary<uint, WorldSession>();
Dictionary<uint, long> m_disconnects = new Dictionary<uint, long>();
@@ -2371,6 +2326,8 @@ namespace Game
Realm _realm;
string _dataPath;
WorldUpdateTime _worldUpdateTime;
#endregion
}