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

            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Gray;

            Console.Title = "UO Aberration : Core";

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

            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;

            /*
             * ServUO's Original Code
             * if (File.Exists("publish.txt"))
             * {
             *  try
             *  {
             *      FileStream fs = new FileStream("publish.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
             *      StreamReader sr = new StreamReader(fs);
             *
             *      publishNumber = sr.ReadLine();
             *
             *      sr.Close();
             *      fs.Close();
             *  }
             *  catch
             *  { }
             * }*/
            //Concept Expanded based upon ServUO's publish number.

            string       header       = "";
            ConsoleColor desiredColor = ConsoleColor.White;

            if (File.Exists("header.txt"))
            {
                bool chopColor = false;

                try
                {
                    FileStream   file   = new FileStream("header.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
                    StreamReader reader = new StreamReader(file);

                    string determineTextColor = (string)(reader.ReadLine().Trim().ToLower());

                    if (Enum.TryParse <ConsoleColor>(determineTextColor, true, out desiredColor))
                    {
                        chopColor = true;
                    }

                    else
                    {
                        Utility.PushColor(ConsoleColor.White);
                    }

                    if (chopColor)
                    {
                        header = (string)(reader.ReadToEnd());
                    }

                    file.Close();
                    reader.Close();

                    file.Dispose();
                    reader.Dispose();
                }

                catch
                {
                    Utility.PushColor(ConsoleColor.Red);
                    Console.Write("Error: ");
                    Utility.PushColor(ConsoleColor.White);
                    Console.WriteLine("Your are either missing header.txt or it is misconfigured.");
                }
            }

            else
            {
                Utility.PushColor(ConsoleColor.Red);
                Console.Write("Error: ");
                Utility.PushColor(ConsoleColor.White);
                Console.WriteLine("header.txt could not be located.");
            }

            Utility.PushColor(desiredColor);
            Console.WriteLine(header);
            Utility.PushColor(ConsoleColor.White);
            Console.WriteLine();
            Console.WriteLine("Core ({3}): Running on .NET Framework Version {0}.{1}.{2}", Environment.Version.Major, Environment.Version.Minor, Environment.Version.Build, Environment.Is64BitProcess ? "x64" : "x86");

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

            if (GCSettings.IsServerGC)
            {
                Console.WriteLine("Core: Server garbage collection mode enabled");
            }

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

            ScriptCompiler.Invoke("Configure");

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

            ScriptCompiler.Invoke("Initialize");

            MessagePump messagePump = 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.UtcNow;

                const int   sampleInterval = 100;
                const float ticksPerSecond = (float)(TimeSpan.TicksPerSecond * sampleInterval);

                long sample = 0;

                while (m_Signal.WaitOne())
                {
                    Mobile.ProcessDeltaQueue();
                    Item.ProcessDeltaQueue();

                    Timer.Slice();
                    messagePump.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();

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

			if ( GCSettings.IsServerGC )
				Console.WriteLine("Core: Server garbage collection mode enabled");

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

			ScriptCompiler.Invoke( "Configure" );
			
			Region.Load();
			World.Load();

			ScriptCompiler.Invoke( "Initialize" );

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

				long 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)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            AppDomain.CurrentDomain.ProcessExit        += CurrentDomain_ProcessExit;

            foreach (string a in args)
            {
                if (Insensitive.Equals(a, "-debug"))
                {
                    Debug = true;
                }
                else if (Insensitive.Equals(a, "-service"))
                {
                    Service = true;
                }
                else if (Insensitive.Equals(a, "-profile"))
                {
                    Profiling = true;
                }
                else if (Insensitive.Equals(a, "-nocache"))
                {
                    _Cache = false;
                }
                else if (Insensitive.Equals(a, "-haltonwarning"))
                {
                    HaltOnWarning = true;
                }
                else if (Insensitive.Equals(a, "-vb"))
                {
                    VBdotNet = true;
                }
                else if (Insensitive.Equals(a, "-usehrt"))
                {
                    _UseHRT = true;
                }
            }

            try
            {
                if (Service)
                {
                    if (!Directory.Exists("Logs"))
                    {
                        Directory.CreateDirectory("Logs");
                    }

                    Console.SetOut(MultiConsoleOut = new MultiTextWriter(new FileLogger("Logs/Console.log")));
                }
                else
                {
                    Console.SetOut(MultiConsoleOut = new MultiTextWriter(Console.Out));
                }
            }
            catch
            { }

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

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

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

            Timer.TimerThread ttObj = new Timer.TimerThread();

            _TimerThread = new Thread(ttObj.TimerMain)
            {
                Name = "Timer Thread"
            };

            Version ver = 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
            Utility.PushColor(ConsoleColor.DarkGreen);
            Console.WriteLine(new String('-', Console.BufferWidth));
            Utility.PopColor();
            Utility.PushColor(ConsoleColor.Cyan);
            Console.WriteLine(
                "ServUO - [http://www.servuo.com] Version {0}.{1}, Build {2}.{3}",
                ver.Major,
                ver.Minor,
                ver.Build,
                ver.Revision);
            Utility.PopColor();

            string s = Arguments;

            if (s.Length > 0)
            {
                Utility.PushColor(ConsoleColor.Yellow);
                Console.WriteLine("Core: Running with arguments: {0}", s);
                Utility.PopColor();
            }

            ProcessorCount = Environment.ProcessorCount;

            if (ProcessorCount > 1)
            {
                MultiProcessor = true;
            }

            if (MultiProcessor || Is64Bit)
            {
                Utility.PushColor(ConsoleColor.Green);
                Console.WriteLine(
                    "Core: Optimizing for {0} {2}processor{1}",
                    ProcessorCount,
                    ProcessorCount == 1 ? "" : "s",
                    Is64Bit ? "64-bit " : "");
                Utility.PopColor();
            }

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

            if (platform == 4 || platform == 128)
            {
                // MS 4, MONO 128
                Unix = true;
                Utility.PushColor(ConsoleColor.Yellow);
                Console.WriteLine("Core: Unix environment detected");
                Utility.PopColor();
            }
            else
            {
                m_ConsoleEventHandler = OnConsoleEvent;
                UnsafeNativeMethods.SetConsoleCtrlHandler(m_ConsoleEventHandler, true);
            }

            if (GCSettings.IsServerGC)
            {
                Utility.PushColor(ConsoleColor.DarkYellow);
                Console.WriteLine("Core: Server garbage collection mode enabled");
                Utility.PopColor();
            }

            if (_UseHRT)
            {
                Utility.PushColor(ConsoleColor.DarkYellow);
                Console.WriteLine(
                    "Core: Requested high resolution timing ({0})",
                    UsingHighResolutionTiming ? "Supported" : "Unsupported");
                Utility.PopColor();
            }

            Utility.PushColor(ConsoleColor.DarkYellow);
            Console.WriteLine("RandomImpl: {0} ({1})", RandomImpl.Type.Name, RandomImpl.IsHardwareRNG ? "Hardware" : "Software");
            Utility.PopColor();

            Utility.PushColor(ConsoleColor.DarkYellow);
            Console.WriteLine("Core: Loading config...");
            Config.Load();
            Utility.PopColor();

            while (!ScriptCompiler.Compile(Debug, _Cache))
            {
                Utility.PushColor(ConsoleColor.Red);
                Console.WriteLine("Scripts: One or more scripts failed to compile or no script files were found.");
                Utility.PopColor();

                if (Service)
                {
                    return;
                }

                Console.WriteLine(" - Press return to exit, or R to try again.");

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

            ScriptCompiler.Invoke("Configure");

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

            ScriptCompiler.Invoke("Initialize");

            MessagePump messagePump = MessagePump = new MessagePump();

            _TimerThread.Start();

            foreach (Map m in Map.AllMaps)
            {
                m.Tiles.Force();
            }

            NetState.Initialize();

            EventSink.InvokeServerStarted();

            try
            {
                long now, last = TickCount;

                const int   sampleInterval = 100;
                const float ticksPerSecond = 1000.0f * sampleInterval;

                long sample = 0;

                while (!Closing)
                {
                    _Signal.WaitOne();

                    Mobile.ProcessDeltaQueue();
                    Item.ProcessDeltaQueue();

                    Timer.Slice();
                    messagePump.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();

                    if (Slice != null)
                    {
                        Slice();
                    }

                    if (sample++ % sampleInterval != 0)
                    {
                        continue;
                    }

                    now = TickCount;
                    _CyclesPerSecond[_CycleIndex++ % _CyclesPerSecond.Length] = ticksPerSecond / (now - last);
                    last = now;
                }
            }
            catch (Exception e)
            {
                CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true));
            }
        }
