Example #1
0
        /// <summary>
        /// Load serialized parcels.
        /// </summary>
        /// <param name="serialisedParcels"></param>
        protected void LoadParcels(List <string> serialisedParcels)
        {
            // Reload serialized parcels
            m_log.InfoFormat("[ARCHIVER]: Loading {0} parcels.  Please wait.", serialisedParcels.Count);
            List <LandData> landData = new List <LandData>();

            foreach (string serialisedParcel in serialisedParcels)
            {
                LandData parcel = LandDataSerializer.Deserialize(serialisedParcel);
                if (!ResolveUserUuid(parcel.OwnerID))
                {
                    parcel.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
                }

//                m_log.DebugFormat(
//                    "[ARCHIVER]: Adding parcel {0}, local id {1}, area {2}",
//                    parcel.Name, parcel.LocalID, parcel.Area);

                landData.Add(parcel);
            }

            if (!m_merge)
            {
                bool setupDefaultParcel = (landData.Count == 0);
                m_scene.LandChannel.Clear(setupDefaultParcel);
            }

            m_scene.EventManager.TriggerIncomingLandDataFromStorage(landData);
            m_log.InfoFormat("[ARCHIVER]: Restored {0} parcels.", landData.Count);
        }
        public void TestLandDataDeserializeNoAccessLists()
        {
            TestHelpers.InMethod();
            //            log4net.Config.XmlConfigurator.Configure();

            Dictionary <string, object> options = new Dictionary <string, object>();
            LandData ld = LandDataSerializer.Deserialize(LandDataSerializer.Serialize(this.land, options));

            Assert.That(ld, Is.Not.Null, "Deserialize(string) returned null");
            //            Assert.That(ld.AABBMax, Is.EqualTo(land.AABBMax));
            //            Assert.That(ld.AABBMin, Is.EqualTo(land.AABBMin));
            Assert.That(ld.Area, Is.EqualTo(land.Area));
            Assert.That(ld.AuctionID, Is.EqualTo(land.AuctionID));
            Assert.That(ld.AuthBuyerID, Is.EqualTo(land.AuthBuyerID));
            Assert.That(ld.Category, Is.EqualTo(land.Category));
            Assert.That(ld.ClaimDate, Is.EqualTo(land.ClaimDate));
            Assert.That(ld.ClaimPrice, Is.EqualTo(land.ClaimPrice));
            Assert.That(ld.GlobalID, Is.EqualTo(land.GlobalID), "Reified LandData.GlobalID != original LandData.GlobalID");
            Assert.That(ld.GroupID, Is.EqualTo(land.GroupID));
            Assert.That(ld.Description, Is.EqualTo(land.Description));
            Assert.That(ld.Flags, Is.EqualTo(land.Flags));
            Assert.That(ld.LandingType, Is.EqualTo(land.LandingType));
            Assert.That(ld.Name, Is.EqualTo(land.Name), "Reified LandData.Name != original LandData.Name");
            Assert.That(ld.Status, Is.EqualTo(land.Status));
            Assert.That(ld.LocalID, Is.EqualTo(land.LocalID));
            Assert.That(ld.MediaAutoScale, Is.EqualTo(land.MediaAutoScale));
            Assert.That(ld.MediaID, Is.EqualTo(land.MediaID));
            Assert.That(ld.MediaURL, Is.EqualTo(land.MediaURL));
            Assert.That(ld.OwnerID, Is.EqualTo(land.OwnerID));
        }
        LandData LoadLandData(byte [] data)
        {
            LandData parcel        = LandDataSerializer.Deserialize(m_utf8Encoding.GetString(data));
            var      estateOwnerId = m_scene.RegionInfo.EstateSettings.EstateOwner;
            var      defaultFlags  =
                (uint)ParcelFlags.AllowAPrimitiveEntry |
                (uint)ParcelFlags.AllowDamage |
                (uint)ParcelFlags.AllowDeedToGroup |
                (uint)ParcelFlags.AllowFly |
                (uint)ParcelFlags.AllowGroupObjectEntry |
                (uint)ParcelFlags.AllowGroupScripts |
                (uint)ParcelFlags.AllowLandmark |
                (uint)ParcelFlags.AllowOtherScripts |
                (uint)ParcelFlags.AllowTerraform |
                (uint)ParcelFlags.AllowVoiceChat |
                (uint)ParcelFlags.CreateGroupObjects |
                (uint)ParcelFlags.CreateObjects |
                (uint)ParcelFlags.SoundLocal |
                (uint)ParcelFlags.UseEstateVoiceChan;

            parcel.OwnerID = ResolveUserUuid(parcel.OwnerID, Vector3.Zero, null);

            // reset to allow a clean start
            parcel.AuthBuyerID = UUID.Zero;
            parcel.Flags       = defaultFlags;

            // we need to check group ownership as well
            if (parcel.IsGroupOwned)
            {
                parcel.GroupID = ResolveGroupUuid(parcel.GroupID);
                if (parcel.GroupID == UUID.Zero)
                {
                    parcel.IsGroupOwned = false;
                }
            }
            else
            {
                parcel.GroupID = UUID.Zero;
            }

            // check the parcel access list in case..
            var parcelAccess = new List <ParcelManager.ParcelAccessEntry> ();

            foreach (var pal in parcel.ParcelAccessList)
            {
                var agentID = ResolveUserUuid(pal.AgentID, Vector3.Zero, null);
                if (agentID != estateOwnerId)
                {
                    parcelAccess.Add(pal);
                }
            }
            parcel.ParcelAccessList = parcelAccess;

            return(parcel);
        }
