internal static void Run() { Properties.Settings.Default.SettingsLoaded += Default_SettingsLoaded; InitializeLogging(); Console.WriteLine("Starting..."); m_Thread = Thread.CurrentThread; m_Process = Process.GetCurrentProcess(); AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; m_Assembly = Assembly.GetEntryAssembly(); if (m_Thread != null) m_Thread.Name = "Core Thread"; Timer.TimerThread ttObj = new Timer.TimerThread(); timerThread = new Thread(new ThreadStart(ttObj.TimerMain)); timerThread.Name = "Timer Thread"; Version ver = m_Assembly.GetName().Version; Timer.DelayCall(TimeSpan.FromSeconds(5.0), () => { Console.WriteLine("RPC Timeout: {0} seconds.", NamecoinLib.RPC.RpcConnector.RpcRequestTimeoutInSeconds); }); Configure(); Initialize(); m_ConsoleEventHandler = new ConsoleEventHandler(OnConsoleEvent); SetConsoleCtrlHandler(m_ConsoleEventHandler, true); timerThread.Start(); try { DateTime now, last = DateTime.UtcNow; const int sampleInterval = 100; const float ticksPerSecond = (float)(TimeSpan.TicksPerSecond * sampleInterval); TimeSpan _oneMS = TimeSpan.FromMilliseconds(1); long sample = 0; while (!m_Closing) { m_Signal.WaitOne(_oneMS); Timer.Slice(); 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)); } finally { UI.Monitor.DisableCacheEntries(); } }
public static readonly bool Is64Bit = (IntPtr.Size == 8); //Returns the size for the current /process/ #endif #region Methods public static void Main(string[] args) { // Stuff needed for arguments string customConfig = ""; m_Assembly = Assembly.GetEntryAssembly(); Version ver = m_Assembly.GetName().Version; if (args.Length > 1) { if (Insensitive.Equals(args[1], "-config")) { try { for (int i = 2; i < args.Length; i++) { customConfig += args[i] + " "; } customConfig = customConfig.Trim(); } catch { } if (customConfig == "") { Console.WriteLine("No config file specified. Proper usage: \"-config <configFilePath>\""); return; } } else if (Insensitive.Equals(args[1], "-version")) { Utility.PrintBanner(); Console.WriteLine(string.Format("Hamaxe - Version {0}.{1}, Build {2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision)); return; } else { Console.WriteLine("Proper usage: Hamaxe.exe [-config <configFilePath>/-version/-help]"); return; } } 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(); 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"; Utility.PrintBanner(); Console.WriteLine(string.Format("Hamaxe - Version {0}.{1}, Build {2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision)); Console.WriteLine(string.Format("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"); } if (GCSettings.IsServerGC) Console.WriteLine("Core: Server garbage collection mode enabled"); while (!ScriptCompiler.Compile(m_Debug, false)) { 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"); //Load ScriptCompiler.Invoke("Initialize"); //Console.WriteLine("Starting up Hamaxe"); //Console.WriteLine("Loading configuration"); Config HamaxeServerConfig; if (customConfig == "") customConfig = Serialization.Config.DEFAULT_CONFIG_FILE; else Console.WriteLine("Core: Config file specified: {0}", customConfig); HamaxeServerConfig = new Config().Load(customConfig); HamaxeServerConfig.Save(); // Create file //Server HamaxeServer = new Server(HamaxeServerConfig); Console.WriteLine("Starting input thread"); Input hamaxeInput = new Input(); hamaxeInput.Start(); Console.WriteLine("Running server"); //HamaxeServer.Run(); MessagePump messagePump = new MessagePump(); timerThread.Start(); NetState.Initialize(); EventSink.InvokeServerStarted(); }
public static void Main( string[] args ) { #if !DEBUG AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException ); #endif AppDomain.CurrentDomain.ProcessExit += new EventHandler( CurrentDomain_ProcessExit ); try { mThread = Thread.CurrentThread; mProcess = Process.GetCurrentProcess(); mAssembly = Assembly.GetEntryAssembly(); if( mThread != null ) mThread.Name = "Core Thread"; Timer.TimerThread ttObj = new Timer.TimerThread(); mTimerThread = new Thread( new ThreadStart( ttObj.TimerMain ) ); mTimerThread.Name = "Timer Thread"; int width = Math.Min( 100, Console.LargestWindowWidth - 2 ); Console.CursorVisible = false; Console.Clear(); Console.WindowLeft = Console.WindowTop = 0; if( Console.WindowWidth < width ) Console.WindowWidth = width; LogoPrinter.PrefixColor = EConsoleColor.Blue; LogoPrinter.SufixColor = EConsoleColor.Blue; LogoPrinter.TextColor = EConsoleColor.Gray; LogoPrinter.PrintLogo(); Version ver = mAssembly.GetName().Version; CConsole.StatusLine( "Shaiya.Extended Server - Version {0}.{1}, Build {2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision ); mConsoleEventHandler = new ConsoleEventHandler( OnConsoleEvent ); SetConsoleCtrlHandler( mConsoleEventHandler, true ); mAppConf = new ApplicationSettings(); mAppConf.ReadAll(); Stopwatch watch = Stopwatch.StartNew(); CConsole.Info( "Connecting to SQL Server {0}...", mAppConf.Network[ "DB Server" ] ); mDatabase = new MySqlWrapper( mAppConf.Network[ "DB Server" ], int.Parse( mAppConf.Network[ "DB Port" ] ), mAppConf.Network[ "DB User" ], mAppConf.Network[ "DB Password" ], mAppConf.Network[ "DB Database" ] ); MysqlError conRes = mDatabase.Prepare(); if( conRes != MysqlError.None ) { CConsole.WriteLine( EConsoleColor.Error, " failed!" ); throw new Exception( "Failed to open Database Connection! Type: " + conRes.ToString() ); } watch.Stop(); CConsole.WriteLine( EConsoleColor.Status, " done! Needed {0:F2} sec", watch.Elapsed.TotalSeconds ); watch = null; ScriptDatabase.Initialize( @"Scripts\ScriptList.xml" ); ScriptCompiler.Compile( AppDomain.CurrentDomain.BaseDirectory + Path.Combine( Settings.Default.MainConfDir, Settings.Default.ScriptAssemblies ), true, true ); World.Load(); // testing CallMethod ScriptCompiler.CallMethod( "Initialize" ); SocketPool.Create(); mSocketConnector = new SocketConnector( mAppConf.Network[ "Server IP" ], mAppConf.Network.GetInt( "Server Port" ) ); PacketHandlers.Initialize(); // start Timer Thread mTimerThread.Start(); NetState.Initialize(); // finished Loading Events.InvokeServerStarted(); DateTime now, last = DateTime.Now; const int sampleInterval = 100; const float ticksPerSecond = (float)( TimeSpan.TicksPerSecond * sampleInterval ); int sample = 0; while( mSignal.WaitOne() ) { Timer.Slice(); mSocketConnector.Slice(); NetState.FlushAll(); NetState.ProcessDisposedQueue(); if( Slice != null ) Slice(); // just for Diagnostics if( ( ++sample % sampleInterval ) == 0 ) { now = DateTime.Now; mCyclesPerSecond[ mCycleIndex++ % mCyclesPerSecond.Length ] = ticksPerSecond / ( now.Ticks - last.Ticks ); last = now; } } } catch( Exception e ) { CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) ); } }