Example #1
0
        static void Main(string[] args)
        {
            #if !DEBUG
            try
            {
            #endif
            /*TextWriter tw = new StreamWriter( "loot.cs" );
                tw.WriteLine("using System;using Server.Items;using System.Collections;using Server;namespace Server{public class LootTemplate {" );

                for(int t = 0;t < 10000;t++ )
                {
                    tw.WriteLine("public static Loot[] loottemplate" + t.ToString() + " = null;" );//new Loot[] { new Loot( typeof( Money ), 9, 20, 60.480000f ) };" );
                }
                tw.WriteLine("}}");
                tw.Close();*/
            /*
                            byte []aaa = new byte[] { 0x32, 0x9D, 0x33, 0x40, 0xA2, 0x63, 0x0B, 0xC6, 0x5A, 0xB5, 0xFB, 0xC2, 0x7B, 0xD9, 0xA2, 0x42, 0xE0, 0xF0, 0x63, 0x40, 0x3F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x60, 0x40 };
                            for(int t = 0;t < aaa.Length;t+=4 )
                            {
                                Console.WriteLine("{0} ", BitConverter.ToSingle( aaa, t ) );
                            }*/
            if ( args.Length > 0 )
            {
                foreach( string s in args )
                {
                    if ( s == "outfile" )
                    {
                        FileStream fs1 = new FileStream("log" + Utility.Random1024().ToString() + ".txt", FileMode.Create);
                        sw1 = new StreamWriter(fs1);
                        Console.SetOut( sw1 );
                    }
                    if ( s == "realmserver" )
                    {
                        World.RealmServer = true;
                        World.StandardServer = false;
                    }
                }
            }

            new MainConsole();

            Process []p = Process.GetProcessesByName( "WowwoW.exe" );

            if ( p.Length > 0 )
                p[ 0 ].WaitForExit();
            //	float a = Converter.ToFloat( new byte[]{ 0x
            Console.WriteLine("WowwoW Alpha v{0} (c) DrNexus ({1})", World.Version, World.ReleaseDate );
            Console.WriteLine("   Supported WoW Client -> v{0}", World.ClientVer );
            /*	if ( !BuildExternalEnvironements() )
                {
                    return;
                }*/
            if ( !World.RealmServer )
            {
                if ( !BuildAllDlls() )
                    return;
                Utility.FillConstructorList();
                ConstructorInfo ct = Utility.FindConstructor( "CustomHandlers", Utility.externAsm[ "globals" ] );
                ct.Invoke( null );
            }
            else
                Utility.FillConstructorList();

            world = new World();

            worldThread1ms = new Thread( new ThreadStart( world.Slice1ms ) );

            //	worldThread500ms = new Thread( new ThreadStart( world.Slice500ms ) );
            if ( !World.RealmServer )
                worldThread1ms.Start();

            th = new Thread[ 1 ];
            if ( !World.RealmServer )
            {
                Listen3724();
                Listen8085();
            }
            else
            {
                dbServer = new DBServer( "localhost", 8087 );
            }
            Listen80();

            worldThread1ms.Priority = ThreadPriority.AboveNormal;//.Highest;
            Area a = new Area();
            if ( sw1 != null )
                sw1.Flush();
            /*

            if ( World.StandardServer )
            {
                DBConnectoid dbc = new DBConnectoid();
                dbc.ConnectTo( "127.0.0.1", 8087 );
                byte []buffer = new byte[ 13 ];
                int offset = 0;
                Converter.ToBytes( (ushort)13, buffer, ref offset );
                Converter.ToBytes( (byte)1, buffer, ref offset );
                Converter.ToBytes( (ushort)0, buffer, ref offset );
                Converter.ToBytes( (UInt64)15051385, buffer, ref offset );
                dbc.SendGet( buffer );

            }*/
            while( !end )
            {
                /*	Process proc = Process.GetCurrentProcess();
                    Console.WriteLine("Virtual memory usage : {0} mb",proc.VirtualMemorySize / ( 1024 * 1024 ));
                    Console.WriteLine("Memory usage : {0} mb",proc.PrivateMemorySize / ( 1024 * 1024 ));
                    Console.WriteLine("Peak Virtual memory usage : {0} mb",proc.PeakVirtualMemorySize / ( 1024 * 1024 ) );
                    Console.WriteLine("Peak Memory usage : {0} mb",proc.PeakWorkingSet / ( 1024 * 1024 ) );
                    */
                /*	world.TimerReport();

                    int t = 0;
                    if ( World.localTime != null )
                        foreach( long l in World.localTime )
                            Console.WriteLine("Time {0} : {1} ({2},{3})", t++, (100*(double)l / (double)World.total).ToString("G5") , l, World.total );
                    */
                Thread.Sleep( 3000 );
            }
            #if !DEBUG
            }
            catch(Exception e )
            {
                Console.WriteLine("Error in main console !" );
                Console.WriteLine( e.Message );
                Console.WriteLine( e.Source );
                Console.WriteLine( e.StackTrace );
            }
            #endif
        }