Example #4
0
        /// <summary>
        /// Load serialized parcels.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="serialisedParcels"></param>
        protected void LoadParcels(Scene scene, List<string> serialisedParcels)
        {
            // Reload serialized parcels
            m_log.InfoFormat("[ARCHIVER]: Loading {0} parcels.  Please wait.", serialisedParcels.Count);
            List<LandData> landData = new List<LandData>();
            foreach (string serialisedParcel in serialisedParcels)
            {
                LandData parcel = LandDataSerializer.Deserialize(serialisedParcel);
                
                // Validate User and Group UUID's

                if (parcel.IsGroupOwned)
                {
                    if (!ResolveGroupUuid(parcel.GroupID))
                    {
                        parcel.OwnerID = m_rootScene.RegionInfo.EstateSettings.EstateOwner;
                        parcel.GroupID = UUID.Zero;
                        parcel.IsGroupOwned = false;
                    }
                }
                else
                {
                    if (!ResolveUserUuid(scene, parcel.OwnerID))
                        parcel.OwnerID = m_rootScene.RegionInfo.EstateSettings.EstateOwner;

                    if (!ResolveGroupUuid(parcel.GroupID))
                        parcel.GroupID = UUID.Zero;
                }

                List<LandAccessEntry> accessList = new List<LandAccessEntry>();
                foreach (LandAccessEntry entry in parcel.ParcelAccessList)
                {
                    if (ResolveUserUuid(scene, entry.AgentID))
                        accessList.Add(entry);
                    // else, drop this access rule
                }
                parcel.ParcelAccessList = accessList;

//                m_log.DebugFormat(
//                    "[ARCHIVER]: Adding parcel {0}, local id {1}, owner {2}, group {3}, isGroupOwned {4}, area {5}", 
//                    parcel.Name, parcel.LocalID, parcel.OwnerID, parcel.GroupID, parcel.IsGroupOwned, parcel.Area);
                
                landData.Add(parcel);
            }

            if (!m_merge)
            {
                bool setupDefaultParcel = (landData.Count == 0);
                scene.LandChannel.Clear(setupDefaultParcel);
            }
            
            scene.EventManager.TriggerIncomingLandDataFromStorage(landData);
            m_log.InfoFormat("[ARCHIVER]: Restored {0} parcels.", landData.Count);
        }
        public void TestLandDataDeserializeNoAccessLists()
        {
            TestHelpers.InMethod();
//            log4net.Config.XmlConfigurator.Configure();

            LandData ld = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerialized);

            Assert.That(ld != null, "Deserialize(string) returned null");
            Assert.That(ld.GlobalID == this.land.GlobalID, "Reified LandData.GlobalID != original LandData.GlobalID");
            Assert.That(ld.Name == this.land.Name, "Reified LandData.Name != original LandData.Name");
        }
Example #6
0
        public void TestLandDataSerializerDeserializeFromStringTest()
        {
            LandData reifiedLandData = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerialized);

            Assert.That(reifiedLandData != null, "Deserialize(string) returned null");
            Assert.That(reifiedLandData.GlobalID == this.land.GlobalID, "Reified LandData.GlobalID != original LandData.GlobalID");
            Assert.That(reifiedLandData.Name == this.land.Name, "Reified LandData.Name != original LandData.Name");

            LandData reifiedLandDataWithParcelAccessList = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerializedWithParcelAccessList);

            Assert.That(reifiedLandDataWithParcelAccessList != null, "Deserialize(string) returned null (pre-serialized with parcel access list)");
            Assert.That(reifiedLandDataWithParcelAccessList.GlobalID == this.landWithParcelAccessList.GlobalID, "Reified LandData.GlobalID != original LandData.GlobalID (pre-serialized with parcel access list)");
            Assert.That(reifiedLandDataWithParcelAccessList.Name == this.landWithParcelAccessList.Name, "Reified LandData.Name != original LandData.Name (pre-serialized with parcel access list)");
        }
        public void TestLandDataDeserializeWithAccessLists()
        {
            TestHelpers.InMethod();
            //            log4net.Config.XmlConfigurator.Configure();

            LandData ld = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerializedWithParcelAccessList);

            Assert.That(ld != null,
                        "Deserialize(string) returned null (pre-serialized with parcel access list)");
            Assert.That(ld.GlobalID == this.landWithParcelAccessList.GlobalID,
                        "Reified LandData.GlobalID != original LandData.GlobalID (pre-serialized with parcel access list)");
            Assert.That(ld.Name == this.landWithParcelAccessList.Name,
                        "Reified LandData.Name != original LandData.Name (pre-serialized with parcel access list)");
            Assert.That(ld.ParcelAccessList.Count, Is.EqualTo(2));
            Assert.That(ld.ParcelAccessList[0].AgentID, Is.EqualTo(UUID.Parse("62d65d45-c91a-4f77-862c-46557d978b6c")));
        }
