Example #1
0
        public void FillFromXml(XmlTextReader reader, UGUI currentOwner, XmlDeserializationOptions options)
        {
            var part = new ObjectPart
            {
                Owner = currentOwner
            };

            if (reader.IsEmptyElement)
            {
                throw new InvalidObjectXmlException();
            }

            for (; ;)
            {
                if (!reader.Read())
                {
                    throw new InvalidObjectXmlException();
                }

                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    if (reader.IsEmptyElement)
                    {
                        break;
                    }
                    switch (reader.Name)
                    {
                    case "TaskInventoryItem":
                        UUID origid;
                        ObjectPartInventoryItem item = FromXML(reader, currentOwner, options, out origid);
                        if (ContainsKey(item.ID))
                        {
                            /* skip duplicate ids. There seems to be at least one OpenSim version generating bogus task inventory */
                            break;
                        }
                        try
                        {
                            Add(item, true);
                        }
                        catch
                        {
                            throw new InvalidObjectXmlException(string.Format("Duplicate task inventory name {0} ({1})", item.Name, origid));
                        }
                        break;

                    default:
                        reader.ReadToEndElement();
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (reader.Name != "TaskInventory")
                    {
                        throw new InvalidObjectXmlException();
                    }
                    return;

                default:
                    break;
                }
            }
        }
        public static void Load(
            SceneList scenes,
            SceneInterface scene,
            LoadOptions options,
            Stream inputFile,
            TTY io = null)
        {
            var currentLoadState = CurrentOarLoadState.Unknown;

            using (var gzipStream = new GZipStream(inputFile, CompressionMode.Decompress))
            {
                using (var reader = new TarArchiveReader(gzipStream))
                {
                    var baseLoc = new GridVector(0, 0);
                    if (scene != null)
                    {
                        baseLoc = scene.GridPosition;
                    }

                    var  regionSize     = new GridVector(256, 256);
                    var  regionMapping  = new Dictionary <string, ArchiveXmlLoader.RegionInfo>();
                    var  regionInfos    = new List <ArchiveXmlLoader.RegionInfo>();
                    bool parcelsCleared = false;
                    var  load_sogs      = new List <ObjectGroup>();

                    for (; ;)
                    {
                        TarArchiveReader.Header header;
                        try
                        {
                            header = reader.ReadHeader();
                        }
                        catch (TarArchiveReader.EndOfTarException)
                        {
                            if ((options & LoadOptions.Merge) == 0 && scene != null)
                            {
                                scene.ClearObjects();
                            }

                            AddObjects(scene, load_sogs, options);
                            return;
                        }

                        if (header.FileType == TarFileType.File)
                        {
                            if (header.FileName == "archive.xml")
                            {
                                ArchiveXmlLoader.RegionInfo rinfo = ArchiveXmlLoader.LoadArchiveXml(new ObjectXmlStreamFilter(reader), regionInfos);

                                regionSize = rinfo.RegionSize;
                                foreach (ArchiveXmlLoader.RegionInfo reginfo in regionInfos)
                                {
                                    regionMapping.Add(reginfo.Path, reginfo);
                                }
                                if (regionInfos.Count != 0 && scene != null)
                                {
                                    throw new MultiRegionOARLoadingTriedOnRegionException();
                                }
                                else if (regionInfos.Count == 0 && scene == null)
                                {
                                    throw new OARLoadingTriedWithoutSelectedRegionException();
                                }
                            }
                            else if (header.FileName.StartsWith("assets/"))
                            {
                                if ((options & LoadOptions.NoAssets) == 0)
                                {
                                    ShowOarLoadState(ref currentLoadState, CurrentOarLoadState.Assets, io);
                                    /* Load asset */
                                    AssetData ad = reader.LoadAsset(header, scene.Owner);
                                    if (!scene.AssetService.Exists(ad.ID))
                                    {
                                        scene.AssetService.Store(ad);
                                    }
                                }
                            }
                            else
                            {
                                if (header.FileName.StartsWith("regions/"))
                                {
                                    ShowOarLoadState(ref currentLoadState, CurrentOarLoadState.Region, io);
                                    if ((options & LoadOptions.Merge) == 0 && scene != null)
                                    {
                                        scene.ClearObjects();
                                    }

                                    if (scene != null)
                                    {
                                        AddObjects(scene, load_sogs, options);
                                    }

                                    string[] pcomps = header.FileName.Split(new char[] { '/' }, 3);
                                    if (pcomps.Length < 3)
                                    {
                                        throw new OARFormatException();
                                    }
                                    string regionname = pcomps[1];
                                    header.FileName = pcomps[2];
                                    regionSize      = regionMapping[regionname].RegionSize;
                                    scene           = scenes[regionMapping[regionname].ID];
                                    parcelsCleared  = false;
                                }

                                if (header.FileName.StartsWith("objects/"))
                                {
                                    ShowOarLoadState(ref currentLoadState, CurrentOarLoadState.Objects, io);
                                    /* Load objects */
                                    List <ObjectGroup>        sogs;
                                    XmlDeserializationOptions xmloptions = XmlDeserializationOptions.ReadKeyframeMotion;
                                    if ((options & LoadOptions.PersistUuids) != 0)
                                    {
                                        xmloptions |= XmlDeserializationOptions.RestoreIDs;
                                    }
                                    try
                                    {
                                        sogs = ObjectXML.FromXml(reader, scene.Owner, xmloptions);
                                    }
                                    catch (Exception e)
                                    {
                                        throw new OARLoadingErrorException("Failed to load sog " + header.FileName, e);
                                    }

                                    foreach (ObjectGroup sog in sogs)
                                    {
                                        if (sog.Owner.ID == UUID.Zero)
                                        {
                                            sog.Owner = scene.Owner;
                                        }
                                    }
                                    load_sogs.AddRange(sogs);
                                }
                                else if (header.FileName.StartsWith("terrains/"))
                                {
                                    ShowOarLoadState(ref currentLoadState, CurrentOarLoadState.Terrain, io);
                                    /* Load terrains */
                                    if ((options & LoadOptions.Merge) == 0)
                                    {
                                        scene.Terrain.AllPatches = TerrainLoader.LoadStream(reader, (int)regionSize.X, (int)regionSize.Y);
                                        scene.StoreTerrainAsDefault();
                                    }
                                }
                                else if (header.FileName.StartsWith("landdata/"))
                                {
                                    ShowOarLoadState(ref currentLoadState, CurrentOarLoadState.Parcels, io);
                                    /* Load landdata */
                                    if ((options & LoadOptions.Merge) == 0)
                                    {
                                        if (!parcelsCleared)
                                        {
                                            scene.ClearParcels();
                                            parcelsCleared = true;
                                        }
                                        var        whiteList = new List <ParcelAccessEntry>();
                                        var        blackList = new List <ParcelAccessEntry>();
                                        ParcelInfo pinfo     = ParcelLoader.GetParcelInfo(new ObjectXmlStreamFilter(reader), regionSize, whiteList, blackList);
                                        if (pinfo.Owner.ID == UUID.Zero)
                                        {
                                            pinfo.Owner = scene.Owner;
                                        }
                                        if ((options & LoadOptions.PersistUuids) == LoadOptions.PersistUuids)
                                        {
                                            ParcelInfo check;
                                            if (scene.Parcels.TryGetValue(pinfo.ID, out check))
                                            {
                                                pinfo.ID = UUID.Random;
                                            }
                                        }
                                        else
                                        {
                                            pinfo.ID = UUID.Random;
                                        }
                                        scene.AddParcel(pinfo);
                                        scene.Parcels.WhiteList.Remove(scene.ID, pinfo.ID);
                                        scene.Parcels.BlackList.Remove(scene.ID, pinfo.ID);
                                        foreach (ParcelAccessEntry pae in whiteList)
                                        {
                                            scene.Parcels.WhiteList.Store(pae);
                                        }
                                        foreach (ParcelAccessEntry pae in blackList)
                                        {
                                            scene.Parcels.BlackList.Store(pae);
                                        }
                                    }
                                }
                                else if (header.FileName.StartsWith("settings/") && ((options & LoadOptions.Merge) == 0))
                                {
                                    ShowOarLoadState(ref currentLoadState, CurrentOarLoadState.Parcels, io);
                                    /* Load settings */
                                    RegionSettingsLoader.LoadRegionSettings(new ObjectXmlStreamFilter(reader), scene);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        public static ObjectGroup FromXml(XmlTextReader reader, UGUI currentOwner, bool inRootPart = false, XmlDeserializationOptions options = XmlDeserializationOptions.None)
        {
            var        group    = new ObjectGroup();
            ObjectPart rootPart = null;

            if (reader.IsEmptyElement)
            {
                throw new InvalidObjectXmlException();
            }

            for (; ;)
            {
                if (inRootPart)
                {
                    inRootPart = false;
                }
                else if (!reader.Read())
                {
                    throw new InvalidObjectXmlException();
                }

                bool   isEmptyElement = reader.IsEmptyElement;
                string nodeName       = reader.Name;
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (nodeName)
                    {
                    case "RootPart":
                        if (isEmptyElement)
                        {
                            throw new InvalidObjectXmlException();
                        }
                        if (rootPart != null)
                        {
                            throw new InvalidObjectXmlException();
                        }
                        rootPart = ParseRootPart(reader, group, currentOwner, options);
                        break;

                    case "SceneObjectPart":
                        if (rootPart != null)
                        {
                            throw new InvalidObjectXmlException();
                        }
                        if (isEmptyElement)
                        {
                            throw new InvalidObjectXmlException();
                        }
                        if (rootPart != null)
                        {
                            throw new InvalidObjectXmlException();
                        }
                        rootPart = ObjectPart.FromXml(reader, group, currentOwner, options);
                        group.Add(LINK_ROOT, rootPart.ID, rootPart);
                        break;

                    case "OtherParts":
                        if (isEmptyElement)
                        {
                            break;
                        }
                        FromXmlOtherParts(reader, group, currentOwner, options);
                        break;

                    case "GroupScriptStates":
                        if (isEmptyElement)
                        {
                            break;
                        }
                        FromXmlGroupScriptStates(reader, group);
                        break;

                    case "KeyframeMotion":
                        if (isEmptyElement)
                        {
                            break;
                        }
                        reader.ReadToEndElement();
                        break;

                    default:
                        reader.ReadToEndElement();
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (nodeName != "SceneObjectGroup")
                    {
                        throw new InvalidObjectXmlException();
                    }

                    foreach (ObjectPart part in group.Values)
                    {
                        part.Owner = currentOwner;
                        if ((options & XmlDeserializationOptions.RestoreIDs) == 0)
                        {
                            foreach (UUID key in part.Inventory.Keys1)
                            {
                                UUID newid = UUID.Random;
                                part.Inventory[key].SetNewID(newid);
                                part.Inventory.ChangeKey(newid, key);
                            }
                        }
                    }
                    group.FinalizeObject();
                    return(group);

                default:
                    break;
                }
            }
        }
Example #4
0
        private ObjectPartInventoryItem FromXML(XmlTextReader reader, UGUI currentOwner, XmlDeserializationOptions options, out UUID origid)
        {
            origid = UUID.Zero;
            var item = new ObjectPartInventoryItem
            {
                Owner = currentOwner
            };
            var  grantinfo    = new ObjectPartInventoryItem.PermsGranterInfo();
            bool ownerChanged = false;

            for (; ;)
            {
                if (!reader.Read())
                {
                    throw new InvalidObjectXmlException();
                }

                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    if (reader.IsEmptyElement)
                    {
                        break;
                    }

                    switch (reader.Name)
                    {
                    case "CollisionFilter":
                        CollisionFilterFromXml(item, reader);
                        break;

                    case "AssetID":
                        item.AssetID = reader.ReadContentAsUUID();
                        break;

                    case "BasePermissions":
                        item.Permissions.Base = (InventoryPermissionsMask)reader.ReadElementValueAsUInt();
                        break;

                    case "CreationDate":
                        item.CreationDate = Date.UnixTimeToDateTime(reader.ReadElementValueAsULong());
                        break;

                    case "CreatorID":
                        item.Creator.ID = reader.ReadContentAsUUID();
                        break;

                    case "CreatorData":
                        try
                        {
                            item.Creator.CreatorData = reader.ReadElementValueAsString();
                        }
                        catch (UriFormatException)
                        {
                            /* ignore this if it fails */
                        }
                        break;

                    case "Description":
                        item.Description = reader.ReadElementValueAsString();
                        break;

                    case "EveryonePermissions":
                        item.Permissions.EveryOne = (InventoryPermissionsMask)reader.ReadElementValueAsUInt();
                        break;

                    case "Flags":
                        item.Flags = (InventoryFlags)reader.ReadElementValueAsUInt();
                        break;

                    case "GroupID":
                        item.Group.ID = reader.ReadContentAsUUID();
                        break;

                    case "GroupPermissions":
                        item.Permissions.Group = (InventoryPermissionsMask)reader.ReadElementValueAsUInt();
                        break;

                    case "InvType":
                        item.InventoryType = (InventoryType)reader.ReadElementValueAsInt();
                        break;

                    case "ItemID":
                        origid = reader.ReadContentAsUUID();
                        item.SetNewID(origid);
                        break;

                    case "LastOwnerID":
                        item.LastOwner.ID = reader.ReadContentAsUUID();
                        break;

                    case "Name":
                        item.Name = reader.ReadElementValueAsString();
                        break;

                    case "NextPermissions":
                        item.Permissions.NextOwner = (InventoryPermissionsMask)reader.ReadElementValueAsUInt();
                        break;

                    case "CurrentPermissions":
                        item.Permissions.Current = (InventoryPermissionsMask)reader.ReadElementValueAsUInt();
                        break;

                    case "PermsGranter":
                        grantinfo.PermsGranter.ID = reader.ReadContentAsUUID();
                        break;

                    case "PermsMask":
                        grantinfo.PermsMask = (ScriptPermissions)reader.ReadElementValueAsUInt();
                        break;

                    case "Type":
                        item.AssetType = (AssetType)reader.ReadElementValueAsInt();
                        break;

                    case "OwnerChanged":
                        ownerChanged = reader.ReadElementValueAsBoolean();
                        break;

                    case "ExperienceID":
                        item.ExperienceID = new UEI(reader.ReadContentAsString());
                        break;

                    case "OwnerID":         /* Do not trust this ever! */
                    default:
                        reader.ReadToEndElement();
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (reader.Name != "TaskInventoryItem")
                    {
                        throw new InvalidObjectXmlException();
                    }
                    if (ownerChanged)
                    {
                        item.Owner = UGUI.Unknown;
                    }
                    return(item);

                default:
                    break;
                }
            }
        }
Example #5
0
        private static ObjectPart ParseRootPart(XmlTextReader reader, ObjectGroup group, UGUI currentOwner, XmlDeserializationOptions options)
        {
            ObjectPart rootPart = null;

            if (reader.IsEmptyElement)
            {
                throw new InvalidObjectXmlException();
            }
            for (; ;)
            {
                if (!reader.Read())
                {
                    throw new InvalidObjectXmlException();
                }

                string nodeName       = reader.Name;
                bool   isEmptyElement = reader.IsEmptyElement;

                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (nodeName)
                    {
                    case "SceneObjectPart":
                        if (rootPart != null)
                        {
                            throw new InvalidObjectXmlException();
                        }
                        if (isEmptyElement)
                        {
                            throw new InvalidObjectXmlException();
                        }
                        if (rootPart != null)
                        {
                            throw new InvalidObjectXmlException();
                        }
                        rootPart = ObjectPart.FromXml(reader, group, currentOwner, options);
                        group.Add(LINK_ROOT, rootPart.ID, rootPart);
                        break;

                    default:
                        reader.ReadToEndElement();
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (nodeName != "RootPart")
                    {
                        throw new InvalidObjectXmlException();
                    }
                    return(rootPart);

                default:
                    break;
                }
            }
        }
Example #6
0
 public static ObjectGroup FromXml(XmlTextReader reader, UGUI currentOwner, XmlDeserializationOptions options) =>
 FromXml(reader, currentOwner, inRootPart: false, options: options);
Example #7
0
        public static List <ObjectGroup> FromAsset(AssetData data, UGUI currentOwner, XmlDeserializationOptions options = XmlDeserializationOptions.None)
        {
            if (data.Type != AssetType.Object)
            {
                throw new InvalidObjectXmlException();
            }

            using (var xmlstream = data.InputStream)
            {
                List <ObjectGroup> grps = FromXml(xmlstream, currentOwner, options);
                foreach (ObjectGroup grp in grps)
                {
                    grp.OriginalAssetID = data.ID;
                }
                return(grps);
            }
        }
Example #8
0
        private static void FromXmlOtherParts(XmlTextReader reader, ObjectGroup group, UGUI currentOwner, XmlDeserializationOptions options)
        {
            ObjectPart part;
            var        links = new SortedDictionary <int, ObjectPart>();

            if (reader.IsEmptyElement)
            {
                throw new InvalidObjectXmlException();
            }

            for (; ;)
            {
                if (!reader.Read())
                {
                    throw new InvalidObjectXmlException();
                }

                bool   isEmptyElement = reader.IsEmptyElement;
                string nodeName       = reader.Name;

                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (nodeName)
                    {
                    case "Part":
                        if (isEmptyElement)
                        {
                            throw new InvalidObjectXmlException();
                        }
                        part = ParseOtherPart(reader, group, currentOwner, options);
                        links.Add(part.LoadedLinkNumber, part);
                        break;

                    case "SceneObjectPart":
                        if (isEmptyElement)
                        {
                            throw new InvalidObjectXmlException();
                        }
                        part = ObjectPart.FromXml(reader, null, currentOwner, options);
                        try
                        {
                            part.LoadedLinkNumber = links.Count + 2;
                            links.Add(part.LoadedLinkNumber, part);
                        }
                        catch
                        {
                            throw new ObjectDeserializationFailedDueKeyException();
                        }
                        break;

                    default:
                        reader.ReadToEndElement();
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (nodeName != "OtherParts")
                    {
                        throw new InvalidObjectXmlException();
                    }
                    foreach (KeyValuePair <int, ObjectPart> kvp in links)
                    {
                        group.Add(kvp.Key, kvp.Value.ID, kvp.Value);
                    }
                    return;

                default:
                    break;
                }
            }
        }
Example #9
0
        private static ObjectGroup FromXmlSingleWithinCoalescedObject(XmlTextReader reader, UGUI currentOwner, XmlDeserializationOptions options = XmlDeserializationOptions.None)
        {
            ObjectGroup grp = null;

            for (; ;)
            {
                if (!reader.Read())
                {
                    throw new InvalidObjectXmlException();
                }

                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (reader.Name)
                    {
                    case "SceneObjectGroup":
                        if (reader.IsEmptyElement)
                        {
                            throw new InvalidObjectXmlException();
                        }
                        grp = ObjectGroup.FromXml(reader, currentOwner, options);
                        break;

                    case "RootPart":
                        /* XML format mess, two different serializations just for that */
                        return(ObjectGroup.FromXml(reader, currentOwner, true));

                    default:
                        reader.ReadToEndElement();
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (reader.Name != "SceneObjectGroup")
                    {
                        throw new InvalidObjectXmlException();
                    }
                    return(grp);

                default:
                    break;
                }
            }
        }
Example #10
0
        private static List <ObjectGroup> FromXmlCoalescedObject(XmlTextReader reader, UGUI currentOwner, XmlDeserializationOptions options = XmlDeserializationOptions.None)
        {
            var list = new List <ObjectGroup>();

            for (;;)
            {
                if (!reader.Read())
                {
                    throw new InvalidObjectXmlException();
                }

                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (reader.Name)
                    {
                    case "SceneObjectGroup":
                        if (reader.IsEmptyElement)
                        {
                            throw new InvalidObjectXmlException();
                        }
                        var sogpos = new Vector3();
                        if (reader.MoveToFirstAttribute())
                        {
                            do
                            {
                                switch (reader.Name)
                                {
                                case "offsetx":
                                    sogpos.X_String = reader.Value;
                                    break;

                                case "offsety":
                                    sogpos.Y_String = reader.Value;
                                    break;

                                case "offsetz":
                                    sogpos.Z_String = reader.Value;
                                    break;

                                default:
                                    break;
                                }
                            }while (reader.MoveToNextAttribute());
                        }
                        var grp = FromXmlSingleWithinCoalescedObject(reader, currentOwner, options);
                        grp.CoalescedRestoreOffset = sogpos;
                        list.Add(grp);
                        break;

                    default:
                        reader.ReadToEndElement();
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (reader.Name != "CoalescedObject")
                    {
                        throw new InvalidObjectXmlException();
                    }
                    return(list);

                default:
                    break;
                }
            }
        }
Example #11
0
 private static List <ObjectGroup> FromXmlSingleObject(XmlTextReader reader, UGUI currentOwner, XmlDeserializationOptions options = XmlDeserializationOptions.None) => new List <ObjectGroup>
 {
     ObjectGroup.FromXml(reader, currentOwner, options)
 };
Example #12
0
        private static List <ObjectGroup> FromXml(XmlTextReader reader, UGUI currentOwner, XmlDeserializationOptions options = XmlDeserializationOptions.None)
        {
            for (;;)
            {
                if (!reader.Read())
                {
                    throw new InvalidObjectXmlException();
                }

                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "SceneObjectGroup":
                        return(FromXmlSingleObject(reader, currentOwner, options));

                    case "CoalescedObject":
                        return(FromXmlCoalescedObject(reader, currentOwner, options));

                    default:
                        throw new InvalidObjectXmlException();
                    }
                }
            }
        }
Example #13
0
 public static List <ObjectGroup> FromXml(Stream xmlstream, UGUI currentOwner, XmlDeserializationOptions options = XmlDeserializationOptions.None)
 {
     using (XmlTextReader reader = new ObjectXmlStreamFilter(xmlstream).CreateXmlReader())
     {
         return(FromXml(reader, currentOwner, options));
     }
 }