public static void Main( string[] args )
{
m_Assembly = Assembly.GetEntryAssembly();
/* print a banner */
Version ver = m_Assembly.GetName().Version;
Console.WriteLine("SunUO Version {0}.{1}.{2} http://www.sunuo.org/",
ver.Major, ver.Minor, ver.Revision);
Console.WriteLine(" on {0}, runtime {1}",
Environment.OSVersion, Environment.Version);
if ((int)Environment.OSVersion.Platform == 128)
Console.WriteLine("Please make sure you have Mono 1.1.7 or newer! (mono -V)");
Console.WriteLine();
/* prepare SunUO */
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException );
AppDomain.CurrentDomain.ProcessExit += new EventHandler( CurrentDomain_ProcessExit );
bool debug = false;
for ( int i = 0; i < args.Length; ++i )
{
if ( Insensitive.Equals( args[i], "-debug" ) )
debug = true;
else if ( Insensitive.Equals( args[i], "-service" ) )
m_Service = true;
else if ( Insensitive.Equals( args[i], "-profile" ) )
Profiling = true;
else if (args[i] == "--logfile") {
string logfile = args[++i];
StreamWriter writer = new StreamWriter(new FileStream(logfile, FileMode.Append, FileAccess.Write));
writer.AutoFlush = true;
Console.SetOut(writer);
Console.SetError(writer);
}
}
config = new Config(Path.Combine(BaseDirectoryInfo.CreateSubdirectory("etc").FullName, "sunuo.xml"));
try
{
m_MultiConOut = new MultiTextWriter(Console.Out);
Console.SetOut(m_MultiConOut);
if (m_Service) {
string filename = Path.Combine(LogDirectoryInfo.FullName, "console.log");
m_MultiConOut.Add(new FileLogger(filename));
}
}
catch
{
}
m_Thread = Thread.CurrentThread;
m_Process = Process.GetCurrentProcess();
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";
if (!ScriptCompiler.Compile(debug))
return;
Console.Write("Verifying scripts:");
m_ItemCount = 0;
m_MobileCount = 0;
foreach (Library l in ScriptCompiler.Libraries) {
int itemCount = 0, mobileCount = 0;
Console.Write(" {0}[", l.Name);
l.Verify(ref itemCount, ref mobileCount);
Console.Write("{0} items, {1} mobiles]", itemCount, mobileCount);
m_ItemCount += itemCount;
m_MobileCount += mobileCount;
}
Console.WriteLine(" - done ({0} items, {1} mobiles)", m_ItemCount, m_MobileCount);
try {
ScriptCompiler.Configure();
} catch (TargetInvocationException e) {
Console.WriteLine("Configure exception: {0}", e.InnerException);
return;
}
if (!config.Exists)
config.Save();
World.Load();
try {
ScriptCompiler.Initialize();
} catch (TargetInvocationException e) {
Console.WriteLine("Initialize exception: {0}", e.InnerException);
return;
}
Region.Load();
m_MessagePump = new MessagePump( new Listener( Listener.Port ) );
timerThread.Start();
NetState.Initialize();
Encryption.Initialize();
EventSink.InvokeServerStarted();
try
{
while ( !m_Closing )
{
Thread.Sleep( 1 );
Mobile.ProcessDeltaQueue();
Item.ProcessDeltaQueue();
Timer.Slice();
m_MessagePump.Slice();
NetState.FlushAll();
NetState.ProcessDisposedQueue();
if ( Slice != null )
Slice();
}
}
catch ( Exception e )
{
CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) );
}
if ( timerThread.IsAlive )
timerThread.Abort();
}