Example #8
0
        private void DearchiveRegion0DotStar()
        {
            if (m_loadStream == null)
            {
                return;
            }
            int      successfulAssetRestores = 0;
            int      failedAssetRestores     = 0;
            string   filePath = "NONE";
            DateTime start    = DateTime.Now;

            TarArchiveReader archive = new TarArchiveReader(m_loadStream);

            if (!m_skipAssets)
            {
                m_threadpool = new AuroraThreadPool(new AuroraThreadPoolStartInfo()
                {
                    Threads  = 1,
                    priority =
                        System.Threading.ThreadPriority
                        .BelowNormal
                });
            }

            IBackupModule backup = m_scene.RequestModuleInterface <IBackupModule>();

            if (!m_merge)
            {
                DateTime before = DateTime.Now;
                MainConsole.Instance.Info("[ARCHIVER]: Clearing all existing scene objects");
                if (backup != null)
                {
                    backup.DeleteAllSceneObjects();
                }
                MainConsole.Instance.Info("[ARCHIVER]: Cleared all existing scene objects in " +
                                          (DateTime.Now - before).Minutes + ":" + (DateTime.Now - before).Seconds);
            }

            IScriptModule[] modules = m_scene.RequestModuleInterfaces <IScriptModule>();
            //Disable the script engine so that it doesn't load in the background and kill OAR loading
            foreach (IScriptModule module in modules)
            {
                module.Disabled = true;
            }
            //Disable backup for now as well
            if (backup != null)
            {
                backup.LoadingPrims = true;
            }

            IRegionSerialiserModule serialiser = m_scene.RequestModuleInterface <IRegionSerialiserModule>();
            int sceneObjectsLoadedCount        = 0;

            //We save the groups so that we can back them up later
            List <ISceneEntity> groupsToBackup = new List <ISceneEntity>();
            List <LandData>     landData       = new List <LandData>();

            // must save off some stuff until after assets have been saved and recieved new uuids
            // keeping these collection local because I am sure they will get large and garbage collection is better that way
            List <byte[]>           seneObjectGroups        = new List <byte[]>();
            Dictionary <UUID, UUID> assetBinaryChangeRecord = new Dictionary <UUID, UUID>();
            Queue <UUID>            assets2Save             = new Queue <UUID>();

            try
            {
                byte[] data;
                TarArchiveReader.TarEntryType entryType;
                while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
                {
                    if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
                    {
                        continue;
                    }

                    if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH))
                    {
                        seneObjectGroups.Add(data);
                    }
                    else if (!m_skipAssets && filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
                    {
                        AssetBase asset;
                        if (LoadAsset(filePath, data, out asset))
                        {
                            successfulAssetRestores++;
                            if (m_useAsync)
                            {
                                lock (AssetsToAdd) AssetsToAdd.Add(asset);
                            }
                            else
                            {
                                if (asset.IsBinaryAsset)
                                {
                                    UUID aid = asset.ID;
                                    asset.ID = m_scene.AssetService.Store(asset);
                                    if (asset.ID != aid && asset.ID != UUID.Zero)
                                    {
                                        assetBinaryChangeRecord.Add(aid, asset.ID);
                                    }
                                }
                                else
                                {
                                    if (!assetNonBinaryCollection.ContainsKey(asset.ID))
                                    {
                                        assetNonBinaryCollection.Add(asset.ID, asset);
                                        // I need something I can safely loop through
                                        assets2Save.Enqueue(asset.ID);
                                    }
                                }
                            }
                        }
                        else
                        {
                            failedAssetRestores++;
                        }

                        if ((successfulAssetRestores + failedAssetRestores) % 250 == 0)
                        {
                            MainConsole.Instance.Info("[ARCHIVER]: Loaded " + successfulAssetRestores +
                                                      " assets and failed to load " + failedAssetRestores + " assets...");
                        }
                    }
                    else if (filePath.StartsWith(ArchiveConstants.TERRAINS_PATH))
                    {
                        LoadTerrain(filePath, data);
                    }
                    else if (!m_merge && filePath.StartsWith(ArchiveConstants.SETTINGS_PATH))
                    {
                        LoadRegionSettings(filePath, data);
                    }
                    else if (filePath.StartsWith(ArchiveConstants.LANDDATA_PATH))
                    {
                        LandData parcel = LandDataSerializer.Deserialize(m_utf8Encoding.GetString(data));
                        parcel.OwnerID = ResolveUserUuid(parcel.OwnerID, UUID.Zero, "", Vector3.Zero, null);
                        landData.Add(parcel);
                    }
                    else if (filePath == ArchiveConstants.CONTROL_FILE_PATH)
                    {
                        LoadControlFile(data);
                    }
                }
                // Save Assets
                int savingAssetsCount = 0;
                while (assets2Save.Count > 0)
                {
                    try
                    {
                        UUID assetid = assets2Save.Dequeue();
                        SaveNonBinaryAssets(assetid, assetNonBinaryCollection[assetid], assetBinaryChangeRecord);
                        savingAssetsCount++;
                        if ((savingAssetsCount) % 250 == 0)
                        {
                            MainConsole.Instance.Info("[ARCHIVER]: Saving " + savingAssetsCount + " assets...");
                        }
                    }
                    catch (Exception ex)
                    {
                        MainConsole.Instance.Info("[ARCHIVER]: Exception in saving an asset: " + ex.ToString());
                    }
                }

                foreach (byte[] data2 in seneObjectGroups)
                {
                    byte[] data3 = data2;

                    string          stringData = Utils.BytesToString(data3);
                    MatchCollection mc         = Regex.Matches(stringData, sPattern);
                    bool            didChange  = false;
                    if (mc.Count >= 1)
                    {
                        foreach (Match match in mc)
                        {
                            UUID thematch = new UUID(match.Value);
                            UUID newvalue = thematch;
                            if (assetNonBinaryCollection.ContainsKey(thematch))
                            {
                                newvalue = assetNonBinaryCollection[thematch].ID;
                            }
                            else if (assetBinaryChangeRecord.ContainsKey(thematch))
                            {
                                newvalue = assetBinaryChangeRecord[thematch];
                            }
                            if (thematch == newvalue)
                            {
                                continue;
                            }
                            stringData = stringData.Replace(thematch.ToString().Trim(), newvalue.ToString().Trim());
                            didChange  = true;
                        }
                    }
                    if (didChange)
                    {
                        data3 = Utils.StringToBytes(stringData);
                    }

                    ISceneEntity sceneObject = serialiser.DeserializeGroupFromXml2(data3, m_scene);

                    if (sceneObject == null)
                    {
                        //! big error!
                        MainConsole.Instance.Error("Error reading SOP XML (Please mantis this!): " +
                                                   m_asciiEncoding.GetString(data3));
                        continue;
                    }

                    foreach (ISceneChildEntity part in sceneObject.ChildrenEntities())
                    {
                        if (string.IsNullOrEmpty(part.CreatorData))
                        {
                            part.CreatorID = ResolveUserUuid(part.CreatorID, part.CreatorID, part.CreatorData,
                                                             part.AbsolutePosition, landData);
                        }

                        part.OwnerID = ResolveUserUuid(part.OwnerID, part.CreatorID, part.CreatorData,
                                                       part.AbsolutePosition, landData);

                        part.LastOwnerID = ResolveUserUuid(part.LastOwnerID, part.CreatorID, part.CreatorData,
                                                           part.AbsolutePosition, landData);

                        // And zap any troublesome sit target information
                        part.SitTargetOrientation = new Quaternion(0, 0, 0, 1);
                        part.SitTargetPosition    = new Vector3(0, 0, 0);

                        // Fix ownership/creator of inventory items
                        // Not doing so results in inventory items
                        // being no copy/no mod for everyone
                        lock (part.TaskInventory)
                        {
                            TaskInventoryDictionary inv = part.TaskInventory;
                            foreach (KeyValuePair <UUID, TaskInventoryItem> kvp in inv)
                            {
                                kvp.Value.OwnerID = ResolveUserUuid(kvp.Value.OwnerID, kvp.Value.CreatorID,
                                                                    kvp.Value.CreatorData, part.AbsolutePosition,
                                                                    landData);
                                if (string.IsNullOrEmpty(kvp.Value.CreatorData))
                                {
                                    kvp.Value.CreatorID = ResolveUserUuid(kvp.Value.CreatorID, kvp.Value.CreatorID,
                                                                          kvp.Value.CreatorData, part.AbsolutePosition,
                                                                          landData);
                                }
                            }
                        }
                    }

                    //Add the offsets of the region
                    Vector3 newPos = new Vector3(sceneObject.AbsolutePosition.X + m_offsetX,
                                                 sceneObject.AbsolutePosition.Y + m_offsetY,
                                                 sceneObject.AbsolutePosition.Z + m_offsetZ);
                    if (m_flipX)
                    {
                        newPos.X = m_scene.RegionInfo.RegionSizeX - newPos.X;
                    }
                    if (m_flipY)
                    {
                        newPos.Y = m_scene.RegionInfo.RegionSizeY - newPos.Y;
                    }
                    sceneObject.SetAbsolutePosition(false, newPos);

                    if (m_scene.SceneGraph.AddPrimToScene(sceneObject))
                    {
                        groupsToBackup.Add(sceneObject);
                        sceneObject.ScheduleGroupUpdate(PrimUpdateFlags.ForcedFullUpdate);
                        sceneObject.CreateScriptInstances(0, false, StateSource.RegionStart, UUID.Zero, true);
                    }
                    sceneObjectsLoadedCount++;
                    if (sceneObjectsLoadedCount % 250 == 0)
                    {
                        MainConsole.Instance.Info("[ARCHIVER]: Loaded " + sceneObjectsLoadedCount + " objects...");
                    }
                }
                assetNonBinaryCollection.Clear();
                assetBinaryChangeRecord.Clear();
                seneObjectGroups.Clear();
            }
            catch (Exception e)
            {
                MainConsole.Instance.ErrorFormat(
                    "[ARCHIVER]: Aborting load with error in archive file {0}.  {1}", filePath, e);
                m_errorMessage += e.ToString();
                m_scene.EventManager.TriggerOarFileLoaded(UUID.Zero.Guid, m_errorMessage);
                return;
            }
            finally
            {
                archive.Close();
                m_loadStream.Close();
                m_loadStream.Dispose();

                //Reeanble now that we are done
                foreach (IScriptModule module in modules)
                {
                    module.Disabled = false;
                }
                //Reset backup too
                if (backup != null)
                {
                    backup.LoadingPrims = false;
                }
            }

            //Now back up the prims
            foreach (ISceneEntity grp in groupsToBackup)
            {
                //Backup!
                grp.HasGroupChanged = true;
            }

            if (!m_skipAssets && m_useAsync && !AssetSaverIsRunning)
            {
                m_threadpool.QueueEvent(SaveAssets, 0);
            }

            if (!m_skipAssets)
            {
                MainConsole.Instance.InfoFormat("[ARCHIVER]: Restored {0} assets", successfulAssetRestores);

                if (failedAssetRestores > 0)
                {
                    MainConsole.Instance.ErrorFormat("[ARCHIVER]: Failed to load {0} assets", failedAssetRestores);
                    m_errorMessage += String.Format("Failed to load {0} assets", failedAssetRestores);
                }
            }

            // Try to retain the original creator/owner/lastowner if their uuid is present on this grid
            // otherwise, use the master avatar uuid instead

            // Reload serialized parcels
            MainConsole.Instance.InfoFormat("[ARCHIVER]: Loading {0} parcels.  Please wait.", landData.Count);

            IParcelManagementModule parcelManagementModule = m_scene.RequestModuleInterface <IParcelManagementModule>();

            if (parcelManagementModule != null)
            {
                parcelManagementModule.IncomingLandDataFromOAR(landData, m_merge, new Vector2(m_offsetX, m_offsetY));
            }

            MainConsole.Instance.InfoFormat("[ARCHIVER]: Restored {0} parcels.", landData.Count);

            //Clean it out
            landData.Clear();

            MainConsole.Instance.InfoFormat("[ARCHIVER]: Successfully loaded archive in " +
                                            (DateTime.Now - start).Minutes + ":" + (DateTime.Now - start).Seconds);

            m_validUserUuids.Clear();
            m_scene.EventManager.TriggerOarFileLoaded(UUID.Zero.Guid, m_errorMessage);
        }
