예제 #1
0
        public static bool TryFromXml(string xml, out CoalescedSceneObjects coa)
        {
//            m_log.DebugFormat("[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() deserializing {0}", xml);

            coa = null;

            using (StringReader sr = new StringReader(xml))
            {
                using (XmlTextReader reader = new XmlTextReader(sr))
                {
                    try
                    {
                        reader.Read();
                        if (reader.Name != "CoalescedObject")
                        {
                            //                        m_log.DebugFormat(
                            //                            "[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() root element was {0} so returning false",
                            //                            reader.Name);

                            return(false);
                        }

                        coa = new CoalescedSceneObjects(UUID.Zero);
                        reader.Read();

                        while (reader.NodeType != XmlNodeType.EndElement && reader.Name != "CoalescedObject")
                        {
                            if (reader.Name == "SceneObjectGroup")
                            {
                                string soXml = reader.ReadOuterXml();
                                coa.Add(SceneObjectSerializer.FromOriginalXmlFormat(soXml));
                            }
                        }

                        reader.ReadEndElement(); // CoalescedObject
                    }
                    catch (Exception e)
                    {
                        m_log.ErrorFormat(
                            "[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of xml failed with {0} {1}",
                            e.Message, e.StackTrace);

                        return(false);
                    }
                }
            }

            return(true);
        }
        public static bool TryFromXmlData(byte[] data, out CoalescedSceneObjects coa)
        {
            // m_log.DebugFormat("[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() deserializing {0}", xml);

            coa = null;
            try
            {
                int len = data.Length;
                if (len < 32)
                {
                    return(false);
                }
                if (data[len - 1] == 0)
                {
                    --len;
                }
                // Quickly check if this is a coalesced object, without fully parsing the XML
                MemoryStream ms = new MemoryStream(data, 0, len, false);
                StreamReader sr = new StreamReader(ms, Encoding.UTF8);
                using (XmlTextReader reader = new XmlTextReader(sr))
                {
                    reader.MoveToContent(); // skip possible xml declaration

                    if (reader.Name != "CoalescedObject")
                    {
                        return(false);
                    }
                }

                XmlDocument doc = new XmlDocument();
                using (ms = new MemoryStream(data, 0, len, false))
                    doc.Load(ms);

                XmlElement e = (XmlElement)doc.SelectSingleNode("/CoalescedObject");
                if (e == null)
                {
                    return(false);
                }

                coa = new CoalescedSceneObjects(UUID.Zero);

                XmlNodeList groups = e.SelectNodes("SceneObjectGroup");
                int         i      = 0;

                foreach (XmlNode n in groups)
                {
                    SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(n.OuterXml);
                    if (so != null)
                    {
                        coa.Add(so);
                    }
                    else
                    {
                        // XXX: Possibly we should fail outright here rather than continuing if a particular component of the
                        // coalesced object fails to load.
                        m_log.WarnFormat(
                            "[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of xml for component {0} failed.  Continuing.",
                            i);
                    }

                    i++;
                }
            }
            catch (Exception e)
            {
                m_log.Error("[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of binary xml failed ", e);
                return(false);
            }

            return(true);
        }
        public static bool TryFromXml(string xml, out CoalescedSceneObjects coa)
        {
            //            m_log.DebugFormat("[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() deserializing {0}", xml);

            coa = null;

            try
            {
                // Quickly check if this is a coalesced object, without fully parsing the XML
                using (XmlTextReader reader = new XmlTextReader(new StringReader(xml)))
                {
                    reader.MoveToContent(); // skip possible xml declaration

                    if (reader.Name != "CoalescedObject")
                    {
                        // m_log.DebugFormat(
                        //     "[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() root element was {0} so returning false",
                        //     reader.Name);

                        return(false);
                    }
                }

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);
                XmlElement e = (XmlElement)doc.SelectSingleNode("/CoalescedObject");
                if (e == null)
                {
                    return(false);
                }

                coa = new CoalescedSceneObjects(UUID.Zero);

                XmlNodeList groups = e.SelectNodes("SceneObjectGroup");
                int         i      = 0;

                foreach (XmlNode n in groups)
                {
                    SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(n.OuterXml);
                    if (so != null)
                    {
                        coa.Add(so);
                    }
                    else
                    {
                        // XXX: Possibly we should fail outright here rather than continuing if a particular component of the
                        // coalesced object fails to load.
                        m_log.WarnFormat(
                            "[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of xml for component {0} failed.  Continuing.",
                            i);
                    }

                    i++;
                }
            }
            catch (Exception e)
            {
                m_log.Error("[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of xml failed ", e);
                Util.LogFailedXML("[COALESCED SCENE OBJECTS SERIALIZER]:", xml);
                return(false);
            }

            return(true);
        }
        public static bool TryFromXml(string xml, out CoalescedSceneObjects coa)
        {
//            m_log.DebugFormat("[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() deserializing {0}", xml);
            
            coa = null;
            
            try
            {
                // Quickly check if this is a coalesced object, without fully parsing the XML
                using (StringReader sr = new StringReader(xml))
                {                
                    using (XmlTextReader reader = new XmlTextReader(sr))
                    {
                        reader.MoveToContent(); // skip possible xml declaration

                        if (reader.Name != "CoalescedObject")
                        {
    //                        m_log.DebugFormat(
    //                            "[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() root element was {0} so returning false", 
    //                            reader.Name);
                            
                            return false;
                        }
                    }
                }

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);
                XmlElement e = (XmlElement)doc.SelectSingleNode("/CoalescedObject");
                if (e == null)
                    return false;
                        
                coa = new CoalescedSceneObjects(UUID.Zero);

                XmlNodeList groups = e.SelectNodes("SceneObjectGroup");
                int i = 0;
                
                foreach (XmlNode n in groups)
                {
                    SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(n.OuterXml);
                    if (so != null)
                    {
                        coa.Add(so);
                    }
                    else
                    {
                        // XXX: Possibly we should fail outright here rather than continuing if a particular component of the 
                        // coalesced object fails to load.
                        m_log.WarnFormat(
                            "[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of xml for component {0} failed.  Continuing.", 
                            i);
                    }

                    i++;
                }
            }
            catch (Exception e)
            {
                m_log.Error(string.Format(
                    "[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of xml failed with {0} ", 
                    e.Message), e);
                        
                return false;
            }                        
            
            return true;
        }