Example #2
0
 private static World TryUpdateWob(World world, Guid id, float secondsPassed)
 {
     var wob = world.GetWob<Wob>(id);
     return wob == null ? world : wob.Update(secondsPassed, world);
 }
Example #3
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);
            }

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

            SocketPool.Create();

            MessagePump ms = m_MessagePump = new MessagePump();

            timerThread.Start();

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

            NetState.Initialize();

            EventSink.InvokeServerStarted();

            try
            {
                DateTime now, last = DateTime.Now;

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

                int sample = 0;

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

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

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

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

                    if ((++sample % sampleInterval) == 0)
                    {
                        now = DateTime.Now;
                        m_CyclesPerSecond[m_CycleIndex++ % m_CyclesPerSecond.Length] =
                            ticksPerSecond / (now.Ticks - last.Ticks);
                        last = now;
                    }
                }
            }
            catch (Exception e)
            {
                CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true));
            }
        }
Example #4
0
        private static void Save(Mobile from, int x1, int y1, int x2, int y2)
        {
            World.Broadcast(0x35, true, "Spawns are being saved, please wait.");
            DateTime  startTime = DateTime.Now;
            int       count     = 0;
            ArrayList itemssave = new ArrayList();

            foreach (Item itemsave in World.Items.Values)
            {
                if (itemsave is PremiumSpawner && ((itemsave.X >= x1 && itemsave.X <= x2) && (itemsave.Y >= y1 && itemsave.Y <= y2) && itemsave.Map == from.Map))
                {
                    itemssave.Add(itemsave);
                    count += 1;
                }
            }

            if (!Directory.Exists("Data/Monsters"))
            {
                Directory.CreateDirectory("Data/Monsters");
            }

            using (StreamWriter op = new StreamWriter("Data/Monsters/spawns.map"))
            {
                foreach (PremiumSpawner itemsave2 in itemssave)
                {
                    int mapnumber = 0;
                    switch (itemsave2.Map.ToString())
                    {
                    case "Felucca":
                        mapnumber = 1;
                        break;

                    case "Trammel":
                        mapnumber = 2;
                        break;

                    case "Ilshenar":
                        mapnumber = 3;
                        break;

                    case "Malas":
                        mapnumber = 4;
                        break;

                    case "Tokuno":
                        mapnumber = 5;
                        break;

                    default:
                        mapnumber = 6;
                        Console.WriteLine("Monster Parser: Warning, unknown map {0}", itemsave2.Map);
                        break;
                    }

                    string   timer1a = itemsave2.MinDelay.ToString();
                    string[] timer1b = timer1a.Split(':');
                    int      timer1c = (Utility.ToInt32(timer1b[0]) * 60) + Utility.ToInt32(timer1b[1]);

                    string   timer2a  = itemsave2.MaxDelay.ToString();
                    string[] timer2b  = timer2a.Split(':');
                    int      timer2c  = (Utility.ToInt32(timer2b[0]) * 60) + Utility.ToInt32(timer2b[1]);
                    string   towrite  = "";
                    string   towriteA = "";
                    string   towriteB = "";
                    string   towriteC = "";
                    string   towriteD = "";
                    string   towriteE = "";

                    if (itemsave2.CreaturesName.Count > 0)
                    {
                        towrite = itemsave2.CreaturesName[0].ToString();
                    }

                    if (itemsave2.SubSpawnerA.Count > 0)
                    {
                        towriteA = itemsave2.SubSpawnerA[0].ToString();
                    }

                    if (itemsave2.SubSpawnerB.Count > 0)
                    {
                        towriteB = itemsave2.SubSpawnerB[0].ToString();
                    }

                    if (itemsave2.SubSpawnerC.Count > 0)
                    {
                        towriteC = itemsave2.SubSpawnerC[0].ToString();
                    }

                    if (itemsave2.SubSpawnerD.Count > 0)
                    {
                        towriteD = itemsave2.SubSpawnerD[0].ToString();
                    }

                    if (itemsave2.SubSpawnerE.Count > 0)
                    {
                        towriteE = itemsave2.SubSpawnerE[0].ToString();
                    }

                    for (int i = 1; i < itemsave2.CreaturesName.Count; ++i)
                    {
                        if (itemsave2.CreaturesName.Count > 0)
                        {
                            towrite = towrite + ":" + itemsave2.CreaturesName[i].ToString();
                        }
                    }

                    for (int i = 1; i < itemsave2.SubSpawnerA.Count; ++i)
                    {
                        if (itemsave2.SubSpawnerA.Count > 0)
                        {
                            towriteA = towriteA + ":" + itemsave2.SubSpawnerA[i].ToString();
                        }
                    }

                    for (int i = 1; i < itemsave2.SubSpawnerB.Count; ++i)
                    {
                        if (itemsave2.SubSpawnerB.Count > 0)
                        {
                            towriteB = towriteB + ":" + itemsave2.SubSpawnerB[i].ToString();
                        }
                    }

                    for (int i = 1; i < itemsave2.SubSpawnerC.Count; ++i)
                    {
                        if (itemsave2.SubSpawnerC.Count > 0)
                        {
                            towriteC = towriteC + ":" + itemsave2.SubSpawnerC[i].ToString();
                        }
                    }

                    for (int i = 1; i < itemsave2.SubSpawnerD.Count; ++i)
                    {
                        if (itemsave2.SubSpawnerD.Count > 0)
                        {
                            towriteD = towriteD + ":" + itemsave2.SubSpawnerD[i].ToString();
                        }
                    }

                    for (int i = 1; i < itemsave2.SubSpawnerE.Count; ++i)
                    {
                        if (itemsave2.SubSpawnerE.Count > 0)
                        {
                            towriteE = towriteE + ":" + itemsave2.SubSpawnerE[i].ToString();
                        }
                    }

                    op.WriteLine("*|{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}|{13}|{14}|{15}|{16}|{17}|{18}|{19}|{20}", towrite, towriteA, towriteB, towriteC, towriteD, towriteE, itemsave2.X, itemsave2.Y, itemsave2.Z, mapnumber, timer1c, timer2c, itemsave2.HomeRange, itemsave2.SpawnRange, itemsave2.SpawnID, itemsave2.Count, itemsave2.SubCountA, itemsave2.SubCountB, itemsave2.SubCountC, itemsave2.SubCountD, itemsave2.SubCountE);
                }
            }

            DateTime endTime = DateTime.Now;

            World.Broadcast(0x35, true, "{0} spawns have been saved. The entire process took {1:F1} seconds.", count, (endTime - startTime).TotalSeconds);
        }