Example #9
0
        private void DearchiveRegion0DotStar()
        {
            int           successfulAssetRestores = 0;
            int           failedAssetRestores     = 0;
            List <string> serialisedSceneObjects  = new List <string>();
            List <string> serialisedParcels       = new List <string>();
            string        filePath = "NONE";

            TarArchiveReader archive = new TarArchiveReader(m_loadStream);

            byte[] data;
            TarArchiveReader.TarEntryType entryType;

            try
            {
                while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
                {
                    //m_log.DebugFormat(
                    //    "[ARCHIVER]: Successfully read {0} ({1} bytes)", filePath, data.Length);

                    if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
                    {
                        continue;
                    }

                    if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH))
                    {
                        serialisedSceneObjects.Add(Encoding.UTF8.GetString(data));
                    }
                    else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH) && !m_skipAssets)
                    {
                        if (LoadAsset(filePath, data))
                        {
                            successfulAssetRestores++;
                        }
                        else
                        {
                            failedAssetRestores++;
                        }

                        if ((successfulAssetRestores + failedAssetRestores) % 250 == 0)
                        {
                            m_log.Debug("[ARCHIVER]: Loaded " + successfulAssetRestores + " assets and failed to load " + failedAssetRestores + " assets...");
                        }
                    }
                    else if (!m_merge && filePath.StartsWith(ArchiveConstants.TERRAINS_PATH))
                    {
                        LoadTerrain(filePath, data);
                    }
                    else if (!m_merge && filePath.StartsWith(ArchiveConstants.SETTINGS_PATH))
                    {
                        LoadRegionSettings(filePath, data);
                    }
                    else if (!m_merge && filePath.StartsWith(ArchiveConstants.LANDDATA_PATH))
                    {
                        serialisedParcels.Add(Encoding.UTF8.GetString(data));
                    }
                    else if (filePath == ArchiveConstants.CONTROL_FILE_PATH)
                    {
                        LoadControlFile(filePath, data);
                    }
                }

                //m_log.Debug("[ARCHIVER]: Reached end of archive");
            }
            catch (Exception e)
            {
                m_log.ErrorFormat(
                    "[ARCHIVER]: Aborting load with error in archive file {0}.  {1}", filePath, e);
                m_errorMessage += e.ToString();
                m_scene.EventManager.TriggerOarFileLoaded(m_requestId, m_errorMessage);
                return;
            }
            finally
            {
                archive.Close();
            }

            if (!m_skipAssets)
            {
                m_log.InfoFormat("[ARCHIVER]: Restored {0} assets", successfulAssetRestores);

                if (failedAssetRestores > 0)
                {
                    m_log.ErrorFormat("[ARCHIVER]: Failed to load {0} assets", failedAssetRestores);
                    m_errorMessage += String.Format("Failed to load {0} assets", failedAssetRestores);
                }
            }

            if (!m_merge)
            {
                m_log.Info("[ARCHIVER]: Clearing all existing scene objects");
                m_scene.DeleteAllSceneObjects();
            }

            // Try to retain the original creator/owner/lastowner if their uuid is present on this grid
            // otherwise, use the master avatar uuid instead

            // Reload serialized parcels
            m_log.InfoFormat("[ARCHIVER]: Loading {0} parcels.  Please wait.", serialisedParcels.Count);
            List <LandData> landData = new List <LandData>();

            foreach (string serialisedParcel in serialisedParcels)
            {
                LandData parcel = LandDataSerializer.Deserialize(serialisedParcel);
                if (!ResolveUserUuid(parcel.OwnerID))
                {
                    parcel.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
                }
                landData.Add(parcel);
            }
            m_scene.EventManager.TriggerIncomingLandDataFromStorage(landData);
            m_log.InfoFormat("[ARCHIVER]: Restored {0} parcels.", landData.Count);

            // Reload serialized prims
            m_log.InfoFormat("[ARCHIVER]: Loading {0} scene objects.  Please wait.", serialisedSceneObjects.Count);

            IRegionSerialiserModule serialiser = m_scene.RequestModuleInterface <IRegionSerialiserModule>();
            int sceneObjectsLoadedCount        = 0;

            foreach (string serialisedSceneObject in serialisedSceneObjects)
            {
                /*
                 * m_log.DebugFormat("[ARCHIVER]: Loading xml with raw size {0}", serialisedSceneObject.Length);
                 *
                 * // Really large xml files (multi megabyte) appear to cause
                 * // memory problems
                 * // when loading the xml.  But don't enable this check yet
                 *
                 * if (serialisedSceneObject.Length > 5000000)
                 * {
                 *  m_log.Error("[ARCHIVER]: Ignoring xml since size > 5000000);");
                 *  continue;
                 * }
                 */

                SceneObjectGroup sceneObject = serialiser.DeserializeGroupFromXml2(serialisedSceneObject);

                // For now, give all incoming scene objects new uuids.  This will allow scenes to be cloned
                // on the same region server and multiple examples a single object archive to be imported
                // to the same scene (when this is possible).
                sceneObject.ResetIDs();

                foreach (SceneObjectPart part in sceneObject.Children.Values)
                {
                    if (!ResolveUserUuid(part.CreatorID))
                    {
                        part.CreatorID = m_scene.RegionInfo.EstateSettings.EstateOwner;
                    }

                    if (!ResolveUserUuid(part.OwnerID))
                    {
                        part.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
                    }

                    if (!ResolveUserUuid(part.LastOwnerID))
                    {
                        part.LastOwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
                    }

                    // And zap any troublesome sit target information
                    part.SitTargetOrientation = new Quaternion(0, 0, 0, 1);
                    part.SitTargetPosition    = new Vector3(0, 0, 0);

                    // Fix ownership/creator of inventory items
                    // Not doing so results in inventory items
                    // being no copy/no mod for everyone
                    lock (part.TaskInventory)
                    {
                        TaskInventoryDictionary inv = part.TaskInventory;
                        foreach (KeyValuePair <UUID, TaskInventoryItem> kvp in inv)
                        {
                            if (!ResolveUserUuid(kvp.Value.OwnerID))
                            {
                                kvp.Value.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
                            }
                            if (!ResolveUserUuid(kvp.Value.CreatorID))
                            {
                                kvp.Value.CreatorID = m_scene.RegionInfo.EstateSettings.EstateOwner;
                            }
                        }
                    }
                }

                if (m_scene.AddRestoredSceneObject(sceneObject, true, false))
                {
                    sceneObjectsLoadedCount++;
                    sceneObject.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, 0);
                    sceneObject.ResumeScripts();
                }
            }

            m_log.InfoFormat("[ARCHIVER]: Restored {0} scene objects to the scene", sceneObjectsLoadedCount);

            int ignoredObjects = serialisedSceneObjects.Count - sceneObjectsLoadedCount;

            if (ignoredObjects > 0)
            {
                m_log.WarnFormat("[ARCHIVER]: Ignored {0} scene objects that already existed in the scene", ignoredObjects);
            }

            m_log.InfoFormat("[ARCHIVER]: Successfully loaded archive");

            m_scene.EventManager.TriggerOarFileLoaded(m_requestId, m_errorMessage);
        }
