aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared')
-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.cs359
-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.cs27
-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.cs44
-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.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs178
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs14
20 files changed, 1277 insertions, 971 deletions
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 0ee2748..b257cd4 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;
@@ -133,7 +138,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
133 {"TURNRIGHT", "Turning Right"} 138 {"TURNRIGHT", "Turning Right"}
134 }; 139 };
135 140
136 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) 141 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item)
137 { 142 {
138 m_ShoutSayTimer = new Timer(1000); 143 m_ShoutSayTimer = new Timer(1000);
139 m_ShoutSayTimer.Elapsed += SayShoutTimerElapsed; 144 m_ShoutSayTimer.Elapsed += SayShoutTimerElapsed;
@@ -142,10 +147,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
142 147
143 m_ScriptEngine = ScriptEngine; 148 m_ScriptEngine = ScriptEngine;
144 m_host = host; 149 m_host = host;
145 m_localID = localID; 150 m_item = item;
146 m_itemID = itemID;
147 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false); 151 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
148 152
153 LoadLimits(); // read script limits from config.
154
155 m_TransferModule =
156 m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
157 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
158
159 AsyncCommands = new AsyncCommandManager(ScriptEngine);
160 }
161
162 /* load configuration items that affect script, object and run-time behavior. */
163 private void LoadLimits()
164 {
149 m_ScriptDelayFactor = 165 m_ScriptDelayFactor =
150 m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f); 166 m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
151 m_ScriptDistanceFactor = 167 m_ScriptDistanceFactor =
@@ -158,12 +174,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
158 m_ScriptEngine.Config.GetInt("NotecardLineReadCharsMax", 255); 174 m_ScriptEngine.Config.GetInt("NotecardLineReadCharsMax", 255);
159 if (m_notecardLineReadCharsMax > 65535) 175 if (m_notecardLineReadCharsMax > 65535)
160 m_notecardLineReadCharsMax = 65535; 176 m_notecardLineReadCharsMax = 65535;
161 177 // load limits for particular subsystems.
162 m_TransferModule = 178 IConfig SMTPConfig;
163 m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>(); 179 if ((SMTPConfig = m_ScriptEngine.ConfigSource.Configs["SMTP"]) != null) {
164 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); 180 // there's an smtp config, so load in the snooze time.
165 181 EMAIL_PAUSE_TIME = SMTPConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME);
166 AsyncCommands = new AsyncCommandManager(ScriptEngine); 182 }
167 } 183 }
168 184
169 public override Object InitializeLifetimeService() 185 public override Object InitializeLifetimeService()
@@ -195,7 +211,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
195 [DebuggerNonUserCode] 211 [DebuggerNonUserCode]
196 public void state(string newState) 212 public void state(string newState)
197 { 213 {
198 m_ScriptEngine.SetState(m_itemID, newState); 214 m_ScriptEngine.SetState(m_item.ItemID, newState);
199 } 215 }
200 216
201 /// <summary> 217 /// <summary>
@@ -206,7 +222,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
206 public void llResetScript() 222 public void llResetScript()
207 { 223 {
208 m_host.AddScriptLPS(1); 224 m_host.AddScriptLPS(1);
209 m_ScriptEngine.ApiResetScript(m_itemID); 225 m_ScriptEngine.ApiResetScript(m_item.ItemID);
210 } 226 }
211 227
212 public void llResetOtherScript(string name) 228 public void llResetOtherScript(string name)
@@ -215,7 +231,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
215 231
216 m_host.AddScriptLPS(1); 232 m_host.AddScriptLPS(1);
217 233
218 if ((item = ScriptByName(name)) != UUID.Zero) 234 if ((item = GetScriptByName(name)) != UUID.Zero)
219 m_ScriptEngine.ResetScript(item); 235 m_ScriptEngine.ResetScript(item);
220 else 236 else
221 ShoutError("llResetOtherScript: script "+name+" not found"); 237 ShoutError("llResetOtherScript: script "+name+" not found");
@@ -227,7 +243,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
227 243
228 m_host.AddScriptLPS(1); 244 m_host.AddScriptLPS(1);
229 245
230 if ((item = ScriptByName(name)) != UUID.Zero) 246 if ((item = GetScriptByName(name)) != UUID.Zero)
231 { 247 {
232 return m_ScriptEngine.GetScriptState(item) ?1:0; 248 return m_ScriptEngine.GetScriptState(item) ?1:0;
233 } 249 }
@@ -249,7 +265,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
249 // These functions are supposed to be robust, 265 // These functions are supposed to be robust,
250 // so get the state one step at a time. 266 // so get the state one step at a time.
251 267
252 if ((item = ScriptByName(name)) != UUID.Zero) 268 if ((item = GetScriptByName(name)) != UUID.Zero)
253 { 269 {
254 m_ScriptEngine.SetScriptState(item, run == 0 ? false : true); 270 m_ScriptEngine.SetScriptState(item, run == 0 ? false : true);
255 } 271 }
@@ -358,77 +374,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
358 } 374 }
359 } 375 }
360 376
361 protected UUID InventorySelf()
362 {
363 UUID invItemID = new UUID();
364 bool unlock = false;
365 if (!m_host.TaskInventory.IsReadLockedByMe())
366 {
367 m_host.TaskInventory.LockItemsForRead(true);
368 unlock = true;
369 }
370 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
371 {
372 if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID)
373 {
374 invItemID = inv.Key;
375 break;
376 }
377 }
378 if (unlock)
379 {
380 m_host.TaskInventory.LockItemsForRead(false);
381 }
382 return invItemID;
383 }
384
385 protected UUID InventoryKey(string name, int type) 377 protected UUID InventoryKey(string name, int type)
386 { 378 {
387 m_host.AddScriptLPS(1); 379 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
388 m_host.TaskInventory.LockItemsForRead(true);
389
390 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
391 {
392 if (inv.Value.Name == name)
393 {
394 m_host.TaskInventory.LockItemsForRead(false);
395
396 if (inv.Value.Type != type)
397 {
398 return UUID.Zero;
399 }
400
401 return inv.Value.AssetID;
402 }
403 }
404
405 m_host.TaskInventory.LockItemsForRead(false);
406 return UUID.Zero;
407 }
408
409 protected UUID InventoryKey(string name)
410 {
411 m_host.AddScriptLPS(1);
412
413
414 m_host.TaskInventory.LockItemsForRead(true);
415
416 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
417 {
418 if (inv.Value.Name == name)
419 {
420 m_host.TaskInventory.LockItemsForRead(false);
421 return inv.Value.AssetID;
422 }
423 }
424 380
425 m_host.TaskInventory.LockItemsForRead(false); 381 if (item != null && item.Type == type)
426 382 return item.AssetID;
427 383 else
428 return UUID.Zero; 384 return UUID.Zero;
429 } 385 }
430 386
431
432 /// <summary> 387 /// <summary>
433 /// accepts a valid UUID, -or- a name of an inventory item. 388 /// accepts a valid UUID, -or- a name of an inventory item.
434 /// Returns a valid UUID or UUID.Zero if key invalid and item not found 389 /// Returns a valid UUID or UUID.Zero if key invalid and item not found
@@ -438,19 +393,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
438 /// <returns></returns> 393 /// <returns></returns>
439 protected UUID KeyOrName(string k) 394 protected UUID KeyOrName(string k)
440 { 395 {
441 UUID key = UUID.Zero; 396 UUID key;
442 397
443 // if we can parse the string as a key, use it. 398 // if we can parse the string as a key, use it.
444 if (UUID.TryParse(k, out key))
445 {
446 return key;
447 }
448 // else try to locate the name in inventory of object. found returns key, 399 // else try to locate the name in inventory of object. found returns key,
449 // not found returns UUID.Zero which will translate to the default particle texture 400 // not found returns UUID.Zero
450 else 401 if (!UUID.TryParse(k, out key))
451 { 402 {
452 return InventoryKey(k); 403 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(k);
404
405 if (item != null)
406 key = item.AssetID;
407 else
408 key = UUID.Zero;
453 } 409 }
410
411 return key;
454 } 412 }
455 413
456 // convert a LSL_Rotation to a Quaternion 414 // convert a LSL_Rotation to a Quaternion
@@ -992,7 +950,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
992 UUID.TryParse(ID, out keyID); 950 UUID.TryParse(ID, out keyID);
993 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 951 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
994 if (wComm != null) 952 if (wComm != null)
995 return wComm.Listen(m_localID, m_itemID, m_host.UUID, channelID, name, keyID, msg); 953 return wComm.Listen(m_host.LocalId, m_item.ItemID, m_host.UUID, channelID, name, keyID, msg);
996 else 954 else
997 return -1; 955 return -1;
998 } 956 }
@@ -1002,7 +960,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1002 m_host.AddScriptLPS(1); 960 m_host.AddScriptLPS(1);
1003 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 961 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
1004 if (wComm != null) 962 if (wComm != null)
1005 wComm.ListenControl(m_itemID, number, active); 963 wComm.ListenControl(m_item.ItemID, number, active);
1006 } 964 }
1007 965
1008 public void llListenRemove(int number) 966 public void llListenRemove(int number)
@@ -1010,7 +968,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1010 m_host.AddScriptLPS(1); 968 m_host.AddScriptLPS(1);
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 wComm.ListenRemove(m_itemID, number); 971 wComm.ListenRemove(m_item.ItemID, number);
1014 } 972 }
1015 973
1016 public void llSensor(string name, string id, int type, double range, double arc) 974 public void llSensor(string name, string id, int type, double range, double arc)
@@ -1019,7 +977,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1019 UUID keyID = UUID.Zero; 977 UUID keyID = UUID.Zero;
1020 UUID.TryParse(id, out keyID); 978 UUID.TryParse(id, out keyID);
1021 979
1022 AsyncCommands.SensorRepeatPlugin.SenseOnce(m_localID, m_itemID, name, keyID, type, range, arc, m_host); 980 AsyncCommands.SensorRepeatPlugin.SenseOnce(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, m_host);
1023 } 981 }
1024 982
1025 public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate) 983 public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
@@ -1028,13 +986,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1028 UUID keyID = UUID.Zero; 986 UUID keyID = UUID.Zero;
1029 UUID.TryParse(id, out keyID); 987 UUID.TryParse(id, out keyID);
1030 988
1031 AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_localID, m_itemID, name, keyID, type, range, arc, rate, m_host); 989 AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, rate, m_host);
1032 } 990 }
1033 991
1034 public void llSensorRemove() 992 public void llSensorRemove()
1035 { 993 {
1036 m_host.AddScriptLPS(1); 994 m_host.AddScriptLPS(1);
1037 AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_localID, m_itemID); 995 AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_host.LocalId, m_item.ItemID);
1038 } 996 }
1039 997
1040 public string resolveName(UUID objecUUID) 998 public string resolveName(UUID objecUUID)
@@ -1075,7 +1033,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1075 public LSL_String llDetectedName(int number) 1033 public LSL_String llDetectedName(int number)
1076 { 1034 {
1077 m_host.AddScriptLPS(1); 1035 m_host.AddScriptLPS(1);
1078 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1036 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1079 if (detectedParams == null) 1037 if (detectedParams == null)
1080 return String.Empty; 1038 return String.Empty;
1081 return detectedParams.Name; 1039 return detectedParams.Name;
@@ -1084,7 +1042,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1084 public LSL_String llDetectedKey(int number) 1042 public LSL_String llDetectedKey(int number)
1085 { 1043 {
1086 m_host.AddScriptLPS(1); 1044 m_host.AddScriptLPS(1);
1087 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1045 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1088 if (detectedParams == null) 1046 if (detectedParams == null)
1089 return String.Empty; 1047 return String.Empty;
1090 return detectedParams.Key.ToString(); 1048 return detectedParams.Key.ToString();
@@ -1093,7 +1051,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1093 public LSL_String llDetectedOwner(int number) 1051 public LSL_String llDetectedOwner(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.Owner.ToString(); 1057 return detectedParams.Owner.ToString();
@@ -1102,7 +1060,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1102 public LSL_Integer llDetectedType(int number) 1060 public LSL_Integer llDetectedType(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 0; 1065 return 0;
1108 return new LSL_Integer(detectedParams.Type); 1066 return new LSL_Integer(detectedParams.Type);
@@ -1111,7 +1069,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1111 public LSL_Vector llDetectedPos(int number) 1069 public LSL_Vector llDetectedPos(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 new LSL_Vector(); 1074 return new LSL_Vector();
1117 return detectedParams.Position; 1075 return detectedParams.Position;
@@ -1120,7 +1078,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1120 public LSL_Vector llDetectedVel(int number) 1078 public LSL_Vector llDetectedVel(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 new LSL_Vector(); 1083 return new LSL_Vector();
1126 return detectedParams.Velocity; 1084 return detectedParams.Velocity;
@@ -1129,7 +1087,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1129 public LSL_Vector llDetectedGrab(int number) 1087 public LSL_Vector llDetectedGrab(int number)
1130 { 1088 {
1131 m_host.AddScriptLPS(1); 1089 m_host.AddScriptLPS(1);
1132 DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number); 1090 DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1133 if (parms == null) 1091 if (parms == null)
1134 return new LSL_Vector(0, 0, 0); 1092 return new LSL_Vector(0, 0, 0);
1135 1093
@@ -1139,7 +1097,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1139 public LSL_Rotation llDetectedRot(int number) 1097 public LSL_Rotation llDetectedRot(int number)
1140 { 1098 {
1141 m_host.AddScriptLPS(1); 1099 m_host.AddScriptLPS(1);
1142 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1100 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1143 if (detectedParams == null) 1101 if (detectedParams == null)
1144 return new LSL_Rotation(); 1102 return new LSL_Rotation();
1145 return detectedParams.Rotation; 1103 return detectedParams.Rotation;
@@ -1148,7 +1106,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1148 public LSL_Integer llDetectedGroup(int number) 1106 public LSL_Integer llDetectedGroup(int number)
1149 { 1107 {
1150 m_host.AddScriptLPS(1); 1108 m_host.AddScriptLPS(1);
1151 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1109 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1152 if (detectedParams == null) 1110 if (detectedParams == null)
1153 return new LSL_Integer(0); 1111 return new LSL_Integer(0);
1154 if (m_host.GroupID == detectedParams.Group) 1112 if (m_host.GroupID == detectedParams.Group)
@@ -1159,7 +1117,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1159 public LSL_Integer llDetectedLinkNumber(int number) 1117 public LSL_Integer llDetectedLinkNumber(int number)
1160 { 1118 {
1161 m_host.AddScriptLPS(1); 1119 m_host.AddScriptLPS(1);
1162 DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number); 1120 DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1163 if (parms == null) 1121 if (parms == null)
1164 return new LSL_Integer(0); 1122 return new LSL_Integer(0);
1165 1123
@@ -1172,7 +1130,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1172 public LSL_Vector llDetectedTouchBinormal(int index) 1130 public LSL_Vector llDetectedTouchBinormal(int index)
1173 { 1131 {
1174 m_host.AddScriptLPS(1); 1132 m_host.AddScriptLPS(1);
1175 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1133 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1176 if (detectedParams == null) 1134 if (detectedParams == null)
1177 return new LSL_Vector(); 1135 return new LSL_Vector();
1178 return detectedParams.TouchBinormal; 1136 return detectedParams.TouchBinormal;
@@ -1184,7 +1142,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1184 public LSL_Integer llDetectedTouchFace(int index) 1142 public LSL_Integer llDetectedTouchFace(int index)
1185 { 1143 {
1186 m_host.AddScriptLPS(1); 1144 m_host.AddScriptLPS(1);
1187 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1145 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1188 if (detectedParams == null) 1146 if (detectedParams == null)
1189 return new LSL_Integer(-1); 1147 return new LSL_Integer(-1);
1190 return new LSL_Integer(detectedParams.TouchFace); 1148 return new LSL_Integer(detectedParams.TouchFace);
@@ -1196,7 +1154,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1196 public LSL_Vector llDetectedTouchNormal(int index) 1154 public LSL_Vector llDetectedTouchNormal(int index)
1197 { 1155 {
1198 m_host.AddScriptLPS(1); 1156 m_host.AddScriptLPS(1);
1199 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1157 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1200 if (detectedParams == null) 1158 if (detectedParams == null)
1201 return new LSL_Vector(); 1159 return new LSL_Vector();
1202 return detectedParams.TouchNormal; 1160 return detectedParams.TouchNormal;
@@ -1208,7 +1166,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1208 public LSL_Vector llDetectedTouchPos(int index) 1166 public LSL_Vector llDetectedTouchPos(int index)
1209 { 1167 {
1210 m_host.AddScriptLPS(1); 1168 m_host.AddScriptLPS(1);
1211 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1169 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1212 if (detectedParams == null) 1170 if (detectedParams == null)
1213 return new LSL_Vector(); 1171 return new LSL_Vector();
1214 return detectedParams.TouchPos; 1172 return detectedParams.TouchPos;
@@ -1220,7 +1178,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1220 public LSL_Vector llDetectedTouchST(int index) 1178 public LSL_Vector llDetectedTouchST(int index)
1221 { 1179 {
1222 m_host.AddScriptLPS(1); 1180 m_host.AddScriptLPS(1);
1223 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1181 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1224 if (detectedParams == null) 1182 if (detectedParams == null)
1225 return new LSL_Vector(-1.0, -1.0, 0.0); 1183 return new LSL_Vector(-1.0, -1.0, 0.0);
1226 return detectedParams.TouchST; 1184 return detectedParams.TouchST;
@@ -1232,7 +1190,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1232 public LSL_Vector llDetectedTouchUV(int index) 1190 public LSL_Vector llDetectedTouchUV(int index)
1233 { 1191 {
1234 m_host.AddScriptLPS(1); 1192 m_host.AddScriptLPS(1);
1235 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1193 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1236 if (detectedParams == null) 1194 if (detectedParams == null)
1237 return new LSL_Vector(-1.0, -1.0, 0.0); 1195 return new LSL_Vector(-1.0, -1.0, 0.0);
1238 return detectedParams.TouchUV; 1196 return detectedParams.TouchUV;
@@ -1944,6 +1902,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1944 rgb.x = texcolor.R; 1902 rgb.x = texcolor.R;
1945 rgb.y = texcolor.G; 1903 rgb.y = texcolor.G;
1946 rgb.z = texcolor.B; 1904 rgb.z = texcolor.B;
1905
1947 return rgb; 1906 return rgb;
1948 } 1907 }
1949 else 1908 else
@@ -3023,20 +2982,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3023 2982
3024 public LSL_Integer llGiveMoney(string destination, int amount) 2983 public LSL_Integer llGiveMoney(string destination, int amount)
3025 { 2984 {
3026 UUID invItemID=InventorySelf();
3027 if (invItemID == UUID.Zero)
3028 return 0;
3029
3030 m_host.AddScriptLPS(1); 2985 m_host.AddScriptLPS(1);
3031 2986
3032 m_host.TaskInventory.LockItemsForRead(true); 2987 if (m_item.PermsGranter == UUID.Zero)
3033 TaskInventoryItem item = m_host.TaskInventory[invItemID];
3034 m_host.TaskInventory.LockItemsForRead(false);
3035
3036 if (item.PermsGranter == UUID.Zero)
3037 return 0; 2988 return 0;
3038 2989
3039 if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0) 2990 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
3040 { 2991 {
3041 LSLError("No permissions to give money"); 2992 LSLError("No permissions to give money");
3042 return 0; 2993 return 0;
@@ -3099,74 +3050,72 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3099 { 3050 {
3100 m_host.AddScriptLPS(1); 3051 m_host.AddScriptLPS(1);
3101 3052
3102 Util.FireAndForget(delegate (object x) 3053 Util.FireAndForget(x =>
3103 { 3054 {
3104 if (Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s)) 3055 if (Double.IsNaN(rot.x) || Double.IsNaN(rot.y) || Double.IsNaN(rot.z) || Double.IsNaN(rot.s))
3105 return; 3056 return;
3057
3106 float dist = (float)llVecDist(llGetPos(), pos); 3058 float dist = (float)llVecDist(llGetPos(), pos);
3107 3059
3108 if (dist > m_ScriptDistanceFactor * 10.0f) 3060 if (dist > m_ScriptDistanceFactor * 10.0f)
3109 return; 3061 return;
3110 3062
3111 //Clone is thread-safe 3063 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
3112 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
3113 3064
3114 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory) 3065 if (item == null)
3115 { 3066 {
3116 if (inv.Value.Name == inventory) 3067 llSay(0, "Could not find object " + inventory);
3117 { 3068 return;
3118 // make sure we're an object. 3069 }
3119 if (inv.Value.InvType != (int)InventoryType.Object)
3120 {
3121 llSay(0, "Unable to create requested object. Object is missing from database.");
3122 return;
3123 }
3124 3070
3125 Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z); 3071 if (item.InvType != (int)InventoryType.Object)
3126 Vector3 llvel = new Vector3((float)vel.x, (float)vel.y, (float)vel.z); 3072 {
3073 llSay(0, "Unable to create requested object. Object is missing from database.");
3074 return;
3075 }
3127 3076
3128 // need the magnitude later 3077 Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
3129 // float velmag = (float)Util.GetMagnitude(llvel); 3078 Vector3 llvel = new Vector3((float)vel.x, (float)vel.y, (float)vel.z);
3130 3079
3131 SceneObjectGroup new_group = World.RezObject(m_host, inv.Value, llpos, Rot2Quaternion(rot), llvel, param); 3080 // need the magnitude later
3081 // float velmag = (float)Util.GetMagnitude(llvel);
3132 3082
3133 // If either of these are null, then there was an unknown error. 3083 SceneObjectGroup new_group = World.RezObject(m_host, item, llpos, Rot2Quaternion(rot), llvel, param);
3134 if (new_group == null)
3135 continue;
3136 3084
3137 // objects rezzed with this method are die_at_edge by default. 3085 // If either of these are null, then there was an unknown error.
3138 new_group.RootPart.SetDieAtEdge(true); 3086 if (new_group == null)
3087 return;
3139 3088
3140 new_group.ResumeScripts(); 3089 // objects rezzed with this method are die_at_edge by default.
3090 new_group.RootPart.SetDieAtEdge(true);
3141 3091
3142 m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams( 3092 new_group.ResumeScripts();
3143 "object_rez", new Object[] {
3144 new LSL_String(
3145 new_group.RootPart.UUID.ToString()) },
3146 new DetectParams[0]));
3147 3093
3148 // do recoil 3094 m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
3149 SceneObjectGroup hostgrp = m_host.ParentGroup; 3095 "object_rez", new Object[] {
3150 if (hostgrp == null) 3096 new LSL_String(
3151 return; 3097 new_group.RootPart.UUID.ToString()) },
3098 new DetectParams[0]));
3152 3099
3153 if (hostgrp.IsAttachment) // don't recoil avatars 3100 // do recoil
3154 return; 3101 SceneObjectGroup hostgrp = m_host.ParentGroup;
3102 if (hostgrp == null)
3103 return;
3155 3104
3156 PhysicsActor pa = new_group.RootPart.PhysActor; 3105 if (hostgrp.IsAttachment) // don't recoil avatars
3106 return;
3157 3107
3158 if (pa != null && pa.IsPhysical && llvel != Vector3.Zero) 3108 PhysicsActor pa = new_group.RootPart.PhysActor;
3159 { 3109
3160 float groupmass = new_group.GetMass(); 3110 if (pa != null && pa.IsPhysical && llvel != Vector3.Zero)
3161 llvel *= -groupmass; 3111 {
3162 llApplyImpulse(new LSL_Vector(llvel.X, llvel.Y,llvel.Z), 0); 3112 float groupmass = new_group.GetMass();
3163 } 3113 llvel *= -groupmass;
3164 // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay) 3114 llApplyImpulse(new LSL_Vector(llvel.X, llvel.Y,llvel.Z), 0);
3165 return;
3166 }
3167 } 3115 }
3116 // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay)
3117 return;
3168 3118
3169 llSay(0, "Could not find object " + inventory);
3170 }); 3119 });
3171 3120
3172 //ScriptSleep((int)((groupmass * velmag) / 10)); 3121 //ScriptSleep((int)((groupmass * velmag) / 10));
@@ -3230,11 +3179,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3230 sec = m_MinTimerInterval; 3179 sec = m_MinTimerInterval;
3231 m_host.AddScriptLPS(1); 3180 m_host.AddScriptLPS(1);
3232 // Setting timer repeat 3181 // Setting timer repeat
3233 AsyncCommands.TimerPlugin.SetTimerEvent(m_localID, m_itemID, sec); 3182 AsyncCommands.TimerPlugin.SetTimerEvent(m_host.LocalId, m_item.ItemID, sec);
3234 } 3183 }
3235 3184
3236 public virtual void llSleep(double sec) 3185 public virtual void llSleep(double sec)
3237 { 3186 {
3187// m_log.Info("llSleep snoozing " + sec + "s.");
3238 m_host.AddScriptLPS(1); 3188 m_host.AddScriptLPS(1);
3239 Thread.Sleep((int)(sec * 1000)); 3189 Thread.Sleep((int)(sec * 1000));
3240 } 3190 }
@@ -3293,29 +3243,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3293 3243
3294 public void llTakeControls(int controls, int accept, int pass_on) 3244 public void llTakeControls(int controls, int accept, int pass_on)
3295 { 3245 {
3296 TaskInventoryItem item; 3246 if (m_item.PermsGranter != UUID.Zero)
3297
3298 m_host.TaskInventory.LockItemsForRead(true);
3299 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3300 {
3301 m_host.TaskInventory.LockItemsForRead(false);
3302 return;
3303 }
3304 else
3305 {
3306 item = m_host.TaskInventory[InventorySelf()];
3307 }
3308 m_host.TaskInventory.LockItemsForRead(false);
3309
3310 if (item.PermsGranter != UUID.Zero)
3311 { 3247 {
3312 ScenePresence presence = World.GetScenePresence(item.PermsGranter); 3248 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3313 3249
3314 if (presence != null) 3250 if (presence != null)
3315 { 3251 {
3316 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 3252 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
3317 { 3253 {
3318 presence.RegisterControlEventsToScript(controls, accept, pass_on, m_localID, m_itemID); 3254 presence.RegisterControlEventsToScript(controls, accept, pass_on, m_host.LocalId, m_item.ItemID);
3319 } 3255 }
3320 } 3256 }
3321 } 3257 }
@@ -3325,38 +3261,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3325 3261
3326 public void llReleaseControls() 3262 public void llReleaseControls()
3327 { 3263 {
3328 TaskInventoryItem item;
3329
3330 m_host.TaskInventory.LockItemsForRead(true);
3331 lock (m_host.TaskInventory)
3332 {
3333
3334 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3335 {
3336 m_host.TaskInventory.LockItemsForRead(false);
3337 return;
3338 }
3339 else
3340 {
3341 item = m_host.TaskInventory[InventorySelf()];
3342 }
3343 }
3344 m_host.TaskInventory.LockItemsForRead(false);
3345
3346 m_host.AddScriptLPS(1); 3264 m_host.AddScriptLPS(1);
3347 3265
3348 if (item.PermsGranter != UUID.Zero) 3266 if (m_item.PermsGranter != UUID.Zero)
3349 { 3267 {
3350 ScenePresence presence = World.GetScenePresence(item.PermsGranter); 3268 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3351 3269
3352 if (presence != null) 3270 if (presence != null)
3353 { 3271 {
3354 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 3272 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
3355 { 3273 {
3356 // Unregister controls from Presence 3274 // Unregister controls from Presence
3357 presence.UnRegisterControlEventsToScript(m_localID, m_itemID); 3275 presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
3358 // Remove Take Control permission. 3276 // Remove Take Control permission.
3359 item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS; 3277 m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
3360 } 3278 }
3361 } 3279 }
3362 } 3280 }
@@ -3369,39 +3287,54 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3369 m_UrlModule.ReleaseURL(url); 3287 m_UrlModule.ReleaseURL(url);
3370 } 3288 }
3371 3289
3372 public void llAttachToAvatar(int attachment) 3290 /// <summary>
3291 /// Attach the object containing this script to the avatar that owns it.
3292 /// </summary>
3293 /// <param name='attachment'>The attachment point (e.g. ATTACH_CHEST)</param>
3294 /// <returns>true if the attach suceeded, false if it did not</returns>
3295 public bool AttachToAvatar(int attachmentPoint)
3373 { 3296 {
3374 m_host.AddScriptLPS(1); 3297 SceneObjectGroup grp = m_host.ParentGroup;
3298 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
3375 3299
3376 TaskInventoryItem item; 3300 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3377
3378 m_host.TaskInventory.LockItemsForRead(true);
3379 3301
3380 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3302 if (attachmentsModule != null)
3381 { 3303 return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true);
3382 m_host.TaskInventory.LockItemsForRead(false);
3383 return;
3384 }
3385 else 3304 else
3305 return false;
3306 }
3307
3308 /// <summary>
3309 /// Detach the object containing this script from the avatar it is attached to.
3310 /// </summary>
3311 /// <remarks>
3312 /// Nothing happens if the object is not attached.
3313 /// </remarks>
3314 public void DetachFromAvatar()
3315 {
3316 Util.FireAndForget(DetachWrapper, m_host);
3317 }
3318
3319 private void DetachWrapper(object o)
3320 {
3321 if (World.AttachmentsModule != null)
3386 { 3322 {
3387 item = m_host.TaskInventory[InventorySelf()]; 3323 SceneObjectPart host = (SceneObjectPart)o;
3324 ScenePresence presence = World.GetScenePresence(host.OwnerID);
3325 World.AttachmentsModule.DetachSingleAttachmentToInv(presence, host.ParentGroup);
3388 } 3326 }
3327 }
3389 3328
3390 m_host.TaskInventory.LockItemsForRead(false); 3329 public void llAttachToAvatar(int attachmentPoint)
3330 {
3331 m_host.AddScriptLPS(1);
3391 3332
3392 if (item.PermsGranter != m_host.OwnerID) 3333 if (m_item.PermsGranter != m_host.OwnerID)
3393 return; 3334 return;
3394 3335
3395 if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0) 3336 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
3396 { 3337 AttachToAvatar(attachmentPoint);
3397 SceneObjectGroup grp = m_host.ParentGroup;
3398
3399 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
3400
3401 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3402 if (attachmentsModule != null)
3403 attachmentsModule.AttachObject(presence, grp, (uint)attachment, false, true);
3404 }
3405 } 3338 }
3406 3339
3407 public void llDetachFromAvatar() 3340 public void llDetachFromAvatar()
@@ -3411,44 +3344,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3411 if (m_host.ParentGroup.AttachmentPoint == 0) 3344 if (m_host.ParentGroup.AttachmentPoint == 0)
3412 return; 3345 return;
3413 3346
3414 TaskInventoryItem item; 3347 if (m_item.PermsGranter != m_host.OwnerID)
3415
3416 m_host.TaskInventory.LockItemsForRead(true);
3417
3418 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3419 {
3420 m_host.TaskInventory.LockItemsForRead(false);
3421 return; 3348 return;
3422 }
3423 else
3424 {
3425 item = m_host.TaskInventory[InventorySelf()];
3426 }
3427 m_host.TaskInventory.LockItemsForRead(false);
3428
3429
3430 if (item.PermsGranter != m_host.OwnerID)
3431 return;
3432
3433 if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
3434 {
3435 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3436 if (attachmentsModule != null)
3437 Util.FireAndForget(DetachWrapper, m_host);
3438 }
3439 }
3440 3349
3441 private void DetachWrapper(object o) 3350 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
3442 { 3351 DetachFromAvatar();
3443 SceneObjectPart host = (SceneObjectPart)o;
3444
3445 SceneObjectGroup grp = host.ParentGroup;
3446 UUID itemID = grp.FromItemID;
3447 ScenePresence presence = World.GetScenePresence(host.OwnerID);
3448
3449 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3450 if (attachmentsModule != null)
3451 attachmentsModule.DetachSingleAttachmentToInv(presence, itemID);
3452 } 3352 }
3453 3353
3454 public void llTakeCamera(string avatar) 3354 public void llTakeCamera(string avatar)
@@ -3569,7 +3469,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3569 } 3469 }
3570 3470
3571 emailModule.SendEmail(m_host.UUID, address, subject, message); 3471 emailModule.SendEmail(m_host.UUID, address, subject, message);
3572 ScriptSleep(15000); 3472 ScriptSleep(EMAIL_PAUSE_TIME * 1000);
3573 } 3473 }
3574 3474
3575 public void llGetNextEmail(string address, string subject) 3475 public void llGetNextEmail(string address, string subject)
@@ -3606,6 +3506,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3606 return m_host.UUID.ToString(); 3506 return m_host.UUID.ToString();
3607 } 3507 }
3608 3508
3509 public LSL_Key llGenerateKey()
3510 {
3511 m_host.AddScriptLPS(1);
3512 return UUID.Random().ToString();
3513 }
3514
3609 public void llSetBuoyancy(double buoyancy) 3515 public void llSetBuoyancy(double buoyancy)
3610 { 3516 {
3611 m_host.AddScriptLPS(1); 3517 m_host.AddScriptLPS(1);
@@ -3652,7 +3558,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3652 m_host.AddScriptLPS(1); 3558 m_host.AddScriptLPS(1);
3653 try 3559 try
3654 { 3560 {
3655 m_ScriptEngine.SetMinEventDelay(m_itemID, delay); 3561 m_ScriptEngine.SetMinEventDelay(m_item.ItemID, delay);
3656 } 3562 }
3657 catch (NotImplementedException) 3563 catch (NotImplementedException)
3658 { 3564 {
@@ -3705,29 +3611,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3705 { 3611 {
3706 m_host.AddScriptLPS(1); 3612 m_host.AddScriptLPS(1);
3707 3613
3708 UUID invItemID = InventorySelf(); 3614 if (m_item.PermsGranter == UUID.Zero)
3709 if (invItemID == UUID.Zero)
3710 return; 3615 return;
3711 3616
3712 TaskInventoryItem item; 3617 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3713
3714 m_host.TaskInventory.LockItemsForRead(true);
3715 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3716 {
3717 m_host.TaskInventory.LockItemsForRead(false);
3718 return;
3719 }
3720 else
3721 { 3618 {
3722 item = m_host.TaskInventory[InventorySelf()]; 3619 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3723 }
3724 m_host.TaskInventory.LockItemsForRead(false);
3725 if (item.PermsGranter == UUID.Zero)
3726 return;
3727
3728 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3729 {
3730 ScenePresence presence = World.GetScenePresence(item.PermsGranter);
3731 3620
3732 if (presence != null) 3621 if (presence != null)
3733 { 3622 {
@@ -3745,41 +3634,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3745 { 3634 {
3746 m_host.AddScriptLPS(1); 3635 m_host.AddScriptLPS(1);
3747 3636
3748 UUID invItemID=InventorySelf(); 3637 if (m_item.PermsGranter == UUID.Zero)
3749 if (invItemID == UUID.Zero)
3750 return;
3751
3752 TaskInventoryItem item;
3753
3754 m_host.TaskInventory.LockItemsForRead(true);
3755 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3756 {
3757 m_host.TaskInventory.LockItemsForRead(false);
3758 return;
3759 }
3760 else
3761 {
3762 item = m_host.TaskInventory[InventorySelf()];
3763 }
3764 m_host.TaskInventory.LockItemsForRead(false);
3765
3766
3767 if (item.PermsGranter == UUID.Zero)
3768 return; 3638 return;
3769 3639
3770 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0) 3640 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3771 { 3641 {
3772 UUID animID = new UUID(); 3642 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3773
3774 if (!UUID.TryParse(anim, out animID))
3775 {
3776 animID=InventoryKey(anim);
3777 }
3778
3779 ScenePresence presence = World.GetScenePresence(item.PermsGranter);
3780 3643
3781 if (presence != null) 3644 if (presence != null)
3782 { 3645 {
3646 UUID animID = KeyOrName(anim);
3647
3783 if (animID == UUID.Zero) 3648 if (animID == UUID.Zero)
3784 presence.Animator.RemoveAnimation(anim); 3649 presence.Animator.RemoveAnimation(anim);
3785 else 3650 else
@@ -3812,44 +3677,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3812 public LSL_Integer llGetStartParameter() 3677 public LSL_Integer llGetStartParameter()
3813 { 3678 {
3814 m_host.AddScriptLPS(1); 3679 m_host.AddScriptLPS(1);
3815 return m_ScriptEngine.GetStartParameter(m_itemID); 3680 return m_ScriptEngine.GetStartParameter(m_item.ItemID);
3816 } 3681 }
3817 3682
3818 public void llRequestPermissions(string agent, int perm) 3683 public void llRequestPermissions(string agent, int perm)
3819 { 3684 {
3820 UUID agentID = new UUID(); 3685 UUID agentID;
3821 3686
3822 if (!UUID.TryParse(agent, out agentID)) 3687 if (!UUID.TryParse(agent, out agentID))
3823 return; 3688 return;
3824 3689
3825 UUID invItemID = InventorySelf();
3826
3827 if (invItemID == UUID.Zero)
3828 return; // Not in a prim? How??
3829
3830 TaskInventoryItem item;
3831
3832
3833 m_host.TaskInventory.LockItemsForRead(true);
3834 if (!m_host.TaskInventory.ContainsKey(invItemID))
3835 {
3836 m_host.TaskInventory.LockItemsForRead(false);
3837 return;
3838 }
3839 else
3840 {
3841 item = m_host.TaskInventory[invItemID];
3842 }
3843 m_host.TaskInventory.LockItemsForRead(false);
3844
3845 if (agentID == UUID.Zero || perm == 0) // Releasing permissions 3690 if (agentID == UUID.Zero || perm == 0) // Releasing permissions
3846 { 3691 {
3847 llReleaseControls(); 3692 llReleaseControls();
3848 3693
3849 item.PermsGranter = UUID.Zero; 3694 m_item.PermsGranter = UUID.Zero;
3850 item.PermsMask = 0; 3695 m_item.PermsMask = 0;
3851 3696
3852 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3697 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3853 "run_time_permissions", new Object[] { 3698 "run_time_permissions", new Object[] {
3854 new LSL_Integer(0) }, 3699 new LSL_Integer(0) },
3855 new DetectParams[0])); 3700 new DetectParams[0]));
@@ -3857,7 +3702,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3857 return; 3702 return;
3858 } 3703 }
3859 3704
3860 if (item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3705 if (m_item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3861 llReleaseControls(); 3706 llReleaseControls();
3862 3707
3863 m_host.AddScriptLPS(1); 3708 m_host.AddScriptLPS(1);
@@ -3874,11 +3719,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3874 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3719 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3875 { 3720 {
3876 m_host.TaskInventory.LockItemsForWrite(true); 3721 m_host.TaskInventory.LockItemsForWrite(true);
3877 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3722 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3878 m_host.TaskInventory[invItemID].PermsMask = perm; 3723 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3879 m_host.TaskInventory.LockItemsForWrite(false); 3724 m_host.TaskInventory.LockItemsForWrite(false);
3880 3725
3881 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3726 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3882 "run_time_permissions", new Object[] { 3727 "run_time_permissions", new Object[] {
3883 new LSL_Integer(perm) }, 3728 new LSL_Integer(perm) },
3884 new DetectParams[0])); 3729 new DetectParams[0]));
@@ -3913,11 +3758,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3913 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3758 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3914 { 3759 {
3915 m_host.TaskInventory.LockItemsForWrite(true); 3760 m_host.TaskInventory.LockItemsForWrite(true);
3916 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3761 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3917 m_host.TaskInventory[invItemID].PermsMask = perm; 3762 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3918 m_host.TaskInventory.LockItemsForWrite(false); 3763 m_host.TaskInventory.LockItemsForWrite(false);
3919 3764
3920 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3765 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3921 "run_time_permissions", new Object[] { 3766 "run_time_permissions", new Object[] {
3922 new LSL_Integer(perm) }, 3767 new LSL_Integer(perm) },
3923 new DetectParams[0])); 3768 new DetectParams[0]));
@@ -3928,9 +3773,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3928 } 3773 }
3929 3774
3930 ScenePresence presence = World.GetScenePresence(agentID); 3775 ScenePresence presence = World.GetScenePresence(agentID);
3931
3932 if (presence != null) 3776 if (presence != null)
3933 { 3777 {
3778 // If permissions are being requested from an NPC and were not implicitly granted above then
3779 // auto grant all reuqested permissions if the script is owned by the NPC or the NPCs owner
3780 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
3781 if (npcModule != null && npcModule.IsNPC(agentID, World))
3782 {
3783 if (agentID == m_host.ParentGroup.OwnerID || npcModule.GetOwner(agentID) == m_host.ParentGroup.OwnerID)
3784 {
3785 lock (m_host.TaskInventory)
3786 {
3787 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3788 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3789 }
3790
3791 m_ScriptEngine.PostScriptEvent(
3792 m_item.ItemID,
3793 new EventParams(
3794 "run_time_permissions", new Object[] { new LSL_Integer(perm) }, new DetectParams[0]));
3795 }
3796
3797 // it is an NPC, exit even if the permissions werent granted above, they are not going to answer
3798 // the question!
3799 return;
3800 }
3801
3934 string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID); 3802 string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
3935 if (ownerName == String.Empty) 3803 if (ownerName == String.Empty)
3936 ownerName = "(hippos)"; 3804 ownerName = "(hippos)";
@@ -3938,8 +3806,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3938 if (!m_waitingForScriptAnswer) 3806 if (!m_waitingForScriptAnswer)
3939 { 3807 {
3940 m_host.TaskInventory.LockItemsForWrite(true); 3808 m_host.TaskInventory.LockItemsForWrite(true);
3941 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3809 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3942 m_host.TaskInventory[invItemID].PermsMask = 0; 3810 m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
3943 m_host.TaskInventory.LockItemsForWrite(false); 3811 m_host.TaskInventory.LockItemsForWrite(false);
3944 3812
3945 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 3813 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
@@ -3947,16 +3815,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3947 } 3815 }
3948 3816
3949 presence.ControllingClient.SendScriptQuestion( 3817 presence.ControllingClient.SendScriptQuestion(
3950 m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, invItemID, perm); 3818 m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_item.ItemID, perm);
3951 3819
3952 return; 3820 return;
3953 } 3821 }
3954 3822
3955 // Requested agent is not in range, refuse perms 3823 // Requested agent is not in range, refuse perms
3956 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3824 m_ScriptEngine.PostScriptEvent(
3957 "run_time_permissions", new Object[] { 3825 m_item.ItemID,
3958 new LSL_Integer(0) }, 3826 new EventParams("run_time_permissions", new Object[] { new LSL_Integer(0) }, new DetectParams[0]));
3959 new DetectParams[0]));
3960 } 3827 }
3961 3828
3962 void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer) 3829 void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
@@ -3964,24 +3831,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3964 if (taskID != m_host.UUID) 3831 if (taskID != m_host.UUID)
3965 return; 3832 return;
3966 3833
3967 UUID invItemID = InventorySelf(); 3834 client.OnScriptAnswer -= handleScriptAnswer;
3968 3835 m_waitingForScriptAnswer = false;
3969 if (invItemID == UUID.Zero)
3970 return;
3971
3972 client.OnScriptAnswer-=handleScriptAnswer;
3973 m_waitingForScriptAnswer=false;
3974 3836
3975 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3837 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3976 llReleaseControls(); 3838 llReleaseControls();
3977 3839
3978
3979 m_host.TaskInventory.LockItemsForWrite(true); 3840 m_host.TaskInventory.LockItemsForWrite(true);
3980 m_host.TaskInventory[invItemID].PermsMask = answer; 3841 m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
3981 m_host.TaskInventory.LockItemsForWrite(false); 3842 m_host.TaskInventory.LockItemsForWrite(false);
3982 3843
3983 3844 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3984 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3985 "run_time_permissions", new Object[] { 3845 "run_time_permissions", new Object[] {
3986 new LSL_Integer(answer) }, 3846 new LSL_Integer(answer) },
3987 new DetectParams[0])); 3847 new DetectParams[0]));
@@ -3991,41 +3851,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3991 { 3851 {
3992 m_host.AddScriptLPS(1); 3852 m_host.AddScriptLPS(1);
3993 3853
3994 m_host.TaskInventory.LockItemsForRead(true); 3854 return m_item.PermsGranter.ToString();
3995
3996 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3997 {
3998 if (item.Type == 10 && item.ItemID == m_itemID)
3999 {
4000 m_host.TaskInventory.LockItemsForRead(false);
4001 return item.PermsGranter.ToString();
4002 }
4003 }
4004 m_host.TaskInventory.LockItemsForRead(false);
4005
4006 return UUID.Zero.ToString();
4007 } 3855 }
4008 3856
4009 public LSL_Integer llGetPermissions() 3857 public LSL_Integer llGetPermissions()
4010 { 3858 {
4011 m_host.AddScriptLPS(1); 3859 m_host.AddScriptLPS(1);
4012 3860
4013 m_host.TaskInventory.LockItemsForRead(true); 3861 int perms = m_item.PermsMask;
4014 3862
4015 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3863 if (m_automaticLinkPermission)
4016 { 3864 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
4017 if (item.Type == 10 && item.ItemID == m_itemID)
4018 {
4019 int perms = item.PermsMask;
4020 if (m_automaticLinkPermission)
4021 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
4022 m_host.TaskInventory.LockItemsForRead(false);
4023 return perms;
4024 }
4025 }
4026 m_host.TaskInventory.LockItemsForRead(false);
4027 3865
4028 return 0; 3866 return perms;
4029 } 3867 }
4030 3868
4031 public LSL_Integer llGetLinkNumber() 3869 public LSL_Integer llGetLinkNumber()
@@ -4063,18 +3901,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4063 public void llCreateLink(string target, int parent) 3901 public void llCreateLink(string target, int parent)
4064 { 3902 {
4065 m_host.AddScriptLPS(1); 3903 m_host.AddScriptLPS(1);
4066 UUID invItemID = InventorySelf(); 3904
4067 UUID targetID; 3905 UUID targetID;
4068 3906
4069 if (!UUID.TryParse(target, out targetID)) 3907 if (!UUID.TryParse(target, out targetID))
4070 return; 3908 return;
4071 3909
4072 TaskInventoryItem item; 3910 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4073 m_host.TaskInventory.LockItemsForRead(true);
4074 item = m_host.TaskInventory[invItemID];
4075 m_host.TaskInventory.LockItemsForRead(false);
4076
4077 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4078 && !m_automaticLinkPermission) 3911 && !m_automaticLinkPermission)
4079 { 3912 {
4080 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3913 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
@@ -4082,7 +3915,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4082 } 3915 }
4083 3916
4084 IClientAPI client = null; 3917 IClientAPI client = null;
4085 ScenePresence sp = World.GetScenePresence(item.PermsGranter); 3918 ScenePresence sp = World.GetScenePresence(m_item.PermsGranter);
4086 if (sp != null) 3919 if (sp != null)
4087 client = sp.ControllingClient; 3920 client = sp.ControllingClient;
4088 3921
@@ -4128,18 +3961,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4128 public void llBreakLink(int linknum) 3961 public void llBreakLink(int linknum)
4129 { 3962 {
4130 m_host.AddScriptLPS(1); 3963 m_host.AddScriptLPS(1);
4131 UUID invItemID = InventorySelf();
4132 3964
4133 m_host.TaskInventory.LockItemsForRead(true); 3965 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4134 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3966 && !m_automaticLinkPermission)
4135 && !m_automaticLinkPermission) 3967 {
4136 { 3968 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
4137 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3969 return;
4138 m_host.TaskInventory.LockItemsForRead(false); 3970 }
4139 return; 3971
4140 }
4141 m_host.TaskInventory.LockItemsForRead(false);
4142
4143 if (linknum < ScriptBaseClass.LINK_THIS) 3972 if (linknum < ScriptBaseClass.LINK_THIS)
4144 return; 3973 return;
4145 3974
@@ -4238,12 +4067,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4238 { 4067 {
4239 m_host.AddScriptLPS(1); 4068 m_host.AddScriptLPS(1);
4240 4069
4241 UUID invItemID = InventorySelf(); 4070 TaskInventoryItem item = m_item;
4242
4243 TaskInventoryItem item;
4244 m_host.TaskInventory.LockItemsForRead(true);
4245 item = m_host.TaskInventory[invItemID];
4246 m_host.TaskInventory.LockItemsForRead(false);
4247 4071
4248 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 4072 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4249 && !m_automaticLinkPermission) 4073 && !m_automaticLinkPermission)
@@ -4440,11 +4264,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4440 public void llGiveInventory(string destination, string inventory) 4264 public void llGiveInventory(string destination, string inventory)
4441 { 4265 {
4442 m_host.AddScriptLPS(1); 4266 m_host.AddScriptLPS(1);
4443 bool found = false; 4267
4444 UUID destId = UUID.Zero; 4268 UUID destId = UUID.Zero;
4445 UUID objId = UUID.Zero;
4446 int assetType = 0;
4447 string objName = String.Empty;
4448 4269
4449 if (!UUID.TryParse(destination, out destId)) 4270 if (!UUID.TryParse(destination, out destId))
4450 { 4271 {
@@ -4452,28 +4273,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4452 return; 4273 return;
4453 } 4274 }
4454 4275
4455 // move the first object found with this inventory name 4276 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(inventory);
4456 m_host.TaskInventory.LockItemsForRead(true);
4457 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
4458 {
4459 if (inv.Value.Name == inventory)
4460 {
4461 found = true;
4462 objId = inv.Key;
4463 assetType = inv.Value.Type;
4464 objName = inv.Value.Name;
4465 break;
4466 }
4467 }
4468 m_host.TaskInventory.LockItemsForRead(false);
4469 4277
4470 if (!found) 4278 if (item == null)
4471 { 4279 {
4472 llSay(0, String.Format("Could not find object '{0}'", inventory)); 4280 llSay(0, String.Format("Could not find object '{0}'", inventory));
4473 return; 4281 return;
4474// throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory)); 4282// throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory));
4475 } 4283 }
4476 4284
4285 UUID objId = item.ItemID;
4286
4477 // check if destination is an object 4287 // check if destination is an object
4478 if (World.GetSceneObjectPart(destId) != null) 4288 if (World.GetSceneObjectPart(destId) != null)
4479 { 4289 {
@@ -4505,14 +4315,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4505 return; 4315 return;
4506 4316
4507 byte[] bucket = new byte[1]; 4317 byte[] bucket = new byte[1];
4508 bucket[0] = (byte)assetType; 4318 bucket[0] = (byte)item.Type;
4509 //byte[] objBytes = agentItem.ID.GetBytes(); 4319 //byte[] objBytes = agentItem.ID.GetBytes();
4510 //Array.Copy(objBytes, 0, bucket, 1, 16); 4320 //Array.Copy(objBytes, 0, bucket, 1, 16);
4511 4321
4512 GridInstantMessage msg = new GridInstantMessage(World, 4322 GridInstantMessage msg = new GridInstantMessage(World,
4513 m_host.OwnerID, m_host.Name, destId, 4323 m_host.OwnerID, m_host.Name, destId,
4514 (byte)InstantMessageDialog.TaskInventoryOffered, 4324 (byte)InstantMessageDialog.TaskInventoryOffered,
4515 false, objName+". "+m_host.Name+" is located at "+ 4325 false, item.Name+". "+m_host.Name+" is located at "+
4516 World.RegionInfo.RegionName+" "+ 4326 World.RegionInfo.RegionName+" "+
4517 m_host.AbsolutePosition.ToString(), 4327 m_host.AbsolutePosition.ToString(),
4518 agentItem.ID, true, m_host.AbsolutePosition, 4328 agentItem.ID, true, m_host.AbsolutePosition,
@@ -4540,27 +4350,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4540 { 4350 {
4541 m_host.AddScriptLPS(1); 4351 m_host.AddScriptLPS(1);
4542 4352
4543 List<TaskInventoryItem> inv; 4353 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
4544 try 4354
4545 { 4355 if (item == null)
4546 m_host.TaskInventory.LockItemsForRead(true); 4356 return;
4547 inv = new List<TaskInventoryItem>(m_host.TaskInventory.Values); 4357
4548 } 4358 if (item.ItemID == m_item.ItemID)
4549 finally 4359 throw new ScriptDeleteException();
4550 { 4360 else
4551 m_host.TaskInventory.LockItemsForRead(false); 4361 m_host.Inventory.RemoveInventoryItem(item.ItemID);
4552 }
4553 foreach (TaskInventoryItem item in inv)
4554 {
4555 if (item.Name == name)
4556 {
4557 if (item.ItemID == m_itemID)
4558 throw new ScriptDeleteException();
4559 else
4560 m_host.Inventory.RemoveInventoryItem(item.ItemID);
4561 return;
4562 }
4563 }
4564 } 4362 }
4565 4363
4566 public void llSetText(string text, LSL_Vector color, double alpha) 4364 public void llSetText(string text, LSL_Vector color, double alpha)
@@ -4688,8 +4486,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4688 UUID rq = UUID.Random(); 4486 UUID rq = UUID.Random();
4689 4487
4690 UUID tid = AsyncCommands. 4488 UUID tid = AsyncCommands.
4691 DataserverPlugin.RegisterRequest(m_localID, 4489 DataserverPlugin.RegisterRequest(m_host.LocalId,
4692 m_itemID, rq.ToString()); 4490 m_item.ItemID, rq.ToString());
4693 4491
4694 AsyncCommands. 4492 AsyncCommands.
4695 DataserverPlugin.DataserverReply(rq.ToString(), reply); 4493 DataserverPlugin.DataserverReply(rq.ToString(), reply);
@@ -4708,16 +4506,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4708 { 4506 {
4709 m_host.AddScriptLPS(1); 4507 m_host.AddScriptLPS(1);
4710 4508
4711 //Clone is thread safe 4509 foreach (TaskInventoryItem item in m_host.Inventory.GetInventoryItems())
4712 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
4713
4714 foreach (TaskInventoryItem item in itemDictionary.Values)
4715 { 4510 {
4716 if (item.Type == 3 && item.Name == name) 4511 if (item.Type == 3 && item.Name == name)
4717 { 4512 {
4718 UUID tid = AsyncCommands. 4513 UUID tid = AsyncCommands.
4719 DataserverPlugin.RegisterRequest(m_localID, 4514 DataserverPlugin.RegisterRequest(m_host.LocalId,
4720 m_itemID, item.AssetID.ToString()); 4515 m_item.ItemID, item.AssetID.ToString());
4721 4516
4722 Vector3 region = new Vector3( 4517 Vector3 region = new Vector3(
4723 World.RegionInfo.RegionLocX * Constants.RegionSize, 4518 World.RegionInfo.RegionLocX * Constants.RegionSize,
@@ -4743,6 +4538,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4743 return tid.ToString(); 4538 return tid.ToString();
4744 } 4539 }
4745 } 4540 }
4541
4746 ScriptSleep(1000); 4542 ScriptSleep(1000);
4747 return String.Empty; 4543 return String.Empty;
4748 } 4544 }
@@ -4935,19 +4731,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4935 UUID soundId = UUID.Zero; 4731 UUID soundId = UUID.Zero;
4936 if (!UUID.TryParse(impact_sound, out soundId)) 4732 if (!UUID.TryParse(impact_sound, out soundId))
4937 { 4733 {
4938 m_host.TaskInventory.LockItemsForRead(true); 4734 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(impact_sound);
4939 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4735
4940 { 4736 if (item != null && item.Type == (int)AssetType.Sound)
4941 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound) 4737 soundId = item.AssetID;
4942 {
4943 soundId = item.AssetID;
4944 break;
4945 }
4946 }
4947 m_host.TaskInventory.LockItemsForRead(false);
4948 } 4738 }
4949 m_host.CollisionSoundVolume = (float)impact_volume; 4739
4950 m_host.CollisionSound = soundId; 4740 m_host.CollisionSound = soundId;
4741 m_host.CollisionSoundVolume = (float)impact_volume;
4951 m_host.CollisionSoundType = 1; 4742 m_host.CollisionSoundType = 1;
4952 } 4743 }
4953 4744
@@ -4989,10 +4780,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4989 UUID partItemID; 4780 UUID partItemID;
4990 foreach (SceneObjectPart part in parts) 4781 foreach (SceneObjectPart part in parts)
4991 { 4782 {
4992 //Clone is thread safe 4783 foreach (TaskInventoryItem item in part.Inventory.GetInventoryItems())
4993 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone();
4994
4995 foreach (TaskInventoryItem item in itemsDictionary.Values)
4996 { 4784 {
4997 if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT) 4785 if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT)
4998 { 4786 {
@@ -5190,22 +4978,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5190 4978
5191 public LSL_String llGetScriptName() 4979 public LSL_String llGetScriptName()
5192 { 4980 {
5193 string result = String.Empty;
5194
5195 m_host.AddScriptLPS(1); 4981 m_host.AddScriptLPS(1);
5196 4982
5197 m_host.TaskInventory.LockItemsForRead(true); 4983 return m_item.Name != null ? m_item.Name : String.Empty;
5198 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
5199 {
5200 if (item.Type == 10 && item.ItemID == m_itemID)
5201 {
5202 result = item.Name!=null?item.Name:String.Empty;
5203 break;
5204 }
5205 }
5206 m_host.TaskInventory.LockItemsForRead(false);
5207
5208 return result;
5209 } 4984 }
5210 4985
5211 public LSL_Integer llGetLinkNumberOfSides(int link) 4986 public LSL_Integer llGetLinkNumberOfSides(int link)
@@ -5376,22 +5151,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5376 { 5151 {
5377 m_host.AddScriptLPS(1); 5152 m_host.AddScriptLPS(1);
5378 5153
5379 m_host.TaskInventory.LockItemsForRead(true); 5154 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
5380 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 5155
5156 if (item == null)
5157 return UUID.Zero.ToString();
5158
5159 if ((item.CurrentPermissions
5160 & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
5161 == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
5381 { 5162 {
5382 if (inv.Value.Name == name) 5163 return item.AssetID.ToString();
5383 {
5384 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
5385 {
5386 m_host.TaskInventory.LockItemsForRead(false);
5387 return inv.Value.AssetID.ToString();
5388 }
5389 else
5390 {
5391 m_host.TaskInventory.LockItemsForRead(false);
5392 return UUID.Zero.ToString();
5393 }
5394 }
5395 } 5164 }
5396 m_host.TaskInventory.LockItemsForRead(false); 5165 m_host.TaskInventory.LockItemsForRead(false);
5397 5166
@@ -6339,7 +6108,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6339 } 6108 }
6340 } 6109 }
6341 } 6110 }
6342 List<UUID> presenceIds = new List<UUID>();
6343 6111
6344 World.ForEachRootScenePresence( 6112 World.ForEachRootScenePresence(
6345 delegate (ScenePresence ssp) 6113 delegate (ScenePresence ssp)
@@ -6490,7 +6258,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6490 if (m_host.OwnerID == land.LandData.OwnerID) 6258 if (m_host.OwnerID == land.LandData.OwnerID)
6491 { 6259 {
6492 Vector3 pos = World.GetNearestAllowedPosition(presence, land); 6260 Vector3 pos = World.GetNearestAllowedPosition(presence, land);
6493 presence.TeleportWithMomentum(pos); 6261 presence.TeleportWithMomentum(pos, null);
6494 presence.ControllingClient.SendAlertMessage("You have been ejected from this land"); 6262 presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
6495 } 6263 }
6496 } 6264 }
@@ -7015,22 +6783,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7015 } 6783 }
7016 } 6784 }
7017 6785
7018 protected UUID GetTaskInventoryItem(string name)
7019 {
7020 m_host.TaskInventory.LockItemsForRead(true);
7021 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
7022 {
7023 if (inv.Value.Name == name)
7024 {
7025 m_host.TaskInventory.LockItemsForRead(false);
7026 return inv.Key;
7027 }
7028 }
7029 m_host.TaskInventory.LockItemsForRead(false);
7030
7031 return UUID.Zero;
7032 }
7033
7034 public void llGiveInventoryList(string destination, string category, LSL_List inventory) 6786 public void llGiveInventoryList(string destination, string category, LSL_List inventory)
7035 { 6787 {
7036 m_host.AddScriptLPS(1); 6788 m_host.AddScriptLPS(1);
@@ -7043,16 +6795,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7043 6795
7044 foreach (Object item in inventory.Data) 6796 foreach (Object item in inventory.Data)
7045 { 6797 {
6798 string rawItemString = item.ToString();
6799
7046 UUID itemID; 6800 UUID itemID;
7047 if (UUID.TryParse(item.ToString(), out itemID)) 6801 if (UUID.TryParse(rawItemString, out itemID))
7048 { 6802 {
7049 itemList.Add(itemID); 6803 itemList.Add(itemID);
7050 } 6804 }
7051 else 6805 else
7052 { 6806 {
7053 itemID = GetTaskInventoryItem(item.ToString()); 6807 TaskInventoryItem taskItem = m_host.Inventory.GetInventoryItem(rawItemString);
7054 if (itemID != UUID.Zero) 6808
7055 itemList.Add(itemID); 6809 if (taskItem != null)
6810 itemList.Add(taskItem.ItemID);
7056 } 6811 }
7057 } 6812 }
7058 6813
@@ -7374,9 +7129,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7374 public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param) 7129 public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
7375 { 7130 {
7376 m_host.AddScriptLPS(1); 7131 m_host.AddScriptLPS(1);
7377 bool found = false; 7132
7378 UUID destId = UUID.Zero; 7133 UUID destId = UUID.Zero;
7379 UUID srcId = UUID.Zero;
7380 7134
7381 if (!UUID.TryParse(target, out destId)) 7135 if (!UUID.TryParse(target, out destId))
7382 { 7136 {
@@ -7391,25 +7145,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7391 } 7145 }
7392 7146
7393 // copy the first script found with this inventory name 7147 // copy the first script found with this inventory name
7394 TaskInventoryItem scriptItem = null; 7148 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
7395 m_host.TaskInventory.LockItemsForRead(true);
7396 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
7397 {
7398 if (inv.Value.Name == name)
7399 {
7400 // make sure the object is a script
7401 if (10 == inv.Value.Type)
7402 {
7403 found = true;
7404 srcId = inv.Key;
7405 scriptItem = inv.Value;
7406 break;
7407 }
7408 }
7409 }
7410 m_host.TaskInventory.LockItemsForRead(false);
7411 7149
7412 if (!found) 7150 // make sure the object is a script
7151 if (item == null || item.Type != 10)
7413 { 7152 {
7414 llSay(0, "Could not find script " + name); 7153 llSay(0, "Could not find script " + name);
7415 return; 7154 return;
@@ -7418,13 +7157,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7418 SceneObjectPart dest = World.GetSceneObjectPart(destId); 7157 SceneObjectPart dest = World.GetSceneObjectPart(destId);
7419 if (dest != null) 7158 if (dest != null)
7420 { 7159 {
7421 if ((scriptItem.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID) 7160 if ((item.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID)
7422 { 7161 {
7423 // the rest of the permission checks are done in RezScript, so check the pin there as well 7162 // the rest of the permission checks are done in RezScript, so check the pin there as well
7424 World.RezScriptFromPrim(srcId, m_host, destId, pin, running, start_param); 7163 World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param);
7425 7164
7426 if ((scriptItem.BasePermissions & (uint)PermissionMask.Copy) == 0) 7165 if ((item.BasePermissions & (uint)PermissionMask.Copy) == 0)
7427 m_host.Inventory.RemoveInventoryItem(srcId); 7166 m_host.Inventory.RemoveInventoryItem(item.ItemID);
7428 } 7167 }
7429 } 7168 }
7430 // this will cause the delay even if the script pin or permissions were wrong - seems ok 7169 // this will cause the delay even if the script pin or permissions were wrong - seems ok
@@ -7437,14 +7176,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7437 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); 7176 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
7438 if (xmlrpcMod.IsEnabled()) 7177 if (xmlrpcMod.IsEnabled())
7439 { 7178 {
7440 UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_localID, m_itemID, UUID.Zero); 7179 UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero);
7441 IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>(); 7180 IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
7442 if (xmlRpcRouter != null) 7181 if (xmlRpcRouter != null)
7443 { 7182 {
7444 string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName; 7183 string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
7445 7184
7446 xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID, 7185 xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
7447 m_itemID, String.Format("http://{0}:{1}/", ExternalHostName, 7186 m_item.ItemID, String.Format("http://{0}:{1}/", ExternalHostName,
7448 xmlrpcMod.Port.ToString())); 7187 xmlrpcMod.Port.ToString()));
7449 } 7188 }
7450 object[] resobj = new object[] 7189 object[] resobj = new object[]
@@ -7456,7 +7195,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7456 new LSL_Integer(0), 7195 new LSL_Integer(0),
7457 new LSL_String(String.Empty) 7196 new LSL_String(String.Empty)
7458 }; 7197 };
7459 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams("remote_data", resobj, 7198 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj,
7460 new DetectParams[0])); 7199 new DetectParams[0]));
7461 } 7200 }
7462 ScriptSleep(1000); 7201 ScriptSleep(1000);
@@ -7467,7 +7206,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7467 m_host.AddScriptLPS(1); 7206 m_host.AddScriptLPS(1);
7468 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); 7207 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
7469 ScriptSleep(3000); 7208 ScriptSleep(3000);
7470 return (xmlrpcMod.SendRemoteData(m_localID, m_itemID, channel, dest, idata, sdata)).ToString(); 7209 return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString();
7471 } 7210 }
7472 7211
7473 public void llRemoteDataReply(string channel, string message_id, string sdata, int idata) 7212 public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
@@ -8471,7 +8210,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8471 return; 8210 return;
8472 face = (int)rules.GetLSLIntegerItem(idx++); 8211 face = (int)rules.GetLSLIntegerItem(idx++);
8473 int shiny = (int)rules.GetLSLIntegerItem(idx++); 8212 int shiny = (int)rules.GetLSLIntegerItem(idx++);
8474 Bumpiness bump = (Bumpiness)Convert.ToByte((int)rules.GetLSLIntegerItem(idx++)); 8213 Bumpiness bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);
8475 8214
8476 SetShiny(part, face, shiny, bump); 8215 SetShiny(part, face, shiny, bump);
8477 8216
@@ -10313,7 +10052,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10313 public LSL_String llGetSimulatorHostname() 10052 public LSL_String llGetSimulatorHostname()
10314 { 10053 {
10315 m_host.AddScriptLPS(1); 10054 m_host.AddScriptLPS(1);
10316 return System.Environment.MachineName; 10055 IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
10056 return UrlModule.ExternalHostNameForLSL;
10317 } 10057 }
10318 10058
10319 // <summary> 10059 // <summary>
@@ -10550,92 +10290,82 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10550 } 10290 }
10551 } 10291 }
10552 10292
10553 public LSL_Integer llGetInventoryPermMask(string item, int mask) 10293 public LSL_Integer llGetInventoryPermMask(string itemName, int mask)
10554 { 10294 {
10555 m_host.AddScriptLPS(1); 10295 m_host.AddScriptLPS(1);
10556 10296
10557 m_host.TaskInventory.LockItemsForRead(true); 10297 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
10558 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 10298
10299 if (item == null)
10300 return -1;
10301
10302 switch (mask)
10559 { 10303 {
10560 if (inv.Value.Name == item) 10304 case 0:
10561 { 10305 return (int)item.BasePermissions;
10562 m_host.TaskInventory.LockItemsForRead(false); 10306 case 1:
10563 switch (mask) 10307 return (int)item.CurrentPermissions;
10564 { 10308 case 2:
10565 case 0: 10309 return (int)item.GroupPermissions;
10566 return (int)inv.Value.BasePermissions; 10310 case 3:
10567 case 1: 10311 return (int)item.EveryonePermissions;
10568 return (int)inv.Value.CurrentPermissions; 10312 case 4:
10569 case 2: 10313 return (int)item.NextPermissions;
10570 return (int)inv.Value.GroupPermissions;
10571 case 3:
10572 return (int)inv.Value.EveryonePermissions;
10573 case 4:
10574 return (int)inv.Value.NextPermissions;
10575 }
10576 }
10577 } 10314 }
10578 m_host.TaskInventory.LockItemsForRead(false); 10315 m_host.TaskInventory.LockItemsForRead(false);
10579 10316
10580 return -1; 10317 return -1;
10581 } 10318 }
10582 10319
10583 public void llSetInventoryPermMask(string item, int mask, int value) 10320 public void llSetInventoryPermMask(string itemName, int mask, int value)
10584 { 10321 {
10585 m_host.AddScriptLPS(1); 10322 m_host.AddScriptLPS(1);
10323
10586 if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false)) 10324 if (m_ScriptEngine.Config.GetBoolean("AllowGodFunctions", false))
10587 { 10325 {
10588 if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID)) 10326 if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID))
10589 { 10327 {
10590 lock (m_host.TaskInventory) 10328 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
10329
10330 if (item != null)
10591 { 10331 {
10592 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 10332 switch (mask)
10593 { 10333 {
10594 if (inv.Value.Name == item) 10334 case 0:
10595 { 10335 item.BasePermissions = (uint)value;
10596 switch (mask) 10336 break;
10597 { 10337 case 1:
10598 case 0: 10338 item.CurrentPermissions = (uint)value;
10599 inv.Value.BasePermissions = (uint)value; 10339 break;
10600 break; 10340 case 2:
10601 case 1: 10341 item.GroupPermissions = (uint)value;
10602 inv.Value.CurrentPermissions = (uint)value; 10342 break;
10603 break; 10343 case 3:
10604 case 2: 10344 item.EveryonePermissions = (uint)value;
10605 inv.Value.GroupPermissions = (uint)value; 10345 break;
10606 break; 10346 case 4:
10607 case 3: 10347 item.NextPermissions = (uint)value;
10608 inv.Value.EveryonePermissions = (uint)value; 10348 break;
10609 break;
10610 case 4:
10611 inv.Value.NextPermissions = (uint)value;
10612 break;
10613 }
10614 }
10615 } 10349 }
10616 } 10350 }
10617 } 10351 }
10618 } 10352 }
10619 } 10353 }
10620 10354
10621 public LSL_String llGetInventoryCreator(string item) 10355 public LSL_String llGetInventoryCreator(string itemName)
10622 { 10356 {
10623 m_host.AddScriptLPS(1); 10357 m_host.AddScriptLPS(1);
10624 10358
10625 m_host.TaskInventory.LockItemsForRead(true); 10359 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
10626 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 10360
10361 if (item == null)
10627 { 10362 {
10628 if (inv.Value.Name == item) 10363 llSay(0, "No item name '" + item + "'");
10629 {
10630 m_host.TaskInventory.LockItemsForRead(false);
10631 return inv.Value.CreatorID.ToString();
10632 }
10633 }
10634 m_host.TaskInventory.LockItemsForRead(false);
10635 10364
10636 llSay(0, "No item name '" + item + "'"); 10365 return String.Empty;
10366 }
10637 10367
10638 return String.Empty; 10368 return item.CreatorID.ToString();
10639 } 10369 }
10640 10370
10641 public void llOwnerSay(string msg) 10371 public void llOwnerSay(string msg)
@@ -10652,13 +10382,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10652 { 10382 {
10653 m_host.AddScriptLPS(1); 10383 m_host.AddScriptLPS(1);
10654 if (m_UrlModule != null) 10384 if (m_UrlModule != null)
10655 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString(); 10385 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
10656 return UUID.Zero.ToString(); 10386 return UUID.Zero.ToString();
10657 } 10387 }
10658 10388
10659 public LSL_String llRequestSimulatorData(string simulator, int data) 10389 public LSL_String llRequestSimulatorData(string simulator, int data)
10660 { 10390 {
10661 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_itemID, "OSSL"); 10391 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
10662 10392
10663 try 10393 try
10664 { 10394 {
@@ -10668,7 +10398,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10668 10398
10669 GridRegion info; 10399 GridRegion info;
10670 10400
10671 if (m_ScriptEngine.World.RegionInfo.RegionName == simulator) 10401 if (m_ScriptEngine.World.RegionInfo.RegionName == simulator) //Det data for this simulator?
10402
10672 info = new GridRegion(m_ScriptEngine.World.RegionInfo); 10403 info = new GridRegion(m_ScriptEngine.World.RegionInfo);
10673 else 10404 else
10674 info = m_ScriptEngine.World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator); 10405 info = m_ScriptEngine.World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator);
@@ -10681,10 +10412,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10681 ScriptSleep(1000); 10412 ScriptSleep(1000);
10682 return UUID.Zero.ToString(); 10413 return UUID.Zero.ToString();
10683 } 10414 }
10684 reply = new LSL_Vector( 10415 if (m_ScriptEngine.World.RegionInfo.RegionName != simulator)
10685 info.RegionLocX, 10416 {
10686 info.RegionLocY, 10417 //Hypergrid Region co-ordinates
10687 0).ToString(); 10418 uint rx = 0, ry = 0;
10419 Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out rx, out ry);
10420
10421 reply = new LSL_Vector(
10422 rx,
10423 ry,
10424 0).ToString();
10425 }
10426 else
10427 {
10428 //Local-cooridnates
10429 reply = new LSL_Vector(
10430 info.RegionLocX,
10431 info.RegionLocY,
10432 0).ToString();
10433 }
10688 break; 10434 break;
10689 case ScriptBaseClass.DATA_SIM_STATUS: 10435 case ScriptBaseClass.DATA_SIM_STATUS:
10690 if (info != null) 10436 if (info != null)
@@ -10720,7 +10466,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10720 UUID rq = UUID.Random(); 10466 UUID rq = UUID.Random();
10721 10467
10722 UUID tid = AsyncCommands. 10468 UUID tid = AsyncCommands.
10723 DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 10469 DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
10724 10470
10725 AsyncCommands. 10471 AsyncCommands.
10726 DataserverPlugin.DataserverReply(rq.ToString(), reply); 10472 DataserverPlugin.DataserverReply(rq.ToString(), reply);
@@ -10739,7 +10485,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10739 m_host.AddScriptLPS(1); 10485 m_host.AddScriptLPS(1);
10740 10486
10741 if (m_UrlModule != null) 10487 if (m_UrlModule != null)
10742 return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString(); 10488 return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
10743 return UUID.Zero.ToString(); 10489 return UUID.Zero.ToString();
10744 } 10490 }
10745 10491
@@ -10775,7 +10521,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10775 // child agents have a mass of 1.0 10521 // child agents have a mass of 1.0
10776 return 1; 10522 return 1;
10777 else 10523 else
10778 return avatar.GetMass(); 10524 return (double)avatar.GetMass();
10779 } 10525 }
10780 catch (KeyNotFoundException) 10526 catch (KeyNotFoundException)
10781 { 10527 {
@@ -11179,18 +10925,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11179 { 10925 {
11180 m_host.AddScriptLPS(1); 10926 m_host.AddScriptLPS(1);
11181 10927
11182 m_host.TaskInventory.LockItemsForRead(true); 10928 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
11183 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
11184 {
11185 if (inv.Value.Name == name)
11186 {
11187 m_host.TaskInventory.LockItemsForRead(false);
11188 return inv.Value.Type;
11189 }
11190 }
11191 m_host.TaskInventory.LockItemsForRead(false);
11192 10929
11193 return -1; 10930 if (item == null)
10931 return -1;
10932
10933 return item.Type;
11194 } 10934 }
11195 10935
11196 public void llSetPayPrice(int price, LSL_List quick_pay_buttons) 10936 public void llSetPayPrice(int price, LSL_List quick_pay_buttons)
@@ -11218,32 +10958,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11218 public LSL_Vector llGetCameraPos() 10958 public LSL_Vector llGetCameraPos()
11219 { 10959 {
11220 m_host.AddScriptLPS(1); 10960 m_host.AddScriptLPS(1);
11221 UUID invItemID = InventorySelf();
11222
11223 if (invItemID == UUID.Zero)
11224 return new LSL_Vector();
11225
11226 m_host.TaskInventory.LockItemsForRead(true);
11227 10961
11228 UUID agentID = m_host.TaskInventory[invItemID].PermsGranter; 10962 if (m_item.PermsGranter == UUID.Zero)
10963 return new LSL_Vector();
11229 10964
11230// if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 10965 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
11231 if (agentID == UUID.Zero)
11232 {
11233 m_host.TaskInventory.LockItemsForRead(false);
11234 return new LSL_Vector();
11235 }
11236
11237 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
11238 { 10966 {
11239 ShoutError("No permissions to track the camera"); 10967 ShoutError("No permissions to track the camera");
11240 m_host.TaskInventory.LockItemsForRead(false);
11241 return new LSL_Vector(); 10968 return new LSL_Vector();
11242 } 10969 }
11243 m_host.TaskInventory.LockItemsForRead(false);
11244 10970
11245// ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10971// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
11246 ScenePresence presence = World.GetScenePresence(agentID); 10972 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
11247 if (presence != null) 10973 if (presence != null)
11248 { 10974 {
11249 LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z); 10975 LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z);
@@ -11255,30 +10981,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11255 public LSL_Rotation llGetCameraRot() 10981 public LSL_Rotation llGetCameraRot()
11256 { 10982 {
11257 m_host.AddScriptLPS(1); 10983 m_host.AddScriptLPS(1);
11258 UUID invItemID = InventorySelf();
11259 if (invItemID == UUID.Zero)
11260 return new LSL_Rotation();
11261 10984
11262 m_host.TaskInventory.LockItemsForRead(true); 10985 if (m_item.PermsGranter == UUID.Zero)
11263 10986 return new LSL_Rotation();
11264 UUID agentID = m_host.TaskInventory[invItemID].PermsGranter;
11265 10987
11266// if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 10988 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
11267 if (agentID == UUID.Zero)
11268 {
11269 m_host.TaskInventory.LockItemsForRead(false);
11270 return new LSL_Rotation();
11271 }
11272 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
11273 { 10989 {
11274 ShoutError("No permissions to track the camera"); 10990 ShoutError("No permissions to track the camera");
11275 m_host.TaskInventory.LockItemsForRead(false);
11276 return new LSL_Rotation(); 10991 return new LSL_Rotation();
11277 } 10992 }
11278 m_host.TaskInventory.LockItemsForRead(false);
11279 10993
11280// ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10994// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
11281 ScenePresence presence = World.GetScenePresence(agentID); 10995 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
11282 if (presence != null) 10996 if (presence != null)
11283 { 10997 {
11284 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W); 10998 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W);
@@ -11337,7 +11051,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11337 public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt) 11051 public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
11338 { 11052 {
11339 m_host.AddScriptLPS(1); 11053 m_host.AddScriptLPS(1);
11340 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0); 11054 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
11341 if (detectedParams == null) 11055 if (detectedParams == null)
11342 { 11056 {
11343 if (m_host.ParentGroup.IsAttachment == true) 11057 if (m_host.ParentGroup.IsAttachment == true)
@@ -11461,30 +11175,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11461 { 11175 {
11462 m_host.AddScriptLPS(1); 11176 m_host.AddScriptLPS(1);
11463 11177
11464 // our key in the object we are in
11465 UUID invItemID = InventorySelf();
11466 if (invItemID == UUID.Zero) return;
11467
11468 // the object we are in 11178 // the object we are in
11469 UUID objectID = m_host.ParentUUID; 11179 UUID objectID = m_host.ParentUUID;
11470 if (objectID == UUID.Zero) return; 11180 if (objectID == UUID.Zero)
11181 return;
11471 11182
11472 UUID agentID;
11473 m_host.TaskInventory.LockItemsForRead(true);
11474 // we need the permission first, to know which avatar we want to set the camera for 11183 // we need the permission first, to know which avatar we want to set the camera for
11475 agentID = m_host.TaskInventory[invItemID].PermsGranter; 11184 UUID agentID = m_item.PermsGranter;
11476 11185
11477 if (agentID == UUID.Zero) 11186 if (agentID == UUID.Zero)
11478 {
11479 m_host.TaskInventory.LockItemsForRead(false);
11480 return; 11187 return;
11481 } 11188
11482 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) 11189 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
11483 {
11484 m_host.TaskInventory.LockItemsForRead(false);
11485 return; 11190 return;
11486 }
11487 m_host.TaskInventory.LockItemsForRead(false);
11488 11191
11489 ScenePresence presence = World.GetScenePresence(agentID); 11192 ScenePresence presence = World.GetScenePresence(agentID);
11490 11193
@@ -11526,34 +11229,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11526 { 11229 {
11527 m_host.AddScriptLPS(1); 11230 m_host.AddScriptLPS(1);
11528 11231
11529 // our key in the object we are in
11530 UUID invItemID=InventorySelf();
11531 if (invItemID == UUID.Zero) return;
11532
11533 // the object we are in 11232 // the object we are in
11534 UUID objectID = m_host.ParentUUID; 11233 UUID objectID = m_host.ParentUUID;
11535 if (objectID == UUID.Zero) return; 11234 if (objectID == UUID.Zero)
11235 return;
11536 11236
11537 // we need the permission first, to know which avatar we want to clear the camera for 11237 // we need the permission first, to know which avatar we want to clear the camera for
11538 UUID agentID; 11238 UUID agentID = m_item.PermsGranter;
11539 m_host.TaskInventory.LockItemsForRead(true); 11239
11540 agentID = m_host.TaskInventory[invItemID].PermsGranter;
11541 if (agentID == UUID.Zero) 11240 if (agentID == UUID.Zero)
11542 {
11543 m_host.TaskInventory.LockItemsForRead(false);
11544 return; 11241 return;
11545 } 11242
11546 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) 11243 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
11547 {
11548 m_host.TaskInventory.LockItemsForRead(false);
11549 return; 11244 return;
11550 }
11551 m_host.TaskInventory.LockItemsForRead(false);
11552 11245
11553 ScenePresence presence = World.GetScenePresence(agentID); 11246 ScenePresence presence = World.GetScenePresence(agentID);
11554 11247
11555 // we are not interested in child-agents 11248 // we are not interested in child-agents
11556 if (presence.IsChildAgent) return; 11249 if (presence.IsChildAgent)
11250 return;
11557 11251
11558 presence.ControllingClient.SendClearFollowCamProperties(objectID); 11252 presence.ControllingClient.SendClearFollowCamProperties(objectID);
11559 } 11253 }
@@ -11744,8 +11438,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11744 } 11438 }
11745 } 11439 }
11746 11440
11747 UUID reqID = httpScriptMod. 11441 UUID reqID
11748 StartHttpRequest(m_localID, m_itemID, url, param, httpHeaders, body); 11442 = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body);
11749 11443
11750 if (reqID != UUID.Zero) 11444 if (reqID != UUID.Zero)
11751 return reqID.ToString(); 11445 return reqID.ToString();
@@ -11999,19 +11693,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11999 break; 11693 break;
12000 // For the following 8 see the Object version below 11694 // For the following 8 see the Object version below
12001 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT: 11695 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
12002 ret.Add(new LSL_Integer(0)); 11696 ret.Add(new LSL_Integer(av.RunningScriptCount()));
12003 break; 11697 break;
12004 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT: 11698 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
12005 ret.Add(new LSL_Integer(0)); 11699 ret.Add(new LSL_Integer(av.ScriptCount()));
12006 break; 11700 break;
12007 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY: 11701 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
12008 ret.Add(new LSL_Integer(0)); 11702 ret.Add(new LSL_Integer(av.RunningScriptCount() * 16384));
12009 break; 11703 break;
12010 case ScriptBaseClass.OBJECT_SCRIPT_TIME: 11704 case ScriptBaseClass.OBJECT_SCRIPT_TIME:
12011 ret.Add(new LSL_Float(0)); 11705 ret.Add(new LSL_Float(av.ScriptExecutionTime() / 1000.0f));
12012 break; 11706 break;
12013 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE: 11707 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
12014 ret.Add(new LSL_Integer(0)); 11708 ret.Add(new LSL_Integer(1));
12015 break; 11709 break;
12016 case ScriptBaseClass.OBJECT_SERVER_COST: 11710 case ScriptBaseClass.OBJECT_SERVER_COST:
12017 ret.Add(new LSL_Float(0)); 11711 ret.Add(new LSL_Float(0));
@@ -12069,37 +11763,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12069 case ScriptBaseClass.OBJECT_CREATOR: 11763 case ScriptBaseClass.OBJECT_CREATOR:
12070 ret.Add(new LSL_String(obj.CreatorID.ToString())); 11764 ret.Add(new LSL_String(obj.CreatorID.ToString()));
12071 break; 11765 break;
12072 // The following 8 I have intentionaly coded to return zero. They are part of
12073 // "Land Impact" calculations. These calculations are probably not applicable
12074 // to OpenSim, required figures (cpu/memory usage) are not currently tracked
12075 // I have intentionally left these all at zero rather than return possibly
12076 // missleading numbers
12077 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT: 11766 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
12078 // in SL this currently includes crashed scripts 11767 ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount()));
12079 ret.Add(new LSL_Integer(0));
12080 break; 11768 break;
12081 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT: 11769 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
12082 ret.Add(new LSL_Integer(0)); 11770 ret.Add(new LSL_Integer(obj.ParentGroup.ScriptCount()));
12083 break; 11771 break;
12084 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY: 11772 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
12085 // The value returned in SL for mono scripts is 65536 * number of active scripts 11773 // The value returned in SL for mono scripts is 65536 * number of active scripts
12086 ret.Add(new LSL_Integer(0)); 11774 // and 16384 * number of active scripts for LSO. since llGetFreememory
11775 // is coded to give the LSO value use it here
11776 ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount() * 16384));
12087 break; 11777 break;
12088 case ScriptBaseClass.OBJECT_SCRIPT_TIME: 11778 case ScriptBaseClass.OBJECT_SCRIPT_TIME:
12089 // Average cpu time per simulator frame expended on all scripts in the objetc 11779 // Average cpu time in seconds per simulator frame expended on all scripts in the object
12090 ret.Add(new LSL_Float(0)); 11780 ret.Add(new LSL_Float(obj.ParentGroup.ScriptExecutionTime() / 1000.0f));
12091 break; 11781 break;
12092 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE: 11782 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
12093 // according to the SL wiki A prim or linkset will have prim 11783 // according to the SL wiki A prim or linkset will have prim
12094 // equivalent of the number of prims in a linkset if it does not 11784 // equivalent of the number of prims in a linkset if it does not
12095 // contain a mesh anywhere in the link set or is not a normal prim 11785 // contain a mesh anywhere in the link set or is not a normal prim
12096 // The value returned in SL for normal prims is prim count 11786 // The value returned in SL for normal prims is prim count
12097 ret.Add(new LSL_Integer(0)); 11787 ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
12098 break; 11788 break;
12099 11789
12100 // costs below may need to be diferent for root parts, need to check 11790 // costs below may need to be diferent for root parts, need to check
12101 case ScriptBaseClass.OBJECT_SERVER_COST: 11791 case ScriptBaseClass.OBJECT_SERVER_COST:
12102 // The value returned in SL for normal prims is prim count 11792 // The linden calculation is here
11793 // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
11794 // The value returned in SL for normal prims looks like the prim count
12103 ret.Add(new LSL_Float(0)); 11795 ret.Add(new LSL_Float(0));
12104 break; 11796 break;
12105 case ScriptBaseClass.OBJECT_STREAMING_COST: 11797 case ScriptBaseClass.OBJECT_STREAMING_COST:
@@ -12124,22 +11816,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12124 return new LSL_List(); 11816 return new LSL_List();
12125 } 11817 }
12126 11818
12127 internal UUID ScriptByName(string name) 11819 internal UUID GetScriptByName(string name)
12128 { 11820 {
12129 m_host.TaskInventory.LockItemsForRead(true); 11821 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
12130
12131 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
12132 {
12133 if (item.Type == 10 && item.Name == name)
12134 {
12135 m_host.TaskInventory.LockItemsForRead(false);
12136 return item.ItemID;
12137 }
12138 }
12139 11822
12140 m_host.TaskInventory.LockItemsForRead(false); 11823 if (item == null || item.Type != 10)
11824 return UUID.Zero;
12141 11825
12142 return UUID.Zero; 11826 return item.ItemID;
12143 } 11827 }
12144 11828
12145 internal void ShoutError(string msg) 11829 internal void ShoutError(string msg)
@@ -12179,21 +11863,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12179 { 11863 {
12180 m_host.AddScriptLPS(1); 11864 m_host.AddScriptLPS(1);
12181 11865
12182 //Clone is thread safe
12183 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
12184
12185 UUID assetID = UUID.Zero; 11866 UUID assetID = UUID.Zero;
12186 11867
12187 if (!UUID.TryParse(name, out assetID)) 11868 if (!UUID.TryParse(name, out assetID))
12188 { 11869 {
12189 foreach (TaskInventoryItem item in itemsDictionary.Values) 11870 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
12190 { 11871
12191 if (item.Type == 7 && item.Name == name) 11872 if (item != null && item.Type == 7)
12192 { 11873 assetID = item.AssetID;
12193 assetID = item.AssetID;
12194 break;
12195 }
12196 }
12197 } 11874 }
12198 11875
12199 if (assetID == UUID.Zero) 11876 if (assetID == UUID.Zero)
@@ -12205,7 +11882,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12205 } 11882 }
12206 11883
12207 // was: UUID tid = tid = AsyncCommands. 11884 // was: UUID tid = tid = AsyncCommands.
12208 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, assetID.ToString()); 11885 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, assetID.ToString());
12209 11886
12210 if (NotecardCache.IsCached(assetID)) 11887 if (NotecardCache.IsCached(assetID))
12211 { 11888 {
@@ -12242,21 +11919,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12242 { 11919 {
12243 m_host.AddScriptLPS(1); 11920 m_host.AddScriptLPS(1);
12244 11921
12245 //Clone is thread safe
12246 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
12247
12248 UUID assetID = UUID.Zero; 11922 UUID assetID = UUID.Zero;
12249 11923
12250 if (!UUID.TryParse(name, out assetID)) 11924 if (!UUID.TryParse(name, out assetID))
12251 { 11925 {
12252 foreach (TaskInventoryItem item in itemsDictionary.Values) 11926 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name);
12253 { 11927
12254 if (item.Type == 7 && item.Name == name) 11928 if (item != null && item.Type == 7)
12255 { 11929 assetID = item.AssetID;
12256 assetID = item.AssetID;
12257 break;
12258 }
12259 }
12260 } 11930 }
12261 11931
12262 if (assetID == UUID.Zero) 11932 if (assetID == UUID.Zero)
@@ -12268,7 +11938,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12268 } 11938 }
12269 11939
12270 // was: UUID tid = tid = AsyncCommands. 11940 // was: UUID tid = tid = AsyncCommands.
12271 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, assetID.ToString()); 11941 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, assetID.ToString());
12272 11942
12273 if (NotecardCache.IsCached(assetID)) 11943 if (NotecardCache.IsCached(assetID))
12274 { 11944 {
@@ -12352,7 +12022,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12352 { 12022 {
12353 UUID rq = UUID.Random(); 12023 UUID rq = UUID.Random();
12354 12024
12355 AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 12025 AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
12356 12026
12357 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id))); 12027 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id)));
12358 12028
@@ -12368,7 +12038,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12368 { 12038 {
12369 UUID rq = UUID.Random(); 12039 UUID rq = UUID.Random();
12370 12040
12371 AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 12041 AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
12372 12042
12373 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id)); 12043 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id));
12374 12044
@@ -12570,7 +12240,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12570 { 12240 {
12571 Tri t1 = new Tri(); 12241 Tri t1 = new Tri();
12572 Tri t2 = new Tri(); 12242 Tri t2 = new Tri();
12573 12243
12574 Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]); 12244 Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]);
12575 Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]); 12245 Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]);
12576 Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]); 12246 Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]);
@@ -12611,7 +12281,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12611 // sometimes 12281 // sometimes
12612 if (Math.Abs(b) < 0.000001) 12282 if (Math.Abs(b) < 0.000001)
12613 continue; 12283 continue;
12614 12284
12615 double r = a / b; 12285 double r = a / b;
12616 12286
12617 // ray points away from plane 12287 // ray points away from plane
@@ -12871,7 +12541,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12871 bool isAccount = false; 12541 bool isAccount = false;
12872 bool isGroup = false; 12542 bool isGroup = false;
12873 12543
12874 if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManager(m_host.OwnerID)) 12544 if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManagerOrOwner(m_host.OwnerID))
12875 return 0; 12545 return 0;
12876 12546
12877 UUID id = new UUID(); 12547 UUID id = new UUID();
@@ -12933,35 +12603,50 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12933 return 1; 12603 return 1;
12934 } 12604 }
12935 12605
12936 #region Not Implemented 12606 public LSL_Integer llGetMemoryLimit()
12937 // 12607 {
12938 // Listing the unimplemented lsl functions here, please move 12608 m_host.AddScriptLPS(1);
12939 // them from this region as they are completed 12609 // The value returned for LSO scripts in SL
12940 // 12610 return 16384;
12611 }
12941 12612
12942 public void llGetEnv(LSL_String name) 12613 public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
12943 { 12614 {
12944 m_host.AddScriptLPS(1); 12615 m_host.AddScriptLPS(1);
12945 NotImplemented("llGetEnv"); 12616 // Treat as an LSO script
12617 return ScriptBaseClass.FALSE;
12946 } 12618 }
12947 12619
12948 public void llGetSPMaxMemory() 12620 public LSL_Integer llGetSPMaxMemory()
12949 { 12621 {
12950 m_host.AddScriptLPS(1); 12622 m_host.AddScriptLPS(1);
12951 NotImplemented("llGetSPMaxMemory"); 12623 // The value returned for LSO scripts in SL
12624 return 16384;
12952 } 12625 }
12953 12626
12954 public virtual LSL_Integer llGetUsedMemory() 12627 public virtual LSL_Integer llGetUsedMemory()
12955 { 12628 {
12956 m_host.AddScriptLPS(1); 12629 m_host.AddScriptLPS(1);
12957 NotImplemented("llGetUsedMemory"); 12630 // The value returned for LSO scripts in SL
12958 return 0; 12631 return 16384;
12959 } 12632 }
12960 12633
12961 public void llScriptProfiler(LSL_Integer flags) 12634 public void llScriptProfiler(LSL_Integer flags)
12962 { 12635 {
12963 m_host.AddScriptLPS(1); 12636 m_host.AddScriptLPS(1);
12964 //NotImplemented("llScriptProfiler"); 12637 // This does nothing for LSO scripts in SL
12638 }
12639
12640 #region Not Implemented
12641 //
12642 // Listing the unimplemented lsl functions here, please move
12643 // them from this region as they are completed
12644 //
12645
12646 public void llGetEnv(LSL_String name)
12647 {
12648 m_host.AddScriptLPS(1);
12649 NotImplemented("llGetEnv");
12965 } 12650 }
12966 12651
12967 public void llSetSoundQueueing(int queue) 12652 public void llSetSoundQueueing(int queue)
@@ -13041,8 +12726,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13041 12726
13042 try 12727 try
13043 { 12728 {
13044 UUID invItemID=InventorySelf(); 12729 TaskInventoryItem item = m_item;
13045 if (invItemID == UUID.Zero) 12730 if (item == null)
13046 { 12731 {
13047 replydata = "SERVICE_ERROR"; 12732 replydata = "SERVICE_ERROR";
13048 return; 12733 return;
@@ -13050,10 +12735,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13050 12735
13051 m_host.AddScriptLPS(1); 12736 m_host.AddScriptLPS(1);
13052 12737
13053 m_host.TaskInventory.LockItemsForRead(true);
13054 TaskInventoryItem item = m_host.TaskInventory[invItemID];
13055 m_host.TaskInventory.LockItemsForRead(false);
13056
13057 if (item.PermsGranter == UUID.Zero) 12738 if (item.PermsGranter == UUID.Zero)
13058 { 12739 {
13059 replydata = "MISSING_PERMISSION_DEBIT"; 12740 replydata = "MISSING_PERMISSION_DEBIT";
@@ -13095,7 +12776,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13095 } 12776 }
13096 finally 12777 finally
13097 { 12778 {
13098 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 12779 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
13099 "transaction_result", new Object[] { 12780 "transaction_result", new Object[] {
13100 new LSL_String(txn.ToString()), 12781 new LSL_String(txn.ToString()),
13101 new LSL_Integer(replycode), 12782 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..77b659b 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,23 @@ 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
2687 /// <summary> 2728 /// <summary>
2688 /// Save the current appearance of the script owner permanently to the named notecard. 2729 /// Save the current appearance of the script owner permanently to the named notecard.
2689 /// </summary> 2730 /// </summary>
@@ -2835,21 +2876,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2835 CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar"); 2876 CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
2836 m_host.AddScriptLPS(1); 2877 m_host.AddScriptLPS(1);
2837 2878
2838 if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID)) 2879 World.ForEachRootScenePresence(delegate(ScenePresence sp)
2839 { 2880 {
2840 World.ForEachRootScenePresence(delegate(ScenePresence sp) 2881 if (sp.Firstname == FirstName && sp.Lastname == SurName)
2841 { 2882 {
2842 if (sp.Firstname == FirstName && sp.Lastname == SurName) 2883 // kick client...
2843 { 2884 if (alert != null)
2844 // kick client... 2885 sp.ControllingClient.Kick(alert);
2845 if (alert != null)
2846 sp.ControllingClient.Kick(alert);
2847 2886
2848 // ...and close on our side 2887 // ...and close on our side
2849 sp.Scene.IncomingCloseAgent(sp.UUID); 2888 sp.Scene.IncomingCloseAgent(sp.UUID);
2850 } 2889 }
2851 }); 2890 });
2852 }
2853 } 2891 }
2854 2892
2855 public void osCauseDamage(string avatar, double damage) 2893 public void osCauseDamage(string avatar, double damage)
@@ -3095,5 +3133,132 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3095 3133
3096 return ScriptBaseClass.TRUE; 3134 return ScriptBaseClass.TRUE;
3097 } 3135 }
3136
3137 /// <summary>
3138 /// Sets terrain estate texture
3139 /// </summary>
3140 /// <param name="level"></param>
3141 /// <param name="texture"></param>
3142 /// <returns></returns>
3143 public void osSetTerrainTexture(int level, LSL_Key texture)
3144 {
3145 CheckThreatLevel(ThreatLevel.High, "osSetTerrainTexture");
3146
3147 m_host.AddScriptLPS(1);
3148 //Check to make sure that the script's owner is the estate manager/master
3149 //World.Permissions.GenericEstatePermission(
3150 if (World.Permissions.IsGod(m_host.OwnerID))
3151 {
3152 if (level < 0 || level > 3)
3153 return;
3154
3155 UUID textureID = new UUID();
3156 if (!UUID.TryParse(texture, out textureID))
3157 return;
3158
3159 // estate module is required
3160 IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
3161 if (estate != null)
3162 estate.setEstateTerrainBaseTexture(level, textureID);
3163 }
3164 }
3165
3166 /// <summary>
3167 /// Sets terrain heights of estate
3168 /// </summary>
3169 /// <param name="corner"></param>
3170 /// <param name="low"></param>
3171 /// <param name="high"></param>
3172 /// <returns></returns>
3173 public void osSetTerrainTextureHeight(int corner, double low, double high)
3174 {
3175 CheckThreatLevel(ThreatLevel.High, "osSetTerrainTextureHeight");
3176
3177 m_host.AddScriptLPS(1);
3178 //Check to make sure that the script's owner is the estate manager/master
3179 //World.Permissions.GenericEstatePermission(
3180 if (World.Permissions.IsGod(m_host.OwnerID))
3181 {
3182 if (corner < 0 || corner > 3)
3183 return;
3184
3185 // estate module is required
3186 IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
3187 if (estate != null)
3188 estate.setEstateTerrainTextureHeights(corner, (float)low, (float)high);
3189 }
3190 }
3191
3192 public void osForceAttachToAvatar(int attachmentPoint)
3193 {
3194 CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar");
3195
3196 m_host.AddScriptLPS(1);
3197
3198 InitLSL();
3199 ((LSL_Api)m_LSL_Api).AttachToAvatar(attachmentPoint);
3200 }
3201
3202 public void osForceAttachToAvatarFromInventory(string itemName, int attachmentPoint)
3203 {
3204 CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatarFromInventory");
3205
3206 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3207
3208 if (attachmentsModule == null)
3209 return;
3210
3211 m_host.AddScriptLPS(1);
3212
3213 InitLSL();
3214
3215 TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
3216
3217 if (item == null)
3218 {
3219 ((LSL_Api)m_LSL_Api).llSay(0, string.Format("Could not find object '{0}'", itemName));
3220 throw new Exception(String.Format("The inventory item '{0}' could not be found", itemName));
3221 }
3222
3223 if (item.InvType != (int)InventoryType.Object)
3224 {
3225 // FIXME: Temporary null check for regression tests since they dont' have the infrastructure to set
3226 // up the api reference.
3227 if (m_LSL_Api != null)
3228 ((LSL_Api)m_LSL_Api).llSay(0, string.Format("Unable to attach, item '{0}' is not an object.", itemName));
3229
3230 throw new Exception(String.Format("The inventory item '{0}' is not an object", itemName));
3231
3232 return;
3233 }
3234
3235 ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
3236
3237 if (sp == null)
3238 return;
3239
3240 InventoryItemBase newItem = World.MoveTaskInventoryItem(sp.UUID, UUID.Zero, m_host, item.ItemID);
3241
3242 if (newItem == null)
3243 {
3244 m_log.ErrorFormat(
3245 "[OSSL API]: Could not create user inventory item {0} for {1}, attach point {2} in {3}",
3246 itemName, m_host.Name, attachmentPoint, World.Name);
3247
3248 return;
3249 }
3250
3251 attachmentsModule.RezSingleAttachmentFromInventory(sp, newItem.ID, (uint)attachmentPoint);
3252 }
3253
3254 public void osForceDetachFromAvatar()
3255 {
3256 CheckThreatLevel(ThreatLevel.High, "osForceDetachFromAvatar");
3257
3258 m_host.AddScriptLPS(1);
3259
3260 InitLSL();
3261 ((LSL_Api)m_LSL_Api).DetachFromAvatar();
3262 }
3098 } 3263 }
3099} 3264}
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..a790cdc 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -98,6 +98,27 @@ 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 checking 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 the inventory item in the object containing this script to the avatar that owns it without checking for PERMISSION_ATTACH
111 /// </summary>
112 /// <param name='itemName'>Tha name of the item. If this is not found then a warning is said to the owner</param>
113 /// <param name='attachment'>The attachment point. For example, ATTACH_CHEST</param>
114 void osForceAttachToAvatarFromInventory(string itemName, int attachment);
115
116 /// <summary>
117 /// Detach the object containing this script from the avatar it is attached to without checking for PERMISSION_ATTACH
118 /// </summary>
119 /// <remarks>Nothing happens if the object is not attached.</remarks>
120 void osForceDetachFromAvatar();
121
101 //texture draw functions 122 //texture draw functions
102 string osMovePen(string drawList, int x, int y); 123 string osMovePen(string drawList, int x, int y);
103 string osDrawLine(string drawList, int startX, int startY, int endX, int endY); 124 string osDrawLine(string drawList, int startX, int startY, int endX, int endY);
@@ -203,11 +224,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
203 void osNpcSetRot(LSL_Key npc, rotation rot); 224 void osNpcSetRot(LSL_Key npc, rotation rot);
204 void osNpcStopMoveToTarget(LSL_Key npc); 225 void osNpcStopMoveToTarget(LSL_Key npc);
205 void osNpcSay(key npc, string message); 226 void osNpcSay(key npc, string message);
227 void osNpcSay(key npc, int channel, string message);
228 void osNpcShout(key npc, int channel, string message);
206 void osNpcSit(key npc, key target, int options); 229 void osNpcSit(key npc, key target, int options);
207 void osNpcStand(LSL_Key npc); 230 void osNpcStand(LSL_Key npc);
208 void osNpcRemove(key npc); 231 void osNpcRemove(key npc);
209 void osNpcPlayAnimation(LSL_Key npc, string animation); 232 void osNpcPlayAnimation(LSL_Key npc, string animation);
210 void osNpcStopAnimation(LSL_Key npc, string animation); 233 void osNpcStopAnimation(LSL_Key npc, string animation);
234 void osNpcWhisper(key npc, int channel, string message);
211 235
212 LSL_Key osOwnerSaveAppearance(string notecard); 236 LSL_Key osOwnerSaveAppearance(string notecard);
213 LSL_Key osAgentSaveAppearance(key agentId, string notecard); 237 LSL_Key osAgentSaveAppearance(key agentId, string notecard);
@@ -234,5 +258,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
234 258
235 LSL_Integer osInviteToGroup(LSL_Key agentId); 259 LSL_Integer osInviteToGroup(LSL_Key agentId);
236 LSL_Integer osEjectFromGroup(LSL_Key agentId); 260 LSL_Integer osEjectFromGroup(LSL_Key agentId);
261
262 void osSetTerrainTexture(int level, LSL_Key texture);
263 void osSetTerrainTextureHeight(int corner, double low, double high);
237 } 264 }
238} 265}
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..500ed96 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -289,8 +289,24 @@ 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 osForceDetachFromAvatar()
305 {
306 m_OSSL_Functions.osForceDetachFromAvatar();
307 }
308
309 // Texture Draw functions
294 310
295 public string osMovePen(string drawList, int x, int y) 311 public string osMovePen(string drawList, int x, int y)
296 { 312 {
@@ -569,6 +585,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
569 m_OSSL_Functions.osNpcSay(npc, message); 585 m_OSSL_Functions.osNpcSay(npc, message);
570 } 586 }
571 587
588 public void osNpcSay(key npc, int channel, string message)
589 {
590 m_OSSL_Functions.osNpcSay(npc, channel, message);
591 }
592
593
594 public void osNpcShout(key npc, int channel, string message)
595 {
596 m_OSSL_Functions.osNpcShout(npc, channel, message);
597 }
598
572 public void osNpcSit(LSL_Key npc, LSL_Key target, int options) 599 public void osNpcSit(LSL_Key npc, LSL_Key target, int options)
573 { 600 {
574 m_OSSL_Functions.osNpcSit(npc, target, options); 601 m_OSSL_Functions.osNpcSit(npc, target, options);
@@ -594,6 +621,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
594 m_OSSL_Functions.osNpcStopAnimation(npc, animation); 621 m_OSSL_Functions.osNpcStopAnimation(npc, animation);
595 } 622 }
596 623
624 public void osNpcWhisper(key npc, int channel, string message)
625 {
626 m_OSSL_Functions.osNpcWhisper(npc, channel, message);
627 }
628
597 public LSL_Key osOwnerSaveAppearance(string notecard) 629 public LSL_Key osOwnerSaveAppearance(string notecard)
598 { 630 {
599 return m_OSSL_Functions.osOwnerSaveAppearance(notecard); 631 return m_OSSL_Functions.osOwnerSaveAppearance(notecard);
@@ -878,5 +910,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
878 { 910 {
879 return m_OSSL_Functions.osEjectFromGroup(agentId); 911 return m_OSSL_Functions.osEjectFromGroup(agentId);
880 } 912 }
913
914 public void osSetTerrainTexture(int level, LSL_Key texture)
915 {
916 m_OSSL_Functions.osSetTerrainTexture(level, texture);
917 }
918
919 public void osSetTerrainTextureHeight(int corner, double low, double high)
920 {
921 m_OSSL_Functions.osSetTerrainTextureHeight(corner, low, high);
922 }
881 } 923 }
882} 924}
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..3965734 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();
@@ -95,7 +95,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
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);
@@ -130,7 +130,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
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);
@@ -161,7 +161,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
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
@@ -202,7 +202,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
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..537b8aa
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs
@@ -0,0 +1,178 @@
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 e)
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} \ 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..813e53b 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();
@@ -104,10 +106,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
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);
@@ -151,7 +153,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
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);