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(); }
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 ms = m_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.Now; const int sampleInterval = 100; const float ticksPerSecond = (float)(TimeSpan.TicksPerSecond * sampleInterval); long sample = 0; while( m_Signal.WaitOne() ) { Mobile.ProcessDeltaQueue(); Item.ProcessDeltaQueue(); Timer.Slice(); m_MessagePump.Slice(); NetState.FlushAll(); NetState.ProcessDisposedQueue(); if( Slice != null ) Slice(); if( (++sample % sampleInterval) == 0 ) { now = DateTime.Now; m_CyclesPerSecond[m_CycleIndex++ % m_CyclesPerSecond.Length] = ticksPerSecond / (now.Ticks - last.Ticks); last = now; } } } catch( Exception e ) { CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) ); } }
public static void Main( string[] args ) { m_Assembly = Assembly.GetEntryAssembly(); /* print a banner */ Version ver = m_Assembly.GetName().Version; Console.WriteLine("SunLogin 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 ); for ( int i = 0; i < args.Length; ++i ) { 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; 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 (!config.Exists) config.Save(); m_MessagePump = new MessagePump( new Listener( Listener.Port ) ); timerThread.Start(); NetState.Initialize(); Encryption.Initialize(); ServerList.Initialize(); Server.Accounting.AccountHandler.Initialize(); EventSink.InvokeServerStarted(); try { while ( !m_Closing ) { Thread.Sleep( 1 ); 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(); }
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; else if ( Insensitive.Equals( args[i], "-publish" ) ) m_Publish = 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; string svn = string.Empty; if ( File.Exists( "Data/RunUO_SVN.cfg" ) ) { using ( StreamReader ip = new StreamReader( "Data/RunUO_SVN.cfg" ) ) { svn = ip.ReadLine(); } } // 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.Green ); Console.WriteLine( "RunUO - [www.runuo.com] Version {0}.{1}, {2}{3}", ver.Major, ver.Minor, svn != String.Empty ? "SVN rev. " : String.Empty, svn ); Utility.PopColor(); #if Mono string version = "MONO"; #else string version = Environment.Version.ToString(); #endif Console.WriteLine( "Core: Running on .NET Framework Version {0}", version ); 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"); if ( File.Exists( "Data/Culture.cfg" ) ) { using ( StreamReader ip = new StreamReader( "Data/Culture.cfg" ) ) { string line = ip.ReadLine(); if ( !String.IsNullOrEmpty( line ) ) { m_Thread.CurrentCulture = new CultureInfo( line ); Console.WriteLine( "Core: Culture modified to {0}", m_Thread.CurrentCulture.NativeName ); } } } while( !ScriptCompiler.Compile( m_Debug, m_Cache, m_Publish ) ) { Console.WriteLine( "Scripts: One or more scripts failed to compile or no script files were found." ); if( m_Publish || 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" ); Console.Write( "Core: Initializing localization strings..." ); ClilocHandler.AddCliloc( "ENU" ); //English - No Argument sets the default ClilocHandler.AddCliloc( "CHS" ); //Chinese ClilocHandler.AddCliloc( "CHT" ); //Chinese ClilocHandler.AddCliloc( "DEU" ); //German ClilocHandler.AddCliloc( "ESP" ); //Spanish ClilocHandler.AddCliloc( "FRA" ); //French ClilocHandler.AddCliloc( "JPN" ); //Japan ClilocHandler.AddCliloc( "KOR" ); //Korean Console.WriteLine( "done ({0} languages)", StringList.StringLists.Count ); 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); const float ticksPerSecond = (float)(1000 * 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 ) ); } }
public static void Main( string[] args ) { 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; } try { if ( m_Service ) { if ( !Directory.Exists( "Logs" ) ) Directory.CreateDirectory( "Logs" ); Console.SetOut( m_MultiConOut = new MultiTextWriter( Console.Out, new FileLogger( "Logs/Console.log" ) ) ); } else { Console.SetOut( m_MultiConOut = new MultiTextWriter( Console.Out ) ); } } catch { } #if !MONO m_ConsoleEventHandler = new ConsoleEventHandler( OnConsoleEvent ); SetConsoleCtrlHandler( m_ConsoleEventHandler, true ); #endif 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}.{3}, Build {2}", ver.Major, ver.Minor, ver.Revision, ver.Build ); while ( !ScriptCompiler.Compile( debug ) ) { Console.WriteLine( "Scripts: One or more scripts failed to compile or no script files were found." ); Console.WriteLine( " - Press return to exit, or R to try again." ); string line = Console.ReadLine(); if ( line == null || line.ToLower() != "r" ) return; } Region.Load(); MessagePump ms = m_MessagePump = new MessagePump( new Listener( Listener.Port ) ); timerThread.Start(); for ( int i = 0; i < Map.AllMaps.Count; ++i ) ((Map)Map.AllMaps[i]).Tiles.Force(); NetState.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(); }
public static void Start(Config.Root _config, bool debug, bool _service, bool _profiling) { config = _config; m_Service = _service; Profiling = _profiling; m_Assembly = Assembly.GetEntryAssembly(); /* prepare SunUO */ AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException ); AppDomain.CurrentDomain.ProcessExit += new EventHandler( CurrentDomain_ProcessExit ); /* redirect Console to file in service mode */ if (m_Service) { string filename = Path.Combine(LogDirectoryInfo.FullName, "console.log"); FileStream stream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Read); StreamWriter writer = new StreamWriter(stream); Console.SetOut(writer); Console.SetError(writer); } 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; m_ItemCount = 0; m_MobileCount = 0; foreach (Library l in ScriptCompiler.Libraries) { int itemCount = 0, mobileCount = 0; l.Verify(ref itemCount, ref mobileCount); log.Info(String.Format("Library {0} verified: {1} items, {2} mobiles", l.Name, itemCount, mobileCount)); m_ItemCount += itemCount; m_MobileCount += mobileCount; } log.Info(String.Format("All libraries verified: {0} items, {1} mobiles)", m_ItemCount, m_MobileCount)); try { ScriptCompiler.Configure(); } catch (TargetInvocationException e) { log.Fatal("Configure exception: {0}", e.InnerException); return; } if (!config.Exists) config.Save(); World.Load(); try { ScriptCompiler.Initialize(); } catch (TargetInvocationException e) { log.Fatal("Initialize exception: {0}", e.InnerException); return; } Region.Load(); m_MessagePump = new MessagePump( new Listener( Listener.Port ) ); timerThread.Start(); NetState.Initialize(); Encryption.Initialize(); EventSink.InvokeServerStarted(); log.Info("SunUO initialized, entering main loop"); try { while ( !m_Closing ) { m_Signal.WaitOne(); m_Now = DateTime.Now; 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(); }
public static void Main( string[] args ) { m_Assembly = Assembly.GetEntryAssembly(); /* print a banner */ Version ver = m_Assembly.GetName().Version; Console.WriteLine("SunLogin 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 ); if (args.Length > 0) { Console.WriteLine("SunLogin does not understand command line arguments"); return; } string baseDirectory = Path.GetDirectoryName(ExePath); string confDirectory = new DirectoryInfo(baseDirectory) .CreateSubdirectory("etc").FullName; config = new Config.Root(baseDirectory, Path.Combine(confDirectory, "sunuo.xml")); Directory.SetCurrentDirectory(config.BaseDirectory); m_Thread = Thread.CurrentThread; 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 (!config.Exists) config.Save(); m_MessagePump = new MessagePump(); foreach (IPEndPoint ipep in Config.Network.Bind) m_MessagePump.AddListener(new Listener(ipep)); timerThread.Start(); NetState.Initialize(); Encryption.Initialize(); ServerList.Initialize(); ServerQueryTimer.Initialize(); Server.Accounting.AccountHandler.Initialize(); EventSink.InvokeServerStarted(); log.Info("SunLogin initialized, entering main loop"); try { while ( !m_Closing ) { m_Signal.WaitOne(); Timer.Slice(); m_MessagePump.Slice(); NetState.FlushAll(); NetState.ProcessDisposedQueue(); } } catch ( Exception e ) { CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) ); } if ( timerThread.IsAlive ) timerThread.Abort(); }
public static void Main( string[] args ) { 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; } 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(); 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("SunUO Version {0}.{1}.{2} http://max.kellermann.name/projects/sunuo/", ver.Major, ver.Minor, ver.Revision); while ( !ScriptCompiler.Compile( debug ) ) { Console.WriteLine( "Scripts: One or more scripts failed to compile or no script files were found." ); Console.WriteLine( " - Press return to exit, or R to try again." ); string line = Console.ReadLine(); if ( line == null || line.ToLower() != "r" ) 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; } config.Save(); World.Load(); try { ScriptCompiler.Initialize(); } catch (TargetInvocationException e) { Console.WriteLine("Initialize exception: {0}", e.InnerException); return; } Region.Load(); MessagePump ms = m_MessagePump = new MessagePump( new Listener( Listener.Port ) ); timerThread.Start(); NetState.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(); }
public static void Main(string[] args) { #if !DEBUG AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); #endif 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(Console.Out, new FileLogger("Logs/Console.log"))); } else { Console.SetOut(m_MultiConOut = new MultiTextWriter(Console.Out)); } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } 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("Angel Island - [www.game-master.net] Version {0}.{1}.{3}, Build {2}", ver.Major, ver.Minor, ver.Revision, ver.Build); #if DEBUG Console.WriteLine("[Debug Build Enabled]"); #endif 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); } while (!ScriptCompiler.Compile(m_Debug)) { if (m_Quiet) //abort and exit if compile scripts failed return; Console.WriteLine("Scripts: One or more scripts failed to compile or no script files were found."); Console.WriteLine(" - Press return to exit, or R to try again."); string line = Console.ReadLine(); if (line == null || line.ToLower() != "r") return; } // adam: I believe the new startup logic is nore robust as it attempts to prevents timers from firing // before the shard is fully up and alive. Region.Load(); SocketPool.Create(); MessagePump ms = m_MessagePump = new MessagePump(); timerThread.Start(); for (int i = 0; i < Map.AllMaps.Count; ++i) ((Map)Map.AllMaps[i]).Tiles.Force(); NetState.Initialize(); EventSink.InvokeServerStarted(); #if !DEBUG try { #endif while (m_Signal.WaitOne()) { Mobile.ProcessDeltaQueue(); Item.ProcessDeltaQueue(); Timer.Slice(); m_MessagePump.Slice(); NetState.FlushAll(); NetState.ProcessDisposedQueue(); if (Slice != null) Slice(); } #if !DEBUG } catch (Exception e) { CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true)); } #endif }