Exemple #4
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;
                }
                else if (Insensitive.Equals(args[i], "-publish"))
                {
                    m_Publish = 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 - [www.runuo.com] Version {0}.{1}, Build {2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision);
#if Framework_3_5
            string version = "3.5";
#elif Mono
            string version = "MONO";
#else
            string version = Environment.Version.ToString();
#endif
            Console.WriteLine("Core: Running on .NET Framework Version {0}", version);

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

            if (GCSettings.IsServerGC)
            {
                Console.WriteLine("Core: Server garbage collection mode enabled");
            }


            if (File.Exists("Data/Culture.cfg"))
            {
                using (StreamReader ip = new StreamReader("Data/Culture.cfg"))
                {
                    string line = ip.ReadLine();
                    if (!String.IsNullOrEmpty(line))
                    {
                        m_Thread.CurrentCulture = new CultureInfo(line);
                        Console.WriteLine("Core: Culture modified to {0}", m_Thread.CurrentCulture.NativeName);
                    }
                }
            }

            while (!ScriptCompiler.Compile(m_Debug, m_Cache, m_Publish))
            {
                Console.WriteLine("Scripts: One or more scripts failed to compile or no script files were found.");

                if (m_Publish || 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");

            Console.Write("Core: Initializing localization strings...");
            ClilocHandler.AddCliloc("ENU");               //English - No Argument sets the default
            ClilocHandler.AddCliloc("CHS");               //Chinese
            ClilocHandler.AddCliloc("CHT");               //Chinese
            ClilocHandler.AddCliloc("DEU");               //German
            ClilocHandler.AddCliloc("ESP");               //Spanish
            ClilocHandler.AddCliloc("FRA");               //French
            ClilocHandler.AddCliloc("JPN");               //Japan
            ClilocHandler.AddCliloc("KOR");               //Korean
            Console.WriteLine("done ({0} languages)", StringList.StringLists.Count);

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

            ScriptCompiler.Invoke("Initialize");

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

                long 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 #5
0
        public static void Main( string[] args )
        {
            m_Assembly = Assembly.GetEntryAssembly();

            /* print a banner */
            Version ver = m_Assembly.GetName().Version;
            Console.WriteLine("SunUO Version {0}.{1}.{2} http://www.sunuo.org/",
                              ver.Major, ver.Minor, ver.Revision);
            Console.WriteLine("  on {0}, runtime {1}",
                              Environment.OSVersion, Environment.Version);

            if ((int)Environment.OSVersion.Platform == 128)
                Console.WriteLine("Please make sure you have Mono 1.1.7 or newer! (mono -V)");

            Console.WriteLine();

            /* prepare SunUO */
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException );
            AppDomain.CurrentDomain.ProcessExit += new EventHandler( CurrentDomain_ProcessExit );

            bool debug = false;

            for ( int i = 0; i < args.Length; ++i )
            {
                if ( Insensitive.Equals( args[i], "-debug" ) )
                    debug = true;
                else if ( Insensitive.Equals( args[i], "-service" ) )
                    m_Service = true;
                else if ( Insensitive.Equals( args[i], "-profile" ) )
                    Profiling = true;
                else if (args[i] == "--logfile") {
                    string logfile = args[++i];
                    StreamWriter writer = new StreamWriter(new FileStream(logfile, FileMode.Append, FileAccess.Write));
                    writer.AutoFlush = true;
                    Console.SetOut(writer);
                    Console.SetError(writer);
                }
            }

            config = new Config(Path.Combine(BaseDirectoryInfo.CreateSubdirectory("etc").FullName, "sunuo.xml"));

            try
            {
                m_MultiConOut = new MultiTextWriter(Console.Out);
                Console.SetOut(m_MultiConOut);

                if (m_Service) {
                    string filename = Path.Combine(LogDirectoryInfo.FullName, "console.log");
                    m_MultiConOut.Add(new FileLogger(filename));
                }
            }
            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";

            if (!ScriptCompiler.Compile(debug))
                return;

            Console.Write("Verifying scripts:");
            m_ItemCount = 0;
            m_MobileCount = 0;
            foreach (Library l in ScriptCompiler.Libraries) {
                int itemCount = 0, mobileCount = 0;
                Console.Write(" {0}[", l.Name);
                l.Verify(ref itemCount, ref mobileCount);
                Console.Write("{0} items, {1} mobiles]", itemCount, mobileCount);
                m_ItemCount += itemCount;
                m_MobileCount += mobileCount;
            }
            Console.WriteLine(" - done ({0} items, {1} mobiles)", m_ItemCount, m_MobileCount);

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

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

            World.Load();

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

            Region.Load();

            m_MessagePump = new MessagePump( new Listener( Listener.Port ) );

            timerThread.Start();

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

            EventSink.InvokeServerStarted();

            try
            {
                while ( !m_Closing )
                {
                    Thread.Sleep( 1 );

                    Mobile.ProcessDeltaQueue();
                    Item.ProcessDeltaQueue();

                    Timer.Slice();
                    m_MessagePump.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();

                    if ( Slice != null )
                        Slice();
                }
            }
            catch ( Exception e )
            {
                CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) );
            }

            if ( timerThread.IsAlive )
                timerThread.Abort();
        }
Exemple #6
0
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            AppDomain.CurrentDomain.ProcessExit        += CurrentDomain_ProcessExit;

            foreach (string a in args)
            {
                if (Insensitive.Equals(a, "-debug"))
                {
                    Debug = true;
                }
                else if (Insensitive.Equals(a, "-service"))
                {
                    Service = true;
                }
                else if (Insensitive.Equals(a, "-profile"))
                {
                    Profiling = true;
                }
                else if (Insensitive.Equals(a, "-nocache"))
                {
                    _Cache = false;
                }
                else if (Insensitive.Equals(a, "-haltonwarning"))
                {
                    HaltOnWarning = true;
                }
                else if (Insensitive.Equals(a, "-vb"))
                {
                    VBdotNet = true;
                }
                else if (Insensitive.Equals(a, "-usehrt"))
                {
                    _UseHRT = true;
                }
                else if (Insensitive.Equals(a, "-noconsole"))
                {
                    NoConsole = true;
                }
                else if (Insensitive.Equals(a, "-h") || Insensitive.Equals(a, "-help"))
                {
                    Console.WriteLine("An Ultima Online server emulator written in C# - Visit https://www.servuo.com for more information.\n\n");
                    Console.WriteLine(System.AppDomain.CurrentDomain.FriendlyName + " [Parameter]\n\n");
                    Console.WriteLine("     -debug              Starting ServUO in Debug Mode. Debug Mode is being used in Core and Scripts to give extended inforamtion during runtime.");
                    Console.WriteLine("     -haltonwarning      ServUO halts if any warning is raised during compilation of scripts.");
                    Console.WriteLine("     -h or -help         Displays this help text.");
                    Console.WriteLine("     -nocache            No known effect.");
                    Console.WriteLine("     -noconsole          No user interaction during startup and runtime.");
                    Console.WriteLine("     -profile            Enables profiling allowing to get performance diagnostic information of packets, timers etc. in AdminGump -> Maintenance. Use with caution. This increases server load.");
                    Console.WriteLine("     -service            This parameter should be set if you're running ServUO as a Windows Service. No user interaction. *Windows only*");
                    Console.WriteLine("     -usehrt             Enables High Resolution Timing if requirements are met. Increasing the resolution of the timer. *Windows only*");
                    Console.WriteLine("     -vb                 Enables compilation of VB.NET Scripts. Without this option VB.NET Scripts are skipped.");

                    System.Environment.Exit(0);
                }
            }

            if (!Environment.UserInteractive || Service)
            {
                NoConsole = true;
            }

            try
            {
                if (Service)
                {
                    if (!Directory.Exists("Logs"))
                    {
                        Directory.CreateDirectory("Logs");
                    }

                    Console.SetOut(MultiConsoleOut = new MultiTextWriter(new FileLogger("Logs/Console.log")));
                }
                else
                {
                    Console.SetOut(MultiConsoleOut = new MultiTextWriter(Console.Out));
                }
            }
            catch
            { }

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

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

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

            Timer.TimerThread ttObj = new Timer.TimerThread();

            _TimerThread = new Thread(ttObj.TimerMain)
            {
                Name = "Timer Thread"
            };

            Version ver = 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
            Utility.PushColor(ConsoleColor.DarkGreen);
            if (!NoConsole)
            {
                Console.WriteLine(new String('-', Console.BufferWidth));
            }
            else
            {
                Console.WriteLine(new String('-', 10));
            }
            Utility.PopColor();
            Utility.PushColor(ConsoleColor.Cyan);
        #if DEBUG
            Console.WriteLine(
                "ServUO - [https://www.servuo.com] Version {0}.{1}, Build {2}.{3} - Debug",
                ver.Major,
                ver.Minor,
                ver.Build,
                ver.Revision);
        #else
            Console.WriteLine(
                "ServUO - [https://www.servuo.com] Version {0}.{1}, Build {2}.{3} - Release",
                ver.Major,
                ver.Minor,
                ver.Build,
                ver.Revision);
        #endif
            Utility.PopColor();

            string s = Arguments;

            if (s.Length > 0)
            {
                Utility.PushColor(ConsoleColor.Yellow);
                Console.WriteLine("Core: Running with arguments: {0}", s);
                Utility.PopColor();
            }

            ProcessorCount = Environment.ProcessorCount;

            if (ProcessorCount > 1)
            {
                MultiProcessor = true;
            }

            if (MultiProcessor || Is64Bit)
            {
                Utility.PushColor(ConsoleColor.Green);
                Console.WriteLine(
                    "Core: Optimizing for {0} {2}processor{1}",
                    ProcessorCount,
                    ProcessorCount == 1 ? "" : "s",
                    Is64Bit ? "64-bit " : "");
                Utility.PopColor();
            }

            string dotnet = null;

            #if NETFX_20
            dotnet = "2.0";
            #endif

            #if NETFX_30
            dotnet = "3.0";
            #endif

            #if NETFX_35
            dotnet = "3.5";
            #endif

            #if NETFX_40
            dotnet = "4.0";
            #endif

            #if NETFX_45
            dotnet = "4.5";
            #endif

            #if NETFX_451
            dotnet = "4.5.1";
            #endif

            #if NETFX_46
            dotnet = "4.6.0";
            #endif

            #if NETFX_461
            dotnet = "4.6.1";
            #endif

            #if NETFX_462
            dotnet = "4.6.2";
            #endif

            #if NETFX_47
            dotnet = "4.7";
            #endif

            #if NETFX_471
            dotnet = "4.7.1";
            #endif

            if (String.IsNullOrEmpty(dotnet))
            {
                dotnet = "MONO/CSC/Unknown";
            }

            Utility.PushColor(ConsoleColor.Green);
            Console.WriteLine("Core: Compiled for .NET {0}", dotnet);
            Utility.PopColor();

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

            if (platform == 4 || platform == 128)
            {
                // MS 4, MONO 128
                Unix = true;
                Utility.PushColor(ConsoleColor.Yellow);
                Console.WriteLine("Core: Unix environment detected");
                Utility.PopColor();
            }
            else
            {
                m_ConsoleEventHandler = OnConsoleEvent;
                UnsafeNativeMethods.SetConsoleCtrlHandler(m_ConsoleEventHandler, true);
            }

            if (GCSettings.IsServerGC)
            {
                Utility.PushColor(ConsoleColor.Green);
                Console.WriteLine("Core: Server garbage collection mode enabled");
                Utility.PopColor();
            }

            if (_UseHRT)
            {
                Utility.PushColor(ConsoleColor.DarkYellow);
                Console.WriteLine(
                    "Core: Requested high resolution timing ({0})",
                    UsingHighResolutionTiming ? "Supported" : "Unsupported");
                Utility.PopColor();
            }

            Utility.PushColor(ConsoleColor.DarkYellow);
            Console.WriteLine("RandomImpl: {0} ({1})", RandomImpl.Type.Name, RandomImpl.IsHardwareRNG ? "Hardware" : "Software");
            Utility.PopColor();

            Utility.PushColor(ConsoleColor.Green);
            Console.WriteLine("Core: Loading config...");
            Config.Load();
            Utility.PopColor();

            while (!ScriptCompiler.Compile(Debug, _Cache))
            {
                Utility.PushColor(ConsoleColor.Red);
                Console.WriteLine("Scripts: One or more scripts failed to compile or no script files were found.");
                Utility.PopColor();

                if (Service)
                {
                    return;
                }

                Console.WriteLine(" - Press return to exit, or R to try again.");

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

            ScriptCompiler.Invoke("Configure");

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

            ScriptCompiler.Invoke("Initialize");

            MessagePump messagePump = MessagePump = new MessagePump();

            _TimerThread.Start();

            foreach (Map m in Map.AllMaps)
            {
                m.Tiles.Force();
            }

            NetState.Initialize();

            EventSink.InvokeServerStarted();

            try
            {
                long now, last = TickCount;

                const int   sampleInterval = 100;
                const float ticksPerSecond = 1000.0f * sampleInterval;

                long sample = 0;

                while (!Closing)
                {
                    _Signal.WaitOne();

                    Mobile.ProcessDeltaQueue();
                    Item.ProcessDeltaQueue();

                    Timer.Slice();
                    messagePump.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();

                    if (Slice != null)
                    {
                        Slice();
                    }

                    if (sample++ % sampleInterval != 0)
                    {
                        continue;
                    }

                    now = TickCount;
                    _CyclesPerSecond[_CycleIndex++ % _CyclesPerSecond.Length] = ticksPerSecond / (now - last);
                    last = now;
                }
            }
            catch (Exception e)
            {
                CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true));
            }
        }
