From b83a22414784495f772d29386bdeb0e2aa708374 Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Sun, 9 Feb 2014 18:07:49 -0800 Subject: [PATCH] Add JsonRezAtRoot script function. Operation is very similar to llRezAtRoot except that the start parameter is a Json string that will be unpacked into a json store identified by the objects uuid. This makes a much more expressive (and simpler) way of passing initial parameters to a rezzed object. --- .../JsonStore/JsonStoreScriptModule.cs | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs index 9fbfb66b8e..a6c12fd670 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs @@ -314,6 +314,19 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore return m_store.TestStore(storeID) ? 1 : 0; } + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + [ScriptInvocation] + public UUID JsonRezAtRoot(UUID hostID, UUID scriptID, string item, Vector3 pos, Vector3 vel, Quaternion rot, string param) + { + UUID reqID = UUID.Random(); + Util.FireAndForget(o => DoJsonRezObject(hostID, scriptID, reqID, item, pos, vel, rot, param)); + return reqID; + } + // ----------------------------------------------------------------- /// /// @@ -682,5 +695,103 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore return path; } + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + private void DoJsonRezObject(UUID hostID, UUID scriptID, UUID reqID, string name, Vector3 pos, Vector3 vel, Quaternion rot, string param) + { + if (Double.IsNaN(rot.X) || Double.IsNaN(rot.Y) || Double.IsNaN(rot.Z) || Double.IsNaN(rot.W)) + { + GenerateRuntimeError("Invalid rez rotation"); + return; + } + + SceneObjectGroup host = m_scene.GetSceneObjectGroup(hostID); + if (host == null) + { + GenerateRuntimeError(String.Format("Unable to find rezzing host '{0}'",hostID)); + return; + } + + // hpos = host.RootPart.GetWorldPosition() + // float dist = (float)llVecDist(hpos, pos); + // if (dist > m_ScriptDistanceFactor * 10.0f) + // return; + + TaskInventoryItem item = host.RootPart.Inventory.GetInventoryItem(name); + if (item == null) + { + GenerateRuntimeError(String.Format("Unable to find object to rez '{0}'",name)); + return; + } + + if (item.InvType != (int)InventoryType.Object) + { + GenerateRuntimeError("Can't create requested object; object is missing from database"); + return; + } + + List objlist; + List veclist; + + bool success = host.RootPart.Inventory.GetRezReadySceneObjects(item, out objlist, out veclist); + if (! success) + { + GenerateRuntimeError("Failed to create object"); + return; + } + + int totalPrims = 0; + foreach (SceneObjectGroup group in objlist) + totalPrims += group.PrimCount; + + if (! m_scene.Permissions.CanRezObject(totalPrims, item.OwnerID, pos)) + { + GenerateRuntimeError("Not allowed to create the object"); + return; + } + + if (! m_scene.Permissions.BypassPermissions()) + { + if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) + host.RootPart.Inventory.RemoveInventoryItem(item.ItemID); + } + + for (int i = 0; i < objlist.Count; i++) + { + SceneObjectGroup group = objlist[i]; + Vector3 curpos = pos + veclist[i]; + + if (group.IsAttachment == false && group.RootPart.Shape.State != 0) + { + group.RootPart.AttachedPos = group.AbsolutePosition; + group.RootPart.Shape.LastAttachPoint = (byte)group.AttachmentPoint; + } + + group.FromPartID = host.RootPart.UUID; + m_scene.AddNewSceneObject(group, true, curpos, rot, vel); + + UUID storeID = group.UUID; + if (! m_store.CreateStore(param, ref storeID)) + { + GenerateRuntimeError("Unable to create jsonstore for new object"); + continue; + } + + // We can only call this after adding the scene object, since the scene object references the scene + // to find out if scripts should be activated at all. + group.RootPart.SetDieAtEdge(true); + group.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 3); + group.ResumeScripts(); + + group.ScheduleGroupForFullUpdate(); + + // send the reply back to the host object, use the integer param to indicate the number + // of remaining objects + m_comms.DispatchReply(scriptID, objlist.Count-i-1, group.RootPart.UUID.ToString(), reqID.ToString()); + } + } } }