AddListener() public méthode

public AddListener ( Listener l ) : void
l Listener
Résultat void
Exemple #1
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 #2
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();
        }