refactor: decompose most of RezScript() into RezScriptFromAgentInventory(), RezNewScript() and rename one RezScript() to RezScriptFromPrim()
parent
2e7c1bcfd9
commit
2de3a1b9da
|
@ -1560,113 +1560,129 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
/// Rez a script into a prim's inventory, either ex nihilo or from an existing avatar inventory
|
||||
/// </summary>
|
||||
/// <param name="remoteClient"></param>
|
||||
/// <param name="itemID"> </param>
|
||||
/// <param name="itemBase"> </param>
|
||||
/// <param name="transactionID"></param>
|
||||
/// <param name="localID"></param>
|
||||
public void RezScript(IClientAPI remoteClient, InventoryItemBase itemBase, UUID transactionID, uint localID)
|
||||
{
|
||||
UUID itemID = itemBase.ID;
|
||||
if (itemBase.ID != UUID.Zero)
|
||||
RezScriptFromAgentInventory(remoteClient, itemBase.ID, localID);
|
||||
else
|
||||
RezNewScript(remoteClient, itemBase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rez a script into a prim from an agent inventory.
|
||||
/// </summary>
|
||||
/// <param name="remoteClient"></param>
|
||||
/// <param name="fromItemID"></param>
|
||||
/// <param name="localID"></param>
|
||||
public void RezScriptFromAgentInventory(IClientAPI remoteClient, UUID fromItemID, uint localID)
|
||||
{
|
||||
UUID copyID = UUID.Random();
|
||||
InventoryItemBase item = new InventoryItemBase(fromItemID, remoteClient.AgentId);
|
||||
item = InventoryService.GetItem(item);
|
||||
|
||||
if (itemID != UUID.Zero) // transferred from an avatar inventory to the prim's inventory
|
||||
// Try library
|
||||
// XXX clumsy, possibly should be one call
|
||||
if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null)
|
||||
{
|
||||
InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
|
||||
item = InventoryService.GetItem(item);
|
||||
item = LibraryService.LibraryRootFolder.FindItem(fromItemID);
|
||||
}
|
||||
|
||||
// Try library
|
||||
// XXX clumsy, possibly should be one call
|
||||
if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null)
|
||||
if (item != null)
|
||||
{
|
||||
SceneObjectPart part = GetSceneObjectPart(localID);
|
||||
if (part != null)
|
||||
{
|
||||
item = LibraryService.LibraryRootFolder.FindItem(itemID);
|
||||
}
|
||||
if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId))
|
||||
return;
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
SceneObjectPart part = GetSceneObjectPart(localID);
|
||||
if (part != null)
|
||||
{
|
||||
if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId))
|
||||
return;
|
||||
part.ParentGroup.AddInventoryItem(remoteClient, localID, item, copyID);
|
||||
// TODO: switch to posting on_rez here when scripts
|
||||
// have state in inventory
|
||||
part.Inventory.CreateScriptInstance(copyID, 0, false, DefaultScriptEngine, 0);
|
||||
|
||||
part.ParentGroup.AddInventoryItem(remoteClient, localID, item, copyID);
|
||||
// TODO: switch to posting on_rez here when scripts
|
||||
// have state in inventory
|
||||
part.Inventory.CreateScriptInstance(copyID, 0, false, DefaultScriptEngine, 0);
|
||||
|
||||
// m_log.InfoFormat("[PRIMINVENTORY]: " +
|
||||
// "Rezzed script {0} into prim local ID {1} for user {2}",
|
||||
// item.inventoryName, localID, remoteClient.Name);
|
||||
part.SendPropertiesToClient(remoteClient);
|
||||
part.ParentGroup.ResumeScripts();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.ErrorFormat(
|
||||
"[PRIM INVENTORY]: " +
|
||||
"Could not rez script {0} into prim local ID {1} for user {2}"
|
||||
+ " because the prim could not be found in the region!",
|
||||
item.Name, localID, remoteClient.Name);
|
||||
}
|
||||
// m_log.InfoFormat("[PRIMINVENTORY]: " +
|
||||
// "Rezzed script {0} into prim local ID {1} for user {2}",
|
||||
// item.inventoryName, localID, remoteClient.Name);
|
||||
part.SendPropertiesToClient(remoteClient);
|
||||
part.ParentGroup.ResumeScripts();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.ErrorFormat(
|
||||
"[PRIM INVENTORY]: Could not find script inventory item {0} to rez for {1}!",
|
||||
itemID, remoteClient.Name);
|
||||
"[PRIM INVENTORY]: " +
|
||||
"Could not rez script {0} into prim local ID {1} for user {2}"
|
||||
+ " because the prim could not be found in the region!",
|
||||
item.Name, localID, remoteClient.Name);
|
||||
}
|
||||
}
|
||||
else // script has been rezzed directly into a prim's inventory
|
||||
else
|
||||
{
|
||||
SceneObjectPart part = GetSceneObjectPart(itemBase.Folder);
|
||||
if (part == null)
|
||||
return;
|
||||
|
||||
if (!Permissions.CanCreateObjectInventory(
|
||||
itemBase.InvType, part.UUID, remoteClient.AgentId))
|
||||
return;
|
||||
|
||||
AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType,
|
||||
Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"),
|
||||
remoteClient.AgentId);
|
||||
AssetService.Store(asset);
|
||||
|
||||
TaskInventoryItem taskItem = new TaskInventoryItem();
|
||||
|
||||
taskItem.ResetIDs(itemBase.Folder);
|
||||
taskItem.ParentID = itemBase.Folder;
|
||||
taskItem.CreationDate = (uint)itemBase.CreationDate;
|
||||
taskItem.Name = itemBase.Name;
|
||||
taskItem.Description = itemBase.Description;
|
||||
taskItem.Type = itemBase.AssetType;
|
||||
taskItem.InvType = itemBase.InvType;
|
||||
taskItem.OwnerID = itemBase.Owner;
|
||||
taskItem.CreatorID = itemBase.CreatorIdAsUuid;
|
||||
taskItem.BasePermissions = itemBase.BasePermissions;
|
||||
taskItem.CurrentPermissions = itemBase.CurrentPermissions;
|
||||
taskItem.EveryonePermissions = itemBase.EveryOnePermissions;
|
||||
taskItem.GroupPermissions = itemBase.GroupPermissions;
|
||||
taskItem.NextPermissions = itemBase.NextPermissions;
|
||||
taskItem.GroupID = itemBase.GroupID;
|
||||
taskItem.GroupPermissions = 0;
|
||||
taskItem.Flags = itemBase.Flags;
|
||||
taskItem.PermsGranter = UUID.Zero;
|
||||
taskItem.PermsMask = 0;
|
||||
taskItem.AssetID = asset.FullID;
|
||||
|
||||
part.Inventory.AddInventoryItem(taskItem, false);
|
||||
part.SendPropertiesToClient(remoteClient);
|
||||
|
||||
part.Inventory.CreateScriptInstance(taskItem, 0, false, DefaultScriptEngine, 0);
|
||||
part.ParentGroup.ResumeScripts();
|
||||
m_log.ErrorFormat(
|
||||
"[PRIM INVENTORY]: Could not find script inventory item {0} to rez for {1}!",
|
||||
fromItemID, remoteClient.Name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rez a new script from nothing.
|
||||
/// </summary>
|
||||
/// <param name="remoteClient"></param>
|
||||
/// <param name="itemBase"></param>
|
||||
public void RezNewScript(IClientAPI remoteClient, InventoryItemBase itemBase)
|
||||
{
|
||||
SceneObjectPart part = GetSceneObjectPart(itemBase.Folder);
|
||||
if (part == null)
|
||||
return;
|
||||
|
||||
if (!Permissions.CanCreateObjectInventory(
|
||||
itemBase.InvType, part.UUID, remoteClient.AgentId))
|
||||
return;
|
||||
|
||||
AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType,
|
||||
Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"),
|
||||
remoteClient.AgentId);
|
||||
AssetService.Store(asset);
|
||||
|
||||
TaskInventoryItem taskItem = new TaskInventoryItem();
|
||||
|
||||
taskItem.ResetIDs(itemBase.Folder);
|
||||
taskItem.ParentID = itemBase.Folder;
|
||||
taskItem.CreationDate = (uint)itemBase.CreationDate;
|
||||
taskItem.Name = itemBase.Name;
|
||||
taskItem.Description = itemBase.Description;
|
||||
taskItem.Type = itemBase.AssetType;
|
||||
taskItem.InvType = itemBase.InvType;
|
||||
taskItem.OwnerID = itemBase.Owner;
|
||||
taskItem.CreatorID = itemBase.CreatorIdAsUuid;
|
||||
taskItem.BasePermissions = itemBase.BasePermissions;
|
||||
taskItem.CurrentPermissions = itemBase.CurrentPermissions;
|
||||
taskItem.EveryonePermissions = itemBase.EveryOnePermissions;
|
||||
taskItem.GroupPermissions = itemBase.GroupPermissions;
|
||||
taskItem.NextPermissions = itemBase.NextPermissions;
|
||||
taskItem.GroupID = itemBase.GroupID;
|
||||
taskItem.GroupPermissions = 0;
|
||||
taskItem.Flags = itemBase.Flags;
|
||||
taskItem.PermsGranter = UUID.Zero;
|
||||
taskItem.PermsMask = 0;
|
||||
taskItem.AssetID = asset.FullID;
|
||||
|
||||
part.Inventory.AddInventoryItem(taskItem, false);
|
||||
part.SendPropertiesToClient(remoteClient);
|
||||
|
||||
part.Inventory.CreateScriptInstance(taskItem, 0, false, DefaultScriptEngine, 0);
|
||||
part.ParentGroup.ResumeScripts();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rez a script into a prim's inventory from another prim
|
||||
/// </summary>
|
||||
/// <param name="remoteClient"></param>
|
||||
/// <param name="itemID"> </param>
|
||||
/// <param name="localID"></param>
|
||||
public void RezScript(UUID srcId, SceneObjectPart srcPart, UUID destId, int pin, int running, int start_param)
|
||||
public void RezScriptFromPrim(UUID srcId, SceneObjectPart srcPart, UUID destId, int pin, int running, int start_param)
|
||||
{
|
||||
TaskInventoryItem srcTaskItem = srcPart.Inventory.GetInventoryItem(srcId);
|
||||
|
||||
|
|
|
@ -6603,7 +6603,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
}
|
||||
|
||||
// the rest of the permission checks are done in RezScript, so check the pin there as well
|
||||
World.RezScript(srcId, m_host, destId, pin, running, start_param);
|
||||
World.RezScriptFromPrim(srcId, m_host, destId, pin, running, start_param);
|
||||
|
||||
// this will cause the delay even if the script pin or permissions were wrong - seems ok
|
||||
ScriptSleep(3000);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue