diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine')
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/Api/Runtime/XEngineScriptBase.cs | 61 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/EventManager.cs | 10 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/Properties/AssemblyInfo.cs | 4 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/ScriptEngineConsoleCommands.cs | 126 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineBasicTests.cs (renamed from OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs) | 2 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 271 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/XWorkItem.cs | 6 |
7 files changed, 395 insertions, 85 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Api/Runtime/XEngineScriptBase.cs b/OpenSim/Region/ScriptEngine/XEngine/Api/Runtime/XEngineScriptBase.cs new file mode 100644 index 0000000..f4211c8 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/XEngine/Api/Runtime/XEngineScriptBase.cs | |||
@@ -0,0 +1,61 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Runtime.Remoting; | ||
30 | using System.Runtime.Remoting.Lifetime; | ||
31 | using System.Security.Permissions; | ||
32 | using System.Threading; | ||
33 | using System.Reflection; | ||
34 | using System.Collections; | ||
35 | using System.Collections.Generic; | ||
36 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
37 | using OpenSim.Region.ScriptEngine.Shared; | ||
38 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | ||
39 | |||
40 | namespace OpenSim.Region.ScriptEngine.XEngine.ScriptBase | ||
41 | { | ||
42 | public class XEngineScriptBase : ScriptBaseClass | ||
43 | { | ||
44 | /// <summary> | ||
45 | /// Used for script sleeps when we are using co-operative script termination. | ||
46 | /// </summary> | ||
47 | /// <remarks>null if co-operative script termination is not active</remarks> | ||
48 | WaitHandle m_coopSleepHandle; | ||
49 | |||
50 | public XEngineScriptBase(WaitHandle coopSleepHandle) : base() | ||
51 | { | ||
52 | m_coopSleepHandle = coopSleepHandle; | ||
53 | } | ||
54 | |||
55 | public void opensim_reserved_CheckForCoopTermination() | ||
56 | { | ||
57 | if (m_coopSleepHandle != null && m_coopSleepHandle.WaitOne(0)) | ||
58 | throw new ScriptCoopStopException(); | ||
59 | } | ||
60 | } | ||
61 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs index 9405075..0ff2da3 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs | |||
@@ -52,7 +52,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
52 | { | 52 | { |
53 | myScriptEngine = _ScriptEngine; | 53 | myScriptEngine = _ScriptEngine; |
54 | 54 | ||
55 | m_log.Info("[XEngine] Hooking up to server events"); | 55 | // m_log.Info("[XEngine] Hooking up to server events"); |
56 | myScriptEngine.World.EventManager.OnAttach += attach; | 56 | myScriptEngine.World.EventManager.OnAttach += attach; |
57 | myScriptEngine.World.EventManager.OnObjectGrab += touch_start; | 57 | myScriptEngine.World.EventManager.OnObjectGrab += touch_start; |
58 | myScriptEngine.World.EventManager.OnObjectGrabbing += touch; | 58 | myScriptEngine.World.EventManager.OnObjectGrabbing += touch; |
@@ -62,6 +62,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
62 | myScriptEngine.World.EventManager.OnScriptNotAtTargetEvent += not_at_target; | 62 | myScriptEngine.World.EventManager.OnScriptNotAtTargetEvent += not_at_target; |
63 | myScriptEngine.World.EventManager.OnScriptAtRotTargetEvent += at_rot_target; | 63 | myScriptEngine.World.EventManager.OnScriptAtRotTargetEvent += at_rot_target; |
64 | myScriptEngine.World.EventManager.OnScriptNotAtRotTargetEvent += not_at_rot_target; | 64 | myScriptEngine.World.EventManager.OnScriptNotAtRotTargetEvent += not_at_rot_target; |
65 | myScriptEngine.World.EventManager.OnScriptMovingStartEvent += moving_start; | ||
66 | myScriptEngine.World.EventManager.OnScriptMovingEndEvent += moving_end; | ||
65 | myScriptEngine.World.EventManager.OnScriptControlEvent += control; | 67 | myScriptEngine.World.EventManager.OnScriptControlEvent += control; |
66 | myScriptEngine.World.EventManager.OnScriptColliderStart += collision_start; | 68 | myScriptEngine.World.EventManager.OnScriptColliderStart += collision_start; |
67 | myScriptEngine.World.EventManager.OnScriptColliding += collision; | 69 | myScriptEngine.World.EventManager.OnScriptColliding += collision; |
@@ -69,7 +71,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
69 | myScriptEngine.World.EventManager.OnScriptLandColliderStart += land_collision_start; | 71 | myScriptEngine.World.EventManager.OnScriptLandColliderStart += land_collision_start; |
70 | myScriptEngine.World.EventManager.OnScriptLandColliding += land_collision; | 72 | myScriptEngine.World.EventManager.OnScriptLandColliding += land_collision; |
71 | myScriptEngine.World.EventManager.OnScriptLandColliderEnd += land_collision_end; | 73 | myScriptEngine.World.EventManager.OnScriptLandColliderEnd += land_collision_end; |
72 | IMoneyModule money=myScriptEngine.World.RequestModuleInterface<IMoneyModule>(); | 74 | IMoneyModule money = myScriptEngine.World.RequestModuleInterface<IMoneyModule>(); |
73 | if (money != null) | 75 | if (money != null) |
74 | { | 76 | { |
75 | money.OnObjectPaid+=HandleObjectPaid; | 77 | money.OnObjectPaid+=HandleObjectPaid; |
@@ -419,14 +421,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
419 | // dataserver: not handled here | 421 | // dataserver: not handled here |
420 | // link_message: not handled here | 422 | // link_message: not handled here |
421 | 423 | ||
422 | public void moving_start(uint localID, UUID itemID) | 424 | public void moving_start(uint localID) |
423 | { | 425 | { |
424 | myScriptEngine.PostObjectEvent(localID, new EventParams( | 426 | myScriptEngine.PostObjectEvent(localID, new EventParams( |
425 | "moving_start",new object[0], | 427 | "moving_start",new object[0], |
426 | new DetectParams[0])); | 428 | new DetectParams[0])); |
427 | } | 429 | } |
428 | 430 | ||
429 | public void moving_end(uint localID, UUID itemID) | 431 | public void moving_end(uint localID) |
430 | { | 432 | { |
431 | myScriptEngine.PostObjectEvent(localID, new EventParams( | 433 | myScriptEngine.PostObjectEvent(localID, new EventParams( |
432 | "moving_end",new object[0], | 434 | "moving_end",new object[0], |
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Properties/AssemblyInfo.cs b/OpenSim/Region/ScriptEngine/XEngine/Properties/AssemblyInfo.cs index bd26a8b..f0640da 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/Properties/AssemblyInfo.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/Properties/AssemblyInfo.cs | |||
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices; | |||
29 | // Build Number | 29 | // Build Number |
30 | // Revision | 30 | // Revision |
31 | // | 31 | // |
32 | [assembly: AssemblyVersion("0.7.5.*")] | 32 | [assembly: AssemblyVersion("0.7.6.*")] |
33 | [assembly: AssemblyFileVersion("1.0.0.0")] | 33 | |
diff --git a/OpenSim/Region/ScriptEngine/XEngine/ScriptEngineConsoleCommands.cs b/OpenSim/Region/ScriptEngine/XEngine/ScriptEngineConsoleCommands.cs new file mode 100644 index 0000000..efb854d --- /dev/null +++ b/OpenSim/Region/ScriptEngine/XEngine/ScriptEngineConsoleCommands.cs | |||
@@ -0,0 +1,126 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenSim.Framework; | ||
31 | using OpenSim.Framework.Console; | ||
32 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
33 | using OpenSim.Region.ScriptEngine.Shared.Api; | ||
34 | using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; | ||
35 | |||
36 | namespace OpenSim.Region.ScriptEngine.XEngine | ||
37 | { | ||
38 | public class ScriptEngineConsoleCommands | ||
39 | { | ||
40 | IScriptEngine m_engine; | ||
41 | |||
42 | public ScriptEngineConsoleCommands(IScriptEngine engine) | ||
43 | { | ||
44 | m_engine = engine; | ||
45 | } | ||
46 | |||
47 | public void RegisterCommands() | ||
48 | { | ||
49 | MainConsole.Instance.Commands.AddCommand( | ||
50 | "Scripts", false, "show script sensors", "show script sensors", "Show script sensors information", | ||
51 | HandleShowSensors); | ||
52 | |||
53 | MainConsole.Instance.Commands.AddCommand( | ||
54 | "Scripts", false, "show script timers", "show script timers", "Show script sensors information", | ||
55 | HandleShowTimers); | ||
56 | } | ||
57 | |||
58 | private bool IsSceneSelected() | ||
59 | { | ||
60 | return MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_engine.World; | ||
61 | } | ||
62 | |||
63 | private void HandleShowSensors(string module, string[] cmdparams) | ||
64 | { | ||
65 | if (!IsSceneSelected()) | ||
66 | return; | ||
67 | |||
68 | SensorRepeat sr = AsyncCommandManager.GetSensorRepeatPlugin(m_engine); | ||
69 | |||
70 | if (sr == null) | ||
71 | { | ||
72 | MainConsole.Instance.Output("Plugin not yet initialized"); | ||
73 | return; | ||
74 | } | ||
75 | |||
76 | List<SensorRepeat.SensorInfo> sensorInfo = sr.GetSensorInfo(); | ||
77 | |||
78 | ConsoleDisplayTable cdt = new ConsoleDisplayTable(); | ||
79 | cdt.AddColumn("Part name", 40); | ||
80 | cdt.AddColumn("Script item ID", 36); | ||
81 | cdt.AddColumn("Type", 4); | ||
82 | cdt.AddColumn("Interval", 8); | ||
83 | cdt.AddColumn("Range", 8); | ||
84 | cdt.AddColumn("Arc", 8); | ||
85 | |||
86 | foreach (SensorRepeat.SensorInfo s in sensorInfo) | ||
87 | { | ||
88 | cdt.AddRow(s.host.Name, s.itemID, s.type, s.interval, s.range, s.arc); | ||
89 | } | ||
90 | |||
91 | MainConsole.Instance.Output(cdt.ToString()); | ||
92 | MainConsole.Instance.OutputFormat("Total: {0}", sensorInfo.Count); | ||
93 | } | ||
94 | |||
95 | private void HandleShowTimers(string module, string[] cmdparams) | ||
96 | { | ||
97 | if (!IsSceneSelected()) | ||
98 | return; | ||
99 | |||
100 | Timer timerPlugin = AsyncCommandManager.GetTimerPlugin(m_engine); | ||
101 | |||
102 | if (timerPlugin == null) | ||
103 | { | ||
104 | MainConsole.Instance.Output("Plugin not yet initialized"); | ||
105 | return; | ||
106 | } | ||
107 | |||
108 | List<Timer.TimerInfo> timersInfo = timerPlugin.GetTimersInfo(); | ||
109 | |||
110 | ConsoleDisplayTable cdt = new ConsoleDisplayTable(); | ||
111 | cdt.AddColumn("Part local ID", 13); | ||
112 | cdt.AddColumn("Script item ID", 36); | ||
113 | cdt.AddColumn("Interval", 10); | ||
114 | cdt.AddColumn("Next", 8); | ||
115 | |||
116 | foreach (Timer.TimerInfo t in timersInfo) | ||
117 | { | ||
118 | // Convert from 100 ns ticks back to seconds | ||
119 | cdt.AddRow(t.localID, t.itemID, (double)t.interval / 10000000, t.next); | ||
120 | } | ||
121 | |||
122 | MainConsole.Instance.Output(cdt.ToString()); | ||
123 | MainConsole.Instance.OutputFormat("Total: {0}", timersInfo.Count); | ||
124 | } | ||
125 | } | ||
126 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineBasicTests.cs index f331658..5abfe9a 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineBasicTests.cs | |||
@@ -44,7 +44,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine.Tests | |||
44 | /// XEngine tests. | 44 | /// XEngine tests. |
45 | /// </summary> | 45 | /// </summary> |
46 | [TestFixture] | 46 | [TestFixture] |
47 | public class XEngineTest | 47 | public class XEngineTest : OpenSimTestCase |
48 | { | 48 | { |
49 | private TestScene m_scene; | 49 | private TestScene m_scene; |
50 | private XEngine m_xEngine; | 50 | private XEngine m_xEngine; |
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 9f05666..17243ab 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | |||
@@ -31,6 +31,7 @@ using System.Collections.Generic; | |||
31 | using System.Diagnostics; //for [DebuggerNonUserCode] | 31 | using System.Diagnostics; //for [DebuggerNonUserCode] |
32 | using System.Globalization; | 32 | using System.Globalization; |
33 | using System.IO; | 33 | using System.IO; |
34 | using System.Linq; | ||
34 | using System.Reflection; | 35 | using System.Reflection; |
35 | using System.Security; | 36 | using System.Security; |
36 | using System.Security.Policy; | 37 | using System.Security.Policy; |
@@ -46,13 +47,14 @@ using OpenSim.Framework; | |||
46 | using OpenSim.Framework.Console; | 47 | using OpenSim.Framework.Console; |
47 | using OpenSim.Region.Framework.Scenes; | 48 | using OpenSim.Region.Framework.Scenes; |
48 | using OpenSim.Region.Framework.Interfaces; | 49 | using OpenSim.Region.Framework.Interfaces; |
50 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
49 | using OpenSim.Region.ScriptEngine.Shared; | 51 | using OpenSim.Region.ScriptEngine.Shared; |
50 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | ||
51 | using OpenSim.Region.ScriptEngine.Shared.CodeTools; | 52 | using OpenSim.Region.ScriptEngine.Shared.CodeTools; |
52 | using OpenSim.Region.ScriptEngine.Shared.Instance; | 53 | using OpenSim.Region.ScriptEngine.Shared.Instance; |
53 | using OpenSim.Region.ScriptEngine.Shared.Api; | 54 | using OpenSim.Region.ScriptEngine.Shared.Api; |
54 | using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; | 55 | using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; |
55 | using OpenSim.Region.ScriptEngine.Interfaces; | 56 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; |
57 | using OpenSim.Region.ScriptEngine.XEngine.ScriptBase; | ||
56 | using Timer = OpenSim.Region.ScriptEngine.Shared.Api.Plugins.Timer; | 58 | using Timer = OpenSim.Region.ScriptEngine.Shared.Api.Plugins.Timer; |
57 | 59 | ||
58 | using ScriptCompileQueue = OpenSim.Framework.LocklessQueue<object[]>; | 60 | using ScriptCompileQueue = OpenSim.Framework.LocklessQueue<object[]>; |
@@ -107,6 +109,24 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
107 | private IXmlRpcRouter m_XmlRpcRouter; | 109 | private IXmlRpcRouter m_XmlRpcRouter; |
108 | private int m_EventLimit; | 110 | private int m_EventLimit; |
109 | private bool m_KillTimedOutScripts; | 111 | private bool m_KillTimedOutScripts; |
112 | |||
113 | /// <summary> | ||
114 | /// Number of milliseconds we will wait for a script event to complete on script stop before we forcibly abort | ||
115 | /// its thread. | ||
116 | /// </summary> | ||
117 | /// <remarks> | ||
118 | /// It appears that if a script thread is aborted whilst it is holding ReaderWriterLockSlim (possibly the write | ||
119 | /// lock) then the lock is not properly released. This causes mono 2.6, 2.10 and possibly | ||
120 | /// later to crash, sometimes with symptoms such as a leap to 100% script usage and a vm thead dump showing | ||
121 | /// all threads waiting on release of ReaderWriterLockSlim write thread which none of the threads listed | ||
122 | /// actually hold. | ||
123 | /// | ||
124 | /// Pausing for event completion reduces the risk of this happening. However, it may be that aborting threads | ||
125 | /// is not a mono issue per se but rather a risky activity in itself in an AppDomain that is not immediately | ||
126 | /// shutting down. | ||
127 | /// </remarks> | ||
128 | private int m_WaitForEventCompletionOnScriptStop = 1000; | ||
129 | |||
110 | private string m_ScriptEnginesPath = null; | 130 | private string m_ScriptEnginesPath = null; |
111 | 131 | ||
112 | private ExpiringCache<UUID, bool> m_runFlags = new ExpiringCache<UUID, bool>(); | 132 | private ExpiringCache<UUID, bool> m_runFlags = new ExpiringCache<UUID, bool>(); |
@@ -218,11 +238,21 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
218 | } | 238 | } |
219 | } | 239 | } |
220 | 240 | ||
241 | private ScriptEngineConsoleCommands m_consoleCommands; | ||
242 | |||
221 | public string ScriptEngineName | 243 | public string ScriptEngineName |
222 | { | 244 | { |
223 | get { return "XEngine"; } | 245 | get { return "XEngine"; } |
224 | } | 246 | } |
225 | 247 | ||
248 | public string ScriptClassName { get; private set; } | ||
249 | |||
250 | public string ScriptBaseClassName { get; private set; } | ||
251 | |||
252 | public ParameterInfo[] ScriptBaseClassParameters { get; private set; } | ||
253 | |||
254 | public string[] ScriptReferencedAssemblies { get; private set; } | ||
255 | |||
226 | public Scene World | 256 | public Scene World |
227 | { | 257 | { |
228 | get { return m_Scene; } | 258 | get { return m_Scene; } |
@@ -277,21 +307,35 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
277 | 307 | ||
278 | m_ScriptConfig = configSource.Configs["XEngine"]; | 308 | m_ScriptConfig = configSource.Configs["XEngine"]; |
279 | m_ConfigSource = configSource; | 309 | m_ConfigSource = configSource; |
310 | |||
311 | string rawScriptStopStrategy = m_ScriptConfig.GetString("ScriptStopStrategy", "abort"); | ||
312 | |||
313 | m_log.InfoFormat("[XEngine]: Script stop strategy is {0}", rawScriptStopStrategy); | ||
314 | |||
315 | if (rawScriptStopStrategy == "co-op") | ||
316 | { | ||
317 | ScriptClassName = "XEngineScript"; | ||
318 | ScriptBaseClassName = typeof(XEngineScriptBase).FullName; | ||
319 | ScriptBaseClassParameters = typeof(XEngineScriptBase).GetConstructor(new Type[] { typeof(WaitHandle) }).GetParameters(); | ||
320 | ScriptReferencedAssemblies = new string[] { Path.GetFileName(typeof(XEngineScriptBase).Assembly.Location) }; | ||
321 | } | ||
322 | else | ||
323 | { | ||
324 | ScriptClassName = "Script"; | ||
325 | ScriptBaseClassName = typeof(ScriptBaseClass).FullName; | ||
326 | } | ||
327 | |||
328 | // Console.WriteLine("ASSEMBLY NAME: {0}", ScriptReferencedAssemblies[0]); | ||
280 | } | 329 | } |
281 | 330 | ||
282 | public void AddRegion(Scene scene) | 331 | public void AddRegion(Scene scene) |
283 | { | 332 | { |
284 | if (m_ScriptConfig == null) | 333 | if (m_ScriptConfig == null) |
285 | return; | 334 | return; |
335 | |||
286 | m_ScriptFailCount = 0; | 336 | m_ScriptFailCount = 0; |
287 | m_ScriptErrorMessage = String.Empty; | 337 | m_ScriptErrorMessage = String.Empty; |
288 | 338 | ||
289 | if (m_ScriptConfig == null) | ||
290 | { | ||
291 | // m_log.ErrorFormat("[XEngine] No script configuration found. Scripts disabled"); | ||
292 | return; | ||
293 | } | ||
294 | |||
295 | m_Enabled = m_ScriptConfig.GetBoolean("Enabled", true); | 339 | m_Enabled = m_ScriptConfig.GetBoolean("Enabled", true); |
296 | 340 | ||
297 | if (!m_Enabled) | 341 | if (!m_Enabled) |
@@ -316,6 +360,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
316 | m_EventLimit = m_ScriptConfig.GetInt("EventLimit", 30); | 360 | m_EventLimit = m_ScriptConfig.GetInt("EventLimit", 30); |
317 | m_KillTimedOutScripts = m_ScriptConfig.GetBoolean("KillTimedOutScripts", false); | 361 | m_KillTimedOutScripts = m_ScriptConfig.GetBoolean("KillTimedOutScripts", false); |
318 | m_SaveTime = m_ScriptConfig.GetInt("SaveInterval", 120) * 1000; | 362 | m_SaveTime = m_ScriptConfig.GetInt("SaveInterval", 120) * 1000; |
363 | m_WaitForEventCompletionOnScriptStop | ||
364 | = m_ScriptConfig.GetInt("WaitForEventCompletionOnScriptStop", m_WaitForEventCompletionOnScriptStop); | ||
365 | |||
319 | m_ScriptEnginesPath = m_ScriptConfig.GetString("ScriptEnginesPath", "ScriptEngines"); | 366 | m_ScriptEnginesPath = m_ScriptConfig.GetString("ScriptEnginesPath", "ScriptEngines"); |
320 | 367 | ||
321 | m_Prio = ThreadPriority.BelowNormal; | 368 | m_Prio = ThreadPriority.BelowNormal; |
@@ -364,48 +411,59 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
364 | OnObjectRemoved += m_XmlRpcRouter.ObjectRemoved; | 411 | OnObjectRemoved += m_XmlRpcRouter.ObjectRemoved; |
365 | } | 412 | } |
366 | 413 | ||
414 | m_consoleCommands = new ScriptEngineConsoleCommands(this); | ||
415 | m_consoleCommands.RegisterCommands(); | ||
416 | |||
367 | MainConsole.Instance.Commands.AddCommand( | 417 | MainConsole.Instance.Commands.AddCommand( |
368 | "Scripts", false, "xengine status", "xengine status", "Show status information", | 418 | "Scripts", false, "xengine status", "xengine status", "Show status information", |
369 | "Show status information on the script engine.", | 419 | "Show status information on the script engine.", |
370 | HandleShowStatus); | 420 | HandleShowStatus); |
371 | 421 | ||
372 | MainConsole.Instance.Commands.AddCommand( | 422 | MainConsole.Instance.Commands.AddCommand( |
373 | "Scripts", false, "scripts show", "scripts show [<script-item-uuid>]", "Show script information", | 423 | "Scripts", false, "scripts show", "scripts show [<script-item-uuid>+]", "Show script information", |
374 | "Show information on all scripts known to the script engine." | 424 | "Show information on all scripts known to the script engine.\n" |
375 | + "If a <script-item-uuid> is given then only information on that script will be shown.", | 425 | + "If one or more <script-item-uuid>s are given then only information on that script will be shown.", |
376 | HandleShowScripts); | 426 | HandleShowScripts); |
377 | 427 | ||
378 | MainConsole.Instance.Commands.AddCommand( | 428 | MainConsole.Instance.Commands.AddCommand( |
379 | "Scripts", false, "show scripts", "show scripts [<script-item-uuid>]", "Show script information", | 429 | "Scripts", false, "show scripts", "show scripts [<script-item-uuid>+]", "Show script information", |
380 | "Synonym for scripts show command", HandleShowScripts); | 430 | "Synonym for scripts show command", HandleShowScripts); |
381 | 431 | ||
382 | MainConsole.Instance.Commands.AddCommand( | 432 | MainConsole.Instance.Commands.AddCommand( |
383 | "Scripts", false, "scripts suspend", "scripts suspend [<script-item-uuid>]", "Suspends all running scripts", | 433 | "Scripts", false, "scripts suspend", "scripts suspend [<script-item-uuid>+]", "Suspends all running scripts", |
384 | "Suspends all currently running scripts. This only suspends event delivery, it will not suspend a" | 434 | "Suspends all currently running scripts. This only suspends event delivery, it will not suspend a" |
385 | + " script that is currently processing an event.\n" | 435 | + " script that is currently processing an event.\n" |
386 | + "Suspended scripts will continue to accumulate events but won't process them.\n" | 436 | + "Suspended scripts will continue to accumulate events but won't process them.\n" |
387 | + "If a <script-item-uuid> is given then only that script will be suspended. Otherwise, all suitable scripts are suspended.", | 437 | + "If one or more <script-item-uuid>s are given then only that script will be suspended. Otherwise, all suitable scripts are suspended.", |
388 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleSuspendScript)); | 438 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleSuspendScript)); |
389 | 439 | ||
390 | MainConsole.Instance.Commands.AddCommand( | 440 | MainConsole.Instance.Commands.AddCommand( |
391 | "Scripts", false, "scripts resume", "scripts resume [<script-item-uuid>]", "Resumes all suspended scripts", | 441 | "Scripts", false, "scripts resume", "scripts resume [<script-item-uuid>+]", "Resumes all suspended scripts", |
392 | "Resumes all currently suspended scripts.\n" | 442 | "Resumes all currently suspended scripts.\n" |
393 | + "Resumed scripts will process all events accumulated whilst suspended." | 443 | + "Resumed scripts will process all events accumulated whilst suspended.\n" |
394 | + "If a <script-item-uuid> is given then only that script will be resumed. Otherwise, all suitable scripts are resumed.", | 444 | + "If one or more <script-item-uuid>s are given then only that script will be resumed. Otherwise, all suitable scripts are resumed.", |
395 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleResumeScript)); | 445 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleResumeScript)); |
396 | 446 | ||
397 | MainConsole.Instance.Commands.AddCommand( | 447 | MainConsole.Instance.Commands.AddCommand( |
398 | "Scripts", false, "scripts stop", "scripts stop [<script-item-uuid>]", "Stops all running scripts", | 448 | "Scripts", false, "scripts stop", "scripts stop [<script-item-uuid>+]", "Stops all running scripts", |
399 | "Stops all running scripts." | 449 | "Stops all running scripts.\n" |
400 | + "If a <script-item-uuid> is given then only that script will be stopped. Otherwise, all suitable scripts are stopped.", | 450 | + "If one or more <script-item-uuid>s are given then only that script will be stopped. Otherwise, all suitable scripts are stopped.", |
401 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStopScript)); | 451 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStopScript)); |
402 | 452 | ||
403 | MainConsole.Instance.Commands.AddCommand( | 453 | MainConsole.Instance.Commands.AddCommand( |
404 | "Scripts", false, "scripts start", "scripts start [<script-item-uuid>]", "Starts all stopped scripts", | 454 | "Scripts", false, "scripts start", "scripts start [<script-item-uuid>+]", "Starts all stopped scripts", |
405 | "Starts all stopped scripts." | 455 | "Starts all stopped scripts.\n" |
406 | + "If a <script-item-uuid> is given then only that script will be started. Otherwise, all suitable scripts are started.", | 456 | + "If one or more <script-item-uuid>s are given then only that script will be started. Otherwise, all suitable scripts are started.", |
407 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStartScript)); | 457 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStartScript)); |
408 | 458 | ||
459 | MainConsole.Instance.Commands.AddCommand( | ||
460 | "Scripts", false, "debug scripts log", "debug scripts log <item-id> <log-level>", "Extra debug logging for a script", | ||
461 | "Activates or deactivates extra debug logging for the given script.\n" | ||
462 | + "Level == 0, deactivate extra debug logging.\n" | ||
463 | + "Level >= 1, log state changes.\n" | ||
464 | + "Level >= 2, log event invocations.\n", | ||
465 | HandleDebugScriptLogCommand); | ||
466 | |||
409 | // MainConsole.Instance.Commands.AddCommand( | 467 | // MainConsole.Instance.Commands.AddCommand( |
410 | // "Debug", false, "debug xengine", "debug xengine [<level>]", | 468 | // "Debug", false, "debug xengine", "debug xengine [<level>]", |
411 | // "Turn on detailed xengine debugging.", | 469 | // "Turn on detailed xengine debugging.", |
@@ -414,6 +472,41 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
414 | // HandleDebugLevelCommand); | 472 | // HandleDebugLevelCommand); |
415 | } | 473 | } |
416 | 474 | ||
475 | private void HandleDebugScriptLogCommand(string module, string[] args) | ||
476 | { | ||
477 | if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_Scene)) | ||
478 | return; | ||
479 | |||
480 | if (args.Length != 5) | ||
481 | { | ||
482 | MainConsole.Instance.Output("Usage: debug script log <item-id> <log-level>"); | ||
483 | return; | ||
484 | } | ||
485 | |||
486 | UUID itemId; | ||
487 | |||
488 | if (!ConsoleUtil.TryParseConsoleUuid(MainConsole.Instance, args[3], out itemId)) | ||
489 | return; | ||
490 | |||
491 | int newLevel; | ||
492 | |||
493 | if (!ConsoleUtil.TryParseConsoleInt(MainConsole.Instance, args[4], out newLevel)) | ||
494 | return; | ||
495 | |||
496 | IScriptInstance si; | ||
497 | |||
498 | lock (m_Scripts) | ||
499 | { | ||
500 | // XXX: We can't give the user feedback on a bad item id because this may apply to a different script | ||
501 | // engine | ||
502 | if (!m_Scripts.TryGetValue(itemId, out si)) | ||
503 | return; | ||
504 | } | ||
505 | |||
506 | si.DebugLevel = newLevel; | ||
507 | MainConsole.Instance.OutputFormat("Set debug level of {0} {1} to {2}", si.ScriptName, si.ItemID, newLevel); | ||
508 | } | ||
509 | |||
417 | /// <summary> | 510 | /// <summary> |
418 | /// Change debug level | 511 | /// Change debug level |
419 | /// </summary> | 512 | /// </summary> |
@@ -445,9 +538,21 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
445 | /// </summary> | 538 | /// </summary> |
446 | /// <param name="cmdparams"></param> | 539 | /// <param name="cmdparams"></param> |
447 | /// <param name="instance"></param> | 540 | /// <param name="instance"></param> |
448 | /// <returns>true if we're okay to proceed, false if not.</returns> | 541 | /// <param name="comparer">Basis on which to sort output. Can be null if no sort needs to take place</param> |
449 | private void HandleScriptsAction(string[] cmdparams, Action<IScriptInstance> action) | 542 | private void HandleScriptsAction(string[] cmdparams, Action<IScriptInstance> action) |
450 | { | 543 | { |
544 | HandleScriptsAction<object>(cmdparams, action, null); | ||
545 | } | ||
546 | |||
547 | /// <summary> | ||
548 | /// Parse the raw item id into a script instance from the command params if it's present. | ||
549 | /// </summary> | ||
550 | /// <param name="cmdparams"></param> | ||
551 | /// <param name="instance"></param> | ||
552 | /// <param name="keySelector">Basis on which to sort output. Can be null if no sort needs to take place</param> | ||
553 | private void HandleScriptsAction<TKey>( | ||
554 | string[] cmdparams, Action<IScriptInstance> action, Func<IScriptInstance, TKey> keySelector) | ||
555 | { | ||
451 | if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_Scene)) | 556 | if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_Scene)) |
452 | return; | 557 | return; |
453 | 558 | ||
@@ -458,35 +563,42 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
458 | 563 | ||
459 | if (cmdparams.Length == 2) | 564 | if (cmdparams.Length == 2) |
460 | { | 565 | { |
461 | foreach (IScriptInstance instance in m_Scripts.Values) | 566 | IEnumerable<IScriptInstance> scripts = m_Scripts.Values; |
567 | |||
568 | if (keySelector != null) | ||
569 | scripts = scripts.OrderBy<IScriptInstance, TKey>(keySelector); | ||
570 | |||
571 | foreach (IScriptInstance instance in scripts) | ||
462 | action(instance); | 572 | action(instance); |
463 | 573 | ||
464 | return; | 574 | return; |
465 | } | 575 | } |
466 | 576 | ||
467 | rawItemId = cmdparams[2]; | 577 | for (int i = 2; i < cmdparams.Length; i++) |
468 | |||
469 | if (!UUID.TryParse(rawItemId, out itemId)) | ||
470 | { | ||
471 | MainConsole.Instance.OutputFormat("Error - {0} is not a valid UUID", rawItemId); | ||
472 | return; | ||
473 | } | ||
474 | |||
475 | if (itemId != UUID.Zero) | ||
476 | { | 578 | { |
477 | IScriptInstance instance = GetInstance(itemId); | 579 | rawItemId = cmdparams[i]; |
478 | if (instance == null) | 580 | |
581 | if (!UUID.TryParse(rawItemId, out itemId)) | ||
479 | { | 582 | { |
480 | // Commented out for now since this will cause false reports on simulators with more than | 583 | MainConsole.Instance.OutputFormat("ERROR: {0} is not a valid UUID", rawItemId); |
481 | // one scene where the current command line set region is 'root' (which causes commands to | 584 | continue; |
482 | // go to both regions... (sigh) | ||
483 | // MainConsole.Instance.OutputFormat("Error - No item found with id {0}", itemId); | ||
484 | return; | ||
485 | } | 585 | } |
486 | else | 586 | |
587 | if (itemId != UUID.Zero) | ||
487 | { | 588 | { |
488 | action(instance); | 589 | IScriptInstance instance = GetInstance(itemId); |
489 | return; | 590 | if (instance == null) |
591 | { | ||
592 | // Commented out for now since this will cause false reports on simulators with more than | ||
593 | // one scene where the current command line set region is 'root' (which causes commands to | ||
594 | // go to both regions... (sigh) | ||
595 | // MainConsole.Instance.OutputFormat("Error - No item found with id {0}", itemId); | ||
596 | continue; | ||
597 | } | ||
598 | else | ||
599 | { | ||
600 | action(instance); | ||
601 | } | ||
490 | } | 602 | } |
491 | } | 603 | } |
492 | } | 604 | } |
@@ -505,9 +617,20 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
505 | StringBuilder sb = new StringBuilder(); | 617 | StringBuilder sb = new StringBuilder(); |
506 | sb.AppendFormat("Status of XEngine instance for {0}\n", m_Scene.RegionInfo.RegionName); | 618 | sb.AppendFormat("Status of XEngine instance for {0}\n", m_Scene.RegionInfo.RegionName); |
507 | 619 | ||
620 | long scriptsLoaded, eventsQueued = 0, eventsProcessed = 0; | ||
621 | |||
508 | lock (m_Scripts) | 622 | lock (m_Scripts) |
509 | sb.AppendFormat("Scripts loaded : {0}\n", m_Scripts.Count); | 623 | { |
624 | scriptsLoaded = m_Scripts.Count; | ||
510 | 625 | ||
626 | foreach (IScriptInstance si in m_Scripts.Values) | ||
627 | { | ||
628 | eventsQueued += si.EventsQueued; | ||
629 | eventsProcessed += si.EventsProcessed; | ||
630 | } | ||
631 | } | ||
632 | |||
633 | sb.AppendFormat("Scripts loaded : {0}\n", scriptsLoaded); | ||
511 | sb.AppendFormat("Unique scripts : {0}\n", m_uniqueScripts.Count); | 634 | sb.AppendFormat("Unique scripts : {0}\n", m_uniqueScripts.Count); |
512 | sb.AppendFormat("Scripts waiting for load : {0}\n", m_CompileQueue.Count); | 635 | sb.AppendFormat("Scripts waiting for load : {0}\n", m_CompileQueue.Count); |
513 | sb.AppendFormat("Max threads : {0}\n", m_ThreadPool.MaxThreads); | 636 | sb.AppendFormat("Max threads : {0}\n", m_ThreadPool.MaxThreads); |
@@ -516,6 +639,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
516 | sb.AppendFormat("In use threads : {0}\n", m_ThreadPool.InUseThreads); | 639 | sb.AppendFormat("In use threads : {0}\n", m_ThreadPool.InUseThreads); |
517 | sb.AppendFormat("Work items waiting : {0}\n", m_ThreadPool.WaitingCallbacks); | 640 | sb.AppendFormat("Work items waiting : {0}\n", m_ThreadPool.WaitingCallbacks); |
518 | // sb.AppendFormat("Assemblies loaded : {0}\n", m_Assemblies.Count); | 641 | // sb.AppendFormat("Assemblies loaded : {0}\n", m_Assemblies.Count); |
642 | sb.AppendFormat("Events queued : {0}\n", eventsQueued); | ||
643 | sb.AppendFormat("Events processed : {0}\n", eventsProcessed); | ||
519 | 644 | ||
520 | SensorRepeat sr = AsyncCommandManager.GetSensorRepeatPlugin(this); | 645 | SensorRepeat sr = AsyncCommandManager.GetSensorRepeatPlugin(this); |
521 | sb.AppendFormat("Sensors : {0}\n", sr != null ? sr.SensorsCount : 0); | 646 | sb.AppendFormat("Sensors : {0}\n", sr != null ? sr.SensorsCount : 0); |
@@ -546,7 +671,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
546 | } | 671 | } |
547 | } | 672 | } |
548 | 673 | ||
549 | HandleScriptsAction(cmdparams, HandleShowScript); | 674 | HandleScriptsAction<long>(cmdparams, HandleShowScript, si => si.EventsProcessed); |
550 | } | 675 | } |
551 | 676 | ||
552 | private void HandleShowScript(IScriptInstance instance) | 677 | private void HandleShowScript(IScriptInstance instance) |
@@ -572,15 +697,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
572 | } | 697 | } |
573 | 698 | ||
574 | StringBuilder sb = new StringBuilder(); | 699 | StringBuilder sb = new StringBuilder(); |
575 | Queue eq = instance.EventQueue; | ||
576 | 700 | ||
577 | sb.AppendFormat("Script name : {0}\n", instance.ScriptName); | 701 | sb.AppendFormat("Script name : {0}\n", instance.ScriptName); |
578 | sb.AppendFormat("Status : {0}\n", status); | 702 | sb.AppendFormat("Status : {0}\n", status); |
579 | 703 | sb.AppendFormat("Queued events : {0}\n", instance.EventsQueued); | |
580 | lock (eq) | 704 | sb.AppendFormat("Processed events : {0}\n", instance.EventsProcessed); |
581 | sb.AppendFormat("Queued events : {0}\n", eq.Count); | ||
582 | |||
583 | sb.AppendFormat("Item UUID : {0}\n", instance.ItemID); | 705 | sb.AppendFormat("Item UUID : {0}\n", instance.ItemID); |
706 | sb.AppendFormat("Asset UUID : {0}\n", instance.AssetID); | ||
584 | sb.AppendFormat("Containing part name: {0}\n", instance.PrimName); | 707 | sb.AppendFormat("Containing part name: {0}\n", instance.PrimName); |
585 | sb.AppendFormat("Containing part UUID: {0}\n", instance.ObjectID); | 708 | sb.AppendFormat("Containing part UUID: {0}\n", instance.ObjectID); |
586 | sb.AppendFormat("Position : {0}\n", sop.AbsolutePosition); | 709 | sb.AppendFormat("Position : {0}\n", sop.AbsolutePosition); |
@@ -1079,7 +1202,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1079 | } | 1202 | } |
1080 | 1203 | ||
1081 | m_log.DebugFormat( | 1204 | m_log.DebugFormat( |
1082 | "[XEngine] Loading script {0}.{1}, item UUID {2}, prim UUID {3} @ {4}.{5}", | 1205 | "[XEngine]: Loading script {0}.{1}, item UUID {2}, prim UUID {3} @ {4}.{5}", |
1083 | part.ParentGroup.RootPart.Name, item.Name, itemID, part.UUID, | 1206 | part.ParentGroup.RootPart.Name, item.Name, itemID, part.UUID, |
1084 | part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName); | 1207 | part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName); |
1085 | 1208 | ||
@@ -1089,8 +1212,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1089 | 1212 | ||
1090 | string assembly = ""; | 1213 | string assembly = ""; |
1091 | 1214 | ||
1092 | CultureInfo USCulture = new CultureInfo("en-US"); | 1215 | Culture.SetCurrentCulture(); |
1093 | Thread.CurrentThread.CurrentCulture = USCulture; | ||
1094 | 1216 | ||
1095 | Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap; | 1217 | Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap; |
1096 | 1218 | ||
@@ -1101,6 +1223,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1101 | lock (m_AddingAssemblies) | 1223 | lock (m_AddingAssemblies) |
1102 | { | 1224 | { |
1103 | m_Compiler.PerformScriptCompile(script, assetID.ToString(), item.OwnerID, out assembly, out linemap); | 1225 | m_Compiler.PerformScriptCompile(script, assetID.ToString(), item.OwnerID, out assembly, out linemap); |
1226 | |||
1104 | if (!m_AddingAssemblies.ContainsKey(assembly)) { | 1227 | if (!m_AddingAssemblies.ContainsKey(assembly)) { |
1105 | m_AddingAssemblies[assembly] = 1; | 1228 | m_AddingAssemblies[assembly] = 1; |
1106 | } else { | 1229 | } else { |
@@ -1150,7 +1273,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1150 | } | 1273 | } |
1151 | catch (Exception e) | 1274 | catch (Exception e) |
1152 | { | 1275 | { |
1153 | // m_log.ErrorFormat("[XEngine]: Exception when rezzing script {0}{1}", e.Message, e.StackTrace); | 1276 | // m_log.ErrorFormat( |
1277 | // "[XEngine]: Exception when rezzing script with item ID {0}, {1}{2}", | ||
1278 | // itemID, e.Message, e.StackTrace); | ||
1154 | 1279 | ||
1155 | // try | 1280 | // try |
1156 | // { | 1281 | // { |
@@ -1229,13 +1354,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1229 | sandbox = AppDomain.CurrentDomain; | 1354 | sandbox = AppDomain.CurrentDomain; |
1230 | } | 1355 | } |
1231 | 1356 | ||
1232 | //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); | 1357 | if (!instance.Load(m_AppDomains[appDomain], assembly, stateSource)) |
1233 | //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); | 1358 | return false; |
1234 | //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet"); | ||
1235 | //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet); | ||
1236 | //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement); | ||
1237 | //sandboxPolicy.RootCodeGroup = sandboxCodeGroup; | ||
1238 | //sandbox.SetAppDomainPolicy(sandboxPolicy); | ||
1239 | 1359 | ||
1240 | m_AppDomains[appDomain] = sandbox; | 1360 | m_AppDomains[appDomain] = sandbox; |
1241 | 1361 | ||
@@ -1256,12 +1376,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1256 | m_DomainScripts[appDomain].Add(itemID); | 1376 | m_DomainScripts[appDomain].Add(itemID); |
1257 | 1377 | ||
1258 | instance = new ScriptInstance(this, part, | 1378 | instance = new ScriptInstance(this, part, |
1259 | itemID, assetID, assembly, | 1379 | item, |
1260 | m_AppDomains[appDomain], | 1380 | startParam, postOnRez, |
1261 | part.ParentGroup.RootPart.Name, | 1381 | m_MaxScriptQueue); |
1262 | item.Name, startParam, postOnRez, | ||
1263 | stateSource, m_MaxScriptQueue); | ||
1264 | 1382 | ||
1383 | instance.Load(m_AppDomains[appDomain], assembly, stateSource); | ||
1265 | // m_log.DebugFormat( | 1384 | // m_log.DebugFormat( |
1266 | // "[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}.{5}", | 1385 | // "[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}.{5}", |
1267 | // part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID, | 1386 | // part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID, |
@@ -1347,9 +1466,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1347 | lockScriptsForWrite(false); | 1466 | lockScriptsForWrite(false); |
1348 | instance.ClearQueue(); | 1467 | instance.ClearQueue(); |
1349 | 1468 | ||
1350 | // Give the script some time to finish processing its last event. Simply aborting the script thread can | 1469 | instance.Stop(m_WaitForEventCompletionOnScriptStop); |
1351 | // cause issues on mono 2.6, 2.10 and possibly later where locks are not released properly on abort. | ||
1352 | instance.Stop(1000); | ||
1353 | 1470 | ||
1354 | // bool objectRemoved = false; | 1471 | // bool objectRemoved = false; |
1355 | 1472 | ||
@@ -1477,7 +1594,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1477 | m_MaxScriptQueue = maxScriptQueue; | 1594 | m_MaxScriptQueue = maxScriptQueue; |
1478 | 1595 | ||
1479 | STPStartInfo startInfo = new STPStartInfo(); | 1596 | STPStartInfo startInfo = new STPStartInfo(); |
1480 | startInfo.IdleTimeout = idleTimeout*1000; // convert to seconds as stated in .ini | 1597 | startInfo.ThreadPoolName = "XEngine"; |
1598 | startInfo.IdleTimeout = idleTimeout * 1000; // convert to seconds as stated in .ini | ||
1481 | startInfo.MaxWorkerThreads = maxThreads; | 1599 | startInfo.MaxWorkerThreads = maxThreads; |
1482 | startInfo.MinWorkerThreads = minThreads; | 1600 | startInfo.MinWorkerThreads = minThreads; |
1483 | startInfo.ThreadPriority = threadPriority;; | 1601 | startInfo.ThreadPriority = threadPriority;; |
@@ -1504,8 +1622,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1504 | /// <returns></returns> | 1622 | /// <returns></returns> |
1505 | private object ProcessEventHandler(object parms) | 1623 | private object ProcessEventHandler(object parms) |
1506 | { | 1624 | { |
1507 | CultureInfo USCulture = new CultureInfo("en-US"); | 1625 | Culture.SetCurrentCulture(); |
1508 | Thread.CurrentThread.CurrentCulture = USCulture; | ||
1509 | 1626 | ||
1510 | IScriptInstance instance = (ScriptInstance) parms; | 1627 | IScriptInstance instance = (ScriptInstance) parms; |
1511 | 1628 | ||
@@ -1693,7 +1810,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1693 | { | 1810 | { |
1694 | IScriptInstance instance = GetInstance(itemID); | 1811 | IScriptInstance instance = GetInstance(itemID); |
1695 | if (instance != null) | 1812 | if (instance != null) |
1696 | instance.ResetScript(); | 1813 | instance.ResetScript(m_WaitForEventCompletionOnScriptStop); |
1697 | } | 1814 | } |
1698 | 1815 | ||
1699 | public void StartScript(UUID itemID) | 1816 | public void StartScript(UUID itemID) |
@@ -1708,14 +1825,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1708 | public void StopScript(UUID itemID) | 1825 | public void StopScript(UUID itemID) |
1709 | { | 1826 | { |
1710 | IScriptInstance instance = GetInstance(itemID); | 1827 | IScriptInstance instance = GetInstance(itemID); |
1828 | |||
1711 | if (instance != null) | 1829 | if (instance != null) |
1712 | { | 1830 | { |
1713 | // Give the script some time to finish processing its last event. Simply aborting the script thread can | 1831 | instance.Stop(m_WaitForEventCompletionOnScriptStop); |
1714 | // cause issues on mono 2.6, 2.10 and possibly later where locks are not released properly on abort. | ||
1715 | instance.Stop(1000); | ||
1716 | } | 1832 | } |
1717 | else | 1833 | else |
1718 | { | 1834 | { |
1835 | // m_log.DebugFormat("[XENGINE]: Could not find script with ID {0} to stop in {1}", itemID, World.Name); | ||
1719 | m_runFlags.AddOrUpdate(itemID, false, 240); | 1836 | m_runFlags.AddOrUpdate(itemID, false, 240); |
1720 | } | 1837 | } |
1721 | } | 1838 | } |
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XWorkItem.cs b/OpenSim/Region/ScriptEngine/XEngine/XWorkItem.cs index 2ac5c31..8dd7677 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XWorkItem.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XWorkItem.cs | |||
@@ -57,8 +57,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
57 | wr.Abort(); | 57 | wr.Abort(); |
58 | } | 58 | } |
59 | 59 | ||
60 | public bool Wait(TimeSpan t) | 60 | public bool Wait(int t) |
61 | { | 61 | { |
62 | // We use the integer version of WaitAll because the current version of SmartThreadPool has a bug with the | ||
63 | // TimeSpan version. The number of milliseconds in TimeSpan is an int64 so when STP casts it down to an | ||
64 | // int (32-bit) we can end up with bad values. This occurs on Windows though curious not on Mono 2.10.8 | ||
65 | // (or very likely other versions of Mono at least up until 3.0.3). | ||
62 | return SmartThreadPool.WaitAll(new IWorkItemResult[] {wr}, t, false); | 66 | return SmartThreadPool.WaitAll(new IWorkItemResult[] {wr}, t, false); |
63 | } | 67 | } |
64 | } | 68 | } |