fix(core): Caches DateTime.NowUtc (#548)
- [X] Caches DateTime.NowUtc on the game loop (not other threads) - [X] Replaces all locations where it makes sense - [X] Adds Min/Max for `IComparable` (TimeSpan, DateTimes, etc) Closes #261
This commit is contained in:
parent
5de6edbeb8
commit
6c4308bce6
208 changed files with 660 additions and 793 deletions
|
|
@ -31,7 +31,7 @@ namespace Server
|
|||
|
||||
using (var op = new StreamWriter("ipLimits.log", true))
|
||||
{
|
||||
op.WriteLine("{0}\tPast IP limit threshold\t{1}", ip, DateTime.UtcNow);
|
||||
op.WriteLine("{0}\tPast IP limit threshold\t{1}", ip, Core.Now);
|
||||
}
|
||||
|
||||
e.AllowConnection = false;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ namespace Server.Accounting
|
|||
|
||||
m_AccessLevel = AccessLevel.Player;
|
||||
|
||||
Created = LastLogin = DateTime.UtcNow;
|
||||
Created = LastLogin = Core.Now;
|
||||
m_TotalGameTime = TimeSpan.Zero;
|
||||
|
||||
m_Mobiles = new Mobile[7];
|
||||
|
|
@ -99,8 +99,8 @@ namespace Server.Accounting
|
|||
|
||||
Enum.TryParse(Utility.GetText(node["accessLevel"], "Player"), true, out m_AccessLevel);
|
||||
Flags = Utility.GetXMLInt32(Utility.GetText(node["flags"], "0"), 0);
|
||||
Created = Utility.GetXMLDateTime(Utility.GetText(node["created"], null), DateTime.UtcNow);
|
||||
LastLogin = Utility.GetXMLDateTime(Utility.GetText(node["lastLogin"], null), DateTime.UtcNow);
|
||||
Created = Utility.GetXMLDateTime(Utility.GetText(node["created"], null), Core.Now);
|
||||
LastLogin = Utility.GetXMLDateTime(Utility.GetText(node["lastLogin"], null), Core.Now);
|
||||
|
||||
TotalGold = Utility.GetXMLInt32(Utility.GetText(node["totalGold"], "0"), 0);
|
||||
TotalPlat = Utility.GetXMLInt32(Utility.GetText(node["totalPlat"], "0"), 0);
|
||||
|
|
@ -193,7 +193,7 @@ namespace Server.Accounting
|
|||
|
||||
if (GetBanTags(out var banTime, out var banDuration))
|
||||
{
|
||||
if (banDuration != TimeSpan.MaxValue && DateTime.UtcNow >= banTime + banDuration)
|
||||
if (banDuration != TimeSpan.MaxValue && Core.Now >= banTime + banDuration)
|
||||
{
|
||||
SetUnspecifiedBan(null); // clear
|
||||
Banned = false;
|
||||
|
|
@ -244,7 +244,7 @@ namespace Server.Accounting
|
|||
return false;
|
||||
}
|
||||
|
||||
var inactiveLength = DateTime.UtcNow - LastLogin;
|
||||
var inactiveLength = Core.Now - LastLogin;
|
||||
|
||||
return inactiveLength > (Count == 0 ? EmptyInactiveDuration : InactiveDuration);
|
||||
}
|
||||
|
|
@ -262,7 +262,7 @@ namespace Server.Accounting
|
|||
{
|
||||
if (m_Mobiles[i] is PlayerMobile m && m.NetState != null)
|
||||
{
|
||||
return m_TotalGameTime + (DateTime.UtcNow - m.SessionStart);
|
||||
return m_TotalGameTime + (Core.Now - m.SessionStart);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -873,7 +873,7 @@ namespace Server.Accounting
|
|||
return;
|
||||
}
|
||||
|
||||
acc.m_TotalGameTime += DateTime.UtcNow - pm.SessionStart;
|
||||
acc.m_TotalGameTime += Core.Now - pm.SessionStart;
|
||||
}
|
||||
|
||||
private static void EventSink_Login(Mobile m)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace Server.Accounting
|
|||
return true;
|
||||
}
|
||||
|
||||
var date = DateTime.UtcNow;
|
||||
var date = Core.Now;
|
||||
var access = accessLog.LastAccessTime + ComputeThrottle(accessLog.Counts);
|
||||
var allow = date >= access;
|
||||
drop = !allow;
|
||||
|
|
@ -96,7 +96,7 @@ namespace Server.Accounting
|
|||
using var op = new StreamWriter("throttle.log", true);
|
||||
op.WriteLine(
|
||||
"{0}\t{1}\t{2}",
|
||||
DateTime.UtcNow,
|
||||
Core.Now,
|
||||
ns,
|
||||
accessLog.Counts
|
||||
);
|
||||
|
|
@ -151,13 +151,13 @@ namespace Server.Accounting
|
|||
|
||||
public DateTime LastAccessTime { get; set; }
|
||||
|
||||
public bool HasExpired => DateTime.UtcNow >= LastAccessTime + TimeSpan.FromHours(1.0);
|
||||
public bool HasExpired => Core.Now >= LastAccessTime + TimeSpan.FromHours(1.0);
|
||||
|
||||
public int Counts { get; set; }
|
||||
|
||||
public void RefreshAccessTime()
|
||||
{
|
||||
LastAccessTime = DateTime.UtcNow;
|
||||
LastAccessTime = Core.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace Server.Accounting
|
|||
{
|
||||
AddedBy = addedBy;
|
||||
m_Content = content;
|
||||
LastModified = DateTime.UtcNow;
|
||||
LastModified = Core.Now;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -26,7 +26,7 @@ namespace Server.Accounting
|
|||
public AccountComment(XmlElement node)
|
||||
{
|
||||
AddedBy = Utility.GetAttribute(node, "addedBy", "empty");
|
||||
LastModified = Utility.GetXMLDateTime(Utility.GetAttribute(node, "lastModified"), DateTime.UtcNow);
|
||||
LastModified = Utility.GetXMLDateTime(Utility.GetAttribute(node, "lastModified"), Core.Now);
|
||||
m_Content = Utility.GetText(node, "");
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +55,7 @@ namespace Server.Accounting
|
|||
set
|
||||
{
|
||||
m_Content = value;
|
||||
LastModified = DateTime.UtcNow;
|
||||
LastModified = Core.Now;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ namespace Server.Misc
|
|||
{
|
||||
res = DeleteResultType.CharBeingPlayed;
|
||||
}
|
||||
else if (RestrictDeletion && DateTime.UtcNow < m.CreationTime + DeleteDelay)
|
||||
else if (RestrictDeletion && Core.Now < m.CreationTime + DeleteDelay)
|
||||
{
|
||||
res = DeleteResultType.CharTooYoung;
|
||||
}
|
||||
|
|
@ -336,7 +336,7 @@ namespace Server.Misc
|
|||
Console.WriteLine("Login: {0}: Past IP limit threshold", e.State);
|
||||
|
||||
using var op = new StreamWriter("ipLimits.log", true);
|
||||
op.WriteLine("{0}\tPast IP limit threshold\t{1}", e.State, DateTime.UtcNow);
|
||||
op.WriteLine("{0}\tPast IP limit threshold\t{1}", e.State, Core.Now);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -404,7 +404,7 @@ namespace Server.Misc
|
|||
Console.WriteLine("Login: {0}: Past IP limit threshold", e.State);
|
||||
|
||||
using var op = new StreamWriter("ipLimits.log", true);
|
||||
op.WriteLine("{0}\tPast IP limit threshold\t{1}", e.State, DateTime.UtcNow);
|
||||
op.WriteLine("{0}\tPast IP limit threshold\t{1}", e.State, Core.Now);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue