aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs19
-rw-r--r--OpenSim/Region/ScriptEngine/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.cs861
-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.cs292
-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.cs20
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs25
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs39
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs9
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs8
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs139
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs7
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs8
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs100
21 files changed, 917 insertions, 733 deletions
diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs
index bb5bacc..2027ca6 100644
--- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs
+++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs
@@ -27,17 +27,22 @@
27 27
28using System; 28using System;
29using OpenMetaverse; 29using OpenMetaverse;
30using OpenSim.Framework;
30using OpenSim.Region.Framework.Scenes; 31using OpenSim.Region.Framework.Scenes;
31 32
32
33namespace OpenSim.Region.ScriptEngine.Interfaces 33namespace OpenSim.Region.ScriptEngine.Interfaces
34{ 34{
35 public interface IScriptApi 35 public interface IScriptApi
36 { 36 {
37 // 37 /// <summary>
38 // Each API has an identifier, which is used to load the 38 /// Initialize the API
39 // proper runtime assembly at load time. 39 /// </summary>
40 // 40 /// <remarks>
41 void Initialize(IScriptEngine engine, SceneObjectPart part, uint localID, UUID item); 41 /// Each API has an identifier, which is used to load the
42 /// proper runtime assembly at load time.
43 /// <param name='engine'>/param>
44 /// <param name='part'></param>
45 /// <param name='item'></param>
46 void Initialize(IScriptEngine engine, SceneObjectPart part, TaskInventoryItem item);
42 } 47 }
43} 48} \ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/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 d83b05d..5905958 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)
@@ -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 380
413 381 if (item != null && item.Type == type)
414 m_host.TaskInventory.LockItemsForRead(true); 382 return item.AssetID;
415 383 else
416 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 384 return UUID.Zero;
417 {
418 if (inv.Value.Name == name)
419 {
420 m_host.TaskInventory.LockItemsForRead(false);
421 return inv.Value.AssetID;
422 }
423 }
424
425 m_host.TaskInventory.LockItemsForRead(false);
426
427
428 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
@@ -963,20 +921,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
963 921
964 public void llRegionSayTo(string target, int channel, string msg) 922 public void llRegionSayTo(string target, int channel, string msg)
965 { 923 {
966 string error = String.Empty;
967
968 if (msg.Length > 1023) 924 if (msg.Length > 1023)
969 msg = msg.Substring(0, 1023); 925 msg = msg.Substring(0, 1023);
970 926
971 m_host.AddScriptLPS(1); 927 m_host.AddScriptLPS(1);
972 928
929 if (channel == ScriptBaseClass.DEBUG_CHANNEL)
930 {
931 return;
932 }
933
973 UUID TargetID; 934 UUID TargetID;
974 UUID.TryParse(target, out TargetID); 935 UUID.TryParse(target, out TargetID);
975 936
976 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 937 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
977 if (wComm != null) 938 if (wComm != null)
978 if (!wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg, out error)) 939 wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg);
979 LSLError(error);
980 } 940 }
981 941
982 public LSL_Integer llListen(int channelID, string name, string ID, string msg) 942 public LSL_Integer llListen(int channelID, string name, string ID, string msg)
@@ -986,7 +946,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
986 UUID.TryParse(ID, out keyID); 946 UUID.TryParse(ID, out keyID);
987 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 947 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
988 if (wComm != null) 948 if (wComm != null)
989 return wComm.Listen(m_localID, m_itemID, m_host.UUID, channelID, name, keyID, msg); 949 return wComm.Listen(m_host.LocalId, m_item.ItemID, m_host.UUID, channelID, name, keyID, msg);
990 else 950 else
991 return -1; 951 return -1;
992 } 952 }
@@ -996,7 +956,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
996 m_host.AddScriptLPS(1); 956 m_host.AddScriptLPS(1);
997 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 957 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
998 if (wComm != null) 958 if (wComm != null)
999 wComm.ListenControl(m_itemID, number, active); 959 wComm.ListenControl(m_item.ItemID, number, active);
1000 } 960 }
1001 961
1002 public void llListenRemove(int number) 962 public void llListenRemove(int number)
@@ -1004,7 +964,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1004 m_host.AddScriptLPS(1); 964 m_host.AddScriptLPS(1);
1005 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 965 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
1006 if (wComm != null) 966 if (wComm != null)
1007 wComm.ListenRemove(m_itemID, number); 967 wComm.ListenRemove(m_item.ItemID, number);
1008 } 968 }
1009 969
1010 public void llSensor(string name, string id, int type, double range, double arc) 970 public void llSensor(string name, string id, int type, double range, double arc)
@@ -1013,7 +973,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1013 UUID keyID = UUID.Zero; 973 UUID keyID = UUID.Zero;
1014 UUID.TryParse(id, out keyID); 974 UUID.TryParse(id, out keyID);
1015 975
1016 AsyncCommands.SensorRepeatPlugin.SenseOnce(m_localID, m_itemID, name, keyID, type, range, arc, m_host); 976 AsyncCommands.SensorRepeatPlugin.SenseOnce(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, m_host);
1017 } 977 }
1018 978
1019 public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate) 979 public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
@@ -1022,13 +982,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1022 UUID keyID = UUID.Zero; 982 UUID keyID = UUID.Zero;
1023 UUID.TryParse(id, out keyID); 983 UUID.TryParse(id, out keyID);
1024 984
1025 AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_localID, m_itemID, name, keyID, type, range, arc, rate, m_host); 985 AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, rate, m_host);
1026 } 986 }
1027 987
1028 public void llSensorRemove() 988 public void llSensorRemove()
1029 { 989 {
1030 m_host.AddScriptLPS(1); 990 m_host.AddScriptLPS(1);
1031 AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_localID, m_itemID); 991 AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_host.LocalId, m_item.ItemID);
1032 } 992 }
1033 993
1034 public string resolveName(UUID objecUUID) 994 public string resolveName(UUID objecUUID)
@@ -1069,7 +1029,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1069 public LSL_String llDetectedName(int number) 1029 public LSL_String llDetectedName(int number)
1070 { 1030 {
1071 m_host.AddScriptLPS(1); 1031 m_host.AddScriptLPS(1);
1072 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1032 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1073 if (detectedParams == null) 1033 if (detectedParams == null)
1074 return String.Empty; 1034 return String.Empty;
1075 return detectedParams.Name; 1035 return detectedParams.Name;
@@ -1078,7 +1038,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1078 public LSL_String llDetectedKey(int number) 1038 public LSL_String llDetectedKey(int number)
1079 { 1039 {
1080 m_host.AddScriptLPS(1); 1040 m_host.AddScriptLPS(1);
1081 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1041 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1082 if (detectedParams == null) 1042 if (detectedParams == null)
1083 return String.Empty; 1043 return String.Empty;
1084 return detectedParams.Key.ToString(); 1044 return detectedParams.Key.ToString();
@@ -1087,7 +1047,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1087 public LSL_String llDetectedOwner(int number) 1047 public LSL_String llDetectedOwner(int number)
1088 { 1048 {
1089 m_host.AddScriptLPS(1); 1049 m_host.AddScriptLPS(1);
1090 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1050 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1091 if (detectedParams == null) 1051 if (detectedParams == null)
1092 return String.Empty; 1052 return String.Empty;
1093 return detectedParams.Owner.ToString(); 1053 return detectedParams.Owner.ToString();
@@ -1096,7 +1056,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1096 public LSL_Integer llDetectedType(int number) 1056 public LSL_Integer llDetectedType(int number)
1097 { 1057 {
1098 m_host.AddScriptLPS(1); 1058 m_host.AddScriptLPS(1);
1099 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1059 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1100 if (detectedParams == null) 1060 if (detectedParams == null)
1101 return 0; 1061 return 0;
1102 return new LSL_Integer(detectedParams.Type); 1062 return new LSL_Integer(detectedParams.Type);
@@ -1105,7 +1065,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1105 public LSL_Vector llDetectedPos(int number) 1065 public LSL_Vector llDetectedPos(int number)
1106 { 1066 {
1107 m_host.AddScriptLPS(1); 1067 m_host.AddScriptLPS(1);
1108 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1068 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1109 if (detectedParams == null) 1069 if (detectedParams == null)
1110 return new LSL_Vector(); 1070 return new LSL_Vector();
1111 return detectedParams.Position; 1071 return detectedParams.Position;
@@ -1114,7 +1074,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1114 public LSL_Vector llDetectedVel(int number) 1074 public LSL_Vector llDetectedVel(int number)
1115 { 1075 {
1116 m_host.AddScriptLPS(1); 1076 m_host.AddScriptLPS(1);
1117 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1077 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1118 if (detectedParams == null) 1078 if (detectedParams == null)
1119 return new LSL_Vector(); 1079 return new LSL_Vector();
1120 return detectedParams.Velocity; 1080 return detectedParams.Velocity;
@@ -1123,7 +1083,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1123 public LSL_Vector llDetectedGrab(int number) 1083 public LSL_Vector llDetectedGrab(int number)
1124 { 1084 {
1125 m_host.AddScriptLPS(1); 1085 m_host.AddScriptLPS(1);
1126 DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number); 1086 DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1127 if (parms == null) 1087 if (parms == null)
1128 return new LSL_Vector(0, 0, 0); 1088 return new LSL_Vector(0, 0, 0);
1129 1089
@@ -1133,7 +1093,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1133 public LSL_Rotation llDetectedRot(int number) 1093 public LSL_Rotation llDetectedRot(int number)
1134 { 1094 {
1135 m_host.AddScriptLPS(1); 1095 m_host.AddScriptLPS(1);
1136 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1096 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1137 if (detectedParams == null) 1097 if (detectedParams == null)
1138 return new LSL_Rotation(); 1098 return new LSL_Rotation();
1139 return detectedParams.Rotation; 1099 return detectedParams.Rotation;
@@ -1142,7 +1102,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1142 public LSL_Integer llDetectedGroup(int number) 1102 public LSL_Integer llDetectedGroup(int number)
1143 { 1103 {
1144 m_host.AddScriptLPS(1); 1104 m_host.AddScriptLPS(1);
1145 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1105 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1146 if (detectedParams == null) 1106 if (detectedParams == null)
1147 return new LSL_Integer(0); 1107 return new LSL_Integer(0);
1148 if (m_host.GroupID == detectedParams.Group) 1108 if (m_host.GroupID == detectedParams.Group)
@@ -1153,7 +1113,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1153 public LSL_Integer llDetectedLinkNumber(int number) 1113 public LSL_Integer llDetectedLinkNumber(int number)
1154 { 1114 {
1155 m_host.AddScriptLPS(1); 1115 m_host.AddScriptLPS(1);
1156 DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number); 1116 DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1157 if (parms == null) 1117 if (parms == null)
1158 return new LSL_Integer(0); 1118 return new LSL_Integer(0);
1159 1119
@@ -1166,7 +1126,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1166 public LSL_Vector llDetectedTouchBinormal(int index) 1126 public LSL_Vector llDetectedTouchBinormal(int index)
1167 { 1127 {
1168 m_host.AddScriptLPS(1); 1128 m_host.AddScriptLPS(1);
1169 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1129 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1170 if (detectedParams == null) 1130 if (detectedParams == null)
1171 return new LSL_Vector(); 1131 return new LSL_Vector();
1172 return detectedParams.TouchBinormal; 1132 return detectedParams.TouchBinormal;
@@ -1178,7 +1138,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1178 public LSL_Integer llDetectedTouchFace(int index) 1138 public LSL_Integer llDetectedTouchFace(int index)
1179 { 1139 {
1180 m_host.AddScriptLPS(1); 1140 m_host.AddScriptLPS(1);
1181 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1141 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1182 if (detectedParams == null) 1142 if (detectedParams == null)
1183 return new LSL_Integer(-1); 1143 return new LSL_Integer(-1);
1184 return new LSL_Integer(detectedParams.TouchFace); 1144 return new LSL_Integer(detectedParams.TouchFace);
@@ -1190,7 +1150,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1190 public LSL_Vector llDetectedTouchNormal(int index) 1150 public LSL_Vector llDetectedTouchNormal(int index)
1191 { 1151 {
1192 m_host.AddScriptLPS(1); 1152 m_host.AddScriptLPS(1);
1193 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1153 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1194 if (detectedParams == null) 1154 if (detectedParams == null)
1195 return new LSL_Vector(); 1155 return new LSL_Vector();
1196 return detectedParams.TouchNormal; 1156 return detectedParams.TouchNormal;
@@ -1202,7 +1162,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1202 public LSL_Vector llDetectedTouchPos(int index) 1162 public LSL_Vector llDetectedTouchPos(int index)
1203 { 1163 {
1204 m_host.AddScriptLPS(1); 1164 m_host.AddScriptLPS(1);
1205 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1165 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1206 if (detectedParams == null) 1166 if (detectedParams == null)
1207 return new LSL_Vector(); 1167 return new LSL_Vector();
1208 return detectedParams.TouchPos; 1168 return detectedParams.TouchPos;
@@ -1214,7 +1174,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1214 public LSL_Vector llDetectedTouchST(int index) 1174 public LSL_Vector llDetectedTouchST(int index)
1215 { 1175 {
1216 m_host.AddScriptLPS(1); 1176 m_host.AddScriptLPS(1);
1217 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1177 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1218 if (detectedParams == null) 1178 if (detectedParams == null)
1219 return new LSL_Vector(-1.0, -1.0, 0.0); 1179 return new LSL_Vector(-1.0, -1.0, 0.0);
1220 return detectedParams.TouchST; 1180 return detectedParams.TouchST;
@@ -1226,7 +1186,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1226 public LSL_Vector llDetectedTouchUV(int index) 1186 public LSL_Vector llDetectedTouchUV(int index)
1227 { 1187 {
1228 m_host.AddScriptLPS(1); 1188 m_host.AddScriptLPS(1);
1229 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1189 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1230 if (detectedParams == null) 1190 if (detectedParams == null)
1231 return new LSL_Vector(-1.0, -1.0, 0.0); 1191 return new LSL_Vector(-1.0, -1.0, 0.0);
1232 return detectedParams.TouchUV; 1192 return detectedParams.TouchUV;
@@ -1929,12 +1889,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1929 1889
1930 return rgb; 1890 return rgb;
1931 } 1891 }
1892
1932 if (face >= 0 && face < GetNumberOfSides(part)) 1893 if (face >= 0 && face < GetNumberOfSides(part))
1933 { 1894 {
1934 texcolor = tex.GetFace((uint)face).RGBA; 1895 texcolor = tex.GetFace((uint)face).RGBA;
1935 rgb.x = texcolor.R; 1896 rgb.x = texcolor.R;
1936 rgb.y = texcolor.G; 1897 rgb.y = texcolor.G;
1937 rgb.z = texcolor.B; 1898 rgb.z = texcolor.B;
1899
1938 return rgb; 1900 return rgb;
1939 } 1901 }
1940 else 1902 else
@@ -2974,20 +2936,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2974 2936
2975 public LSL_Integer llGiveMoney(string destination, int amount) 2937 public LSL_Integer llGiveMoney(string destination, int amount)
2976 { 2938 {
2977 UUID invItemID=InventorySelf();
2978 if (invItemID == UUID.Zero)
2979 return 0;
2980
2981 m_host.AddScriptLPS(1); 2939 m_host.AddScriptLPS(1);
2982 2940
2983 m_host.TaskInventory.LockItemsForRead(true); 2941 if (m_item.PermsGranter == UUID.Zero)
2984 TaskInventoryItem item = m_host.TaskInventory[invItemID];
2985 m_host.TaskInventory.LockItemsForRead(false);
2986
2987 if (item.PermsGranter == UUID.Zero)
2988 return 0; 2942 return 0;
2989 2943
2990 if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0) 2944 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
2991 { 2945 {
2992 LSLError("No permissions to give money"); 2946 LSLError("No permissions to give money");
2993 return 0; 2947 return 0;
@@ -3175,11 +3129,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3175 sec = m_MinTimerInterval; 3129 sec = m_MinTimerInterval;
3176 m_host.AddScriptLPS(1); 3130 m_host.AddScriptLPS(1);
3177 // Setting timer repeat 3131 // Setting timer repeat
3178 AsyncCommands.TimerPlugin.SetTimerEvent(m_localID, m_itemID, sec); 3132 AsyncCommands.TimerPlugin.SetTimerEvent(m_host.LocalId, m_item.ItemID, sec);
3179 } 3133 }
3180 3134
3181 public virtual void llSleep(double sec) 3135 public virtual void llSleep(double sec)
3182 { 3136 {
3137// m_log.Info("llSleep snoozing " + sec + "s.");
3183 m_host.AddScriptLPS(1); 3138 m_host.AddScriptLPS(1);
3184 Thread.Sleep((int)(sec * 1000)); 3139 Thread.Sleep((int)(sec * 1000));
3185 } 3140 }
@@ -3238,29 +3193,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3238 3193
3239 public void llTakeControls(int controls, int accept, int pass_on) 3194 public void llTakeControls(int controls, int accept, int pass_on)
3240 { 3195 {
3241 TaskInventoryItem item; 3196 if (m_item.PermsGranter != UUID.Zero)
3242
3243 m_host.TaskInventory.LockItemsForRead(true);
3244 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3245 { 3197 {
3246 m_host.TaskInventory.LockItemsForRead(false); 3198 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3247 return;
3248 }
3249 else
3250 {
3251 item = m_host.TaskInventory[InventorySelf()];
3252 }
3253 m_host.TaskInventory.LockItemsForRead(false);
3254
3255 if (item.PermsGranter != UUID.Zero)
3256 {
3257 ScenePresence presence = World.GetScenePresence(item.PermsGranter);
3258 3199
3259 if (presence != null) 3200 if (presence != null)
3260 { 3201 {
3261 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 3202 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
3262 { 3203 {
3263 presence.RegisterControlEventsToScript(controls, accept, pass_on, m_localID, m_itemID); 3204 presence.RegisterControlEventsToScript(controls, accept, pass_on, m_host.LocalId, m_item.ItemID);
3264 } 3205 }
3265 } 3206 }
3266 } 3207 }
@@ -3270,38 +3211,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3270 3211
3271 public void llReleaseControls() 3212 public void llReleaseControls()
3272 { 3213 {
3273 TaskInventoryItem item;
3274
3275 m_host.TaskInventory.LockItemsForRead(true);
3276 lock (m_host.TaskInventory)
3277 {
3278
3279 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3280 {
3281 m_host.TaskInventory.LockItemsForRead(false);
3282 return;
3283 }
3284 else
3285 {
3286 item = m_host.TaskInventory[InventorySelf()];
3287 }
3288 }
3289 m_host.TaskInventory.LockItemsForRead(false);
3290
3291 m_host.AddScriptLPS(1); 3214 m_host.AddScriptLPS(1);
3292 3215
3293 if (item.PermsGranter != UUID.Zero) 3216 if (m_item.PermsGranter != UUID.Zero)
3294 { 3217 {
3295 ScenePresence presence = World.GetScenePresence(item.PermsGranter); 3218 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3296 3219
3297 if (presence != null) 3220 if (presence != null)
3298 { 3221 {
3299 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 3222 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
3300 { 3223 {
3301 // Unregister controls from Presence 3224 // Unregister controls from Presence
3302 presence.UnRegisterControlEventsToScript(m_localID, m_itemID); 3225 presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
3303 // Remove Take Control permission. 3226 // Remove Take Control permission.
3304 item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS; 3227 m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
3305 } 3228 }
3306 } 3229 }
3307 } 3230 }
@@ -3314,86 +3237,71 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3314 m_UrlModule.ReleaseURL(url); 3237 m_UrlModule.ReleaseURL(url);
3315 } 3238 }
3316 3239
3317 public void llAttachToAvatar(int attachment) 3240 /// <summary>
3241 /// Attach the object containing this script to the avatar that owns it.
3242 /// </summary>
3243 /// <param name='attachment'>The attachment point (e.g. ATTACH_CHEST)</param>
3244 /// <returns>true if the attach suceeded, false if it did not</returns>
3245 public bool AttachToAvatar(int attachmentPoint)
3318 { 3246 {
3319 m_host.AddScriptLPS(1); 3247 SceneObjectGroup grp = m_host.ParentGroup;
3248 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
3320 3249
3321 TaskInventoryItem item; 3250 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3322
3323 m_host.TaskInventory.LockItemsForRead(true);
3324 3251
3325 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3252 if (attachmentsModule != null)
3326 { 3253 return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true);
3327 m_host.TaskInventory.LockItemsForRead(false);
3328 return;
3329 }
3330 else 3254 else
3331 { 3255 return false;
3332 item = m_host.TaskInventory[InventorySelf()]; 3256 }
3333 }
3334
3335 m_host.TaskInventory.LockItemsForRead(false);
3336 3257
3337 if (item.PermsGranter != m_host.OwnerID) 3258 /// <summary>
3338 return; 3259 /// Detach the object containing this script from the avatar it is attached to.
3260 /// </summary>
3261 /// <remarks>
3262 /// Nothing happens if the object is not attached.
3263 /// </remarks>
3264 public void DetachFromAvatar()
3265 {
3266 Util.FireAndForget(DetachWrapper, m_host);
3267 }
3339 3268
3340 if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0) 3269 private void DetachWrapper(object o)
3341 { 3270 {
3342 SceneObjectGroup grp = m_host.ParentGroup; 3271 SceneObjectPart host = (SceneObjectPart)o;
3343 3272
3344 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 3273 SceneObjectGroup grp = host.ParentGroup;
3274 UUID itemID = grp.FromItemID;
3275 ScenePresence presence = World.GetScenePresence(host.OwnerID);
3345 3276
3346 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; 3277 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3347 if (attachmentsModule != null) 3278 if (attachmentsModule != null)
3348 attachmentsModule.AttachObject(presence, grp, (uint)attachment, false, true); 3279 attachmentsModule.DetachSingleAttachmentToInv(presence, itemID);
3349 }
3350 } 3280 }
3351 3281
3352 public void llDetachFromAvatar() 3282 public void llAttachToAvatar(int attachmentPoint)
3353 { 3283 {
3354 m_host.AddScriptLPS(1); 3284 m_host.AddScriptLPS(1);
3355 3285
3356 if (m_host.ParentGroup.AttachmentPoint == 0) 3286 if (m_item.PermsGranter != m_host.OwnerID)
3357 return; 3287 return;
3358 3288
3359 TaskInventoryItem item; 3289 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
3290 AttachToAvatar(attachmentPoint);
3291 }
3360 3292
3361 m_host.TaskInventory.LockItemsForRead(true); 3293 public void llDetachFromAvatar()
3294 {
3295 m_host.AddScriptLPS(1);
3362 3296
3363 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3297 if (m_host.ParentGroup.AttachmentPoint == 0)
3364 {
3365 m_host.TaskInventory.LockItemsForRead(false);
3366 return; 3298 return;
3367 }
3368 else
3369 {
3370 item = m_host.TaskInventory[InventorySelf()];
3371 }
3372 m_host.TaskInventory.LockItemsForRead(false);
3373
3374 3299
3375 if (item.PermsGranter != m_host.OwnerID) 3300 if (m_item.PermsGranter != m_host.OwnerID)
3376 return; 3301 return;
3377 3302
3378 if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0) 3303 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
3379 { 3304 DetachFromAvatar();
3380 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3381 if (attachmentsModule != null)
3382 Util.FireAndForget(DetachWrapper, m_host);
3383 }
3384 }
3385
3386 private void DetachWrapper(object o)
3387 {
3388 SceneObjectPart host = (SceneObjectPart)o;
3389
3390 SceneObjectGroup grp = host.ParentGroup;
3391 UUID itemID = grp.FromItemID;
3392 ScenePresence presence = World.GetScenePresence(host.OwnerID);
3393
3394 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3395 if (attachmentsModule != null)
3396 attachmentsModule.DetachSingleAttachmentToInv(presence, itemID);
3397 } 3305 }
3398 3306
3399 public void llTakeCamera(string avatar) 3307 public void llTakeCamera(string avatar)
@@ -3514,7 +3422,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3514 } 3422 }
3515 3423
3516 emailModule.SendEmail(m_host.UUID, address, subject, message); 3424 emailModule.SendEmail(m_host.UUID, address, subject, message);
3517 ScriptSleep(15000); 3425 ScriptSleep(EMAIL_PAUSE_TIME * 1000);
3518 } 3426 }
3519 3427
3520 public void llGetNextEmail(string address, string subject) 3428 public void llGetNextEmail(string address, string subject)
@@ -3551,6 +3459,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3551 return m_host.UUID.ToString(); 3459 return m_host.UUID.ToString();
3552 } 3460 }
3553 3461
3462 public LSL_Key llGenerateKey()
3463 {
3464 m_host.AddScriptLPS(1);
3465 return UUID.Random().ToString();
3466 }
3467
3554 public void llSetBuoyancy(double buoyancy) 3468 public void llSetBuoyancy(double buoyancy)
3555 { 3469 {
3556 m_host.AddScriptLPS(1); 3470 m_host.AddScriptLPS(1);
@@ -3597,7 +3511,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3597 m_host.AddScriptLPS(1); 3511 m_host.AddScriptLPS(1);
3598 try 3512 try
3599 { 3513 {
3600 m_ScriptEngine.SetMinEventDelay(m_itemID, delay); 3514 m_ScriptEngine.SetMinEventDelay(m_item.ItemID, delay);
3601 } 3515 }
3602 catch (NotImplementedException) 3516 catch (NotImplementedException)
3603 { 3517 {
@@ -3650,29 +3564,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3650 { 3564 {
3651 m_host.AddScriptLPS(1); 3565 m_host.AddScriptLPS(1);
3652 3566
3653 UUID invItemID = InventorySelf(); 3567 if (m_item.PermsGranter == UUID.Zero)
3654 if (invItemID == UUID.Zero)
3655 return;
3656
3657 TaskInventoryItem item;
3658
3659 m_host.TaskInventory.LockItemsForRead(true);
3660 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3661 {
3662 m_host.TaskInventory.LockItemsForRead(false);
3663 return;
3664 }
3665 else
3666 {
3667 item = m_host.TaskInventory[InventorySelf()];
3668 }
3669 m_host.TaskInventory.LockItemsForRead(false);
3670 if (item.PermsGranter == UUID.Zero)
3671 return; 3568 return;
3672 3569
3673 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0) 3570 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3674 { 3571 {
3675 ScenePresence presence = World.GetScenePresence(item.PermsGranter); 3572 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3676 3573
3677 if (presence != null) 3574 if (presence != null)
3678 { 3575 {
@@ -3690,41 +3587,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3690 { 3587 {
3691 m_host.AddScriptLPS(1); 3588 m_host.AddScriptLPS(1);
3692 3589
3693 UUID invItemID=InventorySelf(); 3590 if (m_item.PermsGranter == UUID.Zero)
3694 if (invItemID == UUID.Zero)
3695 return; 3591 return;
3696 3592
3697 TaskInventoryItem item; 3593 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3698
3699 m_host.TaskInventory.LockItemsForRead(true);
3700 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3701 { 3594 {
3702 m_host.TaskInventory.LockItemsForRead(false); 3595 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3703 return;
3704 }
3705 else
3706 {
3707 item = m_host.TaskInventory[InventorySelf()];
3708 }
3709 m_host.TaskInventory.LockItemsForRead(false);
3710
3711
3712 if (item.PermsGranter == UUID.Zero)
3713 return;
3714
3715 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3716 {
3717 UUID animID = new UUID();
3718
3719 if (!UUID.TryParse(anim, out animID))
3720 {
3721 animID=InventoryKey(anim);
3722 }
3723
3724 ScenePresence presence = World.GetScenePresence(item.PermsGranter);
3725 3596
3726 if (presence != null) 3597 if (presence != null)
3727 { 3598 {
3599 UUID animID = KeyOrName(anim);
3600
3728 if (animID == UUID.Zero) 3601 if (animID == UUID.Zero)
3729 presence.Animator.RemoveAnimation(anim); 3602 presence.Animator.RemoveAnimation(anim);
3730 else 3603 else
@@ -3757,44 +3630,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3757 public LSL_Integer llGetStartParameter() 3630 public LSL_Integer llGetStartParameter()
3758 { 3631 {
3759 m_host.AddScriptLPS(1); 3632 m_host.AddScriptLPS(1);
3760 return m_ScriptEngine.GetStartParameter(m_itemID); 3633 return m_ScriptEngine.GetStartParameter(m_item.ItemID);
3761 } 3634 }
3762 3635
3763 public void llRequestPermissions(string agent, int perm) 3636 public void llRequestPermissions(string agent, int perm)
3764 { 3637 {
3765 UUID agentID = new UUID(); 3638 UUID agentID;
3766 3639
3767 if (!UUID.TryParse(agent, out agentID)) 3640 if (!UUID.TryParse(agent, out agentID))
3768 return; 3641 return;
3769 3642
3770 UUID invItemID = InventorySelf();
3771
3772 if (invItemID == UUID.Zero)
3773 return; // Not in a prim? How??
3774
3775 TaskInventoryItem item;
3776
3777
3778 m_host.TaskInventory.LockItemsForRead(true);
3779 if (!m_host.TaskInventory.ContainsKey(invItemID))
3780 {
3781 m_host.TaskInventory.LockItemsForRead(false);
3782 return;
3783 }
3784 else
3785 {
3786 item = m_host.TaskInventory[invItemID];
3787 }
3788 m_host.TaskInventory.LockItemsForRead(false);
3789
3790 if (agentID == UUID.Zero || perm == 0) // Releasing permissions 3643 if (agentID == UUID.Zero || perm == 0) // Releasing permissions
3791 { 3644 {
3792 llReleaseControls(); 3645 llReleaseControls();
3793 3646
3794 item.PermsGranter = UUID.Zero; 3647 m_item.PermsGranter = UUID.Zero;
3795 item.PermsMask = 0; 3648 m_item.PermsMask = 0;
3796 3649
3797 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3650 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3798 "run_time_permissions", new Object[] { 3651 "run_time_permissions", new Object[] {
3799 new LSL_Integer(0) }, 3652 new LSL_Integer(0) },
3800 new DetectParams[0])); 3653 new DetectParams[0]));
@@ -3802,7 +3655,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3802 return; 3655 return;
3803 } 3656 }
3804 3657
3805 if (item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3658 if (m_item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3806 llReleaseControls(); 3659 llReleaseControls();
3807 3660
3808 m_host.AddScriptLPS(1); 3661 m_host.AddScriptLPS(1);
@@ -3819,11 +3672,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3819 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3672 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3820 { 3673 {
3821 m_host.TaskInventory.LockItemsForWrite(true); 3674 m_host.TaskInventory.LockItemsForWrite(true);
3822 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3675 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3823 m_host.TaskInventory[invItemID].PermsMask = perm; 3676 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3824 m_host.TaskInventory.LockItemsForWrite(false); 3677 m_host.TaskInventory.LockItemsForWrite(false);
3825 3678
3826 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3679 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3827 "run_time_permissions", new Object[] { 3680 "run_time_permissions", new Object[] {
3828 new LSL_Integer(perm) }, 3681 new LSL_Integer(perm) },
3829 new DetectParams[0])); 3682 new DetectParams[0]));
@@ -3858,11 +3711,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3858 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3711 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3859 { 3712 {
3860 m_host.TaskInventory.LockItemsForWrite(true); 3713 m_host.TaskInventory.LockItemsForWrite(true);
3861 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3714 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3862 m_host.TaskInventory[invItemID].PermsMask = perm; 3715 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3863 m_host.TaskInventory.LockItemsForWrite(false); 3716 m_host.TaskInventory.LockItemsForWrite(false);
3864 3717
3865 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3718 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3866 "run_time_permissions", new Object[] { 3719 "run_time_permissions", new Object[] {
3867 new LSL_Integer(perm) }, 3720 new LSL_Integer(perm) },
3868 new DetectParams[0])); 3721 new DetectParams[0]));
@@ -3873,9 +3726,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3873 } 3726 }
3874 3727
3875 ScenePresence presence = World.GetScenePresence(agentID); 3728 ScenePresence presence = World.GetScenePresence(agentID);
3876
3877 if (presence != null) 3729 if (presence != null)
3878 { 3730 {
3731 // If permissions are being requested from an NPC and were not implicitly granted above then
3732 // auto grant all reuqested permissions if the script is owned by the NPC or the NPCs owner
3733 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
3734 if (npcModule != null && npcModule.IsNPC(agentID, World))
3735 {
3736 if (agentID == m_host.ParentGroup.OwnerID || npcModule.GetOwner(agentID) == m_host.ParentGroup.OwnerID)
3737 {
3738 lock (m_host.TaskInventory)
3739 {
3740 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3741 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3742 }
3743
3744 m_ScriptEngine.PostScriptEvent(
3745 m_item.ItemID,
3746 new EventParams(
3747 "run_time_permissions", new Object[] { new LSL_Integer(perm) }, new DetectParams[0]));
3748 }
3749
3750 // it is an NPC, exit even if the permissions werent granted above, they are not going to answer
3751 // the question!
3752 return;
3753 }
3754
3879 string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID); 3755 string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
3880 if (ownerName == String.Empty) 3756 if (ownerName == String.Empty)
3881 ownerName = "(hippos)"; 3757 ownerName = "(hippos)";
@@ -3883,8 +3759,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3883 if (!m_waitingForScriptAnswer) 3759 if (!m_waitingForScriptAnswer)
3884 { 3760 {
3885 m_host.TaskInventory.LockItemsForWrite(true); 3761 m_host.TaskInventory.LockItemsForWrite(true);
3886 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3762 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3887 m_host.TaskInventory[invItemID].PermsMask = 0; 3763 m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
3888 m_host.TaskInventory.LockItemsForWrite(false); 3764 m_host.TaskInventory.LockItemsForWrite(false);
3889 3765
3890 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 3766 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
@@ -3892,16 +3768,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3892 } 3768 }
3893 3769
3894 presence.ControllingClient.SendScriptQuestion( 3770 presence.ControllingClient.SendScriptQuestion(
3895 m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, invItemID, perm); 3771 m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_item.ItemID, perm);
3896 3772
3897 return; 3773 return;
3898 } 3774 }
3899 3775
3900 // Requested agent is not in range, refuse perms 3776 // Requested agent is not in range, refuse perms
3901 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3777 m_ScriptEngine.PostScriptEvent(
3902 "run_time_permissions", new Object[] { 3778 m_item.ItemID,
3903 new LSL_Integer(0) }, 3779 new EventParams("run_time_permissions", new Object[] { new LSL_Integer(0) }, new DetectParams[0]));
3904 new DetectParams[0]));
3905 } 3780 }
3906 3781
3907 void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer) 3782 void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
@@ -3909,24 +3784,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3909 if (taskID != m_host.UUID) 3784 if (taskID != m_host.UUID)
3910 return; 3785 return;
3911 3786
3912 UUID invItemID = InventorySelf(); 3787 client.OnScriptAnswer -= handleScriptAnswer;
3913 3788 m_waitingForScriptAnswer = false;
3914 if (invItemID == UUID.Zero)
3915 return;
3916
3917 client.OnScriptAnswer-=handleScriptAnswer;
3918 m_waitingForScriptAnswer=false;
3919 3789
3920 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3790 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3921 llReleaseControls(); 3791 llReleaseControls();
3922 3792
3923
3924 m_host.TaskInventory.LockItemsForWrite(true); 3793 m_host.TaskInventory.LockItemsForWrite(true);
3925 m_host.TaskInventory[invItemID].PermsMask = answer; 3794 m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
3926 m_host.TaskInventory.LockItemsForWrite(false); 3795 m_host.TaskInventory.LockItemsForWrite(false);
3927 3796
3928 3797 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3929 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3930 "run_time_permissions", new Object[] { 3798 "run_time_permissions", new Object[] {
3931 new LSL_Integer(answer) }, 3799 new LSL_Integer(answer) },
3932 new DetectParams[0])); 3800 new DetectParams[0]));
@@ -3936,41 +3804,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3936 { 3804 {
3937 m_host.AddScriptLPS(1); 3805 m_host.AddScriptLPS(1);
3938 3806
3939 m_host.TaskInventory.LockItemsForRead(true); 3807 return m_item.PermsGranter.ToString();
3940
3941 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3942 {
3943 if (item.Type == 10 && item.ItemID == m_itemID)
3944 {
3945 m_host.TaskInventory.LockItemsForRead(false);
3946 return item.PermsGranter.ToString();
3947 }
3948 }
3949 m_host.TaskInventory.LockItemsForRead(false);
3950
3951 return UUID.Zero.ToString();
3952 } 3808 }
3953 3809
3954 public LSL_Integer llGetPermissions() 3810 public LSL_Integer llGetPermissions()
3955 { 3811 {
3956 m_host.AddScriptLPS(1); 3812 m_host.AddScriptLPS(1);
3957 3813
3958 m_host.TaskInventory.LockItemsForRead(true); 3814 int perms = m_item.PermsMask;
3959 3815
3960 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3816 if (m_automaticLinkPermission)
3961 { 3817 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3962 if (item.Type == 10 && item.ItemID == m_itemID)
3963 {
3964 int perms = item.PermsMask;
3965 if (m_automaticLinkPermission)
3966 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3967 m_host.TaskInventory.LockItemsForRead(false);
3968 return perms;
3969 }
3970 }
3971 m_host.TaskInventory.LockItemsForRead(false);
3972 3818
3973 return 0; 3819 return perms;
3974 } 3820 }
3975 3821
3976 public LSL_Integer llGetLinkNumber() 3822 public LSL_Integer llGetLinkNumber()
@@ -4008,18 +3854,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4008 public void llCreateLink(string target, int parent) 3854 public void llCreateLink(string target, int parent)
4009 { 3855 {
4010 m_host.AddScriptLPS(1); 3856 m_host.AddScriptLPS(1);
4011 UUID invItemID = InventorySelf(); 3857
4012 UUID targetID; 3858 UUID targetID;
4013 3859
4014 if (!UUID.TryParse(target, out targetID)) 3860 if (!UUID.TryParse(target, out targetID))
4015 return; 3861 return;
4016 3862
4017 TaskInventoryItem item; 3863 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4018 m_host.TaskInventory.LockItemsForRead(true);
4019 item = m_host.TaskInventory[invItemID];
4020 m_host.TaskInventory.LockItemsForRead(false);
4021
4022 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4023 && !m_automaticLinkPermission) 3864 && !m_automaticLinkPermission)
4024 { 3865 {
4025 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3866 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
@@ -4027,7 +3868,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4027 } 3868 }
4028 3869
4029 IClientAPI client = null; 3870 IClientAPI client = null;
4030 ScenePresence sp = World.GetScenePresence(item.PermsGranter); 3871 ScenePresence sp = World.GetScenePresence(m_item.PermsGranter);
4031 if (sp != null) 3872 if (sp != null)
4032 client = sp.ControllingClient; 3873 client = sp.ControllingClient;
4033 3874
@@ -4073,18 +3914,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4073 public void llBreakLink(int linknum) 3914 public void llBreakLink(int linknum)
4074 { 3915 {
4075 m_host.AddScriptLPS(1); 3916 m_host.AddScriptLPS(1);
4076 UUID invItemID = InventorySelf();
4077 3917
4078 m_host.TaskInventory.LockItemsForRead(true); 3918 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4079 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3919 && !m_automaticLinkPermission)
4080 && !m_automaticLinkPermission) 3920 {
4081 { 3921 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
4082 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3922 return;
4083 m_host.TaskInventory.LockItemsForRead(false); 3923 }
4084 return; 3924
4085 }
4086 m_host.TaskInventory.LockItemsForRead(false);
4087
4088 if (linknum < ScriptBaseClass.LINK_THIS) 3925 if (linknum < ScriptBaseClass.LINK_THIS)
4089 return; 3926 return;
4090 3927
@@ -4183,12 +4020,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4183 { 4020 {
4184 m_host.AddScriptLPS(1); 4021 m_host.AddScriptLPS(1);
4185 4022
4186 UUID invItemID = InventorySelf(); 4023 TaskInventoryItem item = m_item;
4187
4188 TaskInventoryItem item;
4189 m_host.TaskInventory.LockItemsForRead(true);
4190 item = m_host.TaskInventory[invItemID];
4191 m_host.TaskInventory.LockItemsForRead(false);
4192 4024
4193 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 4025 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4194 && !m_automaticLinkPermission) 4026 && !m_automaticLinkPermission)
@@ -4499,7 +4331,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4499 { 4331 {
4500 if (item.Name == name) 4332 if (item.Name == name)
4501 { 4333 {
4502 if (item.ItemID == m_itemID) 4334 if (item.ItemID == m_item.ItemID)
4503 throw new ScriptDeleteException(); 4335 throw new ScriptDeleteException();
4504 else 4336 else
4505 m_host.Inventory.RemoveInventoryItem(item.ItemID); 4337 m_host.Inventory.RemoveInventoryItem(item.ItemID);
@@ -4633,8 +4465,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4633 UUID rq = UUID.Random(); 4465 UUID rq = UUID.Random();
4634 4466
4635 UUID tid = AsyncCommands. 4467 UUID tid = AsyncCommands.
4636 DataserverPlugin.RegisterRequest(m_localID, 4468 DataserverPlugin.RegisterRequest(m_host.LocalId,
4637 m_itemID, rq.ToString()); 4469 m_item.ItemID, rq.ToString());
4638 4470
4639 AsyncCommands. 4471 AsyncCommands.
4640 DataserverPlugin.DataserverReply(rq.ToString(), reply); 4472 DataserverPlugin.DataserverReply(rq.ToString(), reply);
@@ -4661,8 +4493,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4661 if (item.Type == 3 && item.Name == name) 4493 if (item.Type == 3 && item.Name == name)
4662 { 4494 {
4663 UUID tid = AsyncCommands. 4495 UUID tid = AsyncCommands.
4664 DataserverPlugin.RegisterRequest(m_localID, 4496 DataserverPlugin.RegisterRequest(m_host.LocalId,
4665 m_itemID, item.AssetID.ToString()); 4497 m_item.ItemID, item.AssetID.ToString());
4666 4498
4667 Vector3 region = new Vector3( 4499 Vector3 region = new Vector3(
4668 World.RegionInfo.RegionLocX * Constants.RegionSize, 4500 World.RegionInfo.RegionLocX * Constants.RegionSize,
@@ -5071,22 +4903,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5071 4903
5072 public LSL_String llGetScriptName() 4904 public LSL_String llGetScriptName()
5073 { 4905 {
5074 string result = String.Empty;
5075
5076 m_host.AddScriptLPS(1); 4906 m_host.AddScriptLPS(1);
5077 4907
5078 m_host.TaskInventory.LockItemsForRead(true); 4908 return m_item.Name != null ? m_item.Name : String.Empty;
5079 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
5080 {
5081 if (item.Type == 10 && item.ItemID == m_itemID)
5082 {
5083 result = item.Name!=null?item.Name:String.Empty;
5084 break;
5085 }
5086 }
5087 m_host.TaskInventory.LockItemsForRead(false);
5088
5089 return result;
5090 } 4909 }
5091 4910
5092 public LSL_Integer llGetLinkNumberOfSides(int link) 4911 public LSL_Integer llGetLinkNumberOfSides(int link)
@@ -6220,7 +6039,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6220 } 6039 }
6221 } 6040 }
6222 } 6041 }
6223 List<UUID> presenceIds = new List<UUID>();
6224 6042
6225 World.ForEachRootScenePresence( 6043 World.ForEachRootScenePresence(
6226 delegate (ScenePresence ssp) 6044 delegate (ScenePresence ssp)
@@ -6371,7 +6189,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6371 if (m_host.OwnerID == land.LandData.OwnerID) 6189 if (m_host.OwnerID == land.LandData.OwnerID)
6372 { 6190 {
6373 Vector3 pos = World.GetNearestAllowedPosition(presence, land); 6191 Vector3 pos = World.GetNearestAllowedPosition(presence, land);
6374 presence.TeleportWithMomentum(pos); 6192 presence.TeleportWithMomentum(pos, null);
6375 presence.ControllingClient.SendAlertMessage("You have been ejected from this land"); 6193 presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
6376 } 6194 }
6377 } 6195 }
@@ -7318,14 +7136,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7318 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); 7136 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
7319 if (xmlrpcMod.IsEnabled()) 7137 if (xmlrpcMod.IsEnabled())
7320 { 7138 {
7321 UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_localID, m_itemID, UUID.Zero); 7139 UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero);
7322 IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>(); 7140 IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
7323 if (xmlRpcRouter != null) 7141 if (xmlRpcRouter != null)
7324 { 7142 {
7325 string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName; 7143 string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
7326 7144
7327 xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID, 7145 xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
7328 m_itemID, String.Format("http://{0}:{1}/", ExternalHostName, 7146 m_item.ItemID, String.Format("http://{0}:{1}/", ExternalHostName,
7329 xmlrpcMod.Port.ToString())); 7147 xmlrpcMod.Port.ToString()));
7330 } 7148 }
7331 object[] resobj = new object[] 7149 object[] resobj = new object[]
@@ -7337,7 +7155,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7337 new LSL_Integer(0), 7155 new LSL_Integer(0),
7338 new LSL_String(String.Empty) 7156 new LSL_String(String.Empty)
7339 }; 7157 };
7340 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams("remote_data", resobj, 7158 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj,
7341 new DetectParams[0])); 7159 new DetectParams[0]));
7342 } 7160 }
7343 ScriptSleep(1000); 7161 ScriptSleep(1000);
@@ -7348,7 +7166,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7348 m_host.AddScriptLPS(1); 7166 m_host.AddScriptLPS(1);
7349 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); 7167 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
7350 ScriptSleep(3000); 7168 ScriptSleep(3000);
7351 return (xmlrpcMod.SendRemoteData(m_localID, m_itemID, channel, dest, idata, sdata)).ToString(); 7169 return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString();
7352 } 7170 }
7353 7171
7354 public void llRemoteDataReply(string channel, string message_id, string sdata, int idata) 7172 public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
@@ -8187,7 +8005,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8187 return; 8005 return;
8188 face = (int)rules.GetLSLIntegerItem(idx++); 8006 face = (int)rules.GetLSLIntegerItem(idx++);
8189 int shiny = (int)rules.GetLSLIntegerItem(idx++); 8007 int shiny = (int)rules.GetLSLIntegerItem(idx++);
8190 Bumpiness bump = (Bumpiness)Convert.ToByte((int)rules.GetLSLIntegerItem(idx++)); 8008 Bumpiness bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);
8191 8009
8192 SetShiny(part, face, shiny, bump); 8010 SetShiny(part, face, shiny, bump);
8193 8011
@@ -9652,7 +9470,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9652 public LSL_String llGetSimulatorHostname() 9470 public LSL_String llGetSimulatorHostname()
9653 { 9471 {
9654 m_host.AddScriptLPS(1); 9472 m_host.AddScriptLPS(1);
9655 return System.Environment.MachineName; 9473 IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
9474 return UrlModule.ExternalHostNameForLSL;
9656 } 9475 }
9657 9476
9658 // <summary> 9477 // <summary>
@@ -9991,13 +9810,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9991 { 9810 {
9992 m_host.AddScriptLPS(1); 9811 m_host.AddScriptLPS(1);
9993 if (m_UrlModule != null) 9812 if (m_UrlModule != null)
9994 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString(); 9813 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
9995 return UUID.Zero.ToString(); 9814 return UUID.Zero.ToString();
9996 } 9815 }
9997 9816
9998 public LSL_String llRequestSimulatorData(string simulator, int data) 9817 public LSL_String llRequestSimulatorData(string simulator, int data)
9999 { 9818 {
10000 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_itemID, "OSSL"); 9819 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
10001 9820
10002 try 9821 try
10003 { 9822 {
@@ -10007,7 +9826,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10007 9826
10008 GridRegion info; 9827 GridRegion info;
10009 9828
10010 if (m_ScriptEngine.World.RegionInfo.RegionName == simulator) 9829 if (m_ScriptEngine.World.RegionInfo.RegionName == simulator) //Det data for this simulator?
9830
10011 info = new GridRegion(m_ScriptEngine.World.RegionInfo); 9831 info = new GridRegion(m_ScriptEngine.World.RegionInfo);
10012 else 9832 else
10013 info = m_ScriptEngine.World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator); 9833 info = m_ScriptEngine.World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator);
@@ -10020,10 +9840,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10020 ScriptSleep(1000); 9840 ScriptSleep(1000);
10021 return UUID.Zero.ToString(); 9841 return UUID.Zero.ToString();
10022 } 9842 }
10023 reply = new LSL_Vector( 9843 if (m_ScriptEngine.World.RegionInfo.RegionName != simulator)
10024 info.RegionLocX, 9844 {
10025 info.RegionLocY, 9845 //Hypergrid Region co-ordinates
10026 0).ToString(); 9846 uint rx = 0, ry = 0;
9847 Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out rx, out ry);
9848
9849 reply = new LSL_Vector(
9850 rx,
9851 ry,
9852 0).ToString();
9853 }
9854 else
9855 {
9856 //Local-cooridnates
9857 reply = new LSL_Vector(
9858 info.RegionLocX,
9859 info.RegionLocY,
9860 0).ToString();
9861 }
10027 break; 9862 break;
10028 case ScriptBaseClass.DATA_SIM_STATUS: 9863 case ScriptBaseClass.DATA_SIM_STATUS:
10029 if (info != null) 9864 if (info != null)
@@ -10059,7 +9894,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10059 UUID rq = UUID.Random(); 9894 UUID rq = UUID.Random();
10060 9895
10061 UUID tid = AsyncCommands. 9896 UUID tid = AsyncCommands.
10062 DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 9897 DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
10063 9898
10064 AsyncCommands. 9899 AsyncCommands.
10065 DataserverPlugin.DataserverReply(rq.ToString(), reply); 9900 DataserverPlugin.DataserverReply(rq.ToString(), reply);
@@ -10078,7 +9913,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10078 m_host.AddScriptLPS(1); 9913 m_host.AddScriptLPS(1);
10079 9914
10080 if (m_UrlModule != null) 9915 if (m_UrlModule != null)
10081 return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString(); 9916 return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
10082 return UUID.Zero.ToString(); 9917 return UUID.Zero.ToString();
10083 } 9918 }
10084 9919
@@ -10114,7 +9949,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10114 // child agents have a mass of 1.0 9949 // child agents have a mass of 1.0
10115 return 1; 9950 return 1;
10116 else 9951 else
10117 return avatar.GetMass(); 9952 return (double)avatar.GetMass();
10118 } 9953 }
10119 catch (KeyNotFoundException) 9954 catch (KeyNotFoundException)
10120 { 9955 {
@@ -10557,32 +10392,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10557 public LSL_Vector llGetCameraPos() 10392 public LSL_Vector llGetCameraPos()
10558 { 10393 {
10559 m_host.AddScriptLPS(1); 10394 m_host.AddScriptLPS(1);
10560 UUID invItemID = InventorySelf();
10561
10562 if (invItemID == UUID.Zero)
10563 return new LSL_Vector();
10564
10565 m_host.TaskInventory.LockItemsForRead(true);
10566
10567 UUID agentID = m_host.TaskInventory[invItemID].PermsGranter;
10568 10395
10569// if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 10396 if (m_item.PermsGranter == UUID.Zero)
10570 if (agentID == UUID.Zero) 10397 return new LSL_Vector();
10571 {
10572 m_host.TaskInventory.LockItemsForRead(false);
10573 return new LSL_Vector();
10574 }
10575 10398
10576 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) 10399 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
10577 { 10400 {
10578 ShoutError("No permissions to track the camera"); 10401 ShoutError("No permissions to track the camera");
10579 m_host.TaskInventory.LockItemsForRead(false);
10580 return new LSL_Vector(); 10402 return new LSL_Vector();
10581 } 10403 }
10582 m_host.TaskInventory.LockItemsForRead(false); 10404 m_host.TaskInventory.LockItemsForRead(false);
10583 10405
10584// ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10406// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
10585 ScenePresence presence = World.GetScenePresence(agentID); 10407 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
10586 if (presence != null) 10408 if (presence != null)
10587 { 10409 {
10588 LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z); 10410 LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z);
@@ -10594,30 +10416,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10594 public LSL_Rotation llGetCameraRot() 10416 public LSL_Rotation llGetCameraRot()
10595 { 10417 {
10596 m_host.AddScriptLPS(1); 10418 m_host.AddScriptLPS(1);
10597 UUID invItemID = InventorySelf();
10598 if (invItemID == UUID.Zero)
10599 return new LSL_Rotation();
10600
10601 m_host.TaskInventory.LockItemsForRead(true);
10602 10419
10603 UUID agentID = m_host.TaskInventory[invItemID].PermsGranter; 10420 if (m_item.PermsGranter == UUID.Zero)
10421 return new LSL_Rotation();
10604 10422
10605// if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 10423 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
10606 if (agentID == UUID.Zero)
10607 {
10608 m_host.TaskInventory.LockItemsForRead(false);
10609 return new LSL_Rotation();
10610 }
10611 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
10612 { 10424 {
10613 ShoutError("No permissions to track the camera"); 10425 ShoutError("No permissions to track the camera");
10614 m_host.TaskInventory.LockItemsForRead(false);
10615 return new LSL_Rotation(); 10426 return new LSL_Rotation();
10616 } 10427 }
10617 m_host.TaskInventory.LockItemsForRead(false); 10428 m_host.TaskInventory.LockItemsForRead(false);
10618 10429
10619// ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10430// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
10620 ScenePresence presence = World.GetScenePresence(agentID); 10431 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
10621 if (presence != null) 10432 if (presence != null)
10622 { 10433 {
10623 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W); 10434 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W);
@@ -10676,7 +10487,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10676 public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt) 10487 public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
10677 { 10488 {
10678 m_host.AddScriptLPS(1); 10489 m_host.AddScriptLPS(1);
10679 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0); 10490 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
10680 if (detectedParams == null) 10491 if (detectedParams == null)
10681 { 10492 {
10682 if (m_host.ParentGroup.IsAttachment == true) 10493 if (m_host.ParentGroup.IsAttachment == true)
@@ -10800,30 +10611,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10800 { 10611 {
10801 m_host.AddScriptLPS(1); 10612 m_host.AddScriptLPS(1);
10802 10613
10803 // our key in the object we are in
10804 UUID invItemID = InventorySelf();
10805 if (invItemID == UUID.Zero) return;
10806
10807 // the object we are in 10614 // the object we are in
10808 UUID objectID = m_host.ParentUUID; 10615 UUID objectID = m_host.ParentUUID;
10809 if (objectID == UUID.Zero) return; 10616 if (objectID == UUID.Zero)
10617 return;
10810 10618
10811 UUID agentID;
10812 m_host.TaskInventory.LockItemsForRead(true);
10813 // we need the permission first, to know which avatar we want to set the camera for 10619 // we need the permission first, to know which avatar we want to set the camera for
10814 agentID = m_host.TaskInventory[invItemID].PermsGranter; 10620 UUID agentID = m_item.PermsGranter;
10815 10621
10816 if (agentID == UUID.Zero) 10622 if (agentID == UUID.Zero)
10817 {
10818 m_host.TaskInventory.LockItemsForRead(false);
10819 return; 10623 return;
10820 } 10624
10821 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) 10625 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
10822 {
10823 m_host.TaskInventory.LockItemsForRead(false);
10824 return; 10626 return;
10825 }
10826 m_host.TaskInventory.LockItemsForRead(false);
10827 10627
10828 ScenePresence presence = World.GetScenePresence(agentID); 10628 ScenePresence presence = World.GetScenePresence(agentID);
10829 10629
@@ -10865,34 +10665,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10865 { 10665 {
10866 m_host.AddScriptLPS(1); 10666 m_host.AddScriptLPS(1);
10867 10667
10868 // our key in the object we are in
10869 UUID invItemID=InventorySelf();
10870 if (invItemID == UUID.Zero) return;
10871
10872 // the object we are in 10668 // the object we are in
10873 UUID objectID = m_host.ParentUUID; 10669 UUID objectID = m_host.ParentUUID;
10874 if (objectID == UUID.Zero) return; 10670 if (objectID == UUID.Zero)
10671 return;
10875 10672
10876 // we need the permission first, to know which avatar we want to clear the camera for 10673 // we need the permission first, to know which avatar we want to clear the camera for
10877 UUID agentID; 10674 UUID agentID = m_item.PermsGranter;
10878 m_host.TaskInventory.LockItemsForRead(true); 10675
10879 agentID = m_host.TaskInventory[invItemID].PermsGranter;
10880 if (agentID == UUID.Zero) 10676 if (agentID == UUID.Zero)
10881 {
10882 m_host.TaskInventory.LockItemsForRead(false);
10883 return; 10677 return;
10884 } 10678
10885 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) 10679 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
10886 {
10887 m_host.TaskInventory.LockItemsForRead(false);
10888 return; 10680 return;
10889 }
10890 m_host.TaskInventory.LockItemsForRead(false);
10891 10681
10892 ScenePresence presence = World.GetScenePresence(agentID); 10682 ScenePresence presence = World.GetScenePresence(agentID);
10893 10683
10894 // we are not interested in child-agents 10684 // we are not interested in child-agents
10895 if (presence.IsChildAgent) return; 10685 if (presence.IsChildAgent)
10686 return;
10896 10687
10897 presence.ControllingClient.SendClearFollowCamProperties(objectID); 10688 presence.ControllingClient.SendClearFollowCamProperties(objectID);
10898 } 10689 }
@@ -11083,8 +10874,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11083 } 10874 }
11084 } 10875 }
11085 10876
11086 UUID reqID = httpScriptMod. 10877 UUID reqID
11087 StartHttpRequest(m_localID, m_itemID, url, param, httpHeaders, body); 10878 = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body);
11088 10879
11089 if (reqID != UUID.Zero) 10880 if (reqID != UUID.Zero)
11090 return reqID.ToString(); 10881 return reqID.ToString();
@@ -11316,19 +11107,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11316 break; 11107 break;
11317 // For the following 8 see the Object version below 11108 // For the following 8 see the Object version below
11318 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT: 11109 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
11319 ret.Add(new LSL_Integer(0)); 11110 ret.Add(new LSL_Integer(av.RunningScriptCount()));
11320 break; 11111 break;
11321 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT: 11112 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
11322 ret.Add(new LSL_Integer(0)); 11113 ret.Add(new LSL_Integer(av.ScriptCount()));
11323 break; 11114 break;
11324 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY: 11115 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
11325 ret.Add(new LSL_Integer(0)); 11116 ret.Add(new LSL_Integer(av.RunningScriptCount() * 16384));
11326 break; 11117 break;
11327 case ScriptBaseClass.OBJECT_SCRIPT_TIME: 11118 case ScriptBaseClass.OBJECT_SCRIPT_TIME:
11328 ret.Add(new LSL_Float(0)); 11119 ret.Add(new LSL_Float(av.ScriptExecutionTime() / 1000.0f));
11329 break; 11120 break;
11330 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE: 11121 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
11331 ret.Add(new LSL_Integer(0)); 11122 ret.Add(new LSL_Integer(1));
11332 break; 11123 break;
11333 case ScriptBaseClass.OBJECT_SERVER_COST: 11124 case ScriptBaseClass.OBJECT_SERVER_COST:
11334 ret.Add(new LSL_Float(0)); 11125 ret.Add(new LSL_Float(0));
@@ -11380,43 +11171,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11380 case ScriptBaseClass.OBJECT_CREATOR: 11171 case ScriptBaseClass.OBJECT_CREATOR:
11381 ret.Add(new LSL_String(obj.CreatorID.ToString())); 11172 ret.Add(new LSL_String(obj.CreatorID.ToString()));
11382 break; 11173 break;
11383 // The following 8 I have intentionaly coded to return zero. They are part of
11384 // "Land Impact" calculations. These calculations are probably not applicable
11385 // to OpenSim, required figures (cpu/memory usage) are not currently tracked
11386 // I have intentionally left these all at zero rather than return possibly
11387 // missleading numbers
11388 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT: 11174 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
11389 // in SL this currently includes crashed scripts 11175 ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount()));
11390 ret.Add(new LSL_Integer(0));
11391 break; 11176 break;
11392 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT: 11177 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
11393 ret.Add(new LSL_Integer(0)); 11178 ret.Add(new LSL_Integer(obj.ParentGroup.ScriptCount()));
11394 break; 11179 break;
11395 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY: 11180 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
11396 // The value returned in SL for mono scripts is 65536 * number of active scripts 11181 // The value returned in SL for mono scripts is 65536 * number of active scripts
11397 ret.Add(new LSL_Integer(0)); 11182 // and 16384 * number of active scripts for LSO. since llGetFreememory
11183 // is coded to give the LSO value use it here
11184 ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount() * 16384));
11398 break; 11185 break;
11399 case ScriptBaseClass.OBJECT_SCRIPT_TIME: 11186 case ScriptBaseClass.OBJECT_SCRIPT_TIME:
11400 // Average cpu time per simulator frame expended on all scripts in the objetc 11187 // Average cpu time in seconds per simulator frame expended on all scripts in the object
11401 ret.Add(new LSL_Float(0)); 11188 ret.Add(new LSL_Float(obj.ParentGroup.ScriptExecutionTime() / 1000.0f));
11402 break; 11189 break;
11403 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE: 11190 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
11404 // according to the SL wiki A prim or linkset will have prim 11191 // according to the SL wiki A prim or linkset will have prim
11405 // equivalent of the number of prims in a linkset if it does not 11192 // equivalent of the number of prims in a linkset if it does not
11406 // contain a mesh anywhere in the link set or is not a normal prim 11193 // contain a mesh anywhere in the link set or is not a normal prim
11407 // The value returned in SL for normal prims is prim count 11194 // The value returned in SL for normal prims is prim count
11408 ret.Add(new LSL_Integer(0)); 11195 ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
11409 break; 11196 break;
11197 // The following 3 costs I have intentionaly coded to return zero. They are part of
11198 // "Land Impact" calculations. These calculations are probably not applicable
11199 // to OpenSim and are not yet complete in SL
11410 case ScriptBaseClass.OBJECT_SERVER_COST: 11200 case ScriptBaseClass.OBJECT_SERVER_COST:
11411 // The value returned in SL for normal prims is prim count 11201 // The linden calculation is here
11202 // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
11203 // The value returned in SL for normal prims looks like the prim count
11412 ret.Add(new LSL_Float(0)); 11204 ret.Add(new LSL_Float(0));
11413 break; 11205 break;
11414 case ScriptBaseClass.OBJECT_STREAMING_COST: 11206 case ScriptBaseClass.OBJECT_STREAMING_COST:
11415 // The value returned in SL for normal prims is prim count * 0.06 11207 // The linden calculation is here
11208 // http://wiki.secondlife.com/wiki/Mesh/Mesh_Streaming_Cost
11209 // The value returned in SL for normal prims looks like the prim count * 0.06
11416 ret.Add(new LSL_Float(0)); 11210 ret.Add(new LSL_Float(0));
11417 break; 11211 break;
11418 case ScriptBaseClass.OBJECT_PHYSICS_COST: 11212 case ScriptBaseClass.OBJECT_PHYSICS_COST:
11419 // The value returned in SL for normal prims is prim count 11213 // The linden calculation is here
11214 // http://wiki.secondlife.com/wiki/Mesh/Mesh_physics
11215 // The value returned in SL for normal prims looks like the prim count
11420 ret.Add(new LSL_Float(0)); 11216 ret.Add(new LSL_Float(0));
11421 break; 11217 break;
11422 default: 11218 default:
@@ -11514,7 +11310,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11514 } 11310 }
11515 11311
11516 // was: UUID tid = tid = AsyncCommands. 11312 // was: UUID tid = tid = AsyncCommands.
11517 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, assetID.ToString()); 11313 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, assetID.ToString());
11518 11314
11519 if (NotecardCache.IsCached(assetID)) 11315 if (NotecardCache.IsCached(assetID))
11520 { 11316 {
@@ -11577,7 +11373,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11577 } 11373 }
11578 11374
11579 // was: UUID tid = tid = AsyncCommands. 11375 // was: UUID tid = tid = AsyncCommands.
11580 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, assetID.ToString()); 11376 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, assetID.ToString());
11581 11377
11582 if (NotecardCache.IsCached(assetID)) 11378 if (NotecardCache.IsCached(assetID))
11583 { 11379 {
@@ -11661,7 +11457,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11661 { 11457 {
11662 UUID rq = UUID.Random(); 11458 UUID rq = UUID.Random();
11663 11459
11664 AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 11460 AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
11665 11461
11666 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id))); 11462 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id)));
11667 11463
@@ -11677,7 +11473,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11677 { 11473 {
11678 UUID rq = UUID.Random(); 11474 UUID rq = UUID.Random();
11679 11475
11680 AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 11476 AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
11681 11477
11682 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id)); 11478 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id));
11683 11479
@@ -12171,7 +11967,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12171 bool isAccount = false; 11967 bool isAccount = false;
12172 bool isGroup = false; 11968 bool isGroup = false;
12173 11969
12174 if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManager(m_host.OwnerID)) 11970 if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManagerOrOwner(m_host.OwnerID))
12175 return 0; 11971 return 0;
12176 11972
12177 UUID id = new UUID(); 11973 UUID id = new UUID();
@@ -12233,35 +12029,50 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12233 return 1; 12029 return 1;
12234 } 12030 }
12235 12031
12236 #region Not Implemented 12032 public LSL_Integer llGetMemoryLimit()
12237 // 12033 {
12238 // Listing the unimplemented lsl functions here, please move 12034 m_host.AddScriptLPS(1);
12239 // them from this region as they are completed 12035 // The value returned for LSO scripts in SL
12240 // 12036 return 16384;
12037 }
12241 12038
12242 public void llGetEnv(LSL_String name) 12039 public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
12243 { 12040 {
12244 m_host.AddScriptLPS(1); 12041 m_host.AddScriptLPS(1);
12245 NotImplemented("llGetEnv"); 12042 // Treat as an LSO script
12043 return ScriptBaseClass.FALSE;
12246 } 12044 }
12247 12045
12248 public void llGetSPMaxMemory() 12046 public LSL_Integer llGetSPMaxMemory()
12249 { 12047 {
12250 m_host.AddScriptLPS(1); 12048 m_host.AddScriptLPS(1);
12251 NotImplemented("llGetSPMaxMemory"); 12049 // The value returned for LSO scripts in SL
12050 return 16384;
12252 } 12051 }
12253 12052
12254 public virtual LSL_Integer llGetUsedMemory() 12053 public virtual LSL_Integer llGetUsedMemory()
12255 { 12054 {
12256 m_host.AddScriptLPS(1); 12055 m_host.AddScriptLPS(1);
12257 NotImplemented("llGetUsedMemory"); 12056 // The value returned for LSO scripts in SL
12258 return 0; 12057 return 16384;
12259 } 12058 }
12260 12059
12261 public void llScriptProfiler(LSL_Integer flags) 12060 public void llScriptProfiler(LSL_Integer flags)
12262 { 12061 {
12263 m_host.AddScriptLPS(1); 12062 m_host.AddScriptLPS(1);
12264 //NotImplemented("llScriptProfiler"); 12063 // This does nothing for LSO scripts in SL
12064 }
12065
12066 #region Not Implemented
12067 //
12068 // Listing the unimplemented lsl functions here, please move
12069 // them from this region as they are completed
12070 //
12071
12072 public void llGetEnv(LSL_String name)
12073 {
12074 m_host.AddScriptLPS(1);
12075 NotImplemented("llGetEnv");
12265 } 12076 }
12266 12077
12267 public void llSetSoundQueueing(int queue) 12078 public void llSetSoundQueueing(int queue)
@@ -12341,8 +12152,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12341 12152
12342 try 12153 try
12343 { 12154 {
12344 UUID invItemID=InventorySelf(); 12155 TaskInventoryItem item = m_item;
12345 if (invItemID == UUID.Zero) 12156 if (item == null)
12346 { 12157 {
12347 replydata = "SERVICE_ERROR"; 12158 replydata = "SERVICE_ERROR";
12348 return; 12159 return;
@@ -12350,10 +12161,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12350 12161
12351 m_host.AddScriptLPS(1); 12162 m_host.AddScriptLPS(1);
12352 12163
12353 m_host.TaskInventory.LockItemsForRead(true);
12354 TaskInventoryItem item = m_host.TaskInventory[invItemID];
12355 m_host.TaskInventory.LockItemsForRead(false);
12356
12357 if (item.PermsGranter == UUID.Zero) 12164 if (item.PermsGranter == UUID.Zero)
12358 { 12165 {
12359 replydata = "MISSING_PERMISSION_DEBIT"; 12166 replydata = "MISSING_PERMISSION_DEBIT";
@@ -12395,7 +12202,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12395 } 12202 }
12396 finally 12203 finally
12397 { 12204 {
12398 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 12205 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
12399 "transaction_result", new Object[] { 12206 "transaction_result", new Object[] {
12400 new LSL_String(txn.ToString()), 12207 new LSL_String(txn.ToString()),
12401 new LSL_Integer(replycode), 12208 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..8237b60 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -128,11 +128,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
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 130
131 public const string GridInfoServiceConfigSectionName = "GridInfoService";
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
@@ -2042,8 +2038,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2042 string nick = String.Empty; 2038 string nick = String.Empty;
2043 IConfigSource config = m_ScriptEngine.ConfigSource; 2039 IConfigSource config = m_ScriptEngine.ConfigSource;
2044 2040
2045 if (config.Configs["GridInfo"] != null) 2041 if (config.Configs[GridInfoServiceConfigSectionName] != null)
2046 nick = config.Configs["GridInfo"].GetString("gridnick", nick); 2042 nick = config.Configs[GridInfoServiceConfigSectionName].GetString("gridnick", nick);
2047 2043
2048 if (String.IsNullOrEmpty(nick)) 2044 if (String.IsNullOrEmpty(nick))
2049 nick = GridUserInfo(InfoType.Nick); 2045 nick = GridUserInfo(InfoType.Nick);
@@ -2059,8 +2055,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2059 string name = String.Empty; 2055 string name = String.Empty;
2060 IConfigSource config = m_ScriptEngine.ConfigSource; 2056 IConfigSource config = m_ScriptEngine.ConfigSource;
2061 2057
2062 if (config.Configs["GridInfo"] != null) 2058 if (config.Configs[GridInfoServiceConfigSectionName] != null)
2063 name = config.Configs["GridInfo"].GetString("gridname", name); 2059 name = config.Configs[GridInfoServiceConfigSectionName].GetString("gridname", name);
2064 2060
2065 if (String.IsNullOrEmpty(name)) 2061 if (String.IsNullOrEmpty(name))
2066 name = GridUserInfo(InfoType.Name); 2062 name = GridUserInfo(InfoType.Name);
@@ -2076,8 +2072,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2076 string loginURI = String.Empty; 2072 string loginURI = String.Empty;
2077 IConfigSource config = m_ScriptEngine.ConfigSource; 2073 IConfigSource config = m_ScriptEngine.ConfigSource;
2078 2074
2079 if (config.Configs["GridInfo"] != null) 2075 if (config.Configs[GridInfoServiceConfigSectionName] != null)
2080 loginURI = config.Configs["GridInfo"].GetString("login", loginURI); 2076 loginURI = config.Configs[GridInfoServiceConfigSectionName].GetString("login", loginURI);
2081 2077
2082 if (String.IsNullOrEmpty(loginURI)) 2078 if (String.IsNullOrEmpty(loginURI))
2083 loginURI = GridUserInfo(InfoType.Login); 2079 loginURI = GridUserInfo(InfoType.Login);
@@ -2124,8 +2120,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2124 string retval = String.Empty; 2120 string retval = String.Empty;
2125 IConfigSource config = m_ScriptEngine.ConfigSource; 2121 IConfigSource config = m_ScriptEngine.ConfigSource;
2126 2122
2127 if (config.Configs["GridInfo"] != null) 2123 if (config.Configs[GridInfoServiceConfigSectionName] != null)
2128 retval = config.Configs["GridInfo"].GetString(key, retval); 2124 retval = config.Configs[GridInfoServiceConfigSectionName].GetString(key, retval);
2129 2125
2130 if (String.IsNullOrEmpty(retval)) 2126 if (String.IsNullOrEmpty(retval))
2131 retval = GridUserInfo(InfoType.Custom, key); 2127 retval = GridUserInfo(InfoType.Custom, key);
@@ -2480,7 +2476,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2480 return; 2476 return;
2481 2477
2482 Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z); 2478 Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z);
2483 module.MoveToTarget(npcId, World, pos, false, true); 2479 module.MoveToTarget(npcId, World, pos, false, true, false);
2484 } 2480 }
2485 } 2481 }
2486 2482
@@ -2505,7 +2501,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2505 World, 2501 World,
2506 pos, 2502 pos,
2507 (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0, 2503 (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0,
2508 (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0); 2504 (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0,
2505 (options & ScriptBaseClass.OS_NPC_RUNNING) != 0);
2509 } 2506 }
2510 } 2507 }
2511 2508
@@ -2555,7 +2552,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2555 2552
2556 public void osNpcStopMoveToTarget(LSL_Key npc) 2553 public void osNpcStopMoveToTarget(LSL_Key npc)
2557 { 2554 {
2558 CheckThreatLevel(ThreatLevel.VeryLow, "osNpcStopMoveTo"); 2555 CheckThreatLevel(ThreatLevel.High, "osNpcStopMoveToTarget");
2559 m_host.AddScriptLPS(1); 2556 m_host.AddScriptLPS(1);
2560 2557
2561 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2558 INPCModule module = World.RequestModuleInterface<INPCModule>();
@@ -2572,6 +2569,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2572 2569
2573 public void osNpcSay(LSL_Key npc, string message) 2570 public void osNpcSay(LSL_Key npc, string message)
2574 { 2571 {
2572 osNpcSay(npc, 0, message);
2573 }
2574
2575 public void osNpcSay(LSL_Key npc, int channel, string message)
2576 {
2575 CheckThreatLevel(ThreatLevel.High, "osNpcSay"); 2577 CheckThreatLevel(ThreatLevel.High, "osNpcSay");
2576 m_host.AddScriptLPS(1); 2578 m_host.AddScriptLPS(1);
2577 2579
@@ -2583,7 +2585,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2583 if (!module.CheckPermissions(npcId, m_host.OwnerID)) 2585 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2584 return; 2586 return;
2585 2587
2586 module.Say(npcId, World, message); 2588 module.Say(npcId, World, message, channel);
2589 }
2590 }
2591
2592 public void osNpcShout(LSL_Key npc, int channel, string message)
2593 {
2594 CheckThreatLevel(ThreatLevel.High, "osNpcShout");
2595 m_host.AddScriptLPS(1);
2596
2597 INPCModule module = World.RequestModuleInterface<INPCModule>();
2598 if (module != null)
2599 {
2600 UUID npcId = new UUID(npc.m_string);
2601
2602 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2603 return;
2604
2605 module.Shout(npcId, World, message, channel);
2587 } 2606 }
2588 } 2607 }
2589 2608
@@ -2684,6 +2703,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2684 } 2703 }
2685 } 2704 }
2686 2705
2706 public void osNpcWhisper(LSL_Key npc, int channel, string message)
2707 {
2708 CheckThreatLevel(ThreatLevel.High, "osNpcWhisper");
2709 m_host.AddScriptLPS(1);
2710
2711 INPCModule module = World.RequestModuleInterface<INPCModule>();
2712 if (module != null)
2713 {
2714 UUID npcId = new UUID(npc.m_string);
2715
2716 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2717 return;
2718
2719 module.Whisper(npcId, World, message, channel);
2720 }
2721 }
2722
2687 /// <summary> 2723 /// <summary>
2688 /// Save the current appearance of the script owner permanently to the named notecard. 2724 /// Save the current appearance of the script owner permanently to the named notecard.
2689 /// </summary> 2725 /// </summary>
@@ -2835,21 +2871,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2835 CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar"); 2871 CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
2836 m_host.AddScriptLPS(1); 2872 m_host.AddScriptLPS(1);
2837 2873
2838 if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID)) 2874 World.ForEachRootScenePresence(delegate(ScenePresence sp)
2839 { 2875 {
2840 World.ForEachRootScenePresence(delegate(ScenePresence sp) 2876 if (sp.Firstname == FirstName && sp.Lastname == SurName)
2841 { 2877 {
2842 if (sp.Firstname == FirstName && sp.Lastname == SurName) 2878 // kick client...
2843 { 2879 if (alert != null)
2844 // kick client... 2880 sp.ControllingClient.Kick(alert);
2845 if (alert != null)
2846 sp.ControllingClient.Kick(alert);
2847 2881
2848 // ...and close on our side 2882 // ...and close on our side
2849 sp.Scene.IncomingCloseAgent(sp.UUID); 2883 sp.Scene.IncomingCloseAgent(sp.UUID);
2850 } 2884 }
2851 }); 2885 });
2852 }
2853 } 2886 }
2854 2887
2855 public void osCauseDamage(string avatar, double damage) 2888 public void osCauseDamage(string avatar, double damage)
@@ -3095,5 +3128,80 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3095 3128
3096 return ScriptBaseClass.TRUE; 3129 return ScriptBaseClass.TRUE;
3097 } 3130 }
3131
3132 /// <summary>
3133 /// Sets terrain estate texture
3134 /// </summary>
3135 /// <param name="level"></param>
3136 /// <param name="texture"></param>
3137 /// <returns></returns>
3138 public void osSetTerrainTexture(int level, LSL_Key texture)
3139 {
3140 CheckThreatLevel(ThreatLevel.High, "osSetTerrainTexture");
3141
3142 m_host.AddScriptLPS(1);
3143 //Check to make sure that the script's owner is the estate manager/master
3144 //World.Permissions.GenericEstatePermission(
3145 if (World.Permissions.IsGod(m_host.OwnerID))
3146 {
3147 if (level < 0 || level > 3)
3148 return;
3149
3150 UUID textureID = new UUID();
3151 if (!UUID.TryParse(texture, out textureID))
3152 return;
3153
3154 // estate module is required
3155 IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
3156 if (estate != null)
3157 estate.setEstateTerrainBaseTexture(level, textureID);
3158 }
3159 }
3160
3161 /// <summary>
3162 /// Sets terrain heights of estate
3163 /// </summary>
3164 /// <param name="corner"></param>
3165 /// <param name="low"></param>
3166 /// <param name="high"></param>
3167 /// <returns></returns>
3168 public void osSetTerrainTextureHeight(int corner, double low, double high)
3169 {
3170 CheckThreatLevel(ThreatLevel.High, "osSetTerrainTextureHeight");
3171
3172 m_host.AddScriptLPS(1);
3173 //Check to make sure that the script's owner is the estate manager/master
3174 //World.Permissions.GenericEstatePermission(
3175 if (World.Permissions.IsGod(m_host.OwnerID))
3176 {
3177 if (corner < 0 || corner > 3)
3178 return;
3179
3180 // estate module is required
3181 IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
3182 if (estate != null)
3183 estate.setEstateTerrainTextureHeights(corner, (float)low, (float)high);
3184 }
3185 }
3186
3187 public void osForceAttachToAvatar(int attachmentPoint)
3188 {
3189 CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar");
3190
3191 m_host.AddScriptLPS(1);
3192
3193 InitLSL();
3194 ((LSL_Api)m_LSL_Api).AttachToAvatar(attachmentPoint);
3195 }
3196
3197 public void osForceDetachFromAvatar()
3198 {
3199 CheckThreatLevel(ThreatLevel.High, "osForceDetachFromAvatar");
3200
3201 m_host.AddScriptLPS(1);
3202
3203 InitLSL();
3204 ((LSL_Api)m_LSL_Api).DetachFromAvatar();
3205 }
3098 } 3206 }
3099} 3207}
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 be5740e..048124d 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();
@@ -346,6 +350,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
346 void llSetLinkTexture(int linknumber, string texture, int face); 350 void llSetLinkTexture(int linknumber, string texture, int face);
347 void llSetLinkTextureAnim(int linknum, int mode, int face, int sizex, int sizey, double start, double length, double rate); 351 void llSetLinkTextureAnim(int linknum, int mode, int face, int sizex, int sizey, double start, double length, double rate);
348 void llSetLocalRot(LSL_Rotation rot); 352 void llSetLocalRot(LSL_Rotation rot);
353 LSL_Integer llSetMemoryLimit(LSL_Integer limit);
349 void llSetObjectDesc(string desc); 354 void llSetObjectDesc(string desc);
350 void llSetObjectName(string name); 355 void llSetObjectName(string name);
351 void llSetObjectPermMask(int mask, int value); 356 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..7382495 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -98,6 +98,20 @@ 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 /// Detach the object containing this script from the avatar it is attached to without checking for PERMISSION_ATTACH
111 /// </summary>
112 /// <remarks>Nothing happens if the object is not attached.</remarks>
113 void osForceDetachFromAvatar();
114
101 //texture draw functions 115 //texture draw functions
102 string osMovePen(string drawList, int x, int y); 116 string osMovePen(string drawList, int x, int y);
103 string osDrawLine(string drawList, int startX, int startY, int endX, int endY); 117 string osDrawLine(string drawList, int startX, int startY, int endX, int endY);
@@ -203,11 +217,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
203 void osNpcSetRot(LSL_Key npc, rotation rot); 217 void osNpcSetRot(LSL_Key npc, rotation rot);
204 void osNpcStopMoveToTarget(LSL_Key npc); 218 void osNpcStopMoveToTarget(LSL_Key npc);
205 void osNpcSay(key npc, string message); 219 void osNpcSay(key npc, string message);
220 void osNpcSay(key npc, int channel, string message);
221 void osNpcShout(key npc, int channel, string message);
206 void osNpcSit(key npc, key target, int options); 222 void osNpcSit(key npc, key target, int options);
207 void osNpcStand(LSL_Key npc); 223 void osNpcStand(LSL_Key npc);
208 void osNpcRemove(key npc); 224 void osNpcRemove(key npc);
209 void osNpcPlayAnimation(LSL_Key npc, string animation); 225 void osNpcPlayAnimation(LSL_Key npc, string animation);
210 void osNpcStopAnimation(LSL_Key npc, string animation); 226 void osNpcStopAnimation(LSL_Key npc, string animation);
227 void osNpcWhisper(key npc, int channel, string message);
211 228
212 LSL_Key osOwnerSaveAppearance(string notecard); 229 LSL_Key osOwnerSaveAppearance(string notecard);
213 LSL_Key osAgentSaveAppearance(key agentId, string notecard); 230 LSL_Key osAgentSaveAppearance(key agentId, string notecard);
@@ -234,5 +251,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
234 251
235 LSL_Integer osInviteToGroup(LSL_Key agentId); 252 LSL_Integer osInviteToGroup(LSL_Key agentId);
236 LSL_Integer osEjectFromGroup(LSL_Key agentId); 253 LSL_Integer osEjectFromGroup(LSL_Key agentId);
254
255 void osSetTerrainTexture(int level, LSL_Key texture);
256 void osSetTerrainTextureHeight(int corner, double low, double high);
237 } 257 }
238} 258}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
index 278f74e..5c6ad8a 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 9ba9561..2d23d30 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
@@ -376,6 +376,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
376 return m_LSL_Functions.llFrand(mag); 376 return m_LSL_Functions.llFrand(mag);
377 } 377 }
378 378
379 public LSL_Key llGenerateKey()
380 {
381 return m_LSL_Functions.llGenerateKey();
382 }
383
379 public LSL_Vector llGetAccel() 384 public LSL_Vector llGetAccel()
380 { 385 {
381 return m_LSL_Functions.llGetAccel(); 386 return m_LSL_Functions.llGetAccel();
@@ -591,6 +596,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
591 return m_LSL_Functions.llGetMassMKS(); 596 return m_LSL_Functions.llGetMassMKS();
592 } 597 }
593 598
599 public LSL_Integer llGetMemoryLimit()
600 {
601 return m_LSL_Functions.llGetMemoryLimit();
602 }
603
594 public void llGetNextEmail(string address, string subject) 604 public void llGetNextEmail(string address, string subject)
595 { 605 {
596 m_LSL_Functions.llGetNextEmail(address, subject); 606 m_LSL_Functions.llGetNextEmail(address, subject);
@@ -781,6 +791,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
781 return m_LSL_Functions.llGetSimulatorHostname(); 791 return m_LSL_Functions.llGetSimulatorHostname();
782 } 792 }
783 793
794 public LSL_Integer llGetSPMaxMemory()
795 {
796 return m_LSL_Functions.llGetSPMaxMemory();
797 }
798
784 public LSL_Integer llGetStartParameter() 799 public LSL_Integer llGetStartParameter()
785 { 800 {
786 return m_LSL_Functions.llGetStartParameter(); 801 return m_LSL_Functions.llGetStartParameter();
@@ -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);
@@ -1560,6 +1580,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1560 m_LSL_Functions.llSetLocalRot(rot); 1580 m_LSL_Functions.llSetLocalRot(rot);
1561 } 1581 }
1562 1582
1583 public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
1584 {
1585 return m_LSL_Functions.llSetMemoryLimit(limit);
1586 }
1587
1563 public void llSetObjectDesc(string desc) 1588 public void llSetObjectDesc(string desc)
1564 { 1589 {
1565 m_LSL_Functions.llSetObjectDesc(desc); 1590 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..d230662 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -289,8 +289,19 @@ 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 osForceDetachFromAvatar()
300 {
301 m_OSSL_Functions.osForceDetachFromAvatar();
302 }
303
304 // Texture Draw functions
294 305
295 public string osMovePen(string drawList, int x, int y) 306 public string osMovePen(string drawList, int x, int y)
296 { 307 {
@@ -569,6 +580,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
569 m_OSSL_Functions.osNpcSay(npc, message); 580 m_OSSL_Functions.osNpcSay(npc, message);
570 } 581 }
571 582
583 public void osNpcSay(key npc, int channel, string message)
584 {
585 m_OSSL_Functions.osNpcSay(npc, channel, message);
586 }
587
588
589 public void osNpcShout(key npc, int channel, string message)
590 {
591 m_OSSL_Functions.osNpcShout(npc, channel, message);
592 }
593
572 public void osNpcSit(LSL_Key npc, LSL_Key target, int options) 594 public void osNpcSit(LSL_Key npc, LSL_Key target, int options)
573 { 595 {
574 m_OSSL_Functions.osNpcSit(npc, target, options); 596 m_OSSL_Functions.osNpcSit(npc, target, options);
@@ -594,6 +616,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
594 m_OSSL_Functions.osNpcStopAnimation(npc, animation); 616 m_OSSL_Functions.osNpcStopAnimation(npc, animation);
595 } 617 }
596 618
619 public void osNpcWhisper(key npc, int channel, string message)
620 {
621 m_OSSL_Functions.osNpcWhisper(npc, channel, message);
622 }
623
597 public LSL_Key osOwnerSaveAppearance(string notecard) 624 public LSL_Key osOwnerSaveAppearance(string notecard)
598 { 625 {
599 return m_OSSL_Functions.osOwnerSaveAppearance(notecard); 626 return m_OSSL_Functions.osOwnerSaveAppearance(notecard);
@@ -878,5 +905,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
878 { 905 {
879 return m_OSSL_Functions.osEjectFromGroup(agentId); 906 return m_OSSL_Functions.osEjectFromGroup(agentId);
880 } 907 }
908
909 public void osSetTerrainTexture(int level, LSL_Key texture)
910 {
911 m_OSSL_Functions.osSetTerrainTexture(level, texture);
912 }
913
914 public void osSetTerrainTextureHeight(int corner, double low, double high)
915 {
916 m_OSSL_Functions.osSetTerrainTextureHeight(corner, low, high);
917 }
881 } 918 }
882} 919}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 5e68d69..1c59d45 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -232,7 +232,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
232 foreach (string api in am.GetApis()) 232 foreach (string api in am.GetApis())
233 { 233 {
234 m_Apis[api] = am.CreateApi(api); 234 m_Apis[api] = am.CreateApi(api);
235 m_Apis[api].Initialize(engine, part, LocalID, itemID); 235 m_Apis[api].Initialize(engine, part, ScriptTask);
236 } 236 }
237 237
238 try 238 try
@@ -966,7 +966,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
966 public IScriptApi GetApi(string name) 966 public IScriptApi GetApi(string name)
967 { 967 {
968 if (m_Apis.ContainsKey(name)) 968 if (m_Apis.ContainsKey(name))
969 {
970// m_log.DebugFormat("[SCRIPT INSTANCE]: Found api {0} in {1}@{2}", name, ScriptName, PrimName);
971
969 return m_Apis[name]; 972 return m_Apis[name];
973 }
974
975// m_log.DebugFormat("[SCRIPT INSTANCE]: Did not find api {0} in {1}@{2}", name, ScriptName, PrimName);
976
970 return null; 977 return null;
971 } 978 }
972 979
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..bc3b790
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs
@@ -0,0 +1,139 @@
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(m_scene, grp1.RootPart);
93 grp1Item.PermsMask |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
94
95 SceneObjectGroup grp2 = SceneHelpers.CreateSceneObject(2, ownerId, "grp2-", 0x20);
96 grp2.AbsolutePosition = new Vector3(20, 20, 20);
97
98 // <180,0,0>
99 grp2.UpdateGroupRotationR(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0));
100
101 m_scene.AddSceneObject(grp2);
102
103 LSL_Api apiGrp1 = new LSL_Api();
104 apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item);
105
106 apiGrp1.llCreateLink(grp2.UUID.ToString(), ScriptBaseClass.TRUE);
107
108 Assert.That(grp1.Parts.Length, Is.EqualTo(4));
109 Assert.That(grp2.IsDeleted, Is.True);
110 }
111
112 [Test]
113 public void TestllBreakLink()
114 {
115 TestHelpers.InMethod();
116
117 UUID ownerId = TestHelpers.ParseTail(0x1);
118
119 SceneObjectGroup grp1 = SceneHelpers.CreateSceneObject(2, ownerId, "grp1-", 0x10);
120 grp1.AbsolutePosition = new Vector3(10, 10, 10);
121 m_scene.AddSceneObject(grp1);
122
123 // FIXME: This should really be a script item (with accompanying script)
124 TaskInventoryItem grp1Item
125 = TaskInventoryHelpers.AddNotecard(m_scene, grp1.RootPart);
126 grp1Item.PermsMask |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
127
128 LSL_Api apiGrp1 = new LSL_Api();
129 apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item);
130
131 apiGrp1.llBreakLink(2);
132
133 Assert.That(grp1.Parts.Length, Is.EqualTo(1));
134
135 SceneObjectGroup grp2 = m_scene.GetSceneObjectGroup("grp1-Part1");
136 Assert.That(grp2, Is.Not.Null);
137 }
138 }
139} \ 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..f96a156 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
@@ -58,7 +58,7 @@ 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);
63 63
64 XEngine.XEngine engine = new XEngine.XEngine(); 64 XEngine.XEngine engine = new XEngine.XEngine();
@@ -66,8 +66,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
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_ApiNpcTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs
index 9d9fc51..0ccd889 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs
@@ -68,7 +68,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
68 config = initConfigSource.AddConfig("NPC"); 68 config = initConfigSource.AddConfig("NPC");
69 config.Set("Enabled", "true"); 69 config.Set("Enabled", "true");
70 70
71 m_scene = SceneHelpers.SetupScene(); 71 m_scene = new SceneHelpers().SetupScene();
72 SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule()); 72 SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule());
73 73
74 m_engine = new XEngine.XEngine(); 74 m_engine = new XEngine.XEngine();
@@ -104,10 +104,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
104 m_scene.AddSceneObject(otherSo); 104 m_scene.AddSceneObject(otherSo);
105 105
106 OSSL_Api osslApi = new OSSL_Api(); 106 OSSL_Api osslApi = new OSSL_Api();
107 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); 107 osslApi.Initialize(m_engine, part, null);
108 108
109 OSSL_Api otherOsslApi = new OSSL_Api(); 109 OSSL_Api otherOsslApi = new OSSL_Api();
110 otherOsslApi.Initialize(m_engine, otherPart, otherPart.LocalId, otherPart.UUID); 110 otherOsslApi.Initialize(m_engine, otherPart, null);
111 111
112 string notecardName = "appearanceNc"; 112 string notecardName = "appearanceNc";
113 osslApi.osOwnerSaveAppearance(notecardName); 113 osslApi.osOwnerSaveAppearance(notecardName);
@@ -151,7 +151,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
151 m_scene.AddSceneObject(so); 151 m_scene.AddSceneObject(so);
152 152
153 OSSL_Api osslApi = new OSSL_Api(); 153 OSSL_Api osslApi = new OSSL_Api();
154 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); 154 osslApi.Initialize(m_engine, part, null);
155 155
156 string notecardName = "appearanceNc"; 156 string notecardName = "appearanceNc";
157 osslApi.osOwnerSaveAppearance(notecardName); 157 osslApi.osOwnerSaveAppearance(notecardName);
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs
index 7d7bd82..a3f848c 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs
@@ -73,7 +73,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine.Tests
73 // to AssemblyResolver.OnAssemblyResolve fails. 73 // to AssemblyResolver.OnAssemblyResolve fails.
74 xEngineConfig.Set("AppDomainLoading", "false"); 74 xEngineConfig.Set("AppDomainLoading", "false");
75 75
76 m_scene = SceneHelpers.SetupScene("My Test", UUID.Random(), 1000, 1000, null, configSource); 76 m_scene = new SceneHelpers().SetupScene("My Test", UUID.Random(), 1000, 1000, configSource);
77 SceneHelpers.SetupSceneModules(m_scene, configSource, m_xEngine, wcModule); 77 SceneHelpers.SetupSceneModules(m_scene, configSource, m_xEngine, wcModule);
78 m_scene.StartScripts(); 78 m_scene.StartScripts();
79 } 79 }
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 1e0f01f..eeb125e 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -1089,11 +1089,18 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1089 1089
1090 AppDomain sandbox; 1090 AppDomain sandbox;
1091 if (m_AppDomainLoading) 1091 if (m_AppDomainLoading)
1092 {
1092 sandbox = AppDomain.CreateDomain( 1093 sandbox = AppDomain.CreateDomain(
1093 m_Scene.RegionInfo.RegionID.ToString(), 1094 m_Scene.RegionInfo.RegionID.ToString(),
1094 evidence, appSetup); 1095 evidence, appSetup);
1096 m_AppDomains[appDomain].AssemblyResolve +=
1097 new ResolveEventHandler(
1098 AssemblyResolver.OnAssemblyResolve);
1099 }
1095 else 1100 else
1101 {
1096 sandbox = AppDomain.CurrentDomain; 1102 sandbox = AppDomain.CurrentDomain;
1103 }
1097 1104
1098 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); 1105 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel();
1099 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); 1106 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition();
@@ -1105,9 +1112,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1105 1112
1106 m_AppDomains[appDomain] = sandbox; 1113 m_AppDomains[appDomain] = sandbox;
1107 1114
1108 m_AppDomains[appDomain].AssemblyResolve +=
1109 new ResolveEventHandler(
1110 AssemblyResolver.OnAssemblyResolve);
1111 m_DomainScripts[appDomain] = new List<UUID>(); 1115 m_DomainScripts[appDomain] = new List<UUID>();
1112 } 1116 }
1113 catch (Exception e) 1117 catch (Exception e)
@@ -1898,9 +1902,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1898 // if there already exists a file at that location, it may be locked. 1902 // if there already exists a file at that location, it may be locked.
1899 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message); 1903 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message);
1900 } 1904 }
1905
1906 string textpath = path + ".text";
1901 try 1907 try
1902 { 1908 {
1903 using (FileStream fs = File.Create(path + ".text")) 1909 using (FileStream fs = File.Create(textpath))
1904 { 1910 {
1905 using (StreamWriter sw = new StreamWriter(fs)) 1911 using (StreamWriter sw = new StreamWriter(fs))
1906 { 1912 {
@@ -1913,7 +1919,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1913 catch (IOException ex) 1919 catch (IOException ex)
1914 { 1920 {
1915 // if there already exists a file at that location, it may be locked. 1921 // if there already exists a file at that location, it may be locked.
1916 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message); 1922 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", textpath, ex.Message);
1917 } 1923 }
1918 } 1924 }
1919 } 1925 }
@@ -1962,7 +1968,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1962 catch (IOException ex) 1968 catch (IOException ex)
1963 { 1969 {
1964 // if there already exists a file at that location, it may be locked. 1970 // if there already exists a file at that location, it may be locked.
1965 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", statepath, ex.Message); 1971 m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", mappath, ex.Message);
1966 } 1972 }
1967 } 1973 }
1968 1974
@@ -1997,45 +2003,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1997 if (!topScripts.ContainsKey(si.LocalID)) 2003 if (!topScripts.ContainsKey(si.LocalID))
1998 topScripts[si.RootLocalID] = 0; 2004 topScripts[si.RootLocalID] = 0;
1999 2005
2000// long ticksElapsed = tickNow - si.MeasurementPeriodTickStart; 2006 topScripts[si.RootLocalID] += CalculateAdjustedExectionTime(si, tickNow);
2001// float framesElapsed = ticksElapsed / (18.1818 * TimeSpan.TicksPerMillisecond); 2007 }
2002 2008 }
2003 // Execution time of the script adjusted by it's measurement period to make scripts started at
2004 // different times comparable.
2005// float adjustedExecutionTime
2006// = (float)si.MeasurementPeriodExecutionTime
2007// / ((float)(tickNow - si.MeasurementPeriodTickStart) / ScriptInstance.MaxMeasurementPeriod)
2008// / TimeSpan.TicksPerMillisecond;
2009
2010 long ticksElapsed = tickNow - si.MeasurementPeriodTickStart;
2011
2012 // Avoid divide by zerp
2013 if (ticksElapsed == 0)
2014 ticksElapsed = 1;
2015 2009
2016 // Scale execution time to the ideal 55 fps frame time for these reasons. 2010 return topScripts;
2017 // 2011 }
2018 // 1) XEngine does not execute scripts per frame, unlike other script engines. Hence, there is no
2019 // 'script execution time per frame', which is the original purpose of this value.
2020 //
2021 // 2) Giving the raw execution times is misleading since scripts start at different times, making
2022 // it impossible to compare scripts.
2023 //
2024 // 3) Scaling the raw execution time to the time that the script has been running is better but
2025 // is still misleading since a script that has just been rezzed may appear to have been running
2026 // for much longer.
2027 //
2028 // 4) Hence, we scale execution time to an idealised frame time (55 fps). This is also not perfect
2029 // since the figure does not represent actual execution time and very hard running scripts will
2030 // never exceed 18ms (though this is a very high number for script execution so is a warning sign).
2031 float adjustedExecutionTime
2032 = ((float)si.MeasurementPeriodExecutionTime / ticksElapsed) * 18.1818f;
2033 2012
2034 topScripts[si.RootLocalID] += adjustedExecutionTime; 2013 public float GetScriptExecutionTime(List<UUID> itemIDs)
2014 {
2015 if (itemIDs == null|| itemIDs.Count == 0)
2016 {
2017 return 0.0f;
2018 }
2019 float time = 0.0f;
2020 long tickNow = Util.EnvironmentTickCount();
2021 IScriptInstance si;
2022 // Calculate the time for all scripts that this engine is executing
2023 // Ignore any others
2024 foreach (UUID id in itemIDs)
2025 {
2026 si = GetInstance(id);
2027 if (si != null && si.Running)
2028 {
2029 time += CalculateAdjustedExectionTime(si, tickNow);
2035 } 2030 }
2036 } 2031 }
2032 return time;
2033 }
2037 2034
2038 return topScripts; 2035 private float CalculateAdjustedExectionTime(IScriptInstance si, long tickNow)
2036 {
2037 long ticksElapsed = tickNow - si.MeasurementPeriodTickStart;
2038
2039 // Avoid divide by zero
2040 if (ticksElapsed == 0)
2041 ticksElapsed = 1;
2042
2043 // Scale execution time to the ideal 55 fps frame time for these reasons.
2044 //
2045 // 1) XEngine does not execute scripts per frame, unlike other script engines. Hence, there is no
2046 // 'script execution time per frame', which is the original purpose of this value.
2047 //
2048 // 2) Giving the raw execution times is misleading since scripts start at different times, making
2049 // it impossible to compare scripts.
2050 //
2051 // 3) Scaling the raw execution time to the time that the script has been running is better but
2052 // is still misleading since a script that has just been rezzed may appear to have been running
2053 // for much longer.
2054 //
2055 // 4) Hence, we scale execution time to an idealised frame time (55 fps). This is also not perfect
2056 // since the figure does not represent actual execution time and very hard running scripts will
2057 // never exceed 18ms (though this is a very high number for script execution so is a warning sign).
2058 return ((float)si.MeasurementPeriodExecutionTime / ticksElapsed) * 18.1818f;
2039 } 2059 }
2040 2060
2041 public void SuspendScript(UUID itemID) 2061 public void SuspendScript(UUID itemID)