Prim inventory script saving phase 2.

* It is now possible to edit and save scripts directly from prim inventories
* On saving, the script will be restarted in the region
* Doesn't appear that it's yet possible to drag inventory contents back to agent inventory.  Not quite sure why this is yet - the perms all look very permissive.
afrisby
Justin Clarke Casey 2008-01-09 15:46:45 +00:00
parent c0252073d0
commit 796ae57bea
6 changed files with 241 additions and 57 deletions

View File

@ -433,7 +433,7 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
return returnResult; return returnResult;
} }
public SceneObjectPart GetSceneObjectPart(uint localID) public SceneObjectPart GetSceneObjectPart(uint localID)
{ {

View File

@ -58,7 +58,9 @@ namespace OpenSim.Region.Environment.Scenes
/// in which the item is to be placed.</param> /// in which the item is to be placed.</param>
public void AddInventoryItem(IClientAPI remoteClient, InventoryItemBase item) public void AddInventoryItem(IClientAPI remoteClient, InventoryItemBase item)
{ {
CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); CachedUserInfo userInfo
= CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
if (userInfo != null) if (userInfo != null)
{ {
userInfo.AddItem(remoteClient.AgentId, item); userInfo.AddItem(remoteClient.AgentId, item);
@ -157,28 +159,47 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="itemID"></param> /// <param name="itemID"></param>
/// <param name="primID">The prim which contains the item to update</param> /// <param name="primID">The prim which contains the item to update</param>
/// <param name="isScriptRunning">Indicates whether the script to update is currently running</param> /// <param name="isScriptRunning">Indicates whether the script to update is currently running</param>
/// <param name="data"></param> /// <param name="data"></param>
/// <returns>Asset LLUID created</returns>
public void CapsUpdateTaskInventoryScriptAsset(IClientAPI remoteClient, LLUUID itemId, public void CapsUpdateTaskInventoryScriptAsset(IClientAPI remoteClient, LLUUID itemId,
LLUUID primId, bool isScriptRunning, byte[] data) LLUUID primId, bool isScriptRunning, byte[] data)
{ {
// TODO Not currently doing anything with the isScriptRunning bool // Retrieve group
SceneObjectPart part = GetSceneObjectPart(primId);
SceneObjectGroup group = part.ParentGroup;
if (null == group)
{
MainLog.Instance.Error(
"PRIMINVENTORY",
"Prim inventory update requested for item ID {0} in prim ID {1} but this prim does not exist",
itemId, primId);
MainLog.Instance.Verbose( return;
"PRIMINVENTORY", }
"Prim inventory script save functionality not yet implemented."
+ " remoteClient: {0}, itemID: {1}, primID: {2}, isScriptRunning: {3}",
remoteClient, itemId, primId, isScriptRunning);
// TODO
// Retrieve client LLUID
// Retrieve sog containing primID
// Retrieve item // Retrieve item
// Create new asset and add to cache TaskInventoryItem item = group.GetInventoryItem(part.LocalID, itemId);
if (null == item)
{
return;
}
// Create new asset
// XXX Hardcoding the numbers is a temporary measure - need an enumeration for this
AssetBase asset =
CreateAsset(item.name, item.desc, 10, 10, data);
AssetCache.AddAsset(asset);
// Update item with new asset // Update item with new asset
// Trigger SOG update (see RezScript) item.asset_id = asset.FullID;
// Trigger rerunning of script (use TriggerRezScript event, see RezScript) group.UpdateInventoryItem(item);
// return new asset id group.GetProperites(remoteClient);
// Trigger rerunning of script (use TriggerRezScript event, see RezScript)
if (isScriptRunning)
{
group.StopScript(part.LocalID, item.item_id);
group.StartScript(part.LocalID, item.item_id);
}
} }
/// <summary> /// <summary>
@ -268,14 +289,14 @@ namespace OpenSim.Region.Environment.Scenes
} }
else else
{ {
MainLog.Instance.Warn( MainLog.Instance.Error(
"AGENTINVENTORY", "AGENTINVENTORY",
"Item ID " + itemID + " not found for an inventory item update."); "Item ID " + itemID + " not found for an inventory item update.");
} }
} }
else else
{ {
MainLog.Instance.Warn( MainLog.Instance.Error(
"AGENTINVENTORY", "AGENTINVENTORY",
"Agent ID " + remoteClient.AgentId + " not found for an inventory item update."); "Agent ID " + remoteClient.AgentId + " not found for an inventory item update.");
} }
@ -290,7 +311,7 @@ namespace OpenSim.Region.Environment.Scenes
CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(oldAgentID); CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(oldAgentID);
if (userInfo == null) if (userInfo == null)
{ {
MainLog.Instance.Warn("AGENTINVENTORY", "Failed to find user " + oldAgentID.ToString()); MainLog.Instance.Error("AGENTINVENTORY", "Failed to find user " + oldAgentID.ToString());
return; return;
} }
@ -299,13 +320,13 @@ namespace OpenSim.Region.Environment.Scenes
item = userInfo.RootFolder.HasItem(oldItemID); item = userInfo.RootFolder.HasItem(oldItemID);
if (item == null) if (item == null)
{ {
MainLog.Instance.Warn("AGENTINVENTORY", "Failed to find item " + oldItemID.ToString()); MainLog.Instance.Error("AGENTINVENTORY", "Failed to find item " + oldItemID.ToString());
return; return;
} }
} }
else else
{ {
MainLog.Instance.Warn("AGENTINVENTORY", "Failed to find item " + oldItemID.ToString()); MainLog.Instance.Error("AGENTINVENTORY", "Failed to find item " + oldItemID.ToString());
return; return;
} }
} }
@ -346,7 +367,7 @@ namespace OpenSim.Region.Environment.Scenes
CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
if (userInfo == null) if (userInfo == null)
{ {
MainLog.Instance.Warn("AGENTINVENTORY", "Failed to find user " + remoteClient.AgentId.ToString()); MainLog.Instance.Error("AGENTINVENTORY", "Failed to find user " + remoteClient.AgentId.ToString());
return; return;
} }
@ -367,13 +388,13 @@ namespace OpenSim.Region.Environment.Scenes
} }
else else
{ {
MainLog.Instance.Warn("AGENTINVENTORY", "Failed to find item " + itemID.ToString()); MainLog.Instance.Error("AGENTINVENTORY", "Failed to find item " + itemID.ToString());
return; return;
} }
} }
else else
{ {
MainLog.Instance.Warn("AGENTINVENTORY", "Failed to find item " + itemID.ToString() + ", no root folder"); MainLog.Instance.Error("AGENTINVENTORY", "Failed to find item " + itemID.ToString() + ", no root folder");
return; return;
} }
} }
@ -476,7 +497,7 @@ namespace OpenSim.Region.Environment.Scenes
} }
else else
{ {
MainLog.Instance.Warn( MainLog.Instance.Error(
"PRIMINVENTORY", "Inventory requested of prim {0} which doesn't exist", primLocalID); "PRIMINVENTORY", "Inventory requested of prim {0} which doesn't exist", primLocalID);
} }
} }
@ -484,7 +505,8 @@ namespace OpenSim.Region.Environment.Scenes
/// <summary> /// <summary>
/// Remove an item from a prim (task) inventory /// Remove an item from a prim (task) inventory
/// </summary> /// </summary>
/// <param name="remoteClient"></param> /// <param name="remoteClient">Unused at the moment but retained since the avatar ID might
/// be necessary for a permissions check at some stage.</param>
/// <param name="itemID"></param> /// <param name="itemID"></param>
/// <param name="localID"></param> /// <param name="localID"></param>
public void RemoveTaskInventory(IClientAPI remoteClient, LLUUID itemID, uint localID) public void RemoveTaskInventory(IClientAPI remoteClient, LLUUID itemID, uint localID)
@ -492,7 +514,7 @@ namespace OpenSim.Region.Environment.Scenes
SceneObjectGroup group = GetGroupByPrim(localID); SceneObjectGroup group = GetGroupByPrim(localID);
if (group != null) if (group != null)
{ {
int type = group.RemoveInventoryItem(remoteClient, localID, itemID); int type = group.RemoveInventoryItem(localID, itemID);
group.GetProperites(remoteClient); group.GetProperites(remoteClient);
if (type == 10) if (type == 10)
{ {
@ -501,7 +523,7 @@ namespace OpenSim.Region.Environment.Scenes
} }
else else
{ {
MainLog.Instance.Warn( MainLog.Instance.Error(
"PRIMINVENTORY", "PRIMINVENTORY",
"Removal of item {0} requested of prim {1} but this prim does not exist", "Removal of item {0} requested of prim {1} but this prim does not exist",
itemID, itemID,
@ -752,4 +774,4 @@ namespace OpenSim.Region.Environment.Scenes
rootPart.ScheduleFullUpdate(); rootPart.ScheduleFullUpdate();
} }
} }
} }