Exemple #7
0
        public static void Main( string[] args )
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;

            foreach (string a in args)
            {
                if ( Insensitive.Equals( a, "-debug" ) )
                    m_Debug = true;
                else if ( Insensitive.Equals( a, "-service" ) )
                    m_Service = true;
                else if ( Insensitive.Equals( a, "-profile" ) )
                    Profiling = true;
                else if ( Insensitive.Equals( a, "-nocache" ) )
                    m_Cache = false;
                else if ( Insensitive.Equals( a, "-haltonwarning" ) )
                    m_HaltOnWarning = true;
                else if ( Insensitive.Equals( a, "-vb" ) )
                    m_VBdotNET = true;
                else if ( Insensitive.Equals( a, "-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(ttObj.TimerMain)
            {
                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/] Versão {0}.{1}.{2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision);
            Console.WriteLine("Core: Rodando em .NET Framework Versão {0}.{1}.{2}", Environment.Version.Major, Environment.Version.Minor, Environment.Version.Build);

            string s = Arguments;

            if( s.Length > 0 )
                Console.WriteLine( "Core: Rodando com argumentos: {0}", s );

            m_ProcessorCount = Environment.ProcessorCount;

            if( m_ProcessorCount > 1 )
                m_MultiProcessor = true;

            if( m_MultiProcessor || Is64Bit )
                Console.WriteLine( "Core: Otimizando para {0} processador{1} {2}", m_ProcessorCount, m_ProcessorCount == 1 ? "" : "es", Is64Bit ? "64-bit" : "" );

            int platform = (int)Environment.OSVersion.Platform;
            if( platform == 4 || platform == 128 ) { // MS 4, MONO 128
                m_Unix = true;
                Console.WriteLine( "Core: Ambiente Unix detectado" );
            }
            else {
                m_ConsoleEventHandler = OnConsoleEvent;
                UnsafeNativeMethods.SetConsoleCtrlHandler( m_ConsoleEventHandler, true );
            }

            if ( GCSettings.IsServerGC )
                Console.WriteLine("Core: Coleta de lixo habilitada no servidor");

            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: Um ou mais scripts nao puderam ser compilados ou nenhum script foi encontrado." );

                if( m_Service )
                    return;

                Console.WriteLine( " - Pressione ENTER para sair, ou R para tentar novamente." );

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

            ScriptCompiler.Invoke( "Configure" );

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

            ScriptCompiler.Invoke( "Initialize" );

            MessagePump messagePump = m_MessagePump = new MessagePump();

            timerThread.Start();

            foreach (Map m in Map.AllMaps)
                m.Tiles.Force();

            NetState.Initialize();

            EventSink.InvokeServerStarted();

            try
            {
                long now, last = TickCount;

                const int sampleInterval = 100;
                const float ticksPerSecond = 1000.0f * sampleInterval;

                long sample = 0;

                while( !m_Closing )
                {
                    m_Signal.WaitOne();

                    Mobile.ProcessDeltaQueue();
                    Item.ProcessDeltaQueue();

                    Timer.Slice();
                    messagePump.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();

                    if( Slice != null )
                        Slice();

                    if (sample++ % sampleInterval != 0)
                    {
                        continue;
                    }

                    now = TickCount;
                    m_CyclesPerSecond[m_CycleIndex++ % m_CyclesPerSecond.Length] = ticksPerSecond / (now - last);
                    last = now;
                }
            }
            catch( Exception e )
            {
                CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) );
            }
        }
Exemple #8
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();
        }
Exemple #9
0
        public static void Main( string[] args )
        {
            m_Assembly = Assembly.GetEntryAssembly();

            /* print a banner */
            Version ver = m_Assembly.GetName().Version;
            Console.WriteLine("SunLogin Version {0}.{1}.{2} http://www.sunuo.org/",
                              ver.Major, ver.Minor, ver.Revision);
            Console.WriteLine("  on {0}, runtime {1}",
                              Environment.OSVersion, Environment.Version);

            if ((int)Environment.OSVersion.Platform == 128)
                Console.WriteLine("Please make sure you have Mono 1.1.7 or newer! (mono -V)");

            Console.WriteLine();

            /* prepare SunUO */
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException );
            AppDomain.CurrentDomain.ProcessExit += new EventHandler( CurrentDomain_ProcessExit );

            if (args.Length > 0) {
                Console.WriteLine("SunLogin does not understand command line arguments");
                return;
            }

            string baseDirectory = Path.GetDirectoryName(ExePath);
            string confDirectory = new DirectoryInfo(baseDirectory)
                .CreateSubdirectory("etc").FullName;

            config = new Config.Root(baseDirectory,
                                     Path.Combine(confDirectory, "sunuo.xml"));

            Directory.SetCurrentDirectory(config.BaseDirectory);

            m_Thread = Thread.CurrentThread;

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

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

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

            timerThread.Start();

            NetState.Initialize();
            Encryption.Initialize();
            ServerList.Initialize();
            ServerQueryTimer.Initialize();
            Server.Accounting.AccountHandler.Initialize();

            EventSink.InvokeServerStarted();

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

            try
            {
                while ( !m_Closing )
                {
                    m_Signal.WaitOne();

                    Timer.Slice();
                    m_MessagePump.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();
                }
            }
            catch ( Exception e )
            {
                CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) );
            }

            if ( timerThread.IsAlive )
                timerThread.Abort();
        }
Exemple #10
0
        public static void Main( string[] args )
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException );
            AppDomain.CurrentDomain.ProcessExit += new EventHandler( CurrentDomain_ProcessExit );

            bool debug = false;

            for ( int i = 0; i < args.Length; ++i )
            {
                if ( Insensitive.Equals( args[i], "-debug" ) )
                    debug = true;
                else if ( Insensitive.Equals( args[i], "-service" ) )
                    m_Service = true;
                else if ( Insensitive.Equals( args[i], "-profile" ) )
                    Profiling = true;
            }

            config = new Config(Path.Combine(BaseDirectoryInfo.CreateSubdirectory("etc").FullName, "sunuo.xml"));

            try
            {
                m_MultiConOut = new MultiTextWriter(Console.Out);
                Console.SetOut(m_MultiConOut);

                if (m_Service) {
                    string filename = Path.Combine(LogDirectoryInfo.FullName, "console.log");
                    m_MultiConOut.Add(new FileLogger(filename));
                }
            }
            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("SunUO Version {0}.{1}.{2} http://max.kellermann.name/projects/sunuo/",
                              ver.Major, ver.Minor, ver.Revision);

            while ( !ScriptCompiler.Compile( debug ) )
            {
                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;
            }

            Console.Write("Verifying scripts:");
            m_ItemCount = 0;
            m_MobileCount = 0;
            foreach (Library l in ScriptCompiler.Libraries) {
                int itemCount = 0, mobileCount = 0;
                Console.Write(" {0}[", l.Name);
                l.Verify(ref itemCount, ref mobileCount);
                Console.Write("{0} items, {1} mobiles]", itemCount, mobileCount);
                m_ItemCount += itemCount;
                m_MobileCount += mobileCount;
            }
            Console.WriteLine(" - done ({0} items, {1} mobiles)", m_ItemCount, m_MobileCount);

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

            config.Save();

            World.Load();

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

            Region.Load();

            MessagePump ms = m_MessagePump = new MessagePump( new Listener( Listener.Port ) );

            timerThread.Start();

            NetState.Initialize();

            EventSink.InvokeServerStarted();

            try
            {
                while ( !m_Closing )
                {
                    Thread.Sleep( 1 );

                    Mobile.ProcessDeltaQueue();
                    Item.ProcessDeltaQueue();

                    Timer.Slice();
                    m_MessagePump.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();

                    if ( Slice != null )
                        Slice();
                }
            }
            catch ( Exception e )
            {
                CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) );
            }

            if ( timerThread.IsAlive )
                timerThread.Abort();
        }
