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], "-balancing")) { m_Balancing = 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], "-usehrt")) { _UseHRT = 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 - [https://github.com/runuo/] Version {0}.{1}.{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); UnsafeNativeMethods.SetConsoleCtrlHandler(m_ConsoleEventHandler, true); } if (GCSettings.IsServerGC) { Console.WriteLine("Core: Server garbage collection mode enabled"); } if (_UseHRT) { Console.WriteLine("Core: Requested high resolution timing ({0})", UsingHighResolutionTiming ? "Supported" : "Unsupported"); } Console.WriteLine("RandomImpl: {0} ({1})", RandomImpl.Type.Name, RandomImpl.IsHardwareRNG ? "Hardware" : "Software"); 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; } } Directories.Configure(); ScriptCompiler.Invoke("Configure"); Region.Load(); World.Load(); ScriptCompiler.Invoke("Initialize"); MessagePump messagePump = null; if (!Core.Balancing) { messagePump = m_MessagePump = new MessagePump(); } timerThread.Start(); for (int i = 0; i < Map.AllMaps.Count; ++i) { Map.AllMaps[i].Tiles.Force(); } if (Core.Balancing) { Console.WriteLine("Le serveur fut démarré en mode balancing test. Il est impossible de s'y connecter et les tests vont simplement avoir lieu en background."); } else { NetState.Initialize(); } EventSink.InvokeServerStarted(); try { long now, last = TickCount; const int sampleInterval = 100; const float ticksPerSecond = (float)(1000 * sampleInterval); long sample = 0; while (!m_Closing) { m_Signal.WaitOne(); Mobile.ProcessDeltaQueue(); Item.ProcessDeltaQueue(); Timer.Slice(); if (!Core.Balancing) { messagePump.Slice(); } if (!Core.Balancing) { NetState.FlushAll(); NetState.ProcessDisposedQueue(); } if (Slice != null) { Slice(); } if ((++sample % sampleInterval) == 0) { now = TickCount; m_CyclesPerSecond[m_CycleIndex++ % m_CyclesPerSecond.Length] = ticksPerSecond / (now - last); last = now; } } } catch (Exception e) { CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true)); } }
public static void Save(bool message, bool permitBackgroundWrite) { if (m_Saving) { return; } ++m_Saves; NetState.FlushAll(); NetState.Pause(); World.WaitForWriteCompletion(); //Blocks Save until current disk flush is done. m_Saving = true; m_DiskWriteHandle.Reset(); if (message) { Broadcast(0x35, true, "The world is saving, please wait."); } SaveStrategy strategy = SaveStrategy.Acquire(); Console.WriteLine("Core: Using {0} save strategy", strategy.Name.ToLowerInvariant()); Console.Write("World: Saving..."); Stopwatch watch = Stopwatch.StartNew(); Directories.AppendPath(Directories.saves, "Mobiles"); Directories.AppendPath(Directories.saves, "Items"); Directories.AppendPath(Directories.saves, "Guilds"); Directories.AppendPath(Directories.saves, "Misc"); /*using ( SaveMetrics metrics = new SaveMetrics() ) {*/ strategy.Save(null, permitBackgroundWrite); /*}*/ try { EventSink.InvokeWorldSave(new WorldSaveEventArgs(message)); } catch (Exception e) { throw new Exception("World Save event threw an exception. Save failed!", e); } watch.Stop(); m_Saving = false; if (!permitBackgroundWrite) { World.NotifyDiskWriteComplete(); //Sets the DiskWriteHandle. If we allow background writes, we leave this upto the individual save strategies. } ProcessSafetyQueues(); strategy.ProcessDecay(); Console.WriteLine("Save done in {0:F2} seconds.", watch.Elapsed.TotalSeconds); if (message) { Broadcast(0x35, true, "World save complete. The entire process took {0:F1} seconds.", watch.Elapsed.TotalSeconds); } NetState.Resume(); }