예제 #5
0
        /// <summary>
        /// Copy a bundle of objects to inventory.  If there is only one object, then this will create an object
        /// item.  If there are multiple objects then these will be saved as a single coalesced item.
        /// </summary>
        /// <param name="action"></param>
        /// <param name="folderID"></param>
        /// <param name="objlist"></param>
        /// <param name="remoteClient"></param>
        /// <returns></returns>
        protected UUID CopyBundleToInventory(
            DeRezAction action, UUID folderID, List <SceneObjectGroup> objlist, IClientAPI remoteClient)
        {
            UUID assetID = UUID.Zero;

            CoalescedSceneObjects      coa = new CoalescedSceneObjects(UUID.Zero);
            Dictionary <UUID, Vector3> originalPositions = new Dictionary <UUID, Vector3>();

            foreach (SceneObjectGroup objectGroup in objlist)
            {
                Vector3 inventoryStoredPosition = new Vector3
                                                      (((objectGroup.AbsolutePosition.X > (int)Constants.RegionSize)
                                  ? 250
                                  : objectGroup.AbsolutePosition.X)
                                                      ,
                                                      (objectGroup.AbsolutePosition.Y > (int)Constants.RegionSize)
                                 ? 250
                                 : objectGroup.AbsolutePosition.Y,
                                                      objectGroup.AbsolutePosition.Z);

                originalPositions[objectGroup.UUID] = objectGroup.AbsolutePosition;

                objectGroup.AbsolutePosition = inventoryStoredPosition;

                // Make sure all bits but the ones we want are clear
                // on take.
                // This will be applied to the current perms, so
                // it will do what we want.
                objectGroup.RootPart.NextOwnerMask &=
                    ((uint)PermissionMask.Copy |
                     (uint)PermissionMask.Transfer |
                     (uint)PermissionMask.Modify);
                objectGroup.RootPart.NextOwnerMask |=
                    (uint)PermissionMask.Move;

                coa.Add(objectGroup);
            }

            string itemXml;

            if (objlist.Count > 1)
            {
                itemXml = CoalescedSceneObjectsSerializer.ToXml(coa);
            }
            else
            {
                itemXml = SceneObjectSerializer.ToOriginalXmlFormat(objlist[0]);
            }

            // Restore the position of each group now that it has been stored to inventory.
            foreach (SceneObjectGroup objectGroup in objlist)
            {
                objectGroup.AbsolutePosition = originalPositions[objectGroup.UUID];
            }

            InventoryItemBase item = CreateItemForObject(action, remoteClient, objlist[0], folderID);

            if (item == null)
            {
                return(UUID.Zero);
            }

            // Can't know creator is the same, so null it in inventory
            if (objlist.Count > 1)
            {
                item.CreatorId = UUID.Zero.ToString();
                item.Flags     = (uint)InventoryItemFlags.ObjectHasMultipleItems;
            }
            else
            {
                item.CreatorId = objlist[0].RootPart.CreatorID.ToString();
                item.SaleType  = objlist[0].RootPart.ObjectSaleType;
                item.SalePrice = objlist[0].RootPart.SalePrice;
            }

            AssetBase asset = CreateAsset(
                objlist[0].GetPartName(objlist[0].RootPart.LocalId),
                objlist[0].GetPartDescription(objlist[0].RootPart.LocalId),
                (sbyte)AssetType.Object,
                Utils.StringToBytes(itemXml),
                objlist[0].OwnerID.ToString());

            m_Scene.AssetService.Store(asset);

            item.AssetID = asset.FullID;
            assetID      = asset.FullID;

            if (DeRezAction.SaveToExistingUserInventoryItem == action)
            {
                m_Scene.InventoryService.UpdateItem(item);
            }
            else
            {
                AddPermissions(item, objlist[0], objlist, remoteClient);

                item.CreationDate = Util.UnixTimeSinceEpoch();
                item.Description  = asset.Description;
                item.Name         = asset.Name;
                item.AssetType    = asset.Type;

                m_Scene.AddInventoryItem(item);

                if (remoteClient != null && item.Owner == remoteClient.AgentId)
                {
                    remoteClient.SendInventoryItemCreateUpdate(item, 0);
                }
                else
                {
                    ScenePresence notifyUser = m_Scene.GetScenePresence(item.Owner);
                    if (notifyUser != null)
                    {
                        notifyUser.ControllingClient.SendInventoryItemCreateUpdate(item, 0);
                    }
                }
            }

            // This is a hook to do some per-asset post-processing for subclasses that need that
            ExportAsset(remoteClient.AgentId, assetID);

            return(assetID);
        }
        public static bool TryFromXml(string xml, out CoalescedSceneObjects coa)
        {
//            m_log.DebugFormat("[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() deserializing {0}", xml);

            coa = null;
            int i = 0;

            using (StringReader sr = new StringReader(xml))
            {
                using (XmlTextReader reader = new XmlTextReader(sr))
                {
                    try
                    {
                        reader.Read();
                        if (reader.Name != "CoalescedObject")
                        {
                            //                        m_log.DebugFormat(
                            //                            "[COALESCED SCENE OBJECTS SERIALIZER]: TryFromXml() root element was {0} so returning false",
                            //                            reader.Name);

                            return(false);
                        }

                        coa = new CoalescedSceneObjects(UUID.Zero);
                        reader.Read();

                        while (reader.NodeType != XmlNodeType.EndElement && reader.Name != "CoalescedObject")
                        {
                            if (reader.Name == "SceneObjectGroup")
                            {
                                string soXml = reader.ReadOuterXml();

                                SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(soXml);

                                if (so != null)
                                {
                                    coa.Add(so);
                                }
                                else
                                {
                                    // XXX: Possibly we should fail outright here rather than continuing if a particular component of the
                                    // coalesced object fails to load.
                                    m_log.WarnFormat(
                                        "[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of xml for component {0} failed.  Continuing.",
                                        i);
                                }

                                i++;
                            }
                        }

                        reader.ReadEndElement(); // CoalescedObject
                    }
                    catch (Exception e)
                    {
                        m_log.ErrorFormat(
                            "[COALESCED SCENE OBJECTS SERIALIZER]: Deserialization of xml failed with {0} {1}",
                            e.Message, e.StackTrace);

                        return(false);
                    }
                }
            }

            return(true);
        }