Exemple #11
0
        public static void Main(string[] args)
        {
            m_Assembly = Assembly.GetEntryAssembly();

            /* print a banner */
            Version ver = m_Assembly.GetName().Version;

            Console.WriteLine("SunLogin Version {0}.{1}.{2} http://www.sunuo.org/",
                              ver.Major, ver.Minor, ver.Revision);
            Console.WriteLine("  on {0}, runtime {1}",
                              Environment.OSVersion, Environment.Version);

            if ((int)Environment.OSVersion.Platform == 128)
            {
                Console.WriteLine("Please make sure you have Mono 1.1.7 or newer! (mono -V)");
            }

            Console.WriteLine();

            /* prepare SunUO */
            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], "-service"))
                {
                    m_Service = true;
                }
                else if (Insensitive.Equals(args[i], "-profile"))
                {
                    Profiling = true;
                }
                else if (args[i] == "--logfile")
                {
                    string       logfile = args[++i];
                    StreamWriter writer  = new StreamWriter(new FileStream(logfile, FileMode.Append, FileAccess.Write));
                    writer.AutoFlush = true;
                    Console.SetOut(writer);
                    Console.SetError(writer);
                }
            }

            config = new Config(Path.Combine(BaseDirectoryInfo.CreateSubdirectory("etc").FullName, "sunuo.xml"));

            try
            {
                m_MultiConOut = new MultiTextWriter(Console.Out);
                Console.SetOut(m_MultiConOut);

                if (m_Service)
                {
                    string filename = Path.Combine(LogDirectoryInfo.FullName, "console.log");
                    m_MultiConOut.Add(new FileLogger(filename));
                }
            }
            catch
            {
            }

            m_Thread = Thread.CurrentThread;

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

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

            m_MessagePump = new MessagePump(new Listener(Listener.Port));

            timerThread.Start();

            NetState.Initialize();
            Encryption.Initialize();
            ServerList.Initialize();
            ServerQueryTimer.Initialize();
            Server.Accounting.AccountHandler.Initialize();

            EventSink.InvokeServerStarted();

            try
            {
                while (!m_Closing)
                {
                    Thread.Sleep(1);

                    Timer.Slice();
                    m_MessagePump.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();

                    if (Slice != null)
                    {
                        Slice();
                    }
                }
            }
            catch (Exception e)
            {
                CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true));
            }

            if (timerThread.IsAlive)
            {
                timerThread.Abort();
            }
        }
Exemple #12
0
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            AppDomain.CurrentDomain.ProcessExit        += new EventHandler(CurrentDomain_ProcessExit);

            bool debug = false;

            for (int i = 0; i < args.Length; ++i)
            {
                if (Insensitive.Equals(args[i], "-debug"))
                {
                    debug = true;
                }
                else if (Insensitive.Equals(args[i], "-service"))
                {
                    m_Service = true;
                }
                else if (Insensitive.Equals(args[i], "-profile"))
                {
                    Profiling = 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
            {
            }

#if !MONO
            m_ConsoleEventHandler = new ConsoleEventHandler(OnConsoleEvent);
            SetConsoleCtrlHandler(m_ConsoleEventHandler, true);
#endif

            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}.{3}, Build {2}", ver.Major, ver.Minor, ver.Revision, ver.Build);

            while (!ScriptCompiler.Compile(debug))
            {
                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;
                }
            }

            Region.Load();

            MessagePump ms = m_MessagePump = new MessagePump(new Listener(Listener.Port));

            timerThread.Start();

            for (int i = 0; i < Map.AllMaps.Count; ++i)
            {
                ((Map)Map.AllMaps[i]).Tiles.Force();
            }

            NetState.Initialize();

            EventSink.InvokeServerStarted();

            try
            {
                while (!m_Closing)
                {
                    Thread.Sleep(1);

                    Mobile.ProcessDeltaQueue();
                    Item.ProcessDeltaQueue();

                    Timer.Slice();
                    m_MessagePump.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();

                    if (Slice != null)
                    {
                        Slice();
                    }
                }
            }
            catch (Exception e)
            {
                CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true));
            }

            if (timerThread.IsAlive)
            {
                timerThread.Abort();
            }
        }
Exemple #13
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();
            }
        }
Exemple #14
0
        public static void Start(Config.Root _config, bool debug, bool _service, bool _profiling)
        {
            config    = _config;
            m_Service = _service;
            Profiling = _profiling;

            m_Assembly = Assembly.GetEntryAssembly();

            /* prepare SunUO */
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            AppDomain.CurrentDomain.ProcessExit        += new EventHandler(CurrentDomain_ProcessExit);

            /* redirect Console to file in service mode */
            if (m_Service)
            {
                string     filename = Path.Combine(LogDirectoryInfo.FullName, "console.log");
                FileStream stream   = new FileStream(filename, FileMode.Create,
                                                     FileAccess.Write, FileShare.Read);
                StreamWriter writer = new StreamWriter(stream);
                Console.SetOut(writer);
                Console.SetError(writer);
            }

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

            if (!ScriptCompiler.Compile(debug))
            {
                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.Info(String.Format("Library {0} verified: {1} items, {2} mobiles",
                                       l.Name, itemCount, mobileCount));
                m_ItemCount   += itemCount;
                m_MobileCount += mobileCount;
            }
            log.Info(String.Format("All libraries verified: {0} items, {1} mobiles)",
                                   m_ItemCount, m_MobileCount));

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

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

            World.Load();

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

            Region.Load();

            m_MessagePump = new MessagePump(new Listener(Listener.Port));

            timerThread.Start();

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

            EventSink.InvokeServerStarted();

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

            try
            {
                while (!m_Closing)
                {
                    m_Signal.WaitOne();

                    m_Now = DateTime.Now;

                    Mobile.ProcessDeltaQueue();
                    Item.ProcessDeltaQueue();

                    Timer.Slice();
                    m_MessagePump.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();

                    if (Slice != null)
                    {
                        Slice();
                    }
                }
            }
            catch (Exception e)
            {
                CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true));
            }

            if (timerThread.IsAlive)
            {
                timerThread.Abort();
            }
        }
Exemple #15
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;
				else if ( Insensitive.Equals( args[i], "-publish" ) )
					m_Publish = 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;

			string svn = string.Empty;

			if ( File.Exists( "Data/RunUO_SVN.cfg" ) )
			{
				using ( StreamReader ip = new StreamReader( "Data/RunUO_SVN.cfg" ) )
				{
					svn = ip.ReadLine();
				}
			}

			// Added to help future code support on forums, as a 'check' people can ask for to it see if they recompiled core or not
			Utility.PushColor( ConsoleColor.Green );
			Console.WriteLine( "RunUO - [www.runuo.com] Version {0}.{1}, {2}{3}", ver.Major, ver.Minor, svn != String.Empty ? "SVN rev. " : String.Empty, svn );
			Utility.PopColor();
#if Mono
			string version = "MONO";
#else
			string version = Environment.Version.ToString();
#endif
			Console.WriteLine( "Core: Running on .NET Framework Version {0}", version );

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

            if ( GCSettings.IsServerGC )
                Console.WriteLine("Core: Server garbage collection mode enabled");


			if ( File.Exists( "Data/Culture.cfg" ) )
			{
				using ( StreamReader ip = new StreamReader( "Data/Culture.cfg" ) )
				{
					string line = ip.ReadLine();
					if ( !String.IsNullOrEmpty( line ) )
					{
						m_Thread.CurrentCulture = new CultureInfo( line );
						Console.WriteLine( "Core: Culture modified to {0}", m_Thread.CurrentCulture.NativeName );
					}
				}
			}

			while( !ScriptCompiler.Compile( m_Debug, m_Cache, m_Publish ) )
			{
				Console.WriteLine( "Scripts: One or more scripts failed to compile or no script files were found." );

				if( m_Publish || 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" );

			Console.Write( "Core: Initializing localization strings..." );
			ClilocHandler.AddCliloc( "ENU" ); //English - No Argument sets the default
			ClilocHandler.AddCliloc( "CHS" ); //Chinese
			ClilocHandler.AddCliloc( "CHT" ); //Chinese
			ClilocHandler.AddCliloc( "DEU" ); //German
			ClilocHandler.AddCliloc( "ESP" ); //Spanish
			ClilocHandler.AddCliloc( "FRA" ); //French
			ClilocHandler.AddCliloc( "JPN" ); //Japan
			ClilocHandler.AddCliloc( "KOR" ); //Korean
			Console.WriteLine( "done ({0} languages)", StringList.StringLists.Count );

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

			ScriptCompiler.Invoke( "Initialize" );

			MessagePump 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.UtcNow;

				const int sampleInterval = 100;
				//const float ticksPerSecond = (float)(TimeSpan.TicksPerSecond * sampleInterval);
                const float ticksPerSecond = (float)(1000 * sampleInterval);

				long sample = 0;

				while( m_Signal.WaitOne() )
				{
					Mobile.ProcessDeltaQueue();
					Item.ProcessDeltaQueue();

					Timer.Slice();
					messagePump.Slice();

					NetState.FlushAll();
					NetState.ProcessDisposedQueue();

					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 ) );
			}
		}
