Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
0
        public static void Start(bool repair)
        {
            if (!ScriptCompiler.Compile(true))
            {
                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.InfoFormat("Library {0} verified: {1} items, {2} mobiles",
                               l.Name, itemCount, mobileCount);
                m_ItemCount   += itemCount;
                m_MobileCount += mobileCount;
            }
            log.InfoFormat("All libraries verified: {0} items, {1} mobiles)",
                           m_ItemCount, m_MobileCount);

            try {
                TileData.Configure();

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

            if (!config.Exists)
            {
                config.Save();
            }

            World.Load();
            if (World.LoadErrors > 0)
            {
                log.ErrorFormat("There were {0} errors during world load.", World.LoadErrors);
                if (repair)
                {
                    log.Error("The world load errors are being ignored for now, and will not reappear once you save this world.");
                }
                else
                {
                    log.Error("Try 'SunUO --repair' to repair this world save, or restore an older non-corrupt save.");
                    return;
                }
            }

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

            Region.Load();

            m_MessagePump = new MessagePump();
            foreach (IPEndPoint ipep in Config.Network.Bind)
            {
                m_MessagePump.AddListener(new Listener(ipep));
            }

            Timer.TimerThread ttObj = new Timer.TimerThread();
            timerThread      = new Thread(new ThreadStart(ttObj.TimerMain));
            timerThread.Name = "Timer Thread";
            timerThread.Start();

            NetState.Initialize();
            Encryption.Initialize();

            EventSink.InvokeServerStarted();

            log.Info("SunUO initialized, entering main loop");

            try
            {
                Run();
            }
            catch (Exception e)
            {
                CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true));
            }

            if (timerThread.IsAlive)
            {
                timerThread.Abort();
            }
        }