clockwerk-opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 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; |
||
45 | using PermissionMask = OpenSim.Framework.PermissionMask; |
||
46 | |||
47 | namespace OpenSim.Region.OptionalModules.Scripting.JsonStore |
||
48 | { |
||
49 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "JsonStoreScriptModule")] |
||
50 | |||
51 | public class JsonStoreScriptModule : INonSharedRegionModule |
||
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 | // ----------------------------------------------------------------- |
||
68 | /// <summary> |
||
69 | /// Name of this shared module is it's class name |
||
70 | /// </summary> |
||
71 | // ----------------------------------------------------------------- |
||
72 | public string Name |
||
73 | { |
||
74 | get { return this.GetType().Name; } |
||
75 | } |
||
76 | |||
77 | // ----------------------------------------------------------------- |
||
78 | /// <summary> |
||
79 | /// Initialise this shared module |
||
80 | /// </summary> |
||
81 | /// <param name="scene">this region is getting initialised</param> |
||
82 | /// <param name="source">nini config, we are not using this</param> |
||
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 | // ----------------------------------------------------------------- |
||
108 | /// <summary> |
||
109 | /// everything is loaded, perform post load configuration |
||
110 | /// </summary> |
||
111 | // ----------------------------------------------------------------- |
||
112 | public void PostInitialise() |
||
113 | { |
||
114 | } |
||
115 | |||
116 | // ----------------------------------------------------------------- |
||
117 | /// <summary> |
||
118 | /// Nothing to do on close |
||
119 | /// </summary> |
||
120 | // ----------------------------------------------------------------- |
||
121 | public void Close() |
||
122 | { |
||
123 | } |
||
124 | |||
125 | // ----------------------------------------------------------------- |
||
126 | /// <summary> |
||
127 | /// </summary> |
||
128 | // ----------------------------------------------------------------- |
||
129 | public void AddRegion(Scene scene) |
||
130 | { |
||
131 | scene.EventManager.OnScriptReset += HandleScriptReset; |
||
132 | scene.EventManager.OnRemoveScript += HandleScriptReset; |
||
133 | } |
||
134 | |||
135 | // ----------------------------------------------------------------- |
||
136 | /// <summary> |
||
137 | /// </summary> |
||
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 | // ----------------------------------------------------------------- |
||
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> |
||
169 | /// Called when all modules have been added for a region. This is |
||
170 | /// where we hook up events |
||
171 | /// </summary> |
||
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 | |||
208 | /// ----------------------------------------------------------------- |
||
209 | /// <summary> |
||
210 | /// </summary> |
||
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 | // ----------------------------------------------------------------- |
||
253 | /// <summary> |
||
254 | /// |
||
255 | /// </summary> |
||
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 | // ----------------------------------------------------------------- |
||
268 | /// <summary> |
||
269 | /// |
||
270 | /// </summary> |
||
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 | // ----------------------------------------------------------------- |
||
290 | /// <summary> |
||
291 | /// |
||
292 | /// </summary> |
||
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 | // ----------------------------------------------------------------- |
||
307 | /// <summary> |
||
308 | /// |
||
309 | /// </summary> |
||
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 | // ----------------------------------------------------------------- |
||
318 | /// <summary> |
||
319 | /// |
||
320 | /// </summary> |
||
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(o => DoJsonRezObject(hostID, scriptID, reqID, item, pos, vel, rot, param)); |
||
327 | return reqID; |
||
328 | } |
||
329 | |||
330 | // ----------------------------------------------------------------- |
||
331 | /// <summary> |
||
332 | /// |
||
333 | /// </summary> |
||
334 | // ----------------------------------------------------------------- |
||
335 | [ScriptInvocation] |
||
336 | public UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier) |
||
337 | { |
||
338 | UUID reqID = UUID.Random(); |
||
339 | Util.FireAndForget(o => DoJsonReadNotecard(reqID, hostID, scriptID, storeID, path, notecardIdentifier)); |
||
340 | return reqID; |
||
341 | } |
||
342 | |||
343 | // ----------------------------------------------------------------- |
||
344 | /// <summary> |
||
345 | /// |
||
346 | /// </summary> |
||
347 | // ----------------------------------------------------------------- |
||
348 | [ScriptInvocation] |
||
349 | public UUID JsonWriteNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string name) |
||
350 | { |
||
351 | UUID reqID = UUID.Random(); |
||
352 | Util.FireAndForget(delegate(object o) { DoJsonWriteNotecard(reqID,hostID,scriptID,storeID,path,name); }); |
||
353 | return reqID; |
||
354 | } |
||
355 | |||
356 | // ----------------------------------------------------------------- |
||
357 | /// <summary> |
||
358 | /// |
||
359 | /// </summary> |
||
360 | // ----------------------------------------------------------------- |
||
361 | [ScriptInvocation] |
||
362 | public string JsonList2Path(UUID hostID, UUID scriptID, object[] pathlist) |
||
363 | { |
||
364 | string ipath = ConvertList2Path(pathlist); |
||
365 | string opath; |
||
366 | |||
367 | if (JsonStore.CanonicalPathExpression(ipath,out opath)) |
||
368 | return opath; |
||
369 | |||
370 | // This won't parse if passed to the other routines as opposed to |
||
371 | // returning an empty string which is a valid path and would overwrite |
||
372 | // the entire store |
||
373 | return "**INVALID**"; |
||
374 | } |
||
375 | |||
376 | // ----------------------------------------------------------------- |
||
377 | /// <summary> |
||
378 | /// |
||
379 | /// </summary> |
||
380 | // ----------------------------------------------------------------- |
||
381 | [ScriptInvocation] |
||
382 | public int JsonGetNodeType(UUID hostID, UUID scriptID, UUID storeID, string path) |
||
383 | { |
||
384 | return (int)m_store.GetNodeType(storeID,path); |
||
385 | } |
||
386 | |||
387 | // ----------------------------------------------------------------- |
||
388 | /// <summary> |
||
389 | /// |
||
390 | /// </summary> |
||
391 | // ----------------------------------------------------------------- |
||
392 | [ScriptInvocation] |
||
393 | public int JsonGetValueType(UUID hostID, UUID scriptID, UUID storeID, string path) |
||
394 | { |
||
395 | return (int)m_store.GetValueType(storeID,path); |
||
396 | } |
||
397 | |||
398 | // ----------------------------------------------------------------- |
||
399 | /// <summary> |
||
400 | /// |
||
401 | /// </summary> |
||
402 | // ----------------------------------------------------------------- |
||
403 | [ScriptInvocation] |
||
404 | public int JsonSetValue(UUID hostID, UUID scriptID, UUID storeID, string path, string value) |
||
405 | { |
||
406 | return m_store.SetValue(storeID,path,value,false) ? 1 : 0; |
||
407 | } |
||
408 | |||
409 | [ScriptInvocation] |
||
410 | public int JsonSetJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value) |
||
411 | { |
||
412 | return m_store.SetValue(storeID,path,value,true) ? 1 : 0; |
||
413 | } |
||
414 | |||
415 | // ----------------------------------------------------------------- |
||
416 | /// <summary> |
||
417 | /// |
||
418 | /// </summary> |
||
419 | // ----------------------------------------------------------------- |
||
420 | [ScriptInvocation] |
||
421 | public int JsonRemoveValue(UUID hostID, UUID scriptID, UUID storeID, string path) |
||
422 | { |
||
423 | return m_store.RemoveValue(storeID,path) ? 1 : 0; |
||
424 | } |
||
425 | |||
426 | // ----------------------------------------------------------------- |
||
427 | /// <summary> |
||
428 | /// |
||
429 | /// </summary> |
||
430 | // ----------------------------------------------------------------- |
||
431 | [ScriptInvocation] |
||
432 | public int JsonGetArrayLength(UUID hostID, UUID scriptID, UUID storeID, string path) |
||
433 | { |
||
434 | return m_store.GetArrayLength(storeID,path); |
||
435 | } |
||
436 | |||
437 | // ----------------------------------------------------------------- |
||
438 | /// <summary> |
||
439 | /// |
||
440 | /// </summary> |
||
441 | // ----------------------------------------------------------------- |
||
442 | [ScriptInvocation] |
||
443 | public string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path) |
||
444 | { |
||
445 | string value = String.Empty; |
||
446 | m_store.GetValue(storeID,path,false,out value); |
||
447 | return value; |
||
448 | } |
||
449 | |||
450 | [ScriptInvocation] |
||
451 | public string JsonGetJson(UUID hostID, UUID scriptID, UUID storeID, string path) |
||
452 | { |
||
453 | string value = String.Empty; |
||
454 | m_store.GetValue(storeID,path,true, out value); |
||
455 | return value; |
||
456 | } |
||
457 | |||
458 | // ----------------------------------------------------------------- |
||
459 | /// <summary> |
||
460 | /// |
||
461 | /// </summary> |
||
462 | // ----------------------------------------------------------------- |
||
463 | [ScriptInvocation] |
||
464 | public UUID JsonTakeValue(UUID hostID, UUID scriptID, UUID storeID, string path) |
||
465 | { |
||
466 | UUID reqID = UUID.Random(); |
||
467 | Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,false); }); |
||
468 | return reqID; |
||
469 | } |
||
470 | |||
471 | [ScriptInvocation] |
||
472 | public UUID JsonTakeValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) |
||
473 | { |
||
474 | UUID reqID = UUID.Random(); |
||
475 | Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,true); }); |
||
476 | return reqID; |
||
477 | } |
||
478 | |||
479 | // ----------------------------------------------------------------- |
||
480 | /// <summary> |
||
481 | /// |
||
482 | /// </summary> |
||
483 | // ----------------------------------------------------------------- |
||
484 | [ScriptInvocation] |
||
485 | public UUID JsonReadValue(UUID hostID, UUID scriptID, UUID storeID, string path) |
||
486 | { |
||
487 | UUID reqID = UUID.Random(); |
||
488 | Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,false); }); |
||
489 | return reqID; |
||
490 | } |
||
491 | |||
492 | [ScriptInvocation] |
||
493 | public UUID JsonReadValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) |
||
494 | { |
||
495 | UUID reqID = UUID.Random(); |
||
496 | Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,true); }); |
||
497 | return reqID; |
||
498 | } |
||
499 | |||
500 | #endregion |
||
501 | |||
502 | // ----------------------------------------------------------------- |
||
503 | /// <summary> |
||
504 | /// |
||
505 | /// </summary> |
||
506 | // ----------------------------------------------------------------- |
||
507 | protected void GenerateRuntimeError(string msg) |
||
508 | { |
||
509 | m_log.InfoFormat("[JsonStore] runtime error: {0}",msg); |
||
510 | throw new Exception("JsonStore Runtime Error: " + msg); |
||
511 | } |
||
512 | |||
513 | // ----------------------------------------------------------------- |
||
514 | /// <summary> |
||
515 | /// |
||
516 | /// </summary> |
||
517 | // ----------------------------------------------------------------- |
||
518 | protected void DispatchValue(UUID scriptID, UUID reqID, string value) |
||
519 | { |
||
520 | m_comms.DispatchReply(scriptID,1,value,reqID.ToString()); |
||
521 | } |
||
522 | |||
523 | // ----------------------------------------------------------------- |
||
524 | /// <summary> |
||
525 | /// |
||
526 | /// </summary> |
||
527 | // ----------------------------------------------------------------- |
||
528 | private void DoJsonTakeValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson) |
||
529 | { |
||
530 | try |
||
531 | { |
||
532 | m_store.TakeValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); }); |
||
533 | return; |
||
534 | } |
||
535 | catch (Exception e) |
||
536 | { |
||
537 | m_log.InfoFormat("[JsonStoreScripts]: unable to retrieve value; {0}",e.ToString()); |
||
538 | } |
||
539 | |||
540 | DispatchValue(scriptID,reqID,String.Empty); |
||
541 | } |
||
542 | |||
543 | |||
544 | // ----------------------------------------------------------------- |
||
545 | /// <summary> |
||
546 | /// |
||
547 | /// </summary> |
||
548 | // ----------------------------------------------------------------- |
||
549 | private void DoJsonReadValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson) |
||
550 | { |
||
551 | try |
||
552 | { |
||
553 | m_store.ReadValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); }); |
||
554 | return; |
||
555 | } |
||
556 | catch (Exception e) |
||
557 | { |
||
558 | m_log.InfoFormat("[JsonStoreScripts]: unable to retrieve value; {0}",e.ToString()); |
||
559 | } |
||
560 | |||
561 | DispatchValue(scriptID,reqID,String.Empty); |
||
562 | } |
||
563 | |||
564 | // ----------------------------------------------------------------- |
||
565 | /// <summary> |
||
566 | /// |
||
567 | /// </summary> |
||
568 | // ----------------------------------------------------------------- |
||
569 | private void DoJsonReadNotecard( |
||
570 | UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier) |
||
571 | { |
||
572 | UUID assetID; |
||
573 | |||
574 | if (!UUID.TryParse(notecardIdentifier, out assetID)) |
||
575 | { |
||
576 | SceneObjectPart part = m_scene.GetSceneObjectPart(hostID); |
||
577 | assetID = ScriptUtils.GetAssetIdFromItemName(part, notecardIdentifier, (int)AssetType.Notecard); |
||
578 | } |
||
579 | |||
580 | AssetBase a = m_scene.AssetService.Get(assetID.ToString()); |
||
581 | if (a == null) |
||
582 | GenerateRuntimeError(String.Format("Unable to find notecard asset {0}", assetID)); |
||
583 | |||
584 | if (a.Type != (sbyte)AssetType.Notecard) |
||
585 | GenerateRuntimeError(String.Format("Invalid notecard asset {0}", assetID)); |
||
586 | |||
587 | m_log.DebugFormat("[JsonStoreScripts]: read notecard in context {0}",storeID); |
||
588 | |||
589 | try |
||
590 | { |
||
591 | string jsondata = SLUtil.ParseNotecardToString(Encoding.UTF8.GetString(a.Data)); |
||
592 | int result = m_store.SetValue(storeID, path, jsondata,true) ? 1 : 0; |
||
593 | m_comms.DispatchReply(scriptID, result, "", reqID.ToString()); |
||
594 | return; |
||
595 | } |
||
596 | catch (Exception e) |
||
597 | { |
||
598 | m_log.WarnFormat("[JsonStoreScripts]: Json parsing failed; {0}", e.Message); |
||
599 | } |
||
600 | |||
601 | GenerateRuntimeError(String.Format("Json parsing failed for {0}", assetID)); |
||
602 | m_comms.DispatchReply(scriptID, 0, "", reqID.ToString()); |
||
603 | } |
||
604 | |||
605 | // ----------------------------------------------------------------- |
||
606 | /// <summary> |
||
607 | /// |
||
608 | /// </summary> |
||
609 | // ----------------------------------------------------------------- |
||
610 | private void DoJsonWriteNotecard(UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string name) |
||
611 | { |
||
612 | string data; |
||
613 | if (! m_store.GetValue(storeID,path,true, out data)) |
||
614 | { |
||
615 | m_comms.DispatchReply(scriptID,0,UUID.Zero.ToString(),reqID.ToString()); |
||
616 | return; |
||
617 | } |
||
618 | |||
619 | SceneObjectPart host = m_scene.GetSceneObjectPart(hostID); |
||
620 | |||
621 | // Create new asset |
||
622 | UUID assetID = UUID.Random(); |
||
623 | AssetBase asset = new AssetBase(assetID, name, (sbyte)AssetType.Notecard, host.OwnerID.ToString()); |
||
624 | asset.Description = "Json store"; |
||
625 | |||
626 | int textLength = data.Length; |
||
627 | data = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " |
||
628 | + textLength.ToString() + "\n" + data + "}\n"; |
||
629 | |||
630 | asset.Data = Util.UTF8.GetBytes(data); |
||
631 | m_scene.AssetService.Store(asset); |
||
632 | |||
633 | // Create Task Entry |
||
634 | TaskInventoryItem taskItem = new TaskInventoryItem(); |
||
635 | |||
636 | taskItem.ResetIDs(host.UUID); |
||
637 | taskItem.ParentID = host.UUID; |
||
638 | taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch(); |
||
639 | taskItem.Name = asset.Name; |
||
640 | taskItem.Description = asset.Description; |
||
641 | taskItem.Type = (int)AssetType.Notecard; |
||
642 | taskItem.InvType = (int)InventoryType.Notecard; |
||
643 | taskItem.OwnerID = host.OwnerID; |
||
644 | taskItem.CreatorID = host.OwnerID; |
||
645 | taskItem.BasePermissions = (uint)PermissionMask.All; |
||
646 | taskItem.CurrentPermissions = (uint)PermissionMask.All; |
||
647 | taskItem.EveryonePermissions = 0; |
||
648 | taskItem.NextPermissions = (uint)PermissionMask.All; |
||
649 | taskItem.GroupID = host.GroupID; |
||
650 | taskItem.GroupPermissions = 0; |
||
651 | taskItem.Flags = 0; |
||
652 | taskItem.PermsGranter = UUID.Zero; |
||
653 | taskItem.PermsMask = 0; |
||
654 | taskItem.AssetID = asset.FullID; |
||
655 | |||
656 | host.Inventory.AddInventoryItem(taskItem, false); |
||
657 | |||
658 | m_comms.DispatchReply(scriptID,1,assetID.ToString(),reqID.ToString()); |
||
659 | } |
||
660 | |||
661 | // ----------------------------------------------------------------- |
||
662 | /// <summary> |
||
663 | /// Convert a list of values that are path components to a single string path |
||
664 | /// </summary> |
||
665 | // ----------------------------------------------------------------- |
||
666 | protected static Regex m_ArrayPattern = new Regex("^([0-9]+|\\+)$"); |
||
667 | private string ConvertList2Path(object[] pathlist) |
||
668 | { |
||
669 | string path = ""; |
||
670 | for (int i = 0; i < pathlist.Length; i++) |
||
671 | { |
||
672 | string token = ""; |
||
673 | |||
674 | if (pathlist[i] is string) |
||
675 | { |
||
676 | token = pathlist[i].ToString(); |
||
677 | |||
678 | // Check to see if this is a bare number which would not be a valid |
||
679 | // identifier otherwise |
||
680 | if (m_ArrayPattern.IsMatch(token)) |
||
681 | token = '[' + token + ']'; |
||
682 | } |
||
683 | else if (pathlist[i] is int) |
||
684 | { |
||
685 | token = "[" + pathlist[i].ToString() + "]"; |
||
686 | } |
||
687 | else |
||
688 | { |
||
689 | token = "." + pathlist[i].ToString() + "."; |
||
690 | } |
||
691 | |||
692 | path += token + "."; |
||
693 | } |
||
694 | |||
695 | return path; |
||
696 | } |
||
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 | } |
||
796 | } |
||
797 | } |