예제 #7
0
        /// <summary>
        /// Copy a bundle of objects to inventory.  If there is only one object, then this will create an object
        /// item.  If there are multiple objects then these will be saved as a single coalesced item.
        /// </summary>
        /// <param name="action"></param>
        /// <param name="folderID"></param>
        /// <param name="objlist"></param>
        /// <param name="remoteClient"></param>
        /// <param name="asAttachment">Should be true if the bundle is being copied as an attachment.  This prevents
        /// attempted serialization of any script state which would abort any operating scripts.</param>
        /// <returns>The inventory item created by the copy</returns>
        protected InventoryItemBase CopyBundleToInventory(
            DeRezAction action, UUID folderID, List <SceneObjectGroup> objlist, IClientAPI remoteClient,
            bool asAttachment)
        {
            CoalescedSceneObjects coa = new CoalescedSceneObjects(UUID.Zero);
//            Dictionary<UUID, Vector3> originalPositions = new Dictionary<UUID, Vector3>();

            Dictionary <SceneObjectGroup, KeyframeMotion> group2Keyframe = new Dictionary <SceneObjectGroup, KeyframeMotion>();

            foreach (SceneObjectGroup objectGroup in objlist)
            {
                if (objectGroup.RootPart.KeyframeMotion != null)
                {
                    objectGroup.RootPart.KeyframeMotion.Pause();
                    group2Keyframe.Add(objectGroup, objectGroup.RootPart.KeyframeMotion);
                    objectGroup.RootPart.KeyframeMotion = null;
                }

//                Vector3 inventoryStoredPosition = new Vector3
//                            (((objectGroup.AbsolutePosition.X > (int)Constants.RegionSize)
//                                  ? 250
//                                  : objectGroup.AbsolutePosition.X)
//                             ,
//                             (objectGroup.AbsolutePosition.Y > (int)Constants.RegionSize)
//                                 ? 250
//                                 : objectGroup.AbsolutePosition.Y,
//                             objectGroup.AbsolutePosition.Z);
//
//                originalPositions[objectGroup.UUID] = objectGroup.AbsolutePosition;
//
//                objectGroup.AbsolutePosition = inventoryStoredPosition;

                // Make sure all bits but the ones we want are clear
                // on take.
                // This will be applied to the current perms, so
                // it will do what we want.
                objectGroup.RootPart.NextOwnerMask &=
                    ((uint)PermissionMask.Copy |
                     (uint)PermissionMask.Transfer |
                     (uint)PermissionMask.Modify |
                     (uint)PermissionMask.Export);
                objectGroup.RootPart.NextOwnerMask |=
                    (uint)PermissionMask.Move;

                coa.Add(objectGroup);
            }

            string itemXml;

            // If we're being called from a script, then trying to serialize that same script's state will not complete
            // in any reasonable time period.  Therefore, we'll avoid it.  The worst that can happen is that if
            // the client/server crashes rather than logging out normally, the attachment's scripts will resume
            // without state on relog.  Arguably, this is what we want anyway.
            if (objlist.Count > 1)
            {
                itemXml = CoalescedSceneObjectsSerializer.ToXml(coa, !asAttachment);
            }
            else
            {
                itemXml = SceneObjectSerializer.ToOriginalXmlFormat(objlist[0], !asAttachment);
            }

//            // Restore the position of each group now that it has been stored to inventory.
//            foreach (SceneObjectGroup objectGroup in objlist)
//                objectGroup.AbsolutePosition = originalPositions[objectGroup.UUID];

            InventoryItemBase item = CreateItemForObject(action, remoteClient, objlist[0], folderID);

//            m_log.DebugFormat(
//                "[INVENTORY ACCESS MODULE]: Created item is {0}",
//                item != null ? item.ID.ToString() : "NULL");

            if (item == null)
            {
                return(null);
            }

            item.CreatorId   = objlist[0].RootPart.CreatorID.ToString();
            item.CreatorData = objlist[0].RootPart.CreatorData;

            if (objlist.Count > 1)
            {
                item.Flags = (uint)InventoryItemFlags.ObjectHasMultipleItems;

                // If the objects have different creators then don't specify a creator at all
                foreach (SceneObjectGroup objectGroup in objlist)
                {
                    if ((objectGroup.RootPart.CreatorID.ToString() != item.CreatorId) ||
                        (objectGroup.RootPart.CreatorData.ToString() != item.CreatorData))
                    {
                        item.CreatorId   = UUID.Zero.ToString();
                        item.CreatorData = string.Empty;
                        break;
                    }
                }
            }
            else
            {
                item.SaleType  = objlist[0].RootPart.ObjectSaleType;
                item.SalePrice = objlist[0].RootPart.SalePrice;
            }

            AssetBase asset = CreateAsset(
                objlist[0].GetPartName(objlist[0].RootPart.LocalId),
                objlist[0].GetPartDescription(objlist[0].RootPart.LocalId),
                (sbyte)AssetType.Object,
                Utils.StringToBytes(itemXml),
                objlist[0].OwnerID.ToString());

            m_Scene.AssetService.Store(asset);

            item.AssetID = asset.FullID;

            if (DeRezAction.SaveToExistingUserInventoryItem == action)
            {
                m_Scene.InventoryService.UpdateItem(item);
            }
            else
            {
                item.CreationDate = Util.UnixTimeSinceEpoch();
                item.Description  = asset.Description;
                item.Name         = asset.Name;
                item.AssetType    = asset.Type;

                AddPermissions(item, objlist[0], objlist, remoteClient);

                m_Scene.AddInventoryItem(item);

                if (remoteClient != null && item.Owner == remoteClient.AgentId)
                {
                    remoteClient.SendInventoryItemCreateUpdate(item, 0);
                }
                else
                {
                    ScenePresence notifyUser = m_Scene.GetScenePresence(item.Owner);
                    if (notifyUser != null)
                    {
                        notifyUser.ControllingClient.SendInventoryItemCreateUpdate(item, 0);
                    }
                }
            }

            // Restore KeyframeMotion
            foreach (SceneObjectGroup objectGroup in group2Keyframe.Keys)
            {
                objectGroup.RootPart.KeyframeMotion = group2Keyframe[objectGroup];
                objectGroup.RootPart.KeyframeMotion.Start();
            }

            // This is a hook to do some per-asset post-processing for subclasses that need that
            if (remoteClient != null)
            {
                ExportAsset(remoteClient.AgentId, asset.FullID);
            }

            return(item);
        }