/// <summary> /// Copy an InventoryScript item from the Agents Inventory into a primitives task inventory /// </summary> /// <param name="objectLocalID">An unsigned integer representing a primitive being simulated</param> /// <param name="item">An <seealso cref="InventoryItem"/> which represents a script object from the agents inventory</param> /// <param name="enableScript">true to set the scripts running state to enabled</param> /// <returns>A Unique Transaction ID</returns> /// <example> /// The following example shows the basic steps necessary to copy a script from the agents inventory into a tasks inventory /// and assumes the script exists in the agents inventory. /// <code> /// uint primID = 95899503; // Fake prim ID /// UUID scriptID = UUID.Parse("92a7fe8a-e949-dd39-a8d8-1681d8673232"); // Fake Script UUID in Inventory /// /// Client.Inventory.FolderContents(Client.Inventory.FindFolderForType(AssetType.LSLText), Client.Self.AgentID, /// false, true, InventorySortOrder.ByName, 10000); /// /// Client.Inventory.RezScript(primID, (InventoryItem)Client.Inventory.Store[scriptID]); /// </code> /// </example> // DocTODO: what does the return UUID correlate to if anything? public UUID CopyScriptToTask(uint objectLocalID, InventoryItem item, bool enableScript) { UUID transactionID = UUID.Random(); RezScriptPacket ScriptPacket = new RezScriptPacket(); ScriptPacket.AgentData.AgentID = Client.Self.AgentID; ScriptPacket.AgentData.SessionID = Client.Self.SessionID; ScriptPacket.UpdateBlock.ObjectLocalID = objectLocalID; ScriptPacket.UpdateBlock.Enabled = enableScript; ScriptPacket.InventoryBlock.ItemID = item.UUID; ScriptPacket.InventoryBlock.FolderID = item.ParentUUID; ScriptPacket.InventoryBlock.CreatorID = item.CreatorID; ScriptPacket.InventoryBlock.OwnerID = item.OwnerID; ScriptPacket.InventoryBlock.GroupID = item.GroupID; ScriptPacket.InventoryBlock.BaseMask = (uint)item.Permissions.BaseMask; ScriptPacket.InventoryBlock.OwnerMask = (uint)item.Permissions.OwnerMask; ScriptPacket.InventoryBlock.GroupMask = (uint)item.Permissions.GroupMask; ScriptPacket.InventoryBlock.EveryoneMask = (uint)item.Permissions.EveryoneMask; ScriptPacket.InventoryBlock.NextOwnerMask = (uint)item.Permissions.NextOwnerMask; ScriptPacket.InventoryBlock.GroupOwned = item.GroupOwned; ScriptPacket.InventoryBlock.TransactionID = transactionID; ScriptPacket.InventoryBlock.Type = (sbyte)item.AssetType; ScriptPacket.InventoryBlock.InvType = (sbyte)item.InventoryType; ScriptPacket.InventoryBlock.Flags = (uint)item.Flags; ScriptPacket.InventoryBlock.SaleType = (byte)item.SaleType; ScriptPacket.InventoryBlock.SalePrice = item.SalePrice; ScriptPacket.InventoryBlock.Name = Utils.StringToBytes(item.Name); ScriptPacket.InventoryBlock.Description = Utils.StringToBytes(item.Description); ScriptPacket.InventoryBlock.CreationDate = (int)Utils.DateTimeToUnixTime(item.CreationDate); ScriptPacket.InventoryBlock.CRC = ItemCRC(item); Client.Network.SendPacket(ScriptPacket); return transactionID; }
private void RezScriptHandler(Packet packet, LLAgent agent) { RezScriptPacket rez = (RezScriptPacket)packet; LLInventoryTaskItem scriptItem; ISceneEntity targetObj; if (m_scene.TryGetEntity(rez.UpdateBlock.ObjectLocalID, out targetObj) && targetObj is LLPrimitive) { LLPrimitive targetPrim = (LLPrimitive)targetObj; if (rez.InventoryBlock.ItemID != UUID.Zero) { if (targetPrim.Inventory.TryGetItem(rez.InventoryBlock.ItemID, out scriptItem)) { // Rezzing a script from task inventory UUID assetID = UUID.Combine(rez.InventoryBlock.TransactionID, agent.SecureSessionID); // Update task inventory with the new script source assetID scriptItem.AssetID = assetID; targetPrim.Inventory.AddOrUpdateItem(scriptItem, true); // Run the script if (m_scriptEngine != null) { m_scriptEngine.RezScript(scriptItem.ID, assetID, targetObj, 0); } else { m_log.Warn("Can't rez script in prim " + targetObj.ID + " without an ILSLScriptEngine"); } SignalTaskInventoryChange(agent, targetPrim); } else if (m_inventory != null) { InventoryBase obj; if (m_inventory.TryGetInventory(agent.ID, rez.InventoryBlock.ItemID, out obj) && obj is InventoryItem && ((InventoryItem)obj).ContentType == "application/vnd.ll.lsltext") { LLInventoryItem sourceItem = new LLInventoryItem((InventoryItem)obj); // Rezzing a script from agent inventory scriptItem = new LLInventoryTaskItem(); scriptItem.AssetID = sourceItem.AssetID; scriptItem.ContentType = "application/vnd.ll.lsltext"; scriptItem.CreationDate = DateTime.UtcNow; scriptItem.CreatorID = agent.ID; scriptItem.Description = sourceItem.Description; scriptItem.ID = UUID.Random(); scriptItem.Name = sourceItem.Name; scriptItem.OwnerID = sourceItem.OwnerID; scriptItem.ParentID = sourceItem.ParentID; scriptItem.ParentObjectID = targetPrim.ID; scriptItem.Flags = sourceItem.Flags; scriptItem.GroupID = sourceItem.GroupID; scriptItem.GroupOwned = sourceItem.GroupOwned; scriptItem.Permissions = sourceItem.Permissions; scriptItem.SalePrice = sourceItem.SalePrice; scriptItem.SaleType = sourceItem.SaleType; targetPrim.Inventory.AddOrUpdateItem(scriptItem, false); m_log.Info(agent.Name + " copied agent inventory script to task inventory: " + scriptItem.Name); // Run the script if (m_scriptEngine != null) { m_scriptEngine.RezScript(scriptItem.ID, scriptItem.AssetID, targetObj, 0); } else { m_log.Warn("Can't rez script in prim " + targetObj.ID + " without an ILSLScriptEngine"); } SignalTaskInventoryChange(agent, targetPrim); } else { m_log.Warn(agent.Name + " called RezScript for unknown inventory script " + rez.InventoryBlock.ItemID); } } else { m_log.Warn(agent.Name + "attempted to copy (and rez) script " + rez.InventoryBlock.ItemID + " to task inventory, but we have no IInventoryClient"); } } else { // Rezzing a new script scriptItem = new LLInventoryTaskItem(); scriptItem.AssetID = DEFAULT_SCRIPT; scriptItem.ContentType = "application/vnd.ll.lsltext"; scriptItem.CreationDate = DateTime.UtcNow; scriptItem.CreatorID = agent.ID; scriptItem.Description = String.Empty; scriptItem.ID = UUID.Random(); scriptItem.Name = "New script"; scriptItem.OwnerID = agent.ID; scriptItem.ParentID = rez.InventoryBlock.FolderID; scriptItem.ParentObjectID = targetPrim.ID; scriptItem.Permissions = GetDefaultPermissions(); scriptItem.SalePrice = 10; scriptItem.SaleType = SaleType.Not; targetPrim.Inventory.AddOrUpdateItem(scriptItem, false); m_log.Info(agent.Name + " created new task inventory script: " + scriptItem.Name); // Run the script if (m_scriptEngine != null) { m_scriptEngine.RezScript(scriptItem.ID, scriptItem.AssetID, targetObj, 0); } else { m_log.Warn("Can't rez script in prim " + targetObj.ID + " without an ILSLScriptEngine"); } SignalTaskInventoryChange(agent, targetPrim); } } else { m_log.Warn(agent.Name + "sent a RezScript packet referencing unknown object " + rez.UpdateBlock.ObjectLocalID); } }