diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs | 152 |
1 files changed, 151 insertions, 1 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs index 1bb5aee..a6c12fd 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs | |||
@@ -59,7 +59,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
59 | 59 | ||
60 | private IScriptModuleComms m_comms; | 60 | private IScriptModuleComms m_comms; |
61 | private IJsonStoreModule m_store; | 61 | private IJsonStoreModule m_store; |
62 | 62 | ||
63 | private Dictionary<UUID,HashSet<UUID>> m_scriptStores = new Dictionary<UUID,HashSet<UUID>>(); | ||
64 | |||
63 | #region Region Module interface | 65 | #region Region Module interface |
64 | 66 | ||
65 | // ----------------------------------------------------------------- | 67 | // ----------------------------------------------------------------- |
@@ -126,6 +128,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
126 | // ----------------------------------------------------------------- | 128 | // ----------------------------------------------------------------- |
127 | public void AddRegion(Scene scene) | 129 | public void AddRegion(Scene scene) |
128 | { | 130 | { |
131 | scene.EventManager.OnScriptReset += HandleScriptReset; | ||
132 | scene.EventManager.OnRemoveScript += HandleScriptReset; | ||
129 | } | 133 | } |
130 | 134 | ||
131 | // ----------------------------------------------------------------- | 135 | // ----------------------------------------------------------------- |
@@ -134,12 +138,34 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
134 | // ----------------------------------------------------------------- | 138 | // ----------------------------------------------------------------- |
135 | public void RemoveRegion(Scene scene) | 139 | public void RemoveRegion(Scene scene) |
136 | { | 140 | { |
141 | scene.EventManager.OnScriptReset -= HandleScriptReset; | ||
142 | scene.EventManager.OnRemoveScript -= HandleScriptReset; | ||
143 | |||
137 | // need to remove all references to the scene in the subscription | 144 | // need to remove all references to the scene in the subscription |
138 | // list to enable full garbage collection of the scene object | 145 | // list to enable full garbage collection of the scene object |
139 | } | 146 | } |
140 | 147 | ||
141 | // ----------------------------------------------------------------- | 148 | // ----------------------------------------------------------------- |
142 | /// <summary> | 149 | /// <summary> |
150 | /// </summary> | ||
151 | // ----------------------------------------------------------------- | ||
152 | private void HandleScriptReset(uint localID, UUID itemID) | ||
153 | { | ||
154 | HashSet<UUID> stores; | ||
155 | |||
156 | lock (m_scriptStores) | ||
157 | { | ||
158 | if (! m_scriptStores.TryGetValue(itemID, out stores)) | ||
159 | return; | ||
160 | m_scriptStores.Remove(itemID); | ||
161 | } | ||
162 | |||
163 | foreach (UUID id in stores) | ||
164 | m_store.DestroyStore(id); | ||
165 | } | ||
166 | |||
167 | // ----------------------------------------------------------------- | ||
168 | /// <summary> | ||
143 | /// Called when all modules have been added for a region. This is | 169 | /// Called when all modules have been added for a region. This is |
144 | /// where we hook up events | 170 | /// where we hook up events |
145 | /// </summary> | 171 | /// </summary> |
@@ -250,6 +276,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
250 | if (! m_store.CreateStore(value, ref uuid)) | 276 | if (! m_store.CreateStore(value, ref uuid)) |
251 | GenerateRuntimeError("Failed to create Json store"); | 277 | GenerateRuntimeError("Failed to create Json store"); |
252 | 278 | ||
279 | lock (m_scriptStores) | ||
280 | { | ||
281 | if (! m_scriptStores.ContainsKey(scriptID)) | ||
282 | m_scriptStores[scriptID] = new HashSet<UUID>(); | ||
283 | |||
284 | m_scriptStores[scriptID].Add(uuid); | ||
285 | } | ||
253 | return uuid; | 286 | return uuid; |
254 | } | 287 | } |
255 | 288 | ||
@@ -261,6 +294,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
261 | [ScriptInvocation] | 294 | [ScriptInvocation] |
262 | public int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID) | 295 | public int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID) |
263 | { | 296 | { |
297 | lock(m_scriptStores) | ||
298 | { | ||
299 | if (m_scriptStores.ContainsKey(scriptID)) | ||
300 | m_scriptStores[scriptID].Remove(storeID); | ||
301 | } | ||
302 | |||
264 | return m_store.DestroyStore(storeID) ? 1 : 0; | 303 | return m_store.DestroyStore(storeID) ? 1 : 0; |
265 | } | 304 | } |
266 | 305 | ||
@@ -281,6 +320,19 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
281 | /// </summary> | 320 | /// </summary> |
282 | // ----------------------------------------------------------------- | 321 | // ----------------------------------------------------------------- |
283 | [ScriptInvocation] | 322 | [ScriptInvocation] |
323 | public UUID JsonRezAtRoot(UUID hostID, UUID scriptID, string item, Vector3 pos, Vector3 vel, Quaternion rot, string param) | ||
324 | { | ||
325 | UUID reqID = UUID.Random(); | ||
326 | Util.FireAndForget(o => DoJsonRezObject(hostID, scriptID, reqID, item, pos, vel, rot, param)); | ||
327 | return reqID; | ||
328 | } | ||
329 | |||
330 | // ----------------------------------------------------------------- | ||
331 | /// <summary> | ||
332 | /// | ||
333 | /// </summary> | ||
334 | // ----------------------------------------------------------------- | ||
335 | [ScriptInvocation] | ||
284 | public UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier) | 336 | public UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier) |
285 | { | 337 | { |
286 | UUID reqID = UUID.Random(); | 338 | UUID reqID = UUID.Random(); |
@@ -643,5 +695,103 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
643 | return path; | 695 | return path; |
644 | } | 696 | } |
645 | 697 | ||
698 | // ----------------------------------------------------------------- | ||
699 | /// <summary> | ||
700 | /// | ||
701 | /// </summary> | ||
702 | // ----------------------------------------------------------------- | ||
703 | private void DoJsonRezObject(UUID hostID, UUID scriptID, UUID reqID, string name, Vector3 pos, Vector3 vel, Quaternion rot, string param) | ||
704 | { | ||
705 | if (Double.IsNaN(rot.X) || Double.IsNaN(rot.Y) || Double.IsNaN(rot.Z) || Double.IsNaN(rot.W)) | ||
706 | { | ||
707 | GenerateRuntimeError("Invalid rez rotation"); | ||
708 | return; | ||
709 | } | ||
710 | |||
711 | SceneObjectGroup host = m_scene.GetSceneObjectGroup(hostID); | ||
712 | if (host == null) | ||
713 | { | ||
714 | GenerateRuntimeError(String.Format("Unable to find rezzing host '{0}'",hostID)); | ||
715 | return; | ||
716 | } | ||
717 | |||
718 | // hpos = host.RootPart.GetWorldPosition() | ||
719 | // float dist = (float)llVecDist(hpos, pos); | ||
720 | // if (dist > m_ScriptDistanceFactor * 10.0f) | ||
721 | // return; | ||
722 | |||
723 | TaskInventoryItem item = host.RootPart.Inventory.GetInventoryItem(name); | ||
724 | if (item == null) | ||
725 | { | ||
726 | GenerateRuntimeError(String.Format("Unable to find object to rez '{0}'",name)); | ||
727 | return; | ||
728 | } | ||
729 | |||
730 | if (item.InvType != (int)InventoryType.Object) | ||
731 | { | ||
732 | GenerateRuntimeError("Can't create requested object; object is missing from database"); | ||
733 | return; | ||
734 | } | ||
735 | |||
736 | List<SceneObjectGroup> objlist; | ||
737 | List<Vector3> veclist; | ||
738 | |||
739 | bool success = host.RootPart.Inventory.GetRezReadySceneObjects(item, out objlist, out veclist); | ||
740 | if (! success) | ||
741 | { | ||
742 | GenerateRuntimeError("Failed to create object"); | ||
743 | return; | ||
744 | } | ||
745 | |||
746 | int totalPrims = 0; | ||
747 | foreach (SceneObjectGroup group in objlist) | ||
748 | totalPrims += group.PrimCount; | ||
749 | |||
750 | if (! m_scene.Permissions.CanRezObject(totalPrims, item.OwnerID, pos)) | ||
751 | { | ||
752 | GenerateRuntimeError("Not allowed to create the object"); | ||
753 | return; | ||
754 | } | ||
755 | |||
756 | if (! m_scene.Permissions.BypassPermissions()) | ||
757 | { | ||
758 | if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) | ||
759 | host.RootPart.Inventory.RemoveInventoryItem(item.ItemID); | ||
760 | } | ||
761 | |||
762 | for (int i = 0; i < objlist.Count; i++) | ||
763 | { | ||
764 | SceneObjectGroup group = objlist[i]; | ||
765 | Vector3 curpos = pos + veclist[i]; | ||
766 | |||
767 | if (group.IsAttachment == false && group.RootPart.Shape.State != 0) | ||
768 | { | ||
769 | group.RootPart.AttachedPos = group.AbsolutePosition; | ||
770 | group.RootPart.Shape.LastAttachPoint = (byte)group.AttachmentPoint; | ||
771 | } | ||
772 | |||
773 | group.FromPartID = host.RootPart.UUID; | ||
774 | m_scene.AddNewSceneObject(group, true, curpos, rot, vel); | ||
775 | |||
776 | UUID storeID = group.UUID; | ||
777 | if (! m_store.CreateStore(param, ref storeID)) | ||
778 | { | ||
779 | GenerateRuntimeError("Unable to create jsonstore for new object"); | ||
780 | continue; | ||
781 | } | ||
782 | |||
783 | // We can only call this after adding the scene object, since the scene object references the scene | ||
784 | // to find out if scripts should be activated at all. | ||
785 | group.RootPart.SetDieAtEdge(true); | ||
786 | group.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 3); | ||
787 | group.ResumeScripts(); | ||
788 | |||
789 | group.ScheduleGroupForFullUpdate(); | ||
790 | |||
791 | // send the reply back to the host object, use the integer param to indicate the number | ||
792 | // of remaining objects | ||
793 | m_comms.DispatchReply(scriptID, objlist.Count-i-1, group.RootPart.UUID.ToString(), reqID.ToString()); | ||
794 | } | ||
795 | } | ||
646 | } | 796 | } |
647 | } | 797 | } |