aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs19
-rw-r--r--OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/ApiManager.cs41
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs1269
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs12
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs12
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs413
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs25
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs7
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs42
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs35
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs54
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs31
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs11
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs8
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs142
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs9
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs24
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs231
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs20
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs368
24 files changed, 1683 insertions, 1116 deletions
diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs
index bb5bacc..2027ca6 100644
--- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs
+++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs
@@ -27,17 +27,22 @@
27 27
28using System; 28using System;
29using OpenMetaverse; 29using OpenMetaverse;
30using OpenSim.Framework;
30using OpenSim.Region.Framework.Scenes; 31using OpenSim.Region.Framework.Scenes;
31 32
32
33namespace OpenSim.Region.ScriptEngine.Interfaces 33namespace OpenSim.Region.ScriptEngine.Interfaces
34{ 34{
35 public interface IScriptApi 35 public interface IScriptApi
36 { 36 {
37 // 37 /// <summary>
38 // Each API has an identifier, which is used to load the 38 /// Initialize the API
39 // proper runtime assembly at load time. 39 /// </summary>
40 // 40 /// <remarks>
41 void Initialize(IScriptEngine engine, SceneObjectPart part, uint localID, UUID item); 41 /// Each API has an identifier, which is used to load the
42 /// proper runtime assembly at load time.
43 /// <param name='engine'>/param>
44 /// <param name='part'></param>
45 /// <param name='item'></param>
46 void Initialize(IScriptEngine engine, SceneObjectPart part, TaskInventoryItem item);
42 } 47 }
43} 48} \ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
index b04f6b6..ec13b6c 100644
--- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
@@ -64,6 +64,16 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
64 bool Running { get; set; } 64 bool Running { get; set; }
65 65
66 /// <summary> 66 /// <summary>
67 /// Gets or sets a value indicating whether this
68 /// <see cref="OpenSim.Region.ScriptEngine.Interfaces.IScriptInstance"/> is run.
69 /// For viewer script editor control
70 /// </summary>
71 /// <value>
72 /// <c>true</c> if run; otherwise, <c>false</c>.
73 /// </value>
74 bool Run { get; set; }
75
76 /// <summary>
67 /// Is the script suspended? 77 /// Is the script suspended?
68 /// </summary> 78 /// </summary>
69 bool Suspended { get; set; } 79 bool Suspended { get; set; }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/ApiManager.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/ApiManager.cs
index 47ed6ba..684138f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/ApiManager.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/ApiManager.cs
@@ -29,42 +29,43 @@ using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Reflection; 31using System.Reflection;
32using log4net;
32using OpenSim.Region.ScriptEngine.Interfaces; 33using OpenSim.Region.ScriptEngine.Interfaces;
33 34
34namespace OpenSim.Region.ScriptEngine.Shared.Api 35namespace OpenSim.Region.ScriptEngine.Shared.Api
35{ 36{
36 public class ApiManager 37 public class ApiManager
37 { 38 {
39// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
40
38 private Dictionary<string,Type> m_Apis = new Dictionary<string,Type>(); 41 private Dictionary<string,Type> m_Apis = new Dictionary<string,Type>();
39 42
40 public string[] GetApis() 43 public string[] GetApis()
41 { 44 {
42 if (m_Apis.Count > 0) 45 if (m_Apis.Count <= 0)
43 { 46 {
44 List<string> l = new List<string>(m_Apis.Keys); 47 Assembly a = Assembly.GetExecutingAssembly();
45 return l.ToArray();
46 }
47 48
48 Assembly a = Assembly.GetExecutingAssembly(); 49 Type[] types = a.GetExportedTypes();
49 50
50 Type[] types = a.GetExportedTypes(); 51 foreach (Type t in types)
51
52 foreach (Type t in types)
53 {
54 string name = t.ToString();
55 int idx = name.LastIndexOf('.');
56 if (idx != -1)
57 name = name.Substring(idx+1);
58
59 if (name.EndsWith("_Api"))
60 { 52 {
61 name = name.Substring(0, name.Length - 4); 53 string name = t.ToString();
62 m_Apis[name] = t; 54 int idx = name.LastIndexOf('.');
55 if (idx != -1)
56 name = name.Substring(idx+1);
57
58 if (name.EndsWith("_Api"))
59 {
60 name = name.Substring(0, name.Length - 4);
61 m_Apis[name] = t;
62 }
63 } 63 }
64 } 64 }
65 65
66 List<string> ret = new List<string>(m_Apis.Keys); 66// m_log.DebugFormat("[API MANAGER]: Found {0} apis", m_Apis.Keys.Count);
67 return ret.ToArray(); 67
68 return new List<string>(m_Apis.Keys).ToArray();
68 } 69 }
69 70
70 public IScriptApi CreateApi(string api) 71 public IScriptApi CreateApi(string api)
@@ -76,4 +77,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
76 return ret; 77 return ret;
77 } 78 }
78 } 79 }
79} 80} \ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
index 489c1c6..b5fa6de 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
@@ -59,16 +59,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
59 { 59 {
60 internal IScriptEngine m_ScriptEngine; 60 internal IScriptEngine m_ScriptEngine;
61 internal SceneObjectPart m_host; 61 internal SceneObjectPart m_host;
62 internal uint m_localID; 62 internal TaskInventoryItem m_item;
63 internal UUID m_itemID;
64 internal bool m_CMFunctionsEnabled = false; 63 internal bool m_CMFunctionsEnabled = false;
65 64
66 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) 65 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item)
67 { 66 {
68 m_ScriptEngine = ScriptEngine; 67 m_ScriptEngine = ScriptEngine;
69 m_host = host; 68 m_host = host;
70 m_localID = localID; 69 m_item = item;
71 m_itemID = itemID;
72 70
73 if (m_ScriptEngine.Config.GetBoolean("AllowCareminsterFunctions", false)) 71 if (m_ScriptEngine.Config.GetBoolean("AllowCareminsterFunctions", false))
74 m_CMFunctionsEnabled = true; 72 m_CMFunctionsEnabled = true;
@@ -95,7 +93,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
95 public string cmDetectedCountry(int number) 93 public string cmDetectedCountry(int number)
96 { 94 {
97 m_host.AddScriptLPS(1); 95 m_host.AddScriptLPS(1);
98 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 96 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
99 if (detectedParams == null) 97 if (detectedParams == null)
100 return String.Empty; 98 return String.Empty;
101 return detectedParams.Country; 99 return detectedParams.Country;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index ca62bac..e9db5d5 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -88,8 +88,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
88 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 88 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
89 protected IScriptEngine m_ScriptEngine; 89 protected IScriptEngine m_ScriptEngine;
90 protected SceneObjectPart m_host; 90 protected SceneObjectPart m_host;
91 protected uint m_localID; 91
92 protected UUID m_itemID; 92 /// <summary>
93 /// The item that hosts this script
94 /// </summary>
95 protected TaskInventoryItem m_item;
96
93 protected bool throwErrorOnNotImplemented = true; 97 protected bool throwErrorOnNotImplemented = true;
94 protected AsyncCommandManager AsyncCommands = null; 98 protected AsyncCommandManager AsyncCommands = null;
95 protected float m_ScriptDelayFactor = 1.0f; 99 protected float m_ScriptDelayFactor = 1.0f;
@@ -107,6 +111,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
107 protected IUrlModule m_UrlModule = null; 111 protected IUrlModule m_UrlModule = null;
108 protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = 112 protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache =
109 new Dictionary<UUID, UserInfoCacheEntry>(); 113 new Dictionary<UUID, UserInfoCacheEntry>();
114 protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp.
110 115
111// protected Timer m_ShoutSayTimer; 116// protected Timer m_ShoutSayTimer;
112 protected int m_SayShoutCount = 0; 117 protected int m_SayShoutCount = 0;
@@ -134,7 +139,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
134 {"TURNRIGHT", "Turning Right"} 139 {"TURNRIGHT", "Turning Right"}
135 }; 140 };
136 141
137 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) 142 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item)
138 { 143 {
139/* 144/*
140 m_ShoutSayTimer = new Timer(1000); 145 m_ShoutSayTimer = new Timer(1000);
@@ -146,10 +151,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
146 151
147 m_ScriptEngine = ScriptEngine; 152 m_ScriptEngine = ScriptEngine;
148 m_host = host; 153 m_host = host;
149 m_localID = localID; 154 m_item = item;
150 m_itemID = itemID;
151 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false); 155 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
152 156
157 LoadLimits(); // read script limits from config.
158
159 m_TransferModule =
160 m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
161 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
162
163 AsyncCommands = new AsyncCommandManager(ScriptEngine);
164 }
165
166 /* load configuration items that affect script, object and run-time behavior. */
167 private void LoadLimits()
168 {
153 m_ScriptDelayFactor = 169 m_ScriptDelayFactor =
154 m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f); 170 m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
155 m_ScriptDistanceFactor = 171 m_ScriptDistanceFactor =
@@ -162,12 +178,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
162 m_ScriptEngine.Config.GetInt("NotecardLineReadCharsMax", 255); 178 m_ScriptEngine.Config.GetInt("NotecardLineReadCharsMax", 255);
163 if (m_notecardLineReadCharsMax > 65535) 179 if (m_notecardLineReadCharsMax > 65535)
164 m_notecardLineReadCharsMax = 65535; 180 m_notecardLineReadCharsMax = 65535;
165 181 // load limits for particular subsystems.
166 m_TransferModule = 182 IConfig SMTPConfig;
167 m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>(); 183 if ((SMTPConfig = m_ScriptEngine.ConfigSource.Configs["SMTP"]) != null) {
168 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); 184 // there's an smtp config, so load in the snooze time.
169 185 EMAIL_PAUSE_TIME = SMTPConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME);
170 AsyncCommands = new AsyncCommandManager(ScriptEngine); 186 }
171 } 187 }
172 188
173 public override Object InitializeLifetimeService() 189 public override Object InitializeLifetimeService()
@@ -199,7 +215,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
199 [DebuggerNonUserCode] 215 [DebuggerNonUserCode]
200 public void state(string newState) 216 public void state(string newState)
201 { 217 {
202 m_ScriptEngine.SetState(m_itemID, newState); 218 m_ScriptEngine.SetState(m_item.ItemID, newState);
203 } 219 }
204 220
205 /// <summary> 221 /// <summary>
@@ -210,7 +226,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
210 public void llResetScript() 226 public void llResetScript()
211 { 227 {
212 m_host.AddScriptLPS(1); 228 m_host.AddScriptLPS(1);
213 m_ScriptEngine.ApiResetScript(m_itemID); 229 m_ScriptEngine.ApiResetScript(m_item.ItemID);
214 } 230 }
215 231
216 public void llResetOtherScript(string name) 232 public void llResetOtherScript(string name)
@@ -219,7 +235,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
219 235
220 m_host.AddScriptLPS(1); 236 m_host.AddScriptLPS(1);
221 237
222 if ((item = ScriptByName(name)) != UUID.Zero) 238 if ((item = GetScriptByName(name)) != UUID.Zero)
223 m_ScriptEngine.ResetScript(item); 239 m_ScriptEngine.ResetScript(item);
224 else 240 else
225 ShoutError("llResetOtherScript: script "+name+" not found"); 241 ShoutError("llResetOtherScript: script "+name+" not found");
@@ -231,7 +247,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
231 247
232 m_host.AddScriptLPS(1); 248 m_host.AddScriptLPS(1);
233 249
234 if ((item = ScriptByName(name)) != UUID.Zero) 250 if ((item = GetScriptByName(name)) != UUID.Zero)
235 { 251 {
236 return m_ScriptEngine.GetScriptState(item) ?1:0; 252 return m_ScriptEngine.GetScriptState(item) ?1:0;
237 } 253 }
@@ -253,7 +269,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
253 // These functions are supposed to be robust, 269 // These functions are supposed to be robust,
254 // so get the state one step at a time. 270 // so get the state one step at a time.
255 271
256 if ((item = ScriptByName(name)) != UUID.Zero) 272 if ((item = GetScriptByName(name)) != UUID.Zero)
257 { 273 {
258 m_ScriptEngine.SetScriptState(item, run == 0 ? false : true); 274 m_ScriptEngine.SetScriptState(item, run == 0 ? false : true);
259 } 275 }
@@ -362,77 +378,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
362 } 378 }
363 } 379 }
364 380
365 protected UUID InventorySelf()
366 {
367 UUID invItemID = new UUID();
368 bool unlock = false;
369 if (!m_host.TaskInventory.IsReadLockedByMe())
370 {
371 m_host.TaskInventory.LockItemsForRead(true);
372 unlock = true;
373 }
374 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
375 {
376 if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID)
377 {
378 invItemID = inv.Key;
379 break;
380 }
381 }
382 if (unlock)
383 {
384 m_host.TaskInventory.LockItemsForRead(false);
385 }
386 return invItemID;
387 }
388
389 protected UUID InventoryKey(string name, int type) 381 protected UUID InventoryKey(string name, int type)
390 { 382 {
391 m_host.AddScriptLPS(1); 383 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
392 m_host.TaskInventory.LockItemsForRead(true);
393
394 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
395 {
396 if (inv.Value.Name == name)
397 {
398 m_host.TaskInventory.LockItemsForRead(false);
399
400 if (inv.Value.Type != type)
401 {
402 return UUID.Zero;
403 }
404
405 return inv.Value.AssetID;
406 }
407 }
408
409 m_host.TaskInventory.LockItemsForRead(false);
410 return UUID.Zero;
411 }
412
413 protected UUID InventoryKey(string name)
414 {
415 m_host.AddScriptLPS(1);
416
417
418 m_host.TaskInventory.LockItemsForRead(true);
419
420 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
421 {
422 if (inv.Value.Name == name)
423 {
424 m_host.TaskInventory.LockItemsForRead(false);
425 return inv.Value.AssetID;
426 }
427 }
428 384
429 m_host.TaskInventory.LockItemsForRead(false); 385 if (item != null && item.Type == type)
430 386 return item.AssetID;
431 387 else
432 return UUID.Zero; 388 return UUID.Zero;
433 } 389 }
434 390
435
436 /// <summary> 391 /// <summary>
437 /// accepts a valid UUID, -or- a name of an inventory item. 392 /// accepts a valid UUID, -or- a name of an inventory item.
438 /// Returns a valid UUID or UUID.Zero if key invalid and item not found 393 /// Returns a valid UUID or UUID.Zero if key invalid and item not found
@@ -442,19 +397,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
442 /// <returns></returns> 397 /// <returns></returns>
443 protected UUID KeyOrName(string k) 398 protected UUID KeyOrName(string k)
444 { 399 {
445 UUID key = UUID.Zero; 400 UUID key;
446 401
447 // if we can parse the string as a key, use it. 402 // if we can parse the string as a key, use it.
448 if (UUID.TryParse(k, out key))
449 {
450 return key;
451 }
452 // else try to locate the name in inventory of object. found returns key, 403 // else try to locate the name in inventory of object. found returns key,
453 // not found returns UUID.Zero which will translate to the default particle texture 404 // not found returns UUID.Zero
454 else 405 if (!UUID.TryParse(k, out key))
455 { 406 {
456 return InventoryKey(k); 407 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(k);
408
409 if (item != null)
410 key = item.AssetID;
411 else
412 key = UUID.Zero;
457 } 413 }
414
415 return key;
458 } 416 }
459 417
460 // convert a LSL_Rotation to a Quaternion 418 // convert a LSL_Rotation to a Quaternion
@@ -1010,7 +968,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1010 UUID.TryParse(ID, out keyID); 968 UUID.TryParse(ID, out keyID);
1011 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 969 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
1012 if (wComm != null) 970 if (wComm != null)
1013 return wComm.Listen(m_localID, m_itemID, m_host.UUID, channelID, name, keyID, msg); 971 return wComm.Listen(m_host.LocalId, m_item.ItemID, m_host.UUID, channelID, name, keyID, msg);
1014 else 972 else
1015 return -1; 973 return -1;
1016 } 974 }
@@ -1020,7 +978,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1020 m_host.AddScriptLPS(1); 978 m_host.AddScriptLPS(1);
1021 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 979 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
1022 if (wComm != null) 980 if (wComm != null)
1023 wComm.ListenControl(m_itemID, number, active); 981 wComm.ListenControl(m_item.ItemID, number, active);
1024 } 982 }
1025 983
1026 public void llListenRemove(int number) 984 public void llListenRemove(int number)
@@ -1028,7 +986,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1028 m_host.AddScriptLPS(1); 986 m_host.AddScriptLPS(1);
1029 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 987 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
1030 if (wComm != null) 988 if (wComm != null)
1031 wComm.ListenRemove(m_itemID, number); 989 wComm.ListenRemove(m_item.ItemID, number);
1032 } 990 }
1033 991
1034 public void llSensor(string name, string id, int type, double range, double arc) 992 public void llSensor(string name, string id, int type, double range, double arc)
@@ -1037,7 +995,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1037 UUID keyID = UUID.Zero; 995 UUID keyID = UUID.Zero;
1038 UUID.TryParse(id, out keyID); 996 UUID.TryParse(id, out keyID);
1039 997
1040 AsyncCommands.SensorRepeatPlugin.SenseOnce(m_localID, m_itemID, name, keyID, type, range, arc, m_host); 998 AsyncCommands.SensorRepeatPlugin.SenseOnce(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, m_host);
1041 } 999 }
1042 1000
1043 public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate) 1001 public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
@@ -1046,13 +1004,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1046 UUID keyID = UUID.Zero; 1004 UUID keyID = UUID.Zero;
1047 UUID.TryParse(id, out keyID); 1005 UUID.TryParse(id, out keyID);
1048 1006
1049 AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_localID, m_itemID, name, keyID, type, range, arc, rate, m_host); 1007 AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, rate, m_host);
1050 } 1008 }
1051 1009
1052 public void llSensorRemove() 1010 public void llSensorRemove()
1053 { 1011 {
1054 m_host.AddScriptLPS(1); 1012 m_host.AddScriptLPS(1);
1055 AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_localID, m_itemID); 1013 AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_host.LocalId, m_item.ItemID);
1056 } 1014 }
1057 1015
1058 public string resolveName(UUID objecUUID) 1016 public string resolveName(UUID objecUUID)
@@ -1093,7 +1051,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1093 public LSL_String llDetectedName(int number) 1051 public LSL_String llDetectedName(int number)
1094 { 1052 {
1095 m_host.AddScriptLPS(1); 1053 m_host.AddScriptLPS(1);
1096 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1054 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1097 if (detectedParams == null) 1055 if (detectedParams == null)
1098 return String.Empty; 1056 return String.Empty;
1099 return detectedParams.Name; 1057 return detectedParams.Name;
@@ -1102,7 +1060,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1102 public LSL_String llDetectedKey(int number) 1060 public LSL_String llDetectedKey(int number)
1103 { 1061 {
1104 m_host.AddScriptLPS(1); 1062 m_host.AddScriptLPS(1);
1105 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1063 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1106 if (detectedParams == null) 1064 if (detectedParams == null)
1107 return String.Empty; 1065 return String.Empty;
1108 return detectedParams.Key.ToString(); 1066 return detectedParams.Key.ToString();
@@ -1111,7 +1069,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1111 public LSL_String llDetectedOwner(int number) 1069 public LSL_String llDetectedOwner(int number)
1112 { 1070 {
1113 m_host.AddScriptLPS(1); 1071 m_host.AddScriptLPS(1);
1114 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1072 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1115 if (detectedParams == null) 1073 if (detectedParams == null)
1116 return String.Empty; 1074 return String.Empty;
1117 return detectedParams.Owner.ToString(); 1075 return detectedParams.Owner.ToString();
@@ -1120,7 +1078,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1120 public LSL_Integer llDetectedType(int number) 1078 public LSL_Integer llDetectedType(int number)
1121 { 1079 {
1122 m_host.AddScriptLPS(1); 1080 m_host.AddScriptLPS(1);
1123 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1081 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1124 if (detectedParams == null) 1082 if (detectedParams == null)
1125 return 0; 1083 return 0;
1126 return new LSL_Integer(detectedParams.Type); 1084 return new LSL_Integer(detectedParams.Type);
@@ -1129,7 +1087,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1129 public LSL_Vector llDetectedPos(int number) 1087 public LSL_Vector llDetectedPos(int number)
1130 { 1088 {
1131 m_host.AddScriptLPS(1); 1089 m_host.AddScriptLPS(1);
1132 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1090 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1133 if (detectedParams == null) 1091 if (detectedParams == null)
1134 return new LSL_Vector(); 1092 return new LSL_Vector();
1135 return detectedParams.Position; 1093 return detectedParams.Position;
@@ -1138,7 +1096,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1138 public LSL_Vector llDetectedVel(int number) 1096 public LSL_Vector llDetectedVel(int number)
1139 { 1097 {
1140 m_host.AddScriptLPS(1); 1098 m_host.AddScriptLPS(1);
1141 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1099 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1142 if (detectedParams == null) 1100 if (detectedParams == null)
1143 return new LSL_Vector(); 1101 return new LSL_Vector();
1144 return detectedParams.Velocity; 1102 return detectedParams.Velocity;
@@ -1147,7 +1105,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1147 public LSL_Vector llDetectedGrab(int number) 1105 public LSL_Vector llDetectedGrab(int number)
1148 { 1106 {
1149 m_host.AddScriptLPS(1); 1107 m_host.AddScriptLPS(1);
1150 DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number); 1108 DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1151 if (parms == null) 1109 if (parms == null)
1152 return new LSL_Vector(0, 0, 0); 1110 return new LSL_Vector(0, 0, 0);
1153 1111
@@ -1157,7 +1115,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1157 public LSL_Rotation llDetectedRot(int number) 1115 public LSL_Rotation llDetectedRot(int number)
1158 { 1116 {
1159 m_host.AddScriptLPS(1); 1117 m_host.AddScriptLPS(1);
1160 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1118 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1161 if (detectedParams == null) 1119 if (detectedParams == null)
1162 return new LSL_Rotation(); 1120 return new LSL_Rotation();
1163 return detectedParams.Rotation; 1121 return detectedParams.Rotation;
@@ -1166,7 +1124,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1166 public LSL_Integer llDetectedGroup(int number) 1124 public LSL_Integer llDetectedGroup(int number)
1167 { 1125 {
1168 m_host.AddScriptLPS(1); 1126 m_host.AddScriptLPS(1);
1169 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1127 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1170 if (detectedParams == null) 1128 if (detectedParams == null)
1171 return new LSL_Integer(0); 1129 return new LSL_Integer(0);
1172 if (m_host.GroupID == detectedParams.Group) 1130 if (m_host.GroupID == detectedParams.Group)
@@ -1177,7 +1135,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1177 public LSL_Integer llDetectedLinkNumber(int number) 1135 public LSL_Integer llDetectedLinkNumber(int number)
1178 { 1136 {
1179 m_host.AddScriptLPS(1); 1137 m_host.AddScriptLPS(1);
1180 DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number); 1138 DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1181 if (parms == null) 1139 if (parms == null)
1182 return new LSL_Integer(0); 1140 return new LSL_Integer(0);
1183 1141
@@ -1190,7 +1148,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1190 public LSL_Vector llDetectedTouchBinormal(int index) 1148 public LSL_Vector llDetectedTouchBinormal(int index)
1191 { 1149 {
1192 m_host.AddScriptLPS(1); 1150 m_host.AddScriptLPS(1);
1193 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1151 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1194 if (detectedParams == null) 1152 if (detectedParams == null)
1195 return new LSL_Vector(); 1153 return new LSL_Vector();
1196 return detectedParams.TouchBinormal; 1154 return detectedParams.TouchBinormal;
@@ -1202,7 +1160,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1202 public LSL_Integer llDetectedTouchFace(int index) 1160 public LSL_Integer llDetectedTouchFace(int index)
1203 { 1161 {
1204 m_host.AddScriptLPS(1); 1162 m_host.AddScriptLPS(1);
1205 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1163 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1206 if (detectedParams == null) 1164 if (detectedParams == null)
1207 return new LSL_Integer(-1); 1165 return new LSL_Integer(-1);
1208 return new LSL_Integer(detectedParams.TouchFace); 1166 return new LSL_Integer(detectedParams.TouchFace);
@@ -1214,7 +1172,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1214 public LSL_Vector llDetectedTouchNormal(int index) 1172 public LSL_Vector llDetectedTouchNormal(int index)
1215 { 1173 {
1216 m_host.AddScriptLPS(1); 1174 m_host.AddScriptLPS(1);
1217 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1175 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1218 if (detectedParams == null) 1176 if (detectedParams == null)
1219 return new LSL_Vector(); 1177 return new LSL_Vector();
1220 return detectedParams.TouchNormal; 1178 return detectedParams.TouchNormal;
@@ -1226,7 +1184,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1226 public LSL_Vector llDetectedTouchPos(int index) 1184 public LSL_Vector llDetectedTouchPos(int index)
1227 { 1185 {
1228 m_host.AddScriptLPS(1); 1186 m_host.AddScriptLPS(1);
1229 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1187 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1230 if (detectedParams == null) 1188 if (detectedParams == null)
1231 return new LSL_Vector(); 1189 return new LSL_Vector();
1232 return detectedParams.TouchPos; 1190 return detectedParams.TouchPos;
@@ -1238,7 +1196,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1238 public LSL_Vector llDetectedTouchST(int index) 1196 public LSL_Vector llDetectedTouchST(int index)
1239 { 1197 {
1240 m_host.AddScriptLPS(1); 1198 m_host.AddScriptLPS(1);
1241 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1199 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1242 if (detectedParams == null) 1200 if (detectedParams == null)
1243 return new LSL_Vector(-1.0, -1.0, 0.0); 1201 return new LSL_Vector(-1.0, -1.0, 0.0);
1244 return detectedParams.TouchST; 1202 return detectedParams.TouchST;
@@ -1250,7 +1208,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1250 public LSL_Vector llDetectedTouchUV(int index) 1208 public LSL_Vector llDetectedTouchUV(int index)
1251 { 1209 {
1252 m_host.AddScriptLPS(1); 1210 m_host.AddScriptLPS(1);
1253 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1211 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1254 if (detectedParams == null) 1212 if (detectedParams == null)
1255 return new LSL_Vector(-1.0, -1.0, 0.0); 1213 return new LSL_Vector(-1.0, -1.0, 0.0);
1256 return detectedParams.TouchUV; 1214 return detectedParams.TouchUV;
@@ -1962,6 +1920,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1962 rgb.x = texcolor.R; 1920 rgb.x = texcolor.R;
1963 rgb.y = texcolor.G; 1921 rgb.y = texcolor.G;
1964 rgb.z = texcolor.B; 1922 rgb.z = texcolor.B;
1923
1965 return rgb; 1924 return rgb;
1966 } 1925 }
1967 else 1926 else
@@ -3039,20 +2998,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3039 2998
3040 public LSL_Integer llGiveMoney(string destination, int amount) 2999 public LSL_Integer llGiveMoney(string destination, int amount)
3041 { 3000 {
3042 UUID invItemID=InventorySelf();
3043 if (invItemID == UUID.Zero)
3044 return 0;
3045
3046 m_host.AddScriptLPS(1); 3001 m_host.AddScriptLPS(1);
3047 3002
3048 m_host.TaskInventory.LockItemsForRead(true); 3003 if (m_item.PermsGranter == UUID.Zero)
3049 TaskInventoryItem item = m_host.TaskInventory[invItemID];
3050 m_host.TaskInventory.LockItemsForRead(false);
3051
3052 if (item.PermsGranter == UUID.Zero)
3053 return 0; 3004 return 0;
3054 3005
3055 if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0) 3006 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
3056 { 3007 {
3057 LSLError("No permissions to give money"); 3008 LSLError("No permissions to give money");
3058 return 0; 3009 return 0;
@@ -3115,74 +3066,72 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3115 { 3066 {
3116 m_host.AddScriptLPS(1); 3067 m_host.AddScriptLPS(1);
3117 3068
3118 Util.FireAndForget(delegate (object x) 3069 Util.FireAndForget(x =>
3119 { 3070 {
3120 if (Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s)) 3071 if (Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s))
3121 return; 3072 return;
3073
3122 float dist = (float)llVecDist(llGetPos(), pos); 3074 float dist = (float)llVecDist(llGetPos(), pos);
3123 3075
3124 if (dist > m_ScriptDistanceFactor * 10.0f) 3076 if (dist > m_ScriptDistanceFactor * 10.0f)
3125 return; 3077 return;
3126 3078
3127 //Clone is thread-safe 3079 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
3128 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
3129 3080
3130 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory) 3081 if (item == null)
3131 { 3082 {
3132 if (inv.Value.Name == inventory) 3083 llSay(0, "Could not find object " + inventory);
3133 { 3084 return;
3134 // make sure we're an object. 3085 }
3135 if (inv.Value.InvType != (int)InventoryType.Object)
3136 {
3137 llSay(0, "Unable to create requested object. Object is missing from database.");
3138 return;
3139 }
3140 3086
3141 Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z); 3087 if (item.InvType != (int)InventoryType.Object)
3142 Vector3 llvel = new Vector3((float)vel.x, (float)vel.y, (float)vel.z); 3088 {
3089 llSay(0, "Unable to create requested object. Object is missing from database.");
3090 return;
3091 }
3143 3092
3144 // need the magnitude later 3093 Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
3145 // float velmag = (float)Util.GetMagnitude(llvel); 3094 Vector3 llvel = new Vector3((float)vel.x, (float)vel.y, (float)vel.z);
3146 3095
3147 SceneObjectGroup new_group = World.RezObject(m_host, inv.Value, llpos, Rot2Quaternion(rot), llvel, param); 3096 // need the magnitude later
3097 // float velmag = (float)Util.GetMagnitude(llvel);
3148 3098
3149 // If either of these are null, then there was an unknown error. 3099 SceneObjectGroup new_group = World.RezObject(m_host, item, llpos, Rot2Quaternion(rot), llvel, param);
3150 if (new_group == null)
3151 continue;
3152 3100
3153 // objects rezzed with this method are die_at_edge by default. 3101 // If either of these are null, then there was an unknown error.
3154 new_group.RootPart.SetDieAtEdge(true); 3102 if (new_group == null)
3103 return;
3155 3104
3156 new_group.ResumeScripts(); 3105 // objects rezzed with this method are die_at_edge by default.
3106 new_group.RootPart.SetDieAtEdge(true);
3157 3107
3158 m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams( 3108 new_group.ResumeScripts();
3159 "object_rez", new Object[] {
3160 new LSL_String(
3161 new_group.RootPart.UUID.ToString()) },
3162 new DetectParams[0]));
3163 3109
3164 // do recoil 3110 m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
3165 SceneObjectGroup hostgrp = m_host.ParentGroup; 3111 "object_rez", new Object[] {
3166 if (hostgrp == null) 3112 new LSL_String(
3167 return; 3113 new_group.RootPart.UUID.ToString()) },
3114 new DetectParams[0]));
3168 3115
3169 if (hostgrp.IsAttachment) // don't recoil avatars 3116 // do recoil
3170 return; 3117 SceneObjectGroup hostgrp = m_host.ParentGroup;
3118 if (hostgrp == null)
3119 return;
3171 3120
3172 PhysicsActor pa = new_group.RootPart.PhysActor; 3121 if (hostgrp.IsAttachment) // don't recoil avatars
3122 return;
3173 3123
3174 if (pa != null && pa.IsPhysical && llvel != Vector3.Zero) 3124 PhysicsActor pa = new_group.RootPart.PhysActor;
3175 { 3125
3176 float groupmass = new_group.GetMass(); 3126 if (pa != null && pa.IsPhysical && llvel != Vector3.Zero)
3177 llvel *= -groupmass; 3127 {
3178 llApplyImpulse(new LSL_Vector(llvel.X, llvel.Y,llvel.Z), 0); 3128 float groupmass = new_group.GetMass();
3179 } 3129 llvel *= -groupmass;
3180 // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay) 3130 llApplyImpulse(new LSL_Vector(llvel.X, llvel.Y,llvel.Z), 0);
3181 return;
3182 }
3183 } 3131 }
3132 // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay)
3133 return;
3184 3134
3185 llSay(0, "Could not find object " + inventory);
3186 }); 3135 });
3187 3136
3188 //ScriptSleep((int)((groupmass * velmag) / 10)); 3137 //ScriptSleep((int)((groupmass * velmag) / 10));
@@ -3246,11 +3195,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3246 sec = m_MinTimerInterval; 3195 sec = m_MinTimerInterval;
3247 m_host.AddScriptLPS(1); 3196 m_host.AddScriptLPS(1);
3248 // Setting timer repeat 3197 // Setting timer repeat
3249 AsyncCommands.TimerPlugin.SetTimerEvent(m_localID, m_itemID, sec); 3198 AsyncCommands.TimerPlugin.SetTimerEvent(m_host.LocalId, m_item.ItemID, sec);
3250 } 3199 }
3251 3200
3252 public virtual void llSleep(double sec) 3201 public virtual void llSleep(double sec)
3253 { 3202 {
3203// m_log.Info("llSleep snoozing " + sec + "s.");
3254 m_host.AddScriptLPS(1); 3204 m_host.AddScriptLPS(1);
3255 Thread.Sleep((int)(sec * 1000)); 3205 Thread.Sleep((int)(sec * 1000));
3256 } 3206 }
@@ -3309,29 +3259,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3309 3259
3310 public void llTakeControls(int controls, int accept, int pass_on) 3260 public void llTakeControls(int controls, int accept, int pass_on)
3311 { 3261 {
3312 TaskInventoryItem item; 3262 if (m_item.PermsGranter != UUID.Zero)
3313
3314 m_host.TaskInventory.LockItemsForRead(true);
3315 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3316 {
3317 m_host.TaskInventory.LockItemsForRead(false);
3318 return;
3319 }
3320 else
3321 {
3322 item = m_host.TaskInventory[InventorySelf()];
3323 }
3324 m_host.TaskInventory.LockItemsForRead(false);
3325
3326 if (item.PermsGranter != UUID.Zero)
3327 { 3263 {
3328 ScenePresence presence = World.GetScenePresence(item.PermsGranter); 3264 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3329 3265
3330 if (presence != null) 3266 if (presence != null)
3331 { 3267 {
3332 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 3268 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
3333 { 3269 {
3334 presence.RegisterControlEventsToScript(controls, accept, pass_on, m_localID, m_itemID); 3270 presence.RegisterControlEventsToScript(controls, accept, pass_on, m_host.LocalId, m_item.ItemID);
3335 } 3271 }
3336 } 3272 }
3337 } 3273 }
@@ -3341,38 +3277,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3341 3277
3342 public void llReleaseControls() 3278 public void llReleaseControls()
3343 { 3279 {
3344 TaskInventoryItem item;
3345
3346 m_host.TaskInventory.LockItemsForRead(true);
3347 lock (m_host.TaskInventory)
3348 {
3349
3350 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3351 {
3352 m_host.TaskInventory.LockItemsForRead(false);
3353 return;
3354 }
3355 else
3356 {
3357 item = m_host.TaskInventory[InventorySelf()];
3358 }
3359 }
3360 m_host.TaskInventory.LockItemsForRead(false);
3361
3362 m_host.AddScriptLPS(1); 3280 m_host.AddScriptLPS(1);
3363 3281
3364 if (item.PermsGranter != UUID.Zero) 3282 if (m_item.PermsGranter != UUID.Zero)
3365 { 3283 {
3366 ScenePresence presence = World.GetScenePresence(item.PermsGranter); 3284 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3367 3285
3368 if (presence != null) 3286 if (presence != null)
3369 { 3287 {
3370 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 3288 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
3371 { 3289 {
3372 // Unregister controls from Presence 3290 // Unregister controls from Presence
3373 presence.UnRegisterControlEventsToScript(m_localID, m_itemID); 3291 presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
3374 // Remove Take Control permission. 3292 // Remove Take Control permission.
3375 item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS; 3293 m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
3376 } 3294 }
3377 } 3295 }
3378 } 3296 }
@@ -3385,39 +3303,54 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3385 m_UrlModule.ReleaseURL(url); 3303 m_UrlModule.ReleaseURL(url);
3386 } 3304 }
3387 3305
3388 public void llAttachToAvatar(int attachment) 3306 /// <summary>
3307 /// Attach the object containing this script to the avatar that owns it.
3308 /// </summary>
3309 /// <param name='attachment'>The attachment point (e.g. ATTACH_CHEST)</param>
3310 /// <returns>true if the attach suceeded, false if it did not</returns>
3311 public bool AttachToAvatar(int attachmentPoint)
3389 { 3312 {
3390 m_host.AddScriptLPS(1); 3313 SceneObjectGroup grp = m_host.ParentGroup;
3314 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
3391 3315
3392 TaskInventoryItem item; 3316 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3393
3394 m_host.TaskInventory.LockItemsForRead(true);
3395 3317
3396 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3318 if (attachmentsModule != null)
3397 { 3319 return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true);
3398 m_host.TaskInventory.LockItemsForRead(false);
3399 return;
3400 }
3401 else 3320 else
3321 return false;
3322 }
3323
3324 /// <summary>
3325 /// Detach the object containing this script from the avatar it is attached to.
3326 /// </summary>
3327 /// <remarks>
3328 /// Nothing happens if the object is not attached.
3329 /// </remarks>
3330 public void DetachFromAvatar()
3331 {
3332 Util.FireAndForget(DetachWrapper, m_host);
3333 }
3334
3335 private void DetachWrapper(object o)
3336 {
3337 if (World.AttachmentsModule != null)
3402 { 3338 {
3403 item = m_host.TaskInventory[InventorySelf()]; 3339 SceneObjectPart host = (SceneObjectPart)o;
3340 ScenePresence presence = World.GetScenePresence(host.OwnerID);
3341 World.AttachmentsModule.DetachSingleAttachmentToInv(presence, host.ParentGroup);
3404 } 3342 }
3343 }
3405 3344
3406 m_host.TaskInventory.LockItemsForRead(false); 3345 public void llAttachToAvatar(int attachmentPoint)
3346 {
3347 m_host.AddScriptLPS(1);
3407 3348
3408 if (item.PermsGranter != m_host.OwnerID) 3349 if (m_item.PermsGranter != m_host.OwnerID)
3409 return; 3350 return;
3410 3351
3411 if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0) 3352 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
3412 { 3353 AttachToAvatar(attachmentPoint);
3413 SceneObjectGroup grp = m_host.ParentGroup;
3414
3415 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
3416
3417 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3418 if (attachmentsModule != null)
3419 attachmentsModule.AttachObject(presence, grp, (uint)attachment, false, true);
3420 }
3421 } 3354 }
3422 3355
3423 public void llDetachFromAvatar() 3356 public void llDetachFromAvatar()
@@ -3427,44 +3360,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3427 if (m_host.ParentGroup.AttachmentPoint == 0) 3360 if (m_host.ParentGroup.AttachmentPoint == 0)
3428 return; 3361 return;
3429 3362
3430 TaskInventoryItem item; 3363 if (m_item.PermsGranter != m_host.OwnerID)
3431
3432 m_host.TaskInventory.LockItemsForRead(true);
3433
3434 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3435 {
3436 m_host.TaskInventory.LockItemsForRead(false);
3437 return; 3364 return;
3438 }
3439 else
3440 {
3441 item = m_host.TaskInventory[InventorySelf()];
3442 }
3443 m_host.TaskInventory.LockItemsForRead(false);
3444
3445
3446 if (item.PermsGranter != m_host.OwnerID)
3447 return;
3448
3449 if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
3450 {
3451 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3452 if (attachmentsModule != null)
3453 Util.FireAndForget(DetachWrapper, m_host);
3454 }
3455 }
3456 3365
3457 private void DetachWrapper(object o) 3366 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
3458 { 3367 DetachFromAvatar();
3459 SceneObjectPart host = (SceneObjectPart)o;
3460
3461 SceneObjectGroup grp = host.ParentGroup;
3462 UUID itemID = grp.FromItemID;
3463 ScenePresence presence = World.GetScenePresence(host.OwnerID);
3464
3465 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3466 if (attachmentsModule != null)
3467 attachmentsModule.DetachSingleAttachmentToInv(presence, itemID);
3468 } 3368 }
3469 3369
3470 public void llTakeCamera(string avatar) 3370 public void llTakeCamera(string avatar)
@@ -3585,7 +3485,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3585 } 3485 }
3586 3486
3587 emailModule.SendEmail(m_host.UUID, address, subject, message); 3487 emailModule.SendEmail(m_host.UUID, address, subject, message);
3588 ScriptSleep(15000); 3488 ScriptSleep(EMAIL_PAUSE_TIME * 1000);
3589 } 3489 }
3590 3490
3591 public void llGetNextEmail(string address, string subject) 3491 public void llGetNextEmail(string address, string subject)
@@ -3622,6 +3522,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3622 return m_host.UUID.ToString(); 3522 return m_host.UUID.ToString();
3623 } 3523 }
3624 3524
3525 public LSL_Key llGenerateKey()
3526 {
3527 m_host.AddScriptLPS(1);
3528 return UUID.Random().ToString();
3529 }
3530
3625 public void llSetBuoyancy(double buoyancy) 3531 public void llSetBuoyancy(double buoyancy)
3626 { 3532 {
3627 m_host.AddScriptLPS(1); 3533 m_host.AddScriptLPS(1);
@@ -3668,7 +3574,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3668 m_host.AddScriptLPS(1); 3574 m_host.AddScriptLPS(1);
3669 try 3575 try
3670 { 3576 {
3671 m_ScriptEngine.SetMinEventDelay(m_itemID, delay); 3577 m_ScriptEngine.SetMinEventDelay(m_item.ItemID, delay);
3672 } 3578 }
3673 catch (NotImplementedException) 3579 catch (NotImplementedException)
3674 { 3580 {
@@ -3721,29 +3627,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3721 { 3627 {
3722 m_host.AddScriptLPS(1); 3628 m_host.AddScriptLPS(1);
3723 3629
3724 UUID invItemID = InventorySelf(); 3630 if (m_item.PermsGranter == UUID.Zero)
3725 if (invItemID == UUID.Zero)
3726 return; 3631 return;
3727 3632
3728 TaskInventoryItem item; 3633 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3729
3730 m_host.TaskInventory.LockItemsForRead(true);
3731 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3732 {
3733 m_host.TaskInventory.LockItemsForRead(false);
3734 return;
3735 }
3736 else
3737 { 3634 {
3738 item = m_host.TaskInventory[InventorySelf()]; 3635 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3739 }
3740 m_host.TaskInventory.LockItemsForRead(false);
3741 if (item.PermsGranter == UUID.Zero)
3742 return;
3743
3744 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3745 {
3746 ScenePresence presence = World.GetScenePresence(item.PermsGranter);
3747 3636
3748 if (presence != null) 3637 if (presence != null)
3749 { 3638 {
@@ -3761,41 +3650,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3761 { 3650 {
3762 m_host.AddScriptLPS(1); 3651 m_host.AddScriptLPS(1);
3763 3652
3764 UUID invItemID=InventorySelf(); 3653 if (m_item.PermsGranter == UUID.Zero)
3765 if (invItemID == UUID.Zero)
3766 return;
3767
3768 TaskInventoryItem item;
3769
3770 m_host.TaskInventory.LockItemsForRead(true);
3771 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3772 {
3773 m_host.TaskInventory.LockItemsForRead(false);
3774 return;
3775 }
3776 else
3777 {
3778 item = m_host.TaskInventory[InventorySelf()];
3779 }
3780 m_host.TaskInventory.LockItemsForRead(false);
3781
3782
3783 if (item.PermsGranter == UUID.Zero)
3784 return; 3654 return;
3785 3655
3786 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0) 3656 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3787 { 3657 {
3788 UUID animID = new UUID(); 3658 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3789
3790 if (!UUID.TryParse(anim, out animID))
3791 {
3792 animID=InventoryKey(anim);
3793 }
3794
3795 ScenePresence presence = World.GetScenePresence(item.PermsGranter);
3796 3659
3797 if (presence != null) 3660 if (presence != null)
3798 { 3661 {
3662 UUID animID = KeyOrName(anim);
3663
3799 if (animID == UUID.Zero) 3664 if (animID == UUID.Zero)
3800 presence.Animator.RemoveAnimation(anim); 3665 presence.Animator.RemoveAnimation(anim);
3801 else 3666 else
@@ -3829,44 +3694,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3829 public LSL_Integer llGetStartParameter() 3694 public LSL_Integer llGetStartParameter()
3830 { 3695 {
3831 m_host.AddScriptLPS(1); 3696 m_host.AddScriptLPS(1);
3832 return m_ScriptEngine.GetStartParameter(m_itemID); 3697 return m_ScriptEngine.GetStartParameter(m_item.ItemID);
3833 } 3698 }
3834 3699
3835 public void llRequestPermissions(string agent, int perm) 3700 public void llRequestPermissions(string agent, int perm)
3836 { 3701 {
3837 UUID agentID = new UUID(); 3702 UUID agentID;
3838 3703
3839 if (!UUID.TryParse(agent, out agentID)) 3704 if (!UUID.TryParse(agent, out agentID))
3840 return; 3705 return;
3841 3706
3842 UUID invItemID = InventorySelf();
3843
3844 if (invItemID == UUID.Zero)
3845 return; // Not in a prim? How??
3846
3847 TaskInventoryItem item;
3848
3849
3850 m_host.TaskInventory.LockItemsForRead(true);
3851 if (!m_host.TaskInventory.ContainsKey(invItemID))
3852 {
3853 m_host.TaskInventory.LockItemsForRead(false);
3854 return;
3855 }
3856 else
3857 {
3858 item = m_host.TaskInventory[invItemID];
3859 }
3860 m_host.TaskInventory.LockItemsForRead(false);
3861
3862 if (agentID == UUID.Zero || perm == 0) // Releasing permissions 3707 if (agentID == UUID.Zero || perm == 0) // Releasing permissions
3863 { 3708 {
3864 llReleaseControls(); 3709 llReleaseControls();
3865 3710
3866 item.PermsGranter = UUID.Zero; 3711 m_item.PermsGranter = UUID.Zero;
3867 item.PermsMask = 0; 3712 m_item.PermsMask = 0;
3868 3713
3869 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3714 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3870 "run_time_permissions", new Object[] { 3715 "run_time_permissions", new Object[] {
3871 new LSL_Integer(0) }, 3716 new LSL_Integer(0) },
3872 new DetectParams[0])); 3717 new DetectParams[0]));
@@ -3874,7 +3719,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3874 return; 3719 return;
3875 } 3720 }
3876 3721
3877 if (item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3722 if (m_item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3878 llReleaseControls(); 3723 llReleaseControls();
3879 3724
3880 m_host.AddScriptLPS(1); 3725 m_host.AddScriptLPS(1);
@@ -3891,11 +3736,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3891 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3736 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3892 { 3737 {
3893 m_host.TaskInventory.LockItemsForWrite(true); 3738 m_host.TaskInventory.LockItemsForWrite(true);
3894 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3739 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3895 m_host.TaskInventory[invItemID].PermsMask = perm; 3740 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3896 m_host.TaskInventory.LockItemsForWrite(false); 3741 m_host.TaskInventory.LockItemsForWrite(false);
3897 3742
3898 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3743 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3899 "run_time_permissions", new Object[] { 3744 "run_time_permissions", new Object[] {
3900 new LSL_Integer(perm) }, 3745 new LSL_Integer(perm) },
3901 new DetectParams[0])); 3746 new DetectParams[0]));
@@ -3930,11 +3775,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3930 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3775 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3931 { 3776 {
3932 m_host.TaskInventory.LockItemsForWrite(true); 3777 m_host.TaskInventory.LockItemsForWrite(true);
3933 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3778 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3934 m_host.TaskInventory[invItemID].PermsMask = perm; 3779 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3935 m_host.TaskInventory.LockItemsForWrite(false); 3780 m_host.TaskInventory.LockItemsForWrite(false);
3936 3781
3937 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3782 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3938 "run_time_permissions", new Object[] { 3783 "run_time_permissions", new Object[] {
3939 new LSL_Integer(perm) }, 3784 new LSL_Integer(perm) },
3940 new DetectParams[0])); 3785 new DetectParams[0]));
@@ -3945,9 +3790,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3945 } 3790 }
3946 3791
3947 ScenePresence presence = World.GetScenePresence(agentID); 3792 ScenePresence presence = World.GetScenePresence(agentID);
3948
3949 if (presence != null) 3793 if (presence != null)
3950 { 3794 {
3795 // If permissions are being requested from an NPC and were not implicitly granted above then
3796 // auto grant all reuqested permissions if the script is owned by the NPC or the NPCs owner
3797 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
3798 if (npcModule != null && npcModule.IsNPC(agentID, World))
3799 {
3800 if (agentID == m_host.ParentGroup.OwnerID || npcModule.GetOwner(agentID) == m_host.ParentGroup.OwnerID)
3801 {
3802 lock (m_host.TaskInventory)
3803 {
3804 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3805 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3806 }
3807
3808 m_ScriptEngine.PostScriptEvent(
3809 m_item.ItemID,
3810 new EventParams(
3811 "run_time_permissions", new Object[] { new LSL_Integer(perm) }, new DetectParams[0]));
3812 }
3813
3814 // it is an NPC, exit even if the permissions werent granted above, they are not going to answer
3815 // the question!
3816 return;
3817 }
3818
3951 string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID); 3819 string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
3952 if (ownerName == String.Empty) 3820 if (ownerName == String.Empty)
3953 ownerName = "(hippos)"; 3821 ownerName = "(hippos)";
@@ -3955,8 +3823,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3955 if (!m_waitingForScriptAnswer) 3823 if (!m_waitingForScriptAnswer)
3956 { 3824 {
3957 m_host.TaskInventory.LockItemsForWrite(true); 3825 m_host.TaskInventory.LockItemsForWrite(true);
3958 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3826 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3959 m_host.TaskInventory[invItemID].PermsMask = 0; 3827 m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
3960 m_host.TaskInventory.LockItemsForWrite(false); 3828 m_host.TaskInventory.LockItemsForWrite(false);
3961 3829
3962 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 3830 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
@@ -3964,16 +3832,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3964 } 3832 }
3965 3833
3966 presence.ControllingClient.SendScriptQuestion( 3834 presence.ControllingClient.SendScriptQuestion(
3967 m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, invItemID, perm); 3835 m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_item.ItemID, perm);
3968 3836
3969 return; 3837 return;
3970 } 3838 }
3971 3839
3972 // Requested agent is not in range, refuse perms 3840 // Requested agent is not in range, refuse perms
3973 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3841 m_ScriptEngine.PostScriptEvent(
3974 "run_time_permissions", new Object[] { 3842 m_item.ItemID,
3975 new LSL_Integer(0) }, 3843 new EventParams("run_time_permissions", new Object[] { new LSL_Integer(0) }, new DetectParams[0]));
3976 new DetectParams[0]));
3977 } 3844 }
3978 3845
3979 void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer) 3846 void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
@@ -3981,24 +3848,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3981 if (taskID != m_host.UUID) 3848 if (taskID != m_host.UUID)
3982 return; 3849 return;
3983 3850
3984 UUID invItemID = InventorySelf(); 3851 client.OnScriptAnswer -= handleScriptAnswer;
3985 3852 m_waitingForScriptAnswer = false;
3986 if (invItemID == UUID.Zero)
3987 return;
3988
3989 client.OnScriptAnswer-=handleScriptAnswer;
3990 m_waitingForScriptAnswer=false;
3991 3853
3992 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3854 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3993 llReleaseControls(); 3855 llReleaseControls();
3994 3856
3995
3996 m_host.TaskInventory.LockItemsForWrite(true); 3857 m_host.TaskInventory.LockItemsForWrite(true);
3997 m_host.TaskInventory[invItemID].PermsMask = answer; 3858 m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
3998 m_host.TaskInventory.LockItemsForWrite(false); 3859 m_host.TaskInventory.LockItemsForWrite(false);
3999 3860
4000 3861 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
4001 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
4002 "run_time_permissions", new Object[] { 3862 "run_time_permissions", new Object[] {
4003 new LSL_Integer(answer) }, 3863 new LSL_Integer(answer) },
4004 new DetectParams[0])); 3864 new DetectParams[0]));
@@ -4008,41 +3868,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4008 { 3868 {
4009 m_host.AddScriptLPS(1); 3869 m_host.AddScriptLPS(1);
4010 3870
4011 m_host.TaskInventory.LockItemsForRead(true); 3871 return m_item.PermsGranter.ToString();
4012
4013 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
4014 {
4015 if (item.Type == 10 && item.ItemID == m_itemID)
4016 {
4017 m_host.TaskInventory.LockItemsForRead(false);
4018 return item.PermsGranter.ToString();
4019 }
4020 }
4021 m_host.TaskInventory.LockItemsForRead(false);
4022
4023 return UUID.Zero.ToString();
4024 } 3872 }
4025 3873
4026 public LSL_Integer llGetPermissions() 3874 public LSL_Integer llGetPermissions()
4027 { 3875 {
4028 m_host.AddScriptLPS(1); 3876 m_host.AddScriptLPS(1);
4029 3877
4030 m_host.TaskInventory.LockItemsForRead(true); 3878 int perms = m_item.PermsMask;
4031 3879
4032 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3880 if (m_automaticLinkPermission)
4033 { 3881 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
4034 if (item.Type == 10 && item.ItemID == m_itemID)
4035 {
4036 int perms = item.PermsMask;
4037 if (m_automaticLinkPermission)
4038 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
4039 m_host.TaskInventory.LockItemsForRead(false);
4040 return perms;
4041 }
4042 }
4043 m_host.TaskInventory.LockItemsForRead(false);
4044 3882
4045 return 0; 3883 return perms;
4046 } 3884 }
4047 3885
4048 public LSL_Integer llGetLinkNumber() 3886 public LSL_Integer llGetLinkNumber()
@@ -4080,18 +3918,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4080 public void llCreateLink(string target, int parent) 3918 public void llCreateLink(string target, int parent)
4081 { 3919 {
4082 m_host.AddScriptLPS(1); 3920 m_host.AddScriptLPS(1);
4083 UUID invItemID = InventorySelf(); 3921
4084 UUID targetID; 3922 UUID targetID;
4085 3923
4086 if (!UUID.TryParse(target, out targetID)) 3924 if (!UUID.TryParse(target, out targetID))
4087 return; 3925 return;
4088 3926
4089 TaskInventoryItem item; 3927 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4090 m_host.TaskInventory.LockItemsForRead(true);
4091 item = m_host.TaskInventory[invItemID];
4092 m_host.TaskInventory.LockItemsForRead(false);
4093
4094 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4095 && !m_automaticLinkPermission) 3928 && !m_automaticLinkPermission)
4096 { 3929 {
4097 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3930 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
@@ -4099,7 +3932,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4099 } 3932 }
4100 3933
4101 IClientAPI client = null; 3934 IClientAPI client = null;
4102 ScenePresence sp = World.GetScenePresence(item.PermsGranter); 3935 ScenePresence sp = World.GetScenePresence(m_item.PermsGranter);
4103 if (sp != null) 3936 if (sp != null)
4104 client = sp.ControllingClient; 3937 client = sp.ControllingClient;
4105 3938
@@ -4145,18 +3978,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4145 public void llBreakLink(int linknum) 3978 public void llBreakLink(int linknum)
4146 { 3979 {
4147 m_host.AddScriptLPS(1); 3980 m_host.AddScriptLPS(1);
4148 UUID invItemID = InventorySelf();
4149 3981
4150 m_host.TaskInventory.LockItemsForRead(true); 3982 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4151 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3983 && !m_automaticLinkPermission)
4152 && !m_automaticLinkPermission) 3984 {
4153 { 3985 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
4154 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3986 return;
4155 m_host.TaskInventory.LockItemsForRead(false); 3987 }
4156 return; 3988
4157 }
4158 m_host.TaskInventory.LockItemsForRead(false);
4159
4160 if (linknum < ScriptBaseClass.LINK_THIS) 3989 if (linknum < ScriptBaseClass.LINK_THIS)
4161 return; 3990 return;
4162 3991
@@ -4255,12 +4084,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4255 { 4084 {
4256 m_host.AddScriptLPS(1); 4085 m_host.AddScriptLPS(1);
4257 4086
4258 UUID invItemID = InventorySelf(); 4087 TaskInventoryItem item = m_item;
4259
4260 TaskInventoryItem item;
4261 m_host.TaskInventory.LockItemsForRead(true);
4262 item = m_host.TaskInventory[invItemID];
4263 m_host.TaskInventory.LockItemsForRead(false);
4264 4088
4265 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 4089 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4266 && !m_automaticLinkPermission) 4090 && !m_automaticLinkPermission)
@@ -4457,11 +4281,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4457 public void llGiveInventory(string destination, string inventory) 4281 public void llGiveInventory(string destination, string inventory)
4458 { 4282 {
4459 m_host.AddScriptLPS(1); 4283 m_host.AddScriptLPS(1);
4460 bool found = false; 4284
4461 UUID destId = UUID.Zero; 4285 UUID destId = UUID.Zero;
4462 UUID objId = UUID.Zero;
4463 int assetType = 0;
4464 string objName = String.Empty;
4465 4286
4466 if (!UUID.TryParse(destination, out destId)) 4287 if (!UUID.TryParse(destination, out destId))
4467 { 4288 {
@@ -4469,28 +4290,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4469 return; 4290 return;
4470 } 4291 }
4471 4292
4472 // move the first object found with this inventory name 4293 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
4473 m_host.TaskInventory.LockItemsForRead(true);
4474 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
4475 {
4476 if (inv.Value.Name == inventory)
4477 {
4478 found = true;
4479 objId = inv.Key;
4480 assetType = inv.Value.Type;
4481 objName = inv.Value.Name;
4482 break;
4483 }
4484 }
4485 m_host.TaskInventory.LockItemsForRead(false);
4486 4294
4487 if (!found) 4295 if (item == null)
4488 { 4296 {
4489 llSay(0, String.Format("Could not find object '{0}'", inventory)); 4297 llSay(0, String.Format("Could not find object '{0}'", inventory));
4490 return; 4298 return;
4491// throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory)); 4299// throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory));
4492 } 4300 }
4493 4301
4302 UUID objId = item.ItemID;
4303
4494 // check if destination is an object 4304 // check if destination is an object
4495 if (World.GetSceneObjectPart(destId) != null) 4305 if (World.GetSceneObjectPart(destId) != null)
4496 { 4306 {
@@ -4522,14 +4332,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4522 return; 4332 return;
4523 4333
4524 byte[] bucket = new byte[1]; 4334 byte[] bucket = new byte[1];
4525 bucket[0] = (byte)assetType; 4335 bucket[0] = (byte)item.Type;
4526 //byte[] objBytes = agentItem.ID.GetBytes(); 4336 //byte[] objBytes = agentItem.ID.GetBytes();
4527 //Array.Copy(objBytes, 0, bucket, 1, 16); 4337 //Array.Copy(objBytes, 0, bucket, 1, 16);
4528 4338
4529 GridInstantMessage msg = new GridInstantMessage(World, 4339 GridInstantMessage msg = new GridInstantMessage(World,
4530 m_host.OwnerID, m_host.Name, destId, 4340 m_host.OwnerID, m_host.Name, destId,
4531 (byte)InstantMessageDialog.TaskInventoryOffered, 4341 (byte)InstantMessageDialog.TaskInventoryOffered,
4532 false, objName+". "+m_host.Name+" is located at "+ 4342 false, item.Name+". "+m_host.Name+" is located at "+
4533 World.RegionInfo.RegionName+" "+ 4343 World.RegionInfo.RegionName+" "+
4534 m_host.AbsolutePosition.ToString(), 4344 m_host.AbsolutePosition.ToString(),
4535 agentItem.ID, true, m_host.AbsolutePosition, 4345 agentItem.ID, true, m_host.AbsolutePosition,
@@ -4557,27 +4367,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4557 { 4367 {
4558 m_host.AddScriptLPS(1); 4368 m_host.AddScriptLPS(1);
4559 4369
4560 List<TaskInventoryItem> inv; 4370 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
4561 try 4371
4562 { 4372 if (item == null)
4563 m_host.TaskInventory.LockItemsForRead(true); 4373 return;
4564 inv = new List<TaskInventoryItem>(m_host.TaskInventory.Values); 4374
4565 } 4375 if (item.ItemID == m_item.ItemID)
4566 finally 4376 throw new ScriptDeleteException();
4567 { 4377 else
4568 m_host.TaskInventory.LockItemsForRead(false); 4378 m_host.Inventory.RemoveInventoryItem(item.ItemID);
4569 }
4570 foreach (TaskInventoryItem item in inv)
4571 {
4572 if (item.Name == name)
4573 {
4574 if (item.ItemID == m_itemID)
4575 throw new ScriptDeleteException();
4576 else
4577 m_host.Inventory.RemoveInventoryItem(item.ItemID);
4578 return;
4579 }
4580 }
4581 } 4379 }
4582 4380
4583 public void llSetText(string text, LSL_Vector color, double alpha) 4381 public void llSetText(string text, LSL_Vector color, double alpha)
@@ -4705,8 +4503,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4705 UUID rq = UUID.Random(); 4503 UUID rq = UUID.Random();
4706 4504
4707 UUID tid = AsyncCommands. 4505 UUID tid = AsyncCommands.
4708 DataserverPlugin.RegisterRequest(m_localID, 4506 DataserverPlugin.RegisterRequest(m_host.LocalId,
4709 m_itemID, rq.ToString()); 4507 m_item.ItemID, rq.ToString());
4710 4508
4711 AsyncCommands. 4509 AsyncCommands.
4712 DataserverPlugin.DataserverReply(rq.ToString(), reply); 4510 DataserverPlugin.DataserverReply(rq.ToString(), reply);
@@ -4725,16 +4523,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4725 { 4523 {
4726 m_host.AddScriptLPS(1); 4524 m_host.AddScriptLPS(1);
4727 4525
4728 //Clone is thread safe 4526 foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
4729 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
4730
4731 foreach (TaskInventoryItem item in itemDictionary.Values)
4732 { 4527 {
4733 if (item.Type == 3 && item.Name == name) 4528 if (item.Type == 3 && item.Name == name)
4734 { 4529 {
4735 UUID tid = AsyncCommands. 4530 UUID tid = AsyncCommands.
4736 DataserverPlugin.RegisterRequest(m_localID, 4531 DataserverPlugin.RegisterRequest(m_host.LocalId,
4737 m_itemID, item.AssetID.ToString()); 4532 m_item.ItemID, item.AssetID.ToString());
4738 4533
4739 Vector3 region = new Vector3( 4534 Vector3 region = new Vector3(
4740 World.RegionInfo.RegionLocX * Constants.RegionSize, 4535 World.RegionInfo.RegionLocX * Constants.RegionSize,
@@ -4760,6 +4555,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4760 return tid.ToString(); 4555 return tid.ToString();
4761 } 4556 }
4762 } 4557 }
4558
4763 ScriptSleep(1000); 4559 ScriptSleep(1000);
4764 return String.Empty; 4560 return String.Empty;
4765 } 4561 }
@@ -4952,19 +4748,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4952 UUID soundId = UUID.Zero; 4748 UUID soundId = UUID.Zero;
4953 if (!UUID.TryParse(impact_sound, out soundId)) 4749 if (!UUID.TryParse(impact_sound, out soundId))
4954 { 4750 {
4955 m_host.TaskInventory.LockItemsForRead(true); 4751 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(impact_sound);
4956 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4752
4957 { 4753 if (item != null && item.Type == (int)AssetType.Sound)
4958 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound) 4754 soundId = item.AssetID;
4959 {
4960 soundId = item.AssetID;
4961 break;
4962 }
4963 }
4964 m_host.TaskInventory.LockItemsForRead(false);
4965 } 4755 }
4966 m_host.CollisionSoundVolume = (float)impact_volume; 4756
4967 m_host.CollisionSound = soundId; 4757 m_host.CollisionSound = soundId;
4758 m_host.CollisionSoundVolume = (float)impact_volume;
4968 m_host.CollisionSoundType = 1; 4759 m_host.CollisionSoundType = 1;
4969 } 4760 }
4970 4761
@@ -5006,10 +4797,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5006 UUID partItemID; 4797 UUID partItemID;
5007 foreach (SceneObjectPart part in parts) 4798 foreach (SceneObjectPart part in parts)
5008 { 4799 {
5009 //Clone is thread safe 4800 foreach (TaskInventoryItem item in part.Inventory.GetInventoryItems())
5010 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone();
5011
5012 foreach (TaskInventoryItem item in itemsDictionary.Values)
5013 { 4801 {
5014 if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT) 4802 if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT)
5015 { 4803 {
@@ -5207,22 +4995,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5207 4995
5208 public LSL_String llGetScriptName() 4996 public LSL_String llGetScriptName()
5209 { 4997 {
5210 string result = String.Empty;
5211
5212 m_host.AddScriptLPS(1); 4998 m_host.AddScriptLPS(1);
5213 4999
5214 m_host.TaskInventory.LockItemsForRead(true); 5000 return m_item.Name != null ? m_item.Name : String.Empty;
5215 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
5216 {
5217 if (item.Type == 10 && item.ItemID == m_itemID)
5218 {
5219 result = item.Name!=null?item.Name:String.Empty;
5220 break;
5221 }
5222 }
5223 m_host.TaskInventory.LockItemsForRead(false);
5224
5225 return result;
5226 } 5001 }
5227 5002
5228 public LSL_Integer llGetLinkNumberOfSides(int link) 5003 public LSL_Integer llGetLinkNumberOfSides(int link)
@@ -5393,22 +5168,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5393 { 5168 {
5394 m_host.AddScriptLPS(1); 5169 m_host.AddScriptLPS(1);
5395 5170
5396 m_host.TaskInventory.LockItemsForRead(true); 5171 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
5397 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 5172
5173 if (item == null)
5174 return UUID.Zero.ToString();
5175
5176 if ((item.CurrentPermissions
5177 & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
5178 == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
5398 { 5179 {
5399 if (inv.Value.Name == name) 5180 return item.AssetID.ToString();
5400 {
5401 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
5402 {
5403 m_host.TaskInventory.LockItemsForRead(false);
5404 return inv.Value.AssetID.ToString();
5405 }
5406 else
5407 {
5408 m_host.TaskInventory.LockItemsForRead(false);
5409 return UUID.Zero.ToString();
5410 }
5411 }
5412 } 5181 }
5413 m_host.TaskInventory.LockItemsForRead(false); 5182 m_host.TaskInventory.LockItemsForRead(false);
5414 5183
@@ -6356,7 +6125,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6356 } 6125 }
6357 } 6126 }
6358 } 6127 }
6359 List<UUID> presenceIds = new List<UUID>();
6360 6128
6361 World.ForEachRootScenePresence( 6129 World.ForEachRootScenePresence(
6362 delegate (ScenePresence ssp) 6130 delegate (ScenePresence ssp)
@@ -6507,7 +6275,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6507 if (m_host.OwnerID == land.LandData.OwnerID) 6275 if (m_host.OwnerID == land.LandData.OwnerID)
6508 { 6276 {
6509 Vector3 pos = World.GetNearestAllowedPosition(presence, land); 6277 Vector3 pos = World.GetNearestAllowedPosition(presence, land);
6510 presence.TeleportWithMomentum(pos); 6278 presence.TeleportWithMomentum(pos, null);
6511 presence.ControllingClient.SendAlertMessage("You have been ejected from this land"); 6279 presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
6512 } 6280 }
6513 } 6281 }
@@ -7032,22 +6800,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7032 } 6800 }
7033 } 6801 }
7034 6802
7035 protected UUID GetTaskInventoryItem(string name)
7036 {
7037 m_host.TaskInventory.LockItemsForRead(true);
7038 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
7039 {
7040 if (inv.Value.Name == name)
7041 {
7042 m_host.TaskInventory.LockItemsForRead(false);
7043 return inv.Key;
7044 }
7045 }
7046 m_host.TaskInventory.LockItemsForRead(false);
7047
7048 return UUID.Zero;
7049 }
7050
7051 public void llGiveInventoryList(string destination, string category, LSL_List inventory) 6803 public void llGiveInventoryList(string destination, string category, LSL_List inventory)
7052 { 6804 {
7053 m_host.AddScriptLPS(1); 6805 m_host.AddScriptLPS(1);
@@ -7060,16 +6812,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7060 6812
7061 foreach (Object item in inventory.Data) 6813 foreach (Object item in inventory.Data)
7062 { 6814 {
6815 string rawItemString = item.ToString();
6816
7063 UUID itemID; 6817 UUID itemID;
7064 if (UUID.TryParse(item.ToString(), out itemID)) 6818 if (UUID.TryParse(rawItemString, out itemID))
7065 { 6819 {
7066 itemList.Add(itemID); 6820 itemList.Add(itemID);
7067 } 6821 }
7068 else 6822 else
7069 { 6823 {
7070 itemID = GetTaskInventoryItem(item.ToString()); 6824 TaskInventoryItem taskItem = m_host.Inventory.GetInventoryItem(rawItemString);
7071 if (itemID != UUID.Zero) 6825
7072 itemList.Add(itemID); 6826 if (taskItem != null)
6827 itemList.Add(taskItem.ItemID);
7073 } 6828 }
7074 } 6829 }
7075 6830
@@ -7391,9 +7146,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7391 public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param) 7146 public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
7392 { 7147 {
7393 m_host.AddScriptLPS(1); 7148 m_host.AddScriptLPS(1);
7394 bool found = false; 7149
7395 UUID destId = UUID.Zero; 7150 UUID destId = UUID.Zero;
7396 UUID srcId = UUID.Zero;
7397 7151
7398 if (!UUID.TryParse(target, out destId)) 7152 if (!UUID.TryParse(target, out destId))
7399 { 7153 {
@@ -7408,25 +7162,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7408 } 7162 }
7409 7163
7410 // copy the first script found with this inventory name 7164 // copy the first script found with this inventory name
7411 TaskInventoryItem scriptItem = null; 7165 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
7412 m_host.TaskInventory.LockItemsForRead(true);
7413 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
7414 {
7415 if (inv.Value.Name == name)
7416 {
7417 // make sure the object is a script
7418 if (10 == inv.Value.Type)
7419 {
7420 found = true;
7421 srcId = inv.Key;
7422 scriptItem = inv.Value;
7423 break;
7424 }
7425 }
7426 }
7427 m_host.TaskInventory.LockItemsForRead(false);
7428 7166
7429 if (!found) 7167 // make sure the object is a script
7168 if (item == null || item.Type != 10)
7430 { 7169 {
7431 llSay(0, "Could not find script " + name); 7170 llSay(0, "Could not find script " + name);
7432 return; 7171 return;
@@ -7435,13 +7174,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7435 SceneObjectPart dest = World.GetSceneObjectPart(destId); 7174 SceneObjectPart dest = World.GetSceneObjectPart(destId);
7436 if (dest != null) 7175 if (dest != null)
7437 { 7176 {
7438 if ((scriptItem.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID) 7177 if ((item.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID)
7439 { 7178 {
7440 // the rest of the permission checks are done in RezScript, so check the pin there as well 7179 // the rest of the permission checks are done in RezScript, so check the pin there as well
7441 World.RezScriptFromPrim(srcId, m_host, destId, pin, running, start_param); 7180 World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param);
7442 7181
7443 if ((scriptItem.BasePermissions & (uint)PermissionMask.Copy) == 0) 7182 if ((item.BasePermissions & (uint)PermissionMask.Copy) == 0)
7444 m_host.Inventory.RemoveInventoryItem(srcId); 7183 m_host.Inventory.RemoveInventoryItem(item.ItemID);
7445 } 7184 }
7446 } 7185 }
7447 // this will cause the delay even if the script pin or permissions were wrong - seems ok 7186 // this will cause the delay even if the script pin or permissions were wrong - seems ok
@@ -7454,14 +7193,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7454 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); 7193 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
7455 if (xmlrpcMod.IsEnabled()) 7194 if (xmlrpcMod.IsEnabled())
7456 { 7195 {
7457 UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_localID, m_itemID, UUID.Zero); 7196 UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero);
7458 IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>(); 7197 IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
7459 if (xmlRpcRouter != null) 7198 if (xmlRpcRouter != null)
7460 { 7199 {
7461 string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName; 7200 string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
7462 7201
7463 xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID, 7202 xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
7464 m_itemID, String.Format("http://{0}:{1}/", ExternalHostName, 7203 m_item.ItemID, String.Format("http://{0}:{1}/", ExternalHostName,
7465 xmlrpcMod.Port.ToString())); 7204 xmlrpcMod.Port.ToString()));
7466 } 7205 }
7467 object[] resobj = new object[] 7206 object[] resobj = new object[]
@@ -7473,7 +7212,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7473 new LSL_Integer(0), 7212 new LSL_Integer(0),
7474 new LSL_String(String.Empty) 7213 new LSL_String(String.Empty)
7475 }; 7214 };
7476 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams("remote_data", resobj, 7215 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj,
7477 new DetectParams[0])); 7216 new DetectParams[0]));
7478 } 7217 }
7479 ScriptSleep(1000); 7218 ScriptSleep(1000);
@@ -7484,7 +7223,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7484 m_host.AddScriptLPS(1); 7223 m_host.AddScriptLPS(1);
7485 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); 7224 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
7486 ScriptSleep(3000); 7225 ScriptSleep(3000);
7487 return (xmlrpcMod.SendRemoteData(m_localID, m_itemID, channel, dest, idata, sdata)).ToString(); 7226 return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString();
7488 } 7227 }
7489 7228
7490 public void llRemoteDataReply(string channel, string message_id, string sdata, int idata) 7229 public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
@@ -8488,7 +8227,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8488 return; 8227 return;
8489 face = (int)rules.GetLSLIntegerItem(idx++); 8228 face = (int)rules.GetLSLIntegerItem(idx++);
8490 int shiny = (int)rules.GetLSLIntegerItem(idx++); 8229 int shiny = (int)rules.GetLSLIntegerItem(idx++);
8491 Bumpiness bump = (Bumpiness)Convert.ToByte((int)rules.GetLSLIntegerItem(idx++)); 8230 Bumpiness bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);
8492 8231
8493 SetShiny(part, face, shiny, bump); 8232 SetShiny(part, face, shiny, bump);
8494 8233
@@ -10330,7 +10069,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10330 public LSL_String llGetSimulatorHostname() 10069 public LSL_String llGetSimulatorHostname()
10331 { 10070 {
10332 m_host.AddScriptLPS(1); 10071 m_host.AddScriptLPS(1);
10333 return System.Environment.MachineName; 10072 IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
10073 return UrlModule.ExternalHostNameForLSL;
10334 } 10074 }
10335 10075
10336 // <summary> 10076 // <summary>
@@ -10567,92 +10307,82 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10567 } 10307 }
10568 } 10308 }
10569 10309
10570 public LSL_Integer llGetInventoryPermMask(string item, int mask) 10310 public LSL_Integer llGetInventoryPermMask(string itemName, int mask)
10571 { 10311 {
10572 m_host.AddScriptLPS(1); 10312 m_host.AddScriptLPS(1);
10573 10313
10574 m_host.TaskInventory.LockItemsForRead(true); 10314 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
10575 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 10315
10316 if (item == null)
10317 return -1;
10318
10319 switch (mask)
10576 { 10320 {
10577 if (inv.Value.Name == item) 10321 case 0:
10578 { 10322 return (int)item.BasePermissions;
10579 m_host.TaskInventory.LockItemsForRead(false); 10323 case 1:
10580 switch (mask) 10324 return (int)item.CurrentPermissions;
10581 { 10325 case 2:
10582 case 0: 10326 return (int)item.GroupPermissions;
10583 return (int)inv.Value.BasePermissions; 10327 case 3:
10584 case 1: 10328 return (int)item.EveryonePermissions;
10585 return (int)inv.Value.CurrentPermissions; 10329 case 4:
10586 case 2: 10330 return (int)item.NextPermissions;
10587 return (int)inv.Value.GroupPermissions;
10588 case 3:
10589 return (int)inv.Value.EveryonePermissions;
10590 case 4:
10591 return (int)inv.Value.NextPermissions;
10592 }
10593 }
10594 } 10331 }
10595 m_host.TaskInventory.LockItemsForRead(false); 10332 m_host.TaskInventory.LockItemsForRead(false);
10596 10333
10597 return -1; 10334 return -1;
10598 } 10335 }
10599 10336
10600 public void llSetInventoryPermMask(string item, int mask, int value) 10337 public void llSetInventoryPermMask(string itemName, int mask, int value)
10601 { 10338 {
10602 m_host.AddScriptLPS(1); 10339 m_host.AddScriptLPS(1);
10340
10603 if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false)) 10341 if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
10604 { 10342 {
10605 if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID)) 10343 if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
10606 { 10344 {
10607 lock (m_host.TaskInventory) 10345 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
10346
10347 if (item != null)
10608 { 10348 {
10609 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 10349 switch (mask)
10610 { 10350 {
10611 if (inv.Value.Name == item) 10351 case 0:
10612 { 10352 item.BasePermissions = (uint)value;
10613 switch (mask) 10353 break;
10614 { 10354 case 1:
10615 case 0: 10355 item.CurrentPermissions = (uint)value;
10616 inv.Value.BasePermissions = (uint)value; 10356 break;
10617 break; 10357 case 2:
10618 case 1: 10358 item.GroupPermissions = (uint)value;
10619 inv.Value.CurrentPermissions = (uint)value; 10359 break;
10620 break; 10360 case 3:
10621 case 2: 10361 item.EveryonePermissions = (uint)value;
10622 inv.Value.GroupPermissions = (uint)value; 10362 break;
10623 break; 10363 case 4:
10624 case 3: 10364 item.NextPermissions = (uint)value;
10625 inv.Value.EveryonePermissions = (uint)value; 10365 break;
10626 break;
10627 case 4:
10628 inv.Value.NextPermissions = (uint)value;
10629 break;
10630 }
10631 }
10632 } 10366 }
10633 } 10367 }
10634 } 10368 }
10635 } 10369 }
10636 } 10370 }
10637 10371
10638 public LSL_String llGetInventoryCreator(string item) 10372 public LSL_String llGetInventoryCreator(string itemName)
10639 { 10373 {
10640 m_host.AddScriptLPS(1); 10374 m_host.AddScriptLPS(1);
10641 10375
10642 m_host.TaskInventory.LockItemsForRead(true); 10376 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
10643 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 10377
10378 if (item == null)
10644 { 10379 {
10645 if (inv.Value.Name == item) 10380 llSay(0, "No item name '" + item + "'");
10646 {
10647 m_host.TaskInventory.LockItemsForRead(false);
10648 return inv.Value.CreatorID.ToString();
10649 }
10650 }
10651 m_host.TaskInventory.LockItemsForRead(false);
10652 10381
10653 llSay(0, "No item name '" + item + "'"); 10382 return String.Empty;
10383 }
10654 10384
10655 return String.Empty; 10385 return item.CreatorID.ToString();
10656 } 10386 }
10657 10387
10658 public void llOwnerSay(string msg) 10388 public void llOwnerSay(string msg)
@@ -10669,13 +10399,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10669 { 10399 {
10670 m_host.AddScriptLPS(1); 10400 m_host.AddScriptLPS(1);
10671 if (m_UrlModule != null) 10401 if (m_UrlModule != null)
10672 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString(); 10402 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
10673 return UUID.Zero.ToString(); 10403 return UUID.Zero.ToString();
10674 } 10404 }
10675 10405
10676 public LSL_String llRequestSimulatorData(string simulator, int data) 10406 public LSL_String llRequestSimulatorData(string simulator, int data)
10677 { 10407 {
10678 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_itemID, "OSSL"); 10408 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
10679 10409
10680 try 10410 try
10681 { 10411 {
@@ -10685,7 +10415,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10685 10415
10686 GridRegion info; 10416 GridRegion info;
10687 10417
10688 if (m_ScriptEngine.World.RegionInfo.RegionName == simulator) 10418 if (m_ScriptEngine.World.RegionInfo.RegionName == simulator) //Det data for this simulator?
10419
10689 info = new GridRegion(m_ScriptEngine.World.RegionInfo); 10420 info = new GridRegion(m_ScriptEngine.World.RegionInfo);
10690 else 10421 else
10691 info = m_ScriptEngine.World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator); 10422 info = m_ScriptEngine.World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator);
@@ -10698,10 +10429,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10698 ScriptSleep(1000); 10429 ScriptSleep(1000);
10699 return UUID.Zero.ToString(); 10430 return UUID.Zero.ToString();
10700 } 10431 }
10701 reply = new LSL_Vector( 10432 if (m_ScriptEngine.World.RegionInfo.RegionName != simulator)
10702 info.RegionLocX, 10433 {
10703 info.RegionLocY, 10434 //Hypergrid Region co-ordinates
10704 0).ToString(); 10435 uint rx = 0, ry = 0;
10436 Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out rx, out ry);
10437
10438 reply = new LSL_Vector(
10439 rx,
10440 ry,
10441 0).ToString();
10442 }
10443 else
10444 {
10445 //Local-cooridnates
10446 reply = new LSL_Vector(
10447 info.RegionLocX,
10448 info.RegionLocY,
10449 0).ToString();
10450 }
10705 break; 10451 break;
10706 case ScriptBaseClass.DATA_SIM_STATUS: 10452 case ScriptBaseClass.DATA_SIM_STATUS:
10707 if (info != null) 10453 if (info != null)
@@ -10737,7 +10483,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10737 UUID rq = UUID.Random(); 10483 UUID rq = UUID.Random();
10738 10484
10739 UUID tid = AsyncCommands. 10485 UUID tid = AsyncCommands.
10740 DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 10486 DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
10741 10487
10742 AsyncCommands. 10488 AsyncCommands.
10743 DataserverPlugin.DataserverReply(rq.ToString(), reply); 10489 DataserverPlugin.DataserverReply(rq.ToString(), reply);
@@ -10756,7 +10502,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10756 m_host.AddScriptLPS(1); 10502 m_host.AddScriptLPS(1);
10757 10503
10758 if (m_UrlModule != null) 10504 if (m_UrlModule != null)
10759 return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString(); 10505 return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
10760 return UUID.Zero.ToString(); 10506 return UUID.Zero.ToString();
10761 } 10507 }
10762 10508
@@ -10792,7 +10538,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10792 // child agents have a mass of 1.0 10538 // child agents have a mass of 1.0
10793 return 1; 10539 return 1;
10794 else 10540 else
10795 return avatar.GetMass(); 10541 return (double)avatar.GetMass();
10796 } 10542 }
10797 catch (KeyNotFoundException) 10543 catch (KeyNotFoundException)
10798 { 10544 {
@@ -11196,18 +10942,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11196 { 10942 {
11197 m_host.AddScriptLPS(1); 10943 m_host.AddScriptLPS(1);
11198 10944
11199 m_host.TaskInventory.LockItemsForRead(true); 10945 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
11200 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
11201 {
11202 if (inv.Value.Name == name)
11203 {
11204 m_host.TaskInventory.LockItemsForRead(false);
11205 return inv.Value.Type;
11206 }
11207 }
11208 m_host.TaskInventory.LockItemsForRead(false);
11209 10946
11210 return -1; 10947 if (item == null)
10948 return -1;
10949
10950 return item.Type;
11211 } 10951 }
11212 10952
11213 public void llSetPayPrice(int price, LSL_List quick_pay_buttons) 10953 public void llSetPayPrice(int price, LSL_List quick_pay_buttons)
@@ -11235,32 +10975,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11235 public LSL_Vector llGetCameraPos() 10975 public LSL_Vector llGetCameraPos()
11236 { 10976 {
11237 m_host.AddScriptLPS(1); 10977 m_host.AddScriptLPS(1);
11238 UUID invItemID = InventorySelf();
11239
11240 if (invItemID == UUID.Zero)
11241 return new LSL_Vector();
11242
11243 m_host.TaskInventory.LockItemsForRead(true);
11244 10978
11245 UUID agentID = m_host.TaskInventory[invItemID].PermsGranter; 10979 if (m_item.PermsGranter == UUID.Zero)
10980 return new LSL_Vector();
11246 10981
11247// if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 10982 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
11248 if (agentID == UUID.Zero)
11249 {
11250 m_host.TaskInventory.LockItemsForRead(false);
11251 return new LSL_Vector();
11252 }
11253
11254 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
11255 { 10983 {
11256 ShoutError("No permissions to track the camera"); 10984 ShoutError("No permissions to track the camera");
11257 m_host.TaskInventory.LockItemsForRead(false);
11258 return new LSL_Vector(); 10985 return new LSL_Vector();
11259 } 10986 }
11260 m_host.TaskInventory.LockItemsForRead(false);
11261 10987
11262// ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10988// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
11263 ScenePresence presence = World.GetScenePresence(agentID); 10989 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
11264 if (presence != null) 10990 if (presence != null)
11265 { 10991 {
11266 LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z); 10992 LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z);
@@ -11272,30 +10998,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11272 public LSL_Rotation llGetCameraRot() 10998 public LSL_Rotation llGetCameraRot()
11273 { 10999 {
11274 m_host.AddScriptLPS(1); 11000 m_host.AddScriptLPS(1);
11275 UUID invItemID = InventorySelf();
11276 if (invItemID == UUID.Zero)
11277 return new LSL_Rotation();
11278 11001
11279 m_host.TaskInventory.LockItemsForRead(true); 11002 if (m_item.PermsGranter == UUID.Zero)
11280 11003 return new LSL_Rotation();
11281 UUID agentID = m_host.TaskInventory[invItemID].PermsGranter;
11282 11004
11283// if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 11005 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
11284 if (agentID == UUID.Zero)
11285 {
11286 m_host.TaskInventory.LockItemsForRead(false);
11287 return new LSL_Rotation();
11288 }
11289 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
11290 { 11006 {
11291 ShoutError("No permissions to track the camera"); 11007 ShoutError("No permissions to track the camera");
11292 m_host.TaskInventory.LockItemsForRead(false);
11293 return new LSL_Rotation(); 11008 return new LSL_Rotation();
11294 } 11009 }
11295 m_host.TaskInventory.LockItemsForRead(false);
11296 11010
11297// ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 11011// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
11298 ScenePresence presence = World.GetScenePresence(agentID); 11012 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
11299 if (presence != null) 11013 if (presence != null)
11300 { 11014 {
11301 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W); 11015 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W);
@@ -11354,7 +11068,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11354 public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt) 11068 public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
11355 { 11069 {
11356 m_host.AddScriptLPS(1); 11070 m_host.AddScriptLPS(1);
11357 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0); 11071 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
11358 if (detectedParams == null) 11072 if (detectedParams == null)
11359 { 11073 {
11360 if (m_host.ParentGroup.IsAttachment == true) 11074 if (m_host.ParentGroup.IsAttachment == true)
@@ -11478,30 +11192,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11478 { 11192 {
11479 m_host.AddScriptLPS(1); 11193 m_host.AddScriptLPS(1);
11480 11194
11481 // our key in the object we are in
11482 UUID invItemID = InventorySelf();
11483 if (invItemID == UUID.Zero) return;
11484
11485 // the object we are in 11195 // the object we are in
11486 UUID objectID = m_host.ParentUUID; 11196 UUID objectID = m_host.ParentUUID;
11487 if (objectID == UUID.Zero) return; 11197 if (objectID == UUID.Zero)
11198 return;
11488 11199
11489 UUID agentID;
11490 m_host.TaskInventory.LockItemsForRead(true);
11491 // we need the permission first, to know which avatar we want to set the camera for 11200 // we need the permission first, to know which avatar we want to set the camera for
11492 agentID = m_host.TaskInventory[invItemID].PermsGranter; 11201 UUID agentID = m_item.PermsGranter;
11493 11202
11494 if (agentID == UUID.Zero) 11203 if (agentID == UUID.Zero)
11495 {
11496 m_host.TaskInventory.LockItemsForRead(false);
11497 return; 11204 return;
11498 } 11205
11499 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) 11206 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
11500 {
11501 m_host.TaskInventory.LockItemsForRead(false);
11502 return; 11207 return;
11503 }
11504 m_host.TaskInventory.LockItemsForRead(false);
11505 11208
11506 ScenePresence presence = World.GetScenePresence(agentID); 11209 ScenePresence presence = World.GetScenePresence(agentID);
11507 11210
@@ -11543,34 +11246,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11543 { 11246 {
11544 m_host.AddScriptLPS(1); 11247 m_host.AddScriptLPS(1);
11545 11248
11546 // our key in the object we are in
11547 UUID invItemID=InventorySelf();
11548 if (invItemID == UUID.Zero) return;
11549
11550 // the object we are in 11249 // the object we are in
11551 UUID objectID = m_host.ParentUUID; 11250 UUID objectID = m_host.ParentUUID;
11552 if (objectID == UUID.Zero) return; 11251 if (objectID == UUID.Zero)
11252 return;
11553 11253
11554 // we need the permission first, to know which avatar we want to clear the camera for 11254 // we need the permission first, to know which avatar we want to clear the camera for
11555 UUID agentID; 11255 UUID agentID = m_item.PermsGranter;
11556 m_host.TaskInventory.LockItemsForRead(true); 11256
11557 agentID = m_host.TaskInventory[invItemID].PermsGranter;
11558 if (agentID == UUID.Zero) 11257 if (agentID == UUID.Zero)
11559 {
11560 m_host.TaskInventory.LockItemsForRead(false);
11561 return; 11258 return;
11562 } 11259
11563 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) 11260 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
11564 {
11565 m_host.TaskInventory.LockItemsForRead(false);
11566 return; 11261 return;
11567 }
11568 m_host.TaskInventory.LockItemsForRead(false);
11569 11262
11570 ScenePresence presence = World.GetScenePresence(agentID); 11263 ScenePresence presence = World.GetScenePresence(agentID);
11571 11264
11572 // we are not interested in child-agents 11265 // we are not interested in child-agents
11573 if (presence.IsChildAgent) return; 11266 if (presence.IsChildAgent)
11267 return;
11574 11268
11575 presence.ControllingClient.SendClearFollowCamProperties(objectID); 11269 presence.ControllingClient.SendClearFollowCamProperties(objectID);
11576 } 11270 }
@@ -11761,8 +11455,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11761 } 11455 }
11762 } 11456 }
11763 11457
11764 UUID reqID = httpScriptMod. 11458 UUID reqID
11765 StartHttpRequest(m_localID, m_itemID, url, param, httpHeaders, body); 11459 = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body);
11766 11460
11767 if (reqID != UUID.Zero) 11461 if (reqID != UUID.Zero)
11768 return reqID.ToString(); 11462 return reqID.ToString();
@@ -12016,19 +11710,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12016 break; 11710 break;
12017 // For the following 8 see the Object version below 11711 // For the following 8 see the Object version below
12018 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT: 11712 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
12019 ret.Add(new LSL_Integer(0)); 11713 ret.Add(new LSL_Integer(av.RunningScriptCount()));
12020 break; 11714 break;
12021 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT: 11715 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
12022 ret.Add(new LSL_Integer(0)); 11716 ret.Add(new LSL_Integer(av.ScriptCount()));
12023 break; 11717 break;
12024 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY: 11718 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
12025 ret.Add(new LSL_Integer(0)); 11719 ret.Add(new LSL_Integer(av.RunningScriptCount() * 16384));
12026 break; 11720 break;
12027 case ScriptBaseClass.OBJECT_SCRIPT_TIME: 11721 case ScriptBaseClass.OBJECT_SCRIPT_TIME:
12028 ret.Add(new LSL_Float(0)); 11722 ret.Add(new LSL_Float(av.ScriptExecutionTime() / 1000.0f));
12029 break; 11723 break;
12030 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE: 11724 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
12031 ret.Add(new LSL_Integer(0)); 11725 ret.Add(new LSL_Integer(1));
12032 break; 11726 break;
12033 case ScriptBaseClass.OBJECT_SERVER_COST: 11727 case ScriptBaseClass.OBJECT_SERVER_COST:
12034 ret.Add(new LSL_Float(0)); 11728 ret.Add(new LSL_Float(0));
@@ -12086,37 +11780,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12086 case ScriptBaseClass.OBJECT_CREATOR: 11780 case ScriptBaseClass.OBJECT_CREATOR:
12087 ret.Add(new LSL_String(obj.CreatorID.ToString())); 11781 ret.Add(new LSL_String(obj.CreatorID.ToString()));
12088 break; 11782 break;
12089 // The following 8 I have intentionaly coded to return zero. They are part of
12090 // "Land Impact" calculations. These calculations are probably not applicable
12091 // to OpenSim, required figures (cpu/memory usage) are not currently tracked
12092 // I have intentionally left these all at zero rather than return possibly
12093 // missleading numbers
12094 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT: 11783 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
12095 // in SL this currently includes crashed scripts 11784 ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount()));
12096 ret.Add(new LSL_Integer(0));
12097 break; 11785 break;
12098 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT: 11786 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
12099 ret.Add(new LSL_Integer(0)); 11787 ret.Add(new LSL_Integer(obj.ParentGroup.ScriptCount()));
12100 break; 11788 break;
12101 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY: 11789 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
12102 // The value returned in SL for mono scripts is 65536 * number of active scripts 11790 // The value returned in SL for mono scripts is 65536 * number of active scripts
12103 ret.Add(new LSL_Integer(0)); 11791 // and 16384 * number of active scripts for LSO. since llGetFreememory
11792 // is coded to give the LSO value use it here
11793 ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount() * 16384));
12104 break; 11794 break;
12105 case ScriptBaseClass.OBJECT_SCRIPT_TIME: 11795 case ScriptBaseClass.OBJECT_SCRIPT_TIME:
12106 // Average cpu time per simulator frame expended on all scripts in the objetc 11796 // Average cpu time in seconds per simulator frame expended on all scripts in the object
12107 ret.Add(new LSL_Float(0)); 11797 ret.Add(new LSL_Float(obj.ParentGroup.ScriptExecutionTime() / 1000.0f));
12108 break; 11798 break;
12109 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE: 11799 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
12110 // according to the SL wiki A prim or linkset will have prim 11800 // according to the SL wiki A prim or linkset will have prim
12111 // equivalent of the number of prims in a linkset if it does not 11801 // equivalent of the number of prims in a linkset if it does not
12112 // contain a mesh anywhere in the link set or is not a normal prim 11802 // contain a mesh anywhere in the link set or is not a normal prim
12113 // The value returned in SL for normal prims is prim count 11803 // The value returned in SL for normal prims is prim count
12114 ret.Add(new LSL_Integer(0)); 11804 ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
12115 break; 11805 break;
12116 11806
12117 // costs below may need to be diferent for root parts, need to check 11807 // costs below may need to be diferent for root parts, need to check
12118 case ScriptBaseClass.OBJECT_SERVER_COST: 11808 case ScriptBaseClass.OBJECT_SERVER_COST:
12119 // The value returned in SL for normal prims is prim count 11809 // The linden calculation is here
11810 // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
11811 // The value returned in SL for normal prims looks like the prim count
12120 ret.Add(new LSL_Float(0)); 11812 ret.Add(new LSL_Float(0));
12121 break; 11813 break;
12122 case ScriptBaseClass.OBJECT_STREAMING_COST: 11814 case ScriptBaseClass.OBJECT_STREAMING_COST:
@@ -12141,22 +11833,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12141 return new LSL_List(); 11833 return new LSL_List();
12142 } 11834 }
12143 11835
12144 internal UUID ScriptByName(string name) 11836 internal UUID GetScriptByName(string name)
12145 { 11837 {
12146 m_host.TaskInventory.LockItemsForRead(true); 11838 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
12147
12148 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
12149 {
12150 if (item.Type == 10 && item.Name == name)
12151 {
12152 m_host.TaskInventory.LockItemsForRead(false);
12153 return item.ItemID;
12154 }
12155 }
12156 11839
12157 m_host.TaskInventory.LockItemsForRead(false); 11840 if (item == null || item.Type != 10)
11841 return UUID.Zero;
12158 11842
12159 return UUID.Zero; 11843 return item.ItemID;
12160 } 11844 }
12161 11845
12162 internal void ShoutError(string msg) 11846 internal void ShoutError(string msg)
@@ -12196,21 +11880,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12196 { 11880 {
12197 m_host.AddScriptLPS(1); 11881 m_host.AddScriptLPS(1);
12198 11882
12199 //Clone is thread safe
12200 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
12201
12202 UUID assetID = UUID.Zero; 11883 UUID assetID = UUID.Zero;
12203 11884
12204 if (!UUID.TryParse(name, out assetID)) 11885 if (!UUID.TryParse(name, out assetID))
12205 { 11886 {
12206 foreach (TaskInventoryItem item in itemsDictionary.Values) 11887 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
12207 { 11888
12208 if (item.Type == 7 && item.Name == name) 11889 if (item != null && item.Type == 7)
12209 { 11890 assetID = item.AssetID;
12210 assetID = item.AssetID;
12211 break;
12212 }
12213 }
12214 } 11891 }
12215 11892
12216 if (assetID == UUID.Zero) 11893 if (assetID == UUID.Zero)
@@ -12222,7 +11899,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12222 } 11899 }
12223 11900
12224 // was: UUID tid = tid = AsyncCommands. 11901 // was: UUID tid = tid = AsyncCommands.
12225 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, assetID.ToString()); 11902 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, assetID.ToString());
12226 11903
12227 if (NotecardCache.IsCached(assetID)) 11904 if (NotecardCache.IsCached(assetID))
12228 { 11905 {
@@ -12259,21 +11936,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12259 { 11936 {
12260 m_host.AddScriptLPS(1); 11937 m_host.AddScriptLPS(1);
12261 11938
12262 //Clone is thread safe
12263 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
12264
12265 UUID assetID = UUID.Zero; 11939 UUID assetID = UUID.Zero;
12266 11940
12267 if (!UUID.TryParse(name, out assetID)) 11941 if (!UUID.TryParse(name, out assetID))
12268 { 11942 {
12269 foreach (TaskInventoryItem item in itemsDictionary.Values) 11943 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
12270 { 11944
12271 if (item.Type == 7 && item.Name == name) 11945 if (item != null && item.Type == 7)
12272 { 11946 assetID = item.AssetID;
12273 assetID = item.AssetID;
12274 break;
12275 }
12276 }
12277 } 11947 }
12278 11948
12279 if (assetID == UUID.Zero) 11949 if (assetID == UUID.Zero)
@@ -12285,7 +11955,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12285 } 11955 }
12286 11956
12287 // was: UUID tid = tid = AsyncCommands. 11957 // was: UUID tid = tid = AsyncCommands.
12288 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, assetID.ToString()); 11958 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, assetID.ToString());
12289 11959
12290 if (NotecardCache.IsCached(assetID)) 11960 if (NotecardCache.IsCached(assetID))
12291 { 11961 {
@@ -12369,7 +12039,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12369 { 12039 {
12370 UUID rq = UUID.Random(); 12040 UUID rq = UUID.Random();
12371 12041
12372 AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 12042 AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
12373 12043
12374 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id))); 12044 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id)));
12375 12045
@@ -12385,7 +12055,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12385 { 12055 {
12386 UUID rq = UUID.Random(); 12056 UUID rq = UUID.Random();
12387 12057
12388 AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 12058 AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
12389 12059
12390 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id)); 12060 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id));
12391 12061
@@ -12587,7 +12257,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12587 { 12257 {
12588 Tri t1 = new Tri(); 12258 Tri t1 = new Tri();
12589 Tri t2 = new Tri(); 12259 Tri t2 = new Tri();
12590 12260
12591 Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]); 12261 Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]);
12592 Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]); 12262 Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]);
12593 Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]); 12263 Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]);
@@ -12628,7 +12298,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12628 // sometimes 12298 // sometimes
12629 if (Math.Abs(b) < 0.000001) 12299 if (Math.Abs(b) < 0.000001)
12630 continue; 12300 continue;
12631 12301
12632 double r = a / b; 12302 double r = a / b;
12633 12303
12634 // ray points away from plane 12304 // ray points away from plane
@@ -12888,7 +12558,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12888 bool isAccount = false; 12558 bool isAccount = false;
12889 bool isGroup = false; 12559 bool isGroup = false;
12890 12560
12891 if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManager(m_host.OwnerID)) 12561 if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManagerOrOwner(m_host.OwnerID))
12892 return 0; 12562 return 0;
12893 12563
12894 UUID id = new UUID(); 12564 UUID id = new UUID();
@@ -12950,35 +12620,50 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12950 return 1; 12620 return 1;
12951 } 12621 }
12952 12622
12953 #region Not Implemented 12623 public LSL_Integer llGetMemoryLimit()
12954 // 12624 {
12955 // Listing the unimplemented lsl functions here, please move 12625 m_host.AddScriptLPS(1);
12956 // them from this region as they are completed 12626 // The value returned for LSO scripts in SL
12957 // 12627 return 16384;
12628 }
12958 12629
12959 public void llGetEnv(LSL_String name) 12630 public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
12960 { 12631 {
12961 m_host.AddScriptLPS(1); 12632 m_host.AddScriptLPS(1);
12962 NotImplemented("llGetEnv"); 12633 // Treat as an LSO script
12634 return ScriptBaseClass.FALSE;
12963 } 12635 }
12964 12636
12965 public void llGetSPMaxMemory() 12637 public LSL_Integer llGetSPMaxMemory()
12966 { 12638 {
12967 m_host.AddScriptLPS(1); 12639 m_host.AddScriptLPS(1);
12968 NotImplemented("llGetSPMaxMemory"); 12640 // The value returned for LSO scripts in SL
12641 return 16384;
12969 } 12642 }
12970 12643
12971 public virtual LSL_Integer llGetUsedMemory() 12644 public virtual LSL_Integer llGetUsedMemory()
12972 { 12645 {
12973 m_host.AddScriptLPS(1); 12646 m_host.AddScriptLPS(1);
12974 NotImplemented("llGetUsedMemory"); 12647 // The value returned for LSO scripts in SL
12975 return 0; 12648 return 16384;
12976 } 12649 }
12977 12650
12978 public void llScriptProfiler(LSL_Integer flags) 12651 public void llScriptProfiler(LSL_Integer flags)
12979 { 12652 {
12980 m_host.AddScriptLPS(1); 12653 m_host.AddScriptLPS(1);
12981 //NotImplemented("llScriptProfiler"); 12654 // This does nothing for LSO scripts in SL
12655 }
12656
12657 #region Not Implemented
12658 //
12659 // Listing the unimplemented lsl functions here, please move
12660 // them from this region as they are completed
12661 //
12662
12663 public void llGetEnv(LSL_String name)
12664 {
12665 m_host.AddScriptLPS(1);
12666 NotImplemented("llGetEnv");
12982 } 12667 }
12983 12668
12984 public void llSetSoundQueueing(int queue) 12669 public void llSetSoundQueueing(int queue)
@@ -13058,8 +12743,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13058 12743
13059 try 12744 try
13060 { 12745 {
13061 UUID invItemID=InventorySelf(); 12746 TaskInventoryItem item = m_item;
13062 if (invItemID == UUID.Zero) 12747 if (item == null)
13063 { 12748 {
13064 replydata = "SERVICE_ERROR"; 12749 replydata = "SERVICE_ERROR";
13065 return; 12750 return;
@@ -13067,10 +12752,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13067 12752
13068 m_host.AddScriptLPS(1); 12753 m_host.AddScriptLPS(1);
13069 12754
13070 m_host.TaskInventory.LockItemsForRead(true);
13071 TaskInventoryItem item = m_host.TaskInventory[invItemID];
13072 m_host.TaskInventory.LockItemsForRead(false);
13073
13074 if (item.PermsGranter == UUID.Zero) 12755 if (item.PermsGranter == UUID.Zero)
13075 { 12756 {
13076 replydata = "MISSING_PERMISSION_DEBIT"; 12757 replydata = "MISSING_PERMISSION_DEBIT";
@@ -13112,7 +12793,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13112 } 12793 }
13113 finally 12794 finally
13114 { 12795 {
13115 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 12796 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
13116 "transaction_result", new Object[] { 12797 "transaction_result", new Object[] {
13117 new LSL_String(txn.ToString()), 12798 new LSL_String(txn.ToString()),
13118 new LSL_Integer(replycode), 12799 new LSL_Integer(replycode),
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
index 77a784d..795de80 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
@@ -58,17 +58,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
58 { 58 {
59 internal IScriptEngine m_ScriptEngine; 59 internal IScriptEngine m_ScriptEngine;
60 internal SceneObjectPart m_host; 60 internal SceneObjectPart m_host;
61 internal uint m_localID;
62 internal UUID m_itemID;
63 internal bool m_LSFunctionsEnabled = false; 61 internal bool m_LSFunctionsEnabled = false;
64 internal IScriptModuleComms m_comms = null; 62 internal IScriptModuleComms m_comms = null;
65 63
66 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) 64 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item)
67 { 65 {
68 m_ScriptEngine = ScriptEngine; 66 m_ScriptEngine = ScriptEngine;
69 m_host = host; 67 m_host = host;
70 m_localID = localID;
71 m_itemID = itemID;
72 68
73 if (m_ScriptEngine.Config.GetBoolean("AllowLightShareFunctions", false)) 69 if (m_ScriptEngine.Config.GetBoolean("AllowLightShareFunctions", false))
74 m_LSFunctionsEnabled = true; 70 m_LSFunctionsEnabled = true;
@@ -449,7 +445,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
449 LSShoutError("LightShare functions are not enabled."); 445 LSShoutError("LightShare functions are not enabled.");
450 return 0; 446 return 0;
451 } 447 }
452 if (!World.RegionInfo.EstateSettings.IsEstateManager(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200) 448 if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200)
453 { 449 {
454 LSShoutError("lsSetWindlightScene can only be used by estate managers or owners."); 450 LSShoutError("lsSetWindlightScene can only be used by estate managers or owners.");
455 return 0; 451 return 0;
@@ -477,7 +473,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
477 LSShoutError("LightShare functions are not enabled."); 473 LSShoutError("LightShare functions are not enabled.");
478 return; 474 return;
479 } 475 }
480 if (!World.RegionInfo.EstateSettings.IsEstateManager(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200) 476 if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200)
481 { 477 {
482 LSShoutError("lsSetWindlightScene can only be used by estate managers or owners."); 478 LSShoutError("lsSetWindlightScene can only be used by estate managers or owners.");
483 return; 479 return;
@@ -500,7 +496,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
500 LSShoutError("LightShare functions are not enabled."); 496 LSShoutError("LightShare functions are not enabled.");
501 return 0; 497 return 0;
502 } 498 }
503 if (!World.RegionInfo.EstateSettings.IsEstateManager(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200) 499 if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200)
504 { 500 {
505 LSShoutError("lsSetWindlightSceneTargeted can only be used by estate managers or owners."); 501 LSShoutError("lsSetWindlightSceneTargeted can only be used by estate managers or owners.");
506 return 0; 502 return 0;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
index 7c07e15..4bd3dff 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
@@ -57,17 +57,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
57 { 57 {
58 internal IScriptEngine m_ScriptEngine; 58 internal IScriptEngine m_ScriptEngine;
59 internal SceneObjectPart m_host; 59 internal SceneObjectPart m_host;
60 internal uint m_localID; 60 internal TaskInventoryItem m_item;
61 internal UUID m_itemID;
62 internal bool m_MODFunctionsEnabled = false; 61 internal bool m_MODFunctionsEnabled = false;
63 internal IScriptModuleComms m_comms = null; 62 internal IScriptModuleComms m_comms = null;
64 63
65 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) 64 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item)
66 { 65 {
67 m_ScriptEngine = ScriptEngine; 66 m_ScriptEngine = ScriptEngine;
68 m_host = host; 67 m_host = host;
69 m_localID = localID; 68 m_item = item;
70 m_itemID = itemID;
71 69
72 if (m_ScriptEngine.Config.GetBoolean("AllowMODFunctions", false)) 70 if (m_ScriptEngine.Config.GetBoolean("AllowMODFunctions", false))
73 m_MODFunctionsEnabled = true; 71 m_MODFunctionsEnabled = true;
@@ -252,7 +250,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
252 // non-null but don't trust it completely 250 // non-null but don't trust it completely
253 try 251 try
254 { 252 {
255 object result = m_comms.InvokeOperation(m_host.UUID, m_itemID, fname, convertedParms); 253 object result = m_comms.InvokeOperation(m_host.UUID, m_item.ItemID, fname, convertedParms);
256 if (result != null) 254 if (result != null)
257 return result; 255 return result;
258 256
@@ -279,7 +277,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
279 277
280 UUID req = UUID.Random(); 278 UUID req = UUID.Random();
281 279
282 m_comms.RaiseEvent(m_itemID, req.ToString(), module, command, k); 280 m_comms.RaiseEvent(m_item.ItemID, req.ToString(), module, command, k);
283 281
284 return req.ToString(); 282 return req.ToString();
285 } 283 }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 0dc2aa2..b639d36 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -126,13 +126,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
126 [Serializable] 126 [Serializable]
127 public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi 127 public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi
128 { 128 {
129// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 129 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
130
131 public const string GridInfoServiceConfigSectionName = "GridInfoService";
130 132
131 internal IScriptEngine m_ScriptEngine; 133 internal IScriptEngine m_ScriptEngine;
132 internal ILSL_Api m_LSL_Api = null; // get a reference to the LSL API so we can call methods housed there 134 internal ILSL_Api m_LSL_Api = null; // get a reference to the LSL API so we can call methods housed there
133 internal SceneObjectPart m_host; 135 internal SceneObjectPart m_host;
134 internal uint m_localID; 136 internal TaskInventoryItem m_item;
135 internal UUID m_itemID;
136 internal bool m_OSFunctionsEnabled = false; 137 internal bool m_OSFunctionsEnabled = false;
137 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow; 138 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow;
138 internal float m_ScriptDelayFactor = 1.0f; 139 internal float m_ScriptDelayFactor = 1.0f;
@@ -140,12 +141,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
140 internal bool m_debuggerSafe = false; 141 internal bool m_debuggerSafe = false;
141 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); 142 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
142 143
143 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) 144 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item)
144 { 145 {
145 m_ScriptEngine = ScriptEngine; 146 m_ScriptEngine = ScriptEngine;
146 m_host = host; 147 m_host = host;
147 m_localID = localID; 148 m_item = item;
148 m_itemID = itemID;
149 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false); 149 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
150 150
151 if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false)) 151 if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
@@ -218,12 +218,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
218 } 218 }
219 } 219 }
220 220
221 /// <summary>
222 /// Initialize the LSL interface.
223 /// </summary>
224 /// <remarks>
225 /// FIXME: This is an abomination. We should be able to set this up earlier but currently we have no
226 /// guarantee the interface is present on Initialize(). There needs to be another post initialize call from
227 /// ScriptInstance.
228 /// </remarks>
221 private void InitLSL() 229 private void InitLSL()
222 { 230 {
223 if (m_LSL_Api != null) 231 if (m_LSL_Api != null)
224 return; 232 return;
225 233
226 m_LSL_Api = (ILSL_Api)m_ScriptEngine.GetApi(m_itemID, "LSL"); 234 m_LSL_Api = (ILSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "LSL");
227 } 235 }
228 236
229 // 237 //
@@ -342,22 +350,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
342 return; 350 return;
343 } 351 }
344 352
345 TaskInventoryItem ti = m_host.Inventory.GetInventoryItem(m_itemID); 353 UUID ownerID = m_item.OwnerID;
346 if (ti == null)
347 {
348 OSSLError(
349 String.Format("{0} permission error. Can't find script in prim inventory.",
350 function));
351 }
352
353 UUID ownerID = ti.OwnerID;
354 354
355 //OSSL only may be used if objet is in the same group as the parcel 355 //OSSL only may be used if object is in the same group as the parcel
356 if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("PARCEL_GROUP_MEMBER")) 356 if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("PARCEL_GROUP_MEMBER"))
357 { 357 {
358 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y); 358 ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
359 359
360 if (land.LandData.GroupID == ti.GroupID && land.LandData.GroupID != UUID.Zero) 360 if (land.LandData.GroupID == m_item.GroupID && land.LandData.GroupID != UUID.Zero)
361 { 361 {
362 return; 362 return;
363 } 363 }
@@ -378,7 +378,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
378 if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("ESTATE_MANAGER")) 378 if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("ESTATE_MANAGER"))
379 { 379 {
380 //Only Estate Managers may use the function 380 //Only Estate Managers may use the function
381 if (World.RegionInfo.EstateSettings.IsEstateManager(ownerID) && World.RegionInfo.EstateSettings.EstateOwner != ownerID) 381 if (World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(ownerID) && World.RegionInfo.EstateSettings.EstateOwner != ownerID)
382 { 382 {
383 return; 383 return;
384 } 384 }
@@ -393,13 +393,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
393 } 393 }
394 } 394 }
395 395
396 if (!m_FunctionPerms[function].AllowedCreators.Contains(ti.CreatorID)) 396 if (!m_FunctionPerms[function].AllowedCreators.Contains(m_item.CreatorID))
397 OSSLError( 397 OSSLError(
398 String.Format("{0} permission denied. Script creator is not in the list of users allowed to execute this function and prim owner also has no permission.", 398 String.Format("{0} permission denied. Script creator is not in the list of users allowed to execute this function and prim owner also has no permission.",
399 function)); 399 function));
400 if (ti.CreatorID != ownerID) 400
401 if (m_item.CreatorID != ownerID)
401 { 402 {
402 if ((ti.CurrentPermissions & (uint)PermissionMask.Modify) != 0) 403 if ((m_item.CurrentPermissions & (uint)PermissionMask.Modify) != 0)
403 OSSLError( 404 OSSLError(
404 String.Format("{0} permission denied. Script permissions error.", 405 String.Format("{0} permission denied. Script permissions error.",
405 function)); 406 function));
@@ -730,11 +731,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
730 731
731 m_host.AddScriptLPS(1); 732 m_host.AddScriptLPS(1);
732 733
734 // For safety, we add another permission check here, and don't rely only on the standard OSSL permissions
733 if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID)) 735 if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
734 { 736 {
735 MainConsole.Instance.RunCommand(command); 737 MainConsole.Instance.RunCommand(command);
736 return true; 738 return true;
737 } 739 }
740
738 return false; 741 return false;
739 } 742 }
740 743
@@ -957,21 +960,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
957 UUID avatarID = (UUID)avatar; 960 UUID avatarID = (UUID)avatar;
958 961
959 m_host.AddScriptLPS(1); 962 m_host.AddScriptLPS(1);
963
964 // FIXME: What we really want to do here is factor out the similar code in llStopAnimation() to a common
965 // method (though see that doesn't do the is animation check, which is probably a bug) and have both
966 // these functions call that common code. However, this does mean navigating the brain-dead requirement
967 // of calling InitLSL()
960 if (World.Entities.ContainsKey(avatarID) && World.Entities[avatarID] is ScenePresence) 968 if (World.Entities.ContainsKey(avatarID) && World.Entities[avatarID] is ScenePresence)
961 { 969 {
962 ScenePresence target = (ScenePresence)World.Entities[avatarID]; 970 ScenePresence target = (ScenePresence)World.Entities[avatarID];
963 if (target != null) 971 if (target != null)
964 { 972 {
965 UUID animID = UUID.Zero; 973 UUID animID;
966 m_host.TaskInventory.LockItemsForRead(true); 974
967 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 975 if (!UUID.TryParse(animation, out animID))
968 { 976 {
969 if (inv.Value.Name == animation) 977 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(animation);
970 { 978 if (item != null && item.Type == (int)AssetType.Animation)
971 if (inv.Value.Type == (int)AssetType.Animation) 979 animID = item.AssetID;
972 animID = inv.Value.AssetID; 980 else
973 continue; 981 animID = UUID.Zero;
974 }
975 } 982 }
976 m_host.TaskInventory.LockItemsForRead(false); 983 m_host.TaskInventory.LockItemsForRead(false);
977 984
@@ -1178,7 +1185,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1178 CheckThreatLevel(ThreatLevel.High, "osSetStateEvents"); 1185 CheckThreatLevel(ThreatLevel.High, "osSetStateEvents");
1179 m_host.AddScriptLPS(1); 1186 m_host.AddScriptLPS(1);
1180 1187
1181 m_host.SetScriptEvents(m_itemID, events); 1188 m_host.SetScriptEvents(m_item.ItemID, events);
1182 } 1189 }
1183 1190
1184 public void osSetRegionWaterHeight(double height) 1191 public void osSetRegionWaterHeight(double height)
@@ -1186,12 +1193,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1186 CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight"); 1193 CheckThreatLevel(ThreatLevel.High, "osSetRegionWaterHeight");
1187 1194
1188 m_host.AddScriptLPS(1); 1195 m_host.AddScriptLPS(1);
1189 //Check to make sure that the script's owner is the estate manager/master 1196
1190 //World.Permissions.GenericEstatePermission( 1197 World.EventManager.TriggerRequestChangeWaterHeight((float)height);
1191 if (World.Permissions.IsGod(m_host.OwnerID))
1192 {
1193 World.EventManager.TriggerRequestChangeWaterHeight((float)height);
1194 }
1195 } 1198 }
1196 1199
1197 /// <summary> 1200 /// <summary>
@@ -1202,27 +1205,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1202 /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param> 1205 /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
1203 public void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour) 1206 public void osSetRegionSunSettings(bool useEstateSun, bool sunFixed, double sunHour)
1204 { 1207 {
1205 CheckThreatLevel(ThreatLevel.Nuisance, "osSetRegionSunSettings"); 1208 CheckThreatLevel(ThreatLevel.High, "osSetRegionSunSettings");
1206 1209
1207 m_host.AddScriptLPS(1); 1210 m_host.AddScriptLPS(1);
1208 //Check to make sure that the script's owner is the estate manager/master
1209 //World.Permissions.GenericEstatePermission(
1210 if (World.Permissions.IsGod(m_host.OwnerID))
1211 {
1212 while (sunHour > 24.0)
1213 sunHour -= 24.0;
1214 1211
1215 while (sunHour < 0) 1212 while (sunHour > 24.0)
1216 sunHour += 24.0; 1213 sunHour -= 24.0;
1217 1214
1215 while (sunHour < 0)
1216 sunHour += 24.0;
1218 1217
1219 World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun; 1218 World.RegionInfo.RegionSettings.UseEstateSun = useEstateSun;
1220 World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30 1219 World.RegionInfo.RegionSettings.SunPosition = sunHour + 6; // LL Region Sun Hour is 6 to 30
1221 World.RegionInfo.RegionSettings.FixedSun = sunFixed; 1220 World.RegionInfo.RegionSettings.FixedSun = sunFixed;
1222 World.RegionInfo.RegionSettings.Save(); 1221 World.RegionInfo.RegionSettings.Save();
1223 1222
1224 World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle, sunFixed, useEstateSun, (float)sunHour); 1223 World.EventManager.TriggerEstateToolsSunUpdate(
1225 } 1224 World.RegionInfo.RegionHandle, sunFixed, useEstateSun, (float)sunHour);
1226 } 1225 }
1227 1226
1228 /// <summary> 1227 /// <summary>
@@ -1232,26 +1231,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1232 /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param> 1231 /// <param name="sunHour">The "Sun Hour" that is desired, 0...24, with 0 just after SunRise</param>
1233 public void osSetEstateSunSettings(bool sunFixed, double sunHour) 1232 public void osSetEstateSunSettings(bool sunFixed, double sunHour)
1234 { 1233 {
1235 CheckThreatLevel(ThreatLevel.Nuisance, "osSetEstateSunSettings"); 1234 CheckThreatLevel(ThreatLevel.High, "osSetEstateSunSettings");
1236 1235
1237 m_host.AddScriptLPS(1); 1236 m_host.AddScriptLPS(1);
1238 //Check to make sure that the script's owner is the estate manager/master
1239 //World.Permissions.GenericEstatePermission(
1240 if (World.Permissions.IsGod(m_host.OwnerID))
1241 {
1242 while (sunHour > 24.0)
1243 sunHour -= 24.0;
1244 1237
1245 while (sunHour < 0) 1238 while (sunHour > 24.0)
1246 sunHour += 24.0; 1239 sunHour -= 24.0;
1247 1240
1248 World.RegionInfo.EstateSettings.UseGlobalTime = !sunFixed; 1241 while (sunHour < 0)
1249 World.RegionInfo.EstateSettings.SunPosition = sunHour; 1242 sunHour += 24.0;
1250 World.RegionInfo.EstateSettings.FixedSun = sunFixed;
1251 World.RegionInfo.EstateSettings.Save();
1252 1243
1253 World.EventManager.TriggerEstateToolsSunUpdate(World.RegionInfo.RegionHandle, sunFixed, World.RegionInfo.RegionSettings.UseEstateSun, (float)sunHour); 1244 World.RegionInfo.EstateSettings.UseGlobalTime = !sunFixed;
1254 } 1245 World.RegionInfo.EstateSettings.SunPosition = sunHour;
1246 World.RegionInfo.EstateSettings.FixedSun = sunFixed;
1247 World.RegionInfo.EstateSettings.Save();
1248
1249 World.EventManager.TriggerEstateToolsSunUpdate(
1250 World.RegionInfo.RegionHandle, sunFixed, World.RegionInfo.RegionSettings.UseEstateSun, (float)sunHour);
1255 } 1251 }
1256 1252
1257 /// <summary> 1253 /// <summary>
@@ -1627,7 +1623,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1627 1623
1628 public Object osParseJSONNew(string JSON) 1624 public Object osParseJSONNew(string JSON)
1629 { 1625 {
1630 CheckThreatLevel(ThreatLevel.None, "osParseJSON"); 1626 CheckThreatLevel(ThreatLevel.None, "osParseJSONNew");
1631 1627
1632 m_host.AddScriptLPS(1); 1628 m_host.AddScriptLPS(1);
1633 1629
@@ -1980,7 +1976,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1980 { 1976 {
1981 string retval = String.Empty; 1977 string retval = String.Empty;
1982 IConfigSource config = m_ScriptEngine.ConfigSource; 1978 IConfigSource config = m_ScriptEngine.ConfigSource;
1983 string url = config.Configs["GridInfo"].GetString("GridInfoURI", String.Empty); 1979 string url = null;
1980
1981 IConfig gridInfoConfig = config.Configs["GridInfo"];
1982
1983 if (gridInfoConfig != null)
1984 url = gridInfoConfig.GetString("GridInfoURI", String.Empty);
1984 1985
1985 if (String.IsNullOrEmpty(url)) 1986 if (String.IsNullOrEmpty(url))
1986 return "Configuration Error!"; 1987 return "Configuration Error!";
@@ -2042,8 +2043,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2042 string nick = String.Empty; 2043 string nick = String.Empty;
2043 IConfigSource config = m_ScriptEngine.ConfigSource; 2044 IConfigSource config = m_ScriptEngine.ConfigSource;
2044 2045
2045 if (config.Configs["GridInfo"] != null) 2046 if (config.Configs[GridInfoServiceConfigSectionName] != null)
2046 nick = config.Configs["GridInfo"].GetString("gridnick", nick); 2047 nick = config.Configs[GridInfoServiceConfigSectionName].GetString("gridnick", nick);
2047 2048
2048 if (String.IsNullOrEmpty(nick)) 2049 if (String.IsNullOrEmpty(nick))
2049 nick = GridUserInfo(InfoType.Nick); 2050 nick = GridUserInfo(InfoType.Nick);
@@ -2059,8 +2060,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2059 string name = String.Empty; 2060 string name = String.Empty;
2060 IConfigSource config = m_ScriptEngine.ConfigSource; 2061 IConfigSource config = m_ScriptEngine.ConfigSource;
2061 2062
2062 if (config.Configs["GridInfo"] != null) 2063 if (config.Configs[GridInfoServiceConfigSectionName] != null)
2063 name = config.Configs["GridInfo"].GetString("gridname", name); 2064 name = config.Configs[GridInfoServiceConfigSectionName].GetString("gridname", name);
2064 2065
2065 if (String.IsNullOrEmpty(name)) 2066 if (String.IsNullOrEmpty(name))
2066 name = GridUserInfo(InfoType.Name); 2067 name = GridUserInfo(InfoType.Name);
@@ -2076,8 +2077,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2076 string loginURI = String.Empty; 2077 string loginURI = String.Empty;
2077 IConfigSource config = m_ScriptEngine.ConfigSource; 2078 IConfigSource config = m_ScriptEngine.ConfigSource;
2078 2079
2079 if (config.Configs["GridInfo"] != null) 2080 if (config.Configs[GridInfoServiceConfigSectionName] != null)
2080 loginURI = config.Configs["GridInfo"].GetString("login", loginURI); 2081 loginURI = config.Configs[GridInfoServiceConfigSectionName].GetString("login", loginURI);
2081 2082
2082 if (String.IsNullOrEmpty(loginURI)) 2083 if (String.IsNullOrEmpty(loginURI))
2083 loginURI = GridUserInfo(InfoType.Login); 2084 loginURI = GridUserInfo(InfoType.Login);
@@ -2124,8 +2125,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2124 string retval = String.Empty; 2125 string retval = String.Empty;
2125 IConfigSource config = m_ScriptEngine.ConfigSource; 2126 IConfigSource config = m_ScriptEngine.ConfigSource;
2126 2127
2127 if (config.Configs["GridInfo"] != null) 2128 if (config.Configs[GridInfoServiceConfigSectionName] != null)
2128 retval = config.Configs["GridInfo"].GetString(key, retval); 2129 retval = config.Configs[GridInfoServiceConfigSectionName].GetString(key, retval);
2129 2130
2130 if (String.IsNullOrEmpty(retval)) 2131 if (String.IsNullOrEmpty(retval))
2131 retval = GridUserInfo(InfoType.Custom, key); 2132 retval = GridUserInfo(InfoType.Custom, key);
@@ -2135,7 +2136,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2135 2136
2136 public LSL_String osFormatString(string str, LSL_List strings) 2137 public LSL_String osFormatString(string str, LSL_List strings)
2137 { 2138 {
2138 CheckThreatLevel(ThreatLevel.Low, "osFormatString"); 2139 CheckThreatLevel(ThreatLevel.VeryLow, "osFormatString");
2139 m_host.AddScriptLPS(1); 2140 m_host.AddScriptLPS(1);
2140 2141
2141 return String.Format(str, strings.Data); 2142 return String.Format(str, strings.Data);
@@ -2143,7 +2144,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2143 2144
2144 public LSL_List osMatchString(string src, string pattern, int start) 2145 public LSL_List osMatchString(string src, string pattern, int start)
2145 { 2146 {
2146 CheckThreatLevel(ThreatLevel.High, "osMatchString"); 2147 CheckThreatLevel(ThreatLevel.VeryLow, "osMatchString");
2147 m_host.AddScriptLPS(1); 2148 m_host.AddScriptLPS(1);
2148 2149
2149 LSL_List result = new LSL_List(); 2150 LSL_List result = new LSL_List();
@@ -2185,7 +2186,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2185 2186
2186 public LSL_String osReplaceString(string src, string pattern, string replace, int count, int start) 2187 public LSL_String osReplaceString(string src, string pattern, string replace, int count, int start)
2187 { 2188 {
2188 CheckThreatLevel(ThreatLevel.High, "osReplaceString"); 2189 CheckThreatLevel(ThreatLevel.VeryLow, "osReplaceString");
2189 m_host.AddScriptLPS(1); 2190 m_host.AddScriptLPS(1);
2190 2191
2191 // Normalize indices (if negative). 2192 // Normalize indices (if negative).
@@ -2480,7 +2481,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2480 return; 2481 return;
2481 2482
2482 Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z); 2483 Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z);
2483 module.MoveToTarget(npcId, World, pos, false, true); 2484 module.MoveToTarget(npcId, World, pos, false, true, false);
2484 } 2485 }
2485 } 2486 }
2486 2487
@@ -2505,7 +2506,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2505 World, 2506 World,
2506 pos, 2507 pos,
2507 (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0, 2508 (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0,
2508 (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0); 2509 (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0,
2510 (options & ScriptBaseClass.OS_NPC_RUNNING) != 0);
2509 } 2511 }
2510 } 2512 }
2511 2513
@@ -2555,7 +2557,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2555 2557
2556 public void osNpcStopMoveToTarget(LSL_Key npc) 2558 public void osNpcStopMoveToTarget(LSL_Key npc)
2557 { 2559 {
2558 CheckThreatLevel(ThreatLevel.VeryLow, "osNpcStopMoveTo"); 2560 CheckThreatLevel(ThreatLevel.High, "osNpcStopMoveToTarget");
2559 m_host.AddScriptLPS(1); 2561 m_host.AddScriptLPS(1);
2560 2562
2561 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2563 INPCModule module = World.RequestModuleInterface<INPCModule>();
@@ -2572,6 +2574,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2572 2574
2573 public void osNpcSay(LSL_Key npc, string message) 2575 public void osNpcSay(LSL_Key npc, string message)
2574 { 2576 {
2577 osNpcSay(npc, 0, message);
2578 }
2579
2580 public void osNpcSay(LSL_Key npc, int channel, string message)
2581 {
2575 CheckThreatLevel(ThreatLevel.High, "osNpcSay"); 2582 CheckThreatLevel(ThreatLevel.High, "osNpcSay");
2576 m_host.AddScriptLPS(1); 2583 m_host.AddScriptLPS(1);
2577 2584
@@ -2583,7 +2590,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2583 if (!module.CheckPermissions(npcId, m_host.OwnerID)) 2590 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2584 return; 2591 return;
2585 2592
2586 module.Say(npcId, World, message); 2593 module.Say(npcId, World, message, channel);
2594 }
2595 }
2596
2597 public void osNpcShout(LSL_Key npc, int channel, string message)
2598 {
2599 CheckThreatLevel(ThreatLevel.High, "osNpcShout");
2600 m_host.AddScriptLPS(1);
2601
2602 INPCModule module = World.RequestModuleInterface<INPCModule>();
2603 if (module != null)
2604 {
2605 UUID npcId = new UUID(npc.m_string);
2606
2607 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2608 return;
2609
2610 module.Shout(npcId, World, message, channel);
2587 } 2611 }
2588 } 2612 }
2589 2613
@@ -2684,6 +2708,58 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2684 } 2708 }
2685 } 2709 }
2686 2710
2711 public void osNpcWhisper(LSL_Key npc, int channel, string message)
2712 {
2713 CheckThreatLevel(ThreatLevel.High, "osNpcWhisper");
2714 m_host.AddScriptLPS(1);
2715
2716 INPCModule module = World.RequestModuleInterface<INPCModule>();
2717 if (module != null)
2718 {
2719 UUID npcId = new UUID(npc.m_string);
2720
2721 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2722 return;
2723
2724 module.Whisper(npcId, World, message, channel);
2725 }
2726 }
2727
2728 public void osNpcTouch(LSL_Key npcLSL_Key, LSL_Key object_key, LSL_Integer link_num)
2729 {
2730 CheckThreatLevel(ThreatLevel.High, "osNpcTouch");
2731 m_host.AddScriptLPS(1);
2732 INPCModule module = World.RequestModuleInterface<INPCModule>();
2733 int linkNum = link_num.value;
2734 if (module != null || (linkNum < 0 && linkNum != ScriptBaseClass.LINK_THIS))
2735 {
2736 UUID npcId;
2737 if (!UUID.TryParse(npcLSL_Key, out npcId) || !module.CheckPermissions(npcId, m_host.OwnerID))
2738 return;
2739 SceneObjectPart part = null;
2740 UUID objectId;
2741 if (UUID.TryParse(LSL_String.ToString(object_key), out objectId))
2742 part = World.GetSceneObjectPart(objectId);
2743 if (part == null)
2744 return;
2745 if (linkNum != ScriptBaseClass.LINK_THIS)
2746 {
2747 if (linkNum == 0 || linkNum == ScriptBaseClass.LINK_ROOT)
2748 { // 0 and 1 are treated as root, find the root if the current part isnt it
2749 if (!part.IsRoot)
2750 part = part.ParentGroup.RootPart;
2751 }
2752 else
2753 { // Find the prim with the given link number if not found then fail silently
2754 part = part.ParentGroup.GetLinkNumPart(linkNum);
2755 if (part == null)
2756 return;
2757 }
2758 }
2759 module.Touch(npcId, part.UUID);
2760 }
2761 }
2762
2687 /// <summary> 2763 /// <summary>
2688 /// Save the current appearance of the script owner permanently to the named notecard. 2764 /// Save the current appearance of the script owner permanently to the named notecard.
2689 /// </summary> 2765 /// </summary>
@@ -2835,21 +2911,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2835 CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar"); 2911 CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
2836 m_host.AddScriptLPS(1); 2912 m_host.AddScriptLPS(1);
2837 2913
2838 if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID)) 2914 World.ForEachRootScenePresence(delegate(ScenePresence sp)
2839 { 2915 {
2840 World.ForEachRootScenePresence(delegate(ScenePresence sp) 2916 if (sp.Firstname == FirstName && sp.Lastname == SurName)
2841 { 2917 {
2842 if (sp.Firstname == FirstName && sp.Lastname == SurName) 2918 // kick client...
2843 { 2919 if (alert != null)
2844 // kick client... 2920 sp.ControllingClient.Kick(alert);
2845 if (alert != null)
2846 sp.ControllingClient.Kick(alert);
2847 2921
2848 // ...and close on our side 2922 // ...and close on our side
2849 sp.Scene.IncomingCloseAgent(sp.UUID); 2923 sp.Scene.IncomingCloseAgent(sp.UUID);
2850 } 2924 }
2851 }); 2925 });
2852 }
2853 } 2926 }
2854 2927
2855 public void osCauseDamage(string avatar, double damage) 2928 public void osCauseDamage(string avatar, double damage)
@@ -3095,5 +3168,151 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3095 3168
3096 return ScriptBaseClass.TRUE; 3169 return ScriptBaseClass.TRUE;
3097 } 3170 }
3171
3172 /// <summary>
3173 /// Sets terrain estate texture
3174 /// </summary>
3175 /// <param name="level"></param>
3176 /// <param name="texture"></param>
3177 /// <returns></returns>
3178 public void osSetTerrainTexture(int level, LSL_Key texture)
3179 {
3180 CheckThreatLevel(ThreatLevel.High, "osSetTerrainTexture");
3181
3182 m_host.AddScriptLPS(1);
3183 //Check to make sure that the script's owner is the estate manager/master
3184 //World.Permissions.GenericEstatePermission(
3185 if (World.Permissions.IsGod(m_host.OwnerID))
3186 {
3187 if (level < 0 || level > 3)
3188 return;
3189
3190 UUID textureID = new UUID();
3191 if (!UUID.TryParse(texture, out textureID))
3192 return;
3193
3194 // estate module is required
3195 IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
3196 if (estate != null)
3197 estate.setEstateTerrainBaseTexture(level, textureID);
3198 }
3199 }
3200
3201 /// <summary>
3202 /// Sets terrain heights of estate
3203 /// </summary>
3204 /// <param name="corner"></param>
3205 /// <param name="low"></param>
3206 /// <param name="high"></param>
3207 /// <returns></returns>
3208 public void osSetTerrainTextureHeight(int corner, double low, double high)
3209 {
3210 CheckThreatLevel(ThreatLevel.High, "osSetTerrainTextureHeight");
3211
3212 m_host.AddScriptLPS(1);
3213 //Check to make sure that the script's owner is the estate manager/master
3214 //World.Permissions.GenericEstatePermission(
3215 if (World.Permissions.IsGod(m_host.OwnerID))
3216 {
3217 if (corner < 0 || corner > 3)
3218 return;
3219
3220 // estate module is required
3221 IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
3222 if (estate != null)
3223 estate.setEstateTerrainTextureHeights(corner, (float)low, (float)high);
3224 }
3225 }
3226
3227 public void osForceAttachToAvatar(int attachmentPoint)
3228 {
3229 CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar");
3230
3231 m_host.AddScriptLPS(1);
3232
3233 InitLSL();
3234 ((LSL_Api)m_LSL_Api).AttachToAvatar(attachmentPoint);
3235 }
3236
3237 public void osForceAttachToAvatarFromInventory(string itemName, int attachmentPoint)
3238 {
3239 CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatarFromInventory");
3240
3241 m_host.AddScriptLPS(1);
3242
3243 ForceAttachToAvatarFromInventory(m_host.OwnerID, itemName, attachmentPoint);
3244 }
3245
3246 public void osForceAttachToOtherAvatarFromInventory(string rawAvatarId, string itemName, int attachmentPoint)
3247 {
3248 CheckThreatLevel(ThreatLevel.Severe, "osForceAttachToOtherAvatarFromInventory");
3249
3250 m_host.AddScriptLPS(1);
3251
3252 UUID avatarId;
3253
3254 if (!UUID.TryParse(rawAvatarId, out avatarId))
3255 return;
3256
3257 ForceAttachToAvatarFromInventory(avatarId, itemName, attachmentPoint);
3258 }
3259
3260 public void ForceAttachToAvatarFromInventory(UUID avatarId, string itemName, int attachmentPoint)
3261 {
3262 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3263
3264 if (attachmentsModule == null)
3265 return;
3266
3267 InitLSL();
3268
3269 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
3270
3271 if (item == null)
3272 {
3273 ((LSL_Api)m_LSL_Api).llSay(0, string.Format("Could not find object '{0}'", itemName));
3274 throw new Exception(String.Format("The inventory item '{0}' could not be found", itemName));
3275 }
3276
3277 if (item.InvType != (int)InventoryType.Object)
3278 {
3279 // FIXME: Temporary null check for regression tests since they dont' have the infrastructure to set
3280 // up the api reference.
3281 if (m_LSL_Api != null)
3282 ((LSL_Api)m_LSL_Api).llSay(0, string.Format("Unable to attach, item '{0}' is not an object.", itemName));
3283
3284 throw new Exception(String.Format("The inventory item '{0}' is not an object", itemName));
3285
3286 return;
3287 }
3288
3289 ScenePresence sp = World.GetScenePresence(avatarId);
3290
3291 if (sp == null)
3292 return;
3293
3294 InventoryItemBase newItem = World.MoveTaskInventoryItem(sp.UUID, UUID.Zero, m_host, item.ItemID);
3295
3296 if (newItem == null)
3297 {
3298 m_log.ErrorFormat(
3299 "[OSSL API]: Could not create user inventory item {0} for {1}, attach point {2} in {3}",
3300 itemName, m_host.Name, attachmentPoint, World.Name);
3301
3302 return;
3303 }
3304
3305 attachmentsModule.RezSingleAttachmentFromInventory(sp, newItem.ID, (uint)attachmentPoint);
3306 }
3307
3308 public void osForceDetachFromAvatar()
3309 {
3310 CheckThreatLevel(ThreatLevel.High, "osForceDetachFromAvatar");
3311
3312 m_host.AddScriptLPS(1);
3313
3314 InitLSL();
3315 ((LSL_Api)m_LSL_Api).DetachFromAvatar();
3316 }
3098 } 3317 }
3099} 3318}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
index 1373971..19f3ce1 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
@@ -308,7 +308,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
308 } 308 }
309 SceneObjectPart SensePoint = ts.host; 309 SceneObjectPart SensePoint = ts.host;
310 310
311 Vector3 fromRegionPos = SensePoint.AbsolutePosition; 311 Vector3 fromRegionPos = SensePoint.GetWorldPosition();
312 312
313 // pre define some things to avoid repeated definitions in the loop body 313 // pre define some things to avoid repeated definitions in the loop body
314 Vector3 toRegionPos; 314 Vector3 toRegionPos;
@@ -323,13 +323,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
323 Quaternion q = SensePoint.GetWorldRotation(); // non-attached prim Sensor *always* uses World rotation! 323 Quaternion q = SensePoint.GetWorldRotation(); // non-attached prim Sensor *always* uses World rotation!
324 if (SensePoint.ParentGroup.IsAttachment) 324 if (SensePoint.ParentGroup.IsAttachment)
325 { 325 {
326 // In attachments, the sensor cone always orients with the 326 // In attachments, rotate the sensor cone with the
327 // avatar rotation. This may include a nonzero elevation if 327 // avatar rotation. This may include a nonzero elevation if
328 // in mouselook. 328 // in mouselook.
329 // This will not include the rotation and position of the
330 // attachment point (e.g. your head when a sensor is in your
331 // hair attached to your scull. Your hair will turn with
332 // your head but the sensor will stay with your (global)
333 // avatar rotation and position.
334 // Position of a sensor in a child prim attached to an avatar
335 // will be still wrong.
329 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); 336 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
330 fromRegionPos = avatar.AbsolutePosition; 337 fromRegionPos = avatar.AbsolutePosition;
331 q = avatar.Rotation; 338 q = avatar.Rotation;
332 } 339 }
340
333 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); 341 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
334 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r); 342 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
335 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir); 343 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir);
@@ -441,14 +449,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
441 return sensedEntities; 449 return sensedEntities;
442 450
443 SceneObjectPart SensePoint = ts.host; 451 SceneObjectPart SensePoint = ts.host;
444 Vector3 fromRegionPos = SensePoint.AbsolutePosition; 452 Vector3 fromRegionPos = SensePoint.GetWorldPosition();
445 453
446 Quaternion q = SensePoint.RotationOffset; 454 Quaternion q = SensePoint.GetWorldRotation();
447 if (SensePoint.ParentGroup.IsAttachment) 455 if (SensePoint.ParentGroup.IsAttachment)
448 { 456 {
449 // In attachments, the sensor cone always orients with the 457 // In attachments, rotate the sensor cone with the
450 // avatar rotation. This may include a nonzero elevation if 458 // avatar rotation. This may include a nonzero elevation if
451 // in mouselook. 459 // in mouselook.
460 // This will not include the rotation and position of the
461 // attachment point (e.g. your head when a sensor is in your
462 // hair attached to your scull. Your hair will turn with
463 // your head but the sensor will stay with your (global)
464 // avatar rotation and position.
465 // Position of a sensor in a child prim attached to an avatar
466 // will be still wrong.
452 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); 467 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
453 if (avatar == null) 468 if (avatar == null)
454 return sensedEntities; 469 return sensedEntities;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
index 40ae495..af35258 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
@@ -105,6 +105,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
105 LSL_Integer llFloor(double f); 105 LSL_Integer llFloor(double f);
106 void llForceMouselook(int mouselook); 106 void llForceMouselook(int mouselook);
107 LSL_Float llFrand(double mag); 107 LSL_Float llFrand(double mag);
108 LSL_Key llGenerateKey();
108 LSL_Vector llGetAccel(); 109 LSL_Vector llGetAccel();
109 LSL_Integer llGetAgentInfo(string id); 110 LSL_Integer llGetAgentInfo(string id);
110 LSL_String llGetAgentLanguage(string id); 111 LSL_String llGetAgentLanguage(string id);
@@ -150,7 +151,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
150 LSL_Rotation llGetLocalRot(); 151 LSL_Rotation llGetLocalRot();
151 LSL_Float llGetMass(); 152 LSL_Float llGetMass();
152 LSL_Float llGetMassMKS(); 153 LSL_Float llGetMassMKS();
153 void llGetNextEmail(string address, string subject); 154 LSL_Integer llGetMemoryLimit();
155 void llGetNextEmail(string address, string subject);
154 LSL_String llGetNotecardLine(string name, int line); 156 LSL_String llGetNotecardLine(string name, int line);
155 LSL_Key llGetNumberOfNotecardLines(string name); 157 LSL_Key llGetNumberOfNotecardLines(string name);
156 LSL_Integer llGetNumberOfPrims(); 158 LSL_Integer llGetNumberOfPrims();
@@ -188,6 +190,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
188 LSL_String llGetScriptName(); 190 LSL_String llGetScriptName();
189 LSL_Integer llGetScriptState(string name); 191 LSL_Integer llGetScriptState(string name);
190 LSL_String llGetSimulatorHostname(); 192 LSL_String llGetSimulatorHostname();
193 LSL_Integer llGetSPMaxMemory();
191 LSL_Integer llGetStartParameter(); 194 LSL_Integer llGetStartParameter();
192 LSL_Integer llGetStatus(int status); 195 LSL_Integer llGetStatus(int status);
193 LSL_String llGetSubString(string src, int start, int end); 196 LSL_String llGetSubString(string src, int start, int end);
@@ -323,6 +326,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
323 void llSay(int channelID, string text); 326 void llSay(int channelID, string text);
324 void llScaleTexture(double u, double v, int face); 327 void llScaleTexture(double u, double v, int face);
325 LSL_Integer llScriptDanger(LSL_Vector pos); 328 LSL_Integer llScriptDanger(LSL_Vector pos);
329 void llScriptProfiler(LSL_Integer flag);
326 LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata); 330 LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata);
327 void llSensor(string name, string id, int type, double range, double arc); 331 void llSensor(string name, string id, int type, double range, double arc);
328 void llSensorRemove(); 332 void llSensorRemove();
@@ -347,6 +351,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
347 void llSetLinkTexture(int linknumber, string texture, int face); 351 void llSetLinkTexture(int linknumber, string texture, int face);
348 void llSetLinkTextureAnim(int linknum, int mode, int face, int sizex, int sizey, double start, double length, double rate); 352 void llSetLinkTextureAnim(int linknum, int mode, int face, int sizex, int sizey, double start, double length, double rate);
349 void llSetLocalRot(LSL_Rotation rot); 353 void llSetLocalRot(LSL_Rotation rot);
354 LSL_Integer llSetMemoryLimit(LSL_Integer limit);
350 void llSetObjectDesc(string desc); 355 void llSetObjectDesc(string desc);
351 void llSetObjectName(string name); 356 void llSetObjectName(string name);
352 void llSetObjectPermMask(int mask, int value); 357 void llSetObjectPermMask(int mask, int value);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index 444a681..1facc96 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -98,6 +98,41 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
98 void osAvatarPlayAnimation(string avatar, string animation); 98 void osAvatarPlayAnimation(string avatar, string animation);
99 void osAvatarStopAnimation(string avatar, string animation); 99 void osAvatarStopAnimation(string avatar, string animation);
100 100
101 // Attachment commands
102
103 /// <summary>
104 /// Attach the object containing this script to the avatar that owns it without asking for PERMISSION_ATTACH
105 /// </summary>
106 /// <param name='attachment'>The attachment point. For example, ATTACH_CHEST</param>
107 void osForceAttachToAvatar(int attachment);
108
109 /// <summary>
110 /// Attach an inventory item in the object containing this script to the avatar that owns it without asking for PERMISSION_ATTACH
111 /// </summary>
112 /// <remarks>
113 /// Nothing happens if the owner is not in the region.
114 /// </remarks>
115 /// <param name='itemName'>Tha name of the item. If this is not found then a warning is said to the owner</param>
116 /// <param name='attachment'>The attachment point. For example, ATTACH_CHEST</param>
117 void osForceAttachToAvatarFromInventory(string itemName, int attachment);
118
119 /// <summary>
120 /// Attach an inventory item in the object containing this script to any avatar in the region without asking for PERMISSION_ATTACH
121 /// </summary>
122 /// <remarks>
123 /// Nothing happens if the avatar is not in the region.
124 /// </remarks>
125 /// <param name='rawAvatarId'>The UUID of the avatar to which to attach. Nothing happens if this is not a UUID</para>
126 /// <param name='itemName'>The name of the item. If this is not found then a warning is said to the owner</param>
127 /// <param name='attachment'>The attachment point. For example, ATTACH_CHEST</param>
128 void osForceAttachToOtherAvatarFromInventory(string rawAvatarId, string itemName, int attachmentPoint);
129
130 /// <summary>
131 /// Detach the object containing this script from the avatar it is attached to without checking for PERMISSION_ATTACH
132 /// </summary>
133 /// <remarks>Nothing happens if the object is not attached.</remarks>
134 void osForceDetachFromAvatar();
135
101 //texture draw functions 136 //texture draw functions
102 string osMovePen(string drawList, int x, int y); 137 string osMovePen(string drawList, int x, int y);
103 string osDrawLine(string drawList, int startX, int startY, int endX, int endY); 138 string osDrawLine(string drawList, int startX, int startY, int endX, int endY);
@@ -203,11 +238,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
203 void osNpcSetRot(LSL_Key npc, rotation rot); 238 void osNpcSetRot(LSL_Key npc, rotation rot);
204 void osNpcStopMoveToTarget(LSL_Key npc); 239 void osNpcStopMoveToTarget(LSL_Key npc);
205 void osNpcSay(key npc, string message); 240 void osNpcSay(key npc, string message);
241 void osNpcSay(key npc, int channel, string message);
242 void osNpcShout(key npc, int channel, string message);
206 void osNpcSit(key npc, key target, int options); 243 void osNpcSit(key npc, key target, int options);
207 void osNpcStand(LSL_Key npc); 244 void osNpcStand(LSL_Key npc);
208 void osNpcRemove(key npc); 245 void osNpcRemove(key npc);
209 void osNpcPlayAnimation(LSL_Key npc, string animation); 246 void osNpcPlayAnimation(LSL_Key npc, string animation);
210 void osNpcStopAnimation(LSL_Key npc, string animation); 247 void osNpcStopAnimation(LSL_Key npc, string animation);
248 void osNpcTouch(LSL_Key npcLSL_Key, LSL_Key object_key, LSL_Integer link_num);
249 void osNpcWhisper(key npc, int channel, string message);
211 250
212 LSL_Key osOwnerSaveAppearance(string notecard); 251 LSL_Key osOwnerSaveAppearance(string notecard);
213 LSL_Key osAgentSaveAppearance(key agentId, string notecard); 252 LSL_Key osAgentSaveAppearance(key agentId, string notecard);
@@ -234,5 +273,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
234 273
235 LSL_Integer osInviteToGroup(LSL_Key agentId); 274 LSL_Integer osInviteToGroup(LSL_Key agentId);
236 LSL_Integer osEjectFromGroup(LSL_Key agentId); 275 LSL_Integer osEjectFromGroup(LSL_Key agentId);
276
277 void osSetTerrainTexture(int level, LSL_Key texture);
278 void osSetTerrainTextureHeight(int corner, double low, double high);
237 } 279 }
238} 280}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
index ad4f70c..a08cc42 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -383,6 +383,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
383 public const int PRIM_SCULPT_FLAG_INVERT = 64; 383 public const int PRIM_SCULPT_FLAG_INVERT = 64;
384 public const int PRIM_SCULPT_FLAG_MIRROR = 128; 384 public const int PRIM_SCULPT_FLAG_MIRROR = 128;
385 385
386 public const int PROFILE_NONE = 0;
387 public const int PROFILE_SCRIPT_MEMORY = 1;
388
386 public const int MASK_BASE = 0; 389 public const int MASK_BASE = 0;
387 public const int MASK_OWNER = 1; 390 public const int MASK_OWNER = 1;
388 public const int MASK_GROUP = 2; 391 public const int MASK_GROUP = 2;
@@ -641,6 +644,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
641 public const int OS_NPC_FLY = 0; 644 public const int OS_NPC_FLY = 0;
642 public const int OS_NPC_NO_FLY = 1; 645 public const int OS_NPC_NO_FLY = 1;
643 public const int OS_NPC_LAND_AT_TARGET = 2; 646 public const int OS_NPC_LAND_AT_TARGET = 2;
647 public const int OS_NPC_RUNNING = 4;
644 648
645 public const int OS_NPC_SIT_NOW = 0; 649 public const int OS_NPC_SIT_NOW = 0;
646 650
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
index 2f8e169..89b6eff 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
@@ -165,11 +165,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
165 m_LSL_Functions.llBreakLink(linknum); 165 m_LSL_Functions.llBreakLink(linknum);
166 } 166 }
167 167
168 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
169 {
170 return m_LSL_Functions.llCastRay(start, end, options);
171 }
172
173 public LSL_Integer llCeil(double f) 168 public LSL_Integer llCeil(double f)
174 { 169 {
175 return m_LSL_Functions.llCeil(f); 170 return m_LSL_Functions.llCeil(f);
@@ -376,6 +371,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
376 return m_LSL_Functions.llFrand(mag); 371 return m_LSL_Functions.llFrand(mag);
377 } 372 }
378 373
374 public LSL_Key llGenerateKey()
375 {
376 return m_LSL_Functions.llGenerateKey();
377 }
378
379 public LSL_Vector llGetAccel() 379 public LSL_Vector llGetAccel()
380 { 380 {
381 return m_LSL_Functions.llGetAccel(); 381 return m_LSL_Functions.llGetAccel();
@@ -591,6 +591,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
591 return m_LSL_Functions.llGetMassMKS(); 591 return m_LSL_Functions.llGetMassMKS();
592 } 592 }
593 593
594 public LSL_Integer llGetMemoryLimit()
595 {
596 return m_LSL_Functions.llGetMemoryLimit();
597 }
598
594 public void llGetNextEmail(string address, string subject) 599 public void llGetNextEmail(string address, string subject)
595 { 600 {
596 m_LSL_Functions.llGetNextEmail(address, subject); 601 m_LSL_Functions.llGetNextEmail(address, subject);
@@ -781,6 +786,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
781 return m_LSL_Functions.llGetSimulatorHostname(); 786 return m_LSL_Functions.llGetSimulatorHostname();
782 } 787 }
783 788
789 public LSL_Integer llGetSPMaxMemory()
790 {
791 return m_LSL_Functions.llGetSPMaxMemory();
792 }
793
784 public LSL_Integer llGetStartParameter() 794 public LSL_Integer llGetStartParameter()
785 { 795 {
786 return m_LSL_Functions.llGetStartParameter(); 796 return m_LSL_Functions.llGetStartParameter();
@@ -956,6 +966,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
956 return m_LSL_Functions.llRequestDisplayName(id); 966 return m_LSL_Functions.llRequestDisplayName(id);
957 } 967 }
958 968
969 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
970 {
971 return m_LSL_Functions.llCastRay(start, end, options);
972 }
973
959 public void llLinkParticleSystem(int linknum, LSL_List rules) 974 public void llLinkParticleSystem(int linknum, LSL_List rules)
960 { 975 {
961 m_LSL_Functions.llLinkParticleSystem(linknum, rules); 976 m_LSL_Functions.llLinkParticleSystem(linknum, rules);
@@ -1450,6 +1465,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1450 return m_LSL_Functions.llScriptDanger(pos); 1465 return m_LSL_Functions.llScriptDanger(pos);
1451 } 1466 }
1452 1467
1468 public void llScriptProfiler(LSL_Integer flags)
1469 {
1470 m_LSL_Functions.llScriptProfiler(flags);
1471 }
1472
1453 public LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata) 1473 public LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata)
1454 { 1474 {
1455 return m_LSL_Functions.llSendRemoteData(channel, dest, idata, sdata); 1475 return m_LSL_Functions.llSendRemoteData(channel, dest, idata, sdata);
@@ -1565,6 +1585,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1565 m_LSL_Functions.llSetLocalRot(rot); 1585 m_LSL_Functions.llSetLocalRot(rot);
1566 } 1586 }
1567 1587
1588 public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
1589 {
1590 return m_LSL_Functions.llSetMemoryLimit(limit);
1591 }
1592
1568 public void llSetObjectDesc(string desc) 1593 public void llSetObjectDesc(string desc)
1569 { 1594 {
1570 m_LSL_Functions.llSetObjectDesc(desc); 1595 m_LSL_Functions.llSetObjectDesc(desc);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 680cefb4..b40bdf0 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -289,8 +289,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
289 m_OSSL_Functions.osAvatarStopAnimation(avatar, animation); 289 m_OSSL_Functions.osAvatarStopAnimation(avatar, animation);
290 } 290 }
291 291
292 // Avatar functions
292 293
293 //Texture Draw functions 294 public void osForceAttachToAvatar(int attachmentPoint)
295 {
296 m_OSSL_Functions.osForceAttachToAvatar(attachmentPoint);
297 }
298
299 public void osForceAttachToAvatarFromInventory(string itemName, int attachmentPoint)
300 {
301 m_OSSL_Functions.osForceAttachToAvatarFromInventory(itemName, attachmentPoint);
302 }
303
304 public void osForceAttachToOtherAvatarFromInventory(string rawAvatarId, string itemName, int attachmentPoint)
305 {
306 m_OSSL_Functions.osForceAttachToOtherAvatarFromInventory(rawAvatarId, itemName, attachmentPoint);
307 }
308
309 public void osForceDetachFromAvatar()
310 {
311 m_OSSL_Functions.osForceDetachFromAvatar();
312 }
313
314 // Texture Draw functions
294 315
295 public string osMovePen(string drawList, int x, int y) 316 public string osMovePen(string drawList, int x, int y)
296 { 317 {
@@ -569,6 +590,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
569 m_OSSL_Functions.osNpcSay(npc, message); 590 m_OSSL_Functions.osNpcSay(npc, message);
570 } 591 }
571 592
593 public void osNpcSay(key npc, int channel, string message)
594 {
595 m_OSSL_Functions.osNpcSay(npc, channel, message);
596 }
597
598
599 public void osNpcShout(key npc, int channel, string message)
600 {
601 m_OSSL_Functions.osNpcShout(npc, channel, message);
602 }
603
572 public void osNpcSit(LSL_Key npc, LSL_Key target, int options) 604 public void osNpcSit(LSL_Key npc, LSL_Key target, int options)
573 { 605 {
574 m_OSSL_Functions.osNpcSit(npc, target, options); 606 m_OSSL_Functions.osNpcSit(npc, target, options);
@@ -594,6 +626,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
594 m_OSSL_Functions.osNpcStopAnimation(npc, animation); 626 m_OSSL_Functions.osNpcStopAnimation(npc, animation);
595 } 627 }
596 628
629 public void osNpcWhisper(key npc, int channel, string message)
630 {
631 m_OSSL_Functions.osNpcWhisper(npc, channel, message);
632 }
633
634 public void osNpcTouch(LSL_Key npcLSL_Key, LSL_Key object_key, LSL_Integer link_num)
635 {
636 m_OSSL_Functions.osNpcTouch(npcLSL_Key, object_key, link_num);
637 }
638
597 public LSL_Key osOwnerSaveAppearance(string notecard) 639 public LSL_Key osOwnerSaveAppearance(string notecard)
598 { 640 {
599 return m_OSSL_Functions.osOwnerSaveAppearance(notecard); 641 return m_OSSL_Functions.osOwnerSaveAppearance(notecard);
@@ -878,5 +920,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
878 { 920 {
879 return m_OSSL_Functions.osEjectFromGroup(agentId); 921 return m_OSSL_Functions.osEjectFromGroup(agentId);
880 } 922 }
923
924 public void osSetTerrainTexture(int level, LSL_Key texture)
925 {
926 m_OSSL_Functions.osSetTerrainTexture(level, texture);
927 }
928
929 public void osSetTerrainTextureHeight(int corner, double low, double high)
930 {
931 m_OSSL_Functions.osSetTerrainTextureHeight(corner, low, high);
932 }
881 } 933 }
882} 934}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 5e68d69..3797683 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -121,6 +121,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
121 121
122 public bool Running { get; set; } 122 public bool Running { get; set; }
123 123
124 public bool Run { get; set; }
125
124 public bool Suspended 126 public bool Suspended
125 { 127 {
126 get { return m_Suspended; } 128 get { return m_Suspended; }
@@ -216,6 +218,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
216 m_postOnRez = postOnRez; 218 m_postOnRez = postOnRez;
217 m_AttachedAvatar = part.ParentGroup.AttachedAvatar; 219 m_AttachedAvatar = part.ParentGroup.AttachedAvatar;
218 m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID; 220 m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID;
221 Run = true;
219 222
220 if (part != null) 223 if (part != null)
221 { 224 {
@@ -232,7 +235,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
232 foreach (string api in am.GetApis()) 235 foreach (string api in am.GetApis())
233 { 236 {
234 m_Apis[api] = am.CreateApi(api); 237 m_Apis[api] = am.CreateApi(api);
235 m_Apis[api].Initialize(engine, part, LocalID, itemID); 238 m_Apis[api].Initialize(engine, part, ScriptTask);
236 } 239 }
237 240
238 try 241 try
@@ -330,16 +333,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
330 } 333 }
331 else 334 else
332 { 335 {
333 m_log.ErrorFormat( 336 m_log.WarnFormat(
334 "[SCRIPT INSTANCE]: Unable to load script state from assembly {0}: Memory limit exceeded", 337 "[SCRIPT INSTANCE]: Unable to load script state file {0} for script {1} {2} in {3} {4} (assembly {5}). Memory limit exceeded",
335 assembly); 338 savedState, ScriptName, ItemID, PrimName, ObjectID, assembly);
336 } 339 }
337 } 340 }
338 catch (Exception e) 341 catch (Exception e)
339 { 342 {
340 m_log.ErrorFormat( 343 m_log.ErrorFormat(
341 "[SCRIPT INSTANCE]: Unable to load script state from assembly {0}. XML is {1}. Exception {2}{3}", 344 "[SCRIPT INSTANCE]: Unable to load script state file {0} for script {1} {2} in {3} {4} (assembly {5}). XML is {6}. Exception {7}{8}",
342 assembly, xml, e.Message, e.StackTrace); 345 savedState, ScriptName, ItemID, PrimName, ObjectID, assembly, xml, e.Message, e.StackTrace);
343 } 346 }
344 } 347 }
345// else 348// else
@@ -354,10 +357,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
354 357
355 public void Init() 358 public void Init()
356 { 359 {
357 if (!m_startOnInit) return; 360 if (!m_startOnInit)
361 return;
358 362
359 if (m_startedFromSavedState) 363 if (m_startedFromSavedState)
360 { 364 {
365 if (!Run)
366 return;
367
361 Start(); 368 Start();
362 if (m_postOnRez) 369 if (m_postOnRez)
363 { 370 {
@@ -390,6 +397,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
390 } 397 }
391 else 398 else
392 { 399 {
400 if (!Run)
401 return;
402
393 Start(); 403 Start();
394 PostEvent(new EventParams("state_entry", 404 PostEvent(new EventParams("state_entry",
395 new Object[0], new DetectParams[0])); 405 new Object[0], new DetectParams[0]));
@@ -966,7 +976,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
966 public IScriptApi GetApi(string name) 976 public IScriptApi GetApi(string name)
967 { 977 {
968 if (m_Apis.ContainsKey(name)) 978 if (m_Apis.ContainsKey(name))
979 {
980// m_log.DebugFormat("[SCRIPT INSTANCE]: Found api {0} in {1}@{2}", name, ScriptName, PrimName);
981
969 return m_Apis[name]; 982 return m_Apis[name];
983 }
984
985// m_log.DebugFormat("[SCRIPT INSTANCE]: Did not find api {0} in {1}@{2}", name, ScriptName, PrimName);
986
970 return null; 987 return null;
971 } 988 }
972 989
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs
index bcdc7bf..797bce3 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs
@@ -55,6 +55,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
55 public static string Serialize(ScriptInstance instance) 55 public static string Serialize(ScriptInstance instance)
56 { 56 {
57 bool running = instance.Running; 57 bool running = instance.Running;
58 bool enabled = instance.Run;
58 59
59 XmlDocument xmldoc = new XmlDocument(); 60 XmlDocument xmldoc = new XmlDocument();
60 61
@@ -77,6 +78,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
77 78
78 rootElement.AppendChild(run); 79 rootElement.AppendChild(run);
79 80
81 XmlElement run_enable = xmldoc.CreateElement("", "Run", "");
82 run_enable.AppendChild(xmldoc.CreateTextNode(
83 enabled.ToString()));
84
85 rootElement.AppendChild(run_enable);
86
80 Dictionary<string, Object> vars = instance.GetVars(); 87 Dictionary<string, Object> vars = instance.GetVars();
81 88
82 XmlElement variables = xmldoc.CreateElement("", "Variables", ""); 89 XmlElement variables = xmldoc.CreateElement("", "Variables", "");
@@ -225,6 +232,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
225 { 232 {
226 object varValue; 233 object varValue;
227 XmlNodeList partL = rootNode.ChildNodes; 234 XmlNodeList partL = rootNode.ChildNodes;
235 instance.Run = true;
228 236
229 foreach (XmlNode part in partL) 237 foreach (XmlNode part in partL)
230 { 238 {
@@ -236,6 +244,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
236 case "Running": 244 case "Running":
237 instance.Running=bool.Parse(part.InnerText); 245 instance.Running=bool.Parse(part.InnerText);
238 break; 246 break;
247 case "Run":
248 instance.Run = bool.Parse(part.InnerText);
249 break;
239 case "Variables": 250 case "Variables":
240 XmlNodeList varL = part.ChildNodes; 251 XmlNodeList varL = part.ChildNodes;
241 foreach (XmlNode var in varL) 252 foreach (XmlNode var in varL)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs
index e2d0db2..c73e22f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs
@@ -63,7 +63,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
63 IConfig config = initConfigSource.AddConfig("XEngine"); 63 IConfig config = initConfigSource.AddConfig("XEngine");
64 config.Set("Enabled", "true"); 64 config.Set("Enabled", "true");
65 65
66 m_scene = SceneHelpers.SetupScene(); 66 m_scene = new SceneHelpers().SetupScene();
67 SceneHelpers.SetupSceneModules(m_scene, initConfigSource); 67 SceneHelpers.SetupSceneModules(m_scene, initConfigSource);
68 68
69 m_engine = new XEngine.XEngine(); 69 m_engine = new XEngine.XEngine();
@@ -91,7 +91,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
91 TaskInventoryHelpers.AddSceneObject(m_scene, so1.RootPart, inventoryItemName, itemId, userId); 91 TaskInventoryHelpers.AddSceneObject(m_scene, so1.RootPart, inventoryItemName, itemId, userId);
92 92
93 LSL_Api api = new LSL_Api(); 93 LSL_Api api = new LSL_Api();
94 api.Initialize(m_engine, so1.RootPart, so1.RootPart.LocalId, so1.RootPart.UUID); 94 api.Initialize(m_engine, so1.RootPart, null);
95 95
96 // Create a second object 96 // Create a second object
97 SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, userId, "so2", 0x100); 97 SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, userId, "so2", 0x100);
@@ -124,7 +124,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
124 SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, user1Id, "so1", 0x10); 124 SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, user1Id, "so1", 0x10);
125 m_scene.AddSceneObject(so1); 125 m_scene.AddSceneObject(so1);
126 LSL_Api api = new LSL_Api(); 126 LSL_Api api = new LSL_Api();
127 api.Initialize(m_engine, so1.RootPart, so1.RootPart.LocalId, so1.RootPart.UUID); 127 api.Initialize(m_engine, so1.RootPart, null);
128 128
129 // Create an object embedded inside the first 129 // Create an object embedded inside the first
130 UUID itemId = TestHelpers.ParseTail(0x20); 130 UUID itemId = TestHelpers.ParseTail(0x20);
@@ -134,7 +134,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
134 SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, user2Id, "so2", 0x100); 134 SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, user2Id, "so2", 0x100);
135 m_scene.AddSceneObject(so2); 135 m_scene.AddSceneObject(so2);
136 LSL_Api api2 = new LSL_Api(); 136 LSL_Api api2 = new LSL_Api();
137 api2.Initialize(m_engine, so2.RootPart, so2.RootPart.LocalId, so2.RootPart.UUID); 137 api2.Initialize(m_engine, so2.RootPart, null);
138 138
139 // *** Firstly, we test where llAllowInventoryDrop() has not been called. *** 139 // *** Firstly, we test where llAllowInventoryDrop() has not been called. ***
140 api.llGiveInventory(so2.UUID.ToString(), inventoryItemName); 140 api.llGiveInventory(so2.UUID.ToString(), inventoryItemName);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs
new file mode 100644
index 0000000..2565ae7
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs
@@ -0,0 +1,142 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
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 OpenSimulator 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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Text;
32using log4net;
33using Nini.Config;
34using NUnit.Framework;
35using OpenMetaverse;
36using OpenMetaverse.Assets;
37using OpenMetaverse.StructuredData;
38using OpenSim.Framework;
39using OpenSim.Region.CoreModules.Avatar.AvatarFactory;
40using OpenSim.Region.OptionalModules.World.NPC;
41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.ScriptEngine.Shared;
43using OpenSim.Region.ScriptEngine.Shared.Api;
44using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
45using OpenSim.Services.Interfaces;
46using OpenSim.Tests.Common;
47using OpenSim.Tests.Common.Mock;
48
49namespace OpenSim.Region.ScriptEngine.Shared.Tests
50{
51 /// <summary>
52 /// Tests for linking functions in LSL
53 /// </summary>
54 /// <remarks>
55 /// This relates to LSL. Actual linking functionality should be tested in the main
56 /// OpenSim.Region.Framework.Scenes.Tests.SceneObjectLinkingTests.
57 /// </remarks>
58 [TestFixture]
59 public class LSL_ApiLinkingTests
60 {
61 protected Scene m_scene;
62 protected XEngine.XEngine m_engine;
63
64 [SetUp]
65 public void SetUp()
66 {
67 IConfigSource initConfigSource = new IniConfigSource();
68 IConfig config = initConfigSource.AddConfig("XEngine");
69 config.Set("Enabled", "true");
70
71 m_scene = new SceneHelpers().SetupScene();
72 SceneHelpers.SetupSceneModules(m_scene, initConfigSource);
73
74 m_engine = new XEngine.XEngine();
75 m_engine.Initialise(initConfigSource);
76 m_engine.AddRegion(m_scene);
77 }
78
79 [Test]
80 public void TestllCreateLink()
81 {
82 TestHelpers.InMethod();
83
84 UUID ownerId = TestHelpers.ParseTail(0x1);
85
86 SceneObjectGroup grp1 = SceneHelpers.CreateSceneObject(2, ownerId, "grp1-", 0x10);
87 grp1.AbsolutePosition = new Vector3(10, 10, 10);
88 m_scene.AddSceneObject(grp1);
89
90 // FIXME: This should really be a script item (with accompanying script)
91 TaskInventoryItem grp1Item
92 = TaskInventoryHelpers.AddNotecard(
93 m_scene, grp1.RootPart, "ncItem", TestHelpers.ParseTail(0x800), TestHelpers.ParseTail(0x900));
94 grp1Item.PermsMask |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
95
96 SceneObjectGroup grp2 = SceneHelpers.CreateSceneObject(2, ownerId, "grp2-", 0x20);
97 grp2.AbsolutePosition = new Vector3(20, 20, 20);
98
99 // <180,0,0>
100 grp2.UpdateGroupRotationR(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0));
101
102 m_scene.AddSceneObject(grp2);
103
104 LSL_Api apiGrp1 = new LSL_Api();
105 apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item);
106
107 apiGrp1.llCreateLink(grp2.UUID.ToString(), ScriptBaseClass.TRUE);
108
109 Assert.That(grp1.Parts.Length, Is.EqualTo(4));
110 Assert.That(grp2.IsDeleted, Is.True);
111 }
112
113 [Test]
114 public void TestllBreakLink()
115 {
116 TestHelpers.InMethod();
117
118 UUID ownerId = TestHelpers.ParseTail(0x1);
119
120 SceneObjectGroup grp1 = SceneHelpers.CreateSceneObject(2, ownerId, "grp1-", 0x10);
121 grp1.AbsolutePosition = new Vector3(10, 10, 10);
122 m_scene.AddSceneObject(grp1);
123
124 // FIXME: This should really be a script item (with accompanying script)
125 TaskInventoryItem grp1Item
126 = TaskInventoryHelpers.AddNotecard(
127 m_scene, grp1.RootPart, "ncItem", TestHelpers.ParseTail(0x800), TestHelpers.ParseTail(0x900));
128
129 grp1Item.PermsMask |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
130
131 LSL_Api apiGrp1 = new LSL_Api();
132 apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item);
133
134 apiGrp1.llBreakLink(2);
135
136 Assert.That(grp1.Parts.Length, Is.EqualTo(1));
137
138 SceneObjectGroup grp2 = m_scene.GetSceneObjectGroup("grp1-Part1");
139 Assert.That(grp2, Is.Not.Null);
140 }
141 }
142} \ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
index 9cf9258..c41d1e7 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
@@ -58,16 +58,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
58 IConfig config = initConfigSource.AddConfig("XEngine"); 58 IConfig config = initConfigSource.AddConfig("XEngine");
59 config.Set("Enabled", "true"); 59 config.Set("Enabled", "true");
60 60
61 Scene scene = SceneHelpers.SetupScene(); 61 Scene scene = new SceneHelpers().SetupScene();
62 SceneObjectPart part = SceneHelpers.AddSceneObject(scene); 62 SceneObjectPart part = SceneHelpers.AddSceneObject(scene).RootPart;
63 63
64 XEngine.XEngine engine = new XEngine.XEngine(); 64 XEngine.XEngine engine = new XEngine.XEngine();
65 engine.Initialise(initConfigSource); 65 engine.Initialise(initConfigSource);
66 engine.AddRegion(scene); 66 engine.AddRegion(scene);
67 67
68 m_lslApi = new LSL_Api(); 68 m_lslApi = new LSL_Api();
69 m_lslApi.Initialize(engine, part, part.LocalId, part.UUID); 69 m_lslApi.Initialize(engine, part, null);
70
71 } 70 }
72 71
73 [Test] 72 [Test]
@@ -261,7 +260,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
261 TestHelpers.InMethod(); 260 TestHelpers.InMethod();
262 261
263 // Create Prim1. 262 // Create Prim1.
264 Scene scene = SceneHelpers.SetupScene(); 263 Scene scene = new SceneHelpers().SetupScene();
265 string obj1Name = "Prim1"; 264 string obj1Name = "Prim1";
266 UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001"); 265 UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001");
267 SceneObjectPart part1 = 266 SceneObjectPart part1 =
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs
index 7573dff..c8718d9 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs
@@ -67,7 +67,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
67 config = initConfigSource.AddConfig("NPC"); 67 config = initConfigSource.AddConfig("NPC");
68 config.Set("Enabled", "true"); 68 config.Set("Enabled", "true");
69 69
70 m_scene = SceneHelpers.SetupScene(); 70 m_scene = new SceneHelpers().SetupScene();
71 SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule()); 71 SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule());
72 72
73 m_engine = new XEngine.XEngine(); 73 m_engine = new XEngine.XEngine();
@@ -79,7 +79,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
79 /// Test creation of an NPC where the appearance data comes from a notecard 79 /// Test creation of an NPC where the appearance data comes from a notecard
80 /// </summary> 80 /// </summary>
81 [Test] 81 [Test]
82 public void TestOsNpcCreateFromNotecard() 82 public void TestOsNpcCreateUsingAppearanceFromNotecard()
83 { 83 {
84 TestHelpers.InMethod(); 84 TestHelpers.InMethod();
85// log4net.Config.XmlConfigurator.Configure(); 85// log4net.Config.XmlConfigurator.Configure();
@@ -90,12 +90,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
90 90
91 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); 91 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
92 sp.Appearance.AvatarHeight = newHeight; 92 sp.Appearance.AvatarHeight = newHeight;
93 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId); 93 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
94 SceneObjectPart part = so.RootPart; 94 SceneObjectPart part = so.RootPart;
95 m_scene.AddSceneObject(so); 95 m_scene.AddSceneObject(so);
96 96
97 OSSL_Api osslApi = new OSSL_Api(); 97 OSSL_Api osslApi = new OSSL_Api();
98 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); 98 osslApi.Initialize(m_engine, part, null);
99 99
100 string notecardName = "appearanceNc"; 100 string notecardName = "appearanceNc";
101 osslApi.osOwnerSaveAppearance(notecardName); 101 osslApi.osOwnerSaveAppearance(notecardName);
@@ -114,10 +114,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
114 /// Test creation of an NPC where the appearance data comes from an avatar already in the region. 114 /// Test creation of an NPC where the appearance data comes from an avatar already in the region.
115 /// </summary> 115 /// </summary>
116 [Test] 116 [Test]
117 public void TestOsNpcCreateFromAvatar() 117 public void TestOsNpcCreateUsingAppearanceFromAvatar()
118 { 118 {
119 TestHelpers.InMethod(); 119 TestHelpers.InMethod();
120// log4net.Config.XmlConfigurator.Configure(); 120// TestHelpers.EnableLogging();
121 121
122 // Store an avatar with a different height from default in a notecard. 122 // Store an avatar with a different height from default in a notecard.
123 UUID userId = TestHelpers.ParseTail(0x1); 123 UUID userId = TestHelpers.ParseTail(0x1);
@@ -125,12 +125,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
125 125
126 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); 126 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
127 sp.Appearance.AvatarHeight = newHeight; 127 sp.Appearance.AvatarHeight = newHeight;
128 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId); 128 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
129 SceneObjectPart part = so.RootPart; 129 SceneObjectPart part = so.RootPart;
130 m_scene.AddSceneObject(so); 130 m_scene.AddSceneObject(so);
131 131
132 OSSL_Api osslApi = new OSSL_Api(); 132 OSSL_Api osslApi = new OSSL_Api();
133 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); 133 osslApi.Initialize(m_engine, part, null);
134 134
135 string notecardName = "appearanceNc"; 135 string notecardName = "appearanceNc";
136 osslApi.osOwnerSaveAppearance(notecardName); 136 osslApi.osOwnerSaveAppearance(notecardName);
@@ -156,12 +156,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
156 156
157 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); 157 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
158 sp.Appearance.AvatarHeight = newHeight; 158 sp.Appearance.AvatarHeight = newHeight;
159 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId); 159 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
160 SceneObjectPart part = so.RootPart; 160 SceneObjectPart part = so.RootPart;
161 m_scene.AddSceneObject(so); 161 m_scene.AddSceneObject(so);
162 162
163 OSSL_Api osslApi = new OSSL_Api(); 163 OSSL_Api osslApi = new OSSL_Api();
164 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); 164 osslApi.Initialize(m_engine, part, null);
165 165
166 string notecardName = "appearanceNc"; 166 string notecardName = "appearanceNc";
167 167
@@ -197,12 +197,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
197 197
198 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, nonOwnerId); 198 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, nonOwnerId);
199 sp.Appearance.AvatarHeight = newHeight; 199 sp.Appearance.AvatarHeight = newHeight;
200 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, ownerId); 200 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, ownerId, 0x10);
201 SceneObjectPart part = so.RootPart; 201 SceneObjectPart part = so.RootPart;
202 m_scene.AddSceneObject(so); 202 m_scene.AddSceneObject(so);
203 203
204 OSSL_Api osslApi = new OSSL_Api(); 204 OSSL_Api osslApi = new OSSL_Api();
205 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); 205 osslApi.Initialize(m_engine, part, null);
206 206
207 string notecardName = "appearanceNc"; 207 string notecardName = "appearanceNc";
208 208
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs
new file mode 100644
index 0000000..5ed1f3d
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs
@@ -0,0 +1,231 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
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 OpenSimulator 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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Text;
32using log4net;
33using Nini.Config;
34using NUnit.Framework;
35using OpenMetaverse;
36using OpenMetaverse.Assets;
37using OpenMetaverse.StructuredData;
38using OpenSim.Framework;
39using OpenSim.Region.CoreModules.Avatar.Attachments;
40using OpenSim.Region.CoreModules.Framework.InventoryAccess;
41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.ScriptEngine.Shared;
43using OpenSim.Region.ScriptEngine.Shared.Api;
44using OpenSim.Services.Interfaces;
45using OpenSim.Tests.Common;
46using OpenSim.Tests.Common.Mock;
47
48namespace OpenSim.Region.ScriptEngine.Shared.Tests
49{
50 /// <summary>
51 /// Tests for OSSL attachment functions
52 /// </summary>
53 /// <remarks>
54 /// TODO: Add tests for all functions
55 /// </remarks>
56 [TestFixture]
57 public class OSSL_ApiAttachmentTests : OpenSimTestCase
58 {
59 protected Scene m_scene;
60 protected XEngine.XEngine m_engine;
61
62 [SetUp]
63 public override void SetUp()
64 {
65 base.SetUp();
66
67 IConfigSource initConfigSource = new IniConfigSource();
68
69 IConfig xengineConfig = initConfigSource.AddConfig("XEngine");
70 xengineConfig.Set("Enabled", "true");
71 xengineConfig.Set("AllowOSFunctions", "true");
72 xengineConfig.Set("OSFunctionThreatLevel", "Severe");
73
74 IConfig modulesConfig = initConfigSource.AddConfig("Modules");
75 modulesConfig.Set("InventoryAccessModule", "BasicInventoryAccessModule");
76
77 m_scene = new SceneHelpers().SetupScene();
78 SceneHelpers.SetupSceneModules(
79 m_scene, initConfigSource, new AttachmentsModule(), new BasicInventoryAccessModule());
80
81 m_engine = new XEngine.XEngine();
82 m_engine.Initialise(initConfigSource);
83 m_engine.AddRegion(m_scene);
84 }
85
86 [Test]
87 public void TestOsForceAttachToAvatarFromInventory()
88 {
89 TestHelpers.InMethod();
90// TestHelpers.EnableLogging();
91
92 string taskInvObjItemName = "sphere";
93 UUID taskInvObjItemId = UUID.Parse("00000000-0000-0000-0000-100000000000");
94 AttachmentPoint attachPoint = AttachmentPoint.Chin;
95
96 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_scene, 0x1);
97 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, ua1.PrincipalID);
98 SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID);
99 TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart);
100
101 new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem);
102 OSSL_Api osslApi = new OSSL_Api();
103 osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem);
104
105// SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, ua1.PrincipalID);
106
107 // Create an object embedded inside the first
108 TaskInventoryHelpers.AddSceneObject(m_scene, inWorldObj.RootPart, taskInvObjItemName, taskInvObjItemId, ua1.PrincipalID);
109
110 osslApi.osForceAttachToAvatarFromInventory(taskInvObjItemName, (int)attachPoint);
111
112 // Check scene presence status
113 Assert.That(sp.HasAttachments(), Is.True);
114 List<SceneObjectGroup> attachments = sp.GetAttachments();
115 Assert.That(attachments.Count, Is.EqualTo(1));
116 SceneObjectGroup attSo = attachments[0];
117 Assert.That(attSo.Name, Is.EqualTo(taskInvObjItemName));
118 Assert.That(attSo.AttachmentPoint, Is.EqualTo((uint)attachPoint));
119 Assert.That(attSo.IsAttachment);
120 Assert.That(attSo.UsesPhysics, Is.False);
121 Assert.That(attSo.IsTemporary, Is.False);
122
123 // Check appearance status
124 List<AvatarAttachment> attachmentsInAppearance = sp.Appearance.GetAttachments();
125 Assert.That(attachmentsInAppearance.Count, Is.EqualTo(1));
126 Assert.That(sp.Appearance.GetAttachpoint(attachmentsInAppearance[0].ItemID), Is.EqualTo((uint)attachPoint));
127 }
128
129 /// <summary>
130 /// Make sure we can't force attach anything other than objects.
131 /// </summary>
132 [Test]
133 public void TestOsForceAttachToAvatarFromInventoryNotObject()
134 {
135 TestHelpers.InMethod();
136// TestHelpers.EnableLogging();
137
138 string taskInvObjItemName = "sphere";
139 UUID taskInvObjItemId = UUID.Parse("00000000-0000-0000-0000-100000000000");
140 AttachmentPoint attachPoint = AttachmentPoint.Chin;
141
142 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_scene, 0x1);
143 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, ua1.PrincipalID);
144 SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID);
145 TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart);
146
147 new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem);
148 OSSL_Api osslApi = new OSSL_Api();
149 osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem);
150
151 // Create an object embedded inside the first
152 TaskInventoryHelpers.AddNotecard(
153 m_scene, inWorldObj.RootPart, taskInvObjItemName, taskInvObjItemId, TestHelpers.ParseTail(0x900));
154
155 bool exceptionCaught = false;
156
157 try
158 {
159 osslApi.osForceAttachToAvatarFromInventory(taskInvObjItemName, (int)attachPoint);
160 }
161 catch (Exception)
162 {
163 exceptionCaught = true;
164 }
165
166 Assert.That(exceptionCaught, Is.True);
167
168 // Check scene presence status
169 Assert.That(sp.HasAttachments(), Is.False);
170 List<SceneObjectGroup> attachments = sp.GetAttachments();
171 Assert.That(attachments.Count, Is.EqualTo(0));
172
173 // Check appearance status
174 List<AvatarAttachment> attachmentsInAppearance = sp.Appearance.GetAttachments();
175 Assert.That(attachmentsInAppearance.Count, Is.EqualTo(0));
176 }
177
178 [Test]
179 public void TestOsForceAttachToOtherAvatarFromInventory()
180 {
181 TestHelpers.InMethod();
182// TestHelpers.EnableLogging();
183
184 string taskInvObjItemName = "sphere";
185 UUID taskInvObjItemId = UUID.Parse("00000000-0000-0000-0000-100000000000");
186 AttachmentPoint attachPoint = AttachmentPoint.Chin;
187
188 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_scene, "user", "one", 0x1, "pass");
189 UserAccount ua2 = UserAccountHelpers.CreateUserWithInventory(m_scene, "user", "two", 0x2, "pass");
190
191 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, ua1);
192 SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID);
193 TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart);
194
195 new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem);
196 OSSL_Api osslApi = new OSSL_Api();
197 osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem);
198
199 // Create an object embedded inside the first
200 TaskInventoryHelpers.AddSceneObject(m_scene, inWorldObj.RootPart, taskInvObjItemName, taskInvObjItemId, ua1.PrincipalID);
201
202 ScenePresence sp2 = SceneHelpers.AddScenePresence(m_scene, ua2);
203
204 osslApi.osForceAttachToOtherAvatarFromInventory(sp2.UUID.ToString(), taskInvObjItemName, (int)attachPoint);
205
206 // Check scene presence status
207 Assert.That(sp.HasAttachments(), Is.False);
208 List<SceneObjectGroup> attachments = sp.GetAttachments();
209 Assert.That(attachments.Count, Is.EqualTo(0));
210
211 Assert.That(sp2.HasAttachments(), Is.True);
212 List<SceneObjectGroup> attachments2 = sp2.GetAttachments();
213 Assert.That(attachments2.Count, Is.EqualTo(1));
214 SceneObjectGroup attSo = attachments2[0];
215 Assert.That(attSo.Name, Is.EqualTo(taskInvObjItemName));
216 Assert.That(attSo.OwnerID, Is.EqualTo(ua2.PrincipalID));
217 Assert.That(attSo.AttachmentPoint, Is.EqualTo((uint)attachPoint));
218 Assert.That(attSo.IsAttachment);
219 Assert.That(attSo.UsesPhysics, Is.False);
220 Assert.That(attSo.IsTemporary, Is.False);
221
222 // Check appearance status
223 List<AvatarAttachment> attachmentsInAppearance = sp.Appearance.GetAttachments();
224 Assert.That(attachmentsInAppearance.Count, Is.EqualTo(0));
225
226 List<AvatarAttachment> attachmentsInAppearance2 = sp2.Appearance.GetAttachments();
227 Assert.That(attachmentsInAppearance2.Count, Is.EqualTo(1));
228 Assert.That(sp2.Appearance.GetAttachpoint(attachmentsInAppearance2[0].ItemID), Is.EqualTo((uint)attachPoint));
229 }
230 }
231} \ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs
index 9d9fc51..25679a6 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs
@@ -52,14 +52,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
52 /// Tests for OSSL NPC API 52 /// Tests for OSSL NPC API
53 /// </summary> 53 /// </summary>
54 [TestFixture] 54 [TestFixture]
55 public class OSSL_NpcApiAppearanceTest 55 public class OSSL_NpcApiAppearanceTest : OpenSimTestCase
56 { 56 {
57 protected Scene m_scene; 57 protected Scene m_scene;
58 protected XEngine.XEngine m_engine; 58 protected XEngine.XEngine m_engine;
59 59
60 [SetUp] 60 [SetUp]
61 public void SetUp() 61 public override void SetUp()
62 { 62 {
63 base.SetUp();
64
63 IConfigSource initConfigSource = new IniConfigSource(); 65 IConfigSource initConfigSource = new IniConfigSource();
64 IConfig config = initConfigSource.AddConfig("XEngine"); 66 IConfig config = initConfigSource.AddConfig("XEngine");
65 config.Set("Enabled", "true"); 67 config.Set("Enabled", "true");
@@ -68,7 +70,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
68 config = initConfigSource.AddConfig("NPC"); 70 config = initConfigSource.AddConfig("NPC");
69 config.Set("Enabled", "true"); 71 config.Set("Enabled", "true");
70 72
71 m_scene = SceneHelpers.SetupScene(); 73 m_scene = new SceneHelpers().SetupScene();
72 SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule()); 74 SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule());
73 75
74 m_engine = new XEngine.XEngine(); 76 m_engine = new XEngine.XEngine();
@@ -95,19 +97,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
95 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); 97 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
96 sp.Appearance.AvatarHeight = newHeight; 98 sp.Appearance.AvatarHeight = newHeight;
97 99
98 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId); 100 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
99 SceneObjectPart part = so.RootPart; 101 SceneObjectPart part = so.RootPart;
100 m_scene.AddSceneObject(so); 102 m_scene.AddSceneObject(so);
101 103
102 SceneObjectGroup otherSo = SceneHelpers.CreateSceneObject(1, otherUserId); 104 SceneObjectGroup otherSo = SceneHelpers.CreateSceneObject(1, otherUserId, 0x20);
103 SceneObjectPart otherPart = otherSo.RootPart; 105 SceneObjectPart otherPart = otherSo.RootPart;
104 m_scene.AddSceneObject(otherSo); 106 m_scene.AddSceneObject(otherSo);
105 107
106 OSSL_Api osslApi = new OSSL_Api(); 108 OSSL_Api osslApi = new OSSL_Api();
107 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); 109 osslApi.Initialize(m_engine, part, null);
108 110
109 OSSL_Api otherOsslApi = new OSSL_Api(); 111 OSSL_Api otherOsslApi = new OSSL_Api();
110 otherOsslApi.Initialize(m_engine, otherPart, otherPart.LocalId, otherPart.UUID); 112 otherOsslApi.Initialize(m_engine, otherPart, null);
111 113
112 string notecardName = "appearanceNc"; 114 string notecardName = "appearanceNc";
113 osslApi.osOwnerSaveAppearance(notecardName); 115 osslApi.osOwnerSaveAppearance(notecardName);
@@ -146,12 +148,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
146 148
147 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); 149 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
148 sp.Appearance.AvatarHeight = newHeight; 150 sp.Appearance.AvatarHeight = newHeight;
149 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId); 151 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
150 SceneObjectPart part = so.RootPart; 152 SceneObjectPart part = so.RootPart;
151 m_scene.AddSceneObject(so); 153 m_scene.AddSceneObject(so);
152 154
153 OSSL_Api osslApi = new OSSL_Api(); 155 OSSL_Api osslApi = new OSSL_Api();
154 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); 156 osslApi.Initialize(m_engine, part, null);
155 157
156 string notecardName = "appearanceNc"; 158 string notecardName = "appearanceNc";
157 osslApi.osOwnerSaveAppearance(notecardName); 159 osslApi.osOwnerSaveAppearance(notecardName);
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs
index 7d7bd82..a3f848c 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs
@@ -73,7 +73,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine.Tests
73 // to AssemblyResolver.OnAssemblyResolve fails. 73 // to AssemblyResolver.OnAssemblyResolve fails.
74 xEngineConfig.Set("AppDomainLoading", "false"); 74 xEngineConfig.Set("AppDomainLoading", "false");
75 75
76 m_scene = SceneHelpers.SetupScene("My Test", UUID.Random(), 1000, 1000, null, configSource); 76 m_scene = new SceneHelpers().SetupScene("My Test", UUID.Random(), 1000, 1000, configSource);
77 SceneHelpers.SetupSceneModules(m_scene, configSource, m_xEngine, wcModule); 77 SceneHelpers.SetupSceneModules(m_scene, configSource, m_xEngine, wcModule);
78 m_scene.StartScripts(); 78 m_scene.StartScripts();
79 } 79 }
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 2a01fc4..cc783aa 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -63,6 +63,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine
63 { 63 {
64 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 64 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
65 65
66 /// <summary>
67 /// Control the printing of certain debug messages.
68 /// </summary>
69 /// <remarks>
70 /// If DebugLevel >= 1, then we log every time that a script is started.
71 /// </remarks>
72// public int DebugLevel { get; set; }
73
66 private SmartThreadPool m_ThreadPool; 74 private SmartThreadPool m_ThreadPool;
67 private int m_MaxScriptQueue; 75 private int m_MaxScriptQueue;
68 private Scene m_Scene; 76 private Scene m_Scene;
@@ -284,9 +292,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
284 AppDomain.CurrentDomain.AssemblyResolve += 292 AppDomain.CurrentDomain.AssemblyResolve +=
285 OnAssemblyResolve; 293 OnAssemblyResolve;
286 294
287 m_log.InfoFormat("[XEngine] Initializing scripts in region {0}",
288 scene.RegionInfo.RegionName);
289 m_Scene = scene; 295 m_Scene = scene;
296 m_log.InfoFormat("[XEngine]: Initializing scripts in region {0}", m_Scene.RegionInfo.RegionName);
290 297
291 m_MinThreads = m_ScriptConfig.GetInt("MinThreads", 2); 298 m_MinThreads = m_ScriptConfig.GetInt("MinThreads", 2);
292 m_MaxThreads = m_ScriptConfig.GetInt("MaxThreads", 100); 299 m_MaxThreads = m_ScriptConfig.GetInt("MaxThreads", 100);
@@ -389,9 +396,42 @@ namespace OpenSim.Region.ScriptEngine.XEngine
389 "Starts all stopped scripts." 396 "Starts all stopped scripts."
390 + "If a <script-item-uuid> is given then only that script will be started. Otherwise, all suitable scripts are started.", 397 + "If a <script-item-uuid> is given then only that script will be started. Otherwise, all suitable scripts are started.",
391 (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStartScript)); 398 (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStartScript));
399
400// MainConsole.Instance.Commands.AddCommand(
401// "Debug", false, "debug xengine", "debug xengine [<level>]",
402// "Turn on detailed xengine debugging.",
403// "If level <= 0, then no extra logging is done.\n"
404// + "If level >= 1, then we log every time that a script is started.",
405// HandleDebugLevelCommand);
392 } 406 }
393 407
394 /// <summary> 408 /// <summary>
409 /// Change debug level
410 /// </summary>
411 /// <param name="module"></param>
412 /// <param name="args"></param>
413// private void HandleDebugLevelCommand(string module, string[] args)
414// {
415// if (args.Length == 3)
416// {
417// int newDebug;
418// if (int.TryParse(args[2], out newDebug))
419// {
420// DebugLevel = newDebug;
421// MainConsole.Instance.OutputFormat("Debug level set to {0}", newDebug);
422// }
423// }
424// else if (args.Length == 2)
425// {
426// MainConsole.Instance.OutputFormat("Current debug level is {0}", DebugLevel);
427// }
428// else
429// {
430// MainConsole.Instance.Output("Usage: debug xengine 0..1");
431// }
432// }
433
434 /// <summary>
395 /// Parse the raw item id into a script instance from the command params if it's present. 435 /// Parse the raw item id into a script instance from the command params if it's present.
396 /// </summary> 436 /// </summary>
397 /// <param name="cmdparams"></param> 437 /// <param name="cmdparams"></param>
@@ -799,35 +839,66 @@ namespace OpenSim.Region.ScriptEngine.XEngine
799 int colon = firstline.IndexOf(':'); 839 int colon = firstline.IndexOf(':');
800 if (firstline.Length > 2 && firstline.Substring(0, 2) == "//" && colon != -1) 840 if (firstline.Length > 2 && firstline.Substring(0, 2) == "//" && colon != -1)
801 { 841 {
802 string engineName = firstline.Substring(2, colon-2); 842 string engineName = firstline.Substring(2, colon - 2);
803 843
804 if (names.Contains(engineName)) 844 if (names.Contains(engineName))
805 { 845 {
806 engine = engineName; 846 engine = engineName;
807 script = "//" + script.Substring(script.IndexOf(':')+1); 847 script = "//" + script.Substring(colon + 1);
808 } 848 }
809 else 849 else
810 { 850 {
811 if (engine == ScriptEngineName) 851 if (engine == ScriptEngineName)
812 { 852 {
813 SceneObjectPart part = 853 // If we are falling back on XEngine as the default engine, then only complain to the user
814 m_Scene.GetSceneObjectPart( 854 // if a script language has been explicitly set and it's one that we recognize or there are
815 localID); 855 // no non-whitespace characters after the colon.
816 856 //
817 TaskInventoryItem item = 857 // If the script is
818 part.Inventory.GetInventoryItem(itemID); 858 // explicitly not allowed or the script is not in LSL then the user will be informed by a later compiler message.
819 859 //
820 ScenePresence presence = 860 // If the colon ends the line then we'll risk the false positive as this is more likely
821 m_Scene.GetScenePresence( 861 // to signal a real scriptengine line where the user wants to use the default compile language.
822 item.OwnerID); 862 //
823 863 // This avoids the overwhelming number of false positives where we're in this code because
824 if (presence != null) 864 // there's a colon in a comment in the first line of a script for entirely
865 // unrelated reasons (e.g. vim settings).
866 //
867 // TODO: A better fix would be to deprecate simple : detection and look for some less likely
868 // string to begin the comment (like #! in unix shell scripts).
869 bool warnRunningInXEngine = false;
870 string restOfFirstLine = firstline.Substring(colon + 1);
871
872 // FIXME: These are hardcoded because they are currently hardcoded in Compiler.cs
873 if (restOfFirstLine.StartsWith("c#")
874 || restOfFirstLine.StartsWith("vb")
875 || restOfFirstLine.StartsWith("lsl")
876 || restOfFirstLine.StartsWith("js")
877 || restOfFirstLine.StartsWith("yp")
878 || restOfFirstLine.Length == 0)
879 warnRunningInXEngine = true;
880
881 if (warnRunningInXEngine)
825 { 882 {
826 presence.ControllingClient.SendAgentAlertMessage( 883 SceneObjectPart part =
827 "Selected engine unavailable. "+ 884 m_Scene.GetSceneObjectPart(
828 "Running script on "+ 885 localID);
829 ScriptEngineName, 886
830 false); 887 TaskInventoryItem item =
888 part.Inventory.GetInventoryItem(itemID);
889
890 ScenePresence presence =
891 m_Scene.GetScenePresence(
892 item.OwnerID);
893
894 if (presence != null)
895 {
896 presence.ControllingClient.SendAgentAlertMessage(
897 "Selected engine unavailable. "+
898 "Running script on "+
899 ScriptEngineName,
900 false);
901 }
831 } 902 }
832 } 903 }
833 } 904 }
@@ -884,20 +955,31 @@ namespace OpenSim.Region.ScriptEngine.XEngine
884 { 955 {
885 if (m_InitialStartup) 956 if (m_InitialStartup)
886 { 957 {
887 m_InitialStartup = false; 958 // This delay exists to stop mono problems where script compilation and startup would stop the sim
959 // working properly for the session.
888 System.Threading.Thread.Sleep(15000); 960 System.Threading.Thread.Sleep(15000);
961 }
889 962
890 if (m_CompileQueue.Count == 0) 963 object[] o;
964
965 int scriptsStarted = 0;
966
967 while (m_CompileQueue.Dequeue(out o))
968 {
969 if (DoOnRezScript(o))
891 { 970 {
892 // No scripts on region, so won't get triggered later 971 scriptsStarted++;
893 // by the queue becoming empty so we trigger it here 972
894 m_Scene.EventManager.TriggerEmptyScriptCompileQueue(0, String.Empty); 973 if (m_InitialStartup)
974 if (scriptsStarted % 50 == 0)
975 m_log.InfoFormat(
976 "[XEngine]: Started {0} scripts in {1}", scriptsStarted, m_Scene.RegionInfo.RegionName);
895 } 977 }
896 } 978 }
897 979
898 object[] o; 980 if (m_InitialStartup)
899 while (m_CompileQueue.Dequeue(out o)) 981 m_log.InfoFormat(
900 DoOnRezScript(o); 982 "[XEngine]: Completed starting {0} scripts on {1}", scriptsStarted, m_Scene.RegionInfo.RegionName);
901 983
902 // NOTE: Despite having a lockless queue, this lock is required 984 // NOTE: Despite having a lockless queue, this lock is required
903 // to make sure there is never no compile thread while there 985 // to make sure there is never no compile thread while there
@@ -905,12 +987,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine
905 // due to a race condition 987 // due to a race condition
906 // 988 //
907 lock (m_CompileQueue) 989 lock (m_CompileQueue)
908 {
909 m_CurrentCompile = null; 990 m_CurrentCompile = null;
910 } 991
911 m_Scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptFailCount, 992 m_Scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptFailCount,
912 m_ScriptErrorMessage); 993 m_ScriptErrorMessage);
994
913 m_ScriptFailCount = 0; 995 m_ScriptFailCount = 0;
996 m_InitialStartup = false;
914 997
915 return null; 998 return null;
916 } 999 }
@@ -1093,11 +1176,18 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1093 1176
1094 AppDomain sandbox; 1177 AppDomain sandbox;
1095 if (m_AppDomainLoading) 1178 if (m_AppDomainLoading)
1179 {
1096 sandbox = AppDomain.CreateDomain( 1180 sandbox = AppDomain.CreateDomain(
1097 m_Scene.RegionInfo.RegionID.ToString(), 1181 m_Scene.RegionInfo.RegionID.ToString(),
1098 evidence, appSetup); 1182 evidence, appSetup);
1183 m_AppDomains[appDomain].AssemblyResolve +=
1184 new ResolveEventHandler(
1185 AssemblyResolver.OnAssemblyResolve);
1186 }
1099 else 1187 else
1188 {
1100 sandbox = AppDomain.CurrentDomain; 1189 sandbox = AppDomain.CurrentDomain;
1190 }
1101 1191
1102 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); 1192 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel();
1103 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); 1193 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition();
@@ -1109,9 +1199,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1109 1199
1110 m_AppDomains[appDomain] = sandbox; 1200 m_AppDomains[appDomain] = sandbox;
1111 1201
1112 m_AppDomains[appDomain].AssemblyResolve +=
1113 new ResolveEventHandler(
1114 AssemblyResolver.OnAssemblyResolve);
1115 m_DomainScripts[appDomain] = new List<UUID>(); 1202 m_DomainScripts[appDomain] = new List<UUID>();
1116 } 1203 }
1117 catch (Exception e) 1204 catch (Exception e)
@@ -1396,25 +1483,24 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1396 return false; 1483 return false;
1397 1484
1398 uuids = m_PrimObjects[localID]; 1485 uuids = m_PrimObjects[localID];
1399
1400 1486
1401 foreach (UUID itemID in uuids) 1487 foreach (UUID itemID in uuids)
1402 {
1403 IScriptInstance instance = null;
1404 try
1405 { 1488 {
1406 if (m_Scripts.ContainsKey(itemID)) 1489 IScriptInstance instance = null;
1407 instance = m_Scripts[itemID]; 1490 try
1408 } 1491 {
1409 catch { /* ignore race conditions */ } 1492 if (m_Scripts.ContainsKey(itemID))
1410 1493 instance = m_Scripts[itemID];
1411 if (instance != null) 1494 }
1412 { 1495 catch { /* ignore race conditions */ }
1413 instance.PostEvent(p); 1496
1414 result = true; 1497 if (instance != null)
1498 {
1499 instance.PostEvent(p);
1500 result = true;
1501 }
1415 } 1502 }
1416 } 1503 }
1417 }
1418 1504
1419 return result; 1505 return result;
1420 } 1506 }
@@ -1539,6 +1625,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1539 } 1625 }
1540 } 1626 }
1541 1627
1628 public void SetRunEnable(UUID instanceID, bool enable)
1629 {
1630 IScriptInstance instance = GetInstance(instanceID);
1631 if (instance != null)
1632 instance.Run = enable;
1633 }
1634
1542 public bool GetScriptState(UUID itemID) 1635 public bool GetScriptState(UUID itemID)
1543 { 1636 {
1544 IScriptInstance instance = GetInstance(itemID); 1637 IScriptInstance instance = GetInstance(itemID);
@@ -1573,7 +1666,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1573 { 1666 {
1574 IScriptInstance instance = GetInstance(itemID); 1667 IScriptInstance instance = GetInstance(itemID);
1575 if (instance != null) 1668 if (instance != null)
1576 instance.Stop(0); 1669 {
1670 // Give the script some time to finish processing its last event. Simply aborting the script thread can
1671 // cause issues on mono 2.6, 2.10 and possibly later where locks are not released properly on abort.
1672 instance.Stop(1000);
1673 }
1577 } 1674 }
1578 1675
1579 public DetectParams GetDetectParams(UUID itemID, int idx) 1676 public DetectParams GetDetectParams(UUID itemID, int idx)
@@ -1749,14 +1846,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1749 FileMode.Open, FileAccess.Read)) 1846 FileMode.Open, FileAccess.Read))
1750 { 1847 {
1751 tfs.Read(tdata, 0, tdata.Length); 1848 tfs.Read(tdata, 0, tdata.Length);
1752 tfs.Close();
1753 } 1849 }
1754 1850
1755 assem = new System.Text.ASCIIEncoding().GetString(tdata); 1851 assem = new System.Text.ASCIIEncoding().GetString(tdata);
1756 } 1852 }
1757 catch (Exception e) 1853 catch (Exception e)
1758 { 1854 {
1759 m_log.DebugFormat("[XEngine]: Unable to open script textfile {0}, reason: {1}", assemName+".text", e.Message); 1855 m_log.ErrorFormat(
1856 "[XEngine]: Unable to open script textfile {0}{1}, reason: {2}",
1857 assemName, ".text", e.Message);
1760 } 1858 }
1761 } 1859 }
1762 } 1860 }
@@ -1773,16 +1871,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1773 using (FileStream fs = File.Open(assemName, FileMode.Open, FileAccess.Read)) 1871 using (FileStream fs = File.Open(assemName, FileMode.Open, FileAccess.Read))
1774 { 1872 {
1775 fs.Read(data, 0, data.Length); 1873 fs.Read(data, 0, data.Length);
1776 fs.Close();
1777 } 1874 }
1778 1875
1779 assem = System.Convert.ToBase64String(data); 1876 assem = System.Convert.ToBase64String(data);
1780 } 1877 }
1781 catch (Exception e) 1878 catch (Exception e)
1782 { 1879 {
1783 m_log.DebugFormat("[XEngine]: Unable to open script assembly {0}, reason: {1}", assemName, e.Message); 1880 m_log.ErrorFormat(
1881 "[XEngine]: Unable to open script assembly {0}, reason: {1}", assemName, e.Message);
1784 } 1882 }
1785
1786 } 1883 }
1787 } 1884 }
1788 1885
@@ -1795,9 +1892,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1795 using (StreamReader msr = new StreamReader(mfs)) 1892 using (StreamReader msr = new StreamReader(mfs))
1796 { 1893 {
1797 map = msr.ReadToEnd(); 1894 map = msr.ReadToEnd();
1798 msr.Close();
1799 } 1895 }
1800 mfs.Close();
1801 } 1896 }
1802 } 1897 }
1803 1898
@@ -1833,6 +1928,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1833 1928
1834 public bool SetXMLState(UUID itemID, string xml) 1929 public bool SetXMLState(UUID itemID, string xml)
1835 { 1930 {
1931// m_log.DebugFormat("[XEngine]: Writing state for script item with ID {0}", itemID);
1932
1836 if (xml == String.Empty) 1933 if (xml == String.Empty)
1837 return false; 1934 return false;
1838 1935
@@ -1893,31 +1990,61 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1893 { 1990 {
1894 using (FileStream fs = File.Create(path)) 1991 using (FileStream fs = File.Create(path))
1895 { 1992 {
1993// m_log.DebugFormat("[XEngine]: Writing assembly file {0}", path);
1994
1896 fs.Write(filedata, 0, filedata.Length); 1995 fs.Write(filedata, 0, filedata.Length);
1897 fs.Close();
1898 } 1996 }
1899 } 1997 }
1900 catch (IOException ex) 1998 catch (IOException ex)
1901 { 1999 {
1902 // if there already exists a file at that location, it may be locked. 2000 // if there already exists a file at that location, it may be locked.
1903 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message); 2001 m_log.ErrorFormat("[XEngine]: Error whilst writing assembly file {0}, {1}", path, ex.Message);
1904 } 2002 }
2003
2004 string textpath = path + ".text";
1905 try 2005 try
1906 { 2006 {
1907 using (FileStream fs = File.Create(path + ".text")) 2007 using (FileStream fs = File.Create(textpath))
1908 { 2008 {
1909 using (StreamWriter sw = new StreamWriter(fs)) 2009 using (StreamWriter sw = new StreamWriter(fs))
1910 { 2010 {
2011// m_log.DebugFormat("[XEngine]: Writing .text file {0}", textpath);
2012
1911 sw.Write(base64); 2013 sw.Write(base64);
1912 sw.Close();
1913 } 2014 }
1914 fs.Close();
1915 } 2015 }
1916 } 2016 }
1917 catch (IOException ex) 2017 catch (IOException ex)
1918 { 2018 {
1919 // if there already exists a file at that location, it may be locked. 2019 // if there already exists a file at that location, it may be locked.
1920 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message); 2020 m_log.ErrorFormat("[XEngine]: Error whilst writing .text file {0}, {1}", textpath, ex.Message);
2021 }
2022 }
2023
2024 XmlNodeList mapL = rootE.GetElementsByTagName("LineMap");
2025 if (mapL.Count > 0)
2026 {
2027 XmlElement mapE = (XmlElement)mapL[0];
2028
2029 string mappath = Path.Combine(m_ScriptEnginesPath, World.RegionInfo.RegionID.ToString());
2030 mappath = Path.Combine(mappath, mapE.GetAttribute("Filename"));
2031
2032 try
2033 {
2034 using (FileStream mfs = File.Create(mappath))
2035 {
2036 using (StreamWriter msw = new StreamWriter(mfs))
2037 {
2038 // m_log.DebugFormat("[XEngine]: Writing linemap file {0}", mappath);
2039
2040 msw.Write(mapE.InnerText);
2041 }
2042 }
2043 }
2044 catch (IOException ex)
2045 {
2046 // if there already exists a file at that location, it may be locked.
2047 m_log.ErrorFormat("[XEngine]: Linemap file {0} already exists! {1}", mappath, ex.Message);
1921 } 2048 }
1922 } 2049 }
1923 } 2050 }
@@ -1931,43 +2058,16 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1931 { 2058 {
1932 using (StreamWriter ssw = new StreamWriter(sfs)) 2059 using (StreamWriter ssw = new StreamWriter(sfs))
1933 { 2060 {
2061// m_log.DebugFormat("[XEngine]: Writing state file {0}", statepath);
2062
1934 ssw.Write(stateE.OuterXml); 2063 ssw.Write(stateE.OuterXml);
1935 ssw.Close();
1936 } 2064 }
1937 sfs.Close();
1938 } 2065 }
1939 } 2066 }
1940 catch (IOException ex) 2067 catch (IOException ex)
1941 { 2068 {
1942 // if there already exists a file at that location, it may be locked. 2069 // if there already exists a file at that location, it may be locked.
1943 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", statepath, ex.Message); 2070 m_log.ErrorFormat("[XEngine]: Error whilst writing state file {0}, {1}", statepath, ex.Message);
1944 }
1945
1946 XmlNodeList mapL = rootE.GetElementsByTagName("LineMap");
1947 if (mapL.Count > 0)
1948 {
1949 XmlElement mapE = (XmlElement)mapL[0];
1950
1951 string mappath = Path.Combine(m_ScriptEnginesPath, World.RegionInfo.RegionID.ToString());
1952 mappath = Path.Combine(mappath, mapE.GetAttribute("Filename"));
1953
1954 try
1955 {
1956 using (FileStream mfs = File.Create(mappath))
1957 {
1958 using (StreamWriter msw = new StreamWriter(mfs))
1959 {
1960 msw.Write(mapE.InnerText);
1961 msw.Close();
1962 }
1963 mfs.Close();
1964 }
1965 }
1966 catch (IOException ex)
1967 {
1968 // if there already exists a file at that location, it may be locked.
1969 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", statepath, ex.Message);
1970 }
1971 } 2071 }
1972 2072
1973 return true; 2073 return true;
@@ -2001,45 +2101,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine
2001 if (!topScripts.ContainsKey(si.LocalID)) 2101 if (!topScripts.ContainsKey(si.LocalID))
2002 topScripts[si.RootLocalID] = 0; 2102 topScripts[si.RootLocalID] = 0;
2003 2103
2004// long ticksElapsed = tickNow - si.MeasurementPeriodTickStart; 2104 topScripts[si.RootLocalID] += CalculateAdjustedExectionTime(si, tickNow);
2005// float framesElapsed = ticksElapsed / (18.1818 * TimeSpan.TicksPerMillisecond); 2105 }
2006 2106 }
2007 // Execution time of the script adjusted by it's measurement period to make scripts started at
2008 // different times comparable.
2009// float adjustedExecutionTime
2010// = (float)si.MeasurementPeriodExecutionTime
2011// / ((float)(tickNow - si.MeasurementPeriodTickStart) / ScriptInstance.MaxMeasurementPeriod)
2012// / TimeSpan.TicksPerMillisecond;
2013
2014 long ticksElapsed = tickNow - si.MeasurementPeriodTickStart;
2015
2016 // Avoid divide by zerp
2017 if (ticksElapsed == 0)
2018 ticksElapsed = 1;
2019 2107
2020 // Scale execution time to the ideal 55 fps frame time for these reasons. 2108 return topScripts;
2021 // 2109 }
2022 // 1) XEngine does not execute scripts per frame, unlike other script engines. Hence, there is no
2023 // 'script execution time per frame', which is the original purpose of this value.
2024 //
2025 // 2) Giving the raw execution times is misleading since scripts start at different times, making
2026 // it impossible to compare scripts.
2027 //
2028 // 3) Scaling the raw execution time to the time that the script has been running is better but
2029 // is still misleading since a script that has just been rezzed may appear to have been running
2030 // for much longer.
2031 //
2032 // 4) Hence, we scale execution time to an idealised frame time (55 fps). This is also not perfect
2033 // since the figure does not represent actual execution time and very hard running scripts will
2034 // never exceed 18ms (though this is a very high number for script execution so is a warning sign).
2035 float adjustedExecutionTime
2036 = ((float)si.MeasurementPeriodExecutionTime / ticksElapsed) * 18.1818f;
2037 2110
2038 topScripts[si.RootLocalID] += adjustedExecutionTime; 2111 public float GetScriptExecutionTime(List<UUID> itemIDs)
2112 {
2113 if (itemIDs == null|| itemIDs.Count == 0)
2114 {
2115 return 0.0f;
2116 }
2117 float time = 0.0f;
2118 long tickNow = Util.EnvironmentTickCount();
2119 IScriptInstance si;
2120 // Calculate the time for all scripts that this engine is executing
2121 // Ignore any others
2122 foreach (UUID id in itemIDs)
2123 {
2124 si = GetInstance(id);
2125 if (si != null && si.Running)
2126 {
2127 time += CalculateAdjustedExectionTime(si, tickNow);
2039 } 2128 }
2040 } 2129 }
2130 return time;
2131 }
2041 2132
2042 return topScripts; 2133 private float CalculateAdjustedExectionTime(IScriptInstance si, long tickNow)
2134 {
2135 long ticksElapsed = tickNow - si.MeasurementPeriodTickStart;
2136
2137 // Avoid divide by zero
2138 if (ticksElapsed == 0)
2139 ticksElapsed = 1;
2140
2141 // Scale execution time to the ideal 55 fps frame time for these reasons.
2142 //
2143 // 1) XEngine does not execute scripts per frame, unlike other script engines. Hence, there is no
2144 // 'script execution time per frame', which is the original purpose of this value.
2145 //
2146 // 2) Giving the raw execution times is misleading since scripts start at different times, making
2147 // it impossible to compare scripts.
2148 //
2149 // 3) Scaling the raw execution time to the time that the script has been running is better but
2150 // is still misleading since a script that has just been rezzed may appear to have been running
2151 // for much longer.
2152 //
2153 // 4) Hence, we scale execution time to an idealised frame time (55 fps). This is also not perfect
2154 // since the figure does not represent actual execution time and very hard running scripts will
2155 // never exceed 18ms (though this is a very high number for script execution so is a warning sign).
2156 return ((float)si.MeasurementPeriodExecutionTime / ticksElapsed) * 18.1818f;
2043 } 2157 }
2044 2158
2045 public void SuspendScript(UUID itemID) 2159 public void SuspendScript(UUID itemID)