Revert "Updates Packets & Randomizer (#43)" (#61)

This reverts commit 179cb50557.
This commit is contained in:
Kamron Batman 2019-11-11 08:46:11 -08:00 • committed by GitHub
parent 179cb50557
commit c2ecc76457
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
588 changed files with 16260 additions and 10926 deletions

View file

@ -39,6 +39,10 @@ namespace Server
{
private static bool m_Crashed;
private static Thread timerThread;
private static string m_BaseDirectory;
private static string m_ExePath;
private static bool m_Cache = true;
private static bool m_Profiling;
private static DateTime m_ProfileStart;
@ -52,16 +56,18 @@ namespace Server
* GetTickCount and GetTickCount64 have poor resolution.
* GetTickCount64 is unavailable on Windows XP and Windows Server 2003.
* Stopwatch.GetTimestamp() (QueryPerformanceCounter) is high resolution, but
* somewhat expensive to call because of its difference to DateTime.Now,
* somewhat expensive to call because of its defference to DateTime.Now,
* which is why Stopwatch has been used to verify HRT before calling GetTimestamp(),
* enabling the usage of DateTime.UtcNow instead.
*/
private static readonly bool UsingHighResolutionTiming = Stopwatch.IsHighResolution;
private static readonly bool _HighRes = Stopwatch.IsHighResolution;
private static readonly double _HighFrequency = 1000.0 / Stopwatch.Frequency;
private static readonly double _LowFrequency = 1000.0 / TimeSpan.TicksPerSecond;
private static bool _UseHRT;
public static readonly bool Is64Bit = Environment.Is64BitProcess;
internal static ConsoleEventHandler m_ConsoleEventHandler;
@ -93,8 +99,16 @@ namespace Server
}
}
public static TimeSpan ProfileTime =>
m_ProfileStart > DateTime.MinValue ? m_ProfileTime + (DateTime.UtcNow - m_ProfileStart) : m_ProfileTime;
public static TimeSpan ProfileTime
{
get
{
if (m_ProfileStart > DateTime.MinValue)
return m_ProfileTime + (DateTime.UtcNow - m_ProfileStart);
return m_ProfileTime;
}
}
public static bool Service{ get; private set; }
@ -102,22 +116,28 @@ namespace Server
internal static bool HaltOnWarning{ get; private set; }
public static List<string> DataDirectories{ get; } = new List<string>();
public static Assembly Assembly{ get; set; }
public static Assembly Assembly { get; } = Assembly.GetEntryAssembly();
public static readonly Version Version = Assembly.GetName().Version;
public static Process Process { get; } = Process.GetCurrentProcess();
public static Version Version => Assembly.GetName().Version;
public static Process Process{ get; private set; }
public static Thread Thread{ get; private set; }
public static MultiTextWriter MultiConsoleOut{ get; private set; }
public static bool UsingHighResolutionTiming => _UseHRT && _HighRes && !Unix;
public static long TickCount => (long)Ticks;
public static double Ticks =>
UsingHighResolutionTiming ? Stopwatch.GetTimestamp() * _HighFrequency : DateTime.UtcNow.Ticks * _LowFrequency;
public static double Ticks
{
get
{
if (_UseHRT && _HighRes && !Unix) return Stopwatch.GetTimestamp() * _HighFrequency;
return DateTime.UtcNow.Ticks * _LowFrequency;
}
}
public static bool MultiProcessor{ get; private set; }
@ -125,9 +145,28 @@ namespace Server
public static bool Unix{ get; private set; }
public static string ExePath => Process.MainModule?.FileName;
public static string ExePath => m_ExePath ?? (m_ExePath = Assembly.Location);
public static readonly string BaseDirectory = Path.GetDirectoryName(ExePath ?? "") ?? "";
public static string BaseDirectory
{
get
{
if (m_BaseDirectory == null)
try
{
m_BaseDirectory = ExePath;
if (m_BaseDirectory.Length > 0)
m_BaseDirectory = Path.GetDirectoryName(m_BaseDirectory);
}
catch
{
m_BaseDirectory = "";
}
return m_BaseDirectory;
}
}
public static bool Closing{ get; private set; }
@ -150,9 +189,15 @@ namespace Server
if (m_Profiling)
Utility.Separate(sb, "-profile", " ");
if (!m_Cache)
Utility.Separate(sb, "-nocache", " ");
if (HaltOnWarning)
Utility.Separate(sb, "-haltonwarning", " ");
if (_UseHRT)
Utility.Separate(sb, "-usehrt", " ");
return sb.ToString();
}
}
@ -234,8 +279,10 @@ namespace Server
private static bool OnConsoleEvent(ConsoleEventType type)
{
if (!(World.Saving || Service && type == ConsoleEventType.CTRL_LOGOFF_EVENT))
Kill(); //Kill -> HandleClosed will handle waiting for the completion of flushing to disk
if (World.Saving || Service && type == ConsoleEventType.CTRL_LOGOFF_EVENT)
return true;
Kill(); //Kill -> HandleClosed will handle waiting for the completion of flushing to disk
return true;
}
@ -274,7 +321,10 @@ namespace Server
Console.WriteLine("done");
}
public static void Set() => m_Signal.Set();
public static void Set()
{
m_Signal.Set();
}
public static void Main(string[] args)
{
@ -282,12 +332,18 @@ namespace Server
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
foreach (string a in args)
{
Debug |= Insensitive.Equals(a, "-debug");
Service |= Insensitive.Equals(a, "-service");
Profiling |= Insensitive.Equals(a, "-profiling");
HaltOnWarning |= Insensitive.Equals(a, "-haltonwarning");
}
if (Insensitive.Equals(a, "-debug"))
Debug = true;
else if (Insensitive.Equals(a, "-service"))
Service = true;
else if (Insensitive.Equals(a, "-profile"))
Profiling = true;
else if (Insensitive.Equals(a, "-nocache"))
m_Cache = false;
else if (Insensitive.Equals(a, "-haltonwarning"))
HaltOnWarning = true;
else if (Insensitive.Equals(a, "-usehrt"))
_UseHRT = true;
try
{
@ -299,7 +355,9 @@ namespace Server
Console.SetOut(MultiConsoleOut = new MultiTextWriter(new FileLogger("Logs/Console.log")));
}
else
{
Console.SetOut(MultiConsoleOut = new MultiTextWriter(Console.Out));
}
}
catch
{
@ -307,6 +365,8 @@ namespace Server
}
Thread = Thread.CurrentThread;
Process = Process.GetCurrentProcess();
Assembly = Assembly.GetEntryAssembly();
if (Thread != null)
Thread.Name = "Core Thread";
@ -339,12 +399,6 @@ namespace Server
Name = "Timer Thread"
};
Version ver = Version;
// Added to help future code support on forums, as a 'check' people can ask for to it see if they recompiled core or not
Console.WriteLine("ModernUO - [https://github.com/modernuo/modernuo] v{0}.{1}.{2}{3}", ver.Major, ver.Minor, ver.Build, ver.Revision != 0 ? ver.Revision.ToString() : "");
Console.WriteLine("Core: Running on {0}", RuntimeInformation.FrameworkDescription);
string s = Arguments;
if (s.Length > 0)
@ -352,15 +406,17 @@ namespace Server
ProcessorCount = Environment.ProcessorCount;
MultiProcessor |= ProcessorCount > 1;
if (ProcessorCount > 1)
MultiProcessor = true;
if (!Is64Bit) throw new NotSupportedException("Core: 32-bit operating systems are not supported");
if (MultiProcessor || Is64Bit)
Console.WriteLine("Core: Optimizing for {0} {2}processor{1}", ProcessorCount, ProcessorCount == 1 ? "" : "s",
Is64Bit ? "64-bit " : "");
if (MultiProcessor)
Console.WriteLine("Core: Optimizing for {0} processor{1}", ProcessorCount, ProcessorCount == 1 ? "" : "s");
if (Environment.OSVersion.Platform == PlatformID.Unix)
int platform = (int)Environment.OSVersion.Platform;
if (platform == 4 || platform == 128)
{
// MS 4, MONO 128
Unix = true;
Console.WriteLine("Core: Unix environment detected");
}
@ -373,8 +429,9 @@ namespace Server
if (GCSettings.IsServerGC)
Console.WriteLine("Core: Server garbage collection mode enabled");
if (UsingHighResolutionTiming)
Console.WriteLine("Core: High resolution timing detected");
if (_UseHRT)
Console.WriteLine("Core: Requested high resolution timing ({0})",
UsingHighResolutionTiming ? "Supported" : "Unsupported");
Console.WriteLine("RandomImpl: {0} ({1})", RandomImpl.Type.Name,
RandomImpl.IsHardwareRNG ? "Hardware" : "Software");
@ -416,9 +473,7 @@ namespace Server
{
m_Signal.WaitOne();
Task.WhenAll(
Task.WaitAll(
Task.Run(Mobile.ProcessDeltaQueue),
Task.Run(Item.ProcessDeltaQueue)
);
@ -484,7 +539,8 @@ namespace Server
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly) ==
null)
{
warningSb ??= new StringBuilder();
if (warningSb == null) warningSb = new StringBuilder();
warningSb.AppendLine(" - No Serialize() method");
}
@ -494,7 +550,8 @@ namespace Server
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly) ==
null)
{
warningSb ??= new StringBuilder();
if (warningSb == null) warningSb = new StringBuilder();
warningSb.AppendLine(" - No Deserialize() method");
}
@ -508,8 +565,7 @@ namespace Server
private static void VerifySerialization(Assembly a)
{
if (a != null)
Parallel.ForEach(a.GetTypes(), VerifyType);
if (a != null) Parallel.ForEach(a.GetTypes(), VerifyType);
}
internal enum ConsoleEventType