/OpenMetaverse/Modules/InventoryManager.cs
C# | 4807 lines | 3114 code | 580 blank | 1113 comment | 501 complexity | 3547c5ae30eec944425933a7545fecd0 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- /*
- * Copyright (c) 2006-2008, openmetaverse.org
- * All rights reserved.
- *
- * - Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * - Neither the name of the openmetaverse.org nor the names
- * of its contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
- using System;
- using System.Collections.Generic;
- using System.Net;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Text;
- using System.Runtime.Serialization;
- using OpenMetaverse.Http;
- using OpenMetaverse.Messages.Linden;
- using OpenMetaverse.StructuredData;
- using OpenMetaverse.Packets;
- namespace OpenMetaverse
- {
- #region Enums
- [Flags]
- public enum InventorySortOrder : int
- {
- /// <summary>Sort by name</summary>
- ByName = 0,
- /// <summary>Sort by date</summary>
- ByDate = 1,
- /// <summary>Sort folders by name, regardless of whether items are
- /// sorted by name or date</summary>
- FoldersByName = 2,
- /// <summary>Place system folders at the top</summary>
- SystemFoldersToTop = 4
- }
- /// <summary>
- /// Possible destinations for DeRezObject request
- /// </summary>
- public enum DeRezDestination : byte
- {
- /// <summary></summary>
- AgentInventorySave = 0,
- /// <summary>Copy from in-world to agent inventory</summary>
- AgentInventoryCopy = 1,
- /// <summary>Derez to TaskInventory</summary>
- TaskInventory = 2,
- /// <summary></summary>
- Attachment = 3,
- /// <summary>Take Object</summary>
- AgentInventoryTake = 4,
- /// <summary></summary>
- ForceToGodInventory = 5,
- /// <summary>Delete Object</summary>
- TrashFolder = 6,
- /// <summary>Put an avatar attachment into agent inventory</summary>
- AttachmentToInventory = 7,
- /// <summary></summary>
- AttachmentExists = 8,
- /// <summary>Return an object back to the owner's inventory</summary>
- ReturnToOwner = 9,
- /// <summary>Return a deeded object back to the last owner's inventory</summary>
- ReturnToLastOwner = 10
- }
- /// <summary>
- /// Upper half of the Flags field for inventory items
- /// </summary>
- [Flags]
- public enum InventoryItemFlags : uint
- {
- None = 0,
- /// <summary>Indicates that the NextOwner permission will be set to the
- /// most restrictive set of permissions found in the object set
- /// (including linkset items and object inventory items) on next rez</summary>
- ObjectSlamPerm = 0x100,
- /// <summary>Indicates that the object sale information has been
- /// changed</summary>
- ObjectSlamSale = 0x1000,
- /// <summary>If set, and a slam bit is set, indicates BaseMask will be overwritten on Rez</summary>
- ObjectOverwriteBase = 0x010000,
- /// <summary>If set, and a slam bit is set, indicates OwnerMask will be overwritten on Rez</summary>
- ObjectOverwriteOwner = 0x020000,
- /// <summary>If set, and a slam bit is set, indicates GroupMask will be overwritten on Rez</summary>
- ObjectOverwriteGroup = 0x040000,
- /// <summary>If set, and a slam bit is set, indicates EveryoneMask will be overwritten on Rez</summary>
- ObjectOverwriteEveryone = 0x080000,
- /// <summary>If set, and a slam bit is set, indicates NextOwnerMask will be overwritten on Rez</summary>
- ObjectOverwriteNextOwner = 0x100000,
- /// <summary>Indicates whether this object is composed of multiple
- /// items or not</summary>
- ObjectHasMultipleItems = 0x200000,
- /// <summary>Indicates that the asset is only referenced by this
- /// inventory item. If this item is deleted or updated to reference a
- /// new assetID, the asset can be deleted</summary>
- SharedSingleReference = 0x40000000,
- }
- #endregion Enums
- #region Inventory Object Classes
- /// <summary>
- /// Base Class for Inventory Items
- /// </summary>
- [Serializable()]
- public abstract class InventoryBase : ISerializable
- {
- /// <summary><seealso cref="OpenMetaverse.UUID"/> of item/folder</summary>
- public UUID UUID;
- /// <summary><seealso cref="OpenMetaverse.UUID"/> of parent folder</summary>
- public UUID ParentUUID;
- /// <summary>Name of item/folder</summary>
- public string Name;
- /// <summary>Item/Folder Owners <seealso cref="OpenMetaverse.UUID"/></summary>
- public UUID OwnerID;
- /// <summary>
- /// Constructor, takes an itemID as a parameter
- /// </summary>
- /// <param name="itemID">The <seealso cref="OpenMetaverse.UUID"/> of the item</param>
- public InventoryBase(UUID itemID)
- {
- if (itemID == UUID.Zero)
- Logger.Log("Initializing an InventoryBase with UUID.Zero", Helpers.LogLevel.Warning);
- UUID = itemID;
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public virtual void GetObjectData(SerializationInfo info, StreamingContext ctxt)
- {
- info.AddValue("UUID", UUID);
- info.AddValue("ParentUUID", ParentUUID);
- info.AddValue("Name", Name);
- info.AddValue("OwnerID", OwnerID);
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public InventoryBase(SerializationInfo info, StreamingContext ctxt)
- {
- UUID = (UUID)info.GetValue("UUID", typeof(UUID));
- ParentUUID = (UUID)info.GetValue("ParentUUID", typeof(UUID));
- Name = (string)info.GetValue("Name", typeof(string));
- OwnerID = (UUID)info.GetValue("OwnerID", typeof(UUID));
- }
- /// <summary>
- /// Generates a number corresponding to the value of the object to support the use of a hash table,
- /// suitable for use in hashing algorithms and data structures such as a hash table
- /// </summary>
- /// <returns>A Hashcode of all the combined InventoryBase fields</returns>
- public override int GetHashCode()
- {
- return UUID.GetHashCode() ^ ParentUUID.GetHashCode() ^ Name.GetHashCode() ^ OwnerID.GetHashCode();
- }
- /// <summary>
- /// Determine whether the specified <seealso cref="OpenMetaverse.InventoryBase"/> object is equal to the current object
- /// </summary>
- /// <param name="o">InventoryBase object to compare against</param>
- /// <returns>true if objects are the same</returns>
- public override bool Equals(object o)
- {
- InventoryBase inv = o as InventoryBase;
- return inv != null && Equals(inv);
- }
- /// <summary>
- /// Determine whether the specified <seealso cref="OpenMetaverse.InventoryBase"/> object is equal to the current object
- /// </summary>
- /// <param name="o">InventoryBase object to compare against</param>
- /// <returns>true if objects are the same</returns>
- public virtual bool Equals(InventoryBase o)
- {
- return o.UUID == UUID
- && o.ParentUUID == ParentUUID
- && o.Name == Name
- && o.OwnerID == OwnerID;
- }
- }
- /// <summary>
- /// An Item in Inventory
- /// </summary>
- [Serializable()]
- public class InventoryItem : InventoryBase
- {
- public override string ToString()
- {
- return AssetType + " " + AssetUUID + " (" + InventoryType + " " + UUID + ") '" + Name + "'/'" +
- Description + "' " + Permissions;
- }
- /// <summary>The <seealso cref="OpenMetaverse.UUID"/> of this item</summary>
- public UUID AssetUUID;
- /// <summary>The combined <seealso cref="OpenMetaverse.Permissions"/> of this item</summary>
- public Permissions Permissions;
- /// <summary>The type of item from <seealso cref="OpenMetaverse.AssetType"/></summary>
- public AssetType AssetType;
- /// <summary>The type of item from the <seealso cref="OpenMetaverse.InventoryType"/> enum</summary>
- public InventoryType InventoryType;
- /// <summary>The <seealso cref="OpenMetaverse.UUID"/> of the creator of this item</summary>
- public UUID CreatorID;
- /// <summary>A Description of this item</summary>
- public string Description;
- /// <summary>The <seealso cref="OpenMetaverse.Group"/>s <seealso cref="OpenMetaverse.UUID"/> this item is set to or owned by</summary>
- public UUID GroupID;
- /// <summary>If true, item is owned by a group</summary>
- public bool GroupOwned;
- /// <summary>The price this item can be purchased for</summary>
- public int SalePrice;
- /// <summary>The type of sale from the <seealso cref="OpenMetaverse.SaleType"/> enum</summary>
- public SaleType SaleType;
- /// <summary>Combined flags from <seealso cref="OpenMetaverse.InventoryItemFlags"/></summary>
- public uint Flags;
- /// <summary>Time and date this inventory item was created, stored as
- /// UTC (Coordinated Universal Time)</summary>
- public DateTime CreationDate;
- /// <summary>Used to update the AssetID in requests sent to the server</summary>
- public UUID TransactionID;
- /// <summary>The <seealso cref="OpenMetaverse.UUID"/> of the previous owner of the item</summary>
- public UUID LastOwnerID;
- /// <summary>
- /// Construct a new InventoryItem object
- /// </summary>
- /// <param name="itemID">The <seealso cref="OpenMetaverse.UUID"/> of the item</param>
- public InventoryItem(UUID itemID)
- : base(itemID) { }
- /// <summary>
- /// Construct a new InventoryItem object of a specific Type
- /// </summary>
- /// <param name="type">The type of item from <seealso cref="OpenMetaverse.InventoryType"/></param>
- /// <param name="itemID"><seealso cref="OpenMetaverse.UUID"/> of the item</param>
- public InventoryItem(InventoryType type, UUID itemID) : base(itemID) { InventoryType = type; }
- /// <summary>
- /// Indicates inventory item is a link
- /// </summary>
- /// <returns>True if inventory item is a link to another inventory item</returns>
- public bool IsLink()
- {
- return AssetType == AssetType.Link || AssetType == AssetType.LinkFolder;
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- override public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
- {
- base.GetObjectData(info, ctxt);
- info.AddValue("AssetUUID", AssetUUID, typeof(UUID));
- info.AddValue("Permissions", Permissions, typeof(Permissions));
- info.AddValue("AssetType", AssetType);
- info.AddValue("InventoryType", InventoryType);
- info.AddValue("CreatorID", CreatorID);
- info.AddValue("Description", Description);
- info.AddValue("GroupID", GroupID);
- info.AddValue("GroupOwned", GroupOwned);
- info.AddValue("SalePrice", SalePrice);
- info.AddValue("SaleType", SaleType);
- info.AddValue("Flags", Flags);
- info.AddValue("CreationDate", CreationDate);
- info.AddValue("LastOwnerID", LastOwnerID);
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public InventoryItem(SerializationInfo info, StreamingContext ctxt)
- : base(info, ctxt)
- {
- AssetUUID = (UUID)info.GetValue("AssetUUID", typeof(UUID));
- Permissions = (Permissions)info.GetValue("Permissions", typeof(Permissions));
- AssetType = (AssetType)info.GetValue("AssetType", typeof(AssetType));
- InventoryType = (InventoryType)info.GetValue("InventoryType", typeof(InventoryType));
- CreatorID = (UUID)info.GetValue("CreatorID", typeof(UUID));
- Description = (string)info.GetValue("Description", typeof(string));
- GroupID = (UUID)info.GetValue("GroupID", typeof(UUID));
- GroupOwned = (bool)info.GetValue("GroupOwned", typeof(bool));
- SalePrice = (int)info.GetValue("SalePrice", typeof(int));
- SaleType = (SaleType)info.GetValue("SaleType", typeof(SaleType));
- Flags = (uint)info.GetValue("Flags", typeof(uint));
- CreationDate = (DateTime)info.GetValue("CreationDate", typeof(DateTime));
- LastOwnerID = (UUID)info.GetValue("LastOwnerID", typeof(UUID));
- }
- /// <summary>
- /// Generates a number corresponding to the value of the object to support the use of a hash table.
- /// Suitable for use in hashing algorithms and data structures such as a hash table
- /// </summary>
- /// <returns>A Hashcode of all the combined InventoryItem fields</returns>
- public override int GetHashCode()
- {
- return AssetUUID.GetHashCode() ^ Permissions.GetHashCode() ^ AssetType.GetHashCode() ^
- InventoryType.GetHashCode() ^ Description.GetHashCode() ^ GroupID.GetHashCode() ^
- GroupOwned.GetHashCode() ^ SalePrice.GetHashCode() ^ SaleType.GetHashCode() ^
- Flags.GetHashCode() ^ CreationDate.GetHashCode() ^ LastOwnerID.GetHashCode();
- }
- /// <summary>
- /// Compares an object
- /// </summary>
- /// <param name="o">The object to compare</param>
- /// <returns>true if comparison object matches</returns>
- public override bool Equals(object o)
- {
- InventoryItem item = o as InventoryItem;
- return item != null && Equals(item);
- }
- /// <summary>
- /// Determine whether the specified <seealso cref="OpenMetaverse.InventoryBase"/> object is equal to the current object
- /// </summary>
- /// <param name="o">The <seealso cref="OpenMetaverse.InventoryBase"/> object to compare against</param>
- /// <returns>true if objects are the same</returns>
- public override bool Equals(InventoryBase o)
- {
- InventoryItem item = o as InventoryItem;
- return item != null && Equals(item);
- }
- /// <summary>
- /// Determine whether the specified <seealso cref="OpenMetaverse.InventoryItem"/> object is equal to the current object
- /// </summary>
- /// <param name="o">The <seealso cref="OpenMetaverse.InventoryItem"/> object to compare against</param>
- /// <returns>true if objects are the same</returns>
- public bool Equals(InventoryItem o)
- {
- return base.Equals(o as InventoryBase)
- && o.AssetType == AssetType
- && o.AssetUUID == AssetUUID
- && o.CreationDate == CreationDate
- && o.Description == Description
- && o.Flags == Flags
- && o.GroupID == GroupID
- && o.GroupOwned == GroupOwned
- && o.InventoryType == InventoryType
- && o.Permissions.Equals(Permissions)
- && o.SalePrice == SalePrice
- && o.SaleType == SaleType
- && o.LastOwnerID == LastOwnerID;
- }
- }
- /// <summary>
- /// InventoryTexture Class representing a graphical image
- /// </summary>
- /// <seealso cref="ManagedImage"/>
- [Serializable()]
- public class InventoryTexture : InventoryItem
- {
- /// <summary>
- /// Construct an InventoryTexture object
- /// </summary>
- /// <param name="itemID">A <seealso cref="OpenMetaverse.UUID"/> which becomes the
- /// <seealso cref="OpenMetaverse.InventoryItem"/> objects AssetUUID</param>
- public InventoryTexture(UUID itemID)
- : base(itemID)
- {
- InventoryType = InventoryType.Texture;
- }
- /// <summary>
- /// Construct an InventoryTexture object from a serialization stream
- /// </summary>
- public InventoryTexture(SerializationInfo info, StreamingContext ctxt)
- : base(info, ctxt)
- {
- InventoryType = InventoryType.Texture;
- }
- }
- /// <summary>
- /// InventorySound Class representing a playable sound
- /// </summary>
- [Serializable()]
- public class InventorySound : InventoryItem
- {
- /// <summary>
- /// Construct an InventorySound object
- /// </summary>
- /// <param name="itemID">A <seealso cref="OpenMetaverse.UUID"/> which becomes the
- /// <seealso cref="OpenMetaverse.InventoryItem"/> objects AssetUUID</param>
- public InventorySound(UUID itemID)
- : base(itemID)
- {
- InventoryType = InventoryType.Sound;
- }
- /// <summary>
- /// Construct an InventorySound object from a serialization stream
- /// </summary>
- public InventorySound(SerializationInfo info, StreamingContext ctxt)
- : base(info, ctxt)
- {
- InventoryType = InventoryType.Sound;
- }
- }
- /// <summary>
- /// InventoryCallingCard Class, contains information on another avatar
- /// </summary>
- [Serializable()]
- public class InventoryCallingCard : InventoryItem
- {
- /// <summary>
- /// Construct an InventoryCallingCard object
- /// </summary>
- /// <param name="itemID">A <seealso cref="OpenMetaverse.UUID"/> which becomes the
- /// <seealso cref="OpenMetaverse.InventoryItem"/> objects AssetUUID</param>
- public InventoryCallingCard(UUID itemID)
- : base(itemID)
- {
- InventoryType = InventoryType.CallingCard;
- }
- /// <summary>
- /// Construct an InventoryCallingCard object from a serialization stream
- /// </summary>
- public InventoryCallingCard(SerializationInfo info, StreamingContext ctxt)
- : base(info, ctxt)
- {
- InventoryType = InventoryType.CallingCard;
- }
- }
- /// <summary>
- /// InventoryLandmark Class, contains details on a specific location
- /// </summary>
- [Serializable()]
- public class InventoryLandmark : InventoryItem
- {
- /// <summary>
- /// Construct an InventoryLandmark object
- /// </summary>
- /// <param name="itemID">A <seealso cref="OpenMetaverse.UUID"/> which becomes the
- /// <seealso cref="OpenMetaverse.InventoryItem"/> objects AssetUUID</param>
- public InventoryLandmark(UUID itemID)
- : base(itemID)
- {
- InventoryType = InventoryType.Landmark;
- }
- /// <summary>
- /// Construct an InventoryLandmark object from a serialization stream
- /// </summary>
- public InventoryLandmark(SerializationInfo info, StreamingContext ctxt)
- : base(info, ctxt)
- {
- InventoryType = InventoryType.Landmark;
- }
- /// <summary>
- /// Landmarks use the InventoryItemFlags struct and will have a flag of 1 set if they have been visited
- /// </summary>
- public bool LandmarkVisited
- {
- get { return (Flags & 1) != 0; }
- set
- {
- if (value) Flags |= 1;
- else Flags &= ~1u;
- }
- }
- }
- /// <summary>
- /// InventoryObject Class contains details on a primitive or coalesced set of primitives
- /// </summary>
- [Serializable()]
- public class InventoryObject : InventoryItem
- {
- /// <summary>
- /// Construct an InventoryObject object
- /// </summary>
- /// <param name="itemID">A <seealso cref="OpenMetaverse.UUID"/> which becomes the
- /// <seealso cref="OpenMetaverse.InventoryItem"/> objects AssetUUID</param>
- public InventoryObject(UUID itemID)
- : base(itemID)
- {
- InventoryType = InventoryType.Object;
- }
- /// <summary>
- /// Construct an InventoryObject object from a serialization stream
- /// </summary>
- public InventoryObject(SerializationInfo info, StreamingContext ctxt)
- : base(info, ctxt)
- {
- InventoryType = InventoryType.Object;
- }
- /// <summary>
- /// Gets or sets the upper byte of the Flags value
- /// </summary>
- public InventoryItemFlags ItemFlags
- {
- get { return (InventoryItemFlags)(Flags & ~0xFF); }
- set { Flags = (uint)value | (Flags & 0xFF); }
- }
- /// <summary>
- /// Gets or sets the object attachment point, the lower byte of the Flags value
- /// </summary>
- public AttachmentPoint AttachPoint
- {
- get { return (AttachmentPoint)(Flags & 0xFF); }
- set { Flags = (uint)value | (Flags & 0xFFFFFF00); }
- }
- }
- /// <summary>
- /// InventoryNotecard Class, contains details on an encoded text document
- /// </summary>
- [Serializable()]
- public class InventoryNotecard : InventoryItem
- {
- /// <summary>
- /// Construct an InventoryNotecard object
- /// </summary>
- /// <param name="itemID">A <seealso cref="OpenMetaverse.UUID"/> which becomes the
- /// <seealso cref="OpenMetaverse.InventoryItem"/> objects AssetUUID</param>
- public InventoryNotecard(UUID itemID)
- : base(itemID)
- {
- InventoryType = InventoryType.Notecard;
- }
- /// <summary>
- /// Construct an InventoryNotecard object from a serialization stream
- /// </summary>
- public InventoryNotecard(SerializationInfo info, StreamingContext ctxt)
- : base(info, ctxt)
- {
- InventoryType = InventoryType.Notecard;
- }
- }
- /// <summary>
- /// InventoryCategory Class
- /// </summary>
- /// <remarks>TODO: Is this even used for anything?</remarks>
- [Serializable()]
- public class InventoryCategory : InventoryItem
- {
- /// <summary>
- /// Construct an InventoryCategory object
- /// </summary>
- /// <param name="itemID">A <seealso cref="OpenMetaverse.UUID"/> which becomes the
- /// <seealso cref="OpenMetaverse.InventoryItem"/> objects AssetUUID</param>
- public InventoryCategory(UUID itemID)
- : base(itemID)
- {
- InventoryType = InventoryType.Category;
- }
- /// <summary>
- /// Construct an InventoryCategory object from a serialization stream
- /// </summary>
- public InventoryCategory(SerializationInfo info, StreamingContext ctxt)
- : base(info, ctxt)
- {
- InventoryType = InventoryType.Category;
- }
- }
- /// <summary>
- /// InventoryLSL Class, represents a Linden Scripting Language object
- /// </summary>
- [Serializable()]
- public class InventoryLSL : InventoryItem
- {
- /// <summary>
- /// Construct an InventoryLSL object
- /// </summary>
- /// <param name="itemID">A <seealso cref="OpenMetaverse.UUID"/> which becomes the
- /// <seealso cref="OpenMetaverse.InventoryItem"/> objects AssetUUID</param>
- public InventoryLSL(UUID itemID)
- : base(itemID)
- {
- InventoryType = InventoryType.LSL;
- }
- /// <summary>
- /// Construct an InventoryLSL object from a serialization stream
- /// </summary>
- public InventoryLSL(SerializationInfo info, StreamingContext ctxt)
- : base(info, ctxt)
- {
- InventoryType = InventoryType.LSL;
- }
- }
- /// <summary>
- /// InventorySnapshot Class, an image taken with the viewer
- /// </summary>
- [Serializable()]
- public class InventorySnapshot : InventoryItem
- {
- /// <summary>
- /// Construct an InventorySnapshot object
- /// </summary>
- /// <param name="itemID">A <seealso cref="OpenMetaverse.UUID"/> which becomes the
- /// <seealso cref="OpenMetaverse.InventoryItem"/> objects AssetUUID</param>
- public InventorySnapshot(UUID itemID)
- : base(itemID)
- {
- InventoryType = InventoryType.Snapshot;
- }
- /// <summary>
- /// Construct an InventorySnapshot object from a serialization stream
- /// </summary>
- public InventorySnapshot(SerializationInfo info, StreamingContext ctxt)
- : base(info, ctxt)
- {
- InventoryType = InventoryType.Snapshot;
- }
- }
- /// <summary>
- /// InventoryAttachment Class, contains details on an attachable object
- /// </summary>
- [Serializable()]
- public class InventoryAttachment : InventoryItem
- {
- /// <summary>
- /// Construct an InventoryAttachment object
- /// </summary>
- /// <param name="itemID">A <seealso cref="OpenMetaverse.UUID"/> which becomes the
- /// <seealso cref="OpenMetaverse.InventoryItem"/> objects AssetUUID</param>
- public InventoryAttachment(UUID itemID)
- : base(itemID)
- {
- InventoryType = InventoryType.Attachment;
- }
- /// <summary>
- /// Construct an InventoryAttachment object from a serialization stream
- /// </summary>
- public InventoryAttachment(SerializationInfo info, StreamingContext ctxt)
- : base(info, ctxt)
- {
- InventoryType = InventoryType.Attachment;
- }
- /// <summary>
- /// Get the last AttachmentPoint this object was attached to
- /// </summary>
- public AttachmentPoint AttachmentPoint
- {
- get { return (AttachmentPoint)Flags; }
- set { Flags = (uint)value; }
- }
- }
- /// <summary>
- /// InventoryWearable Class, details on a clothing item or body part
- /// </summary>
- [Serializable()]
- public class InventoryWearable : InventoryItem
- {
- /// <summary>
- /// Construct an InventoryWearable object
- /// </summary>
- /// <param name="itemID">A <seealso cref="OpenMetaverse.UUID"/> which becomes the
- /// <seealso cref="OpenMetaverse.InventoryItem"/> objects AssetUUID</param>
- public InventoryWearable(UUID itemID) : base(itemID) { InventoryType = InventoryType.Wearable; }
- /// <summary>
- /// Construct an InventoryWearable object from a serialization stream
- /// </summary>
- public InventoryWearable(SerializationInfo info, StreamingContext ctxt)
- : base(info, ctxt)
- {
- InventoryType = InventoryType.Wearable;
- }
- /// <summary>
- /// The <seealso cref="OpenMetaverse.WearableType"/>, Skin, Shape, Skirt, Etc
- /// </summary>
- public WearableType WearableType
- {
- get { return (WearableType)Flags; }
- set { Flags = (uint)value; }
- }
- }
- /// <summary>
- /// InventoryAnimation Class, A bvh encoded object which animates an avatar
- /// </summary>
- [Serializable()]
- public class InventoryAnimation : InventoryItem
- {
- /// <summary>
- /// Construct an InventoryAnimation object
- /// </summary>
- /// <param name="itemID">A <seealso cref="OpenMetaverse.UUID"/> which becomes the
- /// <seealso cref="OpenMetaverse.InventoryItem"/> objects AssetUUID</param>
- public InventoryAnimation(UUID itemID)
- : base(itemID)
- {
- InventoryType = InventoryType.Animation;
- }
- /// <summary>
- /// Construct an InventoryAnimation object from a serialization stream
- /// </summary>
- public InventoryAnimation(SerializationInfo info, StreamingContext ctxt)
- : base(info, ctxt)
- {
- InventoryType = InventoryType.Animation;
- }
- }
- /// <summary>
- /// InventoryGesture Class, details on a series of animations, sounds, and actions
- /// </summary>
- [Serializable()]
- public class InventoryGesture : InventoryItem
- {
- /// <summary>
- /// Construct an InventoryGesture object
- /// </summary>
- /// <param name="itemID">A <seealso cref="OpenMetaverse.UUID"/> which becomes the
- /// <seealso cref="OpenMetaverse.InventoryItem"/> objects AssetUUID</param>
- public InventoryGesture(UUID itemID)
- : base(itemID)
- {
- InventoryType = InventoryType.Gesture;
- }
- /// <summary>
- /// Construct an InventoryGesture object from a serialization stream
- /// </summary>
- public InventoryGesture(SerializationInfo info, StreamingContext ctxt)
- : base(info, ctxt)
- {
- InventoryType = InventoryType.Gesture;
- }
- }
- /// <summary>
- /// A folder contains <seealso cref="T:OpenMetaverse.InventoryItem"/>s and has certain attributes specific
- /// to itself
- /// </summary>
- [Serializable()]
- public class InventoryFolder : InventoryBase
- {
- /// <summary>The Preferred <seealso cref="T:OpenMetaverse.AssetType"/> for a folder.</summary>
- public AssetType PreferredType;
- /// <summary>The Version of this folder</summary>
- public int Version;
- /// <summary>Number of child items this folder contains.</summary>
- public int DescendentCount;
- /// <summary>
- /// Constructor
- /// </summary>
- /// <param name="itemID">UUID of the folder</param>
- public InventoryFolder(UUID itemID)
- : base(itemID)
- {
- PreferredType = AssetType.Unknown;
- Version = 1;
- DescendentCount = 0;
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public override string ToString()
- {
- return Name;
- }
- /// <summary>
- /// Get Serilization data for this InventoryFolder object
- /// </summary>
- override public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
- {
- base.GetObjectData(info, ctxt);
- info.AddValue("PreferredType", PreferredType, typeof(AssetType));
- info.AddValue("Version", Version);
- info.AddValue("DescendentCount", DescendentCount);
- }
- /// <summary>
- /// Construct an InventoryFolder object from a serialization stream
- /// </summary>
- public InventoryFolder(SerializationInfo info, StreamingContext ctxt)
- : base(info, ctxt)
- {
- PreferredType = (AssetType)info.GetValue("PreferredType", typeof(AssetType));
- Version = (int)info.GetValue("Version", typeof(int));
- DescendentCount = (int)info.GetValue("DescendentCount", typeof(int));
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public override int GetHashCode()
- {
- return PreferredType.GetHashCode() ^ Version.GetHashCode() ^ DescendentCount.GetHashCode();
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="o"></param>
- /// <returns></returns>
- public override bool Equals(object o)
- {
- InventoryFolder folder = o as InventoryFolder;
- return folder != null && Equals(folder);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="o"></param>
- /// <returns></returns>
- public override bool Equals(InventoryBase o)
- {
- InventoryFolder folder = o as InventoryFolder;
- return folder != null && Equals(folder);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="o"></param>
- /// <returns></returns>
- public bool Equals(InventoryFolder o)
- {
- return base.Equals(o as InventoryBase)
- && o.DescendentCount == DescendentCount
- && o.PreferredType == PreferredType
- && o.Version == Version;
- }
- }
- #endregion Inventory Object Classes
- /// <summary>
- /// Tools for dealing with agents inventory
- /// </summary>
- [Serializable()]
- public class InventoryManager
- {
- /// <summary>Used for converting shadow_id to asset_id</summary>
- public static readonly UUID MAGIC_ID = new UUID("3c115e51-04f4-523c-9fa6-98aff1034730");
- protected struct InventorySearch
- {
- public UUID Folder;
- public UUID Owner;
- public string[] Path;
- public int Level;
- }
- #region Delegates
- /// <summary>
- /// Callback for inventory item creation finishing
- /// </summary>
- /// <param name="success">Whether the request to create an inventory
- /// item succeeded or not</param>
- /// <param name="item">Inventory item being created. If success is
- /// false this will be null</param>
- public delegate void ItemCreatedCallback(bool success, InventoryItem item);
- /// <summary>
- /// Callback for an inventory item being create from an uploaded asset
- /// </summary>
- /// <param name="success">true if inventory item creation was successful</param>
- /// <param name="status"></param>
- /// <param name="itemID"></param>
- /// <param name="assetID"></param>
- public delegate void ItemCreatedFromAssetCallback(bool success, string status, UUID itemID, UUID assetID);
- /// <summary>
- ///
- /// </summary>
- /// <param name="item"></param>
- public delegate void ItemCopiedCallback(InventoryBase item);
- /// <summary>The event subscribers, null of no subscribers</summary>
- private EventHandler<ItemReceivedEventArgs> m_ItemReceived;
- ///<summary>Raises the ItemReceived Event</summary>
- /// <param name="e">A ItemReceivedEventArgs object containing
- /// the data sent from the simulator</param>
- protected virtual void OnItemReceived(ItemReceivedEventArgs e)
- {
- EventHandler<ItemReceivedEventArgs> handler = m_ItemReceived;
- if (handler != null)
- handler(this, e);
- }
- /// <summary>Thread sync lock object</summary>
- private readonly object m_ItemReceivedLock = new object();
- /// <summary>Raised when the simulator sends us data containing
- /// ...</summary>
- public event EventHandler<ItemReceivedEventArgs> ItemReceived
- {
- add { lock (m_ItemReceivedLock) { m_ItemReceived += value; } }
- remove { lock (m_ItemReceivedLock) { m_ItemReceived -= value; } }
- }
- /// <summary>The event subscribers, null of no subscribers</summary>
- private EventHandler<FolderUpdatedEventArgs> m_FolderUpdated;
- ///<summary>Raises the FolderUpdated Event</summary>
- /// <param name="e">A FolderUpdatedEventArgs object containing
- /// the data sent from the simulator</param>
- protected virtual void OnFolderUpdated(FolderUpdatedEventArgs e)
- {
- EventHandler<FolderUpdatedEventArgs> handler = m_FolderUpdated;
- if (handler != null)
- handler(this, e);
- }
- /// <summary>Thread sync lock object</summary>
- private readonly object m_FolderUpdatedLock = new object();
- /// <summary>Raised when the simulator sends us data containing
- /// ...</summary>
- public event EventHandler<FolderUpdatedEventArgs> FolderUpdated
- {
- add { lock (m_FolderUpdatedLock) { m_FolderUpdated += value; } }
- remove { lock (m_FolderUpdatedLock) { m_FolderUpdated -= value; } }
- }
- /// <summary>The event subscribers, null of no subscribers</summary>
- private EventHandler<InventoryObjectOfferedEventArgs> m_InventoryObjectOffered;
- ///<summary>Raises the InventoryObjectOffered Event</summary>
- /// <param name="e">A InventoryObjectOfferedEventArgs object containing
- /// the data sent from the simulator</param>
- protected virtual void OnInventoryObjectOffered(InventoryObjectOfferedEventArgs e)
- {
- EventHandler<InventoryObjectOfferedEventArgs> handler = m_InventoryObjectOffered;
- if (handler != null)
- handler(this, e);
- }
- /// <summary>Thread sync lock object</summary>
- private readonly object m_InventoryObjectOfferedLock = new object();
- /// <summary>Raised when the simulator sends us data containing
- /// an inventory object sent by another avatar or primitive</summary>
- public event EventHandler<InventoryObjectOfferedEventArgs> InventoryObjectOffered
- {
- add { lock (m_InventoryObjectOfferedLock) { m_InventoryObjectOffered += value; } }
- remove { lock (m_InventoryObjectOfferedLock) { m_InventoryObjectOffered -= value; } }
- }
- /// <summary>The event subscribers, null of no subscribers</summary>
- private EventHandler<TaskItemReceivedEventArgs> m_TaskItemReceived;
- ///<summary>Raises the TaskItemReceived Event</summary>
- /// <param name="e">A TaskItemReceivedEventArgs object containing
- /// the data sent from the simulator</param>
- protected virtual void OnTaskItemReceived(TaskItemReceivedEventArgs e)
- {
- EventHandler<TaskItemReceivedEventArgs> handler = m_TaskItemReceived;
- if (handler != null)
- handler(this, e);
- }
- /// <summary>Thread sync lock object</summary>
- private readonly object m_TaskItemReceivedLock = new object();
- /// <summary>Raised when the simulator sends us data containing
- /// ...</summary>
- public event EventHandler<TaskItemReceivedEventArgs> TaskItemReceived
- {
- add { lock (m_TaskItemReceivedLock) { m_TaskItemReceived += value; } }
- remove { lock (m_TaskItemReceivedLock) { m_TaskItemReceived -= value; } }
- }
- /// <summary>The event subscribers, null of no subscribers</summary>
- private EventHandler<FindObjectByPathReplyEventArgs> m_FindObjectByPathReply;
- ///<summary>Raises the FindObjectByPath Event</summary>
- /// <param name="e">A FindObjectByPathEventArgs object containing
- /// the data sent from the simulator</param>
- protected virtual void OnFindObjectByPathReply(FindObjectByPathReplyEventArgs e)
- {
- EventHandler<FindObjectByPathReplyEventArgs> handler = m_FindObjectByPathReply;
- if (handler != null)
- handler(this, e);
- }
- /// <summary>Thread sync lock object</summary>
- private readonly object m_FindObjectByPathReplyLock = new object();
- /// <summary>Raised when the simulator sends us data containing
- /// ...</summary>
- public event EventHandler<FindObjectByPathReplyEventArgs> FindObjectByPathReply
- {
- add { lock (m_FindObjectByPathReplyLock) { m_FindObjectByPathReply += value; } }
- remove { lock (m_FindObjectByPathReplyLock) { m_FindObjectByPathReply -= value; } }
- }
- /// <summary>The event subscribers, null of no subscribers</summary>
- private EventHandler<TaskInventoryReplyEventArgs> m_TaskInventoryReply;
- ///<summary>Raises the TaskInventoryReply Event</summary>
- /// <param name="e">A TaskInventoryReplyEventArgs object containing
- /// the data sent from the simulator</param>
- protected virtual void OnTaskInventoryReply(TaskInventoryReplyEventArgs e)
- {
- EventHandler<TaskInventoryReplyEventArgs> handler = m_TaskInventoryReply;
- if (handler != null)
- handler(this, e);
- }
- /// <summary>Thread sync lock object</summary>
- private readonly object m_TaskInventoryReplyLock = new object();
- /// <summary>Raised when the simulator sends us data containing
- /// ...</summary>
- public event EventHandler<TaskInventoryReplyEventArgs> TaskInventoryReply
- {
- add { lock (m_TaskInventoryReplyLock) { m_TaskInventoryReply += value; } }
- remove { lock (m_TaskInventoryReplyLock) { m_TaskInventoryReply -= value; } }
- }
- /// <summary>
- /// Reply received when uploading an inventory asset
- /// </summary>
- /// <param name="success">Has upload been successful</param>
- /// <param name="status">Error message if upload failed</param>
- /// <param name="itemID">Inventory asset UUID</param>
- /// <param name="assetID">New asset UUID</param>
- public delegate void InventoryUploadedAssetCallback(bool success, string status, UUID itemID, UUID assetID);
- /// <summary>The event subscribers, null of no subscribers</summary>
- private EventHandler<SaveAssetToInventoryEventArgs> m_SaveAssetToInventory;
- ///<summary>Raises the SaveAssetToInventory Event</summary>
- /// <param name="e">A SaveAssetToInventoryEventArgs object containing
- /// the data sent from the simulator</param>
- protected virtual void OnSaveAssetToInventory(SaveAssetToInventoryEventArgs e)
- {
- EventHandler<SaveAssetToInventoryEventArgs> handler = m_SaveAssetToInventory;
- if (handler != null)
- handler(this, e);
- }
- /// <summary>Thread sync lock object</summary>
- private readonly object m_SaveAssetToInventoryLock = new object();
- /// <summary>Raised when the simulator sends us data containing
- /// ...</summary>
- public event EventHandler<SaveAssetToInventoryEventArgs> SaveAssetToInventory
- {
- add { lock (m_SaveAssetToInventoryLock) { m_SaveAssetToInventory += value; } }
- remove { lock (m_SaveAssetToInventoryLock) { m_SaveAssetToInventory -= value; } }
- }
- /// <summary>
- /// Delegate that is invoked when script upload is completed
- /// </summary>
- /// <param name="uploadSuccess">Has upload succeded (note, there still might be compile errors)</param>
- /// <param name="uploadStatus">Upload status message</param>
- /// <param name="compileSuccess">Is compilation successful</param>
- /// <param name="compileMessages">If compilation failed, list of error messages, null on compilation success</param>
- /// <param name="itemID">Script inventory UUID</param>
- /// <param name="assetID">Script's new asset UUID</param>
- public delegate void ScriptUpdatedCallback(bool uploadSuccess, string uploadStatus, bool compileSuccess, List<string> compileMessages, UUID itemID, UUID assetID);
- /// <summary>The event subscribers, null of no subscribers</summary>
- private EventHandler<ScriptRunningReplyEventArgs> m_ScriptRunningReply;
- ///<summary>Raises the ScriptRunningReply Event</summary>
- /// <param name="e">A ScriptRunningReplyEventArgs object containing
- /// the data sent from the simulator</param>
- protected virtual void OnScriptRunningReply(ScriptRunningReplyEventArgs e)
- {
- EventHandler<ScriptRunningReplyEventArgs> handler = m_ScriptRunningReply;
- if (handler != null)
- handler(this, e);
- }
- /// <summary>Thread sync lock object</summary>
- private readonly object m_ScriptRunningReplyLock = new object();
- /// <summary>Raised when the simulator sends us data containing
- /// ...</summary>
- public event EventHandler<ScriptRunningReplyEventArgs> ScriptRunningReply
- {
- add { lock (m_ScriptRunningReplyLock) { m_ScriptRunningReply += value; } }
- remove { lock (m_ScriptRunningReplyLock) { m_ScriptRunningReply -= value; } }
- }
- #endregion Delegates
- #region String Arrays
- /// <summary>Partial mapping of AssetTypes to folder names</summary>
- private static readonly string[] _NewFolderNames = new string[]
- {
- "Textures",
- "Sounds",
- "Calling Cards",
- "Landmarks",
- "Scripts",
- "Clothing",
- "Objects",
- "Notecards",
- "New Folder",
- "Inventory",
- "Scripts",
- "Scripts",
- "Uncompressed Images",
- "Body Parts",
- "Trash",
- "Photo Album",
- "Lost And Found",
- "Uncompressed Sounds",
- "Uncompressed Images",
- "Uncompressed Images",
- "Animations",
- "Gestures"
- };
- #endregion String Arrays
- private GridClient Client;
- private Inventory _Store;
- //private Random _RandNumbers = new Random();
- private object _CallbacksLock = new object();
- private uint _CallbackPos;
- private Dictionary<uint, ItemCreatedCallback> _ItemCreatedCallbacks = new Dictionary<uint, ItemCreatedCallback>();
- private Dictionary<uint, ItemCopiedCallback> _ItemCopiedCallbacks = new Dictionary<uint, ItemCopiedCallback>();
- private List<InventorySearch> _Searches = new List<InventorySearch>();
- #region Properties
- /// <summary>
- /// Get this agents Inventory data
- /// </summary>
- public Inventory Store { get { return _Store; } }
- #endregion Properties
- /// <summary>
- /// Default constructor
- /// </summary>
- /// <param name="client">Reference to the GridClient object</param>
- public InventoryManager(GridClient client)
- {
- Client = client;
- Client.Network.RegisterCallback(PacketType.UpdateCreateInventoryItem, UpdateCreateInventoryItemHandler);
- Client.Network.RegisterCallback(PacketType.SaveAssetIntoInventory, SaveAssetIntoInventoryHandler);
- Client.Network.RegisterCallback(PacketType.BulkUpdateInventory, BulkUpdateInventoryHandler);
- Client.Network.RegisterEventCallback("BulkUpdateInventory", new Caps.EventQueueCallback(BulkUpdateInventoryCapHandler));
- Client.Network.RegisterCallback(PacketType.MoveInventoryItem, MoveInventoryItemHandler);
- Client.Network.RegisterCallback(PacketType.InventoryDescendents, InventoryDescendentsHandler);
- Client.Network.RegisterCallback(PacketType.FetchInventoryReply, FetchInventoryReplyHandler);
- Client.Network.RegisterCallback(PacketType.ReplyTaskInventory, ReplyTaskInventoryHandler);
- Client.Network.RegisterEventCallback("ScriptRunningReply", new Caps.EventQueueCallback(ScriptRunningReplyMessageHandler));
- // Watch for inventory given to us through instant message
- Client.Self.IM += Self_IM;
- // Register extra parameters with login and parse the inventory data that comes back
- Client.Network.RegisterLoginResponseCallback(
- new NetworkManager.LoginResponseCallback(Network_OnLoginResponse),
- new string[] {
- "inventory-root", "inventory-skeleton", "inventory-lib-root",
- "inventory-lib-owner", "inventory-skel-lib"});
- }
- #region Fetch
- /// <summary>
- /// Fetch an inventory item from the dataserver
- /// </summary>
- /// <param name="itemID">The items <seealso cref="UUID"/></param>
- /// <param name="ownerID">The item Owners <seealso cref="OpenMetaverse.UUID"/></param>
- /// <param name="timeoutMS">a integer representing the number of milliseconds to wait for results</param>
- /// <returns>An <seealso cref="InventoryItem"/> object on success, or null if no item was found</returns>
- /// <remarks>Items will also be sent to the <seealso cref="InventoryManager.OnItemReceived"/> event</remarks>
- public InventoryItem FetchItem(UUID itemID, UUID ownerID, int timeoutMS)
- {
- AutoResetEvent fetchEvent = new AutoResetEvent(false);
- InventoryItem fetchedItem = null;
- EventHandler<ItemReceivedEventArgs> callback =
- delegate(object sender, ItemReceivedEventArgs e)
- {
- if (e.Item.UUID == itemID)
- {
- fetchedItem = e.Item;
- fetchEvent.Set();
- }
- };
- ItemReceived += callback;
- RequestFetchInventory(itemID, ownerID);
- fetchEvent.WaitOne(timeoutMS, false);
- ItemReceived -= callback;
- return fetchedItem;
- }
- /// <summary>
- /// Request A single inventory item
- /// </summary>
- /// <param name="itemID">The item…
Large files files are truncated, but you can click here to view the full file