diff --git a/OpenSim/Framework/Communications/Cache/AssetTransactions.cs b/OpenSim/Framework/Communications/Cache/AssetTransactions.cs index e12d234df5..8909bdf156 100644 --- a/OpenSim/Framework/Communications/Cache/AssetTransactions.cs +++ b/OpenSim/Framework/Communications/Cache/AssetTransactions.cs @@ -89,7 +89,7 @@ namespace OpenSim.Framework.Communications.Caches private string uploaderPath = ""; // Events - public event UpLoadedTexture OnUpLoad; + public event UpLoadedAsset OnUpLoad; // Methods public void Initialise(string assetName, string assetDescription, LLUUID assetID, LLUUID inventoryItem, LLUUID folderID, string path, BaseHttpServer httpServer) @@ -230,7 +230,7 @@ namespace OpenSim.Framework.Communications.Caches private string uploaderPath = ""; // Events - public event UpLoadedTexture OnUpLoad; + public event UpLoadedAsset OnUpLoad; // Methods public void Initialise(LLUUID inventoryItem, string path, BaseHttpServer httpServer) diff --git a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs index 57c79b4391..9970d800fe 100644 --- a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs +++ b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs @@ -104,6 +104,14 @@ namespace OpenSim.Framework.Communications.Caches this.m_parentCommsManager.InventoryServer.AddNewInventoryItem(userID, itemInfo); } } + + public void updateItem(LLUUID userID, InventoryItemBase itemInfo) + { + if ((userID == this.UserProfile.UUID) && (this.RootFolder != null)) + { + this.m_parentCommsManager.InventoryServer.AddNewInventoryItem(userID, itemInfo); + } + } } diff --git a/OpenSim/Framework/Communications/Capabilities/Caps.cs b/OpenSim/Framework/Communications/Capabilities/Caps.cs index eb88aa7acc..14f9c955ec 100644 --- a/OpenSim/Framework/Communications/Capabilities/Caps.cs +++ b/OpenSim/Framework/Communications/Capabilities/Caps.cs @@ -39,8 +39,10 @@ using OpenSim.Framework.Data; namespace OpenSim.Region.Capabilities { - public delegate void UpLoadedTexture(string assetName, string description, LLUUID assetID, LLUUID inventoryItem, LLUUID parentFolder, byte[] data); + public delegate void UpLoadedAsset(string assetName, string description, LLUUID assetID, LLUUID inventoryItem, LLUUID parentFolder, byte[] data); + public delegate LLUUID UpdateItem(LLUUID itemID, byte[] data); public delegate void NewInventoryItem(LLUUID userID, InventoryItemBase item); + public delegate LLUUID ItemUpdatedCallback(LLUUID userID, LLUUID itemID, byte[] data); public class Caps { @@ -59,6 +61,7 @@ namespace OpenSim.Region.Capabilities private int eventQueueCount = 1; private Queue CapsEventQueue = new Queue(); public NewInventoryItem AddNewInventoryItem = null; + public ItemUpdatedCallback ItemUpdatedCall = null; public Caps(AssetCache assetCach, BaseHttpServer httpServer, string httpListen, int httpPort, string capsPath, LLUUID agent) { @@ -125,7 +128,8 @@ namespace OpenSim.Region.Capabilities string capsBaseUrl = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + "/CAPS/" + m_capsObjectPath; caps.MapLayer = capsBaseUrl + m_mapLayerPath; caps.NewFileAgentInventory = capsBaseUrl + m_newInventory; - // caps.UpdateNotecardAgentInventory = capsBaseUrl + m_notecardUpdatePath; + caps.UpdateNotecardAgentInventory = capsBaseUrl + m_notecardUpdatePath; + caps.UpdateScriptAgentInventory = capsBaseUrl + m_notecardUpdatePath; return caps; } @@ -238,21 +242,24 @@ namespace OpenSim.Region.Capabilities /// public string NoteCardAgentInventory(string request, string path, string param) { - Console.WriteLine("notecard update request " + request); - string assetName = "notecardupdate"; + Hashtable hash = (Hashtable)LLSD.LLSDDeserialize(Helpers.StringToField(request)); + LLSDItemUpdate llsdRequest = new LLSDItemUpdate(); + LLSDHelpers.DeserialiseLLSDMap(hash, llsdRequest); + string capsBase = "/CAPS/" + m_capsObjectPath; - LLUUID newAsset = LLUUID.Random(); - LLUUID newInvItem = LLUUID.Random(); + LLUUID newInvItem = llsdRequest.item_id; string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); - AssetUploader uploader = new AssetUploader(assetName, "description", newAsset, newInvItem, LLUUID.Zero, "", "", capsBase + uploaderPath, this.httpListener); + ItemUpdater uploader = new ItemUpdater(newInvItem, capsBase + uploaderPath, this.httpListener); + uploader.OnUpLoad += this.ItemUpdated; + httpListener.AddStreamHandler(new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); string uploaderURL = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + uploaderPath; LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); uploadResponse.uploader = uploaderURL; uploadResponse.state = "upload"; - // uploader.OnUpLoad += this.UploadCompleteHandler; + return LLSDHelpers.SerialiseLLSDReply(uploadResponse); } @@ -321,9 +328,18 @@ namespace OpenSim.Region.Capabilities } + public LLUUID ItemUpdated(LLUUID itemID, byte[] data) + { + if (ItemUpdatedCall != null) + { + return ItemUpdatedCall(this.agentID, itemID, data); + } + return LLUUID.Zero; + } + public class AssetUploader { - public event UpLoadedTexture OnUpLoad; + public event UpLoadedAsset OnUpLoad; private string uploaderPath = ""; private LLUUID newAssetID; @@ -392,6 +408,74 @@ namespace OpenSim.Region.Capabilities fs.Close(); } } + + public class ItemUpdater + { + public event UpdateItem OnUpLoad; + + private string uploaderPath = ""; + private LLUUID inventoryItemID; + private BaseHttpServer httpListener; + private bool SaveAssets = false; + + + /// + /// + /// + /// + /// + /// + /// + public ItemUpdater( LLUUID inventoryItem, string path, BaseHttpServer httpServer) + { + + inventoryItemID = inventoryItem; + uploaderPath = path; + httpListener = httpServer; + } + + /// + /// + /// + /// + /// + /// + /// + public string uploaderCaps(byte[] data, string path, string param) + { + LLUUID inv = this.inventoryItemID; + string res = ""; + LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); + LLUUID assetID = LLUUID.Zero; + + if (OnUpLoad != null) + { + assetID = OnUpLoad(inv, data); + } + + uploadComplete.new_asset = assetID.ToStringHyphenated(); + uploadComplete.new_inventory_item = inv; + uploadComplete.state = "complete"; + + res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); + + httpListener.RemoveStreamHandler("POST", uploaderPath); + + if (this.SaveAssets) + this.SaveAssetToFile("updateditem"+Util.RandomClass.Next(1,1000) + ".dat", data); + + return res; + } + + private void SaveAssetToFile(string filename, byte[] data) + { + FileStream fs = File.Create(filename); + BinaryWriter bw = new BinaryWriter(fs); + bw.Write(data); + bw.Close(); + fs.Close(); + } + } } } diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDCapsDetails.cs b/OpenSim/Framework/Communications/Capabilities/LLSDCapsDetails.cs index 913d7abda8..af20468101 100644 --- a/OpenSim/Framework/Communications/Capabilities/LLSDCapsDetails.cs +++ b/OpenSim/Framework/Communications/Capabilities/LLSDCapsDetails.cs @@ -9,6 +9,7 @@ namespace OpenSim.Region.Capabilities // public string RequestTextureDownload = ""; // public string ChatSessionRequest = ""; public string UpdateNotecardAgentInventory = ""; + public string UpdateScriptAgentInventory = ""; // public string ParcelVoiceInfoRequest = ""; public LLSDCapsDetails() diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDItemUpdate.cs b/OpenSim/Framework/Communications/Capabilities/LLSDItemUpdate.cs new file mode 100644 index 0000000000..d47bb0705e --- /dev/null +++ b/OpenSim/Framework/Communications/Capabilities/LLSDItemUpdate.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; +using libsecondlife; + +namespace OpenSim.Region.Capabilities +{ + [LLSDMap] + public class LLSDItemUpdate + { + public LLUUID item_id; + + public LLSDItemUpdate() + { + } + } +} diff --git a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs index e61a5bdec3..bba0138fbb 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs @@ -732,15 +732,6 @@ namespace OpenSim.Region.Environment.Scenes } } - /// - /// Sends prims to a client - /// - /// Client to send to - public void GetInitialPrims(IClientAPI RemoteClient) - { - - } - public void ProcessObjectGrab(uint localID, LLVector3 offsetPos, IClientAPI remoteClient) { this.EventManager.TriggerObjectGrab(localID, offsetPos, remoteClient); diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 73133d4f80..bfc3ee81f6 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -827,6 +827,7 @@ namespace OpenSim.Region.Environment.Scenes agent.CapsPath, agent.AgentID); cap.RegisterHandlers(); cap.AddNewInventoryItem = this.AddInventoryItem; + cap.ItemUpdatedCall = this.UpdateInventoryItemAsset; if (capsHandlers.ContainsKey(agent.AgentID)) { MainLog.Instance.Warn("client", "Adding duplicate CAPS entry for user " + @@ -1023,7 +1024,7 @@ namespace OpenSim.Region.Environment.Scenes { ScriptEngines.Add(ScriptEngine); - ScriptEngine.InitializeEngine(this, m_logger); + ScriptEngine.InitializeEngine(this, m_logger); } #endregion @@ -1046,7 +1047,7 @@ namespace OpenSim.Region.Environment.Scenes public void AddInventoryItem(LLUUID userID, InventoryItemBase item) { - if(this.Avatars.ContainsKey(userID)) + if (this.Avatars.ContainsKey(userID)) { this.AddInventoryItem(this.Avatars[userID].ControllingClient, item); } @@ -1062,5 +1063,45 @@ namespace OpenSim.Region.Environment.Scenes } } + public LLUUID UpdateInventoryItemAsset(LLUUID userID, LLUUID itemID, byte[] data) + { + if (this.Avatars.ContainsKey(userID)) + { + return this.UpdateInventoryItemAsset(this.Avatars[userID].ControllingClient, itemID, data); + } + return LLUUID.Zero; + } + + public LLUUID UpdateInventoryItemAsset(IClientAPI remoteClient, LLUUID itemID, byte[] data) + { + CachedUserInfo userInfo = commsManager.UserProfiles.GetUserDetails(remoteClient.AgentId); + if (userInfo != null) + { + if (userInfo.RootFolder != null) + { + 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; + this.assetCache.AddAsset(asset); + + item.assetID = asset.FullID; + userInfo.updateItem(remoteClient.AgentId, item); + + remoteClient.SendInventoryItemUpdate(item); + + return (asset.FullID); + } + } + } + return LLUUID.Zero; + } + } }