Example #10
0
        private void DearchiveRegion0DotStar()
        {
            int successfulAssetRestores = 0;
            int failedAssetRestores     = 0;
            //List<string> serialisedSceneObjects = new List<string>();
            List <string> serialisedParcels = new List <string>();
            string        filePath          = "NONE";
            DateTime      start             = DateTime.Now;

            TarArchiveReader archive = new TarArchiveReader(m_loadStream);

            byte[] data;
            TarArchiveReader.TarEntryType entryType;

            if (!m_skipAssets)
            {
                m_threadpool = new Aurora.Framework.AuroraThreadPool(new Aurora.Framework.AuroraThreadPoolStartInfo()
                {
                    Threads  = 1,
                    priority = System.Threading.ThreadPriority.BelowNormal
                });
            }

            IBackupModule backup = m_scene.RequestModuleInterface <IBackupModule>();

            if (!m_merge)
            {
                DateTime before = DateTime.Now;
                m_log.Info("[ARCHIVER]: Clearing all existing scene objects");
                if (backup != null)
                {
                    backup.DeleteAllSceneObjects();
                }
                m_log.Info("[ARCHIVER]: Cleared all existing scene objects in " + (DateTime.Now - before).Minutes + ":" + (DateTime.Now - before).Seconds);
            }

            IScriptModule[] modules = m_scene.RequestModuleInterfaces <IScriptModule>();
            //Disable the script engine so that it doesn't load in the background and kill OAR loading
            foreach (IScriptModule module in modules)
            {
                module.Disabled = true;
            }
            //Disable backup for now as well
            if (backup != null)
            {
                backup.LoadingPrims = true;
            }

            IRegionSerialiserModule serialiser = m_scene.RequestModuleInterface <IRegionSerialiserModule>();
            int sceneObjectsLoadedCount        = 0;

            //We save the groups so that we can back them up later
            List <SceneObjectGroup> groupsToBackup = new List <SceneObjectGroup>();

            try
            {
                while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
                {
                    //m_log.DebugFormat(
                    //    "[ARCHIVER]: Successfully read {0} ({1} bytes)", filePath, data.Length);

                    if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
                    {
                        continue;
                    }

                    if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH))
                    {
                        string sogdata = m_utf8Encoding.GetString(data);
                        //serialisedSceneObjects.Add(m_utf8Encoding.GetString(data));

                        /*
                         * m_log.DebugFormat("[ARCHIVER]: Loading xml with raw size {0}", serialisedSceneObject.Length);
                         *
                         * // Really large xml files (multi megabyte) appear to cause
                         * // memory problems
                         * // when loading the xml.  But don't enable this check yet
                         *
                         * if (serialisedSceneObject.Length > 5000000)
                         * {
                         * m_log.Error("[ARCHIVER]: Ignoring xml since size > 5000000);");
                         * continue;
                         * }
                         */

                        string           serialisedSceneObject = sogdata;
                        SceneObjectGroup sceneObject           = (SceneObjectGroup)serialiser.DeserializeGroupFromXml2(serialisedSceneObject, m_scene);

                        if (sceneObject == null)
                        {
                            //! big error!
                            m_log.Error("Error reading SOP XML (Please mantis this!): " + serialisedSceneObject);
                            continue;
                        }

                        foreach (SceneObjectPart part in sceneObject.ChildrenList)
                        {
                            if (!ResolveUserUuid(part.CreatorID))
                            {
                                part.CreatorID = m_scene.RegionInfo.EstateSettings.EstateOwner;
                            }

                            if (!ResolveUserUuid(part.OwnerID))
                            {
                                part.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
                            }

                            if (!ResolveUserUuid(part.LastOwnerID))
                            {
                                part.LastOwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
                            }

                            // And zap any troublesome sit target information
                            part.SitTargetOrientation = new Quaternion(0, 0, 0, 1);
                            part.SitTargetPosition    = new Vector3(0, 0, 0);

                            // Fix ownership/creator of inventory items
                            // Not doing so results in inventory items
                            // being no copy/no mod for everyone
                            lock (part.TaskInventory)
                            {
                                TaskInventoryDictionary inv = part.TaskInventory;
                                foreach (KeyValuePair <UUID, TaskInventoryItem> kvp in inv)
                                {
                                    if (!ResolveUserUuid(kvp.Value.OwnerID))
                                    {
                                        kvp.Value.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
                                    }
                                    if (!ResolveUserUuid(kvp.Value.CreatorID))
                                    {
                                        kvp.Value.CreatorID = m_scene.RegionInfo.EstateSettings.EstateOwner;
                                    }
                                }
                            }
                        }

                        //Add the offsets of the region
                        Vector3 newPos = new Vector3(sceneObject.AbsolutePosition.X + m_offsetX,
                                                     sceneObject.AbsolutePosition.Y + m_offsetY,
                                                     sceneObject.AbsolutePosition.Z + m_offsetZ);
                        if (m_flipX)
                        {
                            newPos.X = m_scene.RegionInfo.RegionSizeX - newPos.X;
                        }
                        if (m_flipY)
                        {
                            newPos.Y = m_scene.RegionInfo.RegionSizeY - newPos.Y;
                        }
                        sceneObject.SetAbsolutePosition(false, newPos);

                        if (m_scene.SceneGraph.AddPrimToScene(sceneObject))
                        {
                            groupsToBackup.Add(sceneObject);
                            sceneObject.ScheduleGroupUpdate(PrimUpdateFlags.FullUpdate);
                            sceneObjectsLoadedCount++;
                            sceneObject.CreateScriptInstances(0, false, 0, UUID.Zero);
                            sceneObject.ResumeScripts();
                        }
                        sceneObjectsLoadedCount++;
                        if (sceneObjectsLoadedCount % 250 == 0)
                        {
                            m_log.Debug("[ARCHIVER]: Loaded " + sceneObjectsLoadedCount + " objects...");
                        }
                    }
                    else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
                    {
                        if (!m_skipAssets)
                        {
                            if (LoadAsset(filePath, data))
                            {
                                successfulAssetRestores++;
                            }
                            else
                            {
                                failedAssetRestores++;
                            }

                            if ((successfulAssetRestores + failedAssetRestores) % 250 == 0)
                            {
                                m_log.Debug("[ARCHIVER]: Loaded " + successfulAssetRestores + " assets and failed to load " + failedAssetRestores + " assets...");
                            }
                        }
                    }
                    else if (!m_merge && filePath.StartsWith(ArchiveConstants.TERRAINS_PATH))
                    {
                        LoadTerrain(filePath, data);
                    }
                    else if (!m_merge && filePath.StartsWith(ArchiveConstants.SETTINGS_PATH))
                    {
                        LoadRegionSettings(filePath, data);
                    }
                    else if (!m_merge && filePath.StartsWith(ArchiveConstants.LANDDATA_PATH))
                    {
                        serialisedParcels.Add(m_utf8Encoding.GetString(data));
                    }
                    else if (filePath == ArchiveConstants.CONTROL_FILE_PATH)
                    {
                        LoadControlFile(filePath, data);
                    }
                    else
                    {
                        m_log.Debug("[ARCHIVER]:UNKNOWN PATH: " + filePath);
                    }
                }

                //m_log.Debug("[ARCHIVER]: Reached end of archive");
            }
            catch (Exception e)
            {
                m_log.ErrorFormat(
                    "[ARCHIVER]: Aborting load with error in archive file {0}.  {1}", filePath, e);
                m_errorMessage += e.ToString();
                m_scene.EventManager.TriggerOarFileLoaded(UUID.Zero.Guid, m_errorMessage);
                return;
            }
            finally
            {
                archive.Close();
                m_loadStream.Close();
                m_loadStream.Dispose();
            }
            //Reeanble now that we are done
            foreach (IScriptModule module in modules)
            {
                module.Disabled = false;
            }
            //Reset backup too
            if (backup != null)
            {
                backup.LoadingPrims = false;
            }

            //Now back up the prims
            foreach (SceneObjectGroup grp in groupsToBackup)
            {
                //Backup!
                grp.HasGroupChanged = true;
            }

            if (!m_skipAssets)
            {
                if (m_useAsync && !AssetSaverIsRunning)
                {
                    m_threadpool.QueueEvent(SaveAssets, 0);
                }
                else if (!AssetSaverIsRunning)
                {
                    SaveAssets();
                }
            }

            if (!m_skipAssets)
            {
                m_log.InfoFormat("[ARCHIVER]: Restored {0} assets", successfulAssetRestores);

                if (failedAssetRestores > 0)
                {
                    m_log.ErrorFormat("[ARCHIVER]: Failed to load {0} assets", failedAssetRestores);
                    m_errorMessage += String.Format("Failed to load {0} assets", failedAssetRestores);
                }
            }

            // Try to retain the original creator/owner/lastowner if their uuid is present on this grid
            // otherwise, use the master avatar uuid instead

            // Reload serialized parcels
            m_log.InfoFormat("[ARCHIVER]: Loading {0} parcels.  Please wait.", serialisedParcels.Count);
            List <LandData> landData = new List <LandData>();

            foreach (string serialisedParcel in serialisedParcels)
            {
                LandData parcel = LandDataSerializer.Deserialize(serialisedParcel);
                if (!ResolveUserUuid(parcel.OwnerID))
                {
                    parcel.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
                }
                landData.Add(parcel);
            }
            m_scene.EventManager.TriggerIncomingLandDataFromStorage(landData);
            //Update the database as well!
            IParcelManagementModule parcelManagementModule = m_scene.RequestModuleInterface <IParcelManagementModule>();

            if (parcelManagementModule != null)
            {
                foreach (LandData parcel in landData)
                {
                    parcelManagementModule.UpdateLandObject(parcel.LocalID, parcel);
                }
            }

            m_log.InfoFormat("[ARCHIVER]: Restored {0} parcels.", landData.Count);

            //Clean it out
            landData.Clear();
            serialisedParcels.Clear();

            m_log.InfoFormat("[ARCHIVER]: Successfully loaded archive in " + (DateTime.Now - start).Minutes + ":" + (DateTime.Now - start).Seconds);

            m_validUserUuids.Clear();
            m_scene.EventManager.TriggerOarFileLoaded(UUID.Zero.Guid, m_errorMessage);
        }