Exemple #16
0
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            AppDomain.CurrentDomain.ProcessExit        += CurrentDomain_ProcessExit;

            foreach (string arg in args)
            {
                if (Insensitive.Equals(arg, "-debug"))
                {
                    m_Debug = true;
                }
                else if (Insensitive.Equals(arg, "-service"))
                {
                    m_Service = true;
                }
                else if (Insensitive.Equals(arg, "-profile"))
                {
                    Profiling = true;
                }
                else if (Insensitive.Equals(arg, "-nocache"))
                {
                    m_Cache = false;
                }
                else if (Insensitive.Equals(arg, "-haltonwarning"))
                {
                    m_HaltOnWarning = true;
                }
                else if (Insensitive.Equals(arg, "-vb"))
                {
                    m_VBdotNET = true;
                }
                else if (Insensitive.Equals(arg, "-usehrt"))
                {
                    m_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);
            }

            var ttObj = new Timer.TimerThread();

            timerThread = new Thread(ttObj.TimerMain)
            {
                Name = "Timer Thread"
            };

            Version ver = m_Assembly.GetName().Version;

            String publishNumber = String.Empty;

            if (File.Exists("publish.txt"))
            {
                try
                {
                    publishNumber = File.ReadAllText("publish.txt", Encoding.UTF8);
                }
                catch
                { }
            }

            // Added to help future code support on forums, as a 'check' people can ask for to it see if they recompiled core or not
            Utility.PushColor(ConsoleColor.DarkGreen);
            Console.WriteLine(@"----------------------------------------------------------------------------");
            Utility.PopColor();
            Utility.PushColor(ConsoleColor.Cyan);
            Console.WriteLine("JustUO - [http://www.playuo.org] Version {0}.{1}", ver.Major, ver.Minor);

            if (!String.IsNullOrWhiteSpace(publishNumber))
            {
                Console.WriteLine("Publish {0}", publishNumber);
            }

            Utility.PopColor();

            Console.WriteLine(
                "Core: .NET Framework Version {0}.{1}.{2}",
                Environment.Version.Major,
                Environment.Version.Minor,
                Environment.Version.Build);

            string s = Arguments;

            if (s.Length > 0)
            {
                Utility.PushColor(ConsoleColor.Yellow);
                Console.WriteLine("Core: Running with arguments: {0}", s);
                Utility.PopColor();
            }

            m_ProcessorCount = Environment.ProcessorCount;

            if (m_ProcessorCount > 1)
            {
                m_MultiProcessor = true;
            }

            if (m_MultiProcessor || Is64Bit)
            {
                Utility.PushColor(ConsoleColor.Green);
                Console.WriteLine(
                    "Core: Optimizing for {0} {2}processor{1}",
                    m_ProcessorCount,
                    m_ProcessorCount == 1 ? "" : "s",
                    Is64Bit ? "64-bit " : "");
                Utility.PopColor();
            }

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

            if (platform == 4 || platform == 128)
            {
                // MS 4, MONO 128
                m_Unix = true;
                Utility.PushColor(ConsoleColor.Yellow);
                Console.WriteLine("Core: Unix environment detected");
                Utility.PopColor();
            }
            else
            {
                m_ConsoleEventHandler = OnConsoleEvent;
                UnsafeNativeMethods.SetConsoleCtrlHandler(m_ConsoleEventHandler, true);
            }

            if (GCSettings.IsServerGC)
            {
                Utility.PushColor(ConsoleColor.DarkYellow);
                Console.WriteLine("Core: Server garbage collection mode enabled");
                Utility.PopColor();
            }

            if (m_UseHRT)
            {
                Console.WriteLine(
                    "Core: Requested high resolution timing ({0})", UsingHighResolutionTiming ? "Supported" : "Unsupported");
            }

            Console.WriteLine("RandomImpl: {0} ({1})", RandomImpl.Type.Name, RandomImpl.IsHardwareRNG ? "Hardware" : "Software");

            _OpenUOSDK = new OpenUOSDK();

            while (!ScriptCompiler.Compile(m_Debug, m_Cache))
            {
                Utility.PushColor(ConsoleColor.Red);
                Console.WriteLine("Scripts: One or more scripts failed to compile or no script files were found.");
                Utility.PopColor();

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

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

            ScriptCompiler.Invoke("Initialize");

            MessagePump messagePump = m_MessagePump = new MessagePump();

            timerThread.Start();

            foreach (Map m in Map.AllMaps)
            {
                m.Tiles.Force();
            }

            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();
                    messagePump.Slice();

                    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));
            }
        }
Exemple #17
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;
                }
            }

            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 {
            }

#if !MONO
            m_ConsoleEventHandler = new ConsoleEventHandler(OnConsoleEvent);
            SetConsoleCtrlHandler(m_ConsoleEventHandler, true);
#endif

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

            int processorCount = Environment.ProcessorCount;

            if (processorCount > 1)
            {
                m_MultiProcessor = true;
            }

            if (m_MultiProcessor || Is64Bit)
            {
                Console.WriteLine("Core: Optimizing for {0} {2}processor{1}", processorCount, processorCount == 1 ? "" : "s", Is64Bit ? "64-bit " : "");
            }

            m_ProcessorCount = processorCount;

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

            MessagePump ms = m_MessagePump = new MessagePump(new Listener(Listener.Port));

            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_Closing)
                {
                    Thread.Sleep(m_MultiProcessor ? 0 : 1);

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

            if (timerThread.IsAlive)
            {
                timerThread.Abort();
            }
        }
Exemple #18
0
        public static void Main(string[] args)
        {
            m_Assembly = Assembly.GetEntryAssembly();

            /* print a banner */
            Version ver = m_Assembly.GetName().Version;

            Console.WriteLine("SunLogin Version {0}.{1}.{2} http://www.sunuo.org/",
                              ver.Major, ver.Minor, ver.Revision);
            Console.WriteLine("  on {0}, runtime {1}",
                              Environment.OSVersion, Environment.Version);

            if ((int)Environment.OSVersion.Platform == 128)
            {
                Console.WriteLine("Please make sure you have Mono 1.1.7 or newer! (mono -V)");
            }

            Console.WriteLine();

            /* prepare SunUO */
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            AppDomain.CurrentDomain.ProcessExit        += new EventHandler(CurrentDomain_ProcessExit);

            if (args.Length > 0)
            {
                Console.WriteLine("SunLogin does not understand command line arguments");
                return;
            }

            string baseDirectory = Path.GetDirectoryName(ExePath);
            string confDirectory = new DirectoryInfo(baseDirectory)
                                   .CreateSubdirectory("etc").FullName;

            config = new Config.Root(baseDirectory,
                                     Path.Combine(confDirectory, "sunuo.xml"));

            Directory.SetCurrentDirectory(config.BaseDirectory);

            m_Thread = Thread.CurrentThread;

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

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

            m_MessagePump = new MessagePump(new Listener(Listener.Port));

            timerThread.Start();

            NetState.Initialize();
            Encryption.Initialize();
            ServerList.Initialize();
            ServerQueryTimer.Initialize();
            Server.Accounting.AccountHandler.Initialize();

            EventSink.InvokeServerStarted();

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

            try
            {
                while (!m_Closing)
                {
                    m_Signal.WaitOne();

                    Timer.Slice();
                    m_MessagePump.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();
                }
            }
            catch (Exception e)
            {
                CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true));
            }

            if (timerThread.IsAlive)
            {
                timerThread.Abort();
            }
        }
Exemple #19
0
        public static void Main(string[] args)
        {
            m_Assembly = Assembly.GetEntryAssembly();

            /* print a banner */
            Version ver = m_Assembly.GetName().Version;

            Console.WriteLine("SunUO Version {0}.{1}.{2} http://max.kellermann.name/projects/sunuo/",
                              ver.Major, ver.Minor, ver.Revision);
            Console.WriteLine("  on {0}, runtime {1}",
                              Environment.OSVersion, Environment.Version);

            if ((int)Environment.OSVersion.Platform == 128)
            {
                Console.WriteLine("Please make sure you have Mono 1.1.3 or newer! (mono -V)");
            }

            Console.WriteLine();

            /* prepare SunUO */
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            AppDomain.CurrentDomain.ProcessExit        += new EventHandler(CurrentDomain_ProcessExit);

            bool debug = false;

            for (int i = 0; i < args.Length; ++i)
            {
                if (Insensitive.Equals(args[i], "-debug"))
                {
                    debug = true;
                }
                else if (Insensitive.Equals(args[i], "-service"))
                {
                    m_Service = true;
                }
                else if (Insensitive.Equals(args[i], "-profile"))
                {
                    Profiling = true;
                }
            }

            config = new Config(Path.Combine(BaseDirectoryInfo.CreateSubdirectory("etc").FullName, "sunuo.xml"));

            try
            {
                m_MultiConOut = new MultiTextWriter(Console.Out);
                Console.SetOut(m_MultiConOut);

                if (m_Service)
                {
                    string filename = Path.Combine(LogDirectoryInfo.FullName, "console.log");
                    m_MultiConOut.Add(new FileLogger(filename));
                }
            }
            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";

            while (!ScriptCompiler.Compile(debug))
            {
                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;
                }
            }

            Console.Write("Verifying scripts:");
            m_ItemCount   = 0;
            m_MobileCount = 0;
            foreach (Library l in ScriptCompiler.Libraries)
            {
                int itemCount = 0, mobileCount = 0;
                Console.Write(" {0}[", l.Name);
                l.Verify(ref itemCount, ref mobileCount);
                Console.Write("{0} items, {1} mobiles]", itemCount, mobileCount);
                m_ItemCount   += itemCount;
                m_MobileCount += mobileCount;
            }
            Console.WriteLine(" - done ({0} items, {1} mobiles)", m_ItemCount, m_MobileCount);

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

            config.Save();

            World.Load();

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

            Region.Load();

            MessagePump ms = m_MessagePump = new MessagePump(new Listener(Listener.Port));

            timerThread.Start();

            NetState.Initialize();

            EventSink.InvokeServerStarted();

            try
            {
                while (!m_Closing)
                {
                    Thread.Sleep(1);

                    Mobile.ProcessDeltaQueue();
                    Item.ProcessDeltaQueue();

                    Timer.Slice();
                    m_MessagePump.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();

                    if (Slice != null)
                    {
                        Slice();
                    }
                }
            }
            catch (Exception e)
            {
                CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true));
            }

            if (timerThread.IsAlive)
            {
                timerThread.Abort();
            }
        }
Exemple #20
0
        public static void Start(Config.Root _config, bool debug, bool _service, bool _profiling)
        {
            config = _config;
            m_Service = _service;
            Profiling = _profiling;

            m_Assembly = Assembly.GetEntryAssembly();

            /* prepare SunUO */
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException );
            AppDomain.CurrentDomain.ProcessExit += new EventHandler( CurrentDomain_ProcessExit );

            /* redirect Console to file in service mode */
            if (m_Service) {
                string filename = Path.Combine(LogDirectoryInfo.FullName, "console.log");
                FileStream stream = new FileStream(filename, FileMode.Create,
                                                   FileAccess.Write, FileShare.Read);
                StreamWriter writer = new StreamWriter(stream);
                Console.SetOut(writer);
                Console.SetError(writer);
            }

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

            if (!ScriptCompiler.Compile(debug))
                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.Info(String.Format("Library {0} verified: {1} items, {2} mobiles",
                                       l.Name, itemCount, mobileCount));
                m_ItemCount += itemCount;
                m_MobileCount += mobileCount;
            }
            log.Info(String.Format("All libraries verified: {0} items, {1} mobiles)",
                                   m_ItemCount, m_MobileCount));

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

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

            World.Load();

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

            Region.Load();

            m_MessagePump = new MessagePump( new Listener( Listener.Port ) );

            timerThread.Start();

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

            EventSink.InvokeServerStarted();

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

            try
            {
                while ( !m_Closing )
                {
                    m_Signal.WaitOne();

                    m_Now = DateTime.Now;

                    Mobile.ProcessDeltaQueue();
                    Item.ProcessDeltaQueue();

                    Timer.Slice();
                    m_MessagePump.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();

                    if ( Slice != null )
                        Slice();
                }
            }
            catch ( Exception e )
            {
                CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) );
            }

            if ( timerThread.IsAlive )
                timerThread.Abort();
        }