View File

@ -176,7 +176,7 @@ namespace OpenSim.Region.Environment.Scenes
agentData.AgentID = avatarID; agentData.AgentID = avatarID;
agentData.QueryID = RequestID; agentData.QueryID = RequestID;
replyPacket.AgentData = agentData; replyPacket.AgentData = agentData;
byte[] bytes = new byte[AvatarResponses.Count*32]; //byte[] bytes = new byte[AvatarResponses.Count*32];
int i = 0; int i = 0;
foreach (AvatarPickerAvatar item in AvatarResponses) foreach (AvatarPickerAvatar item in AvatarResponses)

View File

@ -60,6 +60,27 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
// /// Start a given script.
// /// </summary>
// /// <param name="localID">
// /// A <see cref="System.UInt32"/>
// /// </param>
// public void StartScript(LLUUID partID, LLUUID itemID)
// {
// SceneObjectPart part = GetChildPart(partID);
// if (part != null)
// {
// part.StartScript(itemID);
// }
// else
// {
// MainLog.Instance.Error(
// "PRIMINVENTORY",
// "Couldn't find part {0} in object group {1}, {2} to start script with ID {3}",
// localID, Name, UUID, itemID);
// }
// }
/// <summary> /// <summary>
/// Start the scripts contained in all the prims in this group. /// Start the scripts contained in all the prims in this group.
/// </summary> /// </summary>
@ -71,6 +92,27 @@ namespace OpenSim.Region.Environment.Scenes
} }
} }
/// Start a given script.
/// </summary>
/// <param name="localID">
/// A <see cref="System.UInt32"/>
/// </param>
public void StopScript(uint partID, LLUUID itemID)
{
SceneObjectPart part = GetChildPart(partID);
if (part != null)
{
part.StopScript(itemID);
}
else
{
MainLog.Instance.Error(
"PRIMINVENTORY",
"Couldn't find part {0} in object group {1}, {2} to stop script with ID {3}",
partID, Name, UUID, itemID);
}
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -156,13 +198,63 @@ namespace OpenSim.Region.Environment.Scenes
return false; return false;
} }
/// <summary>
/// Returns an existing inventory item. Returns the original, so any changes will be live.
/// </summary>
/// <param name="primID"></param>
/// <param name="itemID"></param>
/// <returns>null if the item does not exist</returns>
public TaskInventoryItem GetInventoryItem(uint primID, LLUUID itemID)
{
SceneObjectPart part = GetChildPart(primID);
if (part != null)
{
return part.GetInventoryItem(itemID);
}
else
{
MainLog.Instance.Error(
"PRIMINVENTORY",
"Couldn't find prim local ID {0} in prim {1}, {2} to get inventory item ID {3}",
primID, part.Name, part.UUID, itemID);
}
return null;
}
/// <summary>
/// Update an existing inventory item.
/// </summary>
/// <param name="item">The updated item. An item with the same id must already exist
/// in this prim's inventory</param>
/// <returns>false if the item did not exist, true if the update occurred succesfully</returns>
public bool UpdateInventoryItem(TaskInventoryItem item)
{
SceneObjectPart part = GetChildPart(item.ParentPartID);
if (part != null)
{
part.UpdateInventoryItem(item);
return true;
}
else
{
MainLog.Instance.Error(
"PRIMINVENTORY",
"Couldn't find prim ID {0} to update item {1}, {2}",
item.ParentPartID, item.name, item.item_id);
}
return false;
}
public int RemoveInventoryItem(IClientAPI remoteClient, uint localID, LLUUID itemID) public int RemoveInventoryItem(uint localID, LLUUID itemID)
{ {
SceneObjectPart part = GetChildPart(localID); SceneObjectPart part = GetChildPart(localID);
if (part != null) if (part != null)
{ {
int type = part.RemoveInventoryItem(remoteClient, localID, itemID); int type = part.RemoveInventoryItem(itemID);
// It might seem somewhat crude to update the whole group for a single prim inventory change, // It might seem somewhat crude to update the whole group for a single prim inventory change,
// but it's possible that other prim inventory changes will take place before the region // but it's possible that other prim inventory changes will take place before the region
@ -177,4 +269,4 @@ namespace OpenSim.Region.Environment.Scenes
return -1; return -1;
} }
} }
} }

