Inheritance: RegistryCore, IScene
Ejemplo n.º 1
0
        /// <summary>
        ///     Create a scene and its initial base structures.
        /// </summary>
        /// <param name="regionInfo"></param>
        /// <returns></returns>
        public IScene CreateScene(ISimulationDataStore dataStore, RegionInfo regionInfo)
        {
            AgentCircuitManager circuitManager = new AgentCircuitManager();
            List<IClientNetworkServer> clientServers = UniverseModuleLoader.PickupModules<IClientNetworkServer>();
            List<IClientNetworkServer> allClientServers = new List<IClientNetworkServer>();
            foreach (IClientNetworkServer clientServer in clientServers)
            {
                clientServer.Initialize((uint)regionInfo.RegionPort, m_configSource, circuitManager);
                allClientServers.Add(clientServer);
            }

            Scene scene = new Scene();
            scene.AddModuleInterfaces(m_simBase.ApplicationRegistry.GetInterfaces());
            scene.Initialize(regionInfo, dataStore, circuitManager, allClientServers);

            return scene;
        }
        /// <summary>
        ///     Use the asset set information at path to load assets
        /// </summary>
        /// <param name="iarFileName"></param>
        protected void LoadLibraries(string iarFileName)
        {
            RegionInfo regInfo = new RegionInfo();
            IScene m_MockScene = null;
            //Make the scene for the IAR loader
            if (m_registry is IScene)
                m_MockScene = (IScene) m_registry;
            else
            {
                m_MockScene = new Scene();
                m_MockScene.Initialize(regInfo);
                m_MockScene.AddModuleInterfaces(m_registry.GetInterfaces());
            }

            UserAccount uinfo = m_MockScene.UserAccountService.GetUserAccount(null, m_service.LibraryOwner);
            //Make the user account for the default IAR
            if (uinfo == null)
            {
                MainConsole.Instance.Warn("Creating user " + m_service.LibraryOwnerName);
                m_MockScene.UserAccountService.CreateUser(m_service.LibraryOwner, UUID.Zero, m_service.LibraryOwnerName,
                                                          "", "");
                uinfo = m_MockScene.UserAccountService.GetUserAccount(null, m_service.LibraryOwner);
                m_MockScene.InventoryService.CreateUserInventory(uinfo.PrincipalID, false);
            }
            if (m_MockScene.InventoryService.GetRootFolder(m_service.LibraryOwner) == null)
                m_MockScene.InventoryService.CreateUserInventory(uinfo.PrincipalID, false);

            List<InventoryFolderBase> rootFolders = m_MockScene.InventoryService.GetFolderFolders(uinfo.PrincipalID,
                                                                                                  UUID.Zero);
            bool alreadyExists = rootFolders.Any(folder => folder.Name == iarFileName);

            if (alreadyExists)
            {
                MainConsole.Instance.InfoFormat("[LIBRARY INVENTORY]: Found previously loaded iar file {0}, ignoring.",
                                                iarFileName);
                return;
            }

            MainConsole.Instance.InfoFormat("[LIBRARY INVENTORY]: Loading iar file {0}", iarFileName);
            InventoryFolderBase rootFolder = m_MockScene.InventoryService.GetRootFolder(uinfo.PrincipalID);

            if (null == rootFolder)
            {
                //We need to create the root folder, otherwise the IAR freaks
                m_MockScene.InventoryService.CreateUserInventory(uinfo.PrincipalID, false);
            }

            InventoryArchiveReadRequest archread = new InventoryArchiveReadRequest(m_MockScene, uinfo, "/", iarFileName,
                                                                                   false, m_service.LibraryOwner);

            try
            {
                archread.ReplaceAssets = true; //Replace any old assets
                List<InventoryNodeBase> nodes = new List<InventoryNodeBase>(archread.Execute(true));
                if (nodes.Count == 0)
                    return;
                InventoryFolderBase f = (InventoryFolderBase) nodes[0];
                UUID IARRootID = f.ID;

                TraverseFolders(IARRootID, m_MockScene);
                FixParent(IARRootID, m_MockScene, m_service.LibraryRootFolderID);
                f.Name = iarFileName;
                f.ParentID = UUID.Zero;
                f.ID = m_service.LibraryRootFolderID;
                f.Type = (int) AssetType.RootFolder;
                f.Version = 1;
                m_MockScene.InventoryService.UpdateFolder(f);
            }
            catch (Exception e)
            {
                MainConsole.Instance.DebugFormat("[LIBRARY MODULE]: Exception when processing archive {0}: {1}",
                                                 iarFileName,
                                                 e.StackTrace);
            }
            finally
            {
                archread.Close();
            }
        }