aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Api/Implementation
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation')
-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.cs863
-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
7 files changed, 588 insertions, 667 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/ApiManager.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/ApiManager.cs
index 47ed6ba..684138f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/ApiManager.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/ApiManager.cs
@@ -29,42 +29,43 @@ using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Reflection; 31using System.Reflection;
32using log4net;
32using OpenSim.Region.ScriptEngine.Interfaces; 33using OpenSim.Region.ScriptEngine.Interfaces;
33 34
34namespace OpenSim.Region.ScriptEngine.Shared.Api 35namespace OpenSim.Region.ScriptEngine.Shared.Api
35{ 36{
36 public class ApiManager 37 public class ApiManager
37 { 38 {
39// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
40
38 private Dictionary<string,Type> m_Apis = new Dictionary<string,Type>(); 41 private Dictionary<string,Type> m_Apis = new Dictionary<string,Type>();
39 42
40 public string[] GetApis() 43 public string[] GetApis()
41 { 44 {
42 if (m_Apis.Count > 0) 45 if (m_Apis.Count <= 0)
43 { 46 {
44 List<string> l = new List<string>(m_Apis.Keys); 47 Assembly a = Assembly.GetExecutingAssembly();
45 return l.ToArray();
46 }
47 48
48 Assembly a = Assembly.GetExecutingAssembly(); 49 Type[] types = a.GetExportedTypes();
49 50
50 Type[] types = a.GetExportedTypes(); 51 foreach (Type t in types)
51
52 foreach (Type t in types)
53 {
54 string name = t.ToString();
55 int idx = name.LastIndexOf('.');
56 if (idx != -1)
57 name = name.Substring(idx+1);
58
59 if (name.EndsWith("_Api"))
60 { 52 {
61 name = name.Substring(0, name.Length - 4); 53 string name = t.ToString();
62 m_Apis[name] = t; 54 int idx = name.LastIndexOf('.');
55 if (idx != -1)
56 name = name.Substring(idx+1);
57
58 if (name.EndsWith("_Api"))
59 {
60 name = name.Substring(0, name.Length - 4);
61 m_Apis[name] = t;
62 }
63 } 63 }
64 } 64 }
65 65
66 List<string> ret = new List<string>(m_Apis.Keys); 66// m_log.DebugFormat("[API MANAGER]: Found {0} apis", m_Apis.Keys.Count);
67 return ret.ToArray(); 67
68 return new List<string>(m_Apis.Keys).ToArray();
68 } 69 }
69 70
70 public IScriptApi CreateApi(string api) 71 public IScriptApi CreateApi(string api)
@@ -76,4 +77,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
76 return ret; 77 return ret;
77 } 78 }
78 } 79 }
79} 80} \ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
index 489c1c6..b5fa6de 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
@@ -59,16 +59,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
59 { 59 {
60 internal IScriptEngine m_ScriptEngine; 60 internal IScriptEngine m_ScriptEngine;
61 internal SceneObjectPart m_host; 61 internal SceneObjectPart m_host;
62 internal uint m_localID; 62 internal TaskInventoryItem m_item;
63 internal UUID m_itemID;
64 internal bool m_CMFunctionsEnabled = false; 63 internal bool m_CMFunctionsEnabled = false;
65 64
66 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) 65 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item)
67 { 66 {
68 m_ScriptEngine = ScriptEngine; 67 m_ScriptEngine = ScriptEngine;
69 m_host = host; 68 m_host = host;
70 m_localID = localID; 69 m_item = item;
71 m_itemID = itemID;
72 70
73 if (m_ScriptEngine.Config.GetBoolean("AllowCareminsterFunctions", false)) 71 if (m_ScriptEngine.Config.GetBoolean("AllowCareminsterFunctions", false))
74 m_CMFunctionsEnabled = true; 72 m_CMFunctionsEnabled = true;
@@ -95,7 +93,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
95 public string cmDetectedCountry(int number) 93 public string cmDetectedCountry(int number)
96 { 94 {
97 m_host.AddScriptLPS(1); 95 m_host.AddScriptLPS(1);
98 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 96 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
99 if (detectedParams == null) 97 if (detectedParams == null)
100 return String.Empty; 98 return String.Empty;
101 return detectedParams.Country; 99 return detectedParams.Country;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 065d3df..713f832 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
@@ -2975,20 +2937,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2975 2937
2976 public LSL_Integer llGiveMoney(string destination, int amount) 2938 public LSL_Integer llGiveMoney(string destination, int amount)
2977 { 2939 {
2978 UUID invItemID=InventorySelf();
2979 if (invItemID == UUID.Zero)
2980 return 0;
2981
2982 m_host.AddScriptLPS(1); 2940 m_host.AddScriptLPS(1);
2983 2941
2984 m_host.TaskInventory.LockItemsForRead(true); 2942 if (m_item.PermsGranter == UUID.Zero)
2985 TaskInventoryItem item = m_host.TaskInventory[invItemID];
2986 m_host.TaskInventory.LockItemsForRead(false);
2987
2988 if (item.PermsGranter == UUID.Zero)
2989 return 0; 2943 return 0;
2990 2944
2991 if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0) 2945 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
2992 { 2946 {
2993 LSLError("No permissions to give money"); 2947 LSLError("No permissions to give money");
2994 return 0; 2948 return 0;
@@ -3176,11 +3130,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3176 sec = m_MinTimerInterval; 3130 sec = m_MinTimerInterval;
3177 m_host.AddScriptLPS(1); 3131 m_host.AddScriptLPS(1);
3178 // Setting timer repeat 3132 // Setting timer repeat
3179 AsyncCommands.TimerPlugin.SetTimerEvent(m_localID, m_itemID, sec); 3133 AsyncCommands.TimerPlugin.SetTimerEvent(m_host.LocalId, m_item.ItemID, sec);
3180 } 3134 }
3181 3135
3182 public virtual void llSleep(double sec) 3136 public virtual void llSleep(double sec)
3183 { 3137 {
3138// m_log.Info("llSleep snoozing " + sec + "s.");
3184 m_host.AddScriptLPS(1); 3139 m_host.AddScriptLPS(1);
3185 Thread.Sleep((int)(sec * 1000)); 3140 Thread.Sleep((int)(sec * 1000));
3186 } 3141 }
@@ -3239,29 +3194,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3239 3194
3240 public void llTakeControls(int controls, int accept, int pass_on) 3195 public void llTakeControls(int controls, int accept, int pass_on)
3241 { 3196 {
3242 TaskInventoryItem item; 3197 if (m_item.PermsGranter != UUID.Zero)
3243
3244 m_host.TaskInventory.LockItemsForRead(true);
3245 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3246 {
3247 m_host.TaskInventory.LockItemsForRead(false);
3248 return;
3249 }
3250 else
3251 { 3198 {
3252 item = m_host.TaskInventory[InventorySelf()]; 3199 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3253 }
3254 m_host.TaskInventory.LockItemsForRead(false);
3255
3256 if (item.PermsGranter != UUID.Zero)
3257 {
3258 ScenePresence presence = World.GetScenePresence(item.PermsGranter);
3259 3200
3260 if (presence != null) 3201 if (presence != null)
3261 { 3202 {
3262 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 3203 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
3263 { 3204 {
3264 presence.RegisterControlEventsToScript(controls, accept, pass_on, m_localID, m_itemID); 3205 presence.RegisterControlEventsToScript(controls, accept, pass_on, m_host.LocalId, m_item.ItemID);
3265 } 3206 }
3266 } 3207 }
3267 } 3208 }
@@ -3271,38 +3212,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3271 3212
3272 public void llReleaseControls() 3213 public void llReleaseControls()
3273 { 3214 {
3274 TaskInventoryItem item;
3275
3276 m_host.TaskInventory.LockItemsForRead(true);
3277 lock (m_host.TaskInventory)
3278 {
3279
3280 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3281 {
3282 m_host.TaskInventory.LockItemsForRead(false);
3283 return;
3284 }
3285 else
3286 {
3287 item = m_host.TaskInventory[InventorySelf()];
3288 }
3289 }
3290 m_host.TaskInventory.LockItemsForRead(false);
3291
3292 m_host.AddScriptLPS(1); 3215 m_host.AddScriptLPS(1);
3293 3216
3294 if (item.PermsGranter != UUID.Zero) 3217 if (m_item.PermsGranter != UUID.Zero)
3295 { 3218 {
3296 ScenePresence presence = World.GetScenePresence(item.PermsGranter); 3219 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3297 3220
3298 if (presence != null) 3221 if (presence != null)
3299 { 3222 {
3300 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 3223 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
3301 { 3224 {
3302 // Unregister controls from Presence 3225 // Unregister controls from Presence
3303 presence.UnRegisterControlEventsToScript(m_localID, m_itemID); 3226 presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
3304 // Remove Take Control permission. 3227 // Remove Take Control permission.
3305 item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS; 3228 m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
3306 } 3229 }
3307 } 3230 }
3308 } 3231 }
@@ -3315,86 +3238,71 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3315 m_UrlModule.ReleaseURL(url); 3238 m_UrlModule.ReleaseURL(url);
3316 } 3239 }
3317 3240
3318 public void llAttachToAvatar(int attachment) 3241 /// <summary>
3242 /// Attach the object containing this script to the avatar that owns it.
3243 /// </summary>
3244 /// <param name='attachment'>The attachment point (e.g. ATTACH_CHEST)</param>
3245 /// <returns>true if the attach suceeded, false if it did not</returns>
3246 public bool AttachToAvatar(int attachmentPoint)
3319 { 3247 {
3320 m_host.AddScriptLPS(1); 3248 SceneObjectGroup grp = m_host.ParentGroup;
3249 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
3321 3250
3322 TaskInventoryItem item; 3251 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3323
3324 m_host.TaskInventory.LockItemsForRead(true);
3325 3252
3326 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3253 if (attachmentsModule != null)
3327 { 3254 return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true);
3328 m_host.TaskInventory.LockItemsForRead(false);
3329 return;
3330 }
3331 else 3255 else
3332 { 3256 return false;
3333 item = m_host.TaskInventory[InventorySelf()]; 3257 }
3334 }
3335
3336 m_host.TaskInventory.LockItemsForRead(false);
3337 3258
3338 if (item.PermsGranter != m_host.OwnerID) 3259 /// <summary>
3339 return; 3260 /// Detach the object containing this script from the avatar it is attached to.
3261 /// </summary>
3262 /// <remarks>
3263 /// Nothing happens if the object is not attached.
3264 /// </remarks>
3265 public void DetachFromAvatar()
3266 {
3267 Util.FireAndForget(DetachWrapper, m_host);
3268 }
3340 3269
3341 if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0) 3270 private void DetachWrapper(object o)
3342 { 3271 {
3343 SceneObjectGroup grp = m_host.ParentGroup; 3272 SceneObjectPart host = (SceneObjectPart)o;
3344 3273
3345 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 3274 SceneObjectGroup grp = host.ParentGroup;
3275 UUID itemID = grp.FromItemID;
3276 ScenePresence presence = World.GetScenePresence(host.OwnerID);
3346 3277
3347 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; 3278 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3348 if (attachmentsModule != null) 3279 if (attachmentsModule != null)
3349 attachmentsModule.AttachObject(presence, grp, (uint)attachment, false, true); 3280 attachmentsModule.DetachSingleAttachmentToInv(presence, itemID);
3350 }
3351 } 3281 }
3352 3282
3353 public void llDetachFromAvatar() 3283 public void llAttachToAvatar(int attachmentPoint)
3354 { 3284 {
3355 m_host.AddScriptLPS(1); 3285 m_host.AddScriptLPS(1);
3356 3286
3357 if (m_host.ParentGroup.AttachmentPoint == 0) 3287 if (m_item.PermsGranter != m_host.OwnerID)
3358 return; 3288 return;
3359 3289
3360 TaskInventoryItem item; 3290 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
3291 AttachToAvatar(attachmentPoint);
3292 }
3361 3293
3362 m_host.TaskInventory.LockItemsForRead(true); 3294 public void llDetachFromAvatar()
3295 {
3296 m_host.AddScriptLPS(1);
3363 3297
3364 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3298 if (m_host.ParentGroup.AttachmentPoint == 0)
3365 {
3366 m_host.TaskInventory.LockItemsForRead(false);
3367 return; 3299 return;
3368 }
3369 else
3370 {
3371 item = m_host.TaskInventory[InventorySelf()];
3372 }
3373 m_host.TaskInventory.LockItemsForRead(false);
3374
3375 3300
3376 if (item.PermsGranter != m_host.OwnerID) 3301 if (m_item.PermsGranter != m_host.OwnerID)
3377 return; 3302 return;
3378 3303
3379 if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0) 3304 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
3380 { 3305 DetachFromAvatar();
3381 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3382 if (attachmentsModule != null)
3383 Util.FireAndForget(DetachWrapper, m_host);
3384 }
3385 }
3386
3387 private void DetachWrapper(object o)
3388 {
3389 SceneObjectPart host = (SceneObjectPart)o;
3390
3391 SceneObjectGroup grp = host.ParentGroup;
3392 UUID itemID = grp.FromItemID;
3393 ScenePresence presence = World.GetScenePresence(host.OwnerID);
3394
3395 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3396 if (attachmentsModule != null)
3397 attachmentsModule.DetachSingleAttachmentToInv(presence, itemID);
3398 } 3306 }
3399 3307
3400 public void llTakeCamera(string avatar) 3308 public void llTakeCamera(string avatar)
@@ -3515,7 +3423,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3515 } 3423 }
3516 3424
3517 emailModule.SendEmail(m_host.UUID, address, subject, message); 3425 emailModule.SendEmail(m_host.UUID, address, subject, message);
3518 ScriptSleep(15000); 3426 ScriptSleep(EMAIL_PAUSE_TIME * 1000);
3519 } 3427 }
3520 3428
3521 public void llGetNextEmail(string address, string subject) 3429 public void llGetNextEmail(string address, string subject)
@@ -3552,6 +3460,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3552 return m_host.UUID.ToString(); 3460 return m_host.UUID.ToString();
3553 } 3461 }
3554 3462
3463 public LSL_Key llGenerateKey()
3464 {
3465 m_host.AddScriptLPS(1);
3466 return UUID.Random().ToString();
3467 }
3468
3555 public void llSetBuoyancy(double buoyancy) 3469 public void llSetBuoyancy(double buoyancy)
3556 { 3470 {
3557 m_host.AddScriptLPS(1); 3471 m_host.AddScriptLPS(1);
@@ -3598,7 +3512,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3598 m_host.AddScriptLPS(1); 3512 m_host.AddScriptLPS(1);
3599 try 3513 try
3600 { 3514 {
3601 m_ScriptEngine.SetMinEventDelay(m_itemID, delay); 3515 m_ScriptEngine.SetMinEventDelay(m_item.ItemID, delay);
3602 } 3516 }
3603 catch (NotImplementedException) 3517 catch (NotImplementedException)
3604 { 3518 {
@@ -3651,29 +3565,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3651 { 3565 {
3652 m_host.AddScriptLPS(1); 3566 m_host.AddScriptLPS(1);
3653 3567
3654 UUID invItemID = InventorySelf(); 3568 if (m_item.PermsGranter == UUID.Zero)
3655 if (invItemID == UUID.Zero)
3656 return;
3657
3658 TaskInventoryItem item;
3659
3660 m_host.TaskInventory.LockItemsForRead(true);
3661 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3662 {
3663 m_host.TaskInventory.LockItemsForRead(false);
3664 return;
3665 }
3666 else
3667 {
3668 item = m_host.TaskInventory[InventorySelf()];
3669 }
3670 m_host.TaskInventory.LockItemsForRead(false);
3671 if (item.PermsGranter == UUID.Zero)
3672 return; 3569 return;
3673 3570
3674 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0) 3571 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3675 { 3572 {
3676 ScenePresence presence = World.GetScenePresence(item.PermsGranter); 3573 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3677 3574
3678 if (presence != null) 3575 if (presence != null)
3679 { 3576 {
@@ -3691,41 +3588,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3691 { 3588 {
3692 m_host.AddScriptLPS(1); 3589 m_host.AddScriptLPS(1);
3693 3590
3694 UUID invItemID=InventorySelf(); 3591 if (m_item.PermsGranter == UUID.Zero)
3695 if (invItemID == UUID.Zero)
3696 return; 3592 return;
3697 3593
3698 TaskInventoryItem item; 3594 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3699
3700 m_host.TaskInventory.LockItemsForRead(true);
3701 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3702 {
3703 m_host.TaskInventory.LockItemsForRead(false);
3704 return;
3705 }
3706 else
3707 { 3595 {
3708 item = m_host.TaskInventory[InventorySelf()]; 3596 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3709 }
3710 m_host.TaskInventory.LockItemsForRead(false);
3711
3712
3713 if (item.PermsGranter == UUID.Zero)
3714 return;
3715
3716 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3717 {
3718 UUID animID = new UUID();
3719
3720 if (!UUID.TryParse(anim, out animID))
3721 {
3722 animID=InventoryKey(anim);
3723 }
3724
3725 ScenePresence presence = World.GetScenePresence(item.PermsGranter);
3726 3597
3727 if (presence != null) 3598 if (presence != null)
3728 { 3599 {
3600 UUID animID = KeyOrName(anim);
3601
3729 if (animID == UUID.Zero) 3602 if (animID == UUID.Zero)
3730 presence.Animator.RemoveAnimation(anim); 3603 presence.Animator.RemoveAnimation(anim);
3731 else 3604 else
@@ -3758,44 +3631,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3758 public LSL_Integer llGetStartParameter() 3631 public LSL_Integer llGetStartParameter()
3759 { 3632 {
3760 m_host.AddScriptLPS(1); 3633 m_host.AddScriptLPS(1);
3761 return m_ScriptEngine.GetStartParameter(m_itemID); 3634 return m_ScriptEngine.GetStartParameter(m_item.ItemID);
3762 } 3635 }
3763 3636
3764 public void llRequestPermissions(string agent, int perm) 3637 public void llRequestPermissions(string agent, int perm)
3765 { 3638 {
3766 UUID agentID = new UUID(); 3639 UUID agentID;
3767 3640
3768 if (!UUID.TryParse(agent, out agentID)) 3641 if (!UUID.TryParse(agent, out agentID))
3769 return; 3642 return;
3770 3643
3771 UUID invItemID = InventorySelf();
3772
3773 if (invItemID == UUID.Zero)
3774 return; // Not in a prim? How??
3775
3776 TaskInventoryItem item;
3777
3778
3779 m_host.TaskInventory.LockItemsForRead(true);
3780 if (!m_host.TaskInventory.ContainsKey(invItemID))
3781 {
3782 m_host.TaskInventory.LockItemsForRead(false);
3783 return;
3784 }
3785 else
3786 {
3787 item = m_host.TaskInventory[invItemID];
3788 }
3789 m_host.TaskInventory.LockItemsForRead(false);
3790
3791 if (agentID == UUID.Zero || perm == 0) // Releasing permissions 3644 if (agentID == UUID.Zero || perm == 0) // Releasing permissions
3792 { 3645 {
3793 llReleaseControls(); 3646 llReleaseControls();
3794 3647
3795 item.PermsGranter = UUID.Zero; 3648 m_item.PermsGranter = UUID.Zero;
3796 item.PermsMask = 0; 3649 m_item.PermsMask = 0;
3797 3650
3798 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3651 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3799 "run_time_permissions", new Object[] { 3652 "run_time_permissions", new Object[] {
3800 new LSL_Integer(0) }, 3653 new LSL_Integer(0) },
3801 new DetectParams[0])); 3654 new DetectParams[0]));
@@ -3803,7 +3656,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3803 return; 3656 return;
3804 } 3657 }
3805 3658
3806 if (item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3659 if (m_item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3807 llReleaseControls(); 3660 llReleaseControls();
3808 3661
3809 m_host.AddScriptLPS(1); 3662 m_host.AddScriptLPS(1);
@@ -3820,11 +3673,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3820 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3673 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3821 { 3674 {
3822 m_host.TaskInventory.LockItemsForWrite(true); 3675 m_host.TaskInventory.LockItemsForWrite(true);
3823 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3676 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3824 m_host.TaskInventory[invItemID].PermsMask = perm; 3677 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3825 m_host.TaskInventory.LockItemsForWrite(false); 3678 m_host.TaskInventory.LockItemsForWrite(false);
3826 3679
3827 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3680 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3828 "run_time_permissions", new Object[] { 3681 "run_time_permissions", new Object[] {
3829 new LSL_Integer(perm) }, 3682 new LSL_Integer(perm) },
3830 new DetectParams[0])); 3683 new DetectParams[0]));
@@ -3859,11 +3712,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3859 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3712 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3860 { 3713 {
3861 m_host.TaskInventory.LockItemsForWrite(true); 3714 m_host.TaskInventory.LockItemsForWrite(true);
3862 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3715 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3863 m_host.TaskInventory[invItemID].PermsMask = perm; 3716 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3864 m_host.TaskInventory.LockItemsForWrite(false); 3717 m_host.TaskInventory.LockItemsForWrite(false);
3865 3718
3866 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3719 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3867 "run_time_permissions", new Object[] { 3720 "run_time_permissions", new Object[] {
3868 new LSL_Integer(perm) }, 3721 new LSL_Integer(perm) },
3869 new DetectParams[0])); 3722 new DetectParams[0]));
@@ -3874,9 +3727,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3874 } 3727 }
3875 3728
3876 ScenePresence presence = World.GetScenePresence(agentID); 3729 ScenePresence presence = World.GetScenePresence(agentID);
3877
3878 if (presence != null) 3730 if (presence != null)
3879 { 3731 {
3732 // If permissions are being requested from an NPC and were not implicitly granted above then
3733 // auto grant all reuqested permissions if the script is owned by the NPC or the NPCs owner
3734 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
3735 if (npcModule != null && npcModule.IsNPC(agentID, World))
3736 {
3737 if (agentID == m_host.ParentGroup.OwnerID || npcModule.GetOwner(agentID) == m_host.ParentGroup.OwnerID)
3738 {
3739 lock (m_host.TaskInventory)
3740 {
3741 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3742 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3743 }
3744
3745 m_ScriptEngine.PostScriptEvent(
3746 m_item.ItemID,
3747 new EventParams(
3748 "run_time_permissions", new Object[] { new LSL_Integer(perm) }, new DetectParams[0]));
3749 }
3750
3751 // it is an NPC, exit even if the permissions werent granted above, they are not going to answer
3752 // the question!
3753 return;
3754 }
3755
3880 string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID); 3756 string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
3881 if (ownerName == String.Empty) 3757 if (ownerName == String.Empty)
3882 ownerName = "(hippos)"; 3758 ownerName = "(hippos)";
@@ -3884,8 +3760,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3884 if (!m_waitingForScriptAnswer) 3760 if (!m_waitingForScriptAnswer)
3885 { 3761 {
3886 m_host.TaskInventory.LockItemsForWrite(true); 3762 m_host.TaskInventory.LockItemsForWrite(true);
3887 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3763 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3888 m_host.TaskInventory[invItemID].PermsMask = 0; 3764 m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
3889 m_host.TaskInventory.LockItemsForWrite(false); 3765 m_host.TaskInventory.LockItemsForWrite(false);
3890 3766
3891 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 3767 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
@@ -3893,16 +3769,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3893 } 3769 }
3894 3770
3895 presence.ControllingClient.SendScriptQuestion( 3771 presence.ControllingClient.SendScriptQuestion(
3896 m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, invItemID, perm); 3772 m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_item.ItemID, perm);
3897 3773
3898 return; 3774 return;
3899 } 3775 }
3900 3776
3901 // Requested agent is not in range, refuse perms 3777 // Requested agent is not in range, refuse perms
3902 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3778 m_ScriptEngine.PostScriptEvent(
3903 "run_time_permissions", new Object[] { 3779 m_item.ItemID,
3904 new LSL_Integer(0) }, 3780 new EventParams("run_time_permissions", new Object[] { new LSL_Integer(0) }, new DetectParams[0]));
3905 new DetectParams[0]));
3906 } 3781 }
3907 3782
3908 void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer) 3783 void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
@@ -3910,24 +3785,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3910 if (taskID != m_host.UUID) 3785 if (taskID != m_host.UUID)
3911 return; 3786 return;
3912 3787
3913 UUID invItemID = InventorySelf(); 3788 client.OnScriptAnswer -= handleScriptAnswer;
3914 3789 m_waitingForScriptAnswer = false;
3915 if (invItemID == UUID.Zero)
3916 return;
3917
3918 client.OnScriptAnswer-=handleScriptAnswer;
3919 m_waitingForScriptAnswer=false;
3920 3790
3921 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3791 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3922 llReleaseControls(); 3792 llReleaseControls();
3923 3793
3924
3925 m_host.TaskInventory.LockItemsForWrite(true); 3794 m_host.TaskInventory.LockItemsForWrite(true);
3926 m_host.TaskInventory[invItemID].PermsMask = answer; 3795 m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
3927 m_host.TaskInventory.LockItemsForWrite(false); 3796 m_host.TaskInventory.LockItemsForWrite(false);
3928 3797
3929 3798 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3930 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3931 "run_time_permissions", new Object[] { 3799 "run_time_permissions", new Object[] {
3932 new LSL_Integer(answer) }, 3800 new LSL_Integer(answer) },
3933 new DetectParams[0])); 3801 new DetectParams[0]));
@@ -3937,41 +3805,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3937 { 3805 {
3938 m_host.AddScriptLPS(1); 3806 m_host.AddScriptLPS(1);
3939 3807
3940 m_host.TaskInventory.LockItemsForRead(true); 3808 return m_item.PermsGranter.ToString();
3941
3942 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3943 {
3944 if (item.Type == 10 && item.ItemID == m_itemID)
3945 {
3946 m_host.TaskInventory.LockItemsForRead(false);
3947 return item.PermsGranter.ToString();
3948 }
3949 }
3950 m_host.TaskInventory.LockItemsForRead(false);
3951
3952 return UUID.Zero.ToString();
3953 } 3809 }
3954 3810
3955 public LSL_Integer llGetPermissions() 3811 public LSL_Integer llGetPermissions()
3956 { 3812 {
3957 m_host.AddScriptLPS(1); 3813 m_host.AddScriptLPS(1);
3958 3814
3959 m_host.TaskInventory.LockItemsForRead(true); 3815 int perms = m_item.PermsMask;
3960 3816
3961 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3817 if (m_automaticLinkPermission)
3962 { 3818 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3963 if (item.Type == 10 && item.ItemID == m_itemID)
3964 {
3965 int perms = item.PermsMask;
3966 if (m_automaticLinkPermission)
3967 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3968 m_host.TaskInventory.LockItemsForRead(false);
3969 return perms;
3970 }
3971 }
3972 m_host.TaskInventory.LockItemsForRead(false);
3973 3819
3974 return 0; 3820 return perms;
3975 } 3821 }
3976 3822
3977 public LSL_Integer llGetLinkNumber() 3823 public LSL_Integer llGetLinkNumber()
@@ -4009,18 +3855,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4009 public void llCreateLink(string target, int parent) 3855 public void llCreateLink(string target, int parent)
4010 { 3856 {
4011 m_host.AddScriptLPS(1); 3857 m_host.AddScriptLPS(1);
4012 UUID invItemID = InventorySelf(); 3858
4013 UUID targetID; 3859 UUID targetID;
4014 3860
4015 if (!UUID.TryParse(target, out targetID)) 3861 if (!UUID.TryParse(target, out targetID))
4016 return; 3862 return;
4017 3863
4018 TaskInventoryItem item; 3864 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4019 m_host.TaskInventory.LockItemsForRead(true);
4020 item = m_host.TaskInventory[invItemID];
4021 m_host.TaskInventory.LockItemsForRead(false);
4022
4023 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4024 && !m_automaticLinkPermission) 3865 && !m_automaticLinkPermission)
4025 { 3866 {
4026 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3867 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
@@ -4028,7 +3869,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4028 } 3869 }
4029 3870
4030 IClientAPI client = null; 3871 IClientAPI client = null;
4031 ScenePresence sp = World.GetScenePresence(item.PermsGranter); 3872 ScenePresence sp = World.GetScenePresence(m_item.PermsGranter);
4032 if (sp != null) 3873 if (sp != null)
4033 client = sp.ControllingClient; 3874 client = sp.ControllingClient;
4034 3875
@@ -4074,18 +3915,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4074 public void llBreakLink(int linknum) 3915 public void llBreakLink(int linknum)
4075 { 3916 {
4076 m_host.AddScriptLPS(1); 3917 m_host.AddScriptLPS(1);
4077 UUID invItemID = InventorySelf();
4078 3918
4079 m_host.TaskInventory.LockItemsForRead(true); 3919 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4080 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3920 && !m_automaticLinkPermission)
4081 && !m_automaticLinkPermission) 3921 {
4082 { 3922 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
4083 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3923 return;
4084 m_host.TaskInventory.LockItemsForRead(false); 3924 }
4085 return; 3925
4086 }
4087 m_host.TaskInventory.LockItemsForRead(false);
4088
4089 if (linknum < ScriptBaseClass.LINK_THIS) 3926 if (linknum < ScriptBaseClass.LINK_THIS)
4090 return; 3927 return;
4091 3928
@@ -4184,12 +4021,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4184 { 4021 {
4185 m_host.AddScriptLPS(1); 4022 m_host.AddScriptLPS(1);
4186 4023
4187 UUID invItemID = InventorySelf(); 4024 TaskInventoryItem item = m_item;
4188
4189 TaskInventoryItem item;
4190 m_host.TaskInventory.LockItemsForRead(true);
4191 item = m_host.TaskInventory[invItemID];
4192 m_host.TaskInventory.LockItemsForRead(false);
4193 4025
4194 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 4026 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4195 && !m_automaticLinkPermission) 4027 && !m_automaticLinkPermission)
@@ -4500,7 +4332,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4500 { 4332 {
4501 if (item.Name == name) 4333 if (item.Name == name)
4502 { 4334 {
4503 if (item.ItemID == m_itemID) 4335 if (item.ItemID == m_item.ItemID)
4504 throw new ScriptDeleteException(); 4336 throw new ScriptDeleteException();
4505 else 4337 else
4506 m_host.Inventory.RemoveInventoryItem(item.ItemID); 4338 m_host.Inventory.RemoveInventoryItem(item.ItemID);
@@ -4634,8 +4466,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4634 UUID rq = UUID.Random(); 4466 UUID rq = UUID.Random();
4635 4467
4636 UUID tid = AsyncCommands. 4468 UUID tid = AsyncCommands.
4637 DataserverPlugin.RegisterRequest(m_localID, 4469 DataserverPlugin.RegisterRequest(m_host.LocalId,
4638 m_itemID, rq.ToString()); 4470 m_item.ItemID, rq.ToString());
4639 4471
4640 AsyncCommands. 4472 AsyncCommands.
4641 DataserverPlugin.DataserverReply(rq.ToString(), reply); 4473 DataserverPlugin.DataserverReply(rq.ToString(), reply);
@@ -4662,8 +4494,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4662 if (item.Type == 3 && item.Name == name) 4494 if (item.Type == 3 && item.Name == name)
4663 { 4495 {
4664 UUID tid = AsyncCommands. 4496 UUID tid = AsyncCommands.
4665 DataserverPlugin.RegisterRequest(m_localID, 4497 DataserverPlugin.RegisterRequest(m_host.LocalId,
4666 m_itemID, item.AssetID.ToString()); 4498 m_item.ItemID, item.AssetID.ToString());
4667 4499
4668 Vector3 region = new Vector3( 4500 Vector3 region = new Vector3(
4669 World.RegionInfo.RegionLocX * Constants.RegionSize, 4501 World.RegionInfo.RegionLocX * Constants.RegionSize,
@@ -5136,22 +4968,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5136 4968
5137 public LSL_String llGetScriptName() 4969 public LSL_String llGetScriptName()
5138 { 4970 {
5139 string result = String.Empty;
5140
5141 m_host.AddScriptLPS(1); 4971 m_host.AddScriptLPS(1);
5142 4972
5143 m_host.TaskInventory.LockItemsForRead(true); 4973 return m_item.Name != null ? m_item.Name : String.Empty;
5144 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
5145 {
5146 if (item.Type == 10 && item.ItemID == m_itemID)
5147 {
5148 result = item.Name!=null?item.Name:String.Empty;
5149 break;
5150 }
5151 }
5152 m_host.TaskInventory.LockItemsForRead(false);
5153
5154 return result;
5155 } 4974 }
5156 4975
5157 public LSL_Integer llGetLinkNumberOfSides(int link) 4976 public LSL_Integer llGetLinkNumberOfSides(int link)
@@ -6285,7 +6104,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6285 } 6104 }
6286 } 6105 }
6287 } 6106 }
6288 List<UUID> presenceIds = new List<UUID>();
6289 6107
6290 World.ForEachRootScenePresence( 6108 World.ForEachRootScenePresence(
6291 delegate (ScenePresence ssp) 6109 delegate (ScenePresence ssp)
@@ -6436,7 +6254,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6436 if (m_host.OwnerID == land.LandData.OwnerID) 6254 if (m_host.OwnerID == land.LandData.OwnerID)
6437 { 6255 {
6438 Vector3 pos = World.GetNearestAllowedPosition(presence, land); 6256 Vector3 pos = World.GetNearestAllowedPosition(presence, land);
6439 presence.TeleportWithMomentum(pos); 6257 presence.TeleportWithMomentum(pos, null);
6440 presence.ControllingClient.SendAlertMessage("You have been ejected from this land"); 6258 presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
6441 } 6259 }
6442 } 6260 }
@@ -7383,14 +7201,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7383 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); 7201 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
7384 if (xmlrpcMod.IsEnabled()) 7202 if (xmlrpcMod.IsEnabled())
7385 { 7203 {
7386 UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_localID, m_itemID, UUID.Zero); 7204 UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero);
7387 IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>(); 7205 IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
7388 if (xmlRpcRouter != null) 7206 if (xmlRpcRouter != null)
7389 { 7207 {
7390 string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName; 7208 string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
7391 7209
7392 xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID, 7210 xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
7393 m_itemID, String.Format("http://{0}:{1}/", ExternalHostName, 7211 m_item.ItemID, String.Format("http://{0}:{1}/", ExternalHostName,
7394 xmlrpcMod.Port.ToString())); 7212 xmlrpcMod.Port.ToString()));
7395 } 7213 }
7396 object[] resobj = new object[] 7214 object[] resobj = new object[]
@@ -7402,7 +7220,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7402 new LSL_Integer(0), 7220 new LSL_Integer(0),
7403 new LSL_String(String.Empty) 7221 new LSL_String(String.Empty)
7404 }; 7222 };
7405 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams("remote_data", resobj, 7223 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj,
7406 new DetectParams[0])); 7224 new DetectParams[0]));
7407 } 7225 }
7408 ScriptSleep(1000); 7226 ScriptSleep(1000);
@@ -7413,7 +7231,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7413 m_host.AddScriptLPS(1); 7231 m_host.AddScriptLPS(1);
7414 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); 7232 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
7415 ScriptSleep(3000); 7233 ScriptSleep(3000);
7416 return (xmlrpcMod.SendRemoteData(m_localID, m_itemID, channel, dest, idata, sdata)).ToString(); 7234 return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString();
7417 } 7235 }
7418 7236
7419 public void llRemoteDataReply(string channel, string message_id, string sdata, int idata) 7237 public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
@@ -8252,7 +8070,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8252 return; 8070 return;
8253 face = (int)rules.GetLSLIntegerItem(idx++); 8071 face = (int)rules.GetLSLIntegerItem(idx++);
8254 int shiny = (int)rules.GetLSLIntegerItem(idx++); 8072 int shiny = (int)rules.GetLSLIntegerItem(idx++);
8255 Bumpiness bump = (Bumpiness)Convert.ToByte((int)rules.GetLSLIntegerItem(idx++)); 8073 Bumpiness bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);
8256 8074
8257 SetShiny(part, face, shiny, bump); 8075 SetShiny(part, face, shiny, bump);
8258 8076
@@ -9717,7 +9535,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9717 public LSL_String llGetSimulatorHostname() 9535 public LSL_String llGetSimulatorHostname()
9718 { 9536 {
9719 m_host.AddScriptLPS(1); 9537 m_host.AddScriptLPS(1);
9720 return System.Environment.MachineName; 9538 IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
9539 return UrlModule.ExternalHostNameForLSL;
9721 } 9540 }
9722 9541
9723 // <summary> 9542 // <summary>
@@ -10056,13 +9875,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10056 { 9875 {
10057 m_host.AddScriptLPS(1); 9876 m_host.AddScriptLPS(1);
10058 if (m_UrlModule != null) 9877 if (m_UrlModule != null)
10059 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString(); 9878 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
10060 return UUID.Zero.ToString(); 9879 return UUID.Zero.ToString();
10061 } 9880 }
10062 9881
10063 public LSL_String llRequestSimulatorData(string simulator, int data) 9882 public LSL_String llRequestSimulatorData(string simulator, int data)
10064 { 9883 {
10065 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_itemID, "OSSL"); 9884 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
10066 9885
10067 try 9886 try
10068 { 9887 {
@@ -10072,7 +9891,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10072 9891
10073 GridRegion info; 9892 GridRegion info;
10074 9893
10075 if (m_ScriptEngine.World.RegionInfo.RegionName == simulator) 9894 if (m_ScriptEngine.World.RegionInfo.RegionName == simulator) //Det data for this simulator?
9895
10076 info = new GridRegion(m_ScriptEngine.World.RegionInfo); 9896 info = new GridRegion(m_ScriptEngine.World.RegionInfo);
10077 else 9897 else
10078 info = m_ScriptEngine.World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator); 9898 info = m_ScriptEngine.World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator);
@@ -10085,10 +9905,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10085 ScriptSleep(1000); 9905 ScriptSleep(1000);
10086 return UUID.Zero.ToString(); 9906 return UUID.Zero.ToString();
10087 } 9907 }
10088 reply = new LSL_Vector( 9908 if (m_ScriptEngine.World.RegionInfo.RegionName != simulator)
10089 info.RegionLocX, 9909 {
10090 info.RegionLocY, 9910 //Hypergrid Region co-ordinates
10091 0).ToString(); 9911 uint rx = 0, ry = 0;
9912 Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out rx, out ry);
9913
9914 reply = new LSL_Vector(
9915 rx,
9916 ry,
9917 0).ToString();
9918 }
9919 else
9920 {
9921 //Local-cooridnates
9922 reply = new LSL_Vector(
9923 info.RegionLocX,
9924 info.RegionLocY,
9925 0).ToString();
9926 }
10092 break; 9927 break;
10093 case ScriptBaseClass.DATA_SIM_STATUS: 9928 case ScriptBaseClass.DATA_SIM_STATUS:
10094 if (info != null) 9929 if (info != null)
@@ -10124,7 +9959,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10124 UUID rq = UUID.Random(); 9959 UUID rq = UUID.Random();
10125 9960
10126 UUID tid = AsyncCommands. 9961 UUID tid = AsyncCommands.
10127 DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 9962 DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
10128 9963
10129 AsyncCommands. 9964 AsyncCommands.
10130 DataserverPlugin.DataserverReply(rq.ToString(), reply); 9965 DataserverPlugin.DataserverReply(rq.ToString(), reply);
@@ -10143,7 +9978,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10143 m_host.AddScriptLPS(1); 9978 m_host.AddScriptLPS(1);
10144 9979
10145 if (m_UrlModule != null) 9980 if (m_UrlModule != null)
10146 return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString(); 9981 return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
10147 return UUID.Zero.ToString(); 9982 return UUID.Zero.ToString();
10148 } 9983 }
10149 9984
@@ -10179,7 +10014,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10179 // child agents have a mass of 1.0 10014 // child agents have a mass of 1.0
10180 return 1; 10015 return 1;
10181 else 10016 else
10182 return avatar.GetMass(); 10017 return (double)avatar.GetMass();
10183 } 10018 }
10184 catch (KeyNotFoundException) 10019 catch (KeyNotFoundException)
10185 { 10020 {
@@ -10622,32 +10457,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10622 public LSL_Vector llGetCameraPos() 10457 public LSL_Vector llGetCameraPos()
10623 { 10458 {
10624 m_host.AddScriptLPS(1); 10459 m_host.AddScriptLPS(1);
10625 UUID invItemID = InventorySelf();
10626 10460
10627 if (invItemID == UUID.Zero) 10461 if (m_item.PermsGranter == UUID.Zero)
10628 return new LSL_Vector(); 10462 return new LSL_Vector();
10629
10630 m_host.TaskInventory.LockItemsForRead(true);
10631
10632 UUID agentID = m_host.TaskInventory[invItemID].PermsGranter;
10633
10634// if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
10635 if (agentID == UUID.Zero)
10636 {
10637 m_host.TaskInventory.LockItemsForRead(false);
10638 return new LSL_Vector();
10639 }
10640 10463
10641 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) 10464 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
10642 { 10465 {
10643 ShoutError("No permissions to track the camera"); 10466 ShoutError("No permissions to track the camera");
10644 m_host.TaskInventory.LockItemsForRead(false);
10645 return new LSL_Vector(); 10467 return new LSL_Vector();
10646 } 10468 }
10647 m_host.TaskInventory.LockItemsForRead(false);
10648 10469
10649// ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10470// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
10650 ScenePresence presence = World.GetScenePresence(agentID); 10471 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
10651 if (presence != null) 10472 if (presence != null)
10652 { 10473 {
10653 LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z); 10474 LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z);
@@ -10659,30 +10480,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10659 public LSL_Rotation llGetCameraRot() 10480 public LSL_Rotation llGetCameraRot()
10660 { 10481 {
10661 m_host.AddScriptLPS(1); 10482 m_host.AddScriptLPS(1);
10662 UUID invItemID = InventorySelf();
10663 if (invItemID == UUID.Zero)
10664 return new LSL_Rotation();
10665
10666 m_host.TaskInventory.LockItemsForRead(true);
10667 10483
10668 UUID agentID = m_host.TaskInventory[invItemID].PermsGranter; 10484 if (m_item.PermsGranter == UUID.Zero)
10485 return new LSL_Rotation();
10669 10486
10670// if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 10487 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
10671 if (agentID == UUID.Zero)
10672 {
10673 m_host.TaskInventory.LockItemsForRead(false);
10674 return new LSL_Rotation();
10675 }
10676 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
10677 { 10488 {
10678 ShoutError("No permissions to track the camera"); 10489 ShoutError("No permissions to track the camera");
10679 m_host.TaskInventory.LockItemsForRead(false);
10680 return new LSL_Rotation(); 10490 return new LSL_Rotation();
10681 } 10491 }
10682 m_host.TaskInventory.LockItemsForRead(false);
10683 10492
10684// ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10493// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
10685 ScenePresence presence = World.GetScenePresence(agentID); 10494 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
10686 if (presence != null) 10495 if (presence != null)
10687 { 10496 {
10688 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W); 10497 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W);
@@ -10741,7 +10550,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10741 public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt) 10550 public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
10742 { 10551 {
10743 m_host.AddScriptLPS(1); 10552 m_host.AddScriptLPS(1);
10744 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0); 10553 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
10745 if (detectedParams == null) 10554 if (detectedParams == null)
10746 { 10555 {
10747 if (m_host.ParentGroup.IsAttachment == true) 10556 if (m_host.ParentGroup.IsAttachment == true)
@@ -10865,30 +10674,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10865 { 10674 {
10866 m_host.AddScriptLPS(1); 10675 m_host.AddScriptLPS(1);
10867 10676
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 10677 // the object we are in
10873 UUID objectID = m_host.ParentUUID; 10678 UUID objectID = m_host.ParentUUID;
10874 if (objectID == UUID.Zero) return; 10679 if (objectID == UUID.Zero)
10680 return;
10875 10681
10876 UUID agentID;
10877 m_host.TaskInventory.LockItemsForRead(true);
10878 // we need the permission first, to know which avatar we want to set the camera for 10682 // we need the permission first, to know which avatar we want to set the camera for
10879 agentID = m_host.TaskInventory[invItemID].PermsGranter; 10683 UUID agentID = m_item.PermsGranter;
10880 10684
10881 if (agentID == UUID.Zero) 10685 if (agentID == UUID.Zero)
10882 {
10883 m_host.TaskInventory.LockItemsForRead(false);
10884 return; 10686 return;
10885 } 10687
10886 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) 10688 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
10887 {
10888 m_host.TaskInventory.LockItemsForRead(false);
10889 return; 10689 return;
10890 }
10891 m_host.TaskInventory.LockItemsForRead(false);
10892 10690
10893 ScenePresence presence = World.GetScenePresence(agentID); 10691 ScenePresence presence = World.GetScenePresence(agentID);
10894 10692
@@ -10930,34 +10728,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10930 { 10728 {
10931 m_host.AddScriptLPS(1); 10729 m_host.AddScriptLPS(1);
10932 10730
10933 // our key in the object we are in
10934 UUID invItemID=InventorySelf();
10935 if (invItemID == UUID.Zero) return;
10936
10937 // the object we are in 10731 // the object we are in
10938 UUID objectID = m_host.ParentUUID; 10732 UUID objectID = m_host.ParentUUID;
10939 if (objectID == UUID.Zero) return; 10733 if (objectID == UUID.Zero)
10734 return;
10940 10735
10941 // we need the permission first, to know which avatar we want to clear the camera for 10736 // we need the permission first, to know which avatar we want to clear the camera for
10942 UUID agentID; 10737 UUID agentID = m_item.PermsGranter;
10943 m_host.TaskInventory.LockItemsForRead(true); 10738
10944 agentID = m_host.TaskInventory[invItemID].PermsGranter;
10945 if (agentID == UUID.Zero) 10739 if (agentID == UUID.Zero)
10946 {
10947 m_host.TaskInventory.LockItemsForRead(false);
10948 return; 10740 return;
10949 } 10741
10950 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) 10742 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
10951 {
10952 m_host.TaskInventory.LockItemsForRead(false);
10953 return; 10743 return;
10954 }
10955 m_host.TaskInventory.LockItemsForRead(false);
10956 10744
10957 ScenePresence presence = World.GetScenePresence(agentID); 10745 ScenePresence presence = World.GetScenePresence(agentID);
10958 10746
10959 // we are not interested in child-agents 10747 // we are not interested in child-agents
10960 if (presence.IsChildAgent) return; 10748 if (presence.IsChildAgent)
10749 return;
10961 10750
10962 presence.ControllingClient.SendClearFollowCamProperties(objectID); 10751 presence.ControllingClient.SendClearFollowCamProperties(objectID);
10963 } 10752 }
@@ -11148,8 +10937,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11148 } 10937 }
11149 } 10938 }
11150 10939
11151 UUID reqID = httpScriptMod. 10940 UUID reqID
11152 StartHttpRequest(m_localID, m_itemID, url, param, httpHeaders, body); 10941 = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body);
11153 10942
11154 if (reqID != UUID.Zero) 10943 if (reqID != UUID.Zero)
11155 return reqID.ToString(); 10944 return reqID.ToString();
@@ -11381,19 +11170,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11381 break; 11170 break;
11382 // For the following 8 see the Object version below 11171 // For the following 8 see the Object version below
11383 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT: 11172 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
11384 ret.Add(new LSL_Integer(0)); 11173 ret.Add(new LSL_Integer(av.RunningScriptCount()));
11385 break; 11174 break;
11386 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT: 11175 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
11387 ret.Add(new LSL_Integer(0)); 11176 ret.Add(new LSL_Integer(av.ScriptCount()));
11388 break; 11177 break;
11389 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY: 11178 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
11390 ret.Add(new LSL_Integer(0)); 11179 ret.Add(new LSL_Integer(av.RunningScriptCount() * 16384));
11391 break; 11180 break;
11392 case ScriptBaseClass.OBJECT_SCRIPT_TIME: 11181 case ScriptBaseClass.OBJECT_SCRIPT_TIME:
11393 ret.Add(new LSL_Float(0)); 11182 ret.Add(new LSL_Float(av.ScriptExecutionTime() / 1000.0f));
11394 break; 11183 break;
11395 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE: 11184 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
11396 ret.Add(new LSL_Integer(0)); 11185 ret.Add(new LSL_Integer(1));
11397 break; 11186 break;
11398 case ScriptBaseClass.OBJECT_SERVER_COST: 11187 case ScriptBaseClass.OBJECT_SERVER_COST:
11399 ret.Add(new LSL_Float(0)); 11188 ret.Add(new LSL_Float(0));
@@ -11445,43 +11234,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11445 case ScriptBaseClass.OBJECT_CREATOR: 11234 case ScriptBaseClass.OBJECT_CREATOR:
11446 ret.Add(new LSL_String(obj.CreatorID.ToString())); 11235 ret.Add(new LSL_String(obj.CreatorID.ToString()));
11447 break; 11236 break;
11448 // The following 8 I have intentionaly coded to return zero. They are part of
11449 // "Land Impact" calculations. These calculations are probably not applicable
11450 // to OpenSim, required figures (cpu/memory usage) are not currently tracked
11451 // I have intentionally left these all at zero rather than return possibly
11452 // missleading numbers
11453 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT: 11237 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
11454 // in SL this currently includes crashed scripts 11238 ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount()));
11455 ret.Add(new LSL_Integer(0));
11456 break; 11239 break;
11457 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT: 11240 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
11458 ret.Add(new LSL_Integer(0)); 11241 ret.Add(new LSL_Integer(obj.ParentGroup.ScriptCount()));
11459 break; 11242 break;
11460 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY: 11243 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
11461 // The value returned in SL for mono scripts is 65536 * number of active scripts 11244 // The value returned in SL for mono scripts is 65536 * number of active scripts
11462 ret.Add(new LSL_Integer(0)); 11245 // and 16384 * number of active scripts for LSO. since llGetFreememory
11246 // is coded to give the LSO value use it here
11247 ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount() * 16384));
11463 break; 11248 break;
11464 case ScriptBaseClass.OBJECT_SCRIPT_TIME: 11249 case ScriptBaseClass.OBJECT_SCRIPT_TIME:
11465 // Average cpu time per simulator frame expended on all scripts in the objetc 11250 // Average cpu time in seconds per simulator frame expended on all scripts in the object
11466 ret.Add(new LSL_Float(0)); 11251 ret.Add(new LSL_Float(obj.ParentGroup.ScriptExecutionTime() / 1000.0f));
11467 break; 11252 break;
11468 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE: 11253 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
11469 // according to the SL wiki A prim or linkset will have prim 11254 // according to the SL wiki A prim or linkset will have prim
11470 // equivalent of the number of prims in a linkset if it does not 11255 // equivalent of the number of prims in a linkset if it does not
11471 // contain a mesh anywhere in the link set or is not a normal prim 11256 // contain a mesh anywhere in the link set or is not a normal prim
11472 // The value returned in SL for normal prims is prim count 11257 // The value returned in SL for normal prims is prim count
11473 ret.Add(new LSL_Integer(0)); 11258 ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
11474 break; 11259 break;
11260 // The following 3 costs I have intentionaly coded to return zero. They are part of
11261 // "Land Impact" calculations. These calculations are probably not applicable
11262 // to OpenSim and are not yet complete in SL
11475 case ScriptBaseClass.OBJECT_SERVER_COST: 11263 case ScriptBaseClass.OBJECT_SERVER_COST:
11476 // The value returned in SL for normal prims is prim count 11264 // The linden calculation is here
11265 // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
11266 // The value returned in SL for normal prims looks like the prim count
11477 ret.Add(new LSL_Float(0)); 11267 ret.Add(new LSL_Float(0));
11478 break; 11268 break;
11479 case ScriptBaseClass.OBJECT_STREAMING_COST: 11269 case ScriptBaseClass.OBJECT_STREAMING_COST:
11480 // The value returned in SL for normal prims is prim count * 0.06 11270 // The linden calculation is here
11271 // http://wiki.secondlife.com/wiki/Mesh/Mesh_Streaming_Cost
11272 // The value returned in SL for normal prims looks like the prim count * 0.06
11481 ret.Add(new LSL_Float(0)); 11273 ret.Add(new LSL_Float(0));
11482 break; 11274 break;
11483 case ScriptBaseClass.OBJECT_PHYSICS_COST: 11275 case ScriptBaseClass.OBJECT_PHYSICS_COST:
11484 // The value returned in SL for normal prims is prim count 11276 // The linden calculation is here
11277 // http://wiki.secondlife.com/wiki/Mesh/Mesh_physics
11278 // The value returned in SL for normal prims looks like the prim count
11485 ret.Add(new LSL_Float(0)); 11279 ret.Add(new LSL_Float(0));
11486 break; 11280 break;
11487 default: 11281 default:
@@ -11579,7 +11373,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11579 } 11373 }
11580 11374
11581 // was: UUID tid = tid = AsyncCommands. 11375 // was: UUID tid = tid = AsyncCommands.
11582 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());
11583 11377
11584 if (NotecardCache.IsCached(assetID)) 11378 if (NotecardCache.IsCached(assetID))
11585 { 11379 {
@@ -11642,7 +11436,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11642 } 11436 }
11643 11437
11644 // was: UUID tid = tid = AsyncCommands. 11438 // was: UUID tid = tid = AsyncCommands.
11645 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, assetID.ToString()); 11439 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, assetID.ToString());
11646 11440
11647 if (NotecardCache.IsCached(assetID)) 11441 if (NotecardCache.IsCached(assetID))
11648 { 11442 {
@@ -11726,7 +11520,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11726 { 11520 {
11727 UUID rq = UUID.Random(); 11521 UUID rq = UUID.Random();
11728 11522
11729 AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 11523 AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
11730 11524
11731 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id))); 11525 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id)));
11732 11526
@@ -11742,7 +11536,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11742 { 11536 {
11743 UUID rq = UUID.Random(); 11537 UUID rq = UUID.Random();
11744 11538
11745 AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 11539 AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
11746 11540
11747 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id)); 11541 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id));
11748 11542
@@ -12236,7 +12030,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12236 bool isAccount = false; 12030 bool isAccount = false;
12237 bool isGroup = false; 12031 bool isGroup = false;
12238 12032
12239 if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManager(m_host.OwnerID)) 12033 if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManagerOrOwner(m_host.OwnerID))
12240 return 0; 12034 return 0;
12241 12035
12242 UUID id = new UUID(); 12036 UUID id = new UUID();
@@ -12298,35 +12092,50 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12298 return 1; 12092 return 1;
12299 } 12093 }
12300 12094
12301 #region Not Implemented 12095 public LSL_Integer llGetMemoryLimit()
12302 // 12096 {
12303 // Listing the unimplemented lsl functions here, please move 12097 m_host.AddScriptLPS(1);
12304 // them from this region as they are completed 12098 // The value returned for LSO scripts in SL
12305 // 12099 return 16384;
12100 }
12306 12101
12307 public void llGetEnv(LSL_String name) 12102 public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
12308 { 12103 {
12309 m_host.AddScriptLPS(1); 12104 m_host.AddScriptLPS(1);
12310 NotImplemented("llGetEnv"); 12105 // Treat as an LSO script
12106 return ScriptBaseClass.FALSE;
12311 } 12107 }
12312 12108
12313 public void llGetSPMaxMemory() 12109 public LSL_Integer llGetSPMaxMemory()
12314 { 12110 {
12315 m_host.AddScriptLPS(1); 12111 m_host.AddScriptLPS(1);
12316 NotImplemented("llGetSPMaxMemory"); 12112 // The value returned for LSO scripts in SL
12113 return 16384;
12317 } 12114 }
12318 12115
12319 public virtual LSL_Integer llGetUsedMemory() 12116 public virtual LSL_Integer llGetUsedMemory()
12320 { 12117 {
12321 m_host.AddScriptLPS(1); 12118 m_host.AddScriptLPS(1);
12322 NotImplemented("llGetUsedMemory"); 12119 // The value returned for LSO scripts in SL
12323 return 0; 12120 return 16384;
12324 } 12121 }
12325 12122
12326 public void llScriptProfiler(LSL_Integer flags) 12123 public void llScriptProfiler(LSL_Integer flags)
12327 { 12124 {
12328 m_host.AddScriptLPS(1); 12125 m_host.AddScriptLPS(1);
12329 //NotImplemented("llScriptProfiler"); 12126 // This does nothing for LSO scripts in SL
12127 }
12128
12129 #region Not Implemented
12130 //
12131 // Listing the unimplemented lsl functions here, please move
12132 // them from this region as they are completed
12133 //
12134
12135 public void llGetEnv(LSL_String name)
12136 {
12137 m_host.AddScriptLPS(1);
12138 NotImplemented("llGetEnv");
12330 } 12139 }
12331 12140
12332 public void llSetSoundQueueing(int queue) 12141 public void llSetSoundQueueing(int queue)
@@ -12406,8 +12215,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12406 12215
12407 try 12216 try
12408 { 12217 {
12409 UUID invItemID=InventorySelf(); 12218 TaskInventoryItem item = m_item;
12410 if (invItemID == UUID.Zero) 12219 if (item == null)
12411 { 12220 {
12412 replydata = "SERVICE_ERROR"; 12221 replydata = "SERVICE_ERROR";
12413 return; 12222 return;
@@ -12415,10 +12224,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12415 12224
12416 m_host.AddScriptLPS(1); 12225 m_host.AddScriptLPS(1);
12417 12226
12418 m_host.TaskInventory.LockItemsForRead(true);
12419 TaskInventoryItem item = m_host.TaskInventory[invItemID];
12420 m_host.TaskInventory.LockItemsForRead(false);
12421
12422 if (item.PermsGranter == UUID.Zero) 12227 if (item.PermsGranter == UUID.Zero)
12423 { 12228 {
12424 replydata = "MISSING_PERMISSION_DEBIT"; 12229 replydata = "MISSING_PERMISSION_DEBIT";
@@ -12460,7 +12265,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12460 } 12265 }
12461 finally 12266 finally
12462 { 12267 {
12463 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 12268 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
12464 "transaction_result", new Object[] { 12269 "transaction_result", new Object[] {
12465 new LSL_String(txn.ToString()), 12270 new LSL_String(txn.ToString()),
12466 new LSL_Integer(replycode), 12271 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;