From 1cd6b71b60d093b451ba03881ee31efd3eb29a50 Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Thu, 26 Jun 2008 02:46:29 +0000 Subject: Mantis#1594. Thank you, Melanie for a patch that: Fixes: - Wearable icon and name sreset to default on copy/paste - Cache is not updated when renaming/moving folders - Partial refactor to make inventory less dependen on AssetBase having a "Name" field - Add llGiveInventoryList() function --- .../Communications/Cache/CachedUserInfo.cs | 11 ++ .../Region/Environment/Scenes/Scene.Inventory.cs | 142 +++++++++++++-------- .../ScriptEngine/Common/LSL_BuiltIn_Commands.cs | 37 +++++- .../Shared/Api/Implementation/LSL_Api.cs | 38 +++++- 4 files changed, 176 insertions(+), 52 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs index d010bd5..3127bd6 100644 --- a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs +++ b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs @@ -380,6 +380,13 @@ namespace OpenSim.Framework.Communications.Cache baseFolder.Version = RootFolder.Version; m_commsManager.InventoryService.UpdateFolder(baseFolder); + + InventoryFolderImpl folder=RootFolder.FindFolder(folderID); + if(folder != null) + { + folder.Name = name; + folder.ParentID = parentID; + } } else { @@ -416,6 +423,10 @@ namespace OpenSim.Framework.Communications.Cache m_commsManager.InventoryService.MoveFolder(baseFolder); + InventoryFolderImpl folder=RootFolder.FindFolder(folderID); + if(folder != null) + folder.ParentID = parentID; + return true; } else diff --git a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs index b076855..05c0a28 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs @@ -88,61 +88,52 @@ namespace OpenSim.Region.Environment.Scenes } } - /// - /// Add an inventory item to an avatar's inventory. - /// - /// The remote client controlling the avatar - /// The item. This structure contains all the item metadata, including the folder - /// in which the item is to be placed. - public void AddInventoryItem(IClientAPI remoteClient, InventoryItemBase item) + public void AddInventoryItem(LLUUID AgentID, InventoryItemBase item) { CachedUserInfo userInfo - = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); + = CommsManager.UserProfileCacheService.GetUserDetails(AgentID); if (userInfo != null) { userInfo.AddItem(item); - remoteClient.SendInventoryItemCreateUpdate(item); int userlevel = 0; - if (ExternalChecks.ExternalChecksCanBeGodLike(remoteClient.AgentId)) + if (ExternalChecks.ExternalChecksCanBeGodLike(AgentID)) { userlevel = 1; } - if (m_regInfo.MasterAvatarAssignedUUID == remoteClient.AgentId) + if (m_regInfo.MasterAvatarAssignedUUID == AgentID) { userlevel = 2; } - EventManager.TriggerOnNewInventoryItemUploadComplete(remoteClient.AgentId, item.AssetID, item.Name, userlevel); + EventManager.TriggerOnNewInventoryItemUploadComplete(AgentID, item.AssetID, item.Name, userlevel); } else { m_log.ErrorFormat( - "[AGENT INVENTORY]: Agent {0} {1} was not found for add of item {2} {3}", - remoteClient.Name, remoteClient.AgentId, item.Name, item.ID); + "[AGENT INVENTORY]: Agent {1} was not found for add of item {2} {3}", + AgentID, item.Name, item.ID); return; } } /// - /// AddInventoryItem(LLUUID, InventoryItemBase) + /// Add an inventory item to an avatar's inventory. /// - /// The ID of the avatar + /// The remote client controlling the avatar /// The item. This structure contains all the item metadata, including the folder /// in which the item is to be placed. - public void AddInventoryItem(LLUUID avatarId, InventoryItemBase item) + public void AddInventoryItem(IClientAPI remoteClient, InventoryItemBase item) { - ScenePresence avatar; + CachedUserInfo userInfo + = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); - if (!TryGetAvatar(avatarId, out avatar)) + if (userInfo != null) { - m_log.ErrorFormat( - "[AGENT INVENTORY]: Could not find avatar {0} to add inventory item", avatarId); - return; + AddInventoryItem(remoteClient.AgentId, item); + remoteClient.SendInventoryItemCreateUpdate(item); } - - AddInventoryItem(avatar.ControllingClient, item); } /// @@ -517,13 +508,13 @@ namespace OpenSim.Region.Environment.Scenes if (remoteClient.AgentId == oldAgentID) { CreateNewInventoryItem( - remoteClient, newFolderID, callbackID, asset, (sbyte)item.InvType, + remoteClient, newFolderID, item.Name, item.Flags, callbackID, asset, (sbyte)item.InvType, item.BasePermissions, item.CurrentPermissions, item.EveryOnePermissions, item.NextPermissions); } else { CreateNewInventoryItem( - remoteClient, newFolderID, callbackID, asset, (sbyte)item.InvType, + remoteClient, newFolderID, item.Name, item.Flags, callbackID, asset, (sbyte)item.InvType, item.NextPermissions, item.NextPermissions, item.EveryOnePermissions & item.NextPermissions, item.NextPermissions); } } @@ -619,11 +610,11 @@ namespace OpenSim.Region.Environment.Scenes /// /// /// - private void CreateNewInventoryItem(IClientAPI remoteClient, LLUUID folderID, uint callbackID, + private void CreateNewInventoryItem(IClientAPI remoteClient, LLUUID folderID, string name, uint flags, uint callbackID, AssetBase asset, sbyte invType, uint nextOwnerMask) { CreateNewInventoryItem( - remoteClient, folderID, callbackID, asset, invType, + remoteClient, folderID, name, flags, callbackID, asset, invType, (uint)PermissionMask.All, (uint)PermissionMask.All, 0, nextOwnerMask); } @@ -637,7 +628,7 @@ namespace OpenSim.Region.Environment.Scenes /// /// private void CreateNewInventoryItem( - IClientAPI remoteClient, LLUUID folderID, uint callbackID, AssetBase asset, sbyte invType, + IClientAPI remoteClient, LLUUID folderID, string name, uint flags, uint callbackID, AssetBase asset, sbyte invType, uint baseMask, uint currentMask, uint everyoneMask, uint nextOwnerMask) { CachedUserInfo userInfo @@ -651,7 +642,8 @@ namespace OpenSim.Region.Environment.Scenes item.ID = LLUUID.Random(); item.AssetID = asset.FullID; item.Description = asset.Description; - item.Name = asset.Name; + item.Name = name; + item.Flags = flags; item.AssetType = asset.Type; item.InvType = invType; item.Folder = folderID; @@ -715,7 +707,7 @@ namespace OpenSim.Region.Environment.Scenes AssetBase asset = CreateAsset(name, description, assetType, data); AssetCache.AddAsset(asset); - CreateNewInventoryItem(remoteClient, folderID, callbackID, asset, invType, nextOwnerMask); + CreateNewInventoryItem(remoteClient, folderID, asset.Name, 0, callbackID, asset, invType, nextOwnerMask); } else { @@ -864,38 +856,29 @@ namespace OpenSim.Region.Environment.Scenes } } - /// - /// Move the given item in the given prim to a folder in the client's inventory - /// - /// - /// - /// - /// - public void MoveTaskInventoryItem(IClientAPI remoteClient, LLUUID folderId, SceneObjectPart part, LLUUID itemId) + private InventoryItemBase CreateAgentInventoryItemFromTask(LLUUID destAgent, SceneObjectPart part, LLUUID itemId) { - TaskInventoryItem taskItem = part.GetInventoryItem(itemId); if (null == taskItem) { // Console already notified of error in GetInventoryItem - return; + return null; } InventoryItemBase agentItem = new InventoryItemBase(); agentItem.ID = LLUUID.Random(); agentItem.Creator = taskItem.CreatorID; - agentItem.Owner = remoteClient.AgentId; + agentItem.Owner = destAgent; agentItem.AssetID = taskItem.AssetID; agentItem.Description = taskItem.Description; agentItem.Name = taskItem.Name; agentItem.AssetType = taskItem.Type; agentItem.InvType = taskItem.InvType; - agentItem.Folder = folderId; agentItem.Flags = taskItem.Flags; - if ((remoteClient.AgentId != taskItem.OwnerID) && ExternalChecks.ExternalChecksPropagatePermissions()) + if ((destAgent != taskItem.OwnerID) && ExternalChecks.ExternalChecksPropagatePermissions()) { agentItem.BasePermissions = taskItem.NextOwnerMask; agentItem.CurrentPermissions = taskItem.NextOwnerMask; @@ -910,13 +893,29 @@ namespace OpenSim.Region.Environment.Scenes agentItem.EveryOnePermissions = taskItem.EveryoneMask; } - AddInventoryItem(remoteClient, agentItem); if (!ExternalChecks.ExternalChecksBypassPermissions()) { if ((taskItem.OwnerMask & (uint)PermissionMask.Copy) == 0) part.RemoveInventoryItem(itemId); } + return agentItem; + } + + /// + /// Move the given item in the given prim to a folder in the client's inventory + /// + /// + /// + /// + /// + public void MoveTaskInventoryItem(IClientAPI remoteClient, LLUUID folderId, SceneObjectPart part, LLUUID itemId) + { + + InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(remoteClient.AgentId, part, itemId); + + agentItem.Folder = folderId; + AddInventoryItem(remoteClient, agentItem); } /// @@ -964,14 +963,22 @@ namespace OpenSim.Region.Environment.Scenes if (TryGetAvatar(avatarId, out avatar)) { - MoveTaskInventoryItem(avatar.ControllingClient, folderId, part, itemId); + MoveTaskInventoryItem(avatar.ControllingClient, folderId, part, itemId); } else { - m_log.ErrorFormat( - "[PRIM INVENTORY]: " + - "Avatar {0} cannot be found to update its prim item asset", - avatarId); + CachedUserInfo profile = CommsManager.UserProfileCacheService.GetUserDetails(avatarId); + if(profile == null || profile.RootFolder == null) + { + m_log.ErrorFormat( + "[PRIM INVENTORY]: " + + "Avatar {0} cannot be found to add item", + avatarId); + } + InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(avatarId, part, itemId); + agentItem.Folder = folderId; + + AddInventoryItem(avatarId, agentItem); } } @@ -1047,6 +1054,41 @@ namespace OpenSim.Region.Environment.Scenes } + public void MoveTaskInventoryItems(LLUUID destID, string category, SceneObjectPart host, List items) + { + CachedUserInfo profile = CommsManager.UserProfileCacheService.GetUserDetails(destID); + if(profile == null || profile.RootFolder == null) + { + m_log.ErrorFormat( + "[PRIM INVENTORY]: " + + "Avatar {0} cannot be found to add items", + destID); + return; + } + + LLUUID newFolderID = LLUUID.Random(); + + profile.CreateFolder(category, newFolderID, 0xffff, profile.RootFolder.ID); + + foreach (LLUUID itemID in items) + { + InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(destID, host, itemID); + agentItem.Folder = newFolderID; + + AddInventoryItem(destID, agentItem); + } + + ScenePresence avatar; + + if (TryGetAvatar(destID, out avatar)) + { + profile.SendInventoryDecendents(avatar.ControllingClient, + profile.RootFolder.ID, true, false); + profile.SendInventoryDecendents(avatar.ControllingClient, + newFolderID, false, true); + } + } + /// /// Update an item in a prim (task) inventory. /// This method does not handle scripts, RezScript(IClientAPI, LLUUID, unit) diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs index a9d1309..366b20c 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs @@ -4374,10 +4374,45 @@ namespace OpenSim.Region.ScriptEngine.Common NotImplemented("llGroundRepel"); } + private LLUUID GetTaskInventoryItem(string name) + { + foreach (KeyValuePair inv in m_host.TaskInventory) + { + if(inv.Value.Name == name) + return inv.Key; + } + return LLUUID.Zero; + } + public void llGiveInventoryList(string destination, string category, LSL_Types.list inventory) { m_host.AddScriptLPS(1); - NotImplemented("llGiveInventoryList"); + + LLUUID destID; + if(!LLUUID.TryParse(destination, out destID)) + return; + + List itemList = new List(); + + foreach (Object item in inventory.Data) + { + LLUUID itemID; + if(LLUUID.TryParse(item.ToString(), out itemID)) + { + itemList.Add(itemID); + } + else + { + itemID = GetTaskInventoryItem(item.ToString()); + if(itemID != LLUUID.Zero) + itemList.Add(itemID); + } + } + + if(itemList.Count == 0) + return; + + m_ScriptEngine.World.MoveTaskInventoryItems(destID, category, m_host, itemList); } public void llSetVehicleType(int type) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 57c1e02..1d4a72e 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -36,6 +36,7 @@ using Axiom.Math; using libsecondlife; using OpenSim; using OpenSim.Framework; +using OpenSim.Framework.Communications.Cache; using OpenSim.Region.Environment; using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney; @@ -4226,10 +4227,45 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api NotImplemented("llGroundRepel"); } + private LLUUID GetTaskInventoryItem(string name) + { + foreach (KeyValuePair inv in m_host.TaskInventory) + { + if(inv.Value.Name == name) + return inv.Key; + } + return LLUUID.Zero; + } + public void llGiveInventoryList(string destination, string category, LSL_Types.list inventory) { m_host.AddScriptLPS(1); - NotImplemented("llGiveInventoryList"); + + LLUUID destID; + if(!LLUUID.TryParse(destination, out destID)) + return; + + List itemList = new List(); + + foreach (Object item in inventory.Data) + { + LLUUID itemID; + if(LLUUID.TryParse(item.ToString(), out itemID)) + { + itemList.Add(itemID); + } + else + { + itemID = GetTaskInventoryItem(item.ToString()); + if(itemID != LLUUID.Zero) + itemList.Add(itemID); + } + } + + if(itemList.Count == 0) + return; + + m_ScriptEngine.World.MoveTaskInventoryItems(destID, category, m_host, itemList); } public void llSetVehicleType(int type) -- cgit v1.1