Exemplo n.º 1
0
        /// <summary>
        /// Searches through the files in the archive for the control file, and reads it.
        /// We must read the control file first, in order to know which regions are available.
        /// </summary>
        /// <remarks>
        /// In most cases the control file *is* first, since that's how we create archives. However,
        /// it's possible that someone rewrote the archive externally so we can't rely on this fact.
        /// </remarks>
        /// <param name="archive"></param>
        /// <param name="dearchivedScenes"></param>
        private void FindAndLoadControlFile(out TarArchiveReader archive, out DearchiveScenesInfo dearchivedScenes)
        {
            archive = new TarArchiveReader(m_loadStream);
            dearchivedScenes = new DearchiveScenesInfo();

            string filePath;
            byte[] data;
            TarArchiveReader.TarEntryType entryType;
            bool firstFile = true;

            while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
            {
                if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
                    continue;
                    
                if (filePath == ArchiveConstants.CONTROL_FILE_PATH)
                {
                    LoadControlFile(filePath, data, dearchivedScenes);

                    // Find which scenes are available in the simulator
                    ArchiveScenesGroup simulatorScenes = new ArchiveScenesGroup();
                    SceneManager.Instance.ForEachScene(delegate(Scene scene2)
                    {
                        simulatorScenes.AddScene(scene2);
                    });
                    simulatorScenes.CalcSceneLocations();
                    dearchivedScenes.SetSimulatorScenes(m_rootScene, simulatorScenes);

                    // If the control file wasn't the first file then reset the read pointer
                    if (!firstFile)
                    {
                        m_log.Warn("Control file wasn't the first file in the archive");
                        if (m_loadStream.CanSeek)
                        {
                            m_loadStream.Seek(0, SeekOrigin.Begin);
                        }
                        else if (m_loadPath != null)
                        {
                            archive.Close();
                            archive = null;
                            m_loadStream.Close();
                            m_loadStream = null;
                            m_loadStream = new GZipStream(ArchiveHelpers.GetStream(m_loadPath), CompressionMode.Decompress);
                            archive = new TarArchiveReader(m_loadStream);
                        }
                        else
                        {
                            // There isn't currently a scenario where this happens, but it's best to add a check just in case
                            throw new Exception("Error reading archive: control file wasn't the first file, and the input stream doesn't allow seeking");
                        }
                    }

                    return;
                }

                firstFile = false;
            }

            throw new Exception("Control file not found");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load oar control file
        /// </summary>
        /// <param name="path"></param>
        /// <param name="data"></param>
        /// <param name="dearchivedScenes"></param>
        public DearchiveScenesInfo LoadControlFile(string path, byte[] data, DearchiveScenesInfo dearchivedScenes)
        {
            XmlNamespaceManager nsmgr   = new XmlNamespaceManager(new NameTable());
            XmlParserContext    context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
            XmlTextReader       xtr     = new XmlTextReader(Encoding.ASCII.GetString(data), XmlNodeType.Document, context);

            // Loaded metadata will be empty if no information exists in the archive
            dearchivedScenes.LoadedCreationDateTime = 0;
            dearchivedScenes.DefaultOriginalID      = "";

            bool multiRegion = false;

            while (xtr.Read())
            {
                if (xtr.NodeType == XmlNodeType.Element)
                {
                    if (xtr.Name.ToString() == "archive")
                    {
                        int    majorVersion = int.Parse(xtr["major_version"]);
                        int    minorVersion = int.Parse(xtr["minor_version"]);
                        string version      = string.Format("{0}.{1}", majorVersion, minorVersion);

                        if (majorVersion > MAX_MAJOR_VERSION)
                        {
                            throw new Exception(
                                      string.Format(
                                          "The OAR you are trying to load has major version number of {0} but this version of OpenSim can only load OARs with major version number {1} and below",
                                          majorVersion, MAX_MAJOR_VERSION));
                        }

                        m_log.InfoFormat("[ARCHIVER]: Loading OAR with version {0}", version);
                    }
                    if (xtr.Name.ToString() == "datetime")
                    {
                        int value;
                        if (Int32.TryParse(xtr.ReadElementContentAsString(), out value))
                        {
                            dearchivedScenes.LoadedCreationDateTime = value;
                        }
                    }
                    else if (xtr.Name.ToString() == "row")
                    {
                        multiRegion = true;
                        dearchivedScenes.StartRow();
                    }
                    else if (xtr.Name.ToString() == "region")
                    {
                        dearchivedScenes.StartRegion();
                    }
                    else if (xtr.Name.ToString() == "id")
                    {
                        string id = xtr.ReadElementContentAsString();
                        dearchivedScenes.DefaultOriginalID = id;
                        if (multiRegion)
                        {
                            dearchivedScenes.SetRegionOriginalID(id);
                        }
                    }
                    else if (xtr.Name.ToString() == "dir")
                    {
                        dearchivedScenes.SetRegionDirectory(xtr.ReadElementContentAsString());
                    }
                }
            }

            dearchivedScenes.MultiRegionFormat = multiRegion;
            if (!multiRegion)
            {
                // Add the single scene
                dearchivedScenes.StartRow();
                dearchivedScenes.StartRegion();
                dearchivedScenes.SetRegionOriginalID(dearchivedScenes.DefaultOriginalID);
                dearchivedScenes.SetRegionDirectory("");
            }

            ControlFileLoaded = true;

            return(dearchivedScenes);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load region settings data
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="settingsPath"></param>
        /// <param name="data"></param>
        /// <param name="dearchivedScenes"></param>
        /// <returns>
        /// true if settings were loaded successfully, false otherwise
        /// </returns>
        private bool LoadRegionSettings(Scene scene, string settingsPath, byte[] data, DearchiveScenesInfo dearchivedScenes)
        {
            RegionSettings loadedRegionSettings;

            try
            {
                loadedRegionSettings = RegionSettingsSerializer.Deserialize(data);
            }
            catch (Exception e)
            {
                m_log.ErrorFormat(
                    "[ARCHIVER]: Could not parse region settings file {0}.  Ignoring.  Exception was {1}",
                    settingsPath, e);
                return(false);
            }

            RegionSettings currentRegionSettings = scene.RegionInfo.RegionSettings;

            currentRegionSettings.AgentLimit          = loadedRegionSettings.AgentLimit;
            currentRegionSettings.AllowDamage         = loadedRegionSettings.AllowDamage;
            currentRegionSettings.AllowLandJoinDivide = loadedRegionSettings.AllowLandJoinDivide;
            currentRegionSettings.AllowLandResell     = loadedRegionSettings.AllowLandResell;
            currentRegionSettings.BlockFly            = loadedRegionSettings.BlockFly;
            currentRegionSettings.BlockShowInSearch   = loadedRegionSettings.BlockShowInSearch;
            currentRegionSettings.BlockTerraform      = loadedRegionSettings.BlockTerraform;
            currentRegionSettings.DisableCollisions   = loadedRegionSettings.DisableCollisions;
            currentRegionSettings.DisablePhysics      = loadedRegionSettings.DisablePhysics;
            currentRegionSettings.DisableScripts      = loadedRegionSettings.DisableScripts;
            currentRegionSettings.Elevation1NE        = loadedRegionSettings.Elevation1NE;
            currentRegionSettings.Elevation1NW        = loadedRegionSettings.Elevation1NW;
            currentRegionSettings.Elevation1SE        = loadedRegionSettings.Elevation1SE;
            currentRegionSettings.Elevation1SW        = loadedRegionSettings.Elevation1SW;
            currentRegionSettings.Elevation2NE        = loadedRegionSettings.Elevation2NE;
            currentRegionSettings.Elevation2NW        = loadedRegionSettings.Elevation2NW;
            currentRegionSettings.Elevation2SE        = loadedRegionSettings.Elevation2SE;
            currentRegionSettings.Elevation2SW        = loadedRegionSettings.Elevation2SW;
            currentRegionSettings.FixedSun            = loadedRegionSettings.FixedSun;
            currentRegionSettings.SunPosition         = loadedRegionSettings.SunPosition;
            currentRegionSettings.ObjectBonus         = loadedRegionSettings.ObjectBonus;
            currentRegionSettings.RestrictPushing     = loadedRegionSettings.RestrictPushing;
            currentRegionSettings.TerrainLowerLimit   = loadedRegionSettings.TerrainLowerLimit;
            currentRegionSettings.TerrainRaiseLimit   = loadedRegionSettings.TerrainRaiseLimit;
            currentRegionSettings.TerrainTexture1     = loadedRegionSettings.TerrainTexture1;
            currentRegionSettings.TerrainTexture2     = loadedRegionSettings.TerrainTexture2;
            currentRegionSettings.TerrainTexture3     = loadedRegionSettings.TerrainTexture3;
            currentRegionSettings.TerrainTexture4     = loadedRegionSettings.TerrainTexture4;
            currentRegionSettings.UseEstateSun        = loadedRegionSettings.UseEstateSun;
            currentRegionSettings.WaterHeight         = loadedRegionSettings.WaterHeight;
            currentRegionSettings.TelehubObject       = loadedRegionSettings.TelehubObject;
            currentRegionSettings.ClearSpawnPoints();
            foreach (SpawnPoint sp in loadedRegionSettings.SpawnPoints())
            {
                currentRegionSettings.AddSpawnPoint(sp);
            }

            currentRegionSettings.LoadedCreationDateTime = dearchivedScenes.LoadedCreationDateTime;
            currentRegionSettings.LoadedCreationID       = dearchivedScenes.GetOriginalRegionID(scene.RegionInfo.RegionID).ToString();

            currentRegionSettings.Save();

            scene.TriggerEstateSunUpdate();

            IEstateModule estateModule = scene.RequestModuleInterface <IEstateModule>();

            if (estateModule != null)
            {
                estateModule.sendRegionHandshakeToAll();
            }

            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Load oar control file
        /// </summary>
        /// <param name="path"></param>
        /// <param name="data"></param>
        /// <param name="dearchivedScenes"></param>
        public DearchiveScenesInfo LoadControlFile(string path, byte[] data, DearchiveScenesInfo dearchivedScenes)
        {
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
            XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
            XmlTextReader xtr = new XmlTextReader(Encoding.ASCII.GetString(data), XmlNodeType.Document, context);

            // Loaded metadata will be empty if no information exists in the archive
            dearchivedScenes.LoadedCreationDateTime = 0;
            dearchivedScenes.DefaultOriginalID = "";

            bool multiRegion = false;

            while (xtr.Read()) 
            {
                if (xtr.NodeType == XmlNodeType.Element) 
                {
                    if (xtr.Name.ToString() == "archive")
                    {
                        int majorVersion = int.Parse(xtr["major_version"]);
                        int minorVersion = int.Parse(xtr["minor_version"]);
                        string version = string.Format("{0}.{1}", majorVersion, minorVersion);
                        
                        if (majorVersion > MAX_MAJOR_VERSION)
                        {
                            throw new Exception(
                                string.Format(
                                    "The OAR you are trying to load has major version number of {0} but this version of OpenSim can only load OARs with major version number {1} and below",
                                    majorVersion, MAX_MAJOR_VERSION));
                        }
                        
                        m_log.InfoFormat("[ARCHIVER]: Loading OAR with version {0}", version);
                    }
                    if (xtr.Name.ToString() == "datetime") 
                    {
                        int value;
                        if (Int32.TryParse(xtr.ReadElementContentAsString(), out value))
                            dearchivedScenes.LoadedCreationDateTime = value;
                    } 
                    else if (xtr.Name.ToString() == "row")
                    {
                        multiRegion = true;
                        dearchivedScenes.StartRow();
                    }
                    else if (xtr.Name.ToString() == "region")
                    {
                        dearchivedScenes.StartRegion();
                    }
                    else if (xtr.Name.ToString() == "id")
                    {
                        string id = xtr.ReadElementContentAsString();
                        dearchivedScenes.DefaultOriginalID = id;
                        if (multiRegion)
                            dearchivedScenes.SetRegionOriginalID(id);
                    }
                    else if (xtr.Name.ToString() == "dir")
                    {
                        dearchivedScenes.SetRegionDirectory(xtr.ReadElementContentAsString());
                    }
                }
            }

            dearchivedScenes.MultiRegionFormat = multiRegion;
            if (!multiRegion)
            {
                // Add the single scene
                dearchivedScenes.StartRow();
                dearchivedScenes.StartRegion();
                dearchivedScenes.SetRegionOriginalID(dearchivedScenes.DefaultOriginalID);
                dearchivedScenes.SetRegionDirectory("");
            }

            ControlFileLoaded = true;

            return dearchivedScenes;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Load region settings data
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="settingsPath"></param>
        /// <param name="data"></param>
        /// <param name="dearchivedScenes"></param>
        /// <returns>
        /// true if settings were loaded successfully, false otherwise
        /// </returns>
        private bool LoadRegionSettings(Scene scene, string settingsPath, byte[] data, DearchiveScenesInfo dearchivedScenes)
        {
            RegionSettings loadedRegionSettings;

            try
            {
                loadedRegionSettings = RegionSettingsSerializer.Deserialize(data);
            }
            catch (Exception e)
            {
                m_log.ErrorFormat(
                    "[ARCHIVER]: Could not parse region settings file {0}.  Ignoring.  Exception was {1}",
                    settingsPath, e);
                return false;
            }

            RegionSettings currentRegionSettings = scene.RegionInfo.RegionSettings;

            currentRegionSettings.AgentLimit = loadedRegionSettings.AgentLimit;
            currentRegionSettings.AllowDamage = loadedRegionSettings.AllowDamage;
            currentRegionSettings.AllowLandJoinDivide = loadedRegionSettings.AllowLandJoinDivide;
            currentRegionSettings.AllowLandResell = loadedRegionSettings.AllowLandResell;
            currentRegionSettings.BlockFly = loadedRegionSettings.BlockFly;
            currentRegionSettings.BlockShowInSearch = loadedRegionSettings.BlockShowInSearch;
            currentRegionSettings.BlockTerraform = loadedRegionSettings.BlockTerraform;
            currentRegionSettings.DisableCollisions = loadedRegionSettings.DisableCollisions;
            currentRegionSettings.DisablePhysics = loadedRegionSettings.DisablePhysics;
            currentRegionSettings.DisableScripts = loadedRegionSettings.DisableScripts;
            currentRegionSettings.Elevation1NE = loadedRegionSettings.Elevation1NE;
            currentRegionSettings.Elevation1NW = loadedRegionSettings.Elevation1NW;
            currentRegionSettings.Elevation1SE = loadedRegionSettings.Elevation1SE;
            currentRegionSettings.Elevation1SW = loadedRegionSettings.Elevation1SW;
            currentRegionSettings.Elevation2NE = loadedRegionSettings.Elevation2NE;
            currentRegionSettings.Elevation2NW = loadedRegionSettings.Elevation2NW;
            currentRegionSettings.Elevation2SE = loadedRegionSettings.Elevation2SE;
            currentRegionSettings.Elevation2SW = loadedRegionSettings.Elevation2SW;
            currentRegionSettings.FixedSun = loadedRegionSettings.FixedSun;
            currentRegionSettings.SunPosition = loadedRegionSettings.SunPosition;
            currentRegionSettings.ObjectBonus = loadedRegionSettings.ObjectBonus;
            currentRegionSettings.RestrictPushing = loadedRegionSettings.RestrictPushing;
            currentRegionSettings.TerrainLowerLimit = loadedRegionSettings.TerrainLowerLimit;
            currentRegionSettings.TerrainRaiseLimit = loadedRegionSettings.TerrainRaiseLimit;
            currentRegionSettings.TerrainTexture1 = loadedRegionSettings.TerrainTexture1;
            currentRegionSettings.TerrainTexture2 = loadedRegionSettings.TerrainTexture2;
            currentRegionSettings.TerrainTexture3 = loadedRegionSettings.TerrainTexture3;
            currentRegionSettings.TerrainTexture4 = loadedRegionSettings.TerrainTexture4;
            currentRegionSettings.UseEstateSun = loadedRegionSettings.UseEstateSun;
            currentRegionSettings.WaterHeight = loadedRegionSettings.WaterHeight;
            currentRegionSettings.TelehubObject = loadedRegionSettings.TelehubObject;
            currentRegionSettings.ClearSpawnPoints();
            foreach (SpawnPoint sp in loadedRegionSettings.SpawnPoints())
                currentRegionSettings.AddSpawnPoint(sp);

            currentRegionSettings.LoadedCreationDateTime = dearchivedScenes.LoadedCreationDateTime;
            currentRegionSettings.LoadedCreationID = dearchivedScenes.GetOriginalRegionID(scene.RegionInfo.RegionID).ToString();

            currentRegionSettings.Save();

            scene.TriggerEstateSunUpdate();
            
            IEstateModule estateModule = scene.RequestModuleInterface<IEstateModule>();
            if (estateModule != null)
                estateModule.sendRegionHandshakeToAll();

            return true;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Searches through the files in the archive for the control file, and reads it.
        /// We must read the control file first, in order to know which regions are available.
        /// </summary>
        /// <remarks>
        /// In most cases the control file *is* first, since that's how we create archives. However,
        /// it's possible that someone rewrote the archive externally so we can't rely on this fact.
        /// </remarks>
        /// <param name="archive"></param>
        /// <param name="dearchivedScenes"></param>
        private void FindAndLoadControlFile(out TarArchiveReader archive, out DearchiveScenesInfo dearchivedScenes)
        {
            archive = new TarArchiveReader(m_loadStream);
            dearchivedScenes = new DearchiveScenesInfo();

            string filePath;
            byte[] data;
            TarArchiveReader.TarEntryType entryType;
            bool firstFile = true;

            while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
            {
                if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
                    continue;
                    
                if (filePath == ArchiveConstants.CONTROL_FILE_PATH)
                {
                    LoadControlFile(filePath, data, dearchivedScenes);

                    // Find which scenes are available in the simulator
                    ArchiveScenesGroup simulatorScenes = new ArchiveScenesGroup();
                    SceneManager.Instance.ForEachScene(delegate(Scene scene2)
                    {
                        simulatorScenes.AddScene(scene2);
                    });
                    simulatorScenes.CalcSceneLocations();
                    dearchivedScenes.SetSimulatorScenes(m_rootScene, simulatorScenes);

                    // If the control file wasn't the first file then reset the read pointer
                    if (!firstFile)
                    {
                        m_log.Warn("Control file wasn't the first file in the archive");
                        if (m_loadStream.CanSeek)
                        {
                            m_loadStream.Seek(0, SeekOrigin.Begin);
                        }
                        else if (m_loadPath != null)
                        {
                            archive.Close();
                            archive = null;
                            m_loadStream.Close();
                            m_loadStream = null;
                            m_loadStream = new GZipStream(ArchiveHelpers.GetStream(m_loadPath), CompressionMode.Decompress);
                            archive = new TarArchiveReader(m_loadStream);
                        }
                        else
                        {
                            // There isn't currently a scenario where this happens, but it's best to add a check just in case
                            throw new Exception("Error reading archive: control file wasn't the first file, and the input stream doesn't allow seeking");
                        }
                    }

                    return;
                }

                firstFile = false;
            }

            throw new Exception("Control file not found");
        }