From a979808493b20362ab3fe06ac68e5370622ceafa Mon Sep 17 00:00:00 2001 From: MW Date: Tue, 14 Aug 2007 19:19:09 +0000 Subject: preliminary support for editing notecards and scripts. Although there seems to sometimes be a problem of when you login again, old notecards and scripts will have their permissions messed up and you won't be able to even view their text. This seems to be related to the client's cache, and if you clear your client's cache, on the next login they should be fine again. [I have a couple of ideas about what might be causing this so hopefully will have it fixed soon.] --- .../Communications/Cache/AssetTransactions.cs | 4 +- .../Communications/Cache/CachedUserInfo.cs | 8 ++ .../Framework/Communications/Capabilities/Caps.cs | 102 +++++++++++++++++++-- .../Communications/Capabilities/LLSDCapsDetails.cs | 1 + .../Communications/Capabilities/LLSDItemUpdate.cs | 17 ++++ 5 files changed, 121 insertions(+), 11 deletions(-) create mode 100644 OpenSim/Framework/Communications/Capabilities/LLSDItemUpdate.cs (limited to 'OpenSim/Framework/Communications') diff --git a/OpenSim/Framework/Communications/Cache/AssetTransactions.cs b/OpenSim/Framework/Communications/Cache/AssetTransactions.cs index e12d234..8909bdf 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 57c79b4..9970d80 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 eb88aa7..14f9c95 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 913d7ab..af20468 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 0000000..d47bb07 --- /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() + { + } + } +} -- cgit v1.1