Example #5
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;
                }
            }

            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);
            Console.WriteLine(
                "ServUO - [https://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 (Insensitive.Equals(Console.ReadLine(), "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));
            }
        }
Example #6
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();
            }
        }
Example #7
0
        public static void Save(bool message, bool permitBackgroundWrite)
        {
            if (m_Saving)
            {
                return;
            }

            ++m_Saves;

            NetState.FlushAll();
            NetState.Pause();

            World.WaitForWriteCompletion();            //Blocks Save until current disk flush is done.

            m_Saving = true;

            m_DiskWriteHandle.Reset();

            if (message)
            {
                Broadcast(0x35, true, "The world is saving, please wait.");
            }

            SaveStrategy strategy = SaveStrategy.Acquire();

            Console.WriteLine("Core: Using {0} save strategy", strategy.Name.ToLowerInvariant());

            Console.Write("World: Saving...");

            Stopwatch watch = Stopwatch.StartNew();

            if (!Directory.Exists("Saves/Mobiles/"))
            {
                Directory.CreateDirectory("Saves/Mobiles/");
            }
            if (!Directory.Exists("Saves/Items/"))
            {
                Directory.CreateDirectory("Saves/Items/");
            }
            if (!Directory.Exists("Saves/Guilds/"))
            {
                Directory.CreateDirectory("Saves/Guilds/");
            }


            /*using ( SaveMetrics metrics = new SaveMetrics() ) {*/
            strategy.Save(null, permitBackgroundWrite);
            /*}*/

            try {
                EventSink.InvokeWorldSave(new WorldSaveEventArgs(message));
            } catch (Exception e) {
                throw new Exception("World Save event threw an exception.  Save failed!", e);
            }

            watch.Stop();

            m_Saving = false;

            if (!permitBackgroundWrite)
            {
                World.NotifyDiskWriteComplete();                        //Sets the DiskWriteHandle.  If we allow background writes, we leave this upto the individual save strategies.
            }
            ProcessSafetyQueues();

            strategy.ProcessDecay();

            Console.WriteLine("Save done in {0:F2} seconds.", watch.Elapsed.TotalSeconds);

            if (message)
            {
                Broadcast(0x35, true, "World save complete. The entire process took {0:F1} seconds.", watch.Elapsed.TotalSeconds);
            }

            NetState.Resume();
        }
Example #8
0
 public override Mobile ReadMobile()
 {
     return(World.FindMobile(ReadInt()));
 }
Example #9
0
 public override Item ReadItem()
 {
     return(World.FindItem(ReadInt()));
 }
Example #10
0
 public override Mobile ReadMobile()
 {
     return(World.FindMobile(Serial.op_Implicit(this.ReadInt())));
 }
Example #11
0
 public override Item ReadItem()
 {
     return(World.FindItem(Serial.op_Implicit(this.ReadInt())));
 }