コード例 #1
0
        public override void Start(string[] args)
        {
            Host.Object.Say("Starting MRM Meta System.");
            _k = NinjectFactory.getKernel<DynamicLoaderModule>();
            BindableHost.Host = Host;
            BindableWorld.World = World;

            _k.Bind<IHost>().To<BindableHost>().InSingletonScope();
            _k.Bind<IWorld>().To<BindableWorld>().InSingletonScope();

            string queueLibrary = typeof(AsynchQueueFactory).Assembly.Location;
            string queueType = typeof(AsynchQueueFactory).FullName;
            try {
                IConfig masterConfig = new DotNetConfigSource(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile).Configs["Bootstrap"];
                queueLibrary = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, masterConfig.GetString(MRMSystem.QUEUE + MRMSystem.ASSEMBLY, queueLibrary));
                queueType = masterConfig.GetString(MRMSystem.QUEUE + MRMSystem.CLASS, queueType);
            } catch (Exception e) {
            }
            _k.Get<IDynamicLoaderModule>().BindDynamic(typeof(IAsynchQueueFactory), queueLibrary, queueType, true);

            World.OnChat += (world, chatArgs) => {
                lock (this) {
                    if (chatArgs.Channel == CHAN && chatArgs.Text.StartsWith(PING_ACK)) {
                        string configFile = chatArgs.Text.Split(new char[] { ':' }, 2)[1];
                        string baseFolder = Path.GetDirectoryName(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
                        configFile = Path.Combine(baseFolder, configFile);
                        Console.WriteLine("Tying to start " + chatArgs.Sender.Name + " from " + configFile);
                        if (!File.Exists(configFile)) {
                            //throw new Exception("Unable to start MRM system. No config file found at '" + Path.GetFullPath(configFile) + "'.");
                            return;
                        }
                        IConfig config = new DotNetConfigSource(configFile).Configs["Bootstrap"];
                        if (config == null) {
                            //throw new Exception("Unable to start MRM system. No 'Bootstrap' section found in config file '" + Path.GetFullPath(configFile) + "'.");
                            return;
                        }

                        try {
                            UUID id = chatArgs.Sender.GlobalID;
                            MRMSystem system = new MRMSystem();
                            system.InitMiniModule(World, Host, UUID.Random());
                            system.Start(_k, config, configFile, id, false);

                            _liveSystems.Add(chatArgs.Sender.GlobalID, system);
                            _k.Get<IPrimFactory>()[id].OnWorldDelete += destroyedID => {
                                Stop(system);
                                system.Stop();
                                _liveSystems.Remove(id);
                            };
                        } catch (Exception e) {
                            log.Warn("Unable to start MRM system from " + chatArgs.Sender.Name + ". " + e);
                            Host.Object.Say("Unable to start MRM system from " + chatArgs.Sender.Name, 0, true, MRMChatTypeEnum.Region);
                        }
                    }
                }
            };
            Host.Object.Say(PING, CHAN, ChatTargetEnum.LSL);
        }
コード例 #2
0
 private void Stop(MRMSystem system)
 {
     try {
         system.Stop();
     } catch (Exception e) {
         log.Warn("Unable to stop MRM system. " + e);
         Host.Object.Say("Unable to stop MRM system.", 0, true, MRMChatTypeEnum.Region);
     }
 }