fix(core): NPE in Cycles per second (#331)
- [X] Fixes an edge case where the cycle index goes negative and crashes - [X] Fixes average CPS calculation - [X] Fixes issue with logout delay - [X] Bumps release version
This commit is contained in:
parent
b71c754738
commit
75c1b32513
88 changed files with 216 additions and 188 deletions
|
|
@ -40,8 +40,8 @@ namespace Server
|
|||
private static TimeSpan m_ProfileTime;
|
||||
private static bool? m_IsRunningFromXUnit;
|
||||
|
||||
private static int m_CycleIndex = 1;
|
||||
private static readonly float[] m_CyclesPerSecond = new float[100];
|
||||
private static long m_CycleIndex;
|
||||
private static readonly float[] m_CyclesPerSecond = new float[127]; // Divisible by long.MaxValue
|
||||
|
||||
// private static readonly AutoResetEvent m_Signal = new AutoResetEvent(true);
|
||||
|
||||
|
|
@ -137,9 +137,23 @@ namespace Server
|
|||
|
||||
public static bool Closing => ClosingTokenSource.IsCancellationRequested;
|
||||
|
||||
public static float CyclesPerSecond => m_CyclesPerSecond[(m_CycleIndex - 1) % m_CyclesPerSecond.Length];
|
||||
public static float CyclesPerSecond => m_CyclesPerSecond[m_CycleIndex % m_CyclesPerSecond.Length];
|
||||
|
||||
public static float AverageCPS => m_CyclesPerSecond.Take(m_CycleIndex).Average();
|
||||
public static float AverageCPS
|
||||
{
|
||||
get
|
||||
{
|
||||
var total = 0.0f;
|
||||
var count = Math.Min(m_CycleIndex + 1, m_CyclesPerSecond.Length);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
total += m_CyclesPerSecond[i];
|
||||
}
|
||||
|
||||
return total / count;
|
||||
}
|
||||
}
|
||||
|
||||
public static string Arguments
|
||||
{
|
||||
|
|
@ -452,7 +466,7 @@ namespace Server
|
|||
{
|
||||
try
|
||||
{
|
||||
long last = TickCount;
|
||||
long now, last = TickCount;
|
||||
|
||||
const int sampleInterval = 100;
|
||||
const float ticksPerSecond = 1000.0f * sampleInterval;
|
||||
|
|
@ -481,8 +495,9 @@ namespace Server
|
|||
continue;
|
||||
}
|
||||
|
||||
var now = TickCount;
|
||||
m_CyclesPerSecond[m_CycleIndex++ % m_CyclesPerSecond.Length] = ticksPerSecond / (now - last);
|
||||
now = TickCount;
|
||||
m_CyclesPerSecond[m_CycleIndex % m_CyclesPerSecond.Length] = ticksPerSecond / (now - last);
|
||||
m_CycleIndex = Math.Max(unchecked(m_CycleIndex + 1), 0);
|
||||
last = now;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -432,7 +432,6 @@ namespace Server
|
|||
private static readonly TimeSpan WarmodeSpamCatch = TimeSpan.FromSeconds(Core.SE ? 1.0 : 0.5);
|
||||
private static readonly TimeSpan WarmodeSpamDelay = TimeSpan.FromSeconds(Core.SE ? 4.0 : 2.0);
|
||||
private static readonly TimeSpan ExpireCombatantDelay = TimeSpan.FromMinutes(1.0);
|
||||
private static readonly TimeSpan LogoutDelay = TimeSpan.FromDays(1.0);
|
||||
private static readonly TimeSpan ExpireAggressorsDelay = TimeSpan.FromSeconds(5.0);
|
||||
|
||||
private static readonly Packet[][] m_MovingPacketCache =
|
||||
|
|
@ -441,13 +440,13 @@ namespace Server
|
|||
new Packet[8]
|
||||
};
|
||||
|
||||
private static readonly List<IEntity> m_MoveList = new List<IEntity>();
|
||||
private static readonly List<Mobile> m_MoveClientList = new List<Mobile>();
|
||||
private static readonly List<IEntity> m_MoveList = new();
|
||||
private static readonly List<Mobile> m_MoveClientList = new();
|
||||
|
||||
private static readonly object m_GhostMutateContext = new object();
|
||||
private static readonly object m_GhostMutateContext = new();
|
||||
|
||||
private static readonly List<Mobile> m_Hears = new List<Mobile>();
|
||||
private static readonly List<IEntity> m_OnSpeech = new List<IEntity>();
|
||||
private static readonly List<Mobile> m_Hears = new();
|
||||
private static readonly List<IEntity> m_OnSpeech = new();
|
||||
|
||||
private static readonly string[] m_AccessLevelNames =
|
||||
{
|
||||
|
|
@ -469,8 +468,8 @@ namespace Server
|
|||
198
|
||||
};
|
||||
|
||||
private static readonly Queue<Mobile> m_DeltaQueue = new Queue<Mobile>();
|
||||
private static readonly Queue<Mobile> m_DeltaQueueR = new Queue<Mobile>();
|
||||
private static readonly Queue<Mobile> m_DeltaQueue = new();
|
||||
private static readonly Queue<Mobile> m_DeltaQueueR = new();
|
||||
|
||||
private static bool _processing;
|
||||
|
||||
|
|
@ -1496,15 +1495,14 @@ namespace Server
|
|||
// Disconnected, start the logout timer
|
||||
if (m_LogoutTimer == null)
|
||||
{
|
||||
m_LogoutTimer = Timer.DelayCall(LogoutDelay, Logout);
|
||||
m_LogoutTimer = Timer.DelayCall(GetLogoutDelay(), Logout);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_LogoutTimer.Stop();
|
||||
m_LogoutTimer.Delay = GetLogoutDelay();
|
||||
m_LogoutTimer.Start();
|
||||
}
|
||||
|
||||
m_LogoutTimer.Delay = GetLogoutDelay();
|
||||
m_LogoutTimer.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
<Product>ModernUO Server</Product>
|
||||
<PublishDir>..\..\Distribution</PublishDir>
|
||||
<OutDir>..\..\Distribution</OutDir>
|
||||
<Version>0.0.0</Version>
|
||||
</PropertyGroup>
|
||||
<Target Name="CleanPub" AfterTargets="Clean">
|
||||
<Message Text="Removing distribution files..." />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue