public override OSDArray GetLLSDItems(string[] fields, string[] vals)
        {
            string query = "";
            for (int i = 0; i < fields.Length; i++)
            {
                query += String.Format("where {0} = '{1}' and ", fields[i], vals[i]);
                i++;
            }
            query = query.Remove(query.Length - 5);
            if (fields[0] == "inventoryID")
            {
                IInventoryService invService = m_registry.RequestModuleInterface<IInventoryService>();
                if (invService != null)
                {
                    UUID inventoryID = UUID.Parse(vals[0]);
                    InventoryItemBase baseItem = new InventoryItemBase(UUID.Parse(vals[0]));
                    if (vals.Count() > 1)
                    {
                        UUID avatarID = UUID.Parse(vals[1]);
                        IUserFinder userFinder = m_registry.RequestModuleInterface<IUserFinder>();
                        if (userFinder != null && !userFinder.IsLocalGridUser(avatarID))
                        {
                            string serverURL = userFinder.GetUserServerURL(avatarID, "InventoryServerURI") + "xinventory";
                            XInventoryServicesConnector xinv = new XInventoryServicesConnector(serverURL);
                            return BuildLLSDInventoryItems(xinv.GetItem(baseItem));
                        }
                    }
                    return BuildLLSDInventoryItems(invService.GetItem(baseItem));
                }
            }

            return null;
        }
        public override bool AddItem(InventoryItemBase item)
        {
            //            MainConsole.Instance.DebugFormat(
            //                "[XINVENTORY SERVICE]: Adding item {0} to folder {1} for {2}", item.ID, item.Folder, item.Owner);

            item.Folder = GetRootFolder (item.Owner).ID;//All items into the foreign folder please!
            m_Database.IncrementFolder (item.Folder);
            return m_Database.StoreItem (item);
        }
 public override bool AddItem(InventoryItemBase item)
 {
     string invserverURL = "";
     if (GetHandlers.GetIsForeign (item.Owner, "InventoryServerURI", m_registry, out invserverURL))
     {
         XInventoryServicesConnector xinv = new XInventoryServicesConnector (invserverURL + "xinventory");
         bool success = xinv.AddItem (item);
         return success;
     }
     return base.AddItem (item);
 }
        public override bool AddItem(InventoryItemBase item)
        {
            object remoteValue = DoRemote(item);
            if (remoteValue != null || m_doRemoteOnly)
                return remoteValue != null && (bool)remoteValue;

            string invserverURL = "";
            if (GetHandlers.GetIsForeign (item.Owner, "InventoryServerURI", m_registry, out invserverURL))
            {
                XInventoryServicesConnector xinv = new XInventoryServicesConnector (invserverURL + "xinventory");
                bool success = xinv.AddItem (item);
                return success;
            }
            return base.AddItem (item);
        }
Beispiel #5
0
 public override void FromOSD(OSDMap map)
 {
     OSDArray items = (OSDArray)map["Items"];
     Items = items.ConvertAll<InventoryItemBase>((osd) =>
     {
         InventoryItemBase item = new InventoryItemBase();
         item.FromOSD((OSDMap)osd);
         return item;
     }
     );
     OSDArray folders = (OSDArray)map["Folders"];
     Folders = folders.ConvertAll<InventoryFolderBase>((osd) =>
     {
         InventoryFolderBase folder = new InventoryFolderBase();
         folder.FromOSD((OSDMap)osd);
         return folder;
     }
     );
     UserID = map["UserID"];
 }
        public override OSDArray GetLLSDItems(string[] fields, string[] vals)
        {
            string query = "";
            for (int i = 0; i < fields.Length; i++)
            {
                query += String.Format("where {0} = '{1}' and ", fields[i], vals[i]);
                i++;
            }
            query = query.Remove(query.Length - 5);
            if (fields[0] == "inventoryID")
            {
                IInventoryService invService = m_registry.RequestModuleInterface<IInventoryService>();
                if (invService != null)
                {
                    InventoryItemBase baseItem = new InventoryItemBase(UUID.Parse(vals[0]));
                    return BuildLLSDInventoryItems(invService.GetItem(baseItem));
                }
            }

            return null;
        }
        /// <summary>
        /// Update an item in a prim (task) inventory.
        /// This method does not handle scripts, <see>RezScript(IClientAPI, UUID, unit)</see>
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="transactionID"></param>
        /// <param name="itemInfo"></param>
        /// <param name="primLocalID"></param>
        protected void UpdateTaskInventory(IClientAPI remoteClient, UUID transactionID, TaskInventoryItem itemInfo,
                                        uint primLocalID)
        {
            UUID itemID = itemInfo.ItemID;

            // Find the prim we're dealing with
            ISceneChildEntity part = m_scene.GetSceneObjectPart (primLocalID);

            if (part != null)
            {
                TaskInventoryItem currentItem = part.Inventory.GetInventoryItem(itemID);
                bool allowInventoryDrop = (part.GetEffectiveObjectFlags()
                                           & (uint)PrimFlags.AllowInventoryDrop) != 0;

                // Explicity allow anyone to add to the inventory if the
                // AllowInventoryDrop flag has been set. Don't however let
                // them update an item unless they pass the external checks
                //
                if (!m_scene.Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId)
                    && (currentItem != null || !allowInventoryDrop))
                    return;

                if (currentItem == null)
                {
                    UUID copyID = UUID.Random();
                    if (itemID != UUID.Zero)
                    {
                        InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
                        item = m_scene.InventoryService.GetItem(item);

                        // If we've found the item in the user's inventory or in the library
                        if (item != null)
                        {
                            part.ParentEntity.AddInventoryItem (remoteClient, primLocalID, item, copyID);
                            MainConsole.Instance.InfoFormat(
                                "[PRIM INVENTORY]: Update with item {0} requested of prim {1} for {2}",
                                item.Name, primLocalID, remoteClient.Name);
                            part.GetProperties(remoteClient);
                            if (!m_scene.Permissions.BypassPermissions())
                            {
                                if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
                                {
                                    List<UUID> uuids = new List<UUID> {itemID};
                                    RemoveInventoryItem(remoteClient, uuids);
                                }
                            }
                        }
                        else
                        {
                            MainConsole.Instance.ErrorFormat(
                                "[PRIM INVENTORY]: Could not find inventory item {0} to update for {1}!",
                                itemID, remoteClient.Name);
                        }
                    }
                }
                else // Updating existing item with new perms etc
                {
                    // Base ALWAYS has move
                    currentItem.BasePermissions |= (uint)PermissionMask.Move;

                    // Check if we're allowed to mess with permissions
                    if (!m_scene.Permissions.IsGod(remoteClient.AgentId)) // Not a god
                    {
                        if (remoteClient.AgentId != part.OwnerID) // Not owner
                        {
                            // Friends and group members can't change any perms
                            itemInfo.BasePermissions = currentItem.BasePermissions;
                            itemInfo.EveryonePermissions = currentItem.EveryonePermissions;
                            itemInfo.GroupPermissions = currentItem.GroupPermissions;
                            itemInfo.NextPermissions = currentItem.NextPermissions;
                            itemInfo.CurrentPermissions = currentItem.CurrentPermissions;
                        }
                        else
                        {
                            // Owner can't change base, and can change other
                            // only up to base
                            itemInfo.BasePermissions = currentItem.BasePermissions;
                            itemInfo.EveryonePermissions &= currentItem.BasePermissions;
                            itemInfo.GroupPermissions &= currentItem.BasePermissions;
                            itemInfo.CurrentPermissions &= currentItem.BasePermissions;
                            itemInfo.NextPermissions &= currentItem.BasePermissions;
                        }

                    }

                    // Next ALWAYS has move
                    itemInfo.NextPermissions |= (uint)PermissionMask.Move;

                    if (part.Inventory.UpdateInventoryItem(itemInfo))
                    {
                        part.GetProperties(remoteClient);
                    }
                }
            }
            else
            {
                MainConsole.Instance.WarnFormat(
                    "[PRIM INVENTORY]: " +
                    "Update with item {0} requested of prim {1} for {2} but this prim does not exist",
                    itemID, primLocalID, remoteClient.Name);
            }
        }
Beispiel #8
0
        ///<summary>
        ///</summary>
        ///<param name = "assetID"></param>
        ///<param name = "inventoryItem"></param>
        ///<param name = "data"></param>
        public UUID UploadCompleteHandler(string assetName, string assetDescription, UUID assetID,
                                          UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType,
                                          string assetType, uint everyone_mask, uint group_mask, uint next_owner_mask)
        {
            sbyte assType = 0;
            sbyte inType = 0;

            if (inventoryType == "sound")
            {
                inType = 1;
                assType = 1;
            }
            else if (inventoryType == "animation")
            {
                inType = 19;
                assType = 20;
            }
            else if (inventoryType == "snapshot")
            {
                inType = 15;
                assType = 0;
            }
            else if (inventoryType == "wearable")
            {
                inType = 18;
                switch (assetType)
                {
                    case "bodypart":
                        assType = 13;
                        break;
                    case "clothing":
                        assType = 5;
                        break;
                }
            }
            else if (inventoryType == "object")
            {
                inType = (sbyte) InventoryType.Object;
                assType = (sbyte) AssetType.Object;

                List<Vector3> positions = new List<Vector3>();
                List<Quaternion> rotations = new List<Quaternion>();
                OSDMap request = (OSDMap) OSDParser.DeserializeLLSDXml(data);
                OSDArray instance_list = (OSDArray) request["instance_list"];
                OSDArray mesh_list = (OSDArray) request["mesh_list"];
                OSDArray texture_list = (OSDArray) request["texture_list"];
                SceneObjectGroup grp = null;

                List<UUID> textures = new List<UUID>();
#if(!ISWIN)
                for (int i = 0; i < texture_list.Count; i++)
                {
                    AssetBase textureAsset = new AssetBase(UUID.Random(), assetName, AssetType.Texture, m_service.AgentID);
                    textureAsset.Data = texture_list[i].AsBinary();
                    textureAsset.ID = m_assetService.Store(textureAsset);
                    textures.Add(textureAsset.ID);
                }
#else
                foreach (AssetBase textureAsset in texture_list.Select(t => new AssetBase(UUID.Random(), assetName, AssetType.Texture,
                                                                                          m_service.AgentID) {Data = t.AsBinary()}))
                {
                    textureAsset.ID = m_assetService.Store(textureAsset);
                    textures.Add(textureAsset.ID);
                }
#endif
                InventoryFolderBase meshFolder = m_inventoryService.GetFolderForType(m_service.AgentID,
                                                                                     InventoryType.Mesh, AssetType.Mesh);
                for (int i = 0; i < mesh_list.Count; i++)
                {
                    PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox();

                    Primitive.TextureEntry textureEntry =
                        new Primitive.TextureEntry(Primitive.TextureEntry.WHITE_TEXTURE);
                    OSDMap inner_instance_list = (OSDMap) instance_list[i];

                    OSDArray face_list = (OSDArray) inner_instance_list["face_list"];
                    for (uint face = 0; face < face_list.Count; face++)
                    {
                        OSDMap faceMap = (OSDMap) face_list[(int) face];
                        Primitive.TextureEntryFace f = pbs.Textures.CreateFace(face);
                        if (faceMap.ContainsKey("fullbright"))
                            f.Fullbright = faceMap["fullbright"].AsBoolean();
                        if (faceMap.ContainsKey("diffuse_color"))
                            f.RGBA = faceMap["diffuse_color"].AsColor4();

                        int textureNum = faceMap["image"].AsInteger();
                        float imagerot = faceMap["imagerot"].AsInteger();
                        float offsets = (float) faceMap["offsets"].AsReal();
                        float offsett = (float) faceMap["offsett"].AsReal();
                        float scales = (float) faceMap["scales"].AsReal();
                        float scalet = (float) faceMap["scalet"].AsReal();

                        if (imagerot != 0)
                            f.Rotation = imagerot;
                        if (offsets != 0)
                            f.OffsetU = offsets;
                        if (offsett != 0)
                            f.OffsetV = offsett;
                        if (scales != 0)
                            f.RepeatU = scales;
                        if (scalet != 0)
                            f.RepeatV = scalet;
                        f.TextureID = textures.Count > textureNum ? textures[textureNum] : Primitive.TextureEntry.WHITE_TEXTURE;
                        textureEntry.FaceTextures[face] = f;
                    }
                    pbs.TextureEntry = textureEntry.GetBytes();

                    AssetBase meshAsset = new AssetBase(UUID.Random(), assetName, AssetType.Mesh, m_service.AgentID)
                                              {Data = mesh_list[i].AsBinary()};
                    meshAsset.ID = m_assetService.Store(meshAsset);

                    if (meshFolder == null)
                    {
                        m_inventoryService.CreateUserInventory(m_service.AgentID, false);
                        meshFolder = m_inventoryService.GetFolderForType(m_service.AgentID, InventoryType.Mesh,
                                                                         AssetType.Mesh);
                    }

                    InventoryItemBase itemBase = new InventoryItemBase(UUID.Random(), m_service.AgentID)
                                                     {
                                                         AssetType = (sbyte) AssetType.Mesh,
                                                         AssetID = meshAsset.ID,
                                                         CreatorId = m_service.AgentID.ToString(),
                                                         Folder = meshFolder.ID,
                                                         InvType = (int) InventoryType.Texture,
                                                         Name = "(Mesh) - " + assetName,
                                                         CurrentPermissions = (uint) PermissionMask.All,
                                                         BasePermissions = (uint) PermissionMask.All,
                                                         EveryOnePermissions = everyone_mask,
                                                         GroupPermissions = group_mask,
                                                         NextPermissions = next_owner_mask
                                                     };
                    //Bad... but whatever
                    m_inventoryService.AddItem(itemBase);

                    pbs.SculptEntry = true;
                    pbs.SculptTexture = meshAsset.ID;
                    pbs.SculptType = (byte) SculptType.Mesh;
                    pbs.SculptData = meshAsset.Data;

                    Vector3 position = inner_instance_list["position"].AsVector3();
                    Vector3 scale = inner_instance_list["scale"].AsVector3();
                    Quaternion rotation = inner_instance_list["rotation"].AsQuaternion();

                    int physicsShapeType = inner_instance_list["physics_shape_type"].AsInteger();
                    int material = inner_instance_list["material"].AsInteger();
                    int mesh = inner_instance_list["mesh"].AsInteger();

                    UUID owner_id = m_service.AgentID;

                    IScene fakeScene = new Scene();
                    fakeScene.AddModuleInterfaces(m_service.Registry.GetInterfaces());

                    SceneObjectPart prim = new SceneObjectPart(owner_id, pbs, position, Quaternion.Identity,
                                                               Vector3.Zero, assetName, fakeScene)
                                               {Scale = scale, AbsolutePosition = position};

                    rotations.Add(rotation);
                    positions.Add(position);
                    prim.UUID = UUID.Random();
                    prim.CreatorID = owner_id;
                    prim.OwnerID = owner_id;
                    prim.GroupID = UUID.Zero;
                    prim.LastOwnerID = prim.OwnerID;
                    prim.CreationDate = Util.UnixTimeSinceEpoch();
                    prim.Name = assetName;
                    prim.Description = "";
                    prim.PhysicsType = (byte) physicsShapeType;

                    prim.BaseMask = (uint) PermissionMask.All;
                    prim.EveryoneMask = everyone_mask;
                    prim.NextOwnerMask = next_owner_mask;
                    prim.GroupMask = group_mask;
                    prim.OwnerMask = (uint) PermissionMask.All;

                    if (grp == null)
                        grp = new SceneObjectGroup(prim, fakeScene);
                    else
                        grp.AddChild(prim, i + 1);
                    grp.RootPart.IsAttachment = false;
                }
                if (grp.ChildrenList.Count > 1) //Fix first link #
                    grp.RootPart.LinkNum++;

                Vector3 rootPos = positions[0];
                grp.SetAbsolutePosition(false, rootPos);
                for (int i = 0; i < positions.Count; i++)
                {
                    Vector3 offset = positions[i] - rootPos;
                    grp.ChildrenList[i].SetOffsetPosition(offset);
                    Vector3 abs = grp.ChildrenList[i].AbsolutePosition;
                    Vector3 currentPos = positions[i];
                }
                //grp.Rotation = rotations[0];
                for (int i = 0; i < rotations.Count; i++)
                {
                    if (i != 0)
                        grp.ChildrenList[i].SetRotationOffset(false, rotations[i], false);
                }
                grp.UpdateGroupRotationR(rotations[0]);
                data = Encoding.ASCII.GetBytes(grp.ToXml2());
            }
            AssetBase asset = new AssetBase(assetID, assetName, (AssetType) assType, m_service.AgentID) {Data = data};
            asset.ID = m_assetService.Store(asset);
            assetID = asset.ID;

            InventoryItemBase item = new InventoryItemBase
                                         {
                                             Owner = m_service.AgentID,
                                             CreatorId = m_service.AgentID.ToString(),
                                             ID = inventoryItem,
                                             AssetID = asset.ID,
                                             Description = assetDescription,
                                             Name = assetName,
                                             AssetType = assType,
                                             InvType = inType,
                                             Folder = parentFolder,
                                             CurrentPermissions = (uint) PermissionMask.All,
                                             BasePermissions = (uint) PermissionMask.All,
                                             EveryOnePermissions = everyone_mask,
                                             NextPermissions = next_owner_mask,
                                             GroupPermissions = group_mask,
                                             CreationDate = Util.UnixTimeSinceEpoch()
                                         };

            m_inventoryService.AddItem(item);

            return assetID;
        }
        private void SetAppearanceAssets(UUID userID, List<AvatarWearingArgs.Wearable> nowWearing, AvatarAppearance oldAppearance, ref AvatarAppearance appearance)
        {
            IInventoryService invService = m_scene.InventoryService;

            for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++)
            {
                for (int j = 0; j < appearance.Wearables[j].Count; j++)
                {
                    if (appearance.Wearables[i][j].ItemID == UUID.Zero)
                        continue;

                    // Ignore ruth's assets
                    if (appearance.Wearables[i][j].ItemID == AvatarWearable.DefaultWearables[i][j].ItemID)
                    {
                        //MainConsole.Instance.ErrorFormat(
                        //    "[AvatarFactory]: Found an asset for the default avatar, itemID {0}, wearable {1}, asset {2}" +
                        //    ", setting to default asset {3}.",
                        //    appearance.Wearables[i][j].ItemID, (WearableType)i, appearance.Wearables[i][j].AssetID,
                        //    AvatarWearable.DefaultWearables[i][j].AssetID);
                        appearance.Wearables[i].Add(appearance.Wearables[i][j].ItemID,
                                                    appearance.Wearables[i][j].AssetID);
                        continue;
                    }

                    if (nowWearing[i].ItemID == oldAppearance.Wearables[i][j].ItemID)
                        continue;//Don't relookup items that are the same and have already been found earlier

                    InventoryItemBase baseItem = new InventoryItemBase(appearance.Wearables[i][j].ItemID, userID);
                    baseItem = invService.GetItem(baseItem);

                    if (baseItem != null)
                    {
                        if (baseItem.AssetType == (int) AssetType.Link)
                        {
                            baseItem = new InventoryItemBase(baseItem.AssetID, userID);
                            baseItem = invService.GetItem(baseItem);
                        }
                        appearance.Wearables[i].Add(baseItem.ID, baseItem.AssetID);
                    }
                    else
                    {
                        MainConsole.Instance.ErrorFormat(
                            "[AvatarFactory]: Can't find inventory item {0} for {1}, setting to default",
                            appearance.Wearables[i][j].ItemID, (WearableType) i);

                        appearance.Wearables[i].RemoveItem(appearance.Wearables[i][j].ItemID);
                        appearance.Wearables[i].Add(AvatarWearable.DefaultWearables[i][j].ItemID,
                                                    AvatarWearable.DefaultWearables[i][j].AssetID);
                    }
                }
            }
        }
        /// <summary>
        ///   Update what the avatar is wearing using an item from their inventory.
        /// </summary>
        /// <param name = "client"></param>
        /// <param name = "e"></param>
        public void AvatarIsWearing(IClientAPI client, AvatarWearingArgs e)
        {
            IScenePresence sp = m_scene.GetScenePresence(client.AgentId);
            if (sp == null)
            {
                MainConsole.Instance.WarnFormat("[AvatarFactory]: AvatarIsWearing unable to find presence for {0}", client.AgentId);
                return;
            }

            MainConsole.Instance.DebugFormat("[AvatarFactory]: AvatarIsWearing called for {0}", client.AgentId);

            // operate on a copy of the appearance so we don't have to lock anything
            IAvatarAppearanceModule appearance = sp.RequestModuleInterface<IAvatarAppearanceModule>();
            AvatarAppearance avatAppearance = new AvatarAppearance(appearance.Appearance, false);

            IOpenRegionSettingsModule module = m_scene.RequestModuleInterface<IOpenRegionSettingsModule>();

            bool NeedsRebake = false;
            if (module != null && module.EnableTeenMode)
            {
                foreach (AvatarWearingArgs.Wearable wear in e.NowWearing)
                {
                    if (wear.Type == 10 & wear.ItemID == UUID.Zero && module.DefaultUnderpants != UUID.Zero)
                    {
                        NeedsRebake = true;
                        wear.ItemID = module.DefaultUnderpants;
                        InventoryItemBase item = new InventoryItemBase(UUID.Random())
                                                     {
                                                         InvType = (int) InventoryType.Wearable,
                                                         AssetType = (int) AssetType.Clothing,
                                                         Name = "Default Underpants",
                                                         Folder =
                                                             m_scene.InventoryService.GetFolderForType(client.AgentId,
                                                                                                       InventoryType.
                                                                                                           Wearable,
                                                                                                       AssetType.
                                                                                                           Clothing).ID,
                                                         Owner = client.AgentId,
                                                         CurrentPermissions = 0,
                                                         CreatorId = UUID.Zero.ToString(),
                                                         AssetID = module.DefaultUnderpants
                                                     };
                        //Locked
                        client.SendInventoryItemCreateUpdate(item, 0);
                    }
                    else if (wear.Type == 10 & wear.ItemID == UUID.Zero)
                    {
                        NeedsRebake = true;
                        InventoryItemBase item = new InventoryItemBase(UUID.Random())
                                                     {
                                                         InvType = (int) InventoryType.Wearable,
                                                         AssetType = (int) AssetType.Clothing,
                                                         Name = "Default Underpants",
                                                         Folder =
                                                             m_scene.InventoryService.GetFolderForType(client.AgentId,
                                                                                                       InventoryType.
                                                                                                           Wearable,
                                                                                                       AssetType.
                                                                                                           Clothing).ID,
                                                         Owner = client.AgentId,
                                                         CurrentPermissions = 0
                                                     };
                        //Locked
                        if (m_underPantsUUID == UUID.Zero)
                        {
                            m_underPantsUUID = UUID.Random();
                            AssetBase asset = new AssetBase(m_underPantsUUID, "Default Underpants", AssetType.Clothing,
                                                            UUID.Zero) {Data = Utils.StringToBytes(m_defaultUnderPants)};
                            asset.FillHash();
                            asset.ID = m_scene.AssetService.Store(asset);
                            m_underPantsUUID = asset.ID;
                        }
                        item.CreatorId = UUID.Zero.ToString();
                        item.AssetID = m_underPantsUUID;
                        m_scene.InventoryService.AddItem(item);
                        client.SendInventoryItemCreateUpdate(item, 0);
                        wear.ItemID = item.ID;
                    }
                    if (wear.Type == 11 && wear.ItemID == UUID.Zero && module.DefaultUndershirt != UUID.Zero)
                    {
                        NeedsRebake = true;
                        wear.ItemID = module.DefaultUndershirt;
                        InventoryItemBase item = new InventoryItemBase(UUID.Random())
                                                     {
                                                         InvType = (int) InventoryType.Wearable,
                                                         AssetType = (int) AssetType.Clothing,
                                                         Name = "Default Undershirt",
                                                         Folder =
                                                             m_scene.InventoryService.GetFolderForType(client.AgentId,
                                                                                                       InventoryType.
                                                                                                           Wearable,
                                                                                                       AssetType.
                                                                                                           Clothing).ID,
                                                         Owner = client.AgentId,
                                                         CurrentPermissions = 0,
                                                         CreatorId = UUID.Zero.ToString(),
                                                         AssetID = module.DefaultUndershirt
                                                     };
                        //Locked
                        client.SendInventoryItemCreateUpdate(item, 0);
                    }
                    else if (wear.Type == 11 & wear.ItemID == UUID.Zero)
                    {
                        NeedsRebake = true;
                        InventoryItemBase item = new InventoryItemBase(UUID.Random())
                                                     {
                                                         InvType = (int) InventoryType.Wearable,
                                                         AssetType = (int) AssetType.Clothing,
                                                         Name = "Default Undershirt",
                                                         Folder =
                                                             m_scene.InventoryService.GetFolderForType(client.AgentId,
                                                                                                       InventoryType.
                                                                                                           Wearable,
                                                                                                       AssetType.
                                                                                                           Clothing).ID,
                                                         Owner = client.AgentId,
                                                         CurrentPermissions = 0
                                                     };
                        //Locked
                        if (m_underShirtUUID == UUID.Zero)
                        {
                            m_underShirtUUID = UUID.Random();
                            AssetBase asset = new AssetBase(m_underShirtUUID, "Default Undershirt", AssetType.Clothing,
                                                            UUID.Zero) {Data = Utils.StringToBytes(m_defaultUnderShirt)};
                            asset.FillHash();
                            asset.ID = m_scene.AssetService.Store(asset);
                            m_underShirtUUID = asset.ID;
                        }
                        item.CreatorId = UUID.Zero.ToString();
                        item.AssetID = m_underShirtUUID;
                        m_scene.InventoryService.AddItem(item);
                        client.SendInventoryItemCreateUpdate(item, 0);
                        wear.ItemID = item.ID;
                    }
                }
            }

#if (!ISWIN)
            foreach (AvatarWearingArgs.Wearable wear in e.NowWearing)
            {
                if (wear.Type < AvatarWearable.MAX_WEARABLES)
                {
                    /*if (incomingLinks.ContainsKey (wear.ItemID))
                    {
                        wear.ItemID = incomingLinks[wear.ItemID];
                    }*/
                    avatAppearance.Wearables[wear.Type].Add(wear.ItemID, UUID.Zero);
                }
            }
#else
            foreach (AvatarWearingArgs.Wearable wear in e.NowWearing.Where(wear => wear.Type < AvatarWearable.MAX_WEARABLES))
            {
                avatAppearance.Wearables[wear.Type].Add(wear.ItemID, UUID.Zero);
            }
#endif

            avatAppearance.GetAssetsFrom(appearance.Appearance);

            // This could take awhile since it needs to pull inventory
            SetAppearanceAssets(sp.UUID, e.NowWearing, appearance.Appearance, ref avatAppearance);

            // could get fancier with the locks here, but in the spirit of "last write wins"
            // this should work correctly, also, we don't need to send the appearance here
            // since the "iswearing" will trigger a new set of visual param and baked texture changes
            // when those complete, the new appearance will be sent
            appearance.Appearance = avatAppearance;
            if (NeedsRebake)
            {
                //Tell the client about the new things it is wearing
                sp.ControllingClient.SendWearables(appearance.Appearance.Wearables, appearance.Appearance.Serial);
                //Then forcefully tell it to rebake
#if (!ISWIN)
                foreach (Primitive.TextureEntryFace t in appearance.Appearance.Texture.FaceTextures)
                {
                    Primitive.TextureEntryFace face = (t);
                    if (face != null)
                    {
                        sp.ControllingClient.SendRebakeAvatarTextures(face.TextureID);
                    }
                }
#else
                foreach (Primitive.TextureEntryFace face in appearance.Appearance.Texture.FaceTextures.Select(t => (t)).Where(face => face != null))
                {
                    sp.ControllingClient.SendRebakeAvatarTextures(face.TextureID);
                }
#endif
            }
            QueueAppearanceSave(sp.UUID);
            //Send the wearables HERE so that the client knows what it is wearing
            //sp.ControllingClient.SendWearables(sp.Appearance.Wearables, sp.Appearance.Serial);
            //Do not save or send the appearance! The client loops back and sends a bunch of SetAppearance
            //  (handled above) and that takes care of it
        }
        /// <summary>
        /// Update an item which is either already in the client's inventory or is within
        /// a transaction
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="transactionID">The transaction ID.  If this is UUID.Zero we will
        /// assume that we are not in a transaction</param>
        /// <param name="itemID">The ID of the updated item</param>
        /// <param name="itemUpd"></param>
        protected void UpdateInventoryItemAsset(IClientAPI remoteClient, UUID transactionID,
                                             UUID itemID, InventoryItemBase itemUpd)
        {
            // This one will let people set next perms on items in agent
            // inventory. Rut-Roh. Whatever. Make this secure. Yeah.
            //
            // Passing something to another avatar or a an object will already
            InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
            item = m_scene.InventoryService.GetItem(item);

            if (item != null)
            {
                if (UUID.Zero == transactionID)
                {
                    uint oldnextperms = item.NextPermissions;
                    bool hasPermissionsChanged = item.NextPermissions != (itemUpd.NextPermissions & item.BasePermissions);
                    item.Name = itemUpd.Name;
                    item.Description = itemUpd.Description;
                    item.NextPermissions = itemUpd.NextPermissions & item.BasePermissions;
                    item.EveryOnePermissions = itemUpd.EveryOnePermissions & item.BasePermissions;
                    item.GroupPermissions = itemUpd.GroupPermissions & item.BasePermissions;
                    item.GroupID = itemUpd.GroupID;
                    item.GroupOwned = itemUpd.GroupOwned;
                    item.CreationDate = itemUpd.CreationDate;
                    // The client sends zero if its newly created?

                    item.CreationDate = itemUpd.CreationDate == 0 ? Util.UnixTimeSinceEpoch() : itemUpd.CreationDate;

                    // TODO: Check if folder changed and move item
                    //item.NextPermissions = itemUpd.Folder;
                    item.InvType = itemUpd.InvType;
                    item.SalePrice = itemUpd.SalePrice;
                    item.SaleType = itemUpd.SaleType;
                    item.Flags = itemUpd.Flags;

                    if ((hasPermissionsChanged) && (item.AssetType == (int)InventoryType.Object))
                    {
						AssetBase asset = m_scene.AssetService.Get(item.AssetID.ToString());
						if (asset != null)
						{
							SceneObjectGroup group =
								SceneObjectSerializer.FromOriginalXmlFormat(Utils.BytesToString(asset.Data), m_scene);

							bool didchange = false;
							//copy
							if ((((PermissionMask)oldnextperms & PermissionMask.Copy) == PermissionMask.Copy) &&
								(((PermissionMask)item.NextPermissions & PermissionMask.Copy) != PermissionMask.Copy))
							{
								didchange = true;
								group.UpdatePermissions(remoteClient.AgentId, 16, 1, (uint)PermissionMask.Copy, 0);
							}
							else if ((((PermissionMask)oldnextperms & PermissionMask.Copy) != PermissionMask.Copy) &&
								(((PermissionMask)item.NextPermissions & PermissionMask.Copy) == PermissionMask.Copy))
							{
								didchange = true;
								group.UpdatePermissions(remoteClient.AgentId, 16, 1, (uint)PermissionMask.Copy, 1);
							}

							//mod
							if ((((PermissionMask)oldnextperms & PermissionMask.Modify) == PermissionMask.Modify) &&
								(((PermissionMask)item.NextPermissions & PermissionMask.Modify) != PermissionMask.Modify))
							{
								didchange = true;
								group.UpdatePermissions(remoteClient.AgentId, 16, 1, (uint)PermissionMask.Modify, 0);
							}
							else if ((((PermissionMask)oldnextperms & PermissionMask.Modify) != PermissionMask.Modify) &&
								(((PermissionMask)item.NextPermissions & PermissionMask.Modify) == PermissionMask.Modify))
							{
								didchange = true;
								group.UpdatePermissions(remoteClient.AgentId, 16, 1, (uint)PermissionMask.Modify, 1);
							}

							//trans
							if ((((PermissionMask)oldnextperms & PermissionMask.Transfer) == PermissionMask.Transfer) &&
								(((PermissionMask)item.NextPermissions & PermissionMask.Transfer) != PermissionMask.Transfer))
							{
								didchange = true;
								group.UpdatePermissions(remoteClient.AgentId, 16, 1, (uint)PermissionMask.Transfer, 0);
							}
							else if ((((PermissionMask)oldnextperms & PermissionMask.Transfer) != PermissionMask.Transfer) &&
								(((PermissionMask)item.NextPermissions & PermissionMask.Transfer) == PermissionMask.Transfer))
							{
								didchange = true;
								group.UpdatePermissions(remoteClient.AgentId, 16, 1, (uint)PermissionMask.Transfer, 1);
							}

							if (didchange)
							{
								asset.Data = Encoding.ASCII.GetBytes(group.ToXml2());
								asset.ID = m_scene.AssetService.Store(asset);
								item.AssetID = asset.ID;
							}
						}
                    }
                    m_scene.InventoryService.UpdateItem(item);
                }
                else
                {
                    IAgentAssetTransactions agentTransactions = m_scene.RequestModuleInterface<IAgentAssetTransactions>();
                    if (agentTransactions != null)
                    {
                        agentTransactions.HandleItemUpdateFromTransaction(
                                     remoteClient, transactionID, item);
                    }
                }
            }
            else
            {
                MainConsole.Instance.Error(
                    "[AGENTINVENTORY]: Item ID " + itemID + " not found for an inventory item update.");
            }
        }
 /// Add an inventory item to an avatar's inventory.
 /// </summary>
 /// <param name="remoteClient">The remote client controlling the avatar</param>
 /// <param name="item">The item.  This structure contains all the item metadata, including the folder
 /// in which the item is to be placed.</param>
 //public void AddInventoryItem(IClientAPI remoteClient, InventoryItemBase item)
 public void AddInventoryItemAsync(IClientAPI remoteClient, InventoryItemBase item)
 {
     m_scene.InventoryService.AddItemAsync(item,
         (itm) => remoteClient.SendInventoryItemCreateUpdate(itm, 0));
 }
        public virtual InventoryItemBase GetItem(InventoryItemBase item)
        {
            if (item == null)
                return null;

            try
            {
                Dictionary<string, object> ret = MakeRequest("GETITEM",
                                                             new Dictionary<string, object>
                                                                 {
                                                                     {"ID", item.ID.ToString()}
                                                                 });

                if (ret == null)
                    return null;
                if (ret.Count == 0)
                    return null;

                return BuildItem((Dictionary<string, object>)ret["item"]);
            }
            catch (Exception e)
            {
                MainConsole.Instance.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception in GetItem: {0}", e.Message);
            }

            return null;
        }
        // Unfortunately we need to use the inherited method because of how DeRez works.
        // The viewer sends the folderID hard-wired in the derez message
        //public override bool AddItem(InventoryItemBase item)
        //{
        //    // Check if it's under the Suitcase folder
        //    List<InventoryFolderBase> skel = base.GetInventorySkeleton(item.Owner);
        //    InventoryFolderBase suitcase = GetRootFolder(item.Owner);
        //    List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
        //    foreach (InventoryFolderBase f in suitDescendents)
        //        if (item.Folder == f.ID)
        //            return m_Database.StoreItem(ConvertFromOpenSim(item));
        //    return false;
        //}
        //public override bool UpdateItem(InventoryItemBase item)
        //{
        //    // Check if it's under the Suitcase folder
        //    List<InventoryFolderBase> skel = base.GetInventorySkeleton(item.Owner);
        //    InventoryFolderBase suitcase = GetRootFolder(item.Owner);
        //    List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
        //    foreach (InventoryFolderBase f in suitDescendents)
        //        if (item.Folder == f.ID)
        //            return m_Database.StoreItem(ConvertFromOpenSim(item));
        //    return false;
        //}
        //public override bool MoveItems(UUID principalID, List<InventoryItemBase> items)
        //{
        //    // Principal is b0rked. *sigh*
        //    //
        //    // Let's assume they all have the same principal
        //    // Check if it's under the Suitcase folder
        //    List<InventoryFolderBase> skel = base.GetInventorySkeleton(items[0].Owner);
        //    InventoryFolderBase suitcase = GetRootFolder(items[0].Owner);
        //    List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
        //    foreach (InventoryItemBase i in items)
        //    {
        //        foreach (InventoryFolderBase f in suitDescendents)
        //            if (i.Folder == f.ID)
        //                m_Database.MoveItem(i.ID.ToString(), i.Folder.ToString());
        //    }
        //    return true;
        //}
        // Let these pass. Use inherited methods.
        //public bool DeleteItems(UUID principalID, List<UUID> itemIDs)
        //{
        //}
        public override InventoryItemBase GetItem(InventoryItemBase item)
        {
            InventoryItemBase it = base.GetItem (item);

            UserAccount user = m_UserAccountService.GetUserAccount (null, UUID.Parse(it.CreatorId));

            // Adjust the creator data
            if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty))
                it.CreatorData = GetHandlers.PROFILE_URL + "/" + it.CreatorId + ";" + user.FirstName + " " + user.LastName;

            return it;
        }
 /// <summary>
 /// Add the given inventory item to a user's inventory.
 /// </summary>
 /// <param name="item">The item to add</param>
 //public void AddInventoryItem(InventoryItemBase item)
 public void AddInventoryItemAsync(InventoryItemBase item)
 {
     m_scene.InventoryService.AddItemAsync(item, null);
 }
 ///<summary>
 ///  Create the archive name for a particular item.
 ///</summary>
 ///These names are prepended with an inventory item's UUID so that more than one item can have the
 ///same name
 ///<param name = "item"></param>
 ///<returns></returns>
 public static string CreateArchiveItemName(InventoryItemBase item)
 {
     return CreateArchiveItemName(item.Name, item.ID);
 }
        protected void SaveInvItem(InventoryItemBase inventoryItem, string path)
        {
            string filename = path + CreateArchiveItemName(inventoryItem);

            // Record the creator of this item for user record purposes (which might go away soon)
            m_userUuids[inventoryItem.CreatorIdAsUuid] = 1;

            InventoryItemBase saveItem = (InventoryItemBase) inventoryItem.Clone();
            saveItem.CreatorId = OspResolver.MakeOspa(saveItem.CreatorIdAsUuid,
                                                      m_registry.RequestModuleInterface<IUserAccountService>());

            string serialization = UserInventoryItemSerializer.Serialize(saveItem);
            m_archiveWriter.WriteFile(filename, serialization);

            m_assetGatherer.GatherAssetUuids(saveItem.AssetID, (AssetType) saveItem.AssetType, m_assetUuids, m_registry);
        }
        private InventoryItemBase BuildItem(Dictionary<string, object> data)
        {
            InventoryItemBase item = new InventoryItemBase();

            try
            {
                item.AssetID = new UUID(data["AssetID"].ToString());
                item.AssetType = int.Parse(data["AssetType"].ToString());
                item.Name = data["Name"].ToString();
                item.Owner = new UUID(data["Owner"].ToString());
                item.ID = new UUID(data["ID"].ToString());
                item.InvType = int.Parse(data["InvType"].ToString());
                item.Folder = new UUID(data["Folder"].ToString());
                item.CreatorId = data["CreatorId"].ToString();
                item.CreatorData = data.ContainsKey("CreatorData") ? data["CreatorData"].ToString() : String.Empty;
                item.Description = data["Description"].ToString();
                item.NextPermissions = uint.Parse(data["NextPermissions"].ToString());
                item.CurrentPermissions = uint.Parse(data["CurrentPermissions"].ToString());
                item.BasePermissions = uint.Parse(data["BasePermissions"].ToString());
                item.EveryOnePermissions = uint.Parse(data["EveryOnePermissions"].ToString());
                item.GroupPermissions = uint.Parse(data["GroupPermissions"].ToString());
                item.GroupID = new UUID(data["GroupID"].ToString());
                item.GroupOwned = bool.Parse(data["GroupOwned"].ToString());
                item.SalePrice = int.Parse(data["SalePrice"].ToString());
                item.SaleType = byte.Parse(data["SaleType"].ToString());
                item.Flags = uint.Parse(data["Flags"].ToString());
                item.CreationDate = int.Parse(data["CreationDate"].ToString());
            }
            catch (Exception e)
            {
                MainConsole.Instance.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception building item: {0}", e.Message);
            }

            return item;
        }
        /// <summary>
        /// Rez a script into a prim's inventory, either ex nihilo or from an existing avatar inventory
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="transactionID"></param>
        /// <param name="localID"></param>
        /// <param name="itemBase"></param>
        protected void RezScript(IClientAPI remoteClient, InventoryItemBase itemBase, UUID transactionID, uint localID)
        {
            UUID itemID = itemBase.ID;
            UUID copyID = UUID.Random();

            if (itemID != UUID.Zero)  // transferred from an avatar inventory to the prim's inventory
            {
                InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
                item = m_scene.InventoryService.GetItem(item);

                if (item != null)
                {
                    ISceneChildEntity part = m_scene.GetSceneObjectPart (localID);
                    if (part != null)
                    {
                        if (!m_scene.Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId))
                            return;

                        part.ParentEntity.AddInventoryItem (remoteClient, localID, item, copyID);
                        part.Inventory.CreateScriptInstance(copyID, 0, false, 0);

                        //                        MainConsole.Instance.InfoFormat("[PRIMINVENTORY]: " +
                        //                                         "Rezzed script {0} into prim local ID {1} for user {2}",
                        //                                         item.inventoryName, localID, remoteClient.Name);
                        part.GetProperties(remoteClient);
                    }
                    else
                    {
                        MainConsole.Instance.ErrorFormat(
                            "[PRIM INVENTORY]: " +
                            "Could not rez script {0} into prim local ID {1} for user {2}"
                            + " because the prim could not be found in the region!",
                            item.Name, localID, remoteClient.Name);
                    }
                }
                else
                {
                    MainConsole.Instance.ErrorFormat(
                        "[PRIM INVENTORY]: Could not find script inventory item {0} to rez for {1}!",
                        itemID, remoteClient.Name);
                }
            }
            else  // script has been rezzed directly into a prim's inventory
            {
                ISceneChildEntity part = m_scene.GetSceneObjectPart (itemBase.Folder);
                if (part == null)
                    return;

                if (!m_scene.Permissions.CanCreateObjectInventory(
                    itemBase.InvType, part.UUID, remoteClient.AgentId))
                    return;

                AssetBase asset = new AssetBase(UUID.Random(), itemBase.Name, (AssetType)itemBase.AssetType,
                                                remoteClient.AgentId)
                                      {
                                          Description = itemBase.Description,
                                          Data = Encoding.ASCII.GetBytes(DefaultLSLScript)
                                      };
                asset.ID = m_scene.AssetService.Store(asset);

                TaskInventoryItem taskItem = new TaskInventoryItem();

                taskItem.ResetIDs(itemBase.Folder);
                taskItem.ParentID = itemBase.Folder;
                taskItem.CreationDate = (uint)itemBase.CreationDate;
                taskItem.Name = itemBase.Name;
                taskItem.Description = itemBase.Description;
                taskItem.Type = itemBase.AssetType;
                taskItem.InvType = itemBase.InvType;
                taskItem.OwnerID = itemBase.Owner;
                taskItem.CreatorID = itemBase.CreatorIdAsUuid;
                taskItem.CreatorData = itemBase.CreatorData;
                taskItem.BasePermissions = itemBase.BasePermissions;
                taskItem.CurrentPermissions = itemBase.CurrentPermissions;
                taskItem.EveryonePermissions = itemBase.EveryOnePermissions;
                taskItem.GroupPermissions = itemBase.GroupPermissions;
                taskItem.NextPermissions = itemBase.NextPermissions;
                taskItem.GroupID = itemBase.GroupID;
                taskItem.GroupPermissions = 0;
                taskItem.Flags = itemBase.Flags;
                taskItem.PermsGranter = UUID.Zero;
                taskItem.PermsMask = 0;
                taskItem.AssetID = asset.ID;
                taskItem.SalePrice = itemBase.SalePrice;
                taskItem.SaleType = itemBase.SaleType;

                part.Inventory.AddInventoryItem(taskItem, false);
                part.GetProperties(remoteClient);

                part.Inventory.CreateScriptInstance(taskItem, 0, false, StateSource.NewRez);
            }
        }
 /// <summary>
 /// Create a new Inventory Item
 /// </summary>
 /// <param name="remoteClient"></param>
 /// <param name="creatorData"></param>
 /// <param name="folderID"></param>
 /// <param name="flags"></param>
 /// <param name="callbackID"></param>
 /// <param name="asset"></param>
 /// <param name="invType"></param>
 /// <param name="everyoneMask"></param>
 /// <param name="nextOwnerMask"></param>
 /// <param name="groupMask"></param>
 /// <param name="creationDate"></param>
 /// <param name="creatorID"></param>
 /// <param name="name"></param>
 /// <param name="baseMask"></param>
 /// <param name="currentMask"></param>
 protected void CreateNewInventoryItem(
     IClientAPI remoteClient, string creatorID, string creatorData, UUID folderID, string name, uint flags, uint callbackID, AssetBase asset, sbyte invType,
     uint baseMask, uint currentMask, uint everyoneMask, uint nextOwnerMask, uint groupMask, int creationDate)
 {
     InventoryItemBase item = new InventoryItemBase
                                  {
                                      Owner = remoteClient.AgentId,
                                      CreatorId = creatorID,
                                      CreatorData = creatorData,
                                      ID = UUID.Random(),
                                      AssetID = asset.ID,
                                      Description = asset.Description,
                                      Name = name,
                                      Flags = flags,
                                      AssetType = asset.Type,
                                      InvType = invType,
                                      Folder = folderID,
                                      CurrentPermissions = currentMask,
                                      NextPermissions = nextOwnerMask,
                                      EveryOnePermissions = everyoneMask,
                                      GroupPermissions = groupMask,
                                      BasePermissions = baseMask,
                                      CreationDate = creationDate
                                  };
     m_scene.InventoryService.AddItemAsync(item, (itm) =>
     {
         IAvatarFactory avFactory = m_scene.RequestModuleInterface<IAvatarFactory>();
         if (avFactory != null)
             avFactory.NewAppearanceLink(itm);
         remoteClient.SendInventoryItemCreateUpdate(itm, callbackID);
     });
 }
        /// <summary>
        /// Change a task inventory item to a user inventory item
        /// </summary>
        /// <param name="destAgent">The agent who will own the inventory item</param>
        /// <param name="part">The object that the item is in</param>
        /// <param name="itemId">The item to convert</param>
        /// <returns></returns>
        private InventoryItemBase CreateAgentInventoryItemFromTask (UUID destAgent, ISceneChildEntity part, UUID itemId)
        {
            TaskInventoryItem taskItem = part.Inventory.GetInventoryItem(itemId);

            if (null == taskItem)
            {
                MainConsole.Instance.ErrorFormat(
                    "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for creating an avatar"
                        + " inventory item from a prim's inventory item "
                        + " but the required item does not exist in the prim's inventory",
                    itemId, part.Name, part.UUID);

                return null;
            }

            if ((destAgent != taskItem.OwnerID) && ((taskItem.CurrentPermissions & (uint)PermissionMask.Transfer) == 0))
            {
                return null;
            }

            InventoryItemBase agentItem = new InventoryItemBase
                                              {
                                                  ID = UUID.Random(),
                                                  CreatorId = taskItem.CreatorID.ToString(),
                                                  CreatorData = taskItem.CreatorData,
                                                  Owner = destAgent,
                                                  AssetID = taskItem.AssetID,
                                                  Description = taskItem.Description,
                                                  Name = taskItem.Name,
                                                  AssetType = taskItem.Type,
                                                  InvType = taskItem.InvType,
                                                  Flags = taskItem.Flags,
                                                  SalePrice = taskItem.SalePrice,
                                                  SaleType = taskItem.SaleType
                                              };


            if ((part.OwnerID != destAgent) && m_scene.Permissions.PropagatePermissions())
            {
                agentItem.BasePermissions = taskItem.BasePermissions & (taskItem.NextPermissions | (uint)PermissionMask.Move);
                if (taskItem.InvType == (int)InventoryType.Object)
                    agentItem.CurrentPermissions = agentItem.BasePermissions & (((taskItem.CurrentPermissions & 7) << 13) | (taskItem.CurrentPermissions & (uint)PermissionMask.Move));
                else
                    agentItem.CurrentPermissions = agentItem.BasePermissions & taskItem.CurrentPermissions;
                
                agentItem.CurrentPermissions |= 16; // Slam
                agentItem.NextPermissions = taskItem.NextPermissions;
                agentItem.EveryOnePermissions = taskItem.EveryonePermissions & (taskItem.NextPermissions | (uint)PermissionMask.Move);
                agentItem.GroupPermissions = taskItem.GroupPermissions & taskItem.NextPermissions;
            }
            else
            {
                agentItem.BasePermissions = taskItem.BasePermissions;
                agentItem.CurrentPermissions = taskItem.CurrentPermissions;
                agentItem.NextPermissions = taskItem.NextPermissions;
                agentItem.EveryOnePermissions = taskItem.EveryonePermissions;
                agentItem.GroupPermissions = taskItem.GroupPermissions;
            }

            if (!m_scene.Permissions.BypassPermissions())
            {
                if ((taskItem.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
                    part.Inventory.RemoveInventoryItem(itemId);
            }

            return agentItem;
        }
        public virtual bool UpdateItem(InventoryItemBase item)
        {
            if (item == null)
                return false;

            if (item.CreatorData == null)
                item.CreatorData = String.Empty;

            Dictionary<string, object> ret = MakeRequest("UPDATEITEM",
                                                         new Dictionary<string, object>
                                                             {
                                                                 {"AssetID", item.AssetID.ToString()},
                                                                 {"AssetType", item.AssetType.ToString()},
                                                                 {"Name", item.Name},
                                                                 {"Owner", item.Owner.ToString()},
                                                                 {"ID", item.ID.ToString()},
                                                                 {"InvType", item.InvType.ToString()},
                                                                 {"Folder", item.Folder.ToString()},
                                                                 {"CreatorId", item.CreatorId},
                                                                 {"CreatorData", item.CreatorData},
                                                                 {"Description", item.Description},
                                                                 {"NextPermissions", item.NextPermissions.ToString()},
                                                                 {
                                                                     "CurrentPermissions",
                                                                     item.CurrentPermissions.ToString()
                                                                     },
                                                                 {"BasePermissions", item.BasePermissions.ToString()},
                                                                 {
                                                                     "EveryOnePermissions",
                                                                     item.EveryOnePermissions.ToString()
                                                                     },
                                                                 {"GroupPermissions", item.GroupPermissions.ToString()},
                                                                 {"GroupID", item.GroupID.ToString()},
                                                                 {"GroupOwned", item.GroupOwned.ToString()},
                                                                 {"SalePrice", item.SalePrice.ToString()},
                                                                 {"SaleType", item.SaleType.ToString()},
                                                                 {"Flags", item.Flags.ToString()},
                                                                 {"CreationDate", item.CreationDate.ToString()}
                                                             });

            if (ret == null)
                return false;

            return bool.Parse(ret["RESULT"].ToString());
        }
 /// <summary>
 /// 
 public void AddInventoryItem(InventoryItemBase item)
 {
     m_scene.InventoryService.AddItem(item);
 }
Beispiel #24
0
        private void Delete(UUID userID, List<string> nodes, List<string> types)
        {
            List<UUID> items = new List<UUID>();
            List<UUID> folders = new List<UUID>();
            SplitNodes(userID, nodes, types, items, folders);

            var trash = m_InventoryService.GetFolderForType(userID, InventoryType.Folder, AssetType.TrashFolder);
            if (trash != null)
            {
                List<InventoryItemBase> its = new List<InventoryItemBase>();
                foreach (UUID uuid in items)
                {
                    InventoryItemBase itbase = new InventoryItemBase();
                    itbase.ID = uuid;
                    itbase.Folder = UUID.Zero;
                    its.Add(itbase);
                }
                m_InventoryService.MoveItems(userID, its);

                bool purgeTrash = false;
                foreach (UUID uuid in folders)
                {
                    InventoryFolderBase fbase = new InventoryFolderBase(uuid, userID);
                    //if (uuid == trash)
                    //    purgeTrash = true;
                    //else
                    {
                        fbase.ParentID = UUID.Zero;
                        m_InventoryService.MoveFolder(fbase);
                    }
                }
                if (purgeTrash)
                {
                    InventoryFolderBase fbase = new InventoryFolderBase(UUID.Zero, userID);
                    m_InventoryService.PurgeFolder(fbase);
                }
            }
        }
        /// <summary>
        /// Handle a fetch inventory request from the client
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="itemID"></param>
        /// <param name="ownerID"></param>
        protected void HandleFetchInventory(IClientAPI remoteClient, UUID itemID, UUID ownerID)
        {
            //MainConsole.Instance.Warn("[Scene.PacketHandler]: Depriated UDP Inventory request!");
            InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
            item = m_scene.InventoryService.GetItem(item);

            if (item != null)
            {
                remoteClient.SendInventoryItemDetails(ownerID, item);
            }
            // else shouldn't we send an alert message?
        }
Beispiel #26
0
        private void Move(UUID userID, List<string> nodes, List<string> types, string folder)
        {
            UUID folderID = UUID.Zero;
            if (UUID.TryParse(folder, out folderID))
            {
                List<UUID> items = new List<UUID>();
                List<UUID> folders = new List<UUID>();
                SplitNodes(userID, nodes, types, items, folders);

                List<InventoryItemBase> its = new List<InventoryItemBase>();
                foreach (UUID uuid in items)
                {
                    InventoryItemBase itbase = new InventoryItemBase();
                    itbase.ID = uuid;
                    itbase.Folder = folderID;
                    its.Add(itbase);
                }
                m_InventoryService.MoveItems(userID, its);

                foreach (UUID uuid in folders)
                {
                    InventoryFolderBase fbase = new InventoryFolderBase();
                    fbase.ID = uuid;
                    fbase.ParentID = folderID;
                    m_InventoryService.MoveFolder(fbase);
                }
            }
        }
        /// <summary>
        /// Copy an inventory item in the user's inventory
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="callbackID"></param>
        /// <param name="oldAgentID"></param>
        /// <param name="oldItemID"></param>
        /// <param name="newFolderID"></param>
        /// <param name="newName"></param>
        protected void CopyInventoryItem(IClientAPI remoteClient, uint callbackID, UUID oldAgentID, UUID oldItemID,
                                      UUID newFolderID, string newName)
        {
            MainConsole.Instance.DebugFormat(
                "[AGENT INVENTORY]: CopyInventoryItem received by {0} with oldAgentID {1}, oldItemID {2}, new FolderID {3}, newName {4}",
                remoteClient.AgentId, oldAgentID, oldItemID, newFolderID, newName);

            InventoryItemBase item = new InventoryItemBase(oldItemID, remoteClient.AgentId);
            item = m_scene.InventoryService.GetItem(item);
            if (item == null)
            {
                MainConsole.Instance.Error("[AGENT INVENTORY]: Failed to find item " + oldItemID.ToString());
                return;
            }

            if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
                return;

            m_scene.AssetService.Get(item.AssetID.ToString(), null, (id, sender, asset) =>
                {
                    if (asset != null)
                    {
                        if (newName != String.Empty)
                        {
                            asset.Name = newName;
                        }
                        else
                        {
                            newName = item.Name;
                        }

                        if (remoteClient.AgentId == oldAgentID)
                        {
                            CreateNewInventoryItem(
                                remoteClient, item.CreatorId, item.CreatorData, newFolderID, newName, item.Flags, callbackID, asset, (sbyte)item.InvType,
                                item.BasePermissions, item.CurrentPermissions, item.EveryOnePermissions, item.NextPermissions, item.GroupPermissions, Util.UnixTimeSinceEpoch());
                        }
                        else
                        {
                            // If item is transfer or permissions are off or calling agent is allowed to copy item owner's inventory item.
                            if (((item.CurrentPermissions & (uint)PermissionMask.Transfer) != 0) && (m_scene.Permissions.BypassPermissions() || m_scene.Permissions.CanCopyUserInventory(remoteClient.AgentId, oldItemID)))
                            {
                                CreateNewInventoryItem(
                                    remoteClient, item.CreatorId, item.CreatorData, newFolderID, newName, item.Flags, callbackID, asset, (sbyte)item.InvType,
                                    item.NextPermissions, item.NextPermissions, item.EveryOnePermissions & item.NextPermissions, item.NextPermissions, item.GroupPermissions, Util.UnixTimeSinceEpoch());
                            }
                        }
                    }
                    else
                    {
                        MainConsole.Instance.ErrorFormat(
                            "[AGENT INVENTORY]: Could not copy item {0} since asset {1} could not be found",
                            item.Name, item.AssetID);
                    }
                });
        }
        /// <summary>
        ///   Check whether the specified user can view the given notecard
        /// </summary>
        /// <param name = "script"></param>
        /// <param name = "objectID"></param>
        /// <param name = "user"></param>
        /// <param name = "scene"></param>
        /// <returns></returns>
        private bool CanViewNotecard(UUID notecard, UUID objectID, UUID user, IScene scene)
        {
            DebugPermissionInformation(MethodBase.GetCurrentMethod().Name);
            if (m_bypassPermissions) return m_bypassPermissionsValue;

            DebugPermissionInformation(MethodBase.GetCurrentMethod().Name);
            if (m_bypassPermissions) return m_bypassPermissionsValue;

            if (IsAdministrator(user))
                return true;

            if (objectID == UUID.Zero) // User inventory
            {
                IInventoryService invService = m_scene.InventoryService;
                InventoryItemBase assetRequestItem = new InventoryItemBase(notecard, user);
                assetRequestItem = invService.GetItem(assetRequestItem);
                if (assetRequestItem == null) // Library item
                {
                    //Can't find, can't read
                    return false;
                }

                // SL is rather harebrained here. In SL, a script you
                // have mod/copy no trans is readable. This subverts
                // permissions, but is used in some products, most
                // notably Hippo door plugin and HippoRent 5 networked
                // prim counter.
                // To enable this broken SL-ism, remove Transfer from
                // the below expressions.
                // Trying to improve on SL perms by making a script
                // readable only if it's really full perms
                //
                if ((assetRequestItem.CurrentPermissions &
                     ((uint) PermissionMask.Modify |
                      (uint) PermissionMask.Copy |
                      (uint) PermissionMask.Transfer)) !=
                    ((uint) PermissionMask.Modify |
                     (uint) PermissionMask.Copy |
                     (uint) PermissionMask.Transfer))
                    return false;
            }
            else // Prim inventory
            {
                ISceneChildEntity part = scene.GetSceneObjectPart(objectID);

                if (part == null)
                {
                    MainConsole.Instance.Warn("[PERMISSIONS]: NULL PRIM IN canViewNotecard! " + objectID);
                    return false;
                }

                if (part.OwnerID != user)
                {
                    if (part.GroupID != UUID.Zero)
                    {
                        if (!IsGroupMember(part.GroupID, user, 0))
                            return false;

                        if ((part.GroupMask & (uint) PermissionMask.Modify) == 0)
                            return false;
                    }
                }
                else
                {
                    if ((part.OwnerMask & (uint) PermissionMask.Modify) == 0)
                        return false;
                }

                TaskInventoryItem ti = part.Inventory.GetInventoryItem(notecard);

                if (ti == null)
                    return false;

                if (ti.OwnerID != user)
                {
                    if (ti.GroupID == UUID.Zero)
                        return false;

                    if (!IsGroupMember(ti.GroupID, user, 0))
                        return false;
                }

                // Require full perms
                if ((ti.CurrentPermissions &
                     ((uint) PermissionMask.Modify |
                      (uint) PermissionMask.Copy |
                      (uint) PermissionMask.Transfer)) !=
                    ((uint) PermissionMask.Modify |
                     (uint) PermissionMask.Copy |
                     (uint) PermissionMask.Transfer))
                    return false;
            }

            return true;
        }
        /// <summary>
        /// Change an inventory items flags
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="itemID"></param>
        /// <param name="Flags"></param>
        protected void ChangeInventoryItemFlags(IClientAPI remoteClient, UUID itemID, uint Flags)
        {
            InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
            item = m_scene.InventoryService.GetItem(item);

            if (item != null)
            {
                item.Flags = Flags;

                m_scene.InventoryService.UpdateItem(item);
                remoteClient.SendInventoryItemDetails(item.Owner, item);
            }
            else
            {
                MainConsole.Instance.Error(
                    "[AGENTINVENTORY]: Item ID " + itemID + " not found for an inventory item update.");
            }
        }
 public void NewAppearanceLink(InventoryItemBase item)
 {
     /*if (item.InvType == (int)InventoryType.Wearable)
     {
         incomingLinks[item.AssetID] = item.ID;
     }*/
 }