Exemple #21
0
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            AppDomain.CurrentDomain.ProcessExit        += CurrentDomain_ProcessExit;

            foreach (string a in args)
            {
                if (Insensitive.Equals(a, "-debug"))
                {
                    Debug = true;
                }
                else if (Insensitive.Equals(a, "-service"))
                {
                    Service = true;
                }
                else if (Insensitive.Equals(a, "-profile"))
                {
                    Profiling = true;
                }
                else if (Insensitive.Equals(a, "-nocache"))
                {
                    _Cache = false;
                }
                else if (Insensitive.Equals(a, "-haltonwarning"))
                {
                    HaltOnWarning = true;
                }
                else if (Insensitive.Equals(a, "-vb"))
                {
                    VBdotNet = true;
                }
                else if (Insensitive.Equals(a, "-usehrt"))
                {
                    _UseHRT = true;
                }
            }

            try
            {
                if (Service)
                {
                    if (!Directory.Exists("Logs"))
                    {
                        Directory.CreateDirectory("Logs");
                    }

                    Console.SetOut(MultiConsoleOut = new MultiTextWriter(new FileLogger("Logs/Console.log")));
                }
                else
                {
                    Console.SetOut(MultiConsoleOut = new MultiTextWriter(Console.Out));
                }
            }
            catch
            { }

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

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

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

            Timer.TimerThread ttObj = new Timer.TimerThread();

            _TimerThread = new Thread(ttObj.TimerMain)
            {
                Name = "Timer Thread"
            };

            Version ver = Assembly.GetName().Version;

            String publishNumber = "";

            if (File.Exists("publish.txt"))
            {
                publishNumber = File.ReadAllText("publish.txt");
            }

            Utility.PushColor(ConsoleColor.Magenta);

            Console.WriteLine("                ___ _                _   ___           _          ");
            Console.WriteLine("               / __| |_  __ _ _ _ __| | | __|_ _  __ _(_)_ _  ___ ");
            Console.WriteLine("               \\__ \\ ' \\/ _` | '_/ _` | | _|| ' \\/ _` | | ' \\/ -_)");
            Console.WriteLine("               |___/_||_\\__,_|_| \\__,_| |___|_||_\\__, |_|_||_\\___|");
            Console.WriteLine("                                                 |___/            ");

            Utility.PushColor(ConsoleColor.Cyan);
            Console.WriteLine("                            _  __ ___      _                      ");
            Console.WriteLine("                           / |/ /| _ ) ___| |_____ __ __          ");
            Console.WriteLine("                           | / _ \\ _ \\/ -_) / _ \\ V  V /       ");
            Console.WriteLine("                           |_\\___/___/\\___|_\\___/\\_/\\_/      ");
            Console.WriteLine();
            //  Console.WriteLine("                                         16Below                   ");



            Utility.PushColor(ConsoleColor.White);
            Console.WriteLine("                        Running Shard Engine Version {0}.{1}.{2}", new object[]
            {
                ver.Major,
                ver.Minor,
                ver.MinorRevision,
                //  ver.Revision
            });

            if (Environment.Version.Build == 30319)
            {
                Console.WriteLine("                           .NET Framework Version 4.6.1");
            }
            else
            {
                Console.WriteLine("                         .NET Framework Version {0}.{1}.{2}", new object[]
                {
                    Environment.Version.Major,
                    Environment.Version.Minor,
                    Environment.Version.Build,
                });
            }
            Console.WriteLine("                            http://www.shardengine.com");
            Utility.PushColor(ConsoleColor.Blue);
            Console.WriteLine(new String('_', Console.BufferWidth));
            Utility.PushColor(ConsoleColor.White);
            int platform = (int)Environment.OSVersion.Platform;

            Utility.PushColor(ConsoleColor.Magenta);
            Console.Write("Shard: ");
            Utility.PushColor(ConsoleColor.White);
            Console.Write("Detecting Operating System");
            Utility.PushColor(ConsoleColor.DarkGray);
            Console.Write(".....................................");
            Utility.PushColor(ConsoleColor.White);
            if (platform == 4 || platform == 128)
            {
                Unix = true;
                Console.WriteLine("[Unix]");
                Utility.PopColor();
            }
            else
            {
                //   _ConsoleEventHandler = new ConsoleEventHandler(OnConsoleEvent);
                //   UnsafeNativeMethods.SetConsoleCtrlHandler(_ConsoleEventHandler, true);
                switch (Environment.OSVersion.Platform)
                {
                case PlatformID.Win32S:
                    Console.WriteLine("[Win3.1]");
                    Utility.PopColor();
                    break;

                case PlatformID.Win32Windows:
                {
                    int minor = Environment.OSVersion.Version.Minor;
                    if (minor != 0)
                    {
                        if (minor != 10)
                        {
                            if (minor == 90)
                            {
                                Console.WriteLine("[WinME]");
                                Utility.PopColor();
                            }
                        }
                        else
                        {
                            Console.WriteLine("[Win98]");
                            Utility.PopColor();
                        }
                    }
                    else
                    {
                        Console.WriteLine("[Win95]");
                        Utility.PopColor();
                    }
                    break;
                }

                case PlatformID.Win32NT:
                    switch (Environment.OSVersion.Version.Major)
                    {
                    case 3:
                        Console.WriteLine("[NT 3.51]");
                        Utility.PopColor();
                        break;

                    case 4:
                        Console.WriteLine("[NT 4.0]");
                        Utility.PopColor();
                        break;

                    case 5:
                        switch (Environment.OSVersion.Version.Minor)
                        {
                        case 0:
                            Console.WriteLine("[Win2000]");
                            Utility.PopColor();
                            break;

                        case 1:
                            Console.WriteLine("[WinXP]");
                            Utility.PopColor();
                            break;

                        case 2:
                            Console.WriteLine("[Win2003]");
                            Utility.PopColor();
                            break;
                        }
                        break;

                    case 6:
                        switch (Environment.OSVersion.Version.Minor)
                        {
                        case 0:
                            Console.WriteLine("[Vista]");
                            Utility.PopColor();
                            break;

                        case 1:
                            Console.WriteLine("[Win7]");
                            Utility.PopColor();
                            break;

                        case 2:
                            Console.WriteLine("[Win8]");
                            Utility.PopColor();
                            break;

                        case 3:
                            Console.WriteLine("[Win8.1]");
                            Utility.PopColor();
                            break;

                        case 4:
                            Console.WriteLine("[Win10]");
                            Utility.PopColor();
                            break;
                        }
                        break;
                    }
                    break;

                case PlatformID.WinCE:
                    Console.WriteLine("[WinCE]");
                    Utility.PopColor();
                    break;

                default:
                    //    _ConsoleEventHandler = new ConsoleEventHandler(OnConsoleEvent);
                    //    UnsafeNativeMethods.SetConsoleCtrlHandler(_ConsoleEventHandler, true);
                    Console.WriteLine("[Unknown]");
                    Utility.PopColor();
                    break;
                }
            }
            Utility.PushColor(ConsoleColor.Magenta);
            Console.Write("Shard: ");
            Utility.PushColor(ConsoleColor.White);
            Console.Write("Processor Configuration");
            Utility.PushColor(ConsoleColor.Cyan);
            Console.Write("(Core Count {0})", Environment.ProcessorCount);
            Utility.PushColor(ConsoleColor.DarkGray);
            Console.Write("..........................");
            Utility.PushColor(ConsoleColor.White);
            if (Is64Bit)
            {
                Console.WriteLine("[64-bit]");
                Utility.PopColor();
            }
            else
            {
                Console.WriteLine("[32-bit]");
                Utility.PopColor();
            }
            string arguments = Arguments;

            Utility.PushColor(ConsoleColor.Magenta);
            Console.Write("Shard: ");
            Utility.PushColor(ConsoleColor.White);
            Console.Write("Operating Mode");
            Utility.PushColor(ConsoleColor.DarkGray);
            Console.Write(".................................................");
            if (arguments.Length > 0)
            {
                if (arguments.Length > 8)
                {
                    Console.SetCursorPosition(63, Console.CursorTop);
                }
                else if (arguments.Length == 8)
                {
                    Console.SetCursorPosition(69, Console.CursorTop);
                }
                Utility.PushColor(ConsoleColor.Yellow);
                Console.WriteLine("[{0}]", new object[]
                {
                    arguments
                });
                Utility.PopColor();
            }
            else
            {
                Utility.PushColor(ConsoleColor.Gray);
                Console.WriteLine("[default]");
                Utility.PopColor();
            }
            Utility.PushColor(ConsoleColor.Magenta);
            Console.Write("Shard: ");
            Utility.PushColor(ConsoleColor.White);
            Console.Write("Garbage Collection Mode");
            Utility.PushColor(ConsoleColor.DarkGray);
            Console.Write("........................................");
            if (GCSettings.IsServerGC)
            {
                Utility.PushColor(ConsoleColor.White);
                Console.WriteLine("[Enabled]");
                Utility.PopColor();
            }
            else
            {
                Utility.PushColor(ConsoleColor.DarkGray);
                Console.SetCursorPosition(69, Console.CursorTop);
                Console.WriteLine("[Disabled]");
                Utility.PopColor();
            }
            //    string text = ".....................................................";
            int num = 70 - (RandomImpl.Type.Name.Length + 18);

            if (num < 0)
            {
                num = 0;
            }
            Utility.PushColor(ConsoleColor.Magenta);
            Console.Write("Shard: ");
            Utility.PushColor(ConsoleColor.White);
            Console.Write("RandomImpl {0}", new object[]
            {
                RandomImpl.Type.Name
            });
            Utility.PushColor(ConsoleColor.DarkGray);
            Console.Write("............................................");
            Utility.PushColor(ConsoleColor.White);
            Console.SetCursorPosition(69, Console.CursorTop);
            Console.WriteLine("[{0}]", new object[]
            {
                RandomImpl.IsHardwareRNG ? "Hardware" : "Software"
            });
            Utility.PopColor();
            if (_UseHRT)
            {
                Utility.PushColor(ConsoleColor.Magenta);
                Console.Write("Shard: ");
                Utility.PushColor(ConsoleColor.White);
                Console.Write("High Resolution Timing requested");
                Utility.PushColor(ConsoleColor.DarkGray);
                Console.Write("...............................");
                if (UsingHighResolutionTiming)
                {
                    Utility.PushColor(ConsoleColor.Green);
                    Console.WriteLine("[Success]");
                    Utility.PopColor();
                }
                else
                {
                    Utility.PushColor(ConsoleColor.Red);
                    Console.WriteLine("[Failure]");
                    Utility.PopColor();
                }
            }
            else
            {
                Utility.PushColor(ConsoleColor.Magenta);
                Console.Write("Shard: ");
                Utility.PushColor(ConsoleColor.White);
                Console.Write("Standard Timing requested");
                Utility.PushColor(ConsoleColor.DarkGray);
                Console.Write("......................................");
                Utility.PushColor(ConsoleColor.Green);
                Console.WriteLine("[Success]");
                Utility.PopColor();
            }
            Utility.PushColor(ConsoleColor.Magenta);
            Console.Write("Shard: ");
            Utility.PushColor(ConsoleColor.White);
            Console.Write("Initializing Shard Engine settings");
            Utility.PushColor(ConsoleColor.DarkGray);
            Console.Write(".............................");
            Configs.Load();
            bEnforceExpansionClient = Configs.Get("16Below.EnforceExpansionClient", false);
            bDemoVersionEnabled     = Configs.Get("16Below.DemoVersionEnabled", false);
            Utility.PopColor();
            Utility.PushColor(ConsoleColor.Magenta);
            Console.Write("Shard: ");
            Utility.PushColor(ConsoleColor.White);
            Console.Write("Compiling Scripts");
            Utility.PushColor(ConsoleColor.DarkGray);
            Console.Write("..............................................");
            Utility.PopColor();
            while (!ScriptCompiler.Compile(Debug, _Cache))
            {
                Utility.PushColor(ConsoleColor.Red);
                Console.WriteLine("Scripts: One or more scripts failed to compile or no script files were found.");
                Utility.PopColor();
                if (Service)
                {
                    return;
                }

                Utility.PushColor(ConsoleColor.Yellow);
                Console.WriteLine("");
                Console.Write("Shard: Press <return> to exit, or <R> to try again.                   ");
                if (Console.ReadKey(true).Key != ConsoleKey.R)
                {
                    return;
                }
            }

            ScriptCompiler.Invoke("Configure");

            Region.Load();

            World.Load();

            ScriptCompiler.Invoke("Initialize");

            Utility.PushColor(ConsoleColor.Green);
            Console.WriteLine(new String('_', Console.BufferWidth));
            Utility.PopColor();
            Utility.PushColor(ConsoleColor.Magenta);
            Console.Write("Shard: ");
            Utility.PushColor(ConsoleColor.White);
            Console.Write("Initializing Network");
            Utility.PushColor(ConsoleColor.DarkGray);
            Console.Write("...(F5 for a list of available IP's).....");
            Utility.PushColor(ConsoleColor.White);
            if (Configs.Get("16Below.ConsoleBeep", false))
            {
                Console.WriteLine("\a[Listening]");
            }
            else
            {
                Console.WriteLine("[Listening]");
            }
            Utility.PopColor();
            Utility.PushColor(ConsoleColor.Green);
            Console.WriteLine(new String('_', Console.BufferWidth));
            Utility.PopColor();

            MessagePump messagePump = MessagePump = new MessagePump();

            _TimerThread.Start();

            foreach (Map m in Map.AllMaps)
            {
                m.Tiles.Force();
            }

            NetState.Initialize();

            EventSink.InvokeServerStarted();

            try
            {
                long now, last = TickCount;

                const int   sampleInterval = 100;
                const float ticksPerSecond = 1000.0f * sampleInterval;

                long sample = 0;

                while (!Closing)
                {
                    _Signal.WaitOne();

                    Mobile.ProcessDeltaQueue();
                    Item.ProcessDeltaQueue();

                    Timer.Slice();
                    messagePump.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();

                    if (Slice != null)
                    {
                        Slice();
                    }

                    if (sample++ % sampleInterval != 0)
                    {
                        continue;
                    }

                    now = TickCount;
                    _CyclesPerSecond[_CycleIndex++ % _CyclesPerSecond.Length] = ticksPerSecond / (now - last);
                    last = now;
                }
            }
            catch (Exception e)
            {
                CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true));
            }
        }
