aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Api
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api')
-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.cs846
-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.cs299
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs25
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs7
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs20
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs35
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs39
12 files changed, 679 insertions, 671 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 a0dc6cd..389980e 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 380
405 m_host.TaskInventory.LockItemsForRead(false); 381 if (item != null && item.Type == type)
406 return UUID.Zero; 382 return item.AssetID;
407 } 383 else
408 384 return UUID.Zero;
409 protected UUID InventoryKey(string name)
410 {
411 m_host.AddScriptLPS(1);
412
413
414 m_host.TaskInventory.LockItemsForRead(true);
415
416 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
417 {
418 if (inv.Value.Name == name)
419 {
420 m_host.TaskInventory.LockItemsForRead(false);
421 return inv.Value.AssetID;
422 }
423 }
424
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
@@ -986,7 +944,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
986 UUID.TryParse(ID, out keyID); 944 UUID.TryParse(ID, out keyID);
987 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 945 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
988 if (wComm != null) 946 if (wComm != null)
989 return wComm.Listen(m_localID, m_itemID, m_host.UUID, channelID, name, keyID, msg); 947 return wComm.Listen(m_host.LocalId, m_item.ItemID, m_host.UUID, channelID, name, keyID, msg);
990 else 948 else
991 return -1; 949 return -1;
992 } 950 }
@@ -996,7 +954,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
996 m_host.AddScriptLPS(1); 954 m_host.AddScriptLPS(1);
997 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 955 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
998 if (wComm != null) 956 if (wComm != null)
999 wComm.ListenControl(m_itemID, number, active); 957 wComm.ListenControl(m_item.ItemID, number, active);
1000 } 958 }
1001 959
1002 public void llListenRemove(int number) 960 public void llListenRemove(int number)
@@ -1004,7 +962,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1004 m_host.AddScriptLPS(1); 962 m_host.AddScriptLPS(1);
1005 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 963 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
1006 if (wComm != null) 964 if (wComm != null)
1007 wComm.ListenRemove(m_itemID, number); 965 wComm.ListenRemove(m_item.ItemID, number);
1008 } 966 }
1009 967
1010 public void llSensor(string name, string id, int type, double range, double arc) 968 public void llSensor(string name, string id, int type, double range, double arc)
@@ -1013,7 +971,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1013 UUID keyID = UUID.Zero; 971 UUID keyID = UUID.Zero;
1014 UUID.TryParse(id, out keyID); 972 UUID.TryParse(id, out keyID);
1015 973
1016 AsyncCommands.SensorRepeatPlugin.SenseOnce(m_localID, m_itemID, name, keyID, type, range, arc, m_host); 974 AsyncCommands.SensorRepeatPlugin.SenseOnce(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, m_host);
1017 } 975 }
1018 976
1019 public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate) 977 public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
@@ -1022,13 +980,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1022 UUID keyID = UUID.Zero; 980 UUID keyID = UUID.Zero;
1023 UUID.TryParse(id, out keyID); 981 UUID.TryParse(id, out keyID);
1024 982
1025 AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_localID, m_itemID, name, keyID, type, range, arc, rate, m_host); 983 AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, rate, m_host);
1026 } 984 }
1027 985
1028 public void llSensorRemove() 986 public void llSensorRemove()
1029 { 987 {
1030 m_host.AddScriptLPS(1); 988 m_host.AddScriptLPS(1);
1031 AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_localID, m_itemID); 989 AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_host.LocalId, m_item.ItemID);
1032 } 990 }
1033 991
1034 public string resolveName(UUID objecUUID) 992 public string resolveName(UUID objecUUID)
@@ -1069,7 +1027,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1069 public LSL_String llDetectedName(int number) 1027 public LSL_String llDetectedName(int number)
1070 { 1028 {
1071 m_host.AddScriptLPS(1); 1029 m_host.AddScriptLPS(1);
1072 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1030 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1073 if (detectedParams == null) 1031 if (detectedParams == null)
1074 return String.Empty; 1032 return String.Empty;
1075 return detectedParams.Name; 1033 return detectedParams.Name;
@@ -1078,7 +1036,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1078 public LSL_String llDetectedKey(int number) 1036 public LSL_String llDetectedKey(int number)
1079 { 1037 {
1080 m_host.AddScriptLPS(1); 1038 m_host.AddScriptLPS(1);
1081 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1039 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1082 if (detectedParams == null) 1040 if (detectedParams == null)
1083 return String.Empty; 1041 return String.Empty;
1084 return detectedParams.Key.ToString(); 1042 return detectedParams.Key.ToString();
@@ -1087,7 +1045,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1087 public LSL_String llDetectedOwner(int number) 1045 public LSL_String llDetectedOwner(int number)
1088 { 1046 {
1089 m_host.AddScriptLPS(1); 1047 m_host.AddScriptLPS(1);
1090 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1048 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1091 if (detectedParams == null) 1049 if (detectedParams == null)
1092 return String.Empty; 1050 return String.Empty;
1093 return detectedParams.Owner.ToString(); 1051 return detectedParams.Owner.ToString();
@@ -1096,7 +1054,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1096 public LSL_Integer llDetectedType(int number) 1054 public LSL_Integer llDetectedType(int number)
1097 { 1055 {
1098 m_host.AddScriptLPS(1); 1056 m_host.AddScriptLPS(1);
1099 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1057 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1100 if (detectedParams == null) 1058 if (detectedParams == null)
1101 return 0; 1059 return 0;
1102 return new LSL_Integer(detectedParams.Type); 1060 return new LSL_Integer(detectedParams.Type);
@@ -1105,7 +1063,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1105 public LSL_Vector llDetectedPos(int number) 1063 public LSL_Vector llDetectedPos(int number)
1106 { 1064 {
1107 m_host.AddScriptLPS(1); 1065 m_host.AddScriptLPS(1);
1108 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1066 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1109 if (detectedParams == null) 1067 if (detectedParams == null)
1110 return new LSL_Vector(); 1068 return new LSL_Vector();
1111 return detectedParams.Position; 1069 return detectedParams.Position;
@@ -1114,7 +1072,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1114 public LSL_Vector llDetectedVel(int number) 1072 public LSL_Vector llDetectedVel(int number)
1115 { 1073 {
1116 m_host.AddScriptLPS(1); 1074 m_host.AddScriptLPS(1);
1117 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1075 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1118 if (detectedParams == null) 1076 if (detectedParams == null)
1119 return new LSL_Vector(); 1077 return new LSL_Vector();
1120 return detectedParams.Velocity; 1078 return detectedParams.Velocity;
@@ -1123,7 +1081,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1123 public LSL_Vector llDetectedGrab(int number) 1081 public LSL_Vector llDetectedGrab(int number)
1124 { 1082 {
1125 m_host.AddScriptLPS(1); 1083 m_host.AddScriptLPS(1);
1126 DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number); 1084 DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1127 if (parms == null) 1085 if (parms == null)
1128 return new LSL_Vector(0, 0, 0); 1086 return new LSL_Vector(0, 0, 0);
1129 1087
@@ -1133,7 +1091,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1133 public LSL_Rotation llDetectedRot(int number) 1091 public LSL_Rotation llDetectedRot(int number)
1134 { 1092 {
1135 m_host.AddScriptLPS(1); 1093 m_host.AddScriptLPS(1);
1136 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1094 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1137 if (detectedParams == null) 1095 if (detectedParams == null)
1138 return new LSL_Rotation(); 1096 return new LSL_Rotation();
1139 return detectedParams.Rotation; 1097 return detectedParams.Rotation;
@@ -1142,7 +1100,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1142 public LSL_Integer llDetectedGroup(int number) 1100 public LSL_Integer llDetectedGroup(int number)
1143 { 1101 {
1144 m_host.AddScriptLPS(1); 1102 m_host.AddScriptLPS(1);
1145 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1103 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1146 if (detectedParams == null) 1104 if (detectedParams == null)
1147 return new LSL_Integer(0); 1105 return new LSL_Integer(0);
1148 if (m_host.GroupID == detectedParams.Group) 1106 if (m_host.GroupID == detectedParams.Group)
@@ -1153,7 +1111,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1153 public LSL_Integer llDetectedLinkNumber(int number) 1111 public LSL_Integer llDetectedLinkNumber(int number)
1154 { 1112 {
1155 m_host.AddScriptLPS(1); 1113 m_host.AddScriptLPS(1);
1156 DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number); 1114 DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1157 if (parms == null) 1115 if (parms == null)
1158 return new LSL_Integer(0); 1116 return new LSL_Integer(0);
1159 1117
@@ -1166,7 +1124,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1166 public LSL_Vector llDetectedTouchBinormal(int index) 1124 public LSL_Vector llDetectedTouchBinormal(int index)
1167 { 1125 {
1168 m_host.AddScriptLPS(1); 1126 m_host.AddScriptLPS(1);
1169 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1127 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1170 if (detectedParams == null) 1128 if (detectedParams == null)
1171 return new LSL_Vector(); 1129 return new LSL_Vector();
1172 return detectedParams.TouchBinormal; 1130 return detectedParams.TouchBinormal;
@@ -1178,7 +1136,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1178 public LSL_Integer llDetectedTouchFace(int index) 1136 public LSL_Integer llDetectedTouchFace(int index)
1179 { 1137 {
1180 m_host.AddScriptLPS(1); 1138 m_host.AddScriptLPS(1);
1181 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1139 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1182 if (detectedParams == null) 1140 if (detectedParams == null)
1183 return new LSL_Integer(-1); 1141 return new LSL_Integer(-1);
1184 return new LSL_Integer(detectedParams.TouchFace); 1142 return new LSL_Integer(detectedParams.TouchFace);
@@ -1190,7 +1148,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1190 public LSL_Vector llDetectedTouchNormal(int index) 1148 public LSL_Vector llDetectedTouchNormal(int index)
1191 { 1149 {
1192 m_host.AddScriptLPS(1); 1150 m_host.AddScriptLPS(1);
1193 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1151 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1194 if (detectedParams == null) 1152 if (detectedParams == null)
1195 return new LSL_Vector(); 1153 return new LSL_Vector();
1196 return detectedParams.TouchNormal; 1154 return detectedParams.TouchNormal;
@@ -1202,7 +1160,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1202 public LSL_Vector llDetectedTouchPos(int index) 1160 public LSL_Vector llDetectedTouchPos(int index)
1203 { 1161 {
1204 m_host.AddScriptLPS(1); 1162 m_host.AddScriptLPS(1);
1205 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1163 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1206 if (detectedParams == null) 1164 if (detectedParams == null)
1207 return new LSL_Vector(); 1165 return new LSL_Vector();
1208 return detectedParams.TouchPos; 1166 return detectedParams.TouchPos;
@@ -1214,7 +1172,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1214 public LSL_Vector llDetectedTouchST(int index) 1172 public LSL_Vector llDetectedTouchST(int index)
1215 { 1173 {
1216 m_host.AddScriptLPS(1); 1174 m_host.AddScriptLPS(1);
1217 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1175 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1218 if (detectedParams == null) 1176 if (detectedParams == null)
1219 return new LSL_Vector(-1.0, -1.0, 0.0); 1177 return new LSL_Vector(-1.0, -1.0, 0.0);
1220 return detectedParams.TouchST; 1178 return detectedParams.TouchST;
@@ -1226,7 +1184,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1226 public LSL_Vector llDetectedTouchUV(int index) 1184 public LSL_Vector llDetectedTouchUV(int index)
1227 { 1185 {
1228 m_host.AddScriptLPS(1); 1186 m_host.AddScriptLPS(1);
1229 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1187 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1230 if (detectedParams == null) 1188 if (detectedParams == null)
1231 return new LSL_Vector(-1.0, -1.0, 0.0); 1189 return new LSL_Vector(-1.0, -1.0, 0.0);
1232 return detectedParams.TouchUV; 1190 return detectedParams.TouchUV;
@@ -1929,12 +1887,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1929 1887
1930 return rgb; 1888 return rgb;
1931 } 1889 }
1890
1932 if (face >= 0 && face < GetNumberOfSides(part)) 1891 if (face >= 0 && face < GetNumberOfSides(part))
1933 { 1892 {
1934 texcolor = tex.GetFace((uint)face).RGBA; 1893 texcolor = tex.GetFace((uint)face).RGBA;
1935 rgb.x = texcolor.R; 1894 rgb.x = texcolor.R;
1936 rgb.y = texcolor.G; 1895 rgb.y = texcolor.G;
1937 rgb.z = texcolor.B; 1896 rgb.z = texcolor.B;
1897
1938 return rgb; 1898 return rgb;
1939 } 1899 }
1940 else 1900 else
@@ -2975,20 +2935,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2975 2935
2976 public LSL_Integer llGiveMoney(string destination, int amount) 2936 public LSL_Integer llGiveMoney(string destination, int amount)
2977 { 2937 {
2978 UUID invItemID=InventorySelf();
2979 if (invItemID == UUID.Zero)
2980 return 0;
2981
2982 m_host.AddScriptLPS(1); 2938 m_host.AddScriptLPS(1);
2983 2939
2984 m_host.TaskInventory.LockItemsForRead(true); 2940 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; 2941 return 0;
2990 2942
2991 if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0) 2943 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
2992 { 2944 {
2993 LSLError("No permissions to give money"); 2945 LSLError("No permissions to give money");
2994 return 0; 2946 return 0;
@@ -3176,11 +3128,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3176 sec = m_MinTimerInterval; 3128 sec = m_MinTimerInterval;
3177 m_host.AddScriptLPS(1); 3129 m_host.AddScriptLPS(1);
3178 // Setting timer repeat 3130 // Setting timer repeat
3179 AsyncCommands.TimerPlugin.SetTimerEvent(m_localID, m_itemID, sec); 3131 AsyncCommands.TimerPlugin.SetTimerEvent(m_host.LocalId, m_item.ItemID, sec);
3180 } 3132 }
3181 3133
3182 public virtual void llSleep(double sec) 3134 public virtual void llSleep(double sec)
3183 { 3135 {
3136// m_log.Info("llSleep snoozing " + sec + "s.");
3184 m_host.AddScriptLPS(1); 3137 m_host.AddScriptLPS(1);
3185 Thread.Sleep((int)(sec * 1000)); 3138 Thread.Sleep((int)(sec * 1000));
3186 } 3139 }
@@ -3239,29 +3192,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3239 3192
3240 public void llTakeControls(int controls, int accept, int pass_on) 3193 public void llTakeControls(int controls, int accept, int pass_on)
3241 { 3194 {
3242 TaskInventoryItem item; 3195 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 {
3252 item = m_host.TaskInventory[InventorySelf()];
3253 }
3254 m_host.TaskInventory.LockItemsForRead(false);
3255
3256 if (item.PermsGranter != UUID.Zero)
3257 { 3196 {
3258 ScenePresence presence = World.GetScenePresence(item.PermsGranter); 3197 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3259 3198
3260 if (presence != null) 3199 if (presence != null)
3261 { 3200 {
3262 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 3201 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
3263 { 3202 {
3264 presence.RegisterControlEventsToScript(controls, accept, pass_on, m_localID, m_itemID); 3203 presence.RegisterControlEventsToScript(controls, accept, pass_on, m_host.LocalId, m_item.ItemID);
3265 } 3204 }
3266 } 3205 }
3267 } 3206 }
@@ -3271,38 +3210,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3271 3210
3272 public void llReleaseControls() 3211 public void llReleaseControls()
3273 { 3212 {
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); 3213 m_host.AddScriptLPS(1);
3293 3214
3294 if (item.PermsGranter != UUID.Zero) 3215 if (m_item.PermsGranter != UUID.Zero)
3295 { 3216 {
3296 ScenePresence presence = World.GetScenePresence(item.PermsGranter); 3217 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3297 3218
3298 if (presence != null) 3219 if (presence != null)
3299 { 3220 {
3300 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 3221 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
3301 { 3222 {
3302 // Unregister controls from Presence 3223 // Unregister controls from Presence
3303 presence.UnRegisterControlEventsToScript(m_localID, m_itemID); 3224 presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
3304 // Remove Take Control permission. 3225 // Remove Take Control permission.
3305 item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS; 3226 m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
3306 } 3227 }
3307 } 3228 }
3308 } 3229 }
@@ -3315,86 +3236,71 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3315 m_UrlModule.ReleaseURL(url); 3236 m_UrlModule.ReleaseURL(url);
3316 } 3237 }
3317 3238
3318 public void llAttachToAvatar(int attachment) 3239 /// <summary>
3240 /// Attach the object containing this script to the avatar that owns it.
3241 /// </summary>
3242 /// <param name='attachment'>The attachment point (e.g. ATTACH_CHEST)</param>
3243 /// <returns>true if the attach suceeded, false if it did not</returns>
3244 public bool AttachToAvatar(int attachmentPoint)
3319 { 3245 {
3320 m_host.AddScriptLPS(1); 3246 SceneObjectGroup grp = m_host.ParentGroup;
3321 3247 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
3322 TaskInventoryItem item;
3323 3248
3324 m_host.TaskInventory.LockItemsForRead(true); 3249 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3325 3250
3326 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3251 if (attachmentsModule != null)
3327 { 3252 return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true);
3328 m_host.TaskInventory.LockItemsForRead(false);
3329 return;
3330 }
3331 else 3253 else
3332 { 3254 return false;
3333 item = m_host.TaskInventory[InventorySelf()]; 3255 }
3334 }
3335
3336 m_host.TaskInventory.LockItemsForRead(false);
3337 3256
3338 if (item.PermsGranter != m_host.OwnerID) 3257 /// <summary>
3339 return; 3258 /// Detach the object containing this script from the avatar it is attached to.
3259 /// </summary>
3260 /// <remarks>
3261 /// Nothing happens if the object is not attached.
3262 /// </remarks>
3263 public void DetachFromAvatar()
3264 {
3265 Util.FireAndForget(DetachWrapper, m_host);
3266 }
3340 3267
3341 if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0) 3268 private void DetachWrapper(object o)
3342 { 3269 {
3343 SceneObjectGroup grp = m_host.ParentGroup; 3270 SceneObjectPart host = (SceneObjectPart)o;
3344 3271
3345 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 3272 SceneObjectGroup grp = host.ParentGroup;
3273 UUID itemID = grp.FromItemID;
3274 ScenePresence presence = World.GetScenePresence(host.OwnerID);
3346 3275
3347 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; 3276 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3348 if (attachmentsModule != null) 3277 if (attachmentsModule != null)
3349 attachmentsModule.AttachObject(presence, grp, (uint)attachment, false, true); 3278 attachmentsModule.DetachSingleAttachmentToInv(presence, itemID);
3350 }
3351 } 3279 }
3352 3280
3353 public void llDetachFromAvatar() 3281 public void llAttachToAvatar(int attachmentPoint)
3354 { 3282 {
3355 m_host.AddScriptLPS(1); 3283 m_host.AddScriptLPS(1);
3356 3284
3357 if (m_host.ParentGroup.AttachmentPoint == 0) 3285 if (m_item.PermsGranter != m_host.OwnerID)
3358 return; 3286 return;
3359 3287
3360 TaskInventoryItem item; 3288 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
3289 AttachToAvatar(attachmentPoint);
3290 }
3361 3291
3362 m_host.TaskInventory.LockItemsForRead(true); 3292 public void llDetachFromAvatar()
3293 {
3294 m_host.AddScriptLPS(1);
3363 3295
3364 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3296 if (m_host.ParentGroup.AttachmentPoint == 0)
3365 {
3366 m_host.TaskInventory.LockItemsForRead(false);
3367 return; 3297 return;
3368 }
3369 else
3370 {
3371 item = m_host.TaskInventory[InventorySelf()];
3372 }
3373 m_host.TaskInventory.LockItemsForRead(false);
3374
3375 3298
3376 if (item.PermsGranter != m_host.OwnerID) 3299 if (m_item.PermsGranter != m_host.OwnerID)
3377 return; 3300 return;
3378 3301
3379 if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0) 3302 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
3380 { 3303 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 } 3304 }
3399 3305
3400 public void llTakeCamera(string avatar) 3306 public void llTakeCamera(string avatar)
@@ -3515,7 +3421,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3515 } 3421 }
3516 3422
3517 emailModule.SendEmail(m_host.UUID, address, subject, message); 3423 emailModule.SendEmail(m_host.UUID, address, subject, message);
3518 ScriptSleep(15000); 3424 ScriptSleep(EMAIL_PAUSE_TIME * 1000);
3519 } 3425 }
3520 3426
3521 public void llGetNextEmail(string address, string subject) 3427 public void llGetNextEmail(string address, string subject)
@@ -3552,6 +3458,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3552 return m_host.UUID.ToString(); 3458 return m_host.UUID.ToString();
3553 } 3459 }
3554 3460
3461 public LSL_Key llGenerateKey()
3462 {
3463 m_host.AddScriptLPS(1);
3464 return UUID.Random().ToString();
3465 }
3466
3555 public void llSetBuoyancy(double buoyancy) 3467 public void llSetBuoyancy(double buoyancy)
3556 { 3468 {
3557 m_host.AddScriptLPS(1); 3469 m_host.AddScriptLPS(1);
@@ -3598,7 +3510,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3598 m_host.AddScriptLPS(1); 3510 m_host.AddScriptLPS(1);
3599 try 3511 try
3600 { 3512 {
3601 m_ScriptEngine.SetMinEventDelay(m_itemID, delay); 3513 m_ScriptEngine.SetMinEventDelay(m_item.ItemID, delay);
3602 } 3514 }
3603 catch (NotImplementedException) 3515 catch (NotImplementedException)
3604 { 3516 {
@@ -3651,29 +3563,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3651 { 3563 {
3652 m_host.AddScriptLPS(1); 3564 m_host.AddScriptLPS(1);
3653 3565
3654 UUID invItemID = InventorySelf(); 3566 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; 3567 return;
3673 3568
3674 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0) 3569 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3675 { 3570 {
3676 ScenePresence presence = World.GetScenePresence(item.PermsGranter); 3571 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3677 3572
3678 if (presence != null) 3573 if (presence != null)
3679 { 3574 {
@@ -3691,41 +3586,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3691 { 3586 {
3692 m_host.AddScriptLPS(1); 3587 m_host.AddScriptLPS(1);
3693 3588
3694 UUID invItemID=InventorySelf(); 3589 if (m_item.PermsGranter == UUID.Zero)
3695 if (invItemID == UUID.Zero)
3696 return;
3697
3698 TaskInventoryItem item;
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 {
3708 item = m_host.TaskInventory[InventorySelf()];
3709 }
3710 m_host.TaskInventory.LockItemsForRead(false);
3711
3712
3713 if (item.PermsGranter == UUID.Zero)
3714 return; 3590 return;
3715 3591
3716 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0) 3592 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3717 { 3593 {
3718 UUID animID = new UUID(); 3594 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3719
3720 if (!UUID.TryParse(anim, out animID))
3721 {
3722 animID=InventoryKey(anim);
3723 }
3724
3725 ScenePresence presence = World.GetScenePresence(item.PermsGranter);
3726 3595
3727 if (presence != null) 3596 if (presence != null)
3728 { 3597 {
3598 UUID animID = KeyOrName(anim);
3599
3729 if (animID == UUID.Zero) 3600 if (animID == UUID.Zero)
3730 presence.Animator.RemoveAnimation(anim); 3601 presence.Animator.RemoveAnimation(anim);
3731 else 3602 else
@@ -3758,44 +3629,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3758 public LSL_Integer llGetStartParameter() 3629 public LSL_Integer llGetStartParameter()
3759 { 3630 {
3760 m_host.AddScriptLPS(1); 3631 m_host.AddScriptLPS(1);
3761 return m_ScriptEngine.GetStartParameter(m_itemID); 3632 return m_ScriptEngine.GetStartParameter(m_item.ItemID);
3762 } 3633 }
3763 3634
3764 public void llRequestPermissions(string agent, int perm) 3635 public void llRequestPermissions(string agent, int perm)
3765 { 3636 {
3766 UUID agentID = new UUID(); 3637 UUID agentID;
3767 3638
3768 if (!UUID.TryParse(agent, out agentID)) 3639 if (!UUID.TryParse(agent, out agentID))
3769 return; 3640 return;
3770 3641
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 3642 if (agentID == UUID.Zero || perm == 0) // Releasing permissions
3792 { 3643 {
3793 llReleaseControls(); 3644 llReleaseControls();
3794 3645
3795 item.PermsGranter = UUID.Zero; 3646 m_item.PermsGranter = UUID.Zero;
3796 item.PermsMask = 0; 3647 m_item.PermsMask = 0;
3797 3648
3798 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3649 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3799 "run_time_permissions", new Object[] { 3650 "run_time_permissions", new Object[] {
3800 new LSL_Integer(0) }, 3651 new LSL_Integer(0) },
3801 new DetectParams[0])); 3652 new DetectParams[0]));
@@ -3803,7 +3654,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3803 return; 3654 return;
3804 } 3655 }
3805 3656
3806 if (item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3657 if (m_item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3807 llReleaseControls(); 3658 llReleaseControls();
3808 3659
3809 m_host.AddScriptLPS(1); 3660 m_host.AddScriptLPS(1);
@@ -3820,11 +3671,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3820 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3671 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3821 { 3672 {
3822 m_host.TaskInventory.LockItemsForWrite(true); 3673 m_host.TaskInventory.LockItemsForWrite(true);
3823 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3674 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3824 m_host.TaskInventory[invItemID].PermsMask = perm; 3675 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3825 m_host.TaskInventory.LockItemsForWrite(false); 3676 m_host.TaskInventory.LockItemsForWrite(false);
3826 3677
3827 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3678 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3828 "run_time_permissions", new Object[] { 3679 "run_time_permissions", new Object[] {
3829 new LSL_Integer(perm) }, 3680 new LSL_Integer(perm) },
3830 new DetectParams[0])); 3681 new DetectParams[0]));
@@ -3859,11 +3710,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3859 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3710 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3860 { 3711 {
3861 m_host.TaskInventory.LockItemsForWrite(true); 3712 m_host.TaskInventory.LockItemsForWrite(true);
3862 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3713 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3863 m_host.TaskInventory[invItemID].PermsMask = perm; 3714 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3864 m_host.TaskInventory.LockItemsForWrite(false); 3715 m_host.TaskInventory.LockItemsForWrite(false);
3865 3716
3866 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3717 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3867 "run_time_permissions", new Object[] { 3718 "run_time_permissions", new Object[] {
3868 new LSL_Integer(perm) }, 3719 new LSL_Integer(perm) },
3869 new DetectParams[0])); 3720 new DetectParams[0]));
@@ -3874,9 +3725,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3874 } 3725 }
3875 3726
3876 ScenePresence presence = World.GetScenePresence(agentID); 3727 ScenePresence presence = World.GetScenePresence(agentID);
3877
3878 if (presence != null) 3728 if (presence != null)
3879 { 3729 {
3730 // If permissions are being requested from an NPC and were not implicitly granted above then
3731 // auto grant all reuqested permissions if the script is owned by the NPC or the NPCs owner
3732 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
3733 if (npcModule != null && npcModule.IsNPC(agentID, World))
3734 {
3735 if (agentID == m_host.ParentGroup.OwnerID || npcModule.GetOwner(agentID) == m_host.ParentGroup.OwnerID)
3736 {
3737 lock (m_host.TaskInventory)
3738 {
3739 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3740 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3741 }
3742
3743 m_ScriptEngine.PostScriptEvent(
3744 m_item.ItemID,
3745 new EventParams(
3746 "run_time_permissions", new Object[] { new LSL_Integer(perm) }, new DetectParams[0]));
3747 }
3748
3749 // it is an NPC, exit even if the permissions werent granted above, they are not going to answer
3750 // the question!
3751 return;
3752 }
3753
3880 string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID); 3754 string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
3881 if (ownerName == String.Empty) 3755 if (ownerName == String.Empty)
3882 ownerName = "(hippos)"; 3756 ownerName = "(hippos)";
@@ -3884,8 +3758,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3884 if (!m_waitingForScriptAnswer) 3758 if (!m_waitingForScriptAnswer)
3885 { 3759 {
3886 m_host.TaskInventory.LockItemsForWrite(true); 3760 m_host.TaskInventory.LockItemsForWrite(true);
3887 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3761 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3888 m_host.TaskInventory[invItemID].PermsMask = 0; 3762 m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
3889 m_host.TaskInventory.LockItemsForWrite(false); 3763 m_host.TaskInventory.LockItemsForWrite(false);
3890 3764
3891 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 3765 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
@@ -3893,16 +3767,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3893 } 3767 }
3894 3768
3895 presence.ControllingClient.SendScriptQuestion( 3769 presence.ControllingClient.SendScriptQuestion(
3896 m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, invItemID, perm); 3770 m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_item.ItemID, perm);
3897 3771
3898 return; 3772 return;
3899 } 3773 }
3900 3774
3901 // Requested agent is not in range, refuse perms 3775 // Requested agent is not in range, refuse perms
3902 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3776 m_ScriptEngine.PostScriptEvent(
3903 "run_time_permissions", new Object[] { 3777 m_item.ItemID,
3904 new LSL_Integer(0) }, 3778 new EventParams("run_time_permissions", new Object[] { new LSL_Integer(0) }, new DetectParams[0]));
3905 new DetectParams[0]));
3906 } 3779 }
3907 3780
3908 void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer) 3781 void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
@@ -3910,24 +3783,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3910 if (taskID != m_host.UUID) 3783 if (taskID != m_host.UUID)
3911 return; 3784 return;
3912 3785
3913 UUID invItemID = InventorySelf(); 3786 client.OnScriptAnswer -= handleScriptAnswer;
3914 3787 m_waitingForScriptAnswer = false;
3915 if (invItemID == UUID.Zero)
3916 return;
3917
3918 client.OnScriptAnswer-=handleScriptAnswer;
3919 m_waitingForScriptAnswer=false;
3920 3788
3921 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3789 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3922 llReleaseControls(); 3790 llReleaseControls();
3923 3791
3924
3925 m_host.TaskInventory.LockItemsForWrite(true); 3792 m_host.TaskInventory.LockItemsForWrite(true);
3926 m_host.TaskInventory[invItemID].PermsMask = answer; 3793 m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
3927 m_host.TaskInventory.LockItemsForWrite(false); 3794 m_host.TaskInventory.LockItemsForWrite(false);
3928 3795
3929 3796 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3930 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3931 "run_time_permissions", new Object[] { 3797 "run_time_permissions", new Object[] {
3932 new LSL_Integer(answer) }, 3798 new LSL_Integer(answer) },
3933 new DetectParams[0])); 3799 new DetectParams[0]));
@@ -3937,41 +3803,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3937 { 3803 {
3938 m_host.AddScriptLPS(1); 3804 m_host.AddScriptLPS(1);
3939 3805
3940 m_host.TaskInventory.LockItemsForRead(true); 3806 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 } 3807 }
3954 3808
3955 public LSL_Integer llGetPermissions() 3809 public LSL_Integer llGetPermissions()
3956 { 3810 {
3957 m_host.AddScriptLPS(1); 3811 m_host.AddScriptLPS(1);
3958 3812
3959 m_host.TaskInventory.LockItemsForRead(true); 3813 int perms = m_item.PermsMask;
3960 3814
3961 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3815 if (m_automaticLinkPermission)
3962 { 3816 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 3817
3974 return 0; 3818 return perms;
3975 } 3819 }
3976 3820
3977 public LSL_Integer llGetLinkNumber() 3821 public LSL_Integer llGetLinkNumber()
@@ -4009,18 +3853,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4009 public void llCreateLink(string target, int parent) 3853 public void llCreateLink(string target, int parent)
4010 { 3854 {
4011 m_host.AddScriptLPS(1); 3855 m_host.AddScriptLPS(1);
4012 UUID invItemID = InventorySelf(); 3856
4013 UUID targetID; 3857 UUID targetID;
4014 3858
4015 if (!UUID.TryParse(target, out targetID)) 3859 if (!UUID.TryParse(target, out targetID))
4016 return; 3860 return;
4017 3861
4018 TaskInventoryItem item; 3862 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) 3863 && !m_automaticLinkPermission)
4025 { 3864 {
4026 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3865 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
@@ -4028,7 +3867,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4028 } 3867 }
4029 3868
4030 IClientAPI client = null; 3869 IClientAPI client = null;
4031 ScenePresence sp = World.GetScenePresence(item.PermsGranter); 3870 ScenePresence sp = World.GetScenePresence(m_item.PermsGranter);
4032 if (sp != null) 3871 if (sp != null)
4033 client = sp.ControllingClient; 3872 client = sp.ControllingClient;
4034 3873
@@ -4074,18 +3913,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4074 public void llBreakLink(int linknum) 3913 public void llBreakLink(int linknum)
4075 { 3914 {
4076 m_host.AddScriptLPS(1); 3915 m_host.AddScriptLPS(1);
4077 UUID invItemID = InventorySelf();
4078 3916
4079 m_host.TaskInventory.LockItemsForRead(true); 3917 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4080 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3918 && !m_automaticLinkPermission)
4081 && !m_automaticLinkPermission) 3919 {
4082 { 3920 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!"); 3921 return;
4084 m_host.TaskInventory.LockItemsForRead(false); 3922 }
4085 return; 3923
4086 }
4087 m_host.TaskInventory.LockItemsForRead(false);
4088
4089 if (linknum < ScriptBaseClass.LINK_THIS) 3924 if (linknum < ScriptBaseClass.LINK_THIS)
4090 return; 3925 return;
4091 3926
@@ -4184,12 +4019,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4184 { 4019 {
4185 m_host.AddScriptLPS(1); 4020 m_host.AddScriptLPS(1);
4186 4021
4187 UUID invItemID = InventorySelf(); 4022 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 4023
4194 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 4024 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4195 && !m_automaticLinkPermission) 4025 && !m_automaticLinkPermission)
@@ -4500,7 +4330,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4500 { 4330 {
4501 if (item.Name == name) 4331 if (item.Name == name)
4502 { 4332 {
4503 if (item.ItemID == m_itemID) 4333 if (item.ItemID == m_item.ItemID)
4504 throw new ScriptDeleteException(); 4334 throw new ScriptDeleteException();
4505 else 4335 else
4506 m_host.Inventory.RemoveInventoryItem(item.ItemID); 4336 m_host.Inventory.RemoveInventoryItem(item.ItemID);
@@ -4634,8 +4464,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4634 UUID rq = UUID.Random(); 4464 UUID rq = UUID.Random();
4635 4465
4636 UUID tid = AsyncCommands. 4466 UUID tid = AsyncCommands.
4637 DataserverPlugin.RegisterRequest(m_localID, 4467 DataserverPlugin.RegisterRequest(m_host.LocalId,
4638 m_itemID, rq.ToString()); 4468 m_item.ItemID, rq.ToString());
4639 4469
4640 AsyncCommands. 4470 AsyncCommands.
4641 DataserverPlugin.DataserverReply(rq.ToString(), reply); 4471 DataserverPlugin.DataserverReply(rq.ToString(), reply);
@@ -4662,8 +4492,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4662 if (item.Type == 3 && item.Name == name) 4492 if (item.Type == 3 && item.Name == name)
4663 { 4493 {
4664 UUID tid = AsyncCommands. 4494 UUID tid = AsyncCommands.
4665 DataserverPlugin.RegisterRequest(m_localID, 4495 DataserverPlugin.RegisterRequest(m_host.LocalId,
4666 m_itemID, item.AssetID.ToString()); 4496 m_item.ItemID, item.AssetID.ToString());
4667 4497
4668 Vector3 region = new Vector3( 4498 Vector3 region = new Vector3(
4669 World.RegionInfo.RegionLocX * Constants.RegionSize, 4499 World.RegionInfo.RegionLocX * Constants.RegionSize,
@@ -5136,22 +4966,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5136 4966
5137 public LSL_String llGetScriptName() 4967 public LSL_String llGetScriptName()
5138 { 4968 {
5139 string result = String.Empty;
5140
5141 m_host.AddScriptLPS(1); 4969 m_host.AddScriptLPS(1);
5142 4970
5143 m_host.TaskInventory.LockItemsForRead(true); 4971 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 } 4972 }
5156 4973
5157 public LSL_Integer llGetLinkNumberOfSides(int link) 4974 public LSL_Integer llGetLinkNumberOfSides(int link)
@@ -6285,7 +6102,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6285 } 6102 }
6286 } 6103 }
6287 } 6104 }
6288 List<UUID> presenceIds = new List<UUID>();
6289 6105
6290 World.ForEachRootScenePresence( 6106 World.ForEachRootScenePresence(
6291 delegate (ScenePresence ssp) 6107 delegate (ScenePresence ssp)
@@ -6436,7 +6252,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6436 if (m_host.OwnerID == land.LandData.OwnerID) 6252 if (m_host.OwnerID == land.LandData.OwnerID)
6437 { 6253 {
6438 Vector3 pos = World.GetNearestAllowedPosition(presence, land); 6254 Vector3 pos = World.GetNearestAllowedPosition(presence, land);
6439 presence.TeleportWithMomentum(pos); 6255 presence.TeleportWithMomentum(pos, null);
6440 presence.ControllingClient.SendAlertMessage("You have been ejected from this land"); 6256 presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
6441 } 6257 }
6442 } 6258 }
@@ -7383,14 +7199,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7383 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); 7199 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
7384 if (xmlrpcMod.IsEnabled()) 7200 if (xmlrpcMod.IsEnabled())
7385 { 7201 {
7386 UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_localID, m_itemID, UUID.Zero); 7202 UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero);
7387 IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>(); 7203 IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
7388 if (xmlRpcRouter != null) 7204 if (xmlRpcRouter != null)
7389 { 7205 {
7390 string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName; 7206 string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
7391 7207
7392 xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID, 7208 xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
7393 m_itemID, String.Format("http://{0}:{1}/", ExternalHostName, 7209 m_item.ItemID, String.Format("http://{0}:{1}/", ExternalHostName,
7394 xmlrpcMod.Port.ToString())); 7210 xmlrpcMod.Port.ToString()));
7395 } 7211 }
7396 object[] resobj = new object[] 7212 object[] resobj = new object[]
@@ -7402,7 +7218,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7402 new LSL_Integer(0), 7218 new LSL_Integer(0),
7403 new LSL_String(String.Empty) 7219 new LSL_String(String.Empty)
7404 }; 7220 };
7405 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams("remote_data", resobj, 7221 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj,
7406 new DetectParams[0])); 7222 new DetectParams[0]));
7407 } 7223 }
7408 ScriptSleep(1000); 7224 ScriptSleep(1000);
@@ -7413,7 +7229,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7413 m_host.AddScriptLPS(1); 7229 m_host.AddScriptLPS(1);
7414 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); 7230 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
7415 ScriptSleep(3000); 7231 ScriptSleep(3000);
7416 return (xmlrpcMod.SendRemoteData(m_localID, m_itemID, channel, dest, idata, sdata)).ToString(); 7232 return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString();
7417 } 7233 }
7418 7234
7419 public void llRemoteDataReply(string channel, string message_id, string sdata, int idata) 7235 public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
@@ -8413,7 +8229,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8413 return; 8229 return;
8414 face = (int)rules.GetLSLIntegerItem(idx++); 8230 face = (int)rules.GetLSLIntegerItem(idx++);
8415 int shiny = (int)rules.GetLSLIntegerItem(idx++); 8231 int shiny = (int)rules.GetLSLIntegerItem(idx++);
8416 Bumpiness bump = (Bumpiness)Convert.ToByte((int)rules.GetLSLIntegerItem(idx++)); 8232 Bumpiness bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);
8417 8233
8418 SetShiny(part, face, shiny, bump); 8234 SetShiny(part, face, shiny, bump);
8419 8235
@@ -10173,7 +9989,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10173 public LSL_String llGetSimulatorHostname() 9989 public LSL_String llGetSimulatorHostname()
10174 { 9990 {
10175 m_host.AddScriptLPS(1); 9991 m_host.AddScriptLPS(1);
10176 return System.Environment.MachineName; 9992 IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
9993 return UrlModule.ExternalHostNameForLSL;
10177 } 9994 }
10178 9995
10179 // <summary> 9996 // <summary>
@@ -10512,13 +10329,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10512 { 10329 {
10513 m_host.AddScriptLPS(1); 10330 m_host.AddScriptLPS(1);
10514 if (m_UrlModule != null) 10331 if (m_UrlModule != null)
10515 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString(); 10332 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
10516 return UUID.Zero.ToString(); 10333 return UUID.Zero.ToString();
10517 } 10334 }
10518 10335
10519 public LSL_String llRequestSimulatorData(string simulator, int data) 10336 public LSL_String llRequestSimulatorData(string simulator, int data)
10520 { 10337 {
10521 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_itemID, "OSSL"); 10338 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
10522 10339
10523 try 10340 try
10524 { 10341 {
@@ -10528,7 +10345,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10528 10345
10529 GridRegion info; 10346 GridRegion info;
10530 10347
10531 if (m_ScriptEngine.World.RegionInfo.RegionName == simulator) 10348 if (m_ScriptEngine.World.RegionInfo.RegionName == simulator) //Det data for this simulator?
10349
10532 info = new GridRegion(m_ScriptEngine.World.RegionInfo); 10350 info = new GridRegion(m_ScriptEngine.World.RegionInfo);
10533 else 10351 else
10534 info = m_ScriptEngine.World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator); 10352 info = m_ScriptEngine.World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator);
@@ -10541,10 +10359,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10541 ScriptSleep(1000); 10359 ScriptSleep(1000);
10542 return UUID.Zero.ToString(); 10360 return UUID.Zero.ToString();
10543 } 10361 }
10544 reply = new LSL_Vector( 10362 if (m_ScriptEngine.World.RegionInfo.RegionName != simulator)
10545 info.RegionLocX, 10363 {
10546 info.RegionLocY, 10364 //Hypergrid Region co-ordinates
10547 0).ToString(); 10365 uint rx = 0, ry = 0;
10366 Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out rx, out ry);
10367
10368 reply = new LSL_Vector(
10369 rx,
10370 ry,
10371 0).ToString();
10372 }
10373 else
10374 {
10375 //Local-cooridnates
10376 reply = new LSL_Vector(
10377 info.RegionLocX,
10378 info.RegionLocY,
10379 0).ToString();
10380 }
10548 break; 10381 break;
10549 case ScriptBaseClass.DATA_SIM_STATUS: 10382 case ScriptBaseClass.DATA_SIM_STATUS:
10550 if (info != null) 10383 if (info != null)
@@ -10580,7 +10413,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10580 UUID rq = UUID.Random(); 10413 UUID rq = UUID.Random();
10581 10414
10582 UUID tid = AsyncCommands. 10415 UUID tid = AsyncCommands.
10583 DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 10416 DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
10584 10417
10585 AsyncCommands. 10418 AsyncCommands.
10586 DataserverPlugin.DataserverReply(rq.ToString(), reply); 10419 DataserverPlugin.DataserverReply(rq.ToString(), reply);
@@ -10599,7 +10432,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10599 m_host.AddScriptLPS(1); 10432 m_host.AddScriptLPS(1);
10600 10433
10601 if (m_UrlModule != null) 10434 if (m_UrlModule != null)
10602 return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString(); 10435 return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
10603 return UUID.Zero.ToString(); 10436 return UUID.Zero.ToString();
10604 } 10437 }
10605 10438
@@ -10635,7 +10468,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10635 // child agents have a mass of 1.0 10468 // child agents have a mass of 1.0
10636 return 1; 10469 return 1;
10637 else 10470 else
10638 return avatar.GetMass(); 10471 return (double)avatar.GetMass();
10639 } 10472 }
10640 catch (KeyNotFoundException) 10473 catch (KeyNotFoundException)
10641 { 10474 {
@@ -11078,32 +10911,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11078 public LSL_Vector llGetCameraPos() 10911 public LSL_Vector llGetCameraPos()
11079 { 10912 {
11080 m_host.AddScriptLPS(1); 10913 m_host.AddScriptLPS(1);
11081 UUID invItemID = InventorySelf();
11082 10914
11083 if (invItemID == UUID.Zero) 10915 if (m_item.PermsGranter == UUID.Zero)
11084 return new LSL_Vector(); 10916 return new LSL_Vector();
11085 10917
11086 m_host.TaskInventory.LockItemsForRead(true); 10918 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
11087
11088 UUID agentID = m_host.TaskInventory[invItemID].PermsGranter;
11089
11090// if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
11091 if (agentID == UUID.Zero)
11092 {
11093 m_host.TaskInventory.LockItemsForRead(false);
11094 return new LSL_Vector();
11095 }
11096
11097 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
11098 { 10919 {
11099 ShoutError("No permissions to track the camera"); 10920 ShoutError("No permissions to track the camera");
11100 m_host.TaskInventory.LockItemsForRead(false);
11101 return new LSL_Vector(); 10921 return new LSL_Vector();
11102 } 10922 }
11103 m_host.TaskInventory.LockItemsForRead(false);
11104 10923
11105// ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10924// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
11106 ScenePresence presence = World.GetScenePresence(agentID); 10925 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
11107 if (presence != null) 10926 if (presence != null)
11108 { 10927 {
11109 LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z); 10928 LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z);
@@ -11115,30 +10934,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11115 public LSL_Rotation llGetCameraRot() 10934 public LSL_Rotation llGetCameraRot()
11116 { 10935 {
11117 m_host.AddScriptLPS(1); 10936 m_host.AddScriptLPS(1);
11118 UUID invItemID = InventorySelf();
11119 if (invItemID == UUID.Zero)
11120 return new LSL_Rotation();
11121 10937
11122 m_host.TaskInventory.LockItemsForRead(true); 10938 if (m_item.PermsGranter == UUID.Zero)
11123 10939 return new LSL_Rotation();
11124 UUID agentID = m_host.TaskInventory[invItemID].PermsGranter;
11125 10940
11126// if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 10941 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
11127 if (agentID == UUID.Zero)
11128 {
11129 m_host.TaskInventory.LockItemsForRead(false);
11130 return new LSL_Rotation();
11131 }
11132 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
11133 { 10942 {
11134 ShoutError("No permissions to track the camera"); 10943 ShoutError("No permissions to track the camera");
11135 m_host.TaskInventory.LockItemsForRead(false);
11136 return new LSL_Rotation(); 10944 return new LSL_Rotation();
11137 } 10945 }
11138 m_host.TaskInventory.LockItemsForRead(false);
11139 10946
11140// ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10947// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
11141 ScenePresence presence = World.GetScenePresence(agentID); 10948 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
11142 if (presence != null) 10949 if (presence != null)
11143 { 10950 {
11144 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W); 10951 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W);
@@ -11197,7 +11004,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11197 public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt) 11004 public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
11198 { 11005 {
11199 m_host.AddScriptLPS(1); 11006 m_host.AddScriptLPS(1);
11200 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0); 11007 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
11201 if (detectedParams == null) 11008 if (detectedParams == null)
11202 { 11009 {
11203 if (m_host.ParentGroup.IsAttachment == true) 11010 if (m_host.ParentGroup.IsAttachment == true)
@@ -11321,30 +11128,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11321 { 11128 {
11322 m_host.AddScriptLPS(1); 11129 m_host.AddScriptLPS(1);
11323 11130
11324 // our key in the object we are in
11325 UUID invItemID = InventorySelf();
11326 if (invItemID == UUID.Zero) return;
11327
11328 // the object we are in 11131 // the object we are in
11329 UUID objectID = m_host.ParentUUID; 11132 UUID objectID = m_host.ParentUUID;
11330 if (objectID == UUID.Zero) return; 11133 if (objectID == UUID.Zero)
11134 return;
11331 11135
11332 UUID agentID;
11333 m_host.TaskInventory.LockItemsForRead(true);
11334 // we need the permission first, to know which avatar we want to set the camera for 11136 // we need the permission first, to know which avatar we want to set the camera for
11335 agentID = m_host.TaskInventory[invItemID].PermsGranter; 11137 UUID agentID = m_item.PermsGranter;
11336 11138
11337 if (agentID == UUID.Zero) 11139 if (agentID == UUID.Zero)
11338 {
11339 m_host.TaskInventory.LockItemsForRead(false);
11340 return; 11140 return;
11341 } 11141
11342 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) 11142 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
11343 {
11344 m_host.TaskInventory.LockItemsForRead(false);
11345 return; 11143 return;
11346 }
11347 m_host.TaskInventory.LockItemsForRead(false);
11348 11144
11349 ScenePresence presence = World.GetScenePresence(agentID); 11145 ScenePresence presence = World.GetScenePresence(agentID);
11350 11146
@@ -11386,34 +11182,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11386 { 11182 {
11387 m_host.AddScriptLPS(1); 11183 m_host.AddScriptLPS(1);
11388 11184
11389 // our key in the object we are in
11390 UUID invItemID=InventorySelf();
11391 if (invItemID == UUID.Zero) return;
11392
11393 // the object we are in 11185 // the object we are in
11394 UUID objectID = m_host.ParentUUID; 11186 UUID objectID = m_host.ParentUUID;
11395 if (objectID == UUID.Zero) return; 11187 if (objectID == UUID.Zero)
11188 return;
11396 11189
11397 // we need the permission first, to know which avatar we want to clear the camera for 11190 // we need the permission first, to know which avatar we want to clear the camera for
11398 UUID agentID; 11191 UUID agentID = m_item.PermsGranter;
11399 m_host.TaskInventory.LockItemsForRead(true); 11192
11400 agentID = m_host.TaskInventory[invItemID].PermsGranter;
11401 if (agentID == UUID.Zero) 11193 if (agentID == UUID.Zero)
11402 {
11403 m_host.TaskInventory.LockItemsForRead(false);
11404 return; 11194 return;
11405 } 11195
11406 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) 11196 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
11407 {
11408 m_host.TaskInventory.LockItemsForRead(false);
11409 return; 11197 return;
11410 }
11411 m_host.TaskInventory.LockItemsForRead(false);
11412 11198
11413 ScenePresence presence = World.GetScenePresence(agentID); 11199 ScenePresence presence = World.GetScenePresence(agentID);
11414 11200
11415 // we are not interested in child-agents 11201 // we are not interested in child-agents
11416 if (presence.IsChildAgent) return; 11202 if (presence.IsChildAgent)
11203 return;
11417 11204
11418 presence.ControllingClient.SendClearFollowCamProperties(objectID); 11205 presence.ControllingClient.SendClearFollowCamProperties(objectID);
11419 } 11206 }
@@ -11604,8 +11391,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11604 } 11391 }
11605 } 11392 }
11606 11393
11607 UUID reqID = httpScriptMod. 11394 UUID reqID
11608 StartHttpRequest(m_localID, m_itemID, url, param, httpHeaders, body); 11395 = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body);
11609 11396
11610 if (reqID != UUID.Zero) 11397 if (reqID != UUID.Zero)
11611 return reqID.ToString(); 11398 return reqID.ToString();
@@ -11859,19 +11646,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11859 break; 11646 break;
11860 // For the following 8 see the Object version below 11647 // For the following 8 see the Object version below
11861 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT: 11648 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
11862 ret.Add(new LSL_Integer(0)); 11649 ret.Add(new LSL_Integer(av.RunningScriptCount()));
11863 break; 11650 break;
11864 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT: 11651 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
11865 ret.Add(new LSL_Integer(0)); 11652 ret.Add(new LSL_Integer(av.ScriptCount()));
11866 break; 11653 break;
11867 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY: 11654 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
11868 ret.Add(new LSL_Integer(0)); 11655 ret.Add(new LSL_Integer(av.RunningScriptCount() * 16384));
11869 break; 11656 break;
11870 case ScriptBaseClass.OBJECT_SCRIPT_TIME: 11657 case ScriptBaseClass.OBJECT_SCRIPT_TIME:
11871 ret.Add(new LSL_Float(0)); 11658 ret.Add(new LSL_Float(av.ScriptExecutionTime() / 1000.0f));
11872 break; 11659 break;
11873 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE: 11660 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
11874 ret.Add(new LSL_Integer(0)); 11661 ret.Add(new LSL_Integer(1));
11875 break; 11662 break;
11876 case ScriptBaseClass.OBJECT_SERVER_COST: 11663 case ScriptBaseClass.OBJECT_SERVER_COST:
11877 ret.Add(new LSL_Float(0)); 11664 ret.Add(new LSL_Float(0));
@@ -11929,37 +11716,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11929 case ScriptBaseClass.OBJECT_CREATOR: 11716 case ScriptBaseClass.OBJECT_CREATOR:
11930 ret.Add(new LSL_String(obj.CreatorID.ToString())); 11717 ret.Add(new LSL_String(obj.CreatorID.ToString()));
11931 break; 11718 break;
11932 // The following 8 I have intentionaly coded to return zero. They are part of
11933 // "Land Impact" calculations. These calculations are probably not applicable
11934 // to OpenSim, required figures (cpu/memory usage) are not currently tracked
11935 // I have intentionally left these all at zero rather than return possibly
11936 // missleading numbers
11937 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT: 11719 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
11938 // in SL this currently includes crashed scripts 11720 ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount()));
11939 ret.Add(new LSL_Integer(0));
11940 break; 11721 break;
11941 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT: 11722 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
11942 ret.Add(new LSL_Integer(0)); 11723 ret.Add(new LSL_Integer(obj.ParentGroup.ScriptCount()));
11943 break; 11724 break;
11944 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY: 11725 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
11945 // The value returned in SL for mono scripts is 65536 * number of active scripts 11726 // The value returned in SL for mono scripts is 65536 * number of active scripts
11946 ret.Add(new LSL_Integer(0)); 11727 // and 16384 * number of active scripts for LSO. since llGetFreememory
11728 // is coded to give the LSO value use it here
11729 ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount() * 16384));
11947 break; 11730 break;
11948 case ScriptBaseClass.OBJECT_SCRIPT_TIME: 11731 case ScriptBaseClass.OBJECT_SCRIPT_TIME:
11949 // Average cpu time per simulator frame expended on all scripts in the objetc 11732 // Average cpu time in seconds per simulator frame expended on all scripts in the object
11950 ret.Add(new LSL_Float(0)); 11733 ret.Add(new LSL_Float(obj.ParentGroup.ScriptExecutionTime() / 1000.0f));
11951 break; 11734 break;
11952 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE: 11735 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
11953 // according to the SL wiki A prim or linkset will have prim 11736 // according to the SL wiki A prim or linkset will have prim
11954 // equivalent of the number of prims in a linkset if it does not 11737 // equivalent of the number of prims in a linkset if it does not
11955 // contain a mesh anywhere in the link set or is not a normal prim 11738 // contain a mesh anywhere in the link set or is not a normal prim
11956 // The value returned in SL for normal prims is prim count 11739 // The value returned in SL for normal prims is prim count
11957 ret.Add(new LSL_Integer(0)); 11740 ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
11958 break; 11741 break;
11959 11742
11960 // costs below may need to be diferent for root parts, need to check 11743 // costs below may need to be diferent for root parts, need to check
11961 case ScriptBaseClass.OBJECT_SERVER_COST: 11744 case ScriptBaseClass.OBJECT_SERVER_COST:
11962 // The value returned in SL for normal prims is prim count 11745 // The linden calculation is here
11746 // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
11747 // The value returned in SL for normal prims looks like the prim count
11963 ret.Add(new LSL_Float(0)); 11748 ret.Add(new LSL_Float(0));
11964 break; 11749 break;
11965 case ScriptBaseClass.OBJECT_STREAMING_COST: 11750 case ScriptBaseClass.OBJECT_STREAMING_COST:
@@ -12065,7 +11850,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12065 } 11850 }
12066 11851
12067 // was: UUID tid = tid = AsyncCommands. 11852 // was: UUID tid = tid = AsyncCommands.
12068 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, assetID.ToString()); 11853 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, assetID.ToString());
12069 11854
12070 if (NotecardCache.IsCached(assetID)) 11855 if (NotecardCache.IsCached(assetID))
12071 { 11856 {
@@ -12128,7 +11913,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12128 } 11913 }
12129 11914
12130 // was: UUID tid = tid = AsyncCommands. 11915 // was: UUID tid = tid = AsyncCommands.
12131 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, assetID.ToString()); 11916 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, assetID.ToString());
12132 11917
12133 if (NotecardCache.IsCached(assetID)) 11918 if (NotecardCache.IsCached(assetID))
12134 { 11919 {
@@ -12212,7 +11997,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12212 { 11997 {
12213 UUID rq = UUID.Random(); 11998 UUID rq = UUID.Random();
12214 11999
12215 AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 12000 AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
12216 12001
12217 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id))); 12002 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id)));
12218 12003
@@ -12228,7 +12013,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12228 { 12013 {
12229 UUID rq = UUID.Random(); 12014 UUID rq = UUID.Random();
12230 12015
12231 AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 12016 AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
12232 12017
12233 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id)); 12018 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id));
12234 12019
@@ -12430,7 +12215,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12430 { 12215 {
12431 Tri t1 = new Tri(); 12216 Tri t1 = new Tri();
12432 Tri t2 = new Tri(); 12217 Tri t2 = new Tri();
12433 12218
12434 Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]); 12219 Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]);
12435 Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]); 12220 Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]);
12436 Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]); 12221 Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]);
@@ -12471,7 +12256,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12471 // sometimes 12256 // sometimes
12472 if (Math.Abs(b) < 0.000001) 12257 if (Math.Abs(b) < 0.000001)
12473 continue; 12258 continue;
12474 12259
12475 double r = a / b; 12260 double r = a / b;
12476 12261
12477 // ray points away from plane 12262 // ray points away from plane
@@ -12731,7 +12516,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12731 bool isAccount = false; 12516 bool isAccount = false;
12732 bool isGroup = false; 12517 bool isGroup = false;
12733 12518
12734 if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManager(m_host.OwnerID)) 12519 if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManagerOrOwner(m_host.OwnerID))
12735 return 0; 12520 return 0;
12736 12521
12737 UUID id = new UUID(); 12522 UUID id = new UUID();
@@ -12793,35 +12578,50 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12793 return 1; 12578 return 1;
12794 } 12579 }
12795 12580
12796 #region Not Implemented 12581 public LSL_Integer llGetMemoryLimit()
12797 // 12582 {
12798 // Listing the unimplemented lsl functions here, please move 12583 m_host.AddScriptLPS(1);
12799 // them from this region as they are completed 12584 // The value returned for LSO scripts in SL
12800 // 12585 return 16384;
12586 }
12801 12587
12802 public void llGetEnv(LSL_String name) 12588 public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
12803 { 12589 {
12804 m_host.AddScriptLPS(1); 12590 m_host.AddScriptLPS(1);
12805 NotImplemented("llGetEnv"); 12591 // Treat as an LSO script
12592 return ScriptBaseClass.FALSE;
12806 } 12593 }
12807 12594
12808 public void llGetSPMaxMemory() 12595 public LSL_Integer llGetSPMaxMemory()
12809 { 12596 {
12810 m_host.AddScriptLPS(1); 12597 m_host.AddScriptLPS(1);
12811 NotImplemented("llGetSPMaxMemory"); 12598 // The value returned for LSO scripts in SL
12599 return 16384;
12812 } 12600 }
12813 12601
12814 public virtual LSL_Integer llGetUsedMemory() 12602 public virtual LSL_Integer llGetUsedMemory()
12815 { 12603 {
12816 m_host.AddScriptLPS(1); 12604 m_host.AddScriptLPS(1);
12817 NotImplemented("llGetUsedMemory"); 12605 // The value returned for LSO scripts in SL
12818 return 0; 12606 return 16384;
12819 } 12607 }
12820 12608
12821 public void llScriptProfiler(LSL_Integer flags) 12609 public void llScriptProfiler(LSL_Integer flags)
12822 { 12610 {
12823 m_host.AddScriptLPS(1); 12611 m_host.AddScriptLPS(1);
12824 //NotImplemented("llScriptProfiler"); 12612 // This does nothing for LSO scripts in SL
12613 }
12614
12615 #region Not Implemented
12616 //
12617 // Listing the unimplemented lsl functions here, please move
12618 // them from this region as they are completed
12619 //
12620
12621 public void llGetEnv(LSL_String name)
12622 {
12623 m_host.AddScriptLPS(1);
12624 NotImplemented("llGetEnv");
12825 } 12625 }
12826 12626
12827 public void llSetSoundQueueing(int queue) 12627 public void llSetSoundQueueing(int queue)
@@ -12901,8 +12701,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12901 12701
12902 try 12702 try
12903 { 12703 {
12904 UUID invItemID=InventorySelf(); 12704 TaskInventoryItem item = m_item;
12905 if (invItemID == UUID.Zero) 12705 if (item == null)
12906 { 12706 {
12907 replydata = "SERVICE_ERROR"; 12707 replydata = "SERVICE_ERROR";
12908 return; 12708 return;
@@ -12910,10 +12710,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12910 12710
12911 m_host.AddScriptLPS(1); 12711 m_host.AddScriptLPS(1);
12912 12712
12913 m_host.TaskInventory.LockItemsForRead(true);
12914 TaskInventoryItem item = m_host.TaskInventory[invItemID];
12915 m_host.TaskInventory.LockItemsForRead(false);
12916
12917 if (item.PermsGranter == UUID.Zero) 12713 if (item.PermsGranter == UUID.Zero)
12918 { 12714 {
12919 replydata = "MISSING_PERMISSION_DEBIT"; 12715 replydata = "MISSING_PERMISSION_DEBIT";
@@ -12955,7 +12751,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12955 } 12751 }
12956 finally 12752 finally
12957 { 12753 {
12958 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 12754 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
12959 "transaction_result", new Object[] { 12755 "transaction_result", new Object[] {
12960 new LSL_String(txn.ToString()), 12756 new LSL_String(txn.ToString()),
12961 new LSL_Integer(replycode), 12757 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..795376b 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
@@ -1980,7 +1976,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1980 { 1976 {
1981 string retval = String.Empty; 1977 string retval = String.Empty;
1982 IConfigSource config = m_ScriptEngine.ConfigSource; 1978 IConfigSource config = m_ScriptEngine.ConfigSource;
1983 string url = config.Configs["GridInfo"].GetString("GridInfoURI", String.Empty); 1979 string url = null;
1980
1981 IConfig gridInfoConfig = config.Configs["GridInfo"];
1982
1983 if (gridInfoConfig != null)
1984 url = gridInfoConfig.GetString("GridInfoURI", String.Empty);
1984 1985
1985 if (String.IsNullOrEmpty(url)) 1986 if (String.IsNullOrEmpty(url))
1986 return "Configuration Error!"; 1987 return "Configuration Error!";
@@ -2042,8 +2043,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2042 string nick = String.Empty; 2043 string nick = String.Empty;
2043 IConfigSource config = m_ScriptEngine.ConfigSource; 2044 IConfigSource config = m_ScriptEngine.ConfigSource;
2044 2045
2045 if (config.Configs["GridInfo"] != null) 2046 if (config.Configs[GridInfoServiceConfigSectionName] != null)
2046 nick = config.Configs["GridInfo"].GetString("gridnick", nick); 2047 nick = config.Configs[GridInfoServiceConfigSectionName].GetString("gridnick", nick);
2047 2048
2048 if (String.IsNullOrEmpty(nick)) 2049 if (String.IsNullOrEmpty(nick))
2049 nick = GridUserInfo(InfoType.Nick); 2050 nick = GridUserInfo(InfoType.Nick);
@@ -2059,8 +2060,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2059 string name = String.Empty; 2060 string name = String.Empty;
2060 IConfigSource config = m_ScriptEngine.ConfigSource; 2061 IConfigSource config = m_ScriptEngine.ConfigSource;
2061 2062
2062 if (config.Configs["GridInfo"] != null) 2063 if (config.Configs[GridInfoServiceConfigSectionName] != null)
2063 name = config.Configs["GridInfo"].GetString("gridname", name); 2064 name = config.Configs[GridInfoServiceConfigSectionName].GetString("gridname", name);
2064 2065
2065 if (String.IsNullOrEmpty(name)) 2066 if (String.IsNullOrEmpty(name))
2066 name = GridUserInfo(InfoType.Name); 2067 name = GridUserInfo(InfoType.Name);
@@ -2076,8 +2077,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2076 string loginURI = String.Empty; 2077 string loginURI = String.Empty;
2077 IConfigSource config = m_ScriptEngine.ConfigSource; 2078 IConfigSource config = m_ScriptEngine.ConfigSource;
2078 2079
2079 if (config.Configs["GridInfo"] != null) 2080 if (config.Configs[GridInfoServiceConfigSectionName] != null)
2080 loginURI = config.Configs["GridInfo"].GetString("login", loginURI); 2081 loginURI = config.Configs[GridInfoServiceConfigSectionName].GetString("login", loginURI);
2081 2082
2082 if (String.IsNullOrEmpty(loginURI)) 2083 if (String.IsNullOrEmpty(loginURI))
2083 loginURI = GridUserInfo(InfoType.Login); 2084 loginURI = GridUserInfo(InfoType.Login);
@@ -2124,8 +2125,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2124 string retval = String.Empty; 2125 string retval = String.Empty;
2125 IConfigSource config = m_ScriptEngine.ConfigSource; 2126 IConfigSource config = m_ScriptEngine.ConfigSource;
2126 2127
2127 if (config.Configs["GridInfo"] != null) 2128 if (config.Configs[GridInfoServiceConfigSectionName] != null)
2128 retval = config.Configs["GridInfo"].GetString(key, retval); 2129 retval = config.Configs[GridInfoServiceConfigSectionName].GetString(key, retval);
2129 2130
2130 if (String.IsNullOrEmpty(retval)) 2131 if (String.IsNullOrEmpty(retval))
2131 retval = GridUserInfo(InfoType.Custom, key); 2132 retval = GridUserInfo(InfoType.Custom, key);
@@ -2480,7 +2481,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2480 return; 2481 return;
2481 2482
2482 Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z); 2483 Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z);
2483 module.MoveToTarget(npcId, World, pos, false, true); 2484 module.MoveToTarget(npcId, World, pos, false, true, false);
2484 } 2485 }
2485 } 2486 }
2486 2487
@@ -2505,7 +2506,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2505 World, 2506 World,
2506 pos, 2507 pos,
2507 (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0, 2508 (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0,
2508 (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0); 2509 (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0,
2510 (options & ScriptBaseClass.OS_NPC_RUNNING) != 0);
2509 } 2511 }
2510 } 2512 }
2511 2513
@@ -2555,7 +2557,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2555 2557
2556 public void osNpcStopMoveToTarget(LSL_Key npc) 2558 public void osNpcStopMoveToTarget(LSL_Key npc)
2557 { 2559 {
2558 CheckThreatLevel(ThreatLevel.VeryLow, "osNpcStopMoveTo"); 2560 CheckThreatLevel(ThreatLevel.High, "osNpcStopMoveToTarget");
2559 m_host.AddScriptLPS(1); 2561 m_host.AddScriptLPS(1);
2560 2562
2561 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2563 INPCModule module = World.RequestModuleInterface<INPCModule>();
@@ -2572,6 +2574,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2572 2574
2573 public void osNpcSay(LSL_Key npc, string message) 2575 public void osNpcSay(LSL_Key npc, string message)
2574 { 2576 {
2577 osNpcSay(npc, 0, message);
2578 }
2579
2580 public void osNpcSay(LSL_Key npc, int channel, string message)
2581 {
2575 CheckThreatLevel(ThreatLevel.High, "osNpcSay"); 2582 CheckThreatLevel(ThreatLevel.High, "osNpcSay");
2576 m_host.AddScriptLPS(1); 2583 m_host.AddScriptLPS(1);
2577 2584
@@ -2583,7 +2590,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2583 if (!module.CheckPermissions(npcId, m_host.OwnerID)) 2590 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2584 return; 2591 return;
2585 2592
2586 module.Say(npcId, World, message); 2593 module.Say(npcId, World, message, channel);
2594 }
2595 }
2596
2597 public void osNpcShout(LSL_Key npc, int channel, string message)
2598 {
2599 CheckThreatLevel(ThreatLevel.High, "osNpcShout");
2600 m_host.AddScriptLPS(1);
2601
2602 INPCModule module = World.RequestModuleInterface<INPCModule>();
2603 if (module != null)
2604 {
2605 UUID npcId = new UUID(npc.m_string);
2606
2607 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2608 return;
2609
2610 module.Shout(npcId, World, message, channel);
2587 } 2611 }
2588 } 2612 }
2589 2613
@@ -2684,6 +2708,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2684 } 2708 }
2685 } 2709 }
2686 2710
2711 public void osNpcWhisper(LSL_Key npc, int channel, string message)
2712 {
2713 CheckThreatLevel(ThreatLevel.High, "osNpcWhisper");
2714 m_host.AddScriptLPS(1);
2715
2716 INPCModule module = World.RequestModuleInterface<INPCModule>();
2717 if (module != null)
2718 {
2719 UUID npcId = new UUID(npc.m_string);
2720
2721 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2722 return;
2723
2724 module.Whisper(npcId, World, message, channel);
2725 }
2726 }
2727
2687 /// <summary> 2728 /// <summary>
2688 /// Save the current appearance of the script owner permanently to the named notecard. 2729 /// Save the current appearance of the script owner permanently to the named notecard.
2689 /// </summary> 2730 /// </summary>
@@ -2835,21 +2876,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2835 CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar"); 2876 CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
2836 m_host.AddScriptLPS(1); 2877 m_host.AddScriptLPS(1);
2837 2878
2838 if (World.Permissions.CanRunConsoleCommand(m_host.OwnerID)) 2879 World.ForEachRootScenePresence(delegate(ScenePresence sp)
2839 { 2880 {
2840 World.ForEachRootScenePresence(delegate(ScenePresence sp) 2881 if (sp.Firstname == FirstName && sp.Lastname == SurName)
2841 { 2882 {
2842 if (sp.Firstname == FirstName && sp.Lastname == SurName) 2883 // kick client...
2843 { 2884 if (alert != null)
2844 // kick client... 2885 sp.ControllingClient.Kick(alert);
2845 if (alert != null)
2846 sp.ControllingClient.Kick(alert);
2847 2886
2848 // ...and close on our side 2887 // ...and close on our side
2849 sp.Scene.IncomingCloseAgent(sp.UUID); 2888 sp.Scene.IncomingCloseAgent(sp.UUID);
2850 } 2889 }
2851 }); 2890 });
2852 }
2853 } 2891 }
2854 2892
2855 public void osCauseDamage(string avatar, double damage) 2893 public void osCauseDamage(string avatar, double damage)
@@ -3095,5 +3133,80 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3095 3133
3096 return ScriptBaseClass.TRUE; 3134 return ScriptBaseClass.TRUE;
3097 } 3135 }
3136
3137 /// <summary>
3138 /// Sets terrain estate texture
3139 /// </summary>
3140 /// <param name="level"></param>
3141 /// <param name="texture"></param>
3142 /// <returns></returns>
3143 public void osSetTerrainTexture(int level, LSL_Key texture)
3144 {
3145 CheckThreatLevel(ThreatLevel.High, "osSetTerrainTexture");
3146
3147 m_host.AddScriptLPS(1);
3148 //Check to make sure that the script's owner is the estate manager/master
3149 //World.Permissions.GenericEstatePermission(
3150 if (World.Permissions.IsGod(m_host.OwnerID))
3151 {
3152 if (level < 0 || level > 3)
3153 return;
3154
3155 UUID textureID = new UUID();
3156 if (!UUID.TryParse(texture, out textureID))
3157 return;
3158
3159 // estate module is required
3160 IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
3161 if (estate != null)
3162 estate.setEstateTerrainBaseTexture(level, textureID);
3163 }
3164 }
3165
3166 /// <summary>
3167 /// Sets terrain heights of estate
3168 /// </summary>
3169 /// <param name="corner"></param>
3170 /// <param name="low"></param>
3171 /// <param name="high"></param>
3172 /// <returns></returns>
3173 public void osSetTerrainTextureHeight(int corner, double low, double high)
3174 {
3175 CheckThreatLevel(ThreatLevel.High, "osSetTerrainTextureHeight");
3176
3177 m_host.AddScriptLPS(1);
3178 //Check to make sure that the script's owner is the estate manager/master
3179 //World.Permissions.GenericEstatePermission(
3180 if (World.Permissions.IsGod(m_host.OwnerID))
3181 {
3182 if (corner < 0 || corner > 3)
3183 return;
3184
3185 // estate module is required
3186 IEstateModule estate = World.RequestModuleInterface<IEstateModule>();
3187 if (estate != null)
3188 estate.setEstateTerrainTextureHeights(corner, (float)low, (float)high);
3189 }
3190 }
3191
3192 public void osForceAttachToAvatar(int attachmentPoint)
3193 {
3194 CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar");
3195
3196 m_host.AddScriptLPS(1);
3197
3198 InitLSL();
3199 ((LSL_Api)m_LSL_Api).AttachToAvatar(attachmentPoint);
3200 }
3201
3202 public void osForceDetachFromAvatar()
3203 {
3204 CheckThreatLevel(ThreatLevel.High, "osForceDetachFromAvatar");
3205
3206 m_host.AddScriptLPS(1);
3207
3208 InitLSL();
3209 ((LSL_Api)m_LSL_Api).DetachFromAvatar();
3210 }
3098 } 3211 }
3099} 3212}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
index 1373971..19f3ce1 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
@@ -308,7 +308,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
308 } 308 }
309 SceneObjectPart SensePoint = ts.host; 309 SceneObjectPart SensePoint = ts.host;
310 310
311 Vector3 fromRegionPos = SensePoint.AbsolutePosition; 311 Vector3 fromRegionPos = SensePoint.GetWorldPosition();
312 312
313 // pre define some things to avoid repeated definitions in the loop body 313 // pre define some things to avoid repeated definitions in the loop body
314 Vector3 toRegionPos; 314 Vector3 toRegionPos;
@@ -323,13 +323,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
323 Quaternion q = SensePoint.GetWorldRotation(); // non-attached prim Sensor *always* uses World rotation! 323 Quaternion q = SensePoint.GetWorldRotation(); // non-attached prim Sensor *always* uses World rotation!
324 if (SensePoint.ParentGroup.IsAttachment) 324 if (SensePoint.ParentGroup.IsAttachment)
325 { 325 {
326 // In attachments, the sensor cone always orients with the 326 // In attachments, rotate the sensor cone with the
327 // avatar rotation. This may include a nonzero elevation if 327 // avatar rotation. This may include a nonzero elevation if
328 // in mouselook. 328 // in mouselook.
329 // This will not include the rotation and position of the
330 // attachment point (e.g. your head when a sensor is in your
331 // hair attached to your scull. Your hair will turn with
332 // your head but the sensor will stay with your (global)
333 // avatar rotation and position.
334 // Position of a sensor in a child prim attached to an avatar
335 // will be still wrong.
329 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); 336 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
330 fromRegionPos = avatar.AbsolutePosition; 337 fromRegionPos = avatar.AbsolutePosition;
331 q = avatar.Rotation; 338 q = avatar.Rotation;
332 } 339 }
340
333 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); 341 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
334 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r); 342 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
335 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir); 343 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir);
@@ -441,14 +449,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
441 return sensedEntities; 449 return sensedEntities;
442 450
443 SceneObjectPart SensePoint = ts.host; 451 SceneObjectPart SensePoint = ts.host;
444 Vector3 fromRegionPos = SensePoint.AbsolutePosition; 452 Vector3 fromRegionPos = SensePoint.GetWorldPosition();
445 453
446 Quaternion q = SensePoint.RotationOffset; 454 Quaternion q = SensePoint.GetWorldRotation();
447 if (SensePoint.ParentGroup.IsAttachment) 455 if (SensePoint.ParentGroup.IsAttachment)
448 { 456 {
449 // In attachments, the sensor cone always orients with the 457 // In attachments, rotate the sensor cone with the
450 // avatar rotation. This may include a nonzero elevation if 458 // avatar rotation. This may include a nonzero elevation if
451 // in mouselook. 459 // in mouselook.
460 // This will not include the rotation and position of the
461 // attachment point (e.g. your head when a sensor is in your
462 // hair attached to your scull. Your hair will turn with
463 // your head but the sensor will stay with your (global)
464 // avatar rotation and position.
465 // Position of a sensor in a child prim attached to an avatar
466 // will be still wrong.
452 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); 467 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
453 if (avatar == null) 468 if (avatar == null)
454 return sensedEntities; 469 return sensedEntities;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
index 50f520a..749fc97 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
@@ -105,6 +105,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
105 LSL_Integer llFloor(double f); 105 LSL_Integer llFloor(double f);
106 void llForceMouselook(int mouselook); 106 void llForceMouselook(int mouselook);
107 LSL_Float llFrand(double mag); 107 LSL_Float llFrand(double mag);
108 LSL_Key llGenerateKey();
108 LSL_Vector llGetAccel(); 109 LSL_Vector llGetAccel();
109 LSL_Integer llGetAgentInfo(string id); 110 LSL_Integer llGetAgentInfo(string id);
110 LSL_String llGetAgentLanguage(string id); 111 LSL_String llGetAgentLanguage(string id);
@@ -150,7 +151,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
150 LSL_Rotation llGetLocalRot(); 151 LSL_Rotation llGetLocalRot();
151 LSL_Float llGetMass(); 152 LSL_Float llGetMass();
152 LSL_Float llGetMassMKS(); 153 LSL_Float llGetMassMKS();
153 void llGetNextEmail(string address, string subject); 154 LSL_Integer llGetMemoryLimit();
155 void llGetNextEmail(string address, string subject);
154 LSL_String llGetNotecardLine(string name, int line); 156 LSL_String llGetNotecardLine(string name, int line);
155 LSL_Key llGetNumberOfNotecardLines(string name); 157 LSL_Key llGetNumberOfNotecardLines(string name);
156 LSL_Integer llGetNumberOfPrims(); 158 LSL_Integer llGetNumberOfPrims();
@@ -188,6 +190,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
188 LSL_String llGetScriptName(); 190 LSL_String llGetScriptName();
189 LSL_Integer llGetScriptState(string name); 191 LSL_Integer llGetScriptState(string name);
190 LSL_String llGetSimulatorHostname(); 192 LSL_String llGetSimulatorHostname();
193 LSL_Integer llGetSPMaxMemory();
191 LSL_Integer llGetStartParameter(); 194 LSL_Integer llGetStartParameter();
192 LSL_Integer llGetStatus(int status); 195 LSL_Integer llGetStatus(int status);
193 LSL_String llGetSubString(string src, int start, int end); 196 LSL_String llGetSubString(string src, int start, int end);
@@ -323,6 +326,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
323 void llSay(int channelID, string text); 326 void llSay(int channelID, string text);
324 void llScaleTexture(double u, double v, int face); 327 void llScaleTexture(double u, double v, int face);
325 LSL_Integer llScriptDanger(LSL_Vector pos); 328 LSL_Integer llScriptDanger(LSL_Vector pos);
329 void llScriptProfiler(LSL_Integer flag);
326 LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata); 330 LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata);
327 void llSensor(string name, string id, int type, double range, double arc); 331 void llSensor(string name, string id, int type, double range, double arc);
328 void llSensorRemove(); 332 void llSensorRemove();
@@ -346,6 +350,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
346 void llSetLinkTexture(int linknumber, string texture, int face); 350 void llSetLinkTexture(int linknumber, string texture, int face);
347 void llSetLinkTextureAnim(int linknum, int mode, int face, int sizex, int sizey, double start, double length, double rate); 351 void llSetLinkTextureAnim(int linknum, int mode, int face, int sizex, int sizey, double start, double length, double rate);
348 void llSetLocalRot(LSL_Rotation rot); 352 void llSetLocalRot(LSL_Rotation rot);
353 LSL_Integer llSetMemoryLimit(LSL_Integer limit);
349 void llSetObjectDesc(string desc); 354 void llSetObjectDesc(string desc);
350 void llSetObjectName(string name); 355 void llSetObjectName(string name);
351 void llSetObjectPermMask(int mask, int value); 356 void llSetObjectPermMask(int mask, int value);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index 444a681..7382495 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -98,6 +98,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
98 void osAvatarPlayAnimation(string avatar, string animation); 98 void osAvatarPlayAnimation(string avatar, string animation);
99 void osAvatarStopAnimation(string avatar, string animation); 99 void osAvatarStopAnimation(string avatar, string animation);
100 100
101 // Attachment commands
102
103 /// <summary>
104 /// Attach the object containing this script to the avatar that owns it without checking for PERMISSION_ATTACH
105 /// </summary>
106 /// <param name='attachment'>The attachment point. For example, ATTACH_CHEST</param>
107 void osForceAttachToAvatar(int attachment);
108
109 /// <summary>
110 /// Detach the object containing this script from the avatar it is attached to without checking for PERMISSION_ATTACH
111 /// </summary>
112 /// <remarks>Nothing happens if the object is not attached.</remarks>
113 void osForceDetachFromAvatar();
114
101 //texture draw functions 115 //texture draw functions
102 string osMovePen(string drawList, int x, int y); 116 string osMovePen(string drawList, int x, int y);
103 string osDrawLine(string drawList, int startX, int startY, int endX, int endY); 117 string osDrawLine(string drawList, int startX, int startY, int endX, int endY);
@@ -203,11 +217,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
203 void osNpcSetRot(LSL_Key npc, rotation rot); 217 void osNpcSetRot(LSL_Key npc, rotation rot);
204 void osNpcStopMoveToTarget(LSL_Key npc); 218 void osNpcStopMoveToTarget(LSL_Key npc);
205 void osNpcSay(key npc, string message); 219 void osNpcSay(key npc, string message);
220 void osNpcSay(key npc, int channel, string message);
221 void osNpcShout(key npc, int channel, string message);
206 void osNpcSit(key npc, key target, int options); 222 void osNpcSit(key npc, key target, int options);
207 void osNpcStand(LSL_Key npc); 223 void osNpcStand(LSL_Key npc);
208 void osNpcRemove(key npc); 224 void osNpcRemove(key npc);
209 void osNpcPlayAnimation(LSL_Key npc, string animation); 225 void osNpcPlayAnimation(LSL_Key npc, string animation);
210 void osNpcStopAnimation(LSL_Key npc, string animation); 226 void osNpcStopAnimation(LSL_Key npc, string animation);
227 void osNpcWhisper(key npc, int channel, string message);
211 228
212 LSL_Key osOwnerSaveAppearance(string notecard); 229 LSL_Key osOwnerSaveAppearance(string notecard);
213 LSL_Key osAgentSaveAppearance(key agentId, string notecard); 230 LSL_Key osAgentSaveAppearance(key agentId, string notecard);
@@ -234,5 +251,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
234 251
235 LSL_Integer osInviteToGroup(LSL_Key agentId); 252 LSL_Integer osInviteToGroup(LSL_Key agentId);
236 LSL_Integer osEjectFromGroup(LSL_Key agentId); 253 LSL_Integer osEjectFromGroup(LSL_Key agentId);
254
255 void osSetTerrainTexture(int level, LSL_Key texture);
256 void osSetTerrainTextureHeight(int corner, double low, double high);
237 } 257 }
238} 258}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
index ad4f70c..a08cc42 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -383,6 +383,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
383 public const int PRIM_SCULPT_FLAG_INVERT = 64; 383 public const int PRIM_SCULPT_FLAG_INVERT = 64;
384 public const int PRIM_SCULPT_FLAG_MIRROR = 128; 384 public const int PRIM_SCULPT_FLAG_MIRROR = 128;
385 385
386 public const int PROFILE_NONE = 0;
387 public const int PROFILE_SCRIPT_MEMORY = 1;
388
386 public const int MASK_BASE = 0; 389 public const int MASK_BASE = 0;
387 public const int MASK_OWNER = 1; 390 public const int MASK_OWNER = 1;
388 public const int MASK_GROUP = 2; 391 public const int MASK_GROUP = 2;
@@ -641,6 +644,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
641 public const int OS_NPC_FLY = 0; 644 public const int OS_NPC_FLY = 0;
642 public const int OS_NPC_NO_FLY = 1; 645 public const int OS_NPC_NO_FLY = 1;
643 public const int OS_NPC_LAND_AT_TARGET = 2; 646 public const int OS_NPC_LAND_AT_TARGET = 2;
647 public const int OS_NPC_RUNNING = 4;
644 648
645 public const int OS_NPC_SIT_NOW = 0; 649 public const int OS_NPC_SIT_NOW = 0;
646 650
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
index 116f639..06f2c3c 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
@@ -165,11 +165,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
165 m_LSL_Functions.llBreakLink(linknum); 165 m_LSL_Functions.llBreakLink(linknum);
166 } 166 }
167 167
168 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
169 {
170 return m_LSL_Functions.llCastRay(start, end, options);
171 }
172
173 public LSL_Integer llCeil(double f) 168 public LSL_Integer llCeil(double f)
174 { 169 {
175 return m_LSL_Functions.llCeil(f); 170 return m_LSL_Functions.llCeil(f);
@@ -376,6 +371,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
376 return m_LSL_Functions.llFrand(mag); 371 return m_LSL_Functions.llFrand(mag);
377 } 372 }
378 373
374 public LSL_Key llGenerateKey()
375 {
376 return m_LSL_Functions.llGenerateKey();
377 }
378
379 public LSL_Vector llGetAccel() 379 public LSL_Vector llGetAccel()
380 { 380 {
381 return m_LSL_Functions.llGetAccel(); 381 return m_LSL_Functions.llGetAccel();
@@ -591,6 +591,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
591 return m_LSL_Functions.llGetMassMKS(); 591 return m_LSL_Functions.llGetMassMKS();
592 } 592 }
593 593
594 public LSL_Integer llGetMemoryLimit()
595 {
596 return m_LSL_Functions.llGetMemoryLimit();
597 }
598
594 public void llGetNextEmail(string address, string subject) 599 public void llGetNextEmail(string address, string subject)
595 { 600 {
596 m_LSL_Functions.llGetNextEmail(address, subject); 601 m_LSL_Functions.llGetNextEmail(address, subject);
@@ -781,6 +786,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
781 return m_LSL_Functions.llGetSimulatorHostname(); 786 return m_LSL_Functions.llGetSimulatorHostname();
782 } 787 }
783 788
789 public LSL_Integer llGetSPMaxMemory()
790 {
791 return m_LSL_Functions.llGetSPMaxMemory();
792 }
793
784 public LSL_Integer llGetStartParameter() 794 public LSL_Integer llGetStartParameter()
785 { 795 {
786 return m_LSL_Functions.llGetStartParameter(); 796 return m_LSL_Functions.llGetStartParameter();
@@ -956,6 +966,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
956 return m_LSL_Functions.llRequestDisplayName(id); 966 return m_LSL_Functions.llRequestDisplayName(id);
957 } 967 }
958 968
969 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
970 {
971 return m_LSL_Functions.llCastRay(start, end, options);
972 }
973
959 public void llLinkParticleSystem(int linknum, LSL_List rules) 974 public void llLinkParticleSystem(int linknum, LSL_List rules)
960 { 975 {
961 m_LSL_Functions.llLinkParticleSystem(linknum, rules); 976 m_LSL_Functions.llLinkParticleSystem(linknum, rules);
@@ -1450,6 +1465,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1450 return m_LSL_Functions.llScriptDanger(pos); 1465 return m_LSL_Functions.llScriptDanger(pos);
1451 } 1466 }
1452 1467
1468 public void llScriptProfiler(LSL_Integer flags)
1469 {
1470 m_LSL_Functions.llScriptProfiler(flags);
1471 }
1472
1453 public LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata) 1473 public LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata)
1454 { 1474 {
1455 return m_LSL_Functions.llSendRemoteData(channel, dest, idata, sdata); 1475 return m_LSL_Functions.llSendRemoteData(channel, dest, idata, sdata);
@@ -1560,6 +1580,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1560 m_LSL_Functions.llSetLocalRot(rot); 1580 m_LSL_Functions.llSetLocalRot(rot);
1561 } 1581 }
1562 1582
1583 public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
1584 {
1585 return m_LSL_Functions.llSetMemoryLimit(limit);
1586 }
1587
1563 public void llSetObjectDesc(string desc) 1588 public void llSetObjectDesc(string desc)
1564 { 1589 {
1565 m_LSL_Functions.llSetObjectDesc(desc); 1590 m_LSL_Functions.llSetObjectDesc(desc);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 680cefb4..d230662 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -289,8 +289,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
289 m_OSSL_Functions.osAvatarStopAnimation(avatar, animation); 289 m_OSSL_Functions.osAvatarStopAnimation(avatar, animation);
290 } 290 }
291 291
292 // Avatar functions
292 293
293 //Texture Draw functions 294 public void osForceAttachToAvatar(int attachmentPoint)
295 {
296 m_OSSL_Functions.osForceAttachToAvatar(attachmentPoint);
297 }
298
299 public void osForceDetachFromAvatar()
300 {
301 m_OSSL_Functions.osForceDetachFromAvatar();
302 }
303
304 // Texture Draw functions
294 305
295 public string osMovePen(string drawList, int x, int y) 306 public string osMovePen(string drawList, int x, int y)
296 { 307 {
@@ -569,6 +580,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
569 m_OSSL_Functions.osNpcSay(npc, message); 580 m_OSSL_Functions.osNpcSay(npc, message);
570 } 581 }
571 582
583 public void osNpcSay(key npc, int channel, string message)
584 {
585 m_OSSL_Functions.osNpcSay(npc, channel, message);
586 }
587
588
589 public void osNpcShout(key npc, int channel, string message)
590 {
591 m_OSSL_Functions.osNpcShout(npc, channel, message);
592 }
593
572 public void osNpcSit(LSL_Key npc, LSL_Key target, int options) 594 public void osNpcSit(LSL_Key npc, LSL_Key target, int options)
573 { 595 {
574 m_OSSL_Functions.osNpcSit(npc, target, options); 596 m_OSSL_Functions.osNpcSit(npc, target, options);
@@ -594,6 +616,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
594 m_OSSL_Functions.osNpcStopAnimation(npc, animation); 616 m_OSSL_Functions.osNpcStopAnimation(npc, animation);
595 } 617 }
596 618
619 public void osNpcWhisper(key npc, int channel, string message)
620 {
621 m_OSSL_Functions.osNpcWhisper(npc, channel, message);
622 }
623
597 public LSL_Key osOwnerSaveAppearance(string notecard) 624 public LSL_Key osOwnerSaveAppearance(string notecard)
598 { 625 {
599 return m_OSSL_Functions.osOwnerSaveAppearance(notecard); 626 return m_OSSL_Functions.osOwnerSaveAppearance(notecard);
@@ -878,5 +905,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
878 { 905 {
879 return m_OSSL_Functions.osEjectFromGroup(agentId); 906 return m_OSSL_Functions.osEjectFromGroup(agentId);
880 } 907 }
908
909 public void osSetTerrainTexture(int level, LSL_Key texture)
910 {
911 m_OSSL_Functions.osSetTerrainTexture(level, texture);
912 }
913
914 public void osSetTerrainTextureHeight(int corner, double low, double high)
915 {
916 m_OSSL_Functions.osSetTerrainTextureHeight(corner, low, high);
917 }
881 } 918 }
882} 919}