OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
JsonStoreScriptModule.cs
Go to the documentation of this file.
1 /*
2  * Copyright (c) Contributors
3  * See CONTRIBUTORS.TXT for a full list of copyright holders.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the OpenSim Project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 using Mono.Addins;
28 
29 using System;
30 using System.Reflection;
31 using System.Threading;
32 using System.Text;
33 using System.Net;
34 using System.Net.Sockets;
35 using log4net;
36 using Nini.Config;
37 using OpenMetaverse;
38 using OpenMetaverse.StructuredData;
39 using OpenSim.Framework;
40 using OpenSim.Region.Framework.Interfaces;
41 using OpenSim.Region.Framework.Scenes;
42 using OpenSim.Region.Framework.Scenes.Scripting;
43 using System.Collections.Generic;
44 using System.Text.RegularExpressions;
46 
47 namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
48 {
49  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "JsonStoreScriptModule")]
50 
52  {
53  private static readonly ILog m_log =
54  LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55 
56  private IConfig m_config = null;
57  private bool m_enabled = false;
58  private Scene m_scene = null;
59 
60  private IScriptModuleComms m_comms;
61  private IJsonStoreModule m_store;
62 
63  private Dictionary<UUID,HashSet<UUID>> m_scriptStores = new Dictionary<UUID,HashSet<UUID>>();
64 
65 #region Region Module interface
66 
67  // -----------------------------------------------------------------
71  // -----------------------------------------------------------------
72  public string Name
73  {
74  get { return this.GetType().Name; }
75  }
76 
77  // -----------------------------------------------------------------
83  // -----------------------------------------------------------------
84  public void Initialise(IConfigSource config)
85  {
86  try
87  {
88  if ((m_config = config.Configs["JsonStore"]) == null)
89  {
90  // There is no configuration, the module is disabled
91  // m_log.InfoFormat("[JsonStoreScripts] no configuration info");
92  return;
93  }
94 
95  m_enabled = m_config.GetBoolean("Enabled", m_enabled);
96  }
97  catch (Exception e)
98  {
99  m_log.ErrorFormat("[JsonStoreScripts]: initialization error: {0}", e.Message);
100  return;
101  }
102 
103  if (m_enabled)
104  m_log.DebugFormat("[JsonStoreScripts]: module is enabled");
105  }
106 
107  // -----------------------------------------------------------------
111  // -----------------------------------------------------------------
112  public void PostInitialise()
113  {
114  }
115 
116  // -----------------------------------------------------------------
120  // -----------------------------------------------------------------
121  public void Close()
122  {
123  }
124 
125  // -----------------------------------------------------------------
128  // -----------------------------------------------------------------
129  public void AddRegion(Scene scene)
130  {
131  scene.EventManager.OnScriptReset += HandleScriptReset;
132  scene.EventManager.OnRemoveScript += HandleScriptReset;
133  }
134 
135  // -----------------------------------------------------------------
138  // -----------------------------------------------------------------
139  public void RemoveRegion(Scene scene)
140  {
141  scene.EventManager.OnScriptReset -= HandleScriptReset;
142  scene.EventManager.OnRemoveScript -= HandleScriptReset;
143 
144  // need to remove all references to the scene in the subscription
145  // list to enable full garbage collection of the scene object
146  }
147 
148  // -----------------------------------------------------------------
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  // -----------------------------------------------------------------
172  // -----------------------------------------------------------------
173  public void RegionLoaded(Scene scene)
174  {
175  if (m_enabled)
176  {
177  m_scene = scene;
178  m_comms = m_scene.RequestModuleInterface<IScriptModuleComms>();
179  if (m_comms == null)
180  {
181  m_log.ErrorFormat("[JsonStoreScripts]: ScriptModuleComms interface not defined");
182  m_enabled = false;
183  return;
184  }
185 
186  m_store = m_scene.RequestModuleInterface<IJsonStoreModule>();
187  if (m_store == null)
188  {
189  m_log.ErrorFormat("[JsonStoreScripts]: JsonModule interface not defined");
190  m_enabled = false;
191  return;
192  }
193 
194  try
195  {
196  m_comms.RegisterScriptInvocations(this);
197  m_comms.RegisterConstants(this);
198  }
199  catch (Exception e)
200  {
201  // See http://opensimulator.org/mantis/view.php?id=5971 for more information
202  m_log.WarnFormat("[JsonStoreScripts]: script method registration failed; {0}", e.Message);
203  m_enabled = false;
204  }
205  }
206  }
207 
211  // -----------------------------------------------------------------
212  public Type ReplaceableInterface
213  {
214  get { return null; }
215  }
216 
217 #endregion
218 
219 #region ScriptConstantsInterface
220 
221  [ScriptConstant]
222  public static readonly int JSON_NODETYPE_UNDEF = (int)JsonStoreNodeType.Undefined;
223 
224  [ScriptConstant]
225  public static readonly int JSON_NODETYPE_OBJECT = (int)JsonStoreNodeType.Object;
226 
227  [ScriptConstant]
228  public static readonly int JSON_NODETYPE_ARRAY = (int)JsonStoreNodeType.Array;
229 
230  [ScriptConstant]
231  public static readonly int JSON_NODETYPE_VALUE = (int)JsonStoreNodeType.Value;
232 
233  [ScriptConstant]
234  public static readonly int JSON_VALUETYPE_UNDEF = (int)JsonStoreValueType.Undefined;
235 
236  [ScriptConstant]
237  public static readonly int JSON_VALUETYPE_BOOLEAN = (int)JsonStoreValueType.Boolean;
238 
239  [ScriptConstant]
240  public static readonly int JSON_VALUETYPE_INTEGER = (int)JsonStoreValueType.Integer;
241 
242  [ScriptConstant]
243  public static readonly int JSON_VALUETYPE_FLOAT = (int)JsonStoreValueType.Float;
244 
245  [ScriptConstant]
246  public static readonly int JSON_VALUETYPE_STRING = (int)JsonStoreValueType.String;
247 
248 
249 #endregion
250 
251 #region ScriptInvocationInteface
252  // -----------------------------------------------------------------
256  // -----------------------------------------------------------------
257  [ScriptInvocation]
258  public UUID JsonAttachObjectStore(UUID hostID, UUID scriptID)
259  {
260  UUID uuid = UUID.Zero;
261  if (! m_store.AttachObjectStore(hostID))
262  GenerateRuntimeError("Failed to create Json store");
263 
264  return hostID;
265  }
266 
267  // -----------------------------------------------------------------
271  // -----------------------------------------------------------------
272  [ScriptInvocation]
273  public UUID JsonCreateStore(UUID hostID, UUID scriptID, string value)
274  {
275  UUID uuid = UUID.Zero;
276  if (! m_store.CreateStore(value, ref uuid))
277  GenerateRuntimeError("Failed to create Json store");
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  }
286  return uuid;
287  }
288 
289  // -----------------------------------------------------------------
293  // -----------------------------------------------------------------
294  [ScriptInvocation]
295  public int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID)
296  {
297  lock(m_scriptStores)
298  {
299  if (m_scriptStores.ContainsKey(scriptID))
300  m_scriptStores[scriptID].Remove(storeID);
301  }
302 
303  return m_store.DestroyStore(storeID) ? 1 : 0;
304  }
305 
306  // -----------------------------------------------------------------
310  // -----------------------------------------------------------------
311  [ScriptInvocation]
312  public int JsonTestStore(UUID hostID, UUID scriptID, UUID storeID)
313  {
314  return m_store.TestStore(storeID) ? 1 : 0;
315  }
316 
317  // -----------------------------------------------------------------
321  // -----------------------------------------------------------------
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(
327  o => DoJsonRezObject(hostID, scriptID, reqID, item, pos, vel, rot, param), null, "JsonStoreScriptModule.DoJsonRezObject");
328  return reqID;
329  }
330 
331  // -----------------------------------------------------------------
335  // -----------------------------------------------------------------
336  [ScriptInvocation]
337  public UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier)
338  {
339  UUID reqID = UUID.Random();
340  Util.FireAndForget(
341  o => DoJsonReadNotecard(reqID, hostID, scriptID, storeID, path, notecardIdentifier), null, "JsonStoreScriptModule.JsonReadNotecard");
342  return reqID;
343  }
344 
345  // -----------------------------------------------------------------
349  // -----------------------------------------------------------------
350  [ScriptInvocation]
351  public UUID JsonWriteNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string name)
352  {
353  UUID reqID = UUID.Random();
354  Util.FireAndForget(
355  o => DoJsonWriteNotecard(reqID,hostID,scriptID,storeID,path,name), null, "JsonStoreScriptModule.DoJsonWriteNotecard");
356  return reqID;
357  }
358 
359  // -----------------------------------------------------------------
363  // -----------------------------------------------------------------
364  [ScriptInvocation]
365  public string JsonList2Path(UUID hostID, UUID scriptID, object[] pathlist)
366  {
367  string ipath = ConvertList2Path(pathlist);
368  string opath;
369 
370  if (JsonStore.CanonicalPathExpression(ipath,out opath))
371  return opath;
372 
373  // This won't parse if passed to the other routines as opposed to
374  // returning an empty string which is a valid path and would overwrite
375  // the entire store
376  return "**INVALID**";
377  }
378 
379  // -----------------------------------------------------------------
383  // -----------------------------------------------------------------
384  [ScriptInvocation]
385  public int JsonGetNodeType(UUID hostID, UUID scriptID, UUID storeID, string path)
386  {
387  return (int)m_store.GetNodeType(storeID,path);
388  }
389 
390  // -----------------------------------------------------------------
394  // -----------------------------------------------------------------
395  [ScriptInvocation]
396  public int JsonGetValueType(UUID hostID, UUID scriptID, UUID storeID, string path)
397  {
398  return (int)m_store.GetValueType(storeID,path);
399  }
400 
401  // -----------------------------------------------------------------
405  // -----------------------------------------------------------------
406  [ScriptInvocation]
407  public int JsonSetValue(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
408  {
409  return m_store.SetValue(storeID,path,value,false) ? 1 : 0;
410  }
411 
412  [ScriptInvocation]
413  public int JsonSetJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
414  {
415  return m_store.SetValue(storeID,path,value,true) ? 1 : 0;
416  }
417 
418  // -----------------------------------------------------------------
422  // -----------------------------------------------------------------
423  [ScriptInvocation]
424  public int JsonRemoveValue(UUID hostID, UUID scriptID, UUID storeID, string path)
425  {
426  return m_store.RemoveValue(storeID,path) ? 1 : 0;
427  }
428 
429  // -----------------------------------------------------------------
433  // -----------------------------------------------------------------
434  [ScriptInvocation]
435  public int JsonGetArrayLength(UUID hostID, UUID scriptID, UUID storeID, string path)
436  {
437  return m_store.GetArrayLength(storeID,path);
438  }
439 
440  // -----------------------------------------------------------------
444  // -----------------------------------------------------------------
445  [ScriptInvocation]
446  public string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path)
447  {
448  string value = String.Empty;
449  m_store.GetValue(storeID,path,false,out value);
450  return value;
451  }
452 
453  [ScriptInvocation]
454  public string JsonGetJson(UUID hostID, UUID scriptID, UUID storeID, string path)
455  {
456  string value = String.Empty;
457  m_store.GetValue(storeID,path,true, out value);
458  return value;
459  }
460 
461  // -----------------------------------------------------------------
465  // -----------------------------------------------------------------
466  [ScriptInvocation]
467  public UUID JsonTakeValue(UUID hostID, UUID scriptID, UUID storeID, string path)
468  {
469  UUID reqID = UUID.Random();
470  Util.FireAndForget(
471  o => DoJsonTakeValue(scriptID,reqID,storeID,path,false), null, "JsonStoreScriptModule.DoJsonTakeValue");
472  return reqID;
473  }
474 
475  [ScriptInvocation]
476  public UUID JsonTakeValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
477  {
478  UUID reqID = UUID.Random();
479  Util.FireAndForget(
480  o => DoJsonTakeValue(scriptID,reqID,storeID,path,true), null, "JsonStoreScriptModule.DoJsonTakeValueJson");
481  return reqID;
482  }
483 
484  // -----------------------------------------------------------------
488  // -----------------------------------------------------------------
489  [ScriptInvocation]
490  public UUID JsonReadValue(UUID hostID, UUID scriptID, UUID storeID, string path)
491  {
492  UUID reqID = UUID.Random();
493  Util.FireAndForget(
494  o => DoJsonReadValue(scriptID,reqID,storeID,path,false), null, "JsonStoreScriptModule.DoJsonReadValue");
495  return reqID;
496  }
497 
498  [ScriptInvocation]
499  public UUID JsonReadValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
500  {
501  UUID reqID = UUID.Random();
502  Util.FireAndForget(
503  o => DoJsonReadValue(scriptID,reqID,storeID,path,true), null, "JsonStoreScriptModule.DoJsonReadValueJson");
504  return reqID;
505  }
506 
507 #endregion
508 
509  // -----------------------------------------------------------------
513  // -----------------------------------------------------------------
514  protected void GenerateRuntimeError(string msg)
515  {
516  m_log.InfoFormat("[JsonStore] runtime error: {0}",msg);
517  throw new Exception("JsonStore Runtime Error: " + msg);
518  }
519 
520  // -----------------------------------------------------------------
524  // -----------------------------------------------------------------
525  protected void DispatchValue(UUID scriptID, UUID reqID, string value)
526  {
527  m_comms.DispatchReply(scriptID,1,value,reqID.ToString());
528  }
529 
530  // -----------------------------------------------------------------
534  // -----------------------------------------------------------------
535  private void DoJsonTakeValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
536  {
537  try
538  {
539  m_store.TakeValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
540  return;
541  }
542  catch (Exception e)
543  {
544  m_log.InfoFormat("[JsonStoreScripts]: unable to retrieve value; {0}",e.ToString());
545  }
546 
547  DispatchValue(scriptID,reqID,String.Empty);
548  }
549 
550 
551  // -----------------------------------------------------------------
555  // -----------------------------------------------------------------
556  private void DoJsonReadValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson)
557  {
558  try
559  {
560  m_store.ReadValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); });
561  return;
562  }
563  catch (Exception e)
564  {
565  m_log.InfoFormat("[JsonStoreScripts]: unable to retrieve value; {0}",e.ToString());
566  }
567 
568  DispatchValue(scriptID,reqID,String.Empty);
569  }
570 
571  // -----------------------------------------------------------------
575  // -----------------------------------------------------------------
576  private void DoJsonReadNotecard(
577  UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier)
578  {
579  UUID assetID;
580 
581  if (!UUID.TryParse(notecardIdentifier, out assetID))
582  {
583  SceneObjectPart part = m_scene.GetSceneObjectPart(hostID);
584  assetID = ScriptUtils.GetAssetIdFromItemName(part, notecardIdentifier, (int)AssetType.Notecard);
585  }
586 
587  AssetBase a = m_scene.AssetService.Get(assetID.ToString());
588  if (a == null)
589  GenerateRuntimeError(String.Format("Unable to find notecard asset {0}", assetID));
590 
591  if (a.Type != (sbyte)AssetType.Notecard)
592  GenerateRuntimeError(String.Format("Invalid notecard asset {0}", assetID));
593 
594  m_log.DebugFormat("[JsonStoreScripts]: read notecard in context {0}",storeID);
595 
596  try
597  {
598  string jsondata = SLUtil.ParseNotecardToString(a.Data);
599  int result = m_store.SetValue(storeID, path, jsondata,true) ? 1 : 0;
600  m_comms.DispatchReply(scriptID, result, "", reqID.ToString());
601  return;
602  }
603  catch(SLUtil.NotANotecardFormatException e)
604  {
605  m_log.WarnFormat("[JsonStoreScripts]: Notecard parsing failed; assetId {0} at line number {1}", assetID.ToString(), e.lineNumber);
606  }
607  catch (Exception e)
608  {
609  m_log.WarnFormat("[JsonStoreScripts]: Json parsing failed; {0}", e.Message);
610  }
611 
612  GenerateRuntimeError(String.Format("Json parsing failed for {0}", assetID));
613  m_comms.DispatchReply(scriptID, 0, "", reqID.ToString());
614  }
615 
616  // -----------------------------------------------------------------
620  // -----------------------------------------------------------------
621  private void DoJsonWriteNotecard(UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string name)
622  {
623  string data;
624  if (! m_store.GetValue(storeID,path,true, out data))
625  {
626  m_comms.DispatchReply(scriptID,0,UUID.Zero.ToString(),reqID.ToString());
627  return;
628  }
629 
630  SceneObjectPart host = m_scene.GetSceneObjectPart(hostID);
631 
632  // Create new asset
633  UUID assetID = UUID.Random();
634  AssetBase asset = new AssetBase(assetID, name, (sbyte)AssetType.Notecard, host.OwnerID.ToString());
635  asset.Description = "Json store";
636 
637  int textLength = data.Length;
638  data = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length "
639  + textLength.ToString() + "\n" + data + "}\n";
640 
641  asset.Data = Util.UTF8.GetBytes(data);
642  m_scene.AssetService.Store(asset);
643 
644  // Create Task Entry
645  TaskInventoryItem taskItem = new TaskInventoryItem();
646 
647  taskItem.ResetIDs(host.UUID);
648  taskItem.ParentID = host.UUID;
649  taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch();
650  taskItem.Name = asset.Name;
651  taskItem.Description = asset.Description;
652  taskItem.Type = (int)AssetType.Notecard;
653  taskItem.InvType = (int)InventoryType.Notecard;
654  taskItem.OwnerID = host.OwnerID;
655  taskItem.CreatorID = host.OwnerID;
656  taskItem.BasePermissions = (uint)PermissionMask.All;
657  taskItem.CurrentPermissions = (uint)PermissionMask.All;
658  taskItem.EveryonePermissions = 0;
659  taskItem.NextPermissions = (uint)PermissionMask.All;
660  taskItem.GroupID = host.GroupID;
661  taskItem.GroupPermissions = 0;
662  taskItem.Flags = 0;
663  taskItem.PermsGranter = UUID.Zero;
664  taskItem.PermsMask = 0;
665  taskItem.AssetID = asset.FullID;
666 
667  host.Inventory.AddInventoryItem(taskItem, false);
668 
669  m_comms.DispatchReply(scriptID,1,assetID.ToString(),reqID.ToString());
670  }
671 
672  // -----------------------------------------------------------------
676  // -----------------------------------------------------------------
677  protected static Regex m_ArrayPattern = new Regex("^([0-9]+|\\+)$");
678  private string ConvertList2Path(object[] pathlist)
679  {
680  string path = "";
681  for (int i = 0; i < pathlist.Length; i++)
682  {
683  string token = "";
684 
685  if (pathlist[i] is string)
686  {
687  token = pathlist[i].ToString();
688 
689  // Check to see if this is a bare number which would not be a valid
690  // identifier otherwise
691  if (m_ArrayPattern.IsMatch(token))
692  token = '[' + token + ']';
693  }
694  else if (pathlist[i] is int)
695  {
696  token = "[" + pathlist[i].ToString() + "]";
697  }
698  else
699  {
700  token = "." + pathlist[i].ToString() + ".";
701  }
702 
703  path += token + ".";
704  }
705 
706  return path;
707  }
708 
709  // -----------------------------------------------------------------
713  // -----------------------------------------------------------------
714  private void DoJsonRezObject(UUID hostID, UUID scriptID, UUID reqID, string name, Vector3 pos, Vector3 vel, Quaternion rot, string param)
715  {
716  if (Double.IsNaN(rot.X) || Double.IsNaN(rot.Y) || Double.IsNaN(rot.Z) || Double.IsNaN(rot.W))
717  {
718  GenerateRuntimeError("Invalid rez rotation");
719  return;
720  }
721 
722  SceneObjectGroup host = m_scene.GetSceneObjectGroup(hostID);
723  if (host == null)
724  {
725  GenerateRuntimeError(String.Format("Unable to find rezzing host '{0}'",hostID));
726  return;
727  }
728 
729  // hpos = host.RootPart.GetWorldPosition()
730  // float dist = (float)llVecDist(hpos, pos);
731  // if (dist > m_ScriptDistanceFactor * 10.0f)
732  // return;
733 
734  TaskInventoryItem item = host.RootPart.Inventory.GetInventoryItem(name);
735  if (item == null)
736  {
737  GenerateRuntimeError(String.Format("Unable to find object to rez '{0}'",name));
738  return;
739  }
740 
741  if (item.InvType != (int)InventoryType.Object)
742  {
743  GenerateRuntimeError("Can't create requested object; object is missing from database");
744  return;
745  }
746 
747  List<SceneObjectGroup> objlist;
748  List<Vector3> veclist;
749 
750  Vector3 bbox = new Vector3();
751  float offsetHeight;
752  bool success = host.RootPart.Inventory.GetRezReadySceneObjects(item, out objlist, out veclist, out bbox, out offsetHeight);
753  if (! success)
754  {
755  GenerateRuntimeError("Failed to create object");
756  return;
757  }
758 
759  int totalPrims = 0;
760  foreach (SceneObjectGroup group in objlist)
761  totalPrims += group.PrimCount;
762 
763  if (! m_scene.Permissions.CanRezObject(totalPrims, item.OwnerID, pos))
764  {
765  GenerateRuntimeError("Not allowed to create the object");
766  return;
767  }
768 
769  if (! m_scene.Permissions.BypassPermissions())
770  {
771  if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
772  host.RootPart.Inventory.RemoveInventoryItem(item.ItemID);
773  }
774 
775  for (int i = 0; i < objlist.Count; i++)
776  {
777  SceneObjectGroup group = objlist[i];
778  Vector3 curpos = pos + veclist[i];
779 
780  if (group.IsAttachment == false && group.RootPart.Shape.State != 0)
781  {
782  group.RootPart.AttachedPos = group.AbsolutePosition;
783  group.RootPart.Shape.LastAttachPoint = (byte)group.AttachmentPoint;
784  }
785 
786  group.FromPartID = host.RootPart.UUID;
787  m_scene.AddNewSceneObject(group, true, curpos, rot, vel);
788 
789  UUID storeID = group.UUID;
790  if (! m_store.CreateStore(param, ref storeID))
791  {
792  GenerateRuntimeError("Unable to create jsonstore for new object");
793  continue;
794  }
795 
796  // We can only call this after adding the scene object, since the scene object references the scene
797  // to find out if scripts should be activated at all.
798  group.RootPart.SetDieAtEdge(true);
799  group.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 3);
800  group.ResumeScripts();
801 
802  group.ScheduleGroupForFullUpdate();
803 
804  // send the reply back to the host object, use the integer param to indicate the number
805  // of remaining objects
806  m_comms.DispatchReply(scriptID, objlist.Count-i-1, group.RootPart.UUID.ToString(), reqID.ToString());
807  }
808  }
809  }
810 }
int JsonRemoveValue(UUID hostID, UUID scriptID, UUID storeID, string path)
IEntityInventory Inventory
This part's inventory
int JsonSetJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
UUID JsonReadValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
string JsonList2Path(UUID hostID, UUID scriptID, object[] pathlist)
UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier)
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
UUID JsonRezAtRoot(UUID hostID, UUID scriptID, string item, Vector3 pos, Vector3 vel, Quaternion rot, string param)
int JsonGetArrayLength(UUID hostID, UUID scriptID, UUID storeID, string path)
UUID JsonWriteNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string name)
int JsonSetValue(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
Represents an item in a task inventory
OpenSim.Framework.PermissionMask PermissionMask
Asset class. All Assets are reference by this class or a class derived from this class ...
Definition: AssetBase.cs:49
void RegionLoaded(Scene scene)
Called when all modules have been added for a region. This is where we hook up events ...
int JsonGetValueType(UUID hostID, UUID scriptID, UUID storeID, string path)
UUID JsonReadValue(UUID hostID, UUID scriptID, UUID storeID, string path)
void AddInventoryItem(TaskInventoryItem item, bool allowedDrop)
Add an item to this entity's inventory. If an item with the same name already exists, then an alternative name is chosen.
UUID JsonTakeValueJson(UUID hostID, UUID scriptID, UUID storeID, string path)
uint AttachmentPoint
Attachment point of this scene object to an avatar.
Interface for communication between OpenSim modules and in-world scripts
int RemoveInventoryItem(UUID itemID)
Remove an item from this entity's inventory
string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path)
void PostInitialise()
everything is loaded, perform post load configuration
UUID JsonTakeValue(UUID hostID, UUID scriptID, UUID storeID, string path)
void Initialise(IConfigSource config)
Initialise this shared module
static bool CanonicalPathExpression(string ipath, out string opath)
Definition: JsonStore.cs:107
string JsonGetJson(UUID hostID, UUID scriptID, UUID storeID, string path)
int JsonGetNodeType(UUID hostID, UUID scriptID, UUID storeID, string path)
bool IsAttachment
Is this scene object acting as an attachment?