public static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
foreach (string a in args)
{
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"))
{
_Cache = false;
}
else if (Insensitive.Equals(a, "-haltonwarning"))
{
HaltOnWarning = true;
}
else if (Insensitive.Equals(a, "-vb"))
{
VBdotNet = true;
}
else if (Insensitive.Equals(a, "-usehrt"))
{
_UseHRT = true;
}
}
try
{
if (Service)
{
if (!Directory.Exists("Logs"))
{
Directory.CreateDirectory("Logs");
}
Console.SetOut(MultiConsoleOut = new MultiTextWriter(new FileLogger("Logs/Console.log")));
}
else
{
Console.SetOut(MultiConsoleOut = new MultiTextWriter(Console.Out));
}
}
catch
{ }
Thread = Thread.CurrentThread;
Process = Process.GetCurrentProcess();
Assembly = Assembly.GetEntryAssembly();
if (Thread != null)
{
Thread.Name = "Core Thread";
}
if (BaseDirectory.Length > 0)
{
Directory.SetCurrentDirectory(BaseDirectory);
}
Timer.TimerThread ttObj = new Timer.TimerThread();
_TimerThread = new Thread(ttObj.TimerMain)
{
Name = "Timer Thread"
};
Version ver = Assembly.GetName().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
Utility.PushColor(ConsoleColor.DarkGreen);
Console.WriteLine(new String('-', Console.BufferWidth));
Utility.PopColor();
Utility.PushColor(ConsoleColor.Cyan);
Console.WriteLine(
"ServUO - [http://www.servuo.com] Version {0}.{1}, Build {2}.{3}",
ver.Major,
ver.Minor,
ver.Build,
ver.Revision);
Utility.PopColor();
string s = Arguments;
if (s.Length > 0)
{
Utility.PushColor(ConsoleColor.Yellow);
Console.WriteLine("Core: Running with arguments: {0}", s);
Utility.PopColor();
}
ProcessorCount = Environment.ProcessorCount;
if (ProcessorCount > 1)
{
MultiProcessor = true;
}
if (MultiProcessor || Is64Bit)
{
Utility.PushColor(ConsoleColor.Green);
Console.WriteLine(
"Core: Optimizing for {0} {2}processor{1}",
ProcessorCount,
ProcessorCount == 1 ? "" : "s",
Is64Bit ? "64-bit " : "");
Utility.PopColor();
}
int platform = (int)Environment.OSVersion.Platform;
if (platform == 4 || platform == 128)
{
// MS 4, MONO 128
Unix = true;
Utility.PushColor(ConsoleColor.Yellow);
Console.WriteLine("Core: Unix environment detected");
Utility.PopColor();
}
else
{
m_ConsoleEventHandler = OnConsoleEvent;
UnsafeNativeMethods.SetConsoleCtrlHandler(m_ConsoleEventHandler, true);
}
if (GCSettings.IsServerGC)
{
Utility.PushColor(ConsoleColor.DarkYellow);
Console.WriteLine("Core: Server garbage collection mode enabled");
Utility.PopColor();
}
if (_UseHRT)
{
Utility.PushColor(ConsoleColor.DarkYellow);
Console.WriteLine(
"Core: Requested high resolution timing ({0})",
UsingHighResolutionTiming ? "Supported" : "Unsupported");
Utility.PopColor();
}
Utility.PushColor(ConsoleColor.DarkYellow);
Console.WriteLine("RandomImpl: {0} ({1})", RandomImpl.Type.Name, RandomImpl.IsHardwareRNG ? "Hardware" : "Software");
Utility.PopColor();
Utility.PushColor(ConsoleColor.DarkYellow);
Console.WriteLine("Core: Loading config...");
Config.Load();
Utility.PopColor();
while (!ScriptCompiler.Compile(Debug, _Cache))
{
Utility.PushColor(ConsoleColor.Red);
Console.WriteLine("Scripts: One or more scripts failed to compile or no script files were found.");
Utility.PopColor();
if (Service)
{
return;
}
Console.WriteLine(" - Press return to exit, or R to try again.");
if (Console.ReadKey(true).Key != ConsoleKey.R)
{
return;
}
}
ScriptCompiler.Invoke("Configure");
Region.Load();
World.Load();
ScriptCompiler.Invoke("Initialize");
MessagePump messagePump = MessagePump = new MessagePump();
_TimerThread.Start();
foreach (Map m in Map.AllMaps)
{
m.Tiles.Force();
}
NetState.Initialize();
EventSink.InvokeServerStarted();
try
{
long now, last = TickCount;
const int sampleInterval = 100;
const float ticksPerSecond = 1000.0f * sampleInterval;
long sample = 0;
while (!Closing)
{
_Signal.WaitOne();
Mobile.ProcessDeltaQueue();
Item.ProcessDeltaQueue();
Timer.Slice();
messagePump.Slice();
NetState.FlushAll();
NetState.ProcessDisposedQueue();
if (Slice != null)
{
Slice();
}
if (sample++ % sampleInterval != 0)
{
continue;
}
now = TickCount;
_CyclesPerSecond[_CycleIndex++ % _CyclesPerSecond.Length] = ticksPerSecond / (now - last);
last = now;
}
}
catch (Exception e)
{
CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true));
}
}