Exemple #22
0
        public static void Main(string[] args)
        {
            bool isService = !Insensitive.Equals(System.IO.Directory.GetCurrentDirectory().TrimEnd('\\'), System.AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\'));

            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;
                }
            }
            Console.WriteLine("{0}, {1}, {2}", System.IO.Directory.GetCurrentDirectory(), System.AppDomain.CurrentDomain.BaseDirectory, isService);
            System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
#if !MONO
            if (isService)
            {
                ServiceMain();
                return;
            }
#endif

            try
            {
                if (m_Service)
                {
                    if (!Directory.Exists("Logs"))
                    {
                        Directory.CreateDirectory("Logs");
                    }

                    Console.SetOut(m_MultiConOut = new MultiTextWriter(Console.Out, new FileLogger("Logs/" + DateTime.Now.ToString("yyyy-MM-dd.HH-mm-ss") + ".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 (args.Length > 0)
            {
                Console.WriteLine("Core: Running with arguments: {0}", args);
            }

            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_Closing && 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;
                    }
                }
            }
#if !MONO
            catch (ThreadAbortException e)
            {
                e.GetBaseException();                 //Just to remove warning. I can't remember how to supress...
                Thread.ResetAbort();
                HandleClosed();
                //Kill(false);
            }
#endif
            catch (Exception e)
            {
                CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true));
            }
        }
Exemple #23
0
		public static void Main( string[] args )
		{
			AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException );
			AppDomain.CurrentDomain.ProcessExit += new EventHandler( CurrentDomain_ProcessExit );

            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Gray;

			Console.Title = "UO Aberration : Core";

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

			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;

            /*
             * ServUO's Original Code
            if (File.Exists("publish.txt"))
            {
                try
                {
                    FileStream fs = new FileStream("publish.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
                    StreamReader sr = new StreamReader(fs);

                    publishNumber = sr.ReadLine();

                    sr.Close();
                    fs.Close();
                }
                catch
                { }
            }*/
            //Concept Expanded based upon ServUO's publish number.

            string header = "";
            ConsoleColor desiredColor = ConsoleColor.White;

            if (File.Exists("header.txt"))
            {
                bool chopColor = false;

                try
                {
                    FileStream file = new FileStream("header.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
                    StreamReader reader = new StreamReader(file);

                    string determineTextColor = (string)(reader.ReadLine().Trim().ToLower());

                    if (Enum.TryParse<ConsoleColor>(determineTextColor, true, out desiredColor))
                        chopColor = true;

                    else Utility.PushColor(ConsoleColor.White);

                    if (chopColor)
                    {
                        header = (string)(reader.ReadToEnd());
                    }

                    file.Close();
                    reader.Close();

                    file.Dispose();
                    reader.Dispose();
                }

                catch
                {
                    Utility.PushColor(ConsoleColor.Red);
                    Console.Write("Error: ");
                    Utility.PushColor(ConsoleColor.White);
                    Console.WriteLine("Your are either missing header.txt or it is misconfigured.");
                }
            }

            else 
            {
                Utility.PushColor(ConsoleColor.Red);
                Console.Write("Error: ");
                Utility.PushColor(ConsoleColor.White);
                Console.WriteLine("header.txt could not be located.");
            }

            Utility.PushColor( desiredColor );
            Console.WriteLine( header );
            Utility.PushColor(ConsoleColor.White);
            Console.WriteLine();
			Console.WriteLine( "Core ({3}): Running on .NET Framework Version {0}.{1}.{2}", Environment.Version.Major, Environment.Version.Minor, Environment.Version.Build, Environment.Is64BitProcess ? "x64" : "x86" );

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

			if( GCSettings.IsServerGC )
				Console.WriteLine( "Core: Server garbage collection mode enabled" );

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

			ScriptCompiler.Invoke( "Configure" );

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

			ScriptCompiler.Invoke( "Initialize" );

			MessagePump messagePump = 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.UtcNow;

				const int sampleInterval = 100;
				const float ticksPerSecond = (float)(TimeSpan.TicksPerSecond * sampleInterval);

				long sample = 0;

				while( m_Signal.WaitOne() )
				{
					Mobile.ProcessDeltaQueue();
					Item.ProcessDeltaQueue();

					Timer.Slice();
					messagePump.Slice();

					NetState.FlushAll();
					NetState.ProcessDisposedQueue();

					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 ) );
			}
		}
Exemple #24
0
        public static void Main( string[] args )
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException );
            AppDomain.CurrentDomain.ProcessExit += new EventHandler( CurrentDomain_ProcessExit );

            bool debug = false;

            for ( int i = 0; i < args.Length; ++i )
            {
                if ( Insensitive.Equals( args[i], "-debug" ) )
                    debug = true;
                else if ( Insensitive.Equals( args[i], "-service" ) )
                    m_Service = true;
                else if ( Insensitive.Equals( args[i], "-profile" ) )
                    Profiling = 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
            {
            }

            #if !MONO
            m_ConsoleEventHandler = new ConsoleEventHandler( OnConsoleEvent );
            SetConsoleCtrlHandler( m_ConsoleEventHandler, true );
            #endif

            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}.{3}, Build {2}", ver.Major, ver.Minor, ver.Revision, ver.Build );

            while ( !ScriptCompiler.Compile( debug ) )
            {
                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;
            }

            Region.Load();

            MessagePump ms = m_MessagePump = new MessagePump( new Listener( Listener.Port ) );

            timerThread.Start();

            for ( int i = 0; i < Map.AllMaps.Count; ++i )
                ((Map)Map.AllMaps[i]).Tiles.Force();

            NetState.Initialize();

            EventSink.InvokeServerStarted();

            try
            {
                while ( !m_Closing )
                {
                    Thread.Sleep( 1 );

                    Mobile.ProcessDeltaQueue();
                    Item.ProcessDeltaQueue();

                    Timer.Slice();
                    m_MessagePump.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();

                    if ( Slice != null )
                        Slice();
                }
            }
            catch ( Exception e )
            {
                CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) );
            }

            if ( timerThread.IsAlive )
                timerThread.Abort();
        }
