Exemple #1
0
        public static void Main(string[] args)
        {
            int 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 " : "");
            }

            SocketPool.Create();
            PacketskHandler packetsHandler = new PacketskHandler();

            while (m_Signal.WaitOne())
            {
            }
        }
Exemple #2
0
        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(Console.Out, 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);
            }

            while (!ScriptCompiler.Compile(m_Debug, m_Cache))
            {
                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.");

                if (Console.ReadKey(true).Key != ConsoleKey.R)
                {
                    return;
                }
            }

            SocketPool.Create();

            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);

                int 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));
            }
        }
Exemple #3
0
        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
        }
Exemple #4
0
        public static void Main(string[] args)
        {
            // If we set the exceptionhandler also in debug, VS wont throw them and i cant react in Debug-mode
            // They will be printed to the console interface
#if !DEBUG
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
#endif
            AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
#if !DEBUG
            try {
#endif

            // Cleanup before loading any other data
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);

            // Save some infos about our thread and assembly
            mThread   = Thread.CurrentThread;
            mProcess  = Process.GetCurrentProcess();
            mAssembly = Assembly.GetEntryAssembly();
            if (mThread != null)
            {
                // We set a name on our core thread
                mThread.Name = "Core Thread";
            }

            // Initialize our timer manager
            TimerThread ttObj = new TimerThread();
            mTimerThread      = new Thread(new ThreadStart(ttObj.TimerMain));
            mTimerThread.Name = "Timer Thread";

            // Prepare console for a large output
            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;
            }

            // Real fullscreen mode *_*
#if REAL_FULLSCREEN
            IntPtr hConsole = GetStdHandle(-11);
            SetConsoleDisplayMode(hConsole, 0);
#endif

            // Set colors for the logo printer
            LogoPrinter.PrefixColor    = EConsoleColor.Blue;
            LogoPrinter.SufixColor     = EConsoleColor.Blue;
            LogoPrinter.TextColor      = EConsoleColor.Gray;
            LogoPrinter.CopyrightColor = EConsoleColor.Status;
            LogoPrinter.PrintLogo();

            // Output some infos about version and that
            Version ver = mAssembly.GetName().Version;
            ServerConsole.StatusLine("Rovolution Server - Version {0}.{1}.{2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision);

            // Set error and exception handler (dll import)
            mConsoleEventHandler = new ConsoleEventHandler(OnConsoleEvent);
            SetConsoleCtrlHandler(mConsoleEventHandler, true);

            // Read server config
            mAppConf = new ApplicationSettings();
            mAppConf.ReadAll();

            // Mysql init
            Stopwatch watch = Stopwatch.StartNew();
            ServerConsole.Info("Connecting to SQL Server {0}...", mAppConf.Connection["DB Server"]);
            mDatabase = new RovolutionDatabase(Conf.Connection["DB Server"], int.Parse(Conf.Connection["DB Port"]), Conf.Connection["DB User"], Conf.Connection["DB Password"], Conf.Connection["DB Database"]);
            GodLesZ.Library.MySql.EMysqlConnectionError conRes = mDatabase.Prepare();
            if (conRes != GodLesZ.Library.MySql.EMysqlConnectionError.None)
            {
                ServerConsole.WriteLine(EConsoleColor.Error, " failed!");
                throw new Exception("Failed to open Database Connection! Type: " + conRes.ToString() + Environment.NewLine + (mDatabase.LastError != null ? ", Message: " + mDatabase.LastError.Message : ""));
            }
            watch.Stop();
            ServerConsole.WriteLine(EConsoleColor.Status, " done! Needed {0:F2} sec", watch.Elapsed.TotalSeconds);
            watch = null;

            // Load scripts (including events & that)
            ScriptDatabase.Initialize(@"Scripts\ScriptList.xml");

            ScriptCompiler.Compile(AppDomain.CurrentDomain.BaseDirectory + Path.Combine(Settings.Default.MainConfDir, Settings.Default.ScriptAssemblies), true, true);
            // Load assemblies for debug
            // TODO: we should load the assemblies for debugging
            //		 so VS could hijack them and we could debug them at runtime
            //		 also need the *.pdb files for this..

            // Packets handler
            PacketLoader.Initialize();

            // Initialize World events
            ScriptCompiler.Initialize("Rovolution.Server.Scripts");

            // Now we are able load our ressources
            World.Load();

            // Content init done, load Socket pool
            SocketPool.Create();
            mSocketConnector = new SocketConnector(mAppConf.Connection["Server IP"], mAppConf.Connection.GetInt("Server Port"));
            PacketHandlers.Initialize();

            // Start Timer Thread
            mTimerThread.Start();

            // Start timer for checking connections
            NetState.Initialize();


            // Initialize & load finished
            // Clean
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);


            // Trigger ServerStarted event
            Events.InvokeServerStarted();


            DateTime now, last = DateTime.Now;
            const int sampleInterval   = 100;
            const float ticksPerSecond = (float)(TimeSpan.TicksPerSecond * sampleInterval);
            int sample = 0;

            // The server loop
            // - looks for new sockets and process all packets
            while (mSignal.WaitOne())
            {
                // Refresh timer
                Timer.Slice();

                // Kick out old connections
                NetState.FlushAll();
                NetState.ProcessDisposedQueue();
                // Catch new connections
                mSocketConnector.Slice();

                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;
                }
            }
#if !DEBUG
        }

        catch (Exception e) {
            CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true));
        }
#endif
        }
Exemple #5
0
        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));
            }
        }