From d10c79d4216436fd2a5056dbf853f317967202af Mon Sep 17 00:00:00 2001
From: Jeff Ames
Date: Sun, 18 Nov 2007 13:50:46 +0000
Subject: first stab at implementation of CopyInventoryItem
---
.../Framework/Communications/Cache/AssetCache.cs | 11 ++
.../Communications/Cache/LibraryRootFolder.cs | 31 ++---
.../Communications/Cache/UserProfileCache.cs | 5 +-
OpenSim/Framework/IClientAPI.cs | 4 +
OpenSim/Region/ClientStack/ClientView.API.cs | 1 +
.../ClientStack/ClientView.ProcessPackets.cs | 10 ++
.../Region/Environment/Scenes/Scene.Inventory.cs | 127 ++++++++++++++-------
OpenSim/Region/Environment/Scenes/Scene.cs | 1 +
.../Region/Examples/SimpleApp/MyNpcCharacter.cs | 1 +
9 files changed, 134 insertions(+), 57 deletions(-)
(limited to 'OpenSim')
diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs
index 0ea33ff..99041c1 100644
--- a/OpenSim/Framework/Communications/Cache/AssetCache.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs
@@ -239,6 +239,17 @@ namespace OpenSim.Framework.Communications.Cache
//Todo should delete it from memory too
}
+ public AssetBase CopyAsset(LLUUID assetID)
+ {
+ AssetBase asset = GetAsset(assetID);
+ if (asset == null)
+ return null;
+
+ asset.FullID = LLUUID.Random(); // TODO: check for conflicts
+ AddAsset(asset);
+ return asset;
+ }
+
///
///
///
diff --git a/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs b/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs
index 05caa84..62251bc 100644
--- a/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs
+++ b/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs
@@ -88,7 +88,8 @@ namespace OpenSim.Framework.Communications.Cache
item.assetID = new LLUUID("00000000-0000-0000-9999-000000000002");
item.inventoryDescription = "Plywood texture";
item.inventoryName = "Plywood";
- item.assetType = 0;
+ item.assetType = (int) AssetType.Texture;
+ item.invType = (int) InventoryType.Texture;
item.parentFolderID = m_textureFolder.folderID;
item.inventoryBasePermissions = 0x7FFFFFFF;
item.inventoryEveryOnePermissions = 0x7FFFFFFF;
@@ -103,7 +104,8 @@ namespace OpenSim.Framework.Communications.Cache
item.assetID = new LLUUID("00000000-0000-0000-9999-000000000003");
item.inventoryDescription = "Rocks texture";
item.inventoryName = "Rocks";
- item.assetType = 0;
+ item.assetType = (int) AssetType.Texture;
+ item.invType = (int) InventoryType.Texture;
item.parentFolderID = m_textureFolder.folderID;
item.inventoryBasePermissions = 0x7FFFFFFF;
item.inventoryEveryOnePermissions = 0x7FFFFFFF;
@@ -118,7 +120,8 @@ namespace OpenSim.Framework.Communications.Cache
item.assetID = new LLUUID("00000000-0000-0000-9999-000000000001");
item.inventoryDescription = "Bricks texture";
item.inventoryName = "Bricks";
- item.assetType = 0;
+ item.assetType = (int) AssetType.Texture;
+ item.invType = (int) InventoryType.Texture;
item.parentFolderID = m_textureFolder.folderID;
item.inventoryBasePermissions = 0x7FFFFFFF;
item.inventoryEveryOnePermissions = 0x7FFFFFFF;
@@ -133,7 +136,8 @@ namespace OpenSim.Framework.Communications.Cache
item.assetID = new LLUUID("00000000-0000-0000-9999-000000000004");
item.inventoryDescription = "Granite texture";
item.inventoryName = "Granite";
- item.assetType = 0;
+ item.assetType = (int) AssetType.Texture;
+ item.invType = (int) InventoryType.Texture;
item.parentFolderID = m_textureFolder.folderID;
item.inventoryBasePermissions = 0x7FFFFFFF;
item.inventoryEveryOnePermissions = 0x7FFFFFFF;
@@ -148,7 +152,8 @@ namespace OpenSim.Framework.Communications.Cache
item.assetID = new LLUUID("00000000-0000-0000-9999-000000000005");
item.inventoryDescription = "Hardwood texture";
item.inventoryName = "Hardwood";
- item.assetType = 0;
+ item.assetType = (int) AssetType.Texture;
+ item.invType = (int) InventoryType.Texture;
item.parentFolderID = m_textureFolder.folderID;
item.inventoryBasePermissions = 0x7FFFFFFF;
item.inventoryEveryOnePermissions = 0x7FFFFFFF;
@@ -163,8 +168,8 @@ namespace OpenSim.Framework.Communications.Cache
item.assetID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
item.inventoryDescription = "Default Shape";
item.inventoryName = "Default Shape";
- item.assetType = 13;
- item.invType = 18;
+ item.assetType = (int) AssetType.Bodypart;
+ item.invType = (int) InventoryType.Wearable;
item.parentFolderID = folderID;
item.inventoryCurrentPermissions = 0;
item.inventoryNextPermissions = 0;
@@ -177,8 +182,8 @@ namespace OpenSim.Framework.Communications.Cache
item.assetID = new LLUUID("77c41e39-38f9-f75a-024e-585989bbabbb");
item.inventoryDescription = "Default Skin";
item.inventoryName = "Default Skin";
- item.assetType = 13;
- item.invType = 18;
+ item.assetType = (int) AssetType.Bodypart;
+ item.invType = (int) InventoryType.Wearable;
item.parentFolderID = folderID;
item.inventoryCurrentPermissions = 0;
item.inventoryNextPermissions = 0;
@@ -191,8 +196,8 @@ namespace OpenSim.Framework.Communications.Cache
item.assetID = new LLUUID("00000000-38f9-1111-024e-222222111110");
item.inventoryDescription = "Default Shirt";
item.inventoryName = "Default Shirt";
- item.assetType = 5;
- item.invType = 18;
+ item.assetType = (int) AssetType.Clothing;
+ item.invType = (int) InventoryType.Wearable;
item.parentFolderID = folderID;
item.inventoryCurrentPermissions = 0;
item.inventoryNextPermissions = 0;
@@ -205,8 +210,8 @@ namespace OpenSim.Framework.Communications.Cache
item.assetID = new LLUUID("00000000-38f9-1111-024e-222222111120");
item.inventoryDescription = "Default Pants";
item.inventoryName = "Default Pants";
- item.assetType = 5;
- item.invType = 18;
+ item.assetType = (int) AssetType.Clothing;
+ item.invType = (int) InventoryType.Wearable;
item.parentFolderID = folderID;
item.inventoryCurrentPermissions = 0;
item.inventoryNextPermissions = 0;
diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs b/OpenSim/Framework/Communications/Cache/UserProfileCache.cs
index 74b2440..117ed36 100644
--- a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs
+++ b/OpenSim/Framework/Communications/Cache/UserProfileCache.cs
@@ -74,7 +74,10 @@ namespace OpenSim.Framework.Communications.Cache
public CachedUserInfo GetUserDetails(LLUUID userID)
{
- return m_userProfiles[userID];
+ if (m_userProfiles.ContainsKey(userID))
+ return m_userProfiles[userID];
+ else
+ return null;
}
public void HandleCreateInventoryFolder(IClientAPI remoteClient, LLUUID folderID, ushort folderType,
diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs
index ada5ff0..23181bf 100644
--- a/OpenSim/Framework/IClientAPI.cs
+++ b/OpenSim/Framework/IClientAPI.cs
@@ -272,6 +272,9 @@ namespace OpenSim.Framework
public delegate void UpdateInventoryItemTransaction(
IClientAPI remoteClient, LLUUID transactionID, LLUUID assetID, LLUUID itemID);
+ public delegate void CopyInventoryItem(
+ IClientAPI remoteClient, uint callbackID, LLUUID oldAgentID, LLUUID oldItemID, LLUUID newFolderID, string newName);
+
public delegate void RezScript(IClientAPI remoteClient, LLUUID itemID, uint localID);
public delegate void UpdateTaskInventory(IClientAPI remoteClient, LLUUID itemID, LLUUID folderID, uint localID);
@@ -344,6 +347,7 @@ namespace OpenSim.Framework
event FetchInventory OnFetchInventory;
event RequestTaskInventory OnRequestTaskInventory;
event UpdateInventoryItemTransaction OnUpdateInventoryItem;
+ event CopyInventoryItem OnCopyInventoryItem;
event UDPAssetUploadRequest OnAssetUploadRequest;
event XferReceive OnXferReceive;
event RequestXfer OnRequestXfer;
diff --git a/OpenSim/Region/ClientStack/ClientView.API.cs b/OpenSim/Region/ClientStack/ClientView.API.cs
index 65d57ad..70a99f0 100644
--- a/OpenSim/Region/ClientStack/ClientView.API.cs
+++ b/OpenSim/Region/ClientStack/ClientView.API.cs
@@ -96,6 +96,7 @@ namespace OpenSim.Region.ClientStack
public event FetchInventory OnFetchInventory;
public event RequestTaskInventory OnRequestTaskInventory;
public event UpdateInventoryItemTransaction OnUpdateInventoryItem;
+ public event CopyInventoryItem OnCopyInventoryItem;
public event UDPAssetUploadRequest OnAssetUploadRequest;
public event XferReceive OnXferReceive;
public event RequestXfer OnRequestXfer;
diff --git a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs
index 4336eb4..507bd64 100644
--- a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs
+++ b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs
@@ -563,6 +563,16 @@ namespace OpenSim.Region.ClientStack
}
}*/
break;
+ case PacketType.CopyInventoryItem:
+ CopyInventoryItemPacket copyitem = (CopyInventoryItemPacket) Pack;
+ if (OnCopyInventoryItem != null)
+ {
+ foreach (CopyInventoryItemPacket.InventoryDataBlock datablock in copyitem.InventoryData)
+ {
+ OnCopyInventoryItem(this, datablock.CallbackID, datablock.OldAgentID, datablock.OldItemID, datablock.NewFolderID, Util.FieldToString(datablock.NewName));
+ }
+ }
+ break;
case PacketType.RequestTaskInventory:
RequestTaskInventoryPacket requesttask = (RequestTaskInventoryPacket) Pack;
if (OnRequestTaskInventory != null)
diff --git a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs
index b06fa2f..bc0ccb3 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs
@@ -31,6 +31,7 @@ using libsecondlife;
using libsecondlife.Packets;
using OpenSim.Framework;
using OpenSim.Framework.Communications.Cache;
+using OpenSim.Framework.Console;
using OpenSim.Region.Physics.Manager;
namespace OpenSim.Region.Environment.Scenes
@@ -82,24 +83,18 @@ namespace OpenSim.Region.Environment.Scenes
InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
if (item != null)
{
- AssetBase asset;
- asset = new AssetBase();
- asset.FullID = LLUUID.Random();
- asset.Type = (sbyte) item.assetType;
- asset.InvType = (sbyte) item.invType;
- asset.Name = item.inventoryName;
- asset.Data = data;
+ AssetBase asset = CreateAsset(item.inventoryName, item.inventoryDescription, (sbyte) item.invType, (sbyte) item.assetType, data);
AssetCache.AddAsset(asset);
item.assetID = asset.FullID;
userInfo.UpdateItem(remoteClient.AgentId, item);
// remoteClient.SendInventoryItemUpdate(item);
- if (item.invType == 7)
+ if ((InventoryType) item.invType == InventoryType.Notecard)
{
//do we want to know about updated note cards?
}
- else if (item.invType == 10)
+ else if ((InventoryType) item.invType == InventoryType.LSL)
{
// do we want to know about updated scripts
}
@@ -160,6 +155,75 @@ namespace OpenSim.Region.Environment.Scenes
}
}
+ public void CopyInventoryItem(IClientAPI remoteClient, uint callbackID, LLUUID oldAgentID, LLUUID oldItemID, LLUUID newFolderID, string newName)
+ {
+ InventoryItemBase item = CommsManager.UserProfileCache.libraryRoot.HasItem(oldItemID);
+ if (item == null)
+ {
+ CachedUserInfo userInfo = CommsManager.UserProfileCache.GetUserDetails(oldAgentID);
+ if (userInfo == null)
+ {
+ MainLog.Instance.Warn("INVENTORY", "Failed to find user " + oldAgentID.ToString());
+ return;
+ }
+
+ item = userInfo.RootFolder.HasItem(oldItemID);
+ if (item == null)
+ {
+ MainLog.Instance.Warn("INVENTORY", "Failed to find item " + oldItemID.ToString());
+ return;
+ }
+ }
+
+ AssetBase asset = AssetCache.CopyAsset(item.assetID);
+ if (asset == null)
+ {
+ MainLog.Instance.Warn("INVENTORY", "Failed to find asset " + item.assetID.ToString());
+ return;
+ }
+
+ asset.Name = (newName.Length == 0) ? item.inventoryName : newName;
+
+ // TODO: preserve current permissions?
+ CreateNewInventoryItem(remoteClient, newFolderID, callbackID, asset, item.inventoryNextPermissions);
+ }
+
+ private AssetBase CreateAsset(string name, string description, sbyte invType, sbyte assetType, byte[] data)
+ {
+ AssetBase asset = new AssetBase();
+ asset.Name = name;
+ asset.Description = description;
+ asset.InvType = invType;
+ asset.Type = assetType;
+ asset.FullID = LLUUID.Random(); // TODO: check for conflicts
+ asset.Data = (data == null) ? new byte[1] : data;
+ return asset;
+ }
+
+ private void CreateNewInventoryItem(IClientAPI remoteClient, LLUUID folderID, uint callbackID,
+ AssetBase asset, uint nextOwnerMask)
+ {
+ CachedUserInfo userInfo = CommsManager.UserProfileCache.GetUserDetails(remoteClient.AgentId);
+ if (userInfo != null)
+ {
+ InventoryItemBase item = new InventoryItemBase();
+ item.avatarID = remoteClient.AgentId;
+ item.creatorsID = remoteClient.AgentId;
+ item.inventoryID = LLUUID.Random();
+ item.assetID = asset.FullID;
+ item.inventoryDescription = asset.Description;
+ item.inventoryName = asset.Name;
+ item.assetType = asset.Type;
+ item.invType = asset.InvType;
+ item.parentFolderID = folderID;
+ item.inventoryCurrentPermissions = 2147483647;
+ item.inventoryNextPermissions = nextOwnerMask;
+
+ userInfo.AddItem(remoteClient.AgentId, item);
+ remoteClient.SendInventoryItemUpdate(item);
+ }
+ }
+
///
/// temporary method to test out creating new inventory items
///
@@ -174,7 +238,7 @@ namespace OpenSim.Region.Environment.Scenes
///
///
public void CreateNewInventoryItem(IClientAPI remoteClient, LLUUID transActionID, LLUUID folderID,
- uint callbackID, string description, string name, sbyte invType, sbyte type,
+ uint callbackID, string description, string name, sbyte invType, sbyte assetType,
byte wearableType, uint nextOwnerMask)
{
if (transActionID == LLUUID.Zero)
@@ -182,37 +246,17 @@ namespace OpenSim.Region.Environment.Scenes
CachedUserInfo userInfo = CommsManager.UserProfileCache.GetUserDetails(remoteClient.AgentId);
if (userInfo != null)
{
- AssetBase asset = new AssetBase();
- asset.Name = name;
- asset.Description = description;
- asset.InvType = invType;
- asset.Type = type;
- asset.FullID = LLUUID.Random();
- asset.Data = new byte[1];
+ AssetBase asset = CreateAsset(name, description, invType, assetType, null);
AssetCache.AddAsset(asset);
- InventoryItemBase item = new InventoryItemBase();
- item.avatarID = remoteClient.AgentId;
- item.creatorsID = remoteClient.AgentId;
- item.inventoryID = LLUUID.Random();
- item.assetID = asset.FullID;
- item.inventoryDescription = description;
- item.inventoryName = name;
- item.assetType = invType;
- item.invType = invType;
- item.parentFolderID = folderID;
- item.inventoryCurrentPermissions = 2147483647;
- item.inventoryNextPermissions = nextOwnerMask;
-
- userInfo.AddItem(remoteClient.AgentId, item);
- remoteClient.SendInventoryItemUpdate(item);
+ CreateNewInventoryItem(remoteClient, folderID, callbackID, asset, nextOwnerMask);
}
}
else
{
CommsManager.TransactionsManager.HandleInventoryFromTransaction(remoteClient, transActionID, folderID,
callbackID, description, name, invType,
- type, wearableType, nextOwnerMask);
+ assetType, wearableType, nextOwnerMask);
//System.Console.WriteLine("request to create inventory item from transaction " + transActionID);
}
}
@@ -348,21 +392,18 @@ namespace OpenSim.Region.Environment.Scenes
CachedUserInfo userInfo = CommsManager.UserProfileCache.GetUserDetails(remoteClient.AgentId);
if (userInfo != null)
{
- AssetBase asset = new AssetBase();
- asset.Name = ((SceneObjectGroup) selectedEnt).GetPartName(selectedEnt.LocalId);
- asset.Description =
- ((SceneObjectGroup) selectedEnt).GetPartDescription(selectedEnt.LocalId);
- asset.InvType = 6;
- asset.Type = 6;
- asset.FullID = LLUUID.Random();
- asset.Data = Helpers.StringToField(sceneObjectXml);
+ AssetBase asset = CreateAsset(
+ ((SceneObjectGroup) selectedEnt).GetPartName(selectedEnt.LocalId),
+ ((SceneObjectGroup) selectedEnt).GetPartDescription(selectedEnt.LocalId),
+ (sbyte) InventoryType.Object,
+ (sbyte) AssetType.Object, // TODO: after libSL r1357, this becomes AssetType.Primitive
+ Helpers.StringToField(sceneObjectXml));
AssetCache.AddAsset(asset);
-
InventoryItemBase item = new InventoryItemBase();
item.avatarID = remoteClient.AgentId;
item.creatorsID = remoteClient.AgentId;
- item.inventoryID = LLUUID.Random();
+ item.inventoryID = LLUUID.Random(); // TODO: check for conflicts
item.assetID = asset.FullID;
item.inventoryDescription = asset.Description;
item.inventoryName = asset.Name;
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index 0b9d218..87bd0c1 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -789,6 +789,7 @@ namespace OpenSim.Region.Environment.Scenes
client.OnRequestTaskInventory += RequestTaskInventory;
client.OnFetchInventory += CommsManager.UserProfileCache.HandleFetchInventory;
client.OnUpdateInventoryItem += UDPUpdateInventoryItemAsset;
+ client.OnCopyInventoryItem += CopyInventoryItem;
client.OnAssetUploadRequest += CommsManager.TransactionsManager.HandleUDPUploadRequest;
client.OnXferReceive += CommsManager.TransactionsManager.HandleXfer;
client.OnRezScript += RezScript;
diff --git a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs
index e084266..f78dc8f 100644
--- a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs
+++ b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs
@@ -106,6 +106,7 @@ namespace SimpleApp
public event FetchInventory OnFetchInventory;
public event RequestTaskInventory OnRequestTaskInventory;
public event UpdateInventoryItemTransaction OnUpdateInventoryItem;
+ public event CopyInventoryItem OnCopyInventoryItem;
public event UDPAssetUploadRequest OnAssetUploadRequest;
public event XferReceive OnXferReceive;
public event RequestXfer OnRequestXfer;
--
cgit v1.1