public static void Main( string[] args )
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException );
AppDomain.CurrentDomain.ProcessExit += new EventHandler( CurrentDomain_ProcessExit );
for( int i = 0; i < args.Length; ++i )
{
if ( Insensitive.Equals( args[i], "-debug" ) )
m_Debug = true;
else if ( Insensitive.Equals( args[i], "-service" ) )
m_Service = true;
else if ( Insensitive.Equals( args[i], "-profile" ) )
Profiling = true;
else if ( Insensitive.Equals( args[i], "-nocache" ) )
m_Cache = false;
else if ( Insensitive.Equals( args[i], "-haltonwarning" ) )
m_HaltOnWarning = true;
else if ( Insensitive.Equals( args[i], "-vb" ) )
m_VBdotNET = true;
}
try
{
if( m_Service )
{
if( !Directory.Exists( "Logs" ) )
Directory.CreateDirectory( "Logs" );
Console.SetOut( m_MultiConOut = new MultiTextWriter( new FileLogger( "Logs/Console.log" ) ) );
}
else
{
Console.SetOut( m_MultiConOut = new MultiTextWriter( Console.Out ) );
}
}
catch
{
}
m_Thread = Thread.CurrentThread;
m_Process = Process.GetCurrentProcess();
m_Assembly = Assembly.GetEntryAssembly();
if( m_Thread != null )
m_Thread.Name = "Core Thread";
if( BaseDirectory.Length > 0 )
Directory.SetCurrentDirectory( BaseDirectory );
Timer.TimerThread ttObj = new Timer.TimerThread();
timerThread = new Thread( new ThreadStart( ttObj.TimerMain ) );
timerThread.Name = "Timer Thread";
Version ver = m_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
Console.WriteLine( "RunUO - [www.runuo.com] Version {0}.{1}, Build {2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision );
Console.WriteLine( "Core: Running on .NET Framework Version {0}.{1}.{2}", Environment.Version.Major, Environment.Version.Minor, Environment.Version.Build );
string s = Arguments;
if( s.Length > 0 )
Console.WriteLine( "Core: Running with arguments: {0}", s );
m_ProcessorCount = Environment.ProcessorCount;
if( m_ProcessorCount > 1 )
m_MultiProcessor = true;
if( m_MultiProcessor || Is64Bit )
Console.WriteLine( "Core: Optimizing for {0} {2}processor{1}", m_ProcessorCount, m_ProcessorCount == 1 ? "" : "s", Is64Bit ? "64-bit " : "" );
int platform = (int)Environment.OSVersion.Platform;
if( platform == 4 || platform == 128 ) { // MS 4, MONO 128
m_Unix = true;
Console.WriteLine( "Core: Unix environment detected" );
}
else {
m_ConsoleEventHandler = new ConsoleEventHandler( OnConsoleEvent );
SetConsoleCtrlHandler( m_ConsoleEventHandler, true );
}
if ( GCSettings.IsServerGC )
Console.WriteLine("Core: Server garbage collection mode enabled");
while( !ScriptCompiler.Compile( m_Debug, m_Cache ) )
{
Console.WriteLine( "Scripts: One or more scripts failed to compile or no script files were found." );
if( m_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 = new MessagePump();
timerThread.Start();
for( int i = 0; i < Map.AllMaps.Count; ++i )
Map.AllMaps[i].Tiles.Force();
NetState.Initialize();
EventSink.InvokeServerStarted();
try
{
DateTime now, last = DateTime.UtcNow;
const int sampleInterval = 100;
const float ticksPerSecond = (float)(TimeSpan.TicksPerSecond * sampleInterval);
long sample = 0;
while( m_Signal.WaitOne() )
{
Mobile.ProcessDeltaQueue();
Item.ProcessDeltaQueue();
Timer.Slice();
messagePump.Slice();
NetState.FlushAll();
NetState.ProcessDisposedQueue();
if( Slice != null )
Slice();
if( (++sample % sampleInterval) == 0 )
{
now = DateTime.UtcNow;
m_CyclesPerSecond[m_CycleIndex++ % m_CyclesPerSecond.Length] =
ticksPerSecond / (now.Ticks - last.Ticks);
last = now;
}
}
}
catch( Exception e )
{
CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) );
}
}