diff --git a/OpenMetaverse/InventoryManager.cs b/OpenMetaverse/InventoryManager.cs index 9e797503..8e36554a 100644 --- a/OpenMetaverse/InventoryManager.cs +++ b/OpenMetaverse/InventoryManager.cs @@ -2084,7 +2084,7 @@ namespace OpenMetaverse /// public void RequestUpdateScriptAgentInventory(byte[] data, UUID itemID, ScriptUpdatedCallback callback) { - Uri url = _Client.Network.CurrentSim.Caps.CapabilityURI("UpdateScriptAgentInventory"); + Uri url = _Client.Network.CurrentSim.Caps.CapabilityURI("UpdateScriptAgent"); if(url != null) { diff --git a/Programs/examples/TestClient/Commands/Inventory/UploadScriptCommand.cs b/Programs/examples/TestClient/Commands/Inventory/UploadScriptCommand.cs new file mode 100644 index 00000000..771cef94 --- /dev/null +++ b/Programs/examples/TestClient/Commands/Inventory/UploadScriptCommand.cs @@ -0,0 +1,85 @@ +?using System; +using System.IO; + +namespace OpenMetaverse.TestClient +{ + /// + /// Example of how to put a new script in your inventory + /// + public class UploadScriptCommand : Command + { + /// + /// The default constructor for TestClient commands + /// + /// + public UploadScriptCommand(TestClient testClient) + { + Name = "uploadscript"; + Description = "Upload a local .lsl file file into your inventory."; + Category = CommandCategory.Inventory; + } + + /// + /// The default override for TestClient commands + /// + /// + /// + /// + public override string Execute(string[] args, UUID fromAgentID) + { + if (args.Length < 1) + return "Usage: uploadscript filename.lsl"; + + string file = String.Empty; + for (int ct = 0; ct < args.Length; ct++) + file = String.Format("{0}{1} ", file, args[ct]); + file = file.TrimEnd(); + + if (!File.Exists(file)) + return String.Format("Filename '{0}' does not exist", file); + + string ret = String.Format("Filename: {0}", file); + + try + { + using (StreamReader reader = new StreamReader(file)) + { + string body = reader.ReadToEnd(); + string desc = String.Format("{0} created by OpenMetaverse BotClient {1}", file, DateTime.Now); + // create the asset + Client.Inventory.RequestCreateItem(Client.Inventory.FindFolderForType(AssetType.LSLText), file, desc, AssetType.LSLText, UUID.Random(), InventoryType.LSL, PermissionMask.All, + delegate(bool success, InventoryItem item) + { + if (success) + // upload the asset + Client.Inventory.RequestUpdateScriptAgentInventory(EncodeScript(body), item.UUID, new InventoryManager.ScriptUpdatedCallback(delegate(bool success1, string status, UUID itemid, UUID assetid) + { + if (success1) + ret += String.Format("Script successfully uploaded, ItemID {0} AssetID {1}", itemid, assetid); + })); + }); + } + return ret; + + } + catch (System.Exception e) + { + Logger.Log(e.ToString(), Helpers.LogLevel.Error, Client); + return String.Format("Error creating script for {0}", ret); + } + } + /// + /// Encodes the script text for uploading + /// + /// + public static byte[] EncodeScript(string body) + { + // Assume this is a string, add 1 for the null terminator ? + byte[] stringBytes = System.Text.Encoding.UTF8.GetBytes(body); + byte[] assetData = new byte[stringBytes.Length]; //+ 1]; + Array.Copy(stringBytes, 0, assetData, 0, stringBytes.Length); + return assetData; + } + } + +}