aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs26
-rw-r--r--OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs25
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs41
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs13
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs8
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs8
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Helpers.cs18
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs100
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/Tests/CoopTerminationTests.cs157
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs7
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs5
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs3
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs3
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs5
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs19
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs17
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs15
18 files changed, 393 insertions, 87 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
index 5c8b097..92bf85a 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
@@ -1738,6 +1738,21 @@ namespace OpenSim.Region.Framework.Scenes
1738 /// <returns>The part where the script was rezzed if successful. False otherwise.</returns> 1738 /// <returns>The part where the script was rezzed if successful. False otherwise.</returns>
1739 public SceneObjectPart RezNewScript(UUID agentID, InventoryItemBase itemBase) 1739 public SceneObjectPart RezNewScript(UUID agentID, InventoryItemBase itemBase)
1740 { 1740 {
1741 return RezNewScript(
1742 agentID,
1743 itemBase,
1744 "default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}");
1745 }
1746
1747 /// <summary>
1748 /// Rez a new script from nothing with given script text.
1749 /// </summary>
1750 /// <param name="remoteClient"></param>
1751 /// <param name="itemBase">Template item.</param>
1752 /// <param name="scriptText"></param>
1753 /// <returns>The part where the script was rezzed if successful. False otherwise.</returns>
1754 public SceneObjectPart RezNewScript(UUID agentID, InventoryItemBase itemBase, string scriptText)
1755 {
1741 // The part ID is the folder ID! 1756 // The part ID is the folder ID!
1742 SceneObjectPart part = GetSceneObjectPart(itemBase.Folder); 1757 SceneObjectPart part = GetSceneObjectPart(itemBase.Folder);
1743 if (part == null) 1758 if (part == null)
@@ -1757,9 +1772,14 @@ namespace OpenSim.Region.Framework.Scenes
1757 return null; 1772 return null;
1758 } 1773 }
1759 1774
1760 AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType, 1775 AssetBase asset
1761 Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"), 1776 = CreateAsset(
1762 agentID); 1777 itemBase.Name,
1778 itemBase.Description,
1779 (sbyte)itemBase.AssetType,
1780 Encoding.ASCII.GetBytes(scriptText),
1781 agentID);
1782
1763 AssetService.Store(asset); 1783 AssetService.Store(asset);
1764 1784
1765 TaskInventoryItem taskItem = new TaskInventoryItem(); 1785 TaskInventoryItem taskItem = new TaskInventoryItem();
diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs
index 2027ca6..e95cbd7 100644
--- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs
+++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptApi.cs
@@ -29,6 +29,7 @@ using System;
29using OpenMetaverse; 29using OpenMetaverse;
30using OpenSim.Framework; 30using OpenSim.Framework;
31using OpenSim.Region.Framework.Scenes; 31using OpenSim.Region.Framework.Scenes;
32using OpenSim.Region.ScriptEngine.Shared;
32 33
33namespace OpenSim.Region.ScriptEngine.Interfaces 34namespace OpenSim.Region.ScriptEngine.Interfaces
34{ 35{
@@ -38,11 +39,8 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
38 /// Initialize the API 39 /// Initialize the API
39 /// </summary> 40 /// </summary>
40 /// <remarks> 41 /// <remarks>
41 /// Each API has an identifier, which is used to load the 42 /// Each API has an identifier, which is used to load the proper runtime assembly at load time.
42 /// proper runtime assembly at load time. 43 /// <param name='scriptInstance'>/param>
43 /// <param name='engine'>/param> 44 void Initialize(IScriptInstance scriptInstance);
44 /// <param name='part'></param>
45 /// <param name='item'></param>
46 void Initialize(IScriptEngine engine, SceneObjectPart part, TaskInventoryItem item);
47 } 45 }
48} \ No newline at end of file 46} \ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
index 2f5b526..38fff52 100644
--- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
@@ -28,9 +28,11 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Threading;
31using OpenMetaverse; 32using OpenMetaverse;
32using log4net; 33using log4net;
33using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenSim.Region.Framework.Scenes;
34using OpenSim.Region.ScriptEngine.Shared; 36using OpenSim.Region.ScriptEngine.Shared;
35using OpenSim.Region.ScriptEngine.Interfaces; 37using OpenSim.Region.ScriptEngine.Interfaces;
36 38
@@ -105,6 +107,11 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
105 /// </summary> 107 /// </summary>
106 long MeasurementPeriodExecutionTime { get; } 108 long MeasurementPeriodExecutionTime { get; }
107 109
110 /// <summary>
111 /// Scene part in which this script instance is contained.
112 /// </summary>
113 SceneObjectPart Part { get; }
114
108 IScriptEngine Engine { get; } 115 IScriptEngine Engine { get; }
109 UUID AppDomain { get; set; } 116 UUID AppDomain { get; set; }
110 string PrimName { get; } 117 string PrimName { get; }
@@ -124,6 +131,12 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
124 131
125 uint LocalID { get; } 132 uint LocalID { get; }
126 UUID AssetID { get; } 133 UUID AssetID { get; }
134
135 /// <summary>
136 /// Inventory item containing the script used.
137 /// </summary>
138 TaskInventoryItem ScriptTask { get; }
139
127 Queue EventQueue { get; } 140 Queue EventQueue { get; }
128 141
129 /// <summary> 142 /// <summary>
@@ -169,6 +182,18 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
169 void Resume(); 182 void Resume();
170 183
171 /// <summary> 184 /// <summary>
185 /// If true then scripts should look to terminate their threads in co-operation with the script engine rather
186 /// than through Thread.Abort()
187 /// </summary>
188 bool CoopTermination { get; }
189
190 /// <summary>
191 /// Used for script sleeps when we are using co-operative script termination.
192 /// </summary>
193 /// <remarks>null if CoopTermination is not active</remarks>
194 EventWaitHandle CoopSleepHandle { get; }
195
196 /// <summary>
172 /// Process the next event queued for this script instance. 197 /// Process the next event queued for this script instance.
173 /// </summary> 198 /// </summary>
174 /// <returns></returns> 199 /// <returns></returns>
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index ea4e609..b992efa 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -83,6 +83,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
83 public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi 83 public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi
84 { 84 {
85 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 85 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
86
87 /// <summary>
88 /// Instance of this script.
89 /// </summary>
90 protected IScriptInstance m_scriptInstance;
91
86 protected IScriptEngine m_ScriptEngine; 92 protected IScriptEngine m_ScriptEngine;
87 protected SceneObjectPart m_host; 93 protected SceneObjectPart m_host;
88 94
@@ -110,24 +116,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
110 protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp. 116 protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp.
111 protected ISoundModule m_SoundModule = null; 117 protected ISoundModule m_SoundModule = null;
112 118
113 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) 119 public void Initialize(IScriptInstance scriptInstance)
114 { 120 {
115 m_ScriptEngine = ScriptEngine; 121 m_scriptInstance = scriptInstance;
116 m_host = host; 122 m_ScriptEngine = m_scriptInstance.Engine;
117 m_item = item; 123 m_host = m_scriptInstance.Part;
124 m_item = m_scriptInstance.ScriptTask;
118 125
119 LoadLimits(); // read script limits from config. 126 LoadConfig();
120 127
121 m_TransferModule = 128 m_TransferModule =
122 m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>(); 129 m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
123 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); 130 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
124 m_SoundModule = m_ScriptEngine.World.RequestModuleInterface<ISoundModule>(); 131 m_SoundModule = m_ScriptEngine.World.RequestModuleInterface<ISoundModule>();
125 132
126 AsyncCommands = new AsyncCommandManager(ScriptEngine); 133 AsyncCommands = new AsyncCommandManager(m_ScriptEngine);
127 } 134 }
128 135
129 /* load configuration items that affect script, object and run-time behavior. */ 136 /// <summary>
130 private void LoadLimits() 137 /// Load configuration items that affect script, object and run-time behavior. */
138 /// </summary>
139 private void LoadConfig()
131 { 140 {
132 m_ScriptDelayFactor = 141 m_ScriptDelayFactor =
133 m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f); 142 m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
@@ -141,12 +150,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
141 m_ScriptEngine.Config.GetInt("NotecardLineReadCharsMax", 255); 150 m_ScriptEngine.Config.GetInt("NotecardLineReadCharsMax", 255);
142 if (m_notecardLineReadCharsMax > 65535) 151 if (m_notecardLineReadCharsMax > 65535)
143 m_notecardLineReadCharsMax = 65535; 152 m_notecardLineReadCharsMax = 65535;
153
144 // load limits for particular subsystems. 154 // load limits for particular subsystems.
145 IConfig SMTPConfig; 155 IConfig SMTPConfig;
146 if ((SMTPConfig = m_ScriptEngine.ConfigSource.Configs["SMTP"]) != null) { 156 if ((SMTPConfig = m_ScriptEngine.ConfigSource.Configs["SMTP"]) != null) {
147 // there's an smtp config, so load in the snooze time. 157 // there's an smtp config, so load in the snooze time.
148 EMAIL_PAUSE_TIME = SMTPConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME); 158 EMAIL_PAUSE_TIME = SMTPConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME);
149 } 159 }
160
150 // Rezzing an object with a velocity can create recoil. This feature seems to have been 161 // Rezzing an object with a velocity can create recoil. This feature seems to have been
151 // removed from recent versions of SL. The code computes recoil (vel*mass) and scales 162 // removed from recent versions of SL. The code computes recoil (vel*mass) and scales
152 // it by this factor. May be zero to turn off recoil all together. 163 // it by this factor. May be zero to turn off recoil all together.
@@ -171,7 +182,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
171 delay = (int)((float)delay * m_ScriptDelayFactor); 182 delay = (int)((float)delay * m_ScriptDelayFactor);
172 if (delay == 0) 183 if (delay == 0)
173 return; 184 return;
174 System.Threading.Thread.Sleep(delay); 185
186 Sleep(delay);
187 }
188
189 protected virtual void Sleep(int delay)
190 {
191 if (!m_scriptInstance.CoopTermination)
192 System.Threading.Thread.Sleep(delay);
193 else if (m_scriptInstance.CoopSleepHandle.WaitOne(delay))
194 throw new ScriptCoopStopException();
175 } 195 }
176 196
177 public Scene World 197 public Scene World
@@ -2910,7 +2930,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2910 { 2930 {
2911// m_log.Info("llSleep snoozing " + sec + "s."); 2931// m_log.Info("llSleep snoozing " + sec + "s.");
2912 m_host.AddScriptLPS(1); 2932 m_host.AddScriptLPS(1);
2913 Thread.Sleep((int)(sec * 1000)); 2933
2934 Sleep((int)(sec * 1000));
2914 } 2935 }
2915 2936
2916 public LSL_Float llGetMass() 2937 public LSL_Float llGetMass()
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
index ceb4660..071c60e 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
@@ -61,10 +61,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
61 internal bool m_LSFunctionsEnabled = false; 61 internal bool m_LSFunctionsEnabled = false;
62 internal IScriptModuleComms m_comms = null; 62 internal IScriptModuleComms m_comms = null;
63 63
64 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) 64 public void Initialize(IScriptInstance scriptInstance)
65 { 65 {
66 m_ScriptEngine = ScriptEngine; 66 m_ScriptEngine = scriptInstance.Engine;
67 m_host = host; 67 m_host = scriptInstance.Part;
68 68
69 if (m_ScriptEngine.Config.GetBoolean("AllowLightShareFunctions", false)) 69 if (m_ScriptEngine.Config.GetBoolean("AllowLightShareFunctions", false))
70 m_LSFunctionsEnabled = true; 70 m_LSFunctionsEnabled = true;
@@ -92,10 +92,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
92 get { return m_ScriptEngine.World; } 92 get { return m_ScriptEngine.World; }
93 } 93 }
94 94
95 // 95 /// <summary>
96 //Dumps an error message on the debug console. 96 /// Dumps an error message on the debug console.
97 // 97 /// </summary>
98
99 internal void LSShoutError(string message) 98 internal void LSShoutError(string message)
100 { 99 {
101 if (message.Length > 1023) 100 if (message.Length > 1023)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
index 8f34833..cbc69aa 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
@@ -61,11 +61,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
61 internal bool m_MODFunctionsEnabled = false; 61 internal bool m_MODFunctionsEnabled = false;
62 internal IScriptModuleComms m_comms = null; 62 internal IScriptModuleComms m_comms = null;
63 63
64 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) 64 public void Initialize(IScriptInstance scriptInstance)
65 { 65 {
66 m_ScriptEngine = ScriptEngine; 66 m_ScriptEngine = scriptInstance.Engine;
67 m_host = host; 67 m_host = scriptInstance.Part;
68 m_item = item; 68 m_item = scriptInstance.ScriptTask;
69 69
70 if (m_ScriptEngine.Config.GetBoolean("AllowMODFunctions", false)) 70 if (m_ScriptEngine.Config.GetBoolean("AllowMODFunctions", false))
71 m_MODFunctionsEnabled = true; 71 m_MODFunctionsEnabled = true;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 958a448..33ae5f0 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -142,11 +142,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
142 142
143 protected IUrlModule m_UrlModule = null; 143 protected IUrlModule m_UrlModule = null;
144 144
145 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) 145 public void Initialize(IScriptInstance scriptInstance)
146 { 146 {
147 m_ScriptEngine = ScriptEngine; 147 m_ScriptEngine = scriptInstance.Engine;
148 m_host = host; 148 m_host = scriptInstance.Part;
149 m_item = item; 149 m_item = scriptInstance.ScriptTask;
150 150
151 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); 151 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
152 152
diff --git a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
index 5a58f73..e02d35e 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
@@ -81,6 +81,24 @@ namespace OpenSim.Region.ScriptEngine.Shared
81 } 81 }
82 } 82 }
83 83
84 /// <summary>
85 /// Used to signal when the script is stopping in co-operation with the script engine
86 /// (instead of through Thread.Abort()).
87 /// </summary>
88 [Serializable]
89 public class ScriptCoopStopException : Exception
90 {
91 public ScriptCoopStopException()
92 {
93 }
94
95 protected ScriptCoopStopException(
96 SerializationInfo info,
97 StreamingContext context)
98 {
99 }
100 }
101
84 public class DetectParams 102 public class DetectParams
85 { 103 {
86 public const int AGENT = 1; 104 public const int AGENT = 1;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index f172216..00048a1 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -157,9 +157,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
157 157
158 public UUID AppDomain { get; set; } 158 public UUID AppDomain { get; set; }
159 159
160 /// <summary>
161 /// Scene part in which this script instance is contained.
162 /// </summary>
163 public SceneObjectPart Part { get; private set; } 160 public SceneObjectPart Part { get; private set; }
164 161
165 public string PrimName { get; private set; } 162 public string PrimName { get; private set; }
@@ -203,49 +200,68 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
203 200
204 public static readonly long MaxMeasurementPeriod = 30 * TimeSpan.TicksPerMinute; 201 public static readonly long MaxMeasurementPeriod = 30 * TimeSpan.TicksPerMinute;
205 202
203 public bool CoopTermination { get; private set; }
204
205 public EventWaitHandle CoopSleepHandle { get; private set; }
206
206 public void ClearQueue() 207 public void ClearQueue()
207 { 208 {
208 m_TimerQueued = false; 209 m_TimerQueued = false;
209 EventQueue.Clear(); 210 EventQueue.Clear();
210 } 211 }
211 212
212 public ScriptInstance(IScriptEngine engine, SceneObjectPart part, 213 public ScriptInstance(
213 UUID itemID, UUID assetID, string assembly, 214 IScriptEngine engine, SceneObjectPart part, TaskInventoryItem item,
214 AppDomain dom, string primName, string scriptName, 215 int startParam, bool postOnRez,
215 int startParam, bool postOnRez, StateSource stateSource, 216 int maxScriptQueue)
216 int maxScriptQueue)
217 { 217 {
218 State = "default"; 218 State = "default";
219 EventQueue = new Queue(32); 219 EventQueue = new Queue(32);
220 220
221 Engine = engine; 221 Engine = engine;
222 Part = part; 222 Part = part;
223 ItemID = itemID; 223 ScriptTask = item;
224 AssetID = assetID; 224
225 PrimName = primName; 225 // This is currently only here to allow regression tests to get away without specifying any inventory
226 ScriptName = scriptName; 226 // item when they are testing script logic that doesn't require an item.
227 m_Assembly = assembly; 227 if (ScriptTask != null)
228 {
229 ScriptName = ScriptTask.Name;
230 ItemID = ScriptTask.ItemID;
231 AssetID = ScriptTask.AssetID;
232 }
233
234 PrimName = part.ParentGroup.Name;
228 StartParam = startParam; 235 StartParam = startParam;
229 m_MaxScriptQueue = maxScriptQueue; 236 m_MaxScriptQueue = maxScriptQueue;
230 m_stateSource = stateSource;
231 m_postOnRez = postOnRez; 237 m_postOnRez = postOnRez;
232 m_AttachedAvatar = Part.ParentGroup.AttachedAvatar; 238 m_AttachedAvatar = Part.ParentGroup.AttachedAvatar;
233 m_RegionID = Part.ParentGroup.Scene.RegionInfo.RegionID; 239 m_RegionID = Part.ParentGroup.Scene.RegionInfo.RegionID;
234 240
235 lock (Part.TaskInventory) 241 if (Engine.Config.GetString("ScriptStopStrategy", "abort") == "co-op")
236 { 242 {
237 if (Part.TaskInventory.ContainsKey(ItemID)) 243 CoopTermination = true;
238 { 244 CoopSleepHandle = new AutoResetEvent(false);
239 ScriptTask = Part.TaskInventory[ItemID];
240 }
241 } 245 }
246 }
247
248 /// <summary>
249 /// Load the script from an assembly into an AppDomain.
250 /// </summary>
251 /// <param name='dom'></param>
252 /// <param name='assembly'></param>
253 /// <param name='stateSource'></param>
254 public void Load(AppDomain dom, string assembly, StateSource stateSource)
255 {
256 m_Assembly = assembly;
257 m_stateSource = stateSource;
242 258
243 ApiManager am = new ApiManager(); 259 ApiManager am = new ApiManager();
244 260
245 foreach (string api in am.GetApis()) 261 foreach (string api in am.GetApis())
246 { 262 {
247 m_Apis[api] = am.CreateApi(api); 263 m_Apis[api] = am.CreateApi(api);
248 m_Apis[api].Initialize(engine, part, ScriptTask); 264 m_Apis[api].Initialize(this);
249 } 265 }
250 266
251 try 267 try
@@ -279,7 +295,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
279 295
280// // m_log.Debug("[Script] Script instance created"); 296// // m_log.Debug("[Script] Script instance created");
281 297
282 part.SetScriptEvents(ItemID, 298 Part.SetScriptEvents(ItemID,
283 (int)m_Script.GetStateEventFlags(State)); 299 (int)m_Script.GetStateEventFlags(State));
284 } 300 }
285 catch (Exception e) 301 catch (Exception e)
@@ -526,9 +542,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
526 } 542 }
527 543
528 // Wait for the current event to complete. 544 // Wait for the current event to complete.
529 if (!m_InSelfDelete && workItem.Wait(new TimeSpan((long)timeout * 100000))) 545 if (!m_InSelfDelete)
530 { 546 {
531 return true; 547 if (!CoopTermination)
548 {
549 // If we're not co-operative terminating then try and wait for the event to complete before stopping
550 if (workItem.Wait(new TimeSpan((long)timeout * 100000)))
551 return true;
552 }
553 else
554 {
555 m_log.DebugFormat(
556 "[SCRIPT INSTANCE]: Co-operatively stopping script {0} {1} in {2} {3}",
557 ScriptName, ItemID, PrimName, ObjectID);
558
559 // This will terminate the event on next handle check by the script.
560 CoopSleepHandle.Set();
561
562 // For now, we will wait forever since the event should always cleanly terminate once LSL loop
563 // checking is implemented. May want to allow a shorter timeout option later.
564 if (workItem.Wait(TimeSpan.MaxValue))
565 {
566 m_log.DebugFormat(
567 "[SCRIPT INSTANCE]: Co-operatively stopped script {0} {1} in {2} {3}",
568 ScriptName, ItemID, PrimName, ObjectID);
569
570 return true;
571 }
572 }
532 } 573 }
533 574
534 lock (EventQueue) 575 lock (EventQueue)
@@ -541,6 +582,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
541 582
542 // If the event still hasn't stopped and we the stop isn't the result of script or object removal, then 583 // If the event still hasn't stopped and we the stop isn't the result of script or object removal, then
543 // forcibly abort the work item (this aborts the underlying thread). 584 // forcibly abort the work item (this aborts the underlying thread).
585 // Co-operative termination should never reach this point.
544 if (!m_InSelfDelete) 586 if (!m_InSelfDelete)
545 { 587 {
546 m_log.DebugFormat( 588 m_log.DebugFormat(
@@ -780,7 +822,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
780 m_InEvent = false; 822 m_InEvent = false;
781 m_CurrentEvent = String.Empty; 823 m_CurrentEvent = String.Empty;
782 824
783 if ((!(e is TargetInvocationException) || (!(e.InnerException is SelfDeleteException) && !(e.InnerException is ScriptDeleteException))) && !(e is ThreadAbortException)) 825 if ((!(e is TargetInvocationException)
826 || (!(e.InnerException is SelfDeleteException)
827 && !(e.InnerException is ScriptDeleteException)
828 && !(e.InnerException is ScriptCoopStopException)))
829 && !(e is ThreadAbortException))
784 { 830 {
785 try 831 try
786 { 832 {
@@ -828,6 +874,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
828 m_InSelfDelete = true; 874 m_InSelfDelete = true;
829 Part.Inventory.RemoveInventoryItem(ItemID); 875 Part.Inventory.RemoveInventoryItem(ItemID);
830 } 876 }
877 else if ((e is TargetInvocationException) && (e.InnerException is ScriptCoopStopException))
878 {
879 m_log.DebugFormat(
880 "[SCRIPT INSTANCE]: Script {0}.{1} in event {2}, state {3} stopped co-operatively.",
881 PrimName, ScriptName, data.EventName, State);
882 }
831 } 883 }
832 } 884 }
833 } 885 }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/Tests/CoopTerminationTests.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/Tests/CoopTerminationTests.cs
new file mode 100644
index 0000000..f3a6cc9
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/Tests/CoopTerminationTests.cs
@@ -0,0 +1,157 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Threading;
31using Nini.Config;
32using NUnit.Framework;
33using OpenMetaverse;
34using OpenSim.Framework;
35using OpenSim.Region.CoreModules.Scripting.WorldComm;
36using OpenSim.Region.Framework.Scenes;
37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.ScriptEngine.XEngine;
39using OpenSim.Tests.Common;
40using OpenSim.Tests.Common.Mock;
41
42namespace OpenSim.Region.ScriptEngine.Shared.Instance.Tests
43{
44 /// <summary>
45 /// Test that co-operative script thread termination is working correctly.
46 /// </summary>
47 [TestFixture]
48 public class CoopTerminationTests : OpenSimTestCase
49 {
50 private TestScene m_scene;
51 private OpenSim.Region.ScriptEngine.XEngine.XEngine m_xEngine;
52
53 private AutoResetEvent m_chatEvent = new AutoResetEvent(false);
54 private AutoResetEvent m_stoppedEvent = new AutoResetEvent(false);
55
56 private OSChatMessage m_osChatMessageReceived;
57
58 [TestFixtureSetUp]
59 public void Init()
60 {
61 //AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory + "/bin");
62// Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);
63 m_xEngine = new OpenSim.Region.ScriptEngine.XEngine.XEngine();
64
65 IniConfigSource configSource = new IniConfigSource();
66
67 IConfig startupConfig = configSource.AddConfig("Startup");
68 startupConfig.Set("DefaultScriptEngine", "XEngine");
69
70 IConfig xEngineConfig = configSource.AddConfig("XEngine");
71 xEngineConfig.Set("Enabled", "true");
72 xEngineConfig.Set("StartDelay", "0");
73
74 // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call
75 // to AssemblyResolver.OnAssemblyResolve fails.
76 xEngineConfig.Set("AppDomainLoading", "false");
77
78 xEngineConfig.Set("ScriptStopStrategy", "co-op");
79
80 m_scene = new SceneHelpers().SetupScene("My Test", UUID.Random(), 1000, 1000, configSource);
81 SceneHelpers.SetupSceneModules(m_scene, configSource, m_xEngine);
82 m_scene.StartScripts();
83 }
84
85 /// <summary>
86 /// Test co-operative termination on derez of an object containing a script with a long-running event.
87 /// </summary>
88 /// <remarks>
89 /// TODO: Actually compiling the script is incidental to this test. Really want a way to compile test scripts
90 /// within the build itself.
91 /// </remarks>
92 [Test]
93 public void TestStopOnLongSleep()
94 {
95 TestHelpers.InMethod();
96 TestHelpers.EnableLogging();
97
98 UUID userId = TestHelpers.ParseTail(0x1);
99// UUID objectId = TestHelpers.ParseTail(0x100);
100// UUID itemId = TestHelpers.ParseTail(0x3);
101 string itemName = "TestStopOnObjectDerezLongSleep() Item";
102
103 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, "TestStopOnObjectDerezLongSleep", 0x100);
104 m_scene.AddNewSceneObject(so, true);
105
106 InventoryItemBase itemTemplate = new InventoryItemBase();
107// itemTemplate.ID = itemId;
108 itemTemplate.Name = itemName;
109 itemTemplate.Folder = so.UUID;
110 itemTemplate.InvType = (int)InventoryType.LSL;
111
112 m_scene.EventManager.OnChatFromWorld += OnChatFromWorld;
113
114 SceneObjectPart partWhereRezzed = m_scene.RezNewScript(userId, itemTemplate,
115@"default
116{
117 state_entry()
118 {
119 llSay(0, ""Thin Lizzy"");
120 llSleep(60);
121 }
122}");
123
124 TaskInventoryItem rezzedItem = partWhereRezzed.Inventory.GetInventoryItem(itemName);
125
126 // Wait for the script to start the event before we try stopping it.
127 m_chatEvent.WaitOne(60000);
128
129 Console.WriteLine("Script started with message [{0}]", m_osChatMessageReceived.Message);
130
131 // FIXME: This is a very poor way of trying to avoid a low-probability race condition where the script
132 // executes llSay() but has not started the sleep before we try to stop it.
133 Thread.Sleep(1000);
134
135 // We need a way of carrying on if StopScript() fail, since it won't return if the script isn't actually
136 // stopped. This kind of multi-threading is far from ideal in a regression test.
137 new Thread(() => { m_xEngine.StopScript(rezzedItem.ItemID); m_stoppedEvent.Set(); }).Start();
138
139 if (!m_stoppedEvent.WaitOne(30000))
140 Assert.Fail("Script did not co-operatively stop.");
141
142 bool running;
143 TaskInventoryItem scriptItem = partWhereRezzed.Inventory.GetInventoryItem(itemName);
144 Assert.That(
145 SceneObjectPartInventory.TryGetScriptInstanceRunning(m_scene, scriptItem, out running), Is.True);
146 Assert.That(running, Is.False);
147 }
148
149 private void OnChatFromWorld(object sender, OSChatMessage oscm)
150 {
151// Console.WriteLine("Got chat [{0}]", oscm.Message);
152
153 m_osChatMessageReceived = oscm;
154 m_chatEvent.Set();
155 }
156 }
157} \ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs
index cb7291a..36c7582 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs
@@ -41,6 +41,7 @@ using OpenSim.Region.OptionalModules.World.NPC;
41using OpenSim.Region.Framework.Scenes; 41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.ScriptEngine.Shared; 42using OpenSim.Region.ScriptEngine.Shared;
43using OpenSim.Region.ScriptEngine.Shared.Api; 43using OpenSim.Region.ScriptEngine.Shared.Api;
44using OpenSim.Region.ScriptEngine.Shared.Instance;
44using OpenSim.Services.Interfaces; 45using OpenSim.Services.Interfaces;
45using OpenSim.Tests.Common; 46using OpenSim.Tests.Common;
46using OpenSim.Tests.Common.Mock; 47using OpenSim.Tests.Common.Mock;
@@ -93,7 +94,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
93 TaskInventoryHelpers.AddSceneObject(m_scene, so1.RootPart, inventoryItemName, itemId, userId); 94 TaskInventoryHelpers.AddSceneObject(m_scene, so1.RootPart, inventoryItemName, itemId, userId);
94 95
95 LSL_Api api = new LSL_Api(); 96 LSL_Api api = new LSL_Api();
96 api.Initialize(m_engine, so1.RootPart, null); 97 api.Initialize(new ScriptInstance(m_engine, so1.RootPart, null, 0, false, int.MaxValue));
97 98
98 // Create a second object 99 // Create a second object
99 SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, userId, "so2", 0x100); 100 SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, userId, "so2", 0x100);
@@ -126,7 +127,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
126 SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, user1Id, "so1", 0x10); 127 SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, user1Id, "so1", 0x10);
127 m_scene.AddSceneObject(so1); 128 m_scene.AddSceneObject(so1);
128 LSL_Api api = new LSL_Api(); 129 LSL_Api api = new LSL_Api();
129 api.Initialize(m_engine, so1.RootPart, null); 130 api.Initialize(new ScriptInstance(m_engine, so1.RootPart, null, 0, false, int.MaxValue));
130 131
131 // Create an object embedded inside the first 132 // Create an object embedded inside the first
132 UUID itemId = TestHelpers.ParseTail(0x20); 133 UUID itemId = TestHelpers.ParseTail(0x20);
@@ -136,7 +137,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
136 SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, user2Id, "so2", 0x100); 137 SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, user2Id, "so2", 0x100);
137 m_scene.AddSceneObject(so2); 138 m_scene.AddSceneObject(so2);
138 LSL_Api api2 = new LSL_Api(); 139 LSL_Api api2 = new LSL_Api();
139 api2.Initialize(m_engine, so2.RootPart, null); 140 api2.Initialize(new ScriptInstance(m_engine, so2.RootPart, null, 0, false, int.MaxValue));
140 141
141 // *** Firstly, we test where llAllowInventoryDrop() has not been called. *** 142 // *** Firstly, we test where llAllowInventoryDrop() has not been called. ***
142 api.llGiveInventory(so2.UUID.ToString(), inventoryItemName); 143 api.llGiveInventory(so2.UUID.ToString(), inventoryItemName);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs
index d9b17d7..5121344 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiLinkingTests.cs
@@ -41,6 +41,7 @@ using OpenSim.Region.OptionalModules.World.NPC;
41using OpenSim.Region.Framework.Scenes; 41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.ScriptEngine.Shared; 42using OpenSim.Region.ScriptEngine.Shared;
43using OpenSim.Region.ScriptEngine.Shared.Api; 43using OpenSim.Region.ScriptEngine.Shared.Api;
44using OpenSim.Region.ScriptEngine.Shared.Instance;
44using OpenSim.Region.ScriptEngine.Shared.ScriptBase; 45using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
45using OpenSim.Services.Interfaces; 46using OpenSim.Services.Interfaces;
46using OpenSim.Tests.Common; 47using OpenSim.Tests.Common;
@@ -104,7 +105,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
104 m_scene.AddSceneObject(grp2); 105 m_scene.AddSceneObject(grp2);
105 106
106 LSL_Api apiGrp1 = new LSL_Api(); 107 LSL_Api apiGrp1 = new LSL_Api();
107 apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item); 108 apiGrp1.Initialize(new ScriptInstance(m_engine, grp1.RootPart, grp1Item, 0, false, int.MaxValue));
108 109
109 apiGrp1.llCreateLink(grp2.UUID.ToString(), ScriptBaseClass.TRUE); 110 apiGrp1.llCreateLink(grp2.UUID.ToString(), ScriptBaseClass.TRUE);
110 111
@@ -131,7 +132,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
131 grp1Item.PermsMask |= ScriptBaseClass.PERMISSION_CHANGE_LINKS; 132 grp1Item.PermsMask |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
132 133
133 LSL_Api apiGrp1 = new LSL_Api(); 134 LSL_Api apiGrp1 = new LSL_Api();
134 apiGrp1.Initialize(m_engine, grp1.RootPart, grp1Item); 135 apiGrp1.Initialize(new ScriptInstance(m_engine, grp1.RootPart, grp1Item, 0, false, int.MaxValue));
135 136
136 apiGrp1.llBreakLink(2); 137 apiGrp1.llBreakLink(2);
137 138
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs
index 98017d8..28e5831 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs
@@ -34,6 +34,7 @@ using OpenSim.Region.ScriptEngine.Shared;
34using OpenSim.Region.Framework.Scenes; 34using OpenSim.Region.Framework.Scenes;
35using Nini.Config; 35using Nini.Config;
36using OpenSim.Region.ScriptEngine.Shared.Api; 36using OpenSim.Region.ScriptEngine.Shared.Api;
37using OpenSim.Region.ScriptEngine.Shared.Instance;
37using OpenSim.Region.ScriptEngine.Shared.ScriptBase; 38using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
38using OpenMetaverse; 39using OpenMetaverse;
39using OpenSim.Tests.Common.Mock; 40using OpenSim.Tests.Common.Mock;
@@ -67,7 +68,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
67 engine.AddRegion(scene); 68 engine.AddRegion(scene);
68 69
69 m_lslApi = new LSL_Api(); 70 m_lslApi = new LSL_Api();
70 m_lslApi.Initialize(engine, part, null); 71 m_lslApi.Initialize(new ScriptInstance(engine, part, null, 0, false, int.MaxValue));
71 } 72 }
72 73
73 [Test] 74 [Test]
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
index c41d1e7..48c2465 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
@@ -33,6 +33,7 @@ using OpenSim.Region.ScriptEngine.Shared;
33using OpenSim.Region.Framework.Scenes; 33using OpenSim.Region.Framework.Scenes;
34using Nini.Config; 34using Nini.Config;
35using OpenSim.Region.ScriptEngine.Shared.Api; 35using OpenSim.Region.ScriptEngine.Shared.Api;
36using OpenSim.Region.ScriptEngine.Shared.Instance;
36using OpenSim.Region.ScriptEngine.Shared.ScriptBase; 37using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
37using OpenMetaverse; 38using OpenMetaverse;
38using System; 39using System;
@@ -66,7 +67,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
66 engine.AddRegion(scene); 67 engine.AddRegion(scene);
67 68
68 m_lslApi = new LSL_Api(); 69 m_lslApi = new LSL_Api();
69 m_lslApi.Initialize(engine, part, null); 70 m_lslApi.Initialize(new ScriptInstance(engine, part, null, 0, false, int.MaxValue));
70 } 71 }
71 72
72 [Test] 73 [Test]
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs
index 1381d2b..5164d4e 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs
@@ -41,6 +41,7 @@ using OpenSim.Region.OptionalModules.World.NPC;
41using OpenSim.Region.Framework.Scenes; 41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.ScriptEngine.Shared; 42using OpenSim.Region.ScriptEngine.Shared;
43using OpenSim.Region.ScriptEngine.Shared.Api; 43using OpenSim.Region.ScriptEngine.Shared.Api;
44using OpenSim.Region.ScriptEngine.Shared.Instance;
44using OpenSim.Services.Interfaces; 45using OpenSim.Services.Interfaces;
45using OpenSim.Tests.Common; 46using OpenSim.Tests.Common;
46using OpenSim.Tests.Common.Mock; 47using OpenSim.Tests.Common.Mock;
@@ -93,7 +94,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
93 m_scene.AddSceneObject(so); 94 m_scene.AddSceneObject(so);
94 95
95 OSSL_Api osslApi = new OSSL_Api(); 96 OSSL_Api osslApi = new OSSL_Api();
96 osslApi.Initialize(m_engine, part, null); 97 osslApi.Initialize(new ScriptInstance(m_engine, part, null, 0, false, int.MaxValue));
97 98
98 string notecardName = "appearanceNc"; 99 string notecardName = "appearanceNc";
99 100
@@ -134,7 +135,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
134 m_scene.AddSceneObject(so); 135 m_scene.AddSceneObject(so);
135 136
136 OSSL_Api osslApi = new OSSL_Api(); 137 OSSL_Api osslApi = new OSSL_Api();
137 osslApi.Initialize(m_engine, part, null); 138 osslApi.Initialize(new ScriptInstance(m_engine, part, null, 0, false, int.MaxValue));
138 139
139 string notecardName = "appearanceNc"; 140 string notecardName = "appearanceNc";
140 141
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs
index 5ed1f3d..e7b3319 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAttachmentTests.cs
@@ -41,6 +41,7 @@ using OpenSim.Region.CoreModules.Framework.InventoryAccess;
41using OpenSim.Region.Framework.Scenes; 41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.ScriptEngine.Shared; 42using OpenSim.Region.ScriptEngine.Shared;
43using OpenSim.Region.ScriptEngine.Shared.Api; 43using OpenSim.Region.ScriptEngine.Shared.Api;
44using OpenSim.Region.ScriptEngine.Shared.Instance;
44using OpenSim.Services.Interfaces; 45using OpenSim.Services.Interfaces;
45using OpenSim.Tests.Common; 46using OpenSim.Tests.Common;
46using OpenSim.Tests.Common.Mock; 47using OpenSim.Tests.Common.Mock;
@@ -98,9 +99,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
98 SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID); 99 SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID);
99 TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart); 100 TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart);
100 101
101 new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem); 102 ScriptInstance si = new ScriptInstance(m_engine, inWorldObj.RootPart, scriptItem, 0, false, int.MaxValue);
103 new LSL_Api().Initialize(si);
102 OSSL_Api osslApi = new OSSL_Api(); 104 OSSL_Api osslApi = new OSSL_Api();
103 osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem); 105 osslApi.Initialize(si);
104 106
105// SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, ua1.PrincipalID); 107// SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, ua1.PrincipalID);
106 108
@@ -144,9 +146,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
144 SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID); 146 SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID);
145 TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart); 147 TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart);
146 148
147 new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem); 149 ScriptInstance si = new ScriptInstance(m_engine, inWorldObj.RootPart, scriptItem, 0, false, int.MaxValue);
150 new LSL_Api().Initialize(si);
148 OSSL_Api osslApi = new OSSL_Api(); 151 OSSL_Api osslApi = new OSSL_Api();
149 osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem); 152 osslApi.Initialize(si);
150 153
151 // Create an object embedded inside the first 154 // Create an object embedded inside the first
152 TaskInventoryHelpers.AddNotecard( 155 TaskInventoryHelpers.AddNotecard(
@@ -192,12 +195,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
192 SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID); 195 SceneObjectGroup inWorldObj = SceneHelpers.AddSceneObject(m_scene, "inWorldObj", ua1.PrincipalID);
193 TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart); 196 TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene, inWorldObj.RootPart);
194 197
195 new LSL_Api().Initialize(m_engine, inWorldObj.RootPart, scriptItem); 198 ScriptInstance si = new ScriptInstance(m_engine, inWorldObj.RootPart, scriptItem, 0, false, int.MaxValue);
199 new LSL_Api().Initialize(si);
196 OSSL_Api osslApi = new OSSL_Api(); 200 OSSL_Api osslApi = new OSSL_Api();
197 osslApi.Initialize(m_engine, inWorldObj.RootPart, scriptItem); 201 osslApi.Initialize(si);
198 202
199 // Create an object embedded inside the first 203 // Create an object embedded inside the first
200 TaskInventoryHelpers.AddSceneObject(m_scene, inWorldObj.RootPart, taskInvObjItemName, taskInvObjItemId, ua1.PrincipalID); 204 TaskInventoryHelpers.AddSceneObject(
205 m_scene, inWorldObj.RootPart, taskInvObjItemName, taskInvObjItemId, ua1.PrincipalID);
201 206
202 ScenePresence sp2 = SceneHelpers.AddScenePresence(m_scene, ua2); 207 ScenePresence sp2 = SceneHelpers.AddScenePresence(m_scene, ua2);
203 208
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs
index d6c82f1..584f44f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs
@@ -42,6 +42,7 @@ using OpenSim.Region.OptionalModules.World.NPC;
42using OpenSim.Region.Framework.Scenes; 42using OpenSim.Region.Framework.Scenes;
43using OpenSim.Region.ScriptEngine.Shared; 43using OpenSim.Region.ScriptEngine.Shared;
44using OpenSim.Region.ScriptEngine.Shared.Api; 44using OpenSim.Region.ScriptEngine.Shared.Api;
45using OpenSim.Region.ScriptEngine.Shared.Instance;
45using OpenSim.Region.ScriptEngine.Shared.ScriptBase; 46using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
46using OpenSim.Services.Interfaces; 47using OpenSim.Services.Interfaces;
47using OpenSim.Tests.Common; 48using OpenSim.Tests.Common;
@@ -99,7 +100,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
99 m_scene.AddSceneObject(so); 100 m_scene.AddSceneObject(so);
100 101
101 OSSL_Api osslApi = new OSSL_Api(); 102 OSSL_Api osslApi = new OSSL_Api();
102 osslApi.Initialize(m_engine, part, null); 103 osslApi.Initialize(new ScriptInstance(m_engine, part, null, 0, false, int.MaxValue));
103 104
104 string notecardName = "appearanceNc"; 105 string notecardName = "appearanceNc";
105 osslApi.osOwnerSaveAppearance(notecardName); 106 osslApi.osOwnerSaveAppearance(notecardName);
@@ -125,7 +126,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
125 m_scene.AddSceneObject(so); 126 m_scene.AddSceneObject(so);
126 127
127 OSSL_Api osslApi = new OSSL_Api(); 128 OSSL_Api osslApi = new OSSL_Api();
128 osslApi.Initialize(m_engine, so.RootPart, null); 129 osslApi.Initialize(new ScriptInstance(m_engine, so.RootPart, null, 0, false, int.MaxValue));
129 130
130 bool gotExpectedException = false; 131 bool gotExpectedException = false;
131 try 132 try
@@ -160,7 +161,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
160 m_scene.AddSceneObject(so); 161 m_scene.AddSceneObject(so);
161 162
162 OSSL_Api osslApi = new OSSL_Api(); 163 OSSL_Api osslApi = new OSSL_Api();
163 osslApi.Initialize(m_engine, part, null); 164 osslApi.Initialize(new ScriptInstance(m_engine, part, null, 0, false, int.MaxValue));
164 165
165 string notecardName = "appearanceNc"; 166 string notecardName = "appearanceNc";
166 osslApi.osOwnerSaveAppearance(notecardName); 167 osslApi.osOwnerSaveAppearance(notecardName);
@@ -194,7 +195,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
194 m_scene.AddSceneObject(so); 195 m_scene.AddSceneObject(so);
195 196
196 OSSL_Api osslApi = new OSSL_Api(); 197 OSSL_Api osslApi = new OSSL_Api();
197 osslApi.Initialize(m_engine, part, null); 198 osslApi.Initialize(new ScriptInstance(m_engine, part, null, 0, false, int.MaxValue));
198 199
199 osslApi.osOwnerSaveAppearance(firstAppearanceNcName); 200 osslApi.osOwnerSaveAppearance(firstAppearanceNcName);
200 201
@@ -232,7 +233,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
232 m_scene.AddSceneObject(so); 233 m_scene.AddSceneObject(so);
233 234
234 OSSL_Api osslApi = new OSSL_Api(); 235 OSSL_Api osslApi = new OSSL_Api();
235 osslApi.Initialize(m_engine, part, null); 236 osslApi.Initialize(new ScriptInstance(m_engine, part, null, 0, false, int.MaxValue));
236 237
237 osslApi.osOwnerSaveAppearance(firstAppearanceNcName); 238 osslApi.osOwnerSaveAppearance(firstAppearanceNcName);
238 239
@@ -284,10 +285,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
284 m_scene.AddSceneObject(otherSo); 285 m_scene.AddSceneObject(otherSo);
285 286
286 OSSL_Api osslApi = new OSSL_Api(); 287 OSSL_Api osslApi = new OSSL_Api();
287 osslApi.Initialize(m_engine, part, null); 288 osslApi.Initialize(new ScriptInstance(m_engine, part, null, 0, false, int.MaxValue));
288 289
289 OSSL_Api otherOsslApi = new OSSL_Api(); 290 OSSL_Api otherOsslApi = new OSSL_Api();
290 otherOsslApi.Initialize(m_engine, otherPart, null); 291 otherOsslApi.Initialize(new ScriptInstance(m_engine, otherPart, null, 0, false, int.MaxValue));
291 292
292 string notecardName = "appearanceNc"; 293 string notecardName = "appearanceNc";
293 osslApi.osOwnerSaveAppearance(notecardName); 294 osslApi.osOwnerSaveAppearance(notecardName);
@@ -331,7 +332,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
331 m_scene.AddSceneObject(so); 332 m_scene.AddSceneObject(so);
332 333
333 OSSL_Api osslApi = new OSSL_Api(); 334 OSSL_Api osslApi = new OSSL_Api();
334 osslApi.Initialize(m_engine, part, null); 335 osslApi.Initialize(new ScriptInstance(m_engine, part, null, 0, false, int.MaxValue));
335 336
336 string notecardName = "appearanceNc"; 337 string notecardName = "appearanceNc";
337 osslApi.osOwnerSaveAppearance(notecardName); 338 osslApi.osOwnerSaveAppearance(notecardName);
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 8c3bb5b..a17a018 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -1284,11 +1284,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1284 m_DomainScripts[appDomain].Add(itemID); 1284 m_DomainScripts[appDomain].Add(itemID);
1285 1285
1286 instance = new ScriptInstance(this, part, 1286 instance = new ScriptInstance(this, part,
1287 itemID, assetID, assembly, 1287 item,
1288 m_AppDomains[appDomain], 1288 startParam, postOnRez,
1289 part.ParentGroup.RootPart.Name, 1289 m_MaxScriptQueue);
1290 item.Name, startParam, postOnRez, 1290
1291 stateSource, m_MaxScriptQueue); 1291 instance.Load(m_AppDomains[appDomain], assembly, stateSource);
1292 1292
1293// if (DebugLevel >= 1) 1293// if (DebugLevel >= 1)
1294// m_log.DebugFormat( 1294// m_log.DebugFormat(
@@ -1716,9 +1716,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1716 IScriptInstance instance = GetInstance(itemID); 1716 IScriptInstance instance = GetInstance(itemID);
1717 1717
1718 if (instance != null) 1718 if (instance != null)
1719 {
1719 instance.Stop(m_WaitForEventCompletionOnScriptStop); 1720 instance.Stop(m_WaitForEventCompletionOnScriptStop);
1721 }
1720 else 1722 else
1723 {
1724// m_log.DebugFormat("[XENGINE]: Could not find script with ID {0} to stop in {1}", itemID, World.Name);
1721 m_runFlags.AddOrUpdate(itemID, false, 240); 1725 m_runFlags.AddOrUpdate(itemID, false, 240);
1726 }
1722 } 1727 }
1723 1728
1724 public DetectParams GetDetectParams(UUID itemID, int idx) 1729 public DetectParams GetDetectParams(UUID itemID, int idx)