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.cs856
-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.cs25
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs39
12 files changed, 680 insertions, 670 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 fe85118..41de257 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
@@ -963,20 +921,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
963 921
964 public void llRegionSayTo(string target, int channel, string msg) 922 public void llRegionSayTo(string target, int channel, string msg)
965 { 923 {
966 string error = String.Empty;
967
968 if (msg.Length > 1023) 924 if (msg.Length > 1023)
969 msg = msg.Substring(0, 1023); 925 msg = msg.Substring(0, 1023);
970 926
971 m_host.AddScriptLPS(1); 927 m_host.AddScriptLPS(1);
972 928
929 if (channel == ScriptBaseClass.DEBUG_CHANNEL)
930 {
931 return;
932 }
933
973 UUID TargetID; 934 UUID TargetID;
974 UUID.TryParse(target, out TargetID); 935 UUID.TryParse(target, out TargetID);
975 936
976 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 937 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
977 if (wComm != null) 938 if (wComm != null)
978 if (!wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg, out error)) 939 wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg);
979 LSLError(error);
980 } 940 }
981 941
982 public LSL_Integer llListen(int channelID, string name, string ID, string msg) 942 public LSL_Integer llListen(int channelID, string name, string ID, string msg)
@@ -986,7 +946,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
986 UUID.TryParse(ID, out keyID); 946 UUID.TryParse(ID, out keyID);
987 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 947 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
988 if (wComm != null) 948 if (wComm != null)
989 return wComm.Listen(m_localID, m_itemID, m_host.UUID, channelID, name, keyID, msg); 949 return wComm.Listen(m_host.LocalId, m_item.ItemID, m_host.UUID, channelID, name, keyID, msg);
990 else 950 else
991 return -1; 951 return -1;
992 } 952 }
@@ -996,7 +956,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
996 m_host.AddScriptLPS(1); 956 m_host.AddScriptLPS(1);
997 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 957 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
998 if (wComm != null) 958 if (wComm != null)
999 wComm.ListenControl(m_itemID, number, active); 959 wComm.ListenControl(m_item.ItemID, number, active);
1000 } 960 }
1001 961
1002 public void llListenRemove(int number) 962 public void llListenRemove(int number)
@@ -1004,7 +964,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1004 m_host.AddScriptLPS(1); 964 m_host.AddScriptLPS(1);
1005 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 965 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
1006 if (wComm != null) 966 if (wComm != null)
1007 wComm.ListenRemove(m_itemID, number); 967 wComm.ListenRemove(m_item.ItemID, number);
1008 } 968 }
1009 969
1010 public void llSensor(string name, string id, int type, double range, double arc) 970 public void llSensor(string name, string id, int type, double range, double arc)
@@ -1013,7 +973,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1013 UUID keyID = UUID.Zero; 973 UUID keyID = UUID.Zero;
1014 UUID.TryParse(id, out keyID); 974 UUID.TryParse(id, out keyID);
1015 975
1016 AsyncCommands.SensorRepeatPlugin.SenseOnce(m_localID, m_itemID, name, keyID, type, range, arc, m_host); 976 AsyncCommands.SensorRepeatPlugin.SenseOnce(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, m_host);
1017 } 977 }
1018 978
1019 public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate) 979 public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate)
@@ -1022,13 +982,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1022 UUID keyID = UUID.Zero; 982 UUID keyID = UUID.Zero;
1023 UUID.TryParse(id, out keyID); 983 UUID.TryParse(id, out keyID);
1024 984
1025 AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_localID, m_itemID, name, keyID, type, range, arc, rate, m_host); 985 AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, rate, m_host);
1026 } 986 }
1027 987
1028 public void llSensorRemove() 988 public void llSensorRemove()
1029 { 989 {
1030 m_host.AddScriptLPS(1); 990 m_host.AddScriptLPS(1);
1031 AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_localID, m_itemID); 991 AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_host.LocalId, m_item.ItemID);
1032 } 992 }
1033 993
1034 public string resolveName(UUID objecUUID) 994 public string resolveName(UUID objecUUID)
@@ -1069,7 +1029,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1069 public LSL_String llDetectedName(int number) 1029 public LSL_String llDetectedName(int number)
1070 { 1030 {
1071 m_host.AddScriptLPS(1); 1031 m_host.AddScriptLPS(1);
1072 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1032 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1073 if (detectedParams == null) 1033 if (detectedParams == null)
1074 return String.Empty; 1034 return String.Empty;
1075 return detectedParams.Name; 1035 return detectedParams.Name;
@@ -1078,7 +1038,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1078 public LSL_String llDetectedKey(int number) 1038 public LSL_String llDetectedKey(int number)
1079 { 1039 {
1080 m_host.AddScriptLPS(1); 1040 m_host.AddScriptLPS(1);
1081 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1041 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1082 if (detectedParams == null) 1042 if (detectedParams == null)
1083 return String.Empty; 1043 return String.Empty;
1084 return detectedParams.Key.ToString(); 1044 return detectedParams.Key.ToString();
@@ -1087,7 +1047,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1087 public LSL_String llDetectedOwner(int number) 1047 public LSL_String llDetectedOwner(int number)
1088 { 1048 {
1089 m_host.AddScriptLPS(1); 1049 m_host.AddScriptLPS(1);
1090 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1050 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1091 if (detectedParams == null) 1051 if (detectedParams == null)
1092 return String.Empty; 1052 return String.Empty;
1093 return detectedParams.Owner.ToString(); 1053 return detectedParams.Owner.ToString();
@@ -1096,7 +1056,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1096 public LSL_Integer llDetectedType(int number) 1056 public LSL_Integer llDetectedType(int number)
1097 { 1057 {
1098 m_host.AddScriptLPS(1); 1058 m_host.AddScriptLPS(1);
1099 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1059 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1100 if (detectedParams == null) 1060 if (detectedParams == null)
1101 return 0; 1061 return 0;
1102 return new LSL_Integer(detectedParams.Type); 1062 return new LSL_Integer(detectedParams.Type);
@@ -1105,7 +1065,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1105 public LSL_Vector llDetectedPos(int number) 1065 public LSL_Vector llDetectedPos(int number)
1106 { 1066 {
1107 m_host.AddScriptLPS(1); 1067 m_host.AddScriptLPS(1);
1108 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1068 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1109 if (detectedParams == null) 1069 if (detectedParams == null)
1110 return new LSL_Vector(); 1070 return new LSL_Vector();
1111 return detectedParams.Position; 1071 return detectedParams.Position;
@@ -1114,7 +1074,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1114 public LSL_Vector llDetectedVel(int number) 1074 public LSL_Vector llDetectedVel(int number)
1115 { 1075 {
1116 m_host.AddScriptLPS(1); 1076 m_host.AddScriptLPS(1);
1117 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1077 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1118 if (detectedParams == null) 1078 if (detectedParams == null)
1119 return new LSL_Vector(); 1079 return new LSL_Vector();
1120 return detectedParams.Velocity; 1080 return detectedParams.Velocity;
@@ -1123,7 +1083,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1123 public LSL_Vector llDetectedGrab(int number) 1083 public LSL_Vector llDetectedGrab(int number)
1124 { 1084 {
1125 m_host.AddScriptLPS(1); 1085 m_host.AddScriptLPS(1);
1126 DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number); 1086 DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1127 if (parms == null) 1087 if (parms == null)
1128 return new LSL_Vector(0, 0, 0); 1088 return new LSL_Vector(0, 0, 0);
1129 1089
@@ -1133,7 +1093,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1133 public LSL_Rotation llDetectedRot(int number) 1093 public LSL_Rotation llDetectedRot(int number)
1134 { 1094 {
1135 m_host.AddScriptLPS(1); 1095 m_host.AddScriptLPS(1);
1136 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1096 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1137 if (detectedParams == null) 1097 if (detectedParams == null)
1138 return new LSL_Rotation(); 1098 return new LSL_Rotation();
1139 return detectedParams.Rotation; 1099 return detectedParams.Rotation;
@@ -1142,7 +1102,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1142 public LSL_Integer llDetectedGroup(int number) 1102 public LSL_Integer llDetectedGroup(int number)
1143 { 1103 {
1144 m_host.AddScriptLPS(1); 1104 m_host.AddScriptLPS(1);
1145 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number); 1105 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1146 if (detectedParams == null) 1106 if (detectedParams == null)
1147 return new LSL_Integer(0); 1107 return new LSL_Integer(0);
1148 if (m_host.GroupID == detectedParams.Group) 1108 if (m_host.GroupID == detectedParams.Group)
@@ -1153,7 +1113,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1153 public LSL_Integer llDetectedLinkNumber(int number) 1113 public LSL_Integer llDetectedLinkNumber(int number)
1154 { 1114 {
1155 m_host.AddScriptLPS(1); 1115 m_host.AddScriptLPS(1);
1156 DetectParams parms = m_ScriptEngine.GetDetectParams(m_itemID, number); 1116 DetectParams parms = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
1157 if (parms == null) 1117 if (parms == null)
1158 return new LSL_Integer(0); 1118 return new LSL_Integer(0);
1159 1119
@@ -1166,7 +1126,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1166 public LSL_Vector llDetectedTouchBinormal(int index) 1126 public LSL_Vector llDetectedTouchBinormal(int index)
1167 { 1127 {
1168 m_host.AddScriptLPS(1); 1128 m_host.AddScriptLPS(1);
1169 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1129 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1170 if (detectedParams == null) 1130 if (detectedParams == null)
1171 return new LSL_Vector(); 1131 return new LSL_Vector();
1172 return detectedParams.TouchBinormal; 1132 return detectedParams.TouchBinormal;
@@ -1178,7 +1138,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1178 public LSL_Integer llDetectedTouchFace(int index) 1138 public LSL_Integer llDetectedTouchFace(int index)
1179 { 1139 {
1180 m_host.AddScriptLPS(1); 1140 m_host.AddScriptLPS(1);
1181 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1141 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1182 if (detectedParams == null) 1142 if (detectedParams == null)
1183 return new LSL_Integer(-1); 1143 return new LSL_Integer(-1);
1184 return new LSL_Integer(detectedParams.TouchFace); 1144 return new LSL_Integer(detectedParams.TouchFace);
@@ -1190,7 +1150,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1190 public LSL_Vector llDetectedTouchNormal(int index) 1150 public LSL_Vector llDetectedTouchNormal(int index)
1191 { 1151 {
1192 m_host.AddScriptLPS(1); 1152 m_host.AddScriptLPS(1);
1193 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1153 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1194 if (detectedParams == null) 1154 if (detectedParams == null)
1195 return new LSL_Vector(); 1155 return new LSL_Vector();
1196 return detectedParams.TouchNormal; 1156 return detectedParams.TouchNormal;
@@ -1202,7 +1162,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1202 public LSL_Vector llDetectedTouchPos(int index) 1162 public LSL_Vector llDetectedTouchPos(int index)
1203 { 1163 {
1204 m_host.AddScriptLPS(1); 1164 m_host.AddScriptLPS(1);
1205 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1165 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1206 if (detectedParams == null) 1166 if (detectedParams == null)
1207 return new LSL_Vector(); 1167 return new LSL_Vector();
1208 return detectedParams.TouchPos; 1168 return detectedParams.TouchPos;
@@ -1214,7 +1174,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1214 public LSL_Vector llDetectedTouchST(int index) 1174 public LSL_Vector llDetectedTouchST(int index)
1215 { 1175 {
1216 m_host.AddScriptLPS(1); 1176 m_host.AddScriptLPS(1);
1217 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1177 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1218 if (detectedParams == null) 1178 if (detectedParams == null)
1219 return new LSL_Vector(-1.0, -1.0, 0.0); 1179 return new LSL_Vector(-1.0, -1.0, 0.0);
1220 return detectedParams.TouchST; 1180 return detectedParams.TouchST;
@@ -1226,7 +1186,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1226 public LSL_Vector llDetectedTouchUV(int index) 1186 public LSL_Vector llDetectedTouchUV(int index)
1227 { 1187 {
1228 m_host.AddScriptLPS(1); 1188 m_host.AddScriptLPS(1);
1229 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, index); 1189 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, index);
1230 if (detectedParams == null) 1190 if (detectedParams == null)
1231 return new LSL_Vector(-1.0, -1.0, 0.0); 1191 return new LSL_Vector(-1.0, -1.0, 0.0);
1232 return detectedParams.TouchUV; 1192 return detectedParams.TouchUV;
@@ -1929,12 +1889,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1929 1889
1930 return rgb; 1890 return rgb;
1931 } 1891 }
1892
1932 if (face >= 0 && face < GetNumberOfSides(part)) 1893 if (face >= 0 && face < GetNumberOfSides(part))
1933 { 1894 {
1934 texcolor = tex.GetFace((uint)face).RGBA; 1895 texcolor = tex.GetFace((uint)face).RGBA;
1935 rgb.x = texcolor.R; 1896 rgb.x = texcolor.R;
1936 rgb.y = texcolor.G; 1897 rgb.y = texcolor.G;
1937 rgb.z = texcolor.B; 1898 rgb.z = texcolor.B;
1899
1938 return rgb; 1900 return rgb;
1939 } 1901 }
1940 else 1902 else
@@ -2975,20 +2937,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2975 2937
2976 public LSL_Integer llGiveMoney(string destination, int amount) 2938 public LSL_Integer llGiveMoney(string destination, int amount)
2977 { 2939 {
2978 UUID invItemID=InventorySelf();
2979 if (invItemID == UUID.Zero)
2980 return 0;
2981
2982 m_host.AddScriptLPS(1); 2940 m_host.AddScriptLPS(1);
2983 2941
2984 m_host.TaskInventory.LockItemsForRead(true); 2942 if (m_item.PermsGranter == UUID.Zero)
2985 TaskInventoryItem item = m_host.TaskInventory[invItemID];
2986 m_host.TaskInventory.LockItemsForRead(false);
2987
2988 if (item.PermsGranter == UUID.Zero)
2989 return 0; 2943 return 0;
2990 2944
2991 if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0) 2945 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
2992 { 2946 {
2993 LSLError("No permissions to give money"); 2947 LSLError("No permissions to give money");
2994 return 0; 2948 return 0;
@@ -3176,11 +3130,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3176 sec = m_MinTimerInterval; 3130 sec = m_MinTimerInterval;
3177 m_host.AddScriptLPS(1); 3131 m_host.AddScriptLPS(1);
3178 // Setting timer repeat 3132 // Setting timer repeat
3179 AsyncCommands.TimerPlugin.SetTimerEvent(m_localID, m_itemID, sec); 3133 AsyncCommands.TimerPlugin.SetTimerEvent(m_host.LocalId, m_item.ItemID, sec);
3180 } 3134 }
3181 3135
3182 public virtual void llSleep(double sec) 3136 public virtual void llSleep(double sec)
3183 { 3137 {
3138// m_log.Info("llSleep snoozing " + sec + "s.");
3184 m_host.AddScriptLPS(1); 3139 m_host.AddScriptLPS(1);
3185 Thread.Sleep((int)(sec * 1000)); 3140 Thread.Sleep((int)(sec * 1000));
3186 } 3141 }
@@ -3239,29 +3194,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3239 3194
3240 public void llTakeControls(int controls, int accept, int pass_on) 3195 public void llTakeControls(int controls, int accept, int pass_on)
3241 { 3196 {
3242 TaskInventoryItem item; 3197 if (m_item.PermsGranter != UUID.Zero)
3243
3244 m_host.TaskInventory.LockItemsForRead(true);
3245 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3246 {
3247 m_host.TaskInventory.LockItemsForRead(false);
3248 return;
3249 }
3250 else
3251 { 3198 {
3252 item = m_host.TaskInventory[InventorySelf()]; 3199 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3253 }
3254 m_host.TaskInventory.LockItemsForRead(false);
3255
3256 if (item.PermsGranter != UUID.Zero)
3257 {
3258 ScenePresence presence = World.GetScenePresence(item.PermsGranter);
3259 3200
3260 if (presence != null) 3201 if (presence != null)
3261 { 3202 {
3262 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 3203 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
3263 { 3204 {
3264 presence.RegisterControlEventsToScript(controls, accept, pass_on, m_localID, m_itemID); 3205 presence.RegisterControlEventsToScript(controls, accept, pass_on, m_host.LocalId, m_item.ItemID);
3265 } 3206 }
3266 } 3207 }
3267 } 3208 }
@@ -3271,38 +3212,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3271 3212
3272 public void llReleaseControls() 3213 public void llReleaseControls()
3273 { 3214 {
3274 TaskInventoryItem item;
3275
3276 m_host.TaskInventory.LockItemsForRead(true);
3277 lock (m_host.TaskInventory)
3278 {
3279
3280 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3281 {
3282 m_host.TaskInventory.LockItemsForRead(false);
3283 return;
3284 }
3285 else
3286 {
3287 item = m_host.TaskInventory[InventorySelf()];
3288 }
3289 }
3290 m_host.TaskInventory.LockItemsForRead(false);
3291
3292 m_host.AddScriptLPS(1); 3215 m_host.AddScriptLPS(1);
3293 3216
3294 if (item.PermsGranter != UUID.Zero) 3217 if (m_item.PermsGranter != UUID.Zero)
3295 { 3218 {
3296 ScenePresence presence = World.GetScenePresence(item.PermsGranter); 3219 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3297 3220
3298 if (presence != null) 3221 if (presence != null)
3299 { 3222 {
3300 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 3223 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
3301 { 3224 {
3302 // Unregister controls from Presence 3225 // Unregister controls from Presence
3303 presence.UnRegisterControlEventsToScript(m_localID, m_itemID); 3226 presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
3304 // Remove Take Control permission. 3227 // Remove Take Control permission.
3305 item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS; 3228 m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
3306 } 3229 }
3307 } 3230 }
3308 } 3231 }
@@ -3315,86 +3238,71 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3315 m_UrlModule.ReleaseURL(url); 3238 m_UrlModule.ReleaseURL(url);
3316 } 3239 }
3317 3240
3318 public void llAttachToAvatar(int attachment) 3241 /// <summary>
3242 /// Attach the object containing this script to the avatar that owns it.
3243 /// </summary>
3244 /// <param name='attachment'>The attachment point (e.g. ATTACH_CHEST)</param>
3245 /// <returns>true if the attach suceeded, false if it did not</returns>
3246 public bool AttachToAvatar(int attachmentPoint)
3319 { 3247 {
3320 m_host.AddScriptLPS(1); 3248 SceneObjectGroup grp = m_host.ParentGroup;
3321 3249 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
3322 TaskInventoryItem item;
3323 3250
3324 m_host.TaskInventory.LockItemsForRead(true); 3251 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3325 3252
3326 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3253 if (attachmentsModule != null)
3327 { 3254 return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true);
3328 m_host.TaskInventory.LockItemsForRead(false);
3329 return;
3330 }
3331 else 3255 else
3332 { 3256 return false;
3333 item = m_host.TaskInventory[InventorySelf()]; 3257 }
3334 }
3335
3336 m_host.TaskInventory.LockItemsForRead(false);
3337 3258
3338 if (item.PermsGranter != m_host.OwnerID) 3259 /// <summary>
3339 return; 3260 /// Detach the object containing this script from the avatar it is attached to.
3261 /// </summary>
3262 /// <remarks>
3263 /// Nothing happens if the object is not attached.
3264 /// </remarks>
3265 public void DetachFromAvatar()
3266 {
3267 Util.FireAndForget(DetachWrapper, m_host);
3268 }
3340 3269
3341 if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0) 3270 private void DetachWrapper(object o)
3342 { 3271 {
3343 SceneObjectGroup grp = m_host.ParentGroup; 3272 SceneObjectPart host = (SceneObjectPart)o;
3344 3273
3345 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 3274 SceneObjectGroup grp = host.ParentGroup;
3275 UUID itemID = grp.FromItemID;
3276 ScenePresence presence = World.GetScenePresence(host.OwnerID);
3346 3277
3347 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; 3278 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3348 if (attachmentsModule != null) 3279 if (attachmentsModule != null)
3349 attachmentsModule.AttachObject(presence, grp, (uint)attachment, false, true); 3280 attachmentsModule.DetachSingleAttachmentToInv(presence, itemID);
3350 }
3351 } 3281 }
3352 3282
3353 public void llDetachFromAvatar() 3283 public void llAttachToAvatar(int attachmentPoint)
3354 { 3284 {
3355 m_host.AddScriptLPS(1); 3285 m_host.AddScriptLPS(1);
3356 3286
3357 if (m_host.ParentGroup.AttachmentPoint == 0) 3287 if (m_item.PermsGranter != m_host.OwnerID)
3358 return; 3288 return;
3359 3289
3360 TaskInventoryItem item; 3290 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
3291 AttachToAvatar(attachmentPoint);
3292 }
3361 3293
3362 m_host.TaskInventory.LockItemsForRead(true); 3294 public void llDetachFromAvatar()
3295 {
3296 m_host.AddScriptLPS(1);
3363 3297
3364 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3298 if (m_host.ParentGroup.AttachmentPoint == 0)
3365 {
3366 m_host.TaskInventory.LockItemsForRead(false);
3367 return; 3299 return;
3368 }
3369 else
3370 {
3371 item = m_host.TaskInventory[InventorySelf()];
3372 }
3373 m_host.TaskInventory.LockItemsForRead(false);
3374 3300
3375 3301 if (m_item.PermsGranter != m_host.OwnerID)
3376 if (item.PermsGranter != m_host.OwnerID)
3377 return; 3302 return;
3378 3303
3379 if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0) 3304 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
3380 { 3305 DetachFromAvatar();
3381 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3382 if (attachmentsModule != null)
3383 Util.FireAndForget(DetachWrapper, m_host);
3384 }
3385 }
3386
3387 private void DetachWrapper(object o)
3388 {
3389 SceneObjectPart host = (SceneObjectPart)o;
3390
3391 SceneObjectGroup grp = host.ParentGroup;
3392 UUID itemID = grp.FromItemID;
3393 ScenePresence presence = World.GetScenePresence(host.OwnerID);
3394
3395 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3396 if (attachmentsModule != null)
3397 attachmentsModule.DetachSingleAttachmentToInv(presence, itemID);
3398 } 3306 }
3399 3307
3400 public void llTakeCamera(string avatar) 3308 public void llTakeCamera(string avatar)
@@ -3515,7 +3423,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3515 } 3423 }
3516 3424
3517 emailModule.SendEmail(m_host.UUID, address, subject, message); 3425 emailModule.SendEmail(m_host.UUID, address, subject, message);
3518 ScriptSleep(15000); 3426 ScriptSleep(EMAIL_PAUSE_TIME * 1000);
3519 } 3427 }
3520 3428
3521 public void llGetNextEmail(string address, string subject) 3429 public void llGetNextEmail(string address, string subject)
@@ -3552,6 +3460,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3552 return m_host.UUID.ToString(); 3460 return m_host.UUID.ToString();
3553 } 3461 }
3554 3462
3463 public LSL_Key llGenerateKey()
3464 {
3465 m_host.AddScriptLPS(1);
3466 return UUID.Random().ToString();
3467 }
3468
3555 public void llSetBuoyancy(double buoyancy) 3469 public void llSetBuoyancy(double buoyancy)
3556 { 3470 {
3557 m_host.AddScriptLPS(1); 3471 m_host.AddScriptLPS(1);
@@ -3598,7 +3512,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3598 m_host.AddScriptLPS(1); 3512 m_host.AddScriptLPS(1);
3599 try 3513 try
3600 { 3514 {
3601 m_ScriptEngine.SetMinEventDelay(m_itemID, delay); 3515 m_ScriptEngine.SetMinEventDelay(m_item.ItemID, delay);
3602 } 3516 }
3603 catch (NotImplementedException) 3517 catch (NotImplementedException)
3604 { 3518 {
@@ -3651,29 +3565,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3651 { 3565 {
3652 m_host.AddScriptLPS(1); 3566 m_host.AddScriptLPS(1);
3653 3567
3654 UUID invItemID = InventorySelf(); 3568 if (m_item.PermsGranter == UUID.Zero)
3655 if (invItemID == UUID.Zero)
3656 return;
3657
3658 TaskInventoryItem item;
3659
3660 m_host.TaskInventory.LockItemsForRead(true);
3661 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3662 {
3663 m_host.TaskInventory.LockItemsForRead(false);
3664 return;
3665 }
3666 else
3667 {
3668 item = m_host.TaskInventory[InventorySelf()];
3669 }
3670 m_host.TaskInventory.LockItemsForRead(false);
3671 if (item.PermsGranter == UUID.Zero)
3672 return; 3569 return;
3673 3570
3674 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0) 3571 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3675 { 3572 {
3676 ScenePresence presence = World.GetScenePresence(item.PermsGranter); 3573 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
3677 3574
3678 if (presence != null) 3575 if (presence != null)
3679 { 3576 {
@@ -3691,41 +3588,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3691 { 3588 {
3692 m_host.AddScriptLPS(1); 3589 m_host.AddScriptLPS(1);
3693 3590
3694 UUID invItemID=InventorySelf(); 3591 if (m_item.PermsGranter == UUID.Zero)
3695 if (invItemID == UUID.Zero)
3696 return; 3592 return;
3697 3593
3698 TaskInventoryItem item; 3594 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3699
3700 m_host.TaskInventory.LockItemsForRead(true);
3701 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3702 {
3703 m_host.TaskInventory.LockItemsForRead(false);
3704 return;
3705 }
3706 else
3707 {
3708 item = m_host.TaskInventory[InventorySelf()];
3709 }
3710 m_host.TaskInventory.LockItemsForRead(false);
3711
3712
3713 if (item.PermsGranter == UUID.Zero)
3714 return;
3715
3716 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
3717 { 3595 {
3718 UUID animID = new UUID(); 3596 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 3597
3727 if (presence != null) 3598 if (presence != null)
3728 { 3599 {
3600 UUID animID = KeyOrName(anim);
3601
3729 if (animID == UUID.Zero) 3602 if (animID == UUID.Zero)
3730 presence.Animator.RemoveAnimation(anim); 3603 presence.Animator.RemoveAnimation(anim);
3731 else 3604 else
@@ -3758,44 +3631,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3758 public LSL_Integer llGetStartParameter() 3631 public LSL_Integer llGetStartParameter()
3759 { 3632 {
3760 m_host.AddScriptLPS(1); 3633 m_host.AddScriptLPS(1);
3761 return m_ScriptEngine.GetStartParameter(m_itemID); 3634 return m_ScriptEngine.GetStartParameter(m_item.ItemID);
3762 } 3635 }
3763 3636
3764 public void llRequestPermissions(string agent, int perm) 3637 public void llRequestPermissions(string agent, int perm)
3765 { 3638 {
3766 UUID agentID = new UUID(); 3639 UUID agentID;
3767 3640
3768 if (!UUID.TryParse(agent, out agentID)) 3641 if (!UUID.TryParse(agent, out agentID))
3769 return; 3642 return;
3770 3643
3771 UUID invItemID = InventorySelf();
3772
3773 if (invItemID == UUID.Zero)
3774 return; // Not in a prim? How??
3775
3776 TaskInventoryItem item;
3777
3778
3779 m_host.TaskInventory.LockItemsForRead(true);
3780 if (!m_host.TaskInventory.ContainsKey(invItemID))
3781 {
3782 m_host.TaskInventory.LockItemsForRead(false);
3783 return;
3784 }
3785 else
3786 {
3787 item = m_host.TaskInventory[invItemID];
3788 }
3789 m_host.TaskInventory.LockItemsForRead(false);
3790
3791 if (agentID == UUID.Zero || perm == 0) // Releasing permissions 3644 if (agentID == UUID.Zero || perm == 0) // Releasing permissions
3792 { 3645 {
3793 llReleaseControls(); 3646 llReleaseControls();
3794 3647
3795 item.PermsGranter = UUID.Zero; 3648 m_item.PermsGranter = UUID.Zero;
3796 item.PermsMask = 0; 3649 m_item.PermsMask = 0;
3797 3650
3798 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3651 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3799 "run_time_permissions", new Object[] { 3652 "run_time_permissions", new Object[] {
3800 new LSL_Integer(0) }, 3653 new LSL_Integer(0) },
3801 new DetectParams[0])); 3654 new DetectParams[0]));
@@ -3803,7 +3656,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3803 return; 3656 return;
3804 } 3657 }
3805 3658
3806 if (item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3659 if (m_item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3807 llReleaseControls(); 3660 llReleaseControls();
3808 3661
3809 m_host.AddScriptLPS(1); 3662 m_host.AddScriptLPS(1);
@@ -3820,11 +3673,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3820 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3673 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3821 { 3674 {
3822 m_host.TaskInventory.LockItemsForWrite(true); 3675 m_host.TaskInventory.LockItemsForWrite(true);
3823 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3676 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3824 m_host.TaskInventory[invItemID].PermsMask = perm; 3677 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3825 m_host.TaskInventory.LockItemsForWrite(false); 3678 m_host.TaskInventory.LockItemsForWrite(false);
3826 3679
3827 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3680 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3828 "run_time_permissions", new Object[] { 3681 "run_time_permissions", new Object[] {
3829 new LSL_Integer(perm) }, 3682 new LSL_Integer(perm) },
3830 new DetectParams[0])); 3683 new DetectParams[0]));
@@ -3859,11 +3712,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3859 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3712 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3860 { 3713 {
3861 m_host.TaskInventory.LockItemsForWrite(true); 3714 m_host.TaskInventory.LockItemsForWrite(true);
3862 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3715 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3863 m_host.TaskInventory[invItemID].PermsMask = perm; 3716 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3864 m_host.TaskInventory.LockItemsForWrite(false); 3717 m_host.TaskInventory.LockItemsForWrite(false);
3865 3718
3866 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3719 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3867 "run_time_permissions", new Object[] { 3720 "run_time_permissions", new Object[] {
3868 new LSL_Integer(perm) }, 3721 new LSL_Integer(perm) },
3869 new DetectParams[0])); 3722 new DetectParams[0]));
@@ -3874,9 +3727,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3874 } 3727 }
3875 3728
3876 ScenePresence presence = World.GetScenePresence(agentID); 3729 ScenePresence presence = World.GetScenePresence(agentID);
3877
3878 if (presence != null) 3730 if (presence != null)
3879 { 3731 {
3732 // If permissions are being requested from an NPC and were not implicitly granted above then
3733 // auto grant all reuqested permissions if the script is owned by the NPC or the NPCs owner
3734 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
3735 if (npcModule != null && npcModule.IsNPC(agentID, World))
3736 {
3737 if (agentID == m_host.ParentGroup.OwnerID || npcModule.GetOwner(agentID) == m_host.ParentGroup.OwnerID)
3738 {
3739 lock (m_host.TaskInventory)
3740 {
3741 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3742 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3743 }
3744
3745 m_ScriptEngine.PostScriptEvent(
3746 m_item.ItemID,
3747 new EventParams(
3748 "run_time_permissions", new Object[] { new LSL_Integer(perm) }, new DetectParams[0]));
3749 }
3750
3751 // it is an NPC, exit even if the permissions werent granted above, they are not going to answer
3752 // the question!
3753 return;
3754 }
3755
3880 string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID); 3756 string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
3881 if (ownerName == String.Empty) 3757 if (ownerName == String.Empty)
3882 ownerName = "(hippos)"; 3758 ownerName = "(hippos)";
@@ -3884,8 +3760,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3884 if (!m_waitingForScriptAnswer) 3760 if (!m_waitingForScriptAnswer)
3885 { 3761 {
3886 m_host.TaskInventory.LockItemsForWrite(true); 3762 m_host.TaskInventory.LockItemsForWrite(true);
3887 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3763 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3888 m_host.TaskInventory[invItemID].PermsMask = 0; 3764 m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
3889 m_host.TaskInventory.LockItemsForWrite(false); 3765 m_host.TaskInventory.LockItemsForWrite(false);
3890 3766
3891 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 3767 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
@@ -3893,16 +3769,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3893 } 3769 }
3894 3770
3895 presence.ControllingClient.SendScriptQuestion( 3771 presence.ControllingClient.SendScriptQuestion(
3896 m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, invItemID, perm); 3772 m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_item.ItemID, perm);
3897 3773
3898 return; 3774 return;
3899 } 3775 }
3900 3776
3901 // Requested agent is not in range, refuse perms 3777 // Requested agent is not in range, refuse perms
3902 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3778 m_ScriptEngine.PostScriptEvent(
3903 "run_time_permissions", new Object[] { 3779 m_item.ItemID,
3904 new LSL_Integer(0) }, 3780 new EventParams("run_time_permissions", new Object[] { new LSL_Integer(0) }, new DetectParams[0]));
3905 new DetectParams[0]));
3906 } 3781 }
3907 3782
3908 void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer) 3783 void handleScriptAnswer(IClientAPI client, UUID taskID, UUID itemID, int answer)
@@ -3910,24 +3785,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3910 if (taskID != m_host.UUID) 3785 if (taskID != m_host.UUID)
3911 return; 3786 return;
3912 3787
3913 UUID invItemID = InventorySelf(); 3788 client.OnScriptAnswer -= handleScriptAnswer;
3914 3789 m_waitingForScriptAnswer = false;
3915 if (invItemID == UUID.Zero)
3916 return;
3917
3918 client.OnScriptAnswer-=handleScriptAnswer;
3919 m_waitingForScriptAnswer=false;
3920 3790
3921 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3791 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3922 llReleaseControls(); 3792 llReleaseControls();
3923 3793
3924
3925 m_host.TaskInventory.LockItemsForWrite(true); 3794 m_host.TaskInventory.LockItemsForWrite(true);
3926 m_host.TaskInventory[invItemID].PermsMask = answer; 3795 m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
3927 m_host.TaskInventory.LockItemsForWrite(false); 3796 m_host.TaskInventory.LockItemsForWrite(false);
3928 3797
3929 3798 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3930 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3931 "run_time_permissions", new Object[] { 3799 "run_time_permissions", new Object[] {
3932 new LSL_Integer(answer) }, 3800 new LSL_Integer(answer) },
3933 new DetectParams[0])); 3801 new DetectParams[0]));
@@ -3937,41 +3805,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3937 { 3805 {
3938 m_host.AddScriptLPS(1); 3806 m_host.AddScriptLPS(1);
3939 3807
3940 m_host.TaskInventory.LockItemsForRead(true); 3808 return m_item.PermsGranter.ToString();
3941
3942 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3943 {
3944 if (item.Type == 10 && item.ItemID == m_itemID)
3945 {
3946 m_host.TaskInventory.LockItemsForRead(false);
3947 return item.PermsGranter.ToString();
3948 }
3949 }
3950 m_host.TaskInventory.LockItemsForRead(false);
3951
3952 return UUID.Zero.ToString();
3953 } 3809 }
3954 3810
3955 public LSL_Integer llGetPermissions() 3811 public LSL_Integer llGetPermissions()
3956 { 3812 {
3957 m_host.AddScriptLPS(1); 3813 m_host.AddScriptLPS(1);
3958 3814
3959 m_host.TaskInventory.LockItemsForRead(true); 3815 int perms = m_item.PermsMask;
3960 3816
3961 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3817 if (m_automaticLinkPermission)
3962 { 3818 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3963 if (item.Type == 10 && item.ItemID == m_itemID)
3964 {
3965 int perms = item.PermsMask;
3966 if (m_automaticLinkPermission)
3967 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3968 m_host.TaskInventory.LockItemsForRead(false);
3969 return perms;
3970 }
3971 }
3972 m_host.TaskInventory.LockItemsForRead(false);
3973 3819
3974 return 0; 3820 return perms;
3975 } 3821 }
3976 3822
3977 public LSL_Integer llGetLinkNumber() 3823 public LSL_Integer llGetLinkNumber()
@@ -4009,18 +3855,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4009 public void llCreateLink(string target, int parent) 3855 public void llCreateLink(string target, int parent)
4010 { 3856 {
4011 m_host.AddScriptLPS(1); 3857 m_host.AddScriptLPS(1);
4012 UUID invItemID = InventorySelf(); 3858
4013 UUID targetID; 3859 UUID targetID;
4014 3860
4015 if (!UUID.TryParse(target, out targetID)) 3861 if (!UUID.TryParse(target, out targetID))
4016 return; 3862 return;
4017 3863
4018 TaskInventoryItem item; 3864 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4019 m_host.TaskInventory.LockItemsForRead(true);
4020 item = m_host.TaskInventory[invItemID];
4021 m_host.TaskInventory.LockItemsForRead(false);
4022
4023 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4024 && !m_automaticLinkPermission) 3865 && !m_automaticLinkPermission)
4025 { 3866 {
4026 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3867 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
@@ -4028,7 +3869,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4028 } 3869 }
4029 3870
4030 IClientAPI client = null; 3871 IClientAPI client = null;
4031 ScenePresence sp = World.GetScenePresence(item.PermsGranter); 3872 ScenePresence sp = World.GetScenePresence(m_item.PermsGranter);
4032 if (sp != null) 3873 if (sp != null)
4033 client = sp.ControllingClient; 3874 client = sp.ControllingClient;
4034 3875
@@ -4074,18 +3915,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4074 public void llBreakLink(int linknum) 3915 public void llBreakLink(int linknum)
4075 { 3916 {
4076 m_host.AddScriptLPS(1); 3917 m_host.AddScriptLPS(1);
4077 UUID invItemID = InventorySelf();
4078 3918
4079 m_host.TaskInventory.LockItemsForRead(true); 3919 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4080 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3920 && !m_automaticLinkPermission)
4081 && !m_automaticLinkPermission) 3921 {
4082 { 3922 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
4083 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3923 return;
4084 m_host.TaskInventory.LockItemsForRead(false); 3924 }
4085 return; 3925
4086 }
4087 m_host.TaskInventory.LockItemsForRead(false);
4088
4089 if (linknum < ScriptBaseClass.LINK_THIS) 3926 if (linknum < ScriptBaseClass.LINK_THIS)
4090 return; 3927 return;
4091 3928
@@ -4184,12 +4021,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4184 { 4021 {
4185 m_host.AddScriptLPS(1); 4022 m_host.AddScriptLPS(1);
4186 4023
4187 UUID invItemID = InventorySelf(); 4024 TaskInventoryItem item = m_item;
4188
4189 TaskInventoryItem item;
4190 m_host.TaskInventory.LockItemsForRead(true);
4191 item = m_host.TaskInventory[invItemID];
4192 m_host.TaskInventory.LockItemsForRead(false);
4193 4025
4194 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 4026 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4195 && !m_automaticLinkPermission) 4027 && !m_automaticLinkPermission)
@@ -4500,7 +4332,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4500 { 4332 {
4501 if (item.Name == name) 4333 if (item.Name == name)
4502 { 4334 {
4503 if (item.ItemID == m_itemID) 4335 if (item.ItemID == m_item.ItemID)
4504 throw new ScriptDeleteException(); 4336 throw new ScriptDeleteException();
4505 else 4337 else
4506 m_host.Inventory.RemoveInventoryItem(item.ItemID); 4338 m_host.Inventory.RemoveInventoryItem(item.ItemID);
@@ -4634,8 +4466,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4634 UUID rq = UUID.Random(); 4466 UUID rq = UUID.Random();
4635 4467
4636 UUID tid = AsyncCommands. 4468 UUID tid = AsyncCommands.
4637 DataserverPlugin.RegisterRequest(m_localID, 4469 DataserverPlugin.RegisterRequest(m_host.LocalId,
4638 m_itemID, rq.ToString()); 4470 m_item.ItemID, rq.ToString());
4639 4471
4640 AsyncCommands. 4472 AsyncCommands.
4641 DataserverPlugin.DataserverReply(rq.ToString(), reply); 4473 DataserverPlugin.DataserverReply(rq.ToString(), reply);
@@ -4662,8 +4494,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4662 if (item.Type == 3 && item.Name == name) 4494 if (item.Type == 3 && item.Name == name)
4663 { 4495 {
4664 UUID tid = AsyncCommands. 4496 UUID tid = AsyncCommands.
4665 DataserverPlugin.RegisterRequest(m_localID, 4497 DataserverPlugin.RegisterRequest(m_host.LocalId,
4666 m_itemID, item.AssetID.ToString()); 4498 m_item.ItemID, item.AssetID.ToString());
4667 4499
4668 Vector3 region = new Vector3( 4500 Vector3 region = new Vector3(
4669 World.RegionInfo.RegionLocX * Constants.RegionSize, 4501 World.RegionInfo.RegionLocX * Constants.RegionSize,
@@ -5136,22 +4968,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5136 4968
5137 public LSL_String llGetScriptName() 4969 public LSL_String llGetScriptName()
5138 { 4970 {
5139 string result = String.Empty;
5140
5141 m_host.AddScriptLPS(1); 4971 m_host.AddScriptLPS(1);
5142 4972
5143 m_host.TaskInventory.LockItemsForRead(true); 4973 return m_item.Name != null ? m_item.Name : String.Empty;
5144 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
5145 {
5146 if (item.Type == 10 && item.ItemID == m_itemID)
5147 {
5148 result = item.Name!=null?item.Name:String.Empty;
5149 break;
5150 }
5151 }
5152 m_host.TaskInventory.LockItemsForRead(false);
5153
5154 return result;
5155 } 4974 }
5156 4975
5157 public LSL_Integer llGetLinkNumberOfSides(int link) 4976 public LSL_Integer llGetLinkNumberOfSides(int link)
@@ -6285,7 +6104,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6285 } 6104 }
6286 } 6105 }
6287 } 6106 }
6288 List<UUID> presenceIds = new List<UUID>();
6289 6107
6290 World.ForEachRootScenePresence( 6108 World.ForEachRootScenePresence(
6291 delegate (ScenePresence ssp) 6109 delegate (ScenePresence ssp)
@@ -6436,7 +6254,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6436 if (m_host.OwnerID == land.LandData.OwnerID) 6254 if (m_host.OwnerID == land.LandData.OwnerID)
6437 { 6255 {
6438 Vector3 pos = World.GetNearestAllowedPosition(presence, land); 6256 Vector3 pos = World.GetNearestAllowedPosition(presence, land);
6439 presence.TeleportWithMomentum(pos); 6257 presence.TeleportWithMomentum(pos, null);
6440 presence.ControllingClient.SendAlertMessage("You have been ejected from this land"); 6258 presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
6441 } 6259 }
6442 } 6260 }
@@ -7383,14 +7201,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7383 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); 7201 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
7384 if (xmlrpcMod.IsEnabled()) 7202 if (xmlrpcMod.IsEnabled())
7385 { 7203 {
7386 UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_localID, m_itemID, UUID.Zero); 7204 UUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_host.LocalId, m_item.ItemID, UUID.Zero);
7387 IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>(); 7205 IXmlRpcRouter xmlRpcRouter = m_ScriptEngine.World.RequestModuleInterface<IXmlRpcRouter>();
7388 if (xmlRpcRouter != null) 7206 if (xmlRpcRouter != null)
7389 { 7207 {
7390 string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName; 7208 string ExternalHostName = m_ScriptEngine.World.RegionInfo.ExternalHostName;
7391 7209
7392 xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID, 7210 xmlRpcRouter.RegisterNewReceiver(m_ScriptEngine.ScriptModule, channelID, m_host.UUID,
7393 m_itemID, String.Format("http://{0}:{1}/", ExternalHostName, 7211 m_item.ItemID, String.Format("http://{0}:{1}/", ExternalHostName,
7394 xmlrpcMod.Port.ToString())); 7212 xmlrpcMod.Port.ToString()));
7395 } 7213 }
7396 object[] resobj = new object[] 7214 object[] resobj = new object[]
@@ -7402,7 +7220,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7402 new LSL_Integer(0), 7220 new LSL_Integer(0),
7403 new LSL_String(String.Empty) 7221 new LSL_String(String.Empty)
7404 }; 7222 };
7405 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams("remote_data", resobj, 7223 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams("remote_data", resobj,
7406 new DetectParams[0])); 7224 new DetectParams[0]));
7407 } 7225 }
7408 ScriptSleep(1000); 7226 ScriptSleep(1000);
@@ -7413,7 +7231,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7413 m_host.AddScriptLPS(1); 7231 m_host.AddScriptLPS(1);
7414 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>(); 7232 IXMLRPC xmlrpcMod = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
7415 ScriptSleep(3000); 7233 ScriptSleep(3000);
7416 return (xmlrpcMod.SendRemoteData(m_localID, m_itemID, channel, dest, idata, sdata)).ToString(); 7234 return (xmlrpcMod.SendRemoteData(m_host.LocalId, m_item.ItemID, channel, dest, idata, sdata)).ToString();
7417 } 7235 }
7418 7236
7419 public void llRemoteDataReply(string channel, string message_id, string sdata, int idata) 7237 public void llRemoteDataReply(string channel, string message_id, string sdata, int idata)
@@ -8413,7 +8231,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8413 return; 8231 return;
8414 face = (int)rules.GetLSLIntegerItem(idx++); 8232 face = (int)rules.GetLSLIntegerItem(idx++);
8415 int shiny = (int)rules.GetLSLIntegerItem(idx++); 8233 int shiny = (int)rules.GetLSLIntegerItem(idx++);
8416 Bumpiness bump = (Bumpiness)Convert.ToByte((int)rules.GetLSLIntegerItem(idx++)); 8234 Bumpiness bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);
8417 8235
8418 SetShiny(part, face, shiny, bump); 8236 SetShiny(part, face, shiny, bump);
8419 8237
@@ -10173,7 +9991,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10173 public LSL_String llGetSimulatorHostname() 9991 public LSL_String llGetSimulatorHostname()
10174 { 9992 {
10175 m_host.AddScriptLPS(1); 9993 m_host.AddScriptLPS(1);
10176 return System.Environment.MachineName; 9994 IUrlModule UrlModule = World.RequestModuleInterface<IUrlModule>();
9995 return UrlModule.ExternalHostNameForLSL;
10177 } 9996 }
10178 9997
10179 // <summary> 9998 // <summary>
@@ -10512,13 +10331,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10512 { 10331 {
10513 m_host.AddScriptLPS(1); 10332 m_host.AddScriptLPS(1);
10514 if (m_UrlModule != null) 10333 if (m_UrlModule != null)
10515 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString(); 10334 return m_UrlModule.RequestSecureURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
10516 return UUID.Zero.ToString(); 10335 return UUID.Zero.ToString();
10517 } 10336 }
10518 10337
10519 public LSL_String llRequestSimulatorData(string simulator, int data) 10338 public LSL_String llRequestSimulatorData(string simulator, int data)
10520 { 10339 {
10521 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_itemID, "OSSL"); 10340 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL");
10522 10341
10523 try 10342 try
10524 { 10343 {
@@ -10528,7 +10347,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10528 10347
10529 GridRegion info; 10348 GridRegion info;
10530 10349
10531 if (m_ScriptEngine.World.RegionInfo.RegionName == simulator) 10350 if (m_ScriptEngine.World.RegionInfo.RegionName == simulator) //Det data for this simulator?
10351
10532 info = new GridRegion(m_ScriptEngine.World.RegionInfo); 10352 info = new GridRegion(m_ScriptEngine.World.RegionInfo);
10533 else 10353 else
10534 info = m_ScriptEngine.World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator); 10354 info = m_ScriptEngine.World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator);
@@ -10541,10 +10361,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10541 ScriptSleep(1000); 10361 ScriptSleep(1000);
10542 return UUID.Zero.ToString(); 10362 return UUID.Zero.ToString();
10543 } 10363 }
10544 reply = new LSL_Vector( 10364 if (m_ScriptEngine.World.RegionInfo.RegionName != simulator)
10545 info.RegionLocX, 10365 {
10546 info.RegionLocY, 10366 //Hypergrid Region co-ordinates
10547 0).ToString(); 10367 uint rx = 0, ry = 0;
10368 Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out rx, out ry);
10369
10370 reply = new LSL_Vector(
10371 rx,
10372 ry,
10373 0).ToString();
10374 }
10375 else
10376 {
10377 //Local-cooridnates
10378 reply = new LSL_Vector(
10379 info.RegionLocX,
10380 info.RegionLocY,
10381 0).ToString();
10382 }
10548 break; 10383 break;
10549 case ScriptBaseClass.DATA_SIM_STATUS: 10384 case ScriptBaseClass.DATA_SIM_STATUS:
10550 if (info != null) 10385 if (info != null)
@@ -10580,7 +10415,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10580 UUID rq = UUID.Random(); 10415 UUID rq = UUID.Random();
10581 10416
10582 UUID tid = AsyncCommands. 10417 UUID tid = AsyncCommands.
10583 DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 10418 DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
10584 10419
10585 AsyncCommands. 10420 AsyncCommands.
10586 DataserverPlugin.DataserverReply(rq.ToString(), reply); 10421 DataserverPlugin.DataserverReply(rq.ToString(), reply);
@@ -10599,7 +10434,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10599 m_host.AddScriptLPS(1); 10434 m_host.AddScriptLPS(1);
10600 10435
10601 if (m_UrlModule != null) 10436 if (m_UrlModule != null)
10602 return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_itemID).ToString(); 10437 return m_UrlModule.RequestURL(m_ScriptEngine.ScriptModule, m_host, m_item.ItemID).ToString();
10603 return UUID.Zero.ToString(); 10438 return UUID.Zero.ToString();
10604 } 10439 }
10605 10440
@@ -10635,7 +10470,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10635 // child agents have a mass of 1.0 10470 // child agents have a mass of 1.0
10636 return 1; 10471 return 1;
10637 else 10472 else
10638 return avatar.GetMass(); 10473 return (double)avatar.GetMass();
10639 } 10474 }
10640 catch (KeyNotFoundException) 10475 catch (KeyNotFoundException)
10641 { 10476 {
@@ -11078,32 +10913,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11078 public LSL_Vector llGetCameraPos() 10913 public LSL_Vector llGetCameraPos()
11079 { 10914 {
11080 m_host.AddScriptLPS(1); 10915 m_host.AddScriptLPS(1);
11081 UUID invItemID = InventorySelf();
11082 10916
11083 if (invItemID == UUID.Zero) 10917 if (m_item.PermsGranter == UUID.Zero)
11084 return new LSL_Vector(); 10918 return new LSL_Vector();
11085 10919
11086 m_host.TaskInventory.LockItemsForRead(true); 10920 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 { 10921 {
11099 ShoutError("No permissions to track the camera"); 10922 ShoutError("No permissions to track the camera");
11100 m_host.TaskInventory.LockItemsForRead(false);
11101 return new LSL_Vector(); 10923 return new LSL_Vector();
11102 } 10924 }
11103 m_host.TaskInventory.LockItemsForRead(false);
11104 10925
11105// ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10926// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
11106 ScenePresence presence = World.GetScenePresence(agentID); 10927 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
11107 if (presence != null) 10928 if (presence != null)
11108 { 10929 {
11109 LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z); 10930 LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z);
@@ -11115,30 +10936,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11115 public LSL_Rotation llGetCameraRot() 10936 public LSL_Rotation llGetCameraRot()
11116 { 10937 {
11117 m_host.AddScriptLPS(1); 10938 m_host.AddScriptLPS(1);
11118 UUID invItemID = InventorySelf();
11119 if (invItemID == UUID.Zero)
11120 return new LSL_Rotation();
11121
11122 m_host.TaskInventory.LockItemsForRead(true);
11123 10939
11124 UUID agentID = m_host.TaskInventory[invItemID].PermsGranter; 10940 if (m_item.PermsGranter == UUID.Zero)
10941 return new LSL_Rotation();
11125 10942
11126// if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 10943 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 { 10944 {
11134 ShoutError("No permissions to track the camera"); 10945 ShoutError("No permissions to track the camera");
11135 m_host.TaskInventory.LockItemsForRead(false);
11136 return new LSL_Rotation(); 10946 return new LSL_Rotation();
11137 } 10947 }
11138 m_host.TaskInventory.LockItemsForRead(false);
11139 10948
11140// ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10949// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
11141 ScenePresence presence = World.GetScenePresence(agentID); 10950 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
11142 if (presence != null) 10951 if (presence != null)
11143 { 10952 {
11144 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W); 10953 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W);
@@ -11197,7 +11006,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11197 public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt) 11006 public void llMapDestination(string simname, LSL_Vector pos, LSL_Vector lookAt)
11198 { 11007 {
11199 m_host.AddScriptLPS(1); 11008 m_host.AddScriptLPS(1);
11200 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0); 11009 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
11201 if (detectedParams == null) 11010 if (detectedParams == null)
11202 { 11011 {
11203 if (m_host.ParentGroup.IsAttachment == true) 11012 if (m_host.ParentGroup.IsAttachment == true)
@@ -11321,30 +11130,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11321 { 11130 {
11322 m_host.AddScriptLPS(1); 11131 m_host.AddScriptLPS(1);
11323 11132
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 11133 // the object we are in
11329 UUID objectID = m_host.ParentUUID; 11134 UUID objectID = m_host.ParentUUID;
11330 if (objectID == UUID.Zero) return; 11135 if (objectID == UUID.Zero)
11136 return;
11331 11137
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 11138 // we need the permission first, to know which avatar we want to set the camera for
11335 agentID = m_host.TaskInventory[invItemID].PermsGranter; 11139 UUID agentID = m_item.PermsGranter;
11336 11140
11337 if (agentID == UUID.Zero) 11141 if (agentID == UUID.Zero)
11338 {
11339 m_host.TaskInventory.LockItemsForRead(false);
11340 return; 11142 return;
11341 } 11143
11342 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) 11144 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
11343 {
11344 m_host.TaskInventory.LockItemsForRead(false);
11345 return; 11145 return;
11346 }
11347 m_host.TaskInventory.LockItemsForRead(false);
11348 11146
11349 ScenePresence presence = World.GetScenePresence(agentID); 11147 ScenePresence presence = World.GetScenePresence(agentID);
11350 11148
@@ -11386,34 +11184,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11386 { 11184 {
11387 m_host.AddScriptLPS(1); 11185 m_host.AddScriptLPS(1);
11388 11186
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 11187 // the object we are in
11394 UUID objectID = m_host.ParentUUID; 11188 UUID objectID = m_host.ParentUUID;
11395 if (objectID == UUID.Zero) return; 11189 if (objectID == UUID.Zero)
11190 return;
11396 11191
11397 // we need the permission first, to know which avatar we want to clear the camera for 11192 // we need the permission first, to know which avatar we want to clear the camera for
11398 UUID agentID; 11193 UUID agentID = m_item.PermsGranter;
11399 m_host.TaskInventory.LockItemsForRead(true); 11194
11400 agentID = m_host.TaskInventory[invItemID].PermsGranter;
11401 if (agentID == UUID.Zero) 11195 if (agentID == UUID.Zero)
11402 {
11403 m_host.TaskInventory.LockItemsForRead(false);
11404 return; 11196 return;
11405 } 11197
11406 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) 11198 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
11407 {
11408 m_host.TaskInventory.LockItemsForRead(false);
11409 return; 11199 return;
11410 }
11411 m_host.TaskInventory.LockItemsForRead(false);
11412 11200
11413 ScenePresence presence = World.GetScenePresence(agentID); 11201 ScenePresence presence = World.GetScenePresence(agentID);
11414 11202
11415 // we are not interested in child-agents 11203 // we are not interested in child-agents
11416 if (presence.IsChildAgent) return; 11204 if (presence.IsChildAgent)
11205 return;
11417 11206
11418 presence.ControllingClient.SendClearFollowCamProperties(objectID); 11207 presence.ControllingClient.SendClearFollowCamProperties(objectID);
11419 } 11208 }
@@ -11604,8 +11393,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11604 } 11393 }
11605 } 11394 }
11606 11395
11607 UUID reqID = httpScriptMod. 11396 UUID reqID
11608 StartHttpRequest(m_localID, m_itemID, url, param, httpHeaders, body); 11397 = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body);
11609 11398
11610 if (reqID != UUID.Zero) 11399 if (reqID != UUID.Zero)
11611 return reqID.ToString(); 11400 return reqID.ToString();
@@ -11859,19 +11648,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11859 break; 11648 break;
11860 // For the following 8 see the Object version below 11649 // For the following 8 see the Object version below
11861 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT: 11650 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
11862 ret.Add(new LSL_Integer(0)); 11651 ret.Add(new LSL_Integer(av.RunningScriptCount()));
11863 break; 11652 break;
11864 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT: 11653 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
11865 ret.Add(new LSL_Integer(0)); 11654 ret.Add(new LSL_Integer(av.ScriptCount()));
11866 break; 11655 break;
11867 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY: 11656 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
11868 ret.Add(new LSL_Integer(0)); 11657 ret.Add(new LSL_Integer(av.RunningScriptCount() * 16384));
11869 break; 11658 break;
11870 case ScriptBaseClass.OBJECT_SCRIPT_TIME: 11659 case ScriptBaseClass.OBJECT_SCRIPT_TIME:
11871 ret.Add(new LSL_Float(0)); 11660 ret.Add(new LSL_Float(av.ScriptExecutionTime() / 1000.0f));
11872 break; 11661 break;
11873 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE: 11662 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
11874 ret.Add(new LSL_Integer(0)); 11663 ret.Add(new LSL_Integer(1));
11875 break; 11664 break;
11876 case ScriptBaseClass.OBJECT_SERVER_COST: 11665 case ScriptBaseClass.OBJECT_SERVER_COST:
11877 ret.Add(new LSL_Float(0)); 11666 ret.Add(new LSL_Float(0));
@@ -11929,37 +11718,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11929 case ScriptBaseClass.OBJECT_CREATOR: 11718 case ScriptBaseClass.OBJECT_CREATOR:
11930 ret.Add(new LSL_String(obj.CreatorID.ToString())); 11719 ret.Add(new LSL_String(obj.CreatorID.ToString()));
11931 break; 11720 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: 11721 case ScriptBaseClass.OBJECT_RUNNING_SCRIPT_COUNT:
11938 // in SL this currently includes crashed scripts 11722 ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount()));
11939 ret.Add(new LSL_Integer(0));
11940 break; 11723 break;
11941 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT: 11724 case ScriptBaseClass.OBJECT_TOTAL_SCRIPT_COUNT:
11942 ret.Add(new LSL_Integer(0)); 11725 ret.Add(new LSL_Integer(obj.ParentGroup.ScriptCount()));
11943 break; 11726 break;
11944 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY: 11727 case ScriptBaseClass.OBJECT_SCRIPT_MEMORY:
11945 // The value returned in SL for mono scripts is 65536 * number of active scripts 11728 // The value returned in SL for mono scripts is 65536 * number of active scripts
11946 ret.Add(new LSL_Integer(0)); 11729 // and 16384 * number of active scripts for LSO. since llGetFreememory
11730 // is coded to give the LSO value use it here
11731 ret.Add(new LSL_Integer(obj.ParentGroup.RunningScriptCount() * 16384));
11947 break; 11732 break;
11948 case ScriptBaseClass.OBJECT_SCRIPT_TIME: 11733 case ScriptBaseClass.OBJECT_SCRIPT_TIME:
11949 // Average cpu time per simulator frame expended on all scripts in the objetc 11734 // Average cpu time in seconds per simulator frame expended on all scripts in the object
11950 ret.Add(new LSL_Float(0)); 11735 ret.Add(new LSL_Float(obj.ParentGroup.ScriptExecutionTime() / 1000.0f));
11951 break; 11736 break;
11952 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE: 11737 case ScriptBaseClass.OBJECT_PRIM_EQUIVALENCE:
11953 // according to the SL wiki A prim or linkset will have prim 11738 // 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 11739 // 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 11740 // 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 11741 // The value returned in SL for normal prims is prim count
11957 ret.Add(new LSL_Integer(0)); 11742 ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
11958 break; 11743 break;
11959 11744
11960 // costs below may need to be diferent for root parts, need to check 11745 // costs below may need to be diferent for root parts, need to check
11961 case ScriptBaseClass.OBJECT_SERVER_COST: 11746 case ScriptBaseClass.OBJECT_SERVER_COST:
11962 // The value returned in SL for normal prims is prim count 11747 // The linden calculation is here
11748 // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
11749 // The value returned in SL for normal prims looks like the prim count
11963 ret.Add(new LSL_Float(0)); 11750 ret.Add(new LSL_Float(0));
11964 break; 11751 break;
11965 case ScriptBaseClass.OBJECT_STREAMING_COST: 11752 case ScriptBaseClass.OBJECT_STREAMING_COST:
@@ -12065,7 +11852,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12065 } 11852 }
12066 11853
12067 // was: UUID tid = tid = AsyncCommands. 11854 // was: UUID tid = tid = AsyncCommands.
12068 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, assetID.ToString()); 11855 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, assetID.ToString());
12069 11856
12070 if (NotecardCache.IsCached(assetID)) 11857 if (NotecardCache.IsCached(assetID))
12071 { 11858 {
@@ -12128,7 +11915,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12128 } 11915 }
12129 11916
12130 // was: UUID tid = tid = AsyncCommands. 11917 // was: UUID tid = tid = AsyncCommands.
12131 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, assetID.ToString()); 11918 UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, assetID.ToString());
12132 11919
12133 if (NotecardCache.IsCached(assetID)) 11920 if (NotecardCache.IsCached(assetID))
12134 { 11921 {
@@ -12212,7 +11999,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12212 { 11999 {
12213 UUID rq = UUID.Random(); 12000 UUID rq = UUID.Random();
12214 12001
12215 AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 12002 AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
12216 12003
12217 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id))); 12004 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id)));
12218 12005
@@ -12228,7 +12015,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12228 { 12015 {
12229 UUID rq = UUID.Random(); 12016 UUID rq = UUID.Random();
12230 12017
12231 AsyncCommands.DataserverPlugin.RegisterRequest(m_localID, m_itemID, rq.ToString()); 12018 AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString());
12232 12019
12233 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id)); 12020 AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id));
12234 12021
@@ -12429,7 +12216,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12429 { 12216 {
12430 Tri t1 = new Tri(); 12217 Tri t1 = new Tri();
12431 Tri t2 = new Tri(); 12218 Tri t2 = new Tri();
12432 12219
12433 Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]); 12220 Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]);
12434 Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]); 12221 Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]);
12435 Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]); 12222 Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]);
@@ -12470,7 +12257,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12470 // sometimes 12257 // sometimes
12471 if (Math.Abs(b) < 0.000001) 12258 if (Math.Abs(b) < 0.000001)
12472 continue; 12259 continue;
12473 12260
12474 double r = a / b; 12261 double r = a / b;
12475 12262
12476 // ray points away from plane 12263 // ray points away from plane
@@ -12730,7 +12517,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12730 bool isAccount = false; 12517 bool isAccount = false;
12731 bool isGroup = false; 12518 bool isGroup = false;
12732 12519
12733 if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManager(m_host.OwnerID)) 12520 if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManagerOrOwner(m_host.OwnerID))
12734 return 0; 12521 return 0;
12735 12522
12736 UUID id = new UUID(); 12523 UUID id = new UUID();
@@ -12792,35 +12579,50 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12792 return 1; 12579 return 1;
12793 } 12580 }
12794 12581
12795 #region Not Implemented 12582 public LSL_Integer llGetMemoryLimit()
12796 // 12583 {
12797 // Listing the unimplemented lsl functions here, please move 12584 m_host.AddScriptLPS(1);
12798 // them from this region as they are completed 12585 // The value returned for LSO scripts in SL
12799 // 12586 return 16384;
12587 }
12800 12588
12801 public void llGetEnv(LSL_String name) 12589 public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
12802 { 12590 {
12803 m_host.AddScriptLPS(1); 12591 m_host.AddScriptLPS(1);
12804 NotImplemented("llGetEnv"); 12592 // Treat as an LSO script
12593 return ScriptBaseClass.FALSE;
12805 } 12594 }
12806 12595
12807 public void llGetSPMaxMemory() 12596 public LSL_Integer llGetSPMaxMemory()
12808 { 12597 {
12809 m_host.AddScriptLPS(1); 12598 m_host.AddScriptLPS(1);
12810 NotImplemented("llGetSPMaxMemory"); 12599 // The value returned for LSO scripts in SL
12600 return 16384;
12811 } 12601 }
12812 12602
12813 public virtual LSL_Integer llGetUsedMemory() 12603 public virtual LSL_Integer llGetUsedMemory()
12814 { 12604 {
12815 m_host.AddScriptLPS(1); 12605 m_host.AddScriptLPS(1);
12816 NotImplemented("llGetUsedMemory"); 12606 // The value returned for LSO scripts in SL
12817 return 0; 12607 return 16384;
12818 } 12608 }
12819 12609
12820 public void llScriptProfiler(LSL_Integer flags) 12610 public void llScriptProfiler(LSL_Integer flags)
12821 { 12611 {
12822 m_host.AddScriptLPS(1); 12612 m_host.AddScriptLPS(1);
12823 //NotImplemented("llScriptProfiler"); 12613 // This does nothing for LSO scripts in SL
12614 }
12615
12616 #region Not Implemented
12617 //
12618 // Listing the unimplemented lsl functions here, please move
12619 // them from this region as they are completed
12620 //
12621
12622 public void llGetEnv(LSL_String name)
12623 {
12624 m_host.AddScriptLPS(1);
12625 NotImplemented("llGetEnv");
12824 } 12626 }
12825 12627
12826 public void llSetSoundQueueing(int queue) 12628 public void llSetSoundQueueing(int queue)
@@ -12900,8 +12702,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12900 12702
12901 try 12703 try
12902 { 12704 {
12903 UUID invItemID=InventorySelf(); 12705 TaskInventoryItem item = m_item;
12904 if (invItemID == UUID.Zero) 12706 if (item == null)
12905 { 12707 {
12906 replydata = "SERVICE_ERROR"; 12708 replydata = "SERVICE_ERROR";
12907 return; 12709 return;
@@ -12909,10 +12711,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12909 12711
12910 m_host.AddScriptLPS(1); 12712 m_host.AddScriptLPS(1);
12911 12713
12912 m_host.TaskInventory.LockItemsForRead(true);
12913 TaskInventoryItem item = m_host.TaskInventory[invItemID];
12914 m_host.TaskInventory.LockItemsForRead(false);
12915
12916 if (item.PermsGranter == UUID.Zero) 12714 if (item.PermsGranter == UUID.Zero)
12917 { 12715 {
12918 replydata = "MISSING_PERMISSION_DEBIT"; 12716 replydata = "MISSING_PERMISSION_DEBIT";
@@ -12954,7 +12752,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12954 } 12752 }
12955 finally 12753 finally
12956 { 12754 {
12957 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 12755 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
12958 "transaction_result", new Object[] { 12756 "transaction_result", new Object[] {
12959 new LSL_String(txn.ToString()), 12757 new LSL_String(txn.ToString()),
12960 new LSL_Integer(replycode), 12758 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 278f74e..5c6ad8a 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -383,6 +383,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
383 public const int PRIM_SCULPT_FLAG_INVERT = 64; 383 public const int PRIM_SCULPT_FLAG_INVERT = 64;
384 public const int PRIM_SCULPT_FLAG_MIRROR = 128; 384 public const int PRIM_SCULPT_FLAG_MIRROR = 128;
385 385
386 public const int PROFILE_NONE = 0;
387 public const int PROFILE_SCRIPT_MEMORY = 1;
388
386 public const int MASK_BASE = 0; 389 public const int MASK_BASE = 0;
387 public const int MASK_OWNER = 1; 390 public const int MASK_OWNER = 1;
388 public const int MASK_GROUP = 2; 391 public const int MASK_GROUP = 2;
@@ -641,6 +644,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
641 public const int OS_NPC_FLY = 0; 644 public const int OS_NPC_FLY = 0;
642 public const int OS_NPC_NO_FLY = 1; 645 public const int OS_NPC_NO_FLY = 1;
643 public const int OS_NPC_LAND_AT_TARGET = 2; 646 public const int OS_NPC_LAND_AT_TARGET = 2;
647 public const int OS_NPC_RUNNING = 4;
644 648
645 public const int OS_NPC_SIT_NOW = 0; 649 public const int OS_NPC_SIT_NOW = 0;
646 650
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
index 116f639..976969a 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
@@ -376,6 +376,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
376 return m_LSL_Functions.llFrand(mag); 376 return m_LSL_Functions.llFrand(mag);
377 } 377 }
378 378
379 public LSL_Key llGenerateKey()
380 {
381 return m_LSL_Functions.llGenerateKey();
382 }
383
379 public LSL_Vector llGetAccel() 384 public LSL_Vector llGetAccel()
380 { 385 {
381 return m_LSL_Functions.llGetAccel(); 386 return m_LSL_Functions.llGetAccel();
@@ -591,6 +596,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
591 return m_LSL_Functions.llGetMassMKS(); 596 return m_LSL_Functions.llGetMassMKS();
592 } 597 }
593 598
599 public LSL_Integer llGetMemoryLimit()
600 {
601 return m_LSL_Functions.llGetMemoryLimit();
602 }
603
594 public void llGetNextEmail(string address, string subject) 604 public void llGetNextEmail(string address, string subject)
595 { 605 {
596 m_LSL_Functions.llGetNextEmail(address, subject); 606 m_LSL_Functions.llGetNextEmail(address, subject);
@@ -781,6 +791,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
781 return m_LSL_Functions.llGetSimulatorHostname(); 791 return m_LSL_Functions.llGetSimulatorHostname();
782 } 792 }
783 793
794 public LSL_Integer llGetSPMaxMemory()
795 {
796 return m_LSL_Functions.llGetSPMaxMemory();
797 }
798
784 public LSL_Integer llGetStartParameter() 799 public LSL_Integer llGetStartParameter()
785 { 800 {
786 return m_LSL_Functions.llGetStartParameter(); 801 return m_LSL_Functions.llGetStartParameter();
@@ -1450,6 +1465,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1450 return m_LSL_Functions.llScriptDanger(pos); 1465 return m_LSL_Functions.llScriptDanger(pos);
1451 } 1466 }
1452 1467
1468 public void llScriptProfiler(LSL_Integer flags)
1469 {
1470 m_LSL_Functions.llScriptProfiler(flags);
1471 }
1472
1453 public LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata) 1473 public LSL_Key llSendRemoteData(string channel, string dest, int idata, string sdata)
1454 { 1474 {
1455 return m_LSL_Functions.llSendRemoteData(channel, dest, idata, sdata); 1475 return m_LSL_Functions.llSendRemoteData(channel, dest, idata, sdata);
@@ -1560,6 +1580,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1560 m_LSL_Functions.llSetLocalRot(rot); 1580 m_LSL_Functions.llSetLocalRot(rot);
1561 } 1581 }
1562 1582
1583 public LSL_Integer llSetMemoryLimit(LSL_Integer limit)
1584 {
1585 return m_LSL_Functions.llSetMemoryLimit(limit);
1586 }
1587
1563 public void llSetObjectDesc(string desc) 1588 public void llSetObjectDesc(string desc)
1564 { 1589 {
1565 m_LSL_Functions.llSetObjectDesc(desc); 1590 m_LSL_Functions.llSetObjectDesc(desc);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 680cefb4..d230662 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -289,8 +289,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
289 m_OSSL_Functions.osAvatarStopAnimation(avatar, animation); 289 m_OSSL_Functions.osAvatarStopAnimation(avatar, animation);
290 } 290 }
291 291
292 // Avatar functions
292 293
293 //Texture Draw functions 294 public void osForceAttachToAvatar(int attachmentPoint)
295 {
296 m_OSSL_Functions.osForceAttachToAvatar(attachmentPoint);
297 }
298
299 public void osForceDetachFromAvatar()
300 {
301 m_OSSL_Functions.osForceDetachFromAvatar();
302 }
303
304 // Texture Draw functions
294 305
295 public string osMovePen(string drawList, int x, int y) 306 public string osMovePen(string drawList, int x, int y)
296 { 307 {
@@ -569,6 +580,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
569 m_OSSL_Functions.osNpcSay(npc, message); 580 m_OSSL_Functions.osNpcSay(npc, message);
570 } 581 }
571 582
583 public void osNpcSay(key npc, int channel, string message)
584 {
585 m_OSSL_Functions.osNpcSay(npc, channel, message);
586 }
587
588
589 public void osNpcShout(key npc, int channel, string message)
590 {
591 m_OSSL_Functions.osNpcShout(npc, channel, message);
592 }
593
572 public void osNpcSit(LSL_Key npc, LSL_Key target, int options) 594 public void osNpcSit(LSL_Key npc, LSL_Key target, int options)
573 { 595 {
574 m_OSSL_Functions.osNpcSit(npc, target, options); 596 m_OSSL_Functions.osNpcSit(npc, target, options);
@@ -594,6 +616,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
594 m_OSSL_Functions.osNpcStopAnimation(npc, animation); 616 m_OSSL_Functions.osNpcStopAnimation(npc, animation);
595 } 617 }
596 618
619 public void osNpcWhisper(key npc, int channel, string message)
620 {
621 m_OSSL_Functions.osNpcWhisper(npc, channel, message);
622 }
623
597 public LSL_Key osOwnerSaveAppearance(string notecard) 624 public LSL_Key osOwnerSaveAppearance(string notecard)
598 { 625 {
599 return m_OSSL_Functions.osOwnerSaveAppearance(notecard); 626 return m_OSSL_Functions.osOwnerSaveAppearance(notecard);
@@ -878,5 +905,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
878 { 905 {
879 return m_OSSL_Functions.osEjectFromGroup(agentId); 906 return m_OSSL_Functions.osEjectFromGroup(agentId);
880 } 907 }
908
909 public void osSetTerrainTexture(int level, LSL_Key texture)
910 {
911 m_OSSL_Functions.osSetTerrainTexture(level, texture);
912 }
913
914 public void osSetTerrainTextureHeight(int corner, double low, double high)
915 {
916 m_OSSL_Functions.osSetTerrainTextureHeight(corner, low, high);
917 }
881 } 918 }
882} 919}