Example #1
0
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            AppDomain.CurrentDomain.ProcessExit        += CurrentDomain_ProcessExit;

            ParseArguments(args);

            SetupConsoleLogging();

            m_Thread = Thread.CurrentThread;
            Process  = Process.GetCurrentProcess();
            Assembly = Assembly.GetEntryAssembly();

            if (m_Thread != null)
            {
                m_Thread.Name = "Core Thread";
            }

            if (BaseDirectory.Length > 0)
            {
                Directory.SetCurrentDirectory(BaseDirectory);
            }

            var version = Assembly.GetName().Version;

            CoreVersion = version;

            var platform = (int)Environment.OSVersion.Platform;

            if (platform == 4 || platform == 128)
            {
                Unix = true;
            }

            GCSettings.LatencyMode = GCLatencyMode.LowLatency;

            log.Info("X-RunUO Server - Version {0}.{1}.{2}, Build {3}", version.Major, version.Minor, version.Build, version.Revision);
            log.Info("Running on OS {0}", Environment.OSVersion);
            log.Info("Running on {0} {1}", Unix ? "Mono" : ".NET Framework", Environment.Version);

            if (MultiProcessor || Is64Bit)
            {
                log.Info("Optimizing for {0} {2}processor{1}", ProcessorCount, ProcessorCount == 1 ? "" : "s", Is64Bit ? "64-bit " : "");
            }

            log.Info("Using GC {0} {1} mode", GCSettings.IsServerGC ? "Server" : "Workstation", GCSettings.LatencyMode);

            Config = new RootConfig(BaseDirectory, "x-runuo.xml");

            Server.Config.Load();

            #region Dependency management
            LibraryConfig = new LibraryConfig(BaseDirectory, "libraries.xml");

            if (ForceUpdateDeps)
            {
                Directory.Delete(Path.Combine(BaseDirectory, "deps"), recursive: true);
            }
            #endregion

            if (!ScriptCompiler.Compile(Debug))
            {
                log.Fatal("Compilation failed. Press any key to exit.");
                Console.ReadLine();
                return;
            }

            ScriptCompiler.VerifyLibraries();

            // This instance is shared among timer scheduler and timer executor,
            // and accessed from both core & timer threads.
            var timerQueue = new Queue <Timer>();

            // Timer scheduler must be set up before world load, since world load
            // could schedule timers on entity deserialization.
            var timerScheduler = TimerScheduler.Instance = new TimerScheduler(timerQueue);
            m_TimerThread = new TimerThread(timerScheduler);

            var timerExecutor = new TimerExecutor(timerQueue);

            try
            {
                ScriptCompiler.Configure();

                TileData.Configure();
            }
            catch (TargetInvocationException e)
            {
                log.Fatal("Configure exception: {0}", e.InnerException);
                return;
            }

            SaveConfig();

            Region.Load();
            World.Load();

            try
            {
                ScriptCompiler.Initialize();
            }
            catch (TargetInvocationException e)
            {
                log.Fatal("Initialize exception: {0}", e.InnerException);
                return;
            }

            m_TimerThread.Start();

            NetServer netServer = new NetServer(new Listener(Listener.Port));
            netServer.Initialize();

            GameServer.Instance = new GameServer(netServer);
            GameServer.Instance.Initialize();

            EventSink.InvokeServerStarted();

            PacketDispatcher.Initialize();

            Now              = DateTime.UtcNow;
            m_TotalProfile   = new MainProfile(Now);
            m_CurrentProfile = new MainProfile(Now);

            try
            {
                while (!Closing)
                {
                    Now = DateTime.UtcNow;

                    Thread.Sleep(1);

                    ClockProfile(MainProfile.TimerId.Idle);

                    Mobile.ProcessDeltaQueue();

                    ClockProfile(MainProfile.TimerId.MobileDelta);

                    Item.ProcessDeltaQueue();

                    ClockProfile(MainProfile.TimerId.ItemDelta);

                    timerExecutor.Slice();

                    ClockProfile(MainProfile.TimerId.Timers);

                    netServer.Slice();

                    ClockProfile(MainProfile.TimerId.Network);

                    // Done with this iteration.
                    m_TotalProfile.Next();
                    m_CurrentProfile.Next();
                }
            }
            catch (Exception e)
            {
                HandleCrashed(e);
            }

            m_TimerThread.Stop();
        }
Example #2
0
        public static void Run()
        {
            EventSink.Instance = new EventSink();

            if (!ScriptCompiler.Compile(Environment.Debug))
            {
                Console.WriteLine("Fatal: Compilation failed. Press any key to exit.");
                Console.ReadLine();
                return;
            }

            ScriptCompiler.VerifyLibraries();

            // This instance is shared among timer scheduler and timer executor,
            // and accessed from both core & timer threads.
            Queue <Timer> timerQueue = new Queue <Timer>();

            // Timer scheduler must be set up before world load, since world load
            // could schedule timers on entity deserialization.
            var timerScheduler = TimerScheduler.Instance = new TimerScheduler(timerQueue);

            m_TimerThread = new TimerThread(timerScheduler);

            TimerExecutor timerExecutor = new TimerExecutor(timerQueue);

            PacketHandlers.Instance = new PacketHandlers();

            try
            {
                ScriptCompiler.Configure();

                TileData.Configure();
            }
            catch (TargetInvocationException e)
            {
                Console.WriteLine("Fatal: Configure exception: {0}", e.InnerException);
                return;
            }

            Environment.SaveConfig();

            Region.Load();
            World.Instance.Load();

            try
            {
                ScriptCompiler.Initialize();
            }
            catch (TargetInvocationException e)
            {
                Logger.Error("Initialize exception: {0}", e.InnerException);
                return;
            }

            m_TimerThread.Start();

            NetServer netServer = new NetServer(new Listener(Listener.Port));

            netServer.Initialize();

            GameServer.Instance = new GameServer(netServer, PacketHandlers.Instance);
            GameServer.Instance.Initialize();

            EventSink.Instance.InvokeServerStarted();

            PacketDispatcher.Initialize();

            m_Now            = DateTime.UtcNow;
            m_TotalProfile   = new MainProfile(m_Now);
            m_CurrentProfile = new MainProfile(m_Now);

            try
            {
                while (!m_Closing)
                {
                    m_Now = DateTime.UtcNow;

                    Thread.Sleep(1);

                    ClockProfile(MainProfile.TimerId.Idle);

                    Mobile.ProcessDeltaQueue();

                    ClockProfile(MainProfile.TimerId.MobileDelta);

                    Item.ProcessDeltaQueue();

                    ClockProfile(MainProfile.TimerId.ItemDelta);

                    timerExecutor.Slice();

                    ClockProfile(MainProfile.TimerId.Timers);

                    netServer.Slice();

                    ClockProfile(MainProfile.TimerId.Network);

                    // Done with this iteration.
                    m_TotalProfile.Next();
                    m_CurrentProfile.Next();
                }
            }
            catch (Exception e)
            {
                HandleCrashed(e);
            }

            m_TimerThread.Stop();
        }