View File

@ -375,8 +375,9 @@ namespace OpenSim.Region.Environment.Scenes
foreach (SceneObjectPart part in m_parts.Values) foreach (SceneObjectPart part in m_parts.Values)
{ {
Vector3 partPosition = // Temporary commented to stop compiler warning
new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z); //Vector3 partPosition =
// new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z);
Quaternion parentrotation = Quaternion parentrotation =
new Quaternion(GroupRotation.W, GroupRotation.X, GroupRotation.Y, GroupRotation.Z); new Quaternion(GroupRotation.W, GroupRotation.X, GroupRotation.Y, GroupRotation.Z);
@ -827,10 +828,8 @@ namespace OpenSim.Region.Environment.Scenes
/// <returns></returns> /// <returns></returns>
public bool HasChildPrim(LLUUID primID) public bool HasChildPrim(LLUUID primID)
{ {
SceneObjectPart childPart = null;
if (m_parts.ContainsKey(primID)) if (m_parts.ContainsKey(primID))
{ {
childPart = m_parts[primID];
return true; return true;
} }
return false; return false;

View File

@ -144,7 +144,26 @@ namespace OpenSim.Region.Environment.Scenes
itemId, Name, UUID); itemId, Name, UUID);
} }
} }
/// <summary>
/// Stop a script which is in this prim's inventory.
/// </summary>
/// <param name="itemId"></param>
public void StopScript(LLUUID itemId)
{
if (m_taskInventory.ContainsKey(itemId))
{
m_parentGroup.Scene.EventManager.TriggerRemoveScript(LocalID, itemId);
}
else
{
MainLog.Instance.Error(
"PRIMINVENTORY",
"Couldn't stop script with ID {0} since it couldn't be found for prim {1}, {2}",
itemId, Name, UUID);
}
}
/// <summary> /// <summary>
/// Add an item to this prim's inventory. /// Add an item to this prim's inventory.
@ -173,33 +192,85 @@ namespace OpenSim.Region.Environment.Scenes
m_inventorySerial++; m_inventorySerial++;
} }
/// <summary>
/// Returns an existing inventory item. Returns the original, so any changes will be live.
/// </summary>
/// <param name="itemID"></param>
/// <returns>null if the item does not exist</returns>
public TaskInventoryItem GetInventoryItem(LLUUID itemID)
{
if (m_taskInventory.ContainsKey(itemID))
{
return m_taskInventory[itemID];
}
else
{
MainLog.Instance.Error(
"PRIMINVENTORY",
"Tried to retrieve item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
itemID, Name, UUID);
}
return null;
}
/// <summary>
/// Update an existing inventory item.
/// </summary>
/// <param name="item">The updated item. An item with the same id must already exist
/// in this prim's inventory.</param>
/// <returns>false if the item did not exist, true if the update occurred succesfully</returns>
public bool UpdateInventoryItem(TaskInventoryItem item)
{
if (m_taskInventory.ContainsKey(item.item_id))
{
m_taskInventory[item.item_id] = item;
m_inventorySerial++;
return true;
}
else
{
MainLog.Instance.Error(
"PRIMINVENTORY",
"Tried to retrieve item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
item.item_id, Name, UUID);
}
return false;
}
/// <summary> /// <summary>
/// Remove an item from this prim's inventory /// Remove an item from this prim's inventory
/// </summary> /// </summary>
/// <param name="remoteClient"></param>
/// <param name="localID"></param>
/// <param name="itemID"></param> /// <param name="itemID"></param>
/// <returns>Numeric asset type of the item removed.</returns> /// <returns>Numeric asset type of the item removed. Returns -1 if the item did not exist
public int RemoveInventoryItem(IClientAPI remoteClient, uint localID, LLUUID itemID) /// in this prim's inventory.</returns>
public int RemoveInventoryItem(LLUUID itemID)
{ {
if (localID == LocalID) if (m_taskInventory.ContainsKey(itemID))
{ {
if (m_taskInventory.ContainsKey(itemID)) string type = m_taskInventory[itemID].inv_type;
m_taskInventory.Remove(itemID);
m_inventorySerial++;
if (type == "lsltext")
{ {
string type = m_taskInventory[itemID].inv_type; return 10;
m_taskInventory.Remove(itemID); }
m_inventorySerial++; else
if (type == "lsltext") {
{ return 0;
return 10;
}
else
{
return 0;
}
} }
} }
else
{
MainLog.Instance.Error(
"PRIMINVENTORY",
"Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
itemID, Name, UUID);
}
return -1; return -1;
} }