Exemple #25
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(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;

            String publishNumber = "";

            if (File.Exists("publish.txt"))
            {
                try
                {
                    FileStream   fs = new FileStream("publish.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
                    StreamReader sr = new StreamReader(fs);

                    publishNumber = sr.ReadLine();

                    sr.Close();
                    fs.Close();
                }
                catch { }
            }

            // Added to help future code support on forums, as a 'check' people can ask for to it see if they recompiled core or not
            Utility.PushColor(ConsoleColor.DarkGreen);
            Console.WriteLine(@"----------------------------------------------------------------------------");
            Utility.PopColor();
            Utility.PushColor(ConsoleColor.Cyan);
            Console.WriteLine("ServUO - [http://www.servuo.com] Version {0}.{1}, Build {2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision);
            Console.WriteLine("Publish {0}", publishNumber);
            Utility.PopColor();

            string s = Arguments;

            if (s.Length > 0)
            {
                Utility.PushColor(ConsoleColor.Yellow);
                Console.WriteLine("Core: Running with arguments: {0}", s);
                Utility.PopColor();
            }

            m_ProcessorCount = Environment.ProcessorCount;

            if (m_ProcessorCount > 1)
            {
                m_MultiProcessor = true;
            }

            if (m_MultiProcessor || Is64Bit)
            {
                Utility.PushColor(ConsoleColor.Green);
                Console.WriteLine("Core: Optimizing for {0} {2}processor{1}", m_ProcessorCount, m_ProcessorCount == 1 ? "" : "s", Is64Bit ? "64-bit " : "");
                Utility.PopColor();
            }

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

            if (platform == 4 || platform == 128)
            {             // MS 4, MONO 128
                m_Unix = true;
                Utility.PushColor(ConsoleColor.Yellow);
                Console.WriteLine("Core: Unix environment detected");
                Utility.PopColor();
            }
            else
            {
                m_ConsoleEventHandler = new ConsoleEventHandler(OnConsoleEvent);
                SetConsoleCtrlHandler(m_ConsoleEventHandler, true);
            }

            if (GCSettings.IsServerGC)
            {
                Utility.PushColor(ConsoleColor.DarkYellow);
                Console.WriteLine("Core: Server garbage collection mode enabled");
                Utility.PopColor();
            }

            _openUOSDK = new OpenUOSDK();

            while (!ScriptCompiler.Compile(m_Debug, m_Cache))
            {
                Utility.PushColor(ConsoleColor.Red);
                Console.WriteLine("Scripts: One or more scripts failed to compile or no script files were found.");
                Utility.PopColor();

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

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

            ScriptCompiler.Invoke("Initialize");

            MessagePump 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.UtcNow;

                const int   sampleInterval = 100;
                const float ticksPerSecond = (float)(TimeSpan.TicksPerSecond * sampleInterval);

                long sample = 0;

                while (m_Signal.WaitOne())
                {
                    Mobile.ProcessDeltaQueue();
                    Item.ProcessDeltaQueue();

                    Timer.Slice();
                    messagePump.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();

                    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));
            }
        }
Exemple #26
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 #27
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(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);
                UnsafeNativeMethods.SetConsoleCtrlHandler(m_ConsoleEventHandler, true);
            }

            if (GCSettings.IsServerGC)
            {
                Console.WriteLine("Core: Server garbage collection mode enabled");
            }

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

            ScriptCompiler.Invoke("Configure");

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

            ScriptCompiler.Invoke("Initialize");

            MessagePump messagePump = 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
            {
                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();
                    messagePump.Slice();

                    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));
            }
        }
Exemple #28
0
        public static void Main( string[] args )
        {
            m_Assembly = Assembly.GetEntryAssembly();

            /* print a banner */
            Version ver = m_Assembly.GetName().Version;
            Console.WriteLine("SunLogin Version {0}.{1}.{2} http://www.sunuo.org/",
                              ver.Major, ver.Minor, ver.Revision);
            Console.WriteLine("  on {0}, runtime {1}",
                              Environment.OSVersion, Environment.Version);

            if ((int)Environment.OSVersion.Platform == 128)
                Console.WriteLine("Please make sure you have Mono 1.1.7 or newer! (mono -V)");

            Console.WriteLine();

            /* prepare SunUO */
            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], "-service" ) )
                    m_Service = true;
                else if ( Insensitive.Equals( args[i], "-profile" ) )
                    Profiling = true;
                else if (args[i] == "--logfile") {
                    string logfile = args[++i];
                    StreamWriter writer = new StreamWriter(new FileStream(logfile, FileMode.Append, FileAccess.Write));
                    writer.AutoFlush = true;
                    Console.SetOut(writer);
                    Console.SetError(writer);
                }
            }

            config = new Config(Path.Combine(BaseDirectoryInfo.CreateSubdirectory("etc").FullName, "sunuo.xml"));

            try
            {
                m_MultiConOut = new MultiTextWriter(Console.Out);
                Console.SetOut(m_MultiConOut);

                if (m_Service) {
                    string filename = Path.Combine(LogDirectoryInfo.FullName, "console.log");
                    m_MultiConOut.Add(new FileLogger(filename));
                }
            }
            catch
            {
            }

            m_Thread = Thread.CurrentThread;

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

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

            m_MessagePump = new MessagePump( new Listener( Listener.Port ) );

            timerThread.Start();

            NetState.Initialize();
            Encryption.Initialize();
            ServerList.Initialize();
            Server.Accounting.AccountHandler.Initialize();

            EventSink.InvokeServerStarted();

            try
            {
                while ( !m_Closing )
                {
                    Thread.Sleep( 1 );

                    Timer.Slice();
                    m_MessagePump.Slice();

                    NetState.FlushAll();
                    NetState.ProcessDisposedQueue();

                    if ( Slice != null )
                        Slice();
                }
            }
            catch ( Exception e )
            {
                CurrentDomain_UnhandledException( null, new UnhandledExceptionEventArgs( e, true ) );
            }

            if ( timerThread.IsAlive )
                timerThread.Abort();
        }
Exemple #29
0
		public static void Main(string[] args)
		{
			AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
			AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;

			foreach (string arg in args)
			{
				if (Insensitive.Equals(arg, "-debug"))
				{
					m_Debug = true;
				}
				else if (Insensitive.Equals(arg, "-service"))
				{
					m_Service = true;
				}
				else if (Insensitive.Equals(arg, "-profile"))
				{
					Profiling = true;
				}
				else if (Insensitive.Equals(arg, "-nocache"))
				{
					m_Cache = false;
				}
				else if (Insensitive.Equals(arg, "-haltonwarning"))
				{
					m_HaltOnWarning = true;
				}
				else if (Insensitive.Equals(arg, "-vb"))
				{
					m_VBdotNET = true;
				}
				else if (Insensitive.Equals(arg, "-usehrt"))
				{
					m_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);
			}

			var ttObj = new Timer.TimerThread();

			timerThread = new Thread(ttObj.TimerMain)
			{
				Name = "Timer Thread"
			};

			Version ver = m_Assembly.GetName().Version;

			String publishNumber = String.Empty;

			if (File.Exists("publish.txt"))
			{
				try
				{
					publishNumber = File.ReadAllText("publish.txt", Encoding.UTF8);
				}
				catch
				{ }
			}

			// Added to help future code support on forums, as a 'check' people can ask for to it see if they recompiled core or not
			Utility.PushColor(ConsoleColor.DarkGreen);
			Console.WriteLine(@"----------------------------------------------------------------------------");
			Utility.PopColor();
			Utility.PushColor(ConsoleColor.Cyan);
			Console.WriteLine("JustUO - [http://www.playuo.org] Version {0}.{1}", ver.Major, ver.Minor);

			if (!String.IsNullOrWhiteSpace(publishNumber))
			{
				Console.WriteLine("Publish {0}", publishNumber);
			}

			Utility.PopColor();

			Console.WriteLine(
				"Core: .NET Framework Version {0}.{1}.{2}",
				Environment.Version.Major,
				Environment.Version.Minor,
				Environment.Version.Build);

			string s = Arguments;

			if (s.Length > 0)
			{
				Utility.PushColor(ConsoleColor.Yellow);
				Console.WriteLine("Core: Running with arguments: {0}", s);
				Utility.PopColor();
			}

			m_ProcessorCount = Environment.ProcessorCount;

			if (m_ProcessorCount > 1)
			{
				m_MultiProcessor = true;
			}

			if (m_MultiProcessor || Is64Bit)
			{
				Utility.PushColor(ConsoleColor.Green);
				Console.WriteLine(
					"Core: Optimizing for {0} {2}processor{1}",
					m_ProcessorCount,
					m_ProcessorCount == 1 ? "" : "s",
					Is64Bit ? "64-bit " : "");
				Utility.PopColor();
			}

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

			if (platform == 4 || platform == 128)
			{
				// MS 4, MONO 128
				m_Unix = true;
				Utility.PushColor(ConsoleColor.Yellow);
				Console.WriteLine("Core: Unix environment detected");
				Utility.PopColor();
			}
			else
			{
				m_ConsoleEventHandler = OnConsoleEvent;
				UnsafeNativeMethods.SetConsoleCtrlHandler(m_ConsoleEventHandler, true);
			}

			if (GCSettings.IsServerGC)
			{
				Utility.PushColor(ConsoleColor.DarkYellow);
				Console.WriteLine("Core: Server garbage collection mode enabled");
				Utility.PopColor();
			}

			if (m_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))
			{
				Utility.PushColor(ConsoleColor.Red);
				Console.WriteLine("Scripts: One or more scripts failed to compile or no script files were found.");
				Utility.PopColor();

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

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

			ScriptCompiler.Invoke("Initialize");

			MessagePump messagePump = m_MessagePump = new MessagePump();

			timerThread.Start();

			foreach (Map m in Map.AllMaps)
			{
				m.Tiles.Force();
			}

			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();
					messagePump.Slice();

					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));
			}
		}
Exemple #30
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

		}