diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Common/Executor.cs | 18 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs | 69 |
2 files changed, 53 insertions, 34 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/Executor.cs b/OpenSim/Region/ScriptEngine/Common/Executor.cs index dedf00d..148ae0f 100644 --- a/OpenSim/Region/ScriptEngine/Common/Executor.cs +++ b/OpenSim/Region/ScriptEngine/Common/Executor.cs | |||
@@ -17,12 +17,24 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
17 | 17 | ||
18 | private IScript m_Script; | 18 | private IScript m_Script; |
19 | private Dictionary<string, MethodInfo> Events = new Dictionary<string, MethodInfo>(); | 19 | private Dictionary<string, MethodInfo> Events = new Dictionary<string, MethodInfo>(); |
20 | private bool m_Running = true; | ||
21 | |||
20 | 22 | ||
21 | public Executor(IScript Script) | 23 | public Executor(IScript Script) |
22 | { | 24 | { |
23 | m_Script = Script; | 25 | m_Script = Script; |
24 | 26 | ||
25 | } | 27 | } |
28 | |||
29 | public void StopScript() | ||
30 | { | ||
31 | m_Running = false; | ||
32 | } | ||
33 | public AppDomain GetAppDomain() | ||
34 | { | ||
35 | return AppDomain.CurrentDomain; | ||
36 | } | ||
37 | |||
26 | public void ExecuteEvent(string FunctionName, object[] args) | 38 | public void ExecuteEvent(string FunctionName, object[] args) |
27 | { | 39 | { |
28 | // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. | 40 | // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. |
@@ -36,7 +48,11 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
36 | //} | 48 | //} |
37 | //} | 49 | //} |
38 | 50 | ||
39 | 51 | if (m_Running == false) | |
52 | { | ||
53 | // Script is inactive, do not execute! | ||
54 | return; | ||
55 | } | ||
40 | 56 | ||
41 | string EventName = m_Script.State() + "_event_" + FunctionName; | 57 | string EventName = m_Script.State() + "_event_" + FunctionName; |
42 | 58 | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs index 07d5d54..7f78790 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs | |||
@@ -69,7 +69,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
69 | // Object<string, Script<string, script>> | 69 | // Object<string, Script<string, script>> |
70 | // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. | 70 | // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. |
71 | // Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead! | 71 | // Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead! |
72 | internal Dictionary<IScriptHost, Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass>> Scripts = new Dictionary<IScriptHost, Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass>>(); | 72 | internal Dictionary<IScriptHost, Dictionary<string, LSL_BaseClass>> Scripts = new Dictionary<IScriptHost, Dictionary<string, LSL_BaseClass>>(); |
73 | public Scene World | 73 | public Scene World |
74 | { | 74 | { |
75 | get | 75 | get |
@@ -79,45 +79,45 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
79 | } | 79 | } |
80 | 80 | ||
81 | 81 | ||
82 | internal Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass>.KeyCollection GetScriptKeys(IScriptHost ObjectID) | 82 | internal Dictionary<string, LSL_BaseClass>.KeyCollection GetScriptKeys(IScriptHost ObjectID) |
83 | { | 83 | { |
84 | if (Scripts.ContainsKey(ObjectID) == false) | 84 | if (Scripts.ContainsKey(ObjectID) == false) |
85 | return null; | 85 | return null; |
86 | 86 | ||
87 | Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass> Obj; | 87 | Dictionary<string, LSL_BaseClass> Obj; |
88 | Scripts.TryGetValue(ObjectID, out Obj); | 88 | Scripts.TryGetValue(ObjectID, out Obj); |
89 | 89 | ||
90 | return Obj.Keys; | 90 | return Obj.Keys; |
91 | 91 | ||
92 | } | 92 | } |
93 | 93 | ||
94 | internal OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass GetScript(IScriptHost ObjectID, string ScriptID) | 94 | internal LSL_BaseClass GetScript(IScriptHost ObjectID, string ScriptID) |
95 | { | 95 | { |
96 | if (Scripts.ContainsKey(ObjectID) == false) | 96 | if (Scripts.ContainsKey(ObjectID) == false) |
97 | return null; | 97 | return null; |
98 | 98 | ||
99 | Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass> Obj; | 99 | Dictionary<string, LSL_BaseClass> Obj; |
100 | Scripts.TryGetValue(ObjectID, out Obj); | 100 | Scripts.TryGetValue(ObjectID, out Obj); |
101 | if (Obj.ContainsKey(ScriptID) == false) | 101 | if (Obj.ContainsKey(ScriptID) == false) |
102 | return null; | 102 | return null; |
103 | 103 | ||
104 | // Get script | 104 | // Get script |
105 | OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script; | 105 | LSL_BaseClass Script; |
106 | Obj.TryGetValue(ScriptID, out Script); | 106 | Obj.TryGetValue(ScriptID, out Script); |
107 | 107 | ||
108 | return Script; | 108 | return Script; |
109 | 109 | ||
110 | } | 110 | } |
111 | internal void SetScript(IScriptHost ObjectID, string ScriptID, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script) | 111 | internal void SetScript(IScriptHost ObjectID, string ScriptID, LSL_BaseClass Script) |
112 | { | 112 | { |
113 | // Create object if it doesn't exist | 113 | // Create object if it doesn't exist |
114 | if (Scripts.ContainsKey(ObjectID) == false) | 114 | if (Scripts.ContainsKey(ObjectID) == false) |
115 | { | 115 | { |
116 | Scripts.Add(ObjectID, new Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass>()); | 116 | Scripts.Add(ObjectID, new Dictionary<string, LSL_BaseClass>()); |
117 | } | 117 | } |
118 | 118 | ||
119 | // Delete script if it exists | 119 | // Delete script if it exists |
120 | Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass> Obj; | 120 | Dictionary<string, LSL_BaseClass> Obj; |
121 | Scripts.TryGetValue(ObjectID, out Obj); | 121 | Scripts.TryGetValue(ObjectID, out Obj); |
122 | if (Obj.ContainsKey(ScriptID) == true) | 122 | if (Obj.ContainsKey(ScriptID) == true) |
123 | Obj.Remove(ScriptID); | 123 | Obj.Remove(ScriptID); |
@@ -126,7 +126,19 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
126 | Obj.Add(ScriptID, Script); | 126 | Obj.Add(ScriptID, Script); |
127 | 127 | ||
128 | } | 128 | } |
129 | internal void RemoveScript(IScriptHost ObjectID, string ScriptID) | ||
130 | { | ||
131 | // Don't have that object? | ||
132 | if (Scripts.ContainsKey(ObjectID) == false) | ||
133 | return; | ||
129 | 134 | ||
135 | // Delete script if it exists | ||
136 | Dictionary<string, LSL_BaseClass> Obj; | ||
137 | Scripts.TryGetValue(ObjectID, out Obj); | ||
138 | if (Obj.ContainsKey(ScriptID) == true) | ||
139 | Obj.Remove(ScriptID); | ||
140 | |||
141 | } | ||
130 | /// <summary> | 142 | /// <summary> |
131 | /// Fetches, loads and hooks up a script to an objects events | 143 | /// Fetches, loads and hooks up a script to an objects events |
132 | /// </summary> | 144 | /// </summary> |
@@ -207,7 +219,20 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
207 | 219 | ||
208 | 220 | ||
209 | } | 221 | } |
210 | private string ProcessYield(string FileName) | 222 | public void StopScript(string ScriptID, IScriptHost ObjectID) |
223 | { | ||
224 | // Stop script | ||
225 | |||
226 | // Get AppDomain | ||
227 | AppDomain ad = GetScript(ObjectID, ScriptID).Exec.GetAppDomain(); | ||
228 | // Tell script not to accept new requests | ||
229 | GetScript(ObjectID, ScriptID).Exec.StopScript(); | ||
230 | // Remove from internal structure | ||
231 | RemoveScript(ObjectID, ScriptID); | ||
232 | // Tell AppDomain that we have stopped script | ||
233 | m_scriptEngine.myAppDomainManager.StopScript(ad); | ||
234 | } | ||
235 | private string ProcessYield(string FileName) | ||
211 | { | 236 | { |
212 | // TODO: Create a new assembly and copy old but insert Yield Code | 237 | // TODO: Create a new assembly and copy old but insert Yield Code |
213 | //return TempDotNetMicroThreadingCodeInjector.TestFix(FileName); | 238 | //return TempDotNetMicroThreadingCodeInjector.TestFix(FileName); |
@@ -228,33 +253,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
228 | 253 | ||
229 | // Execute a function in the script | 254 | // Execute a function in the script |
230 | m_scriptEngine.Log.Verbose("ScriptEngine", "Executing Function ObjectID: " + ObjectID + ", ScriptID: " + ScriptID + ", FunctionName: " + FunctionName); | 255 | m_scriptEngine.Log.Verbose("ScriptEngine", "Executing Function ObjectID: " + ObjectID + ", ScriptID: " + ScriptID + ", FunctionName: " + FunctionName); |
231 | OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = m_scriptEngine.myScriptManager.GetScript(ObjectID, ScriptID); | 256 | LSL_BaseClass Script = m_scriptEngine.myScriptManager.GetScript(ObjectID, ScriptID); |
232 | 257 | ||
233 | // Must be done in correct AppDomain, so leaving it up to the script itself | 258 | // Must be done in correct AppDomain, so leaving it up to the script itself |
234 | |||
235 | Script.Exec.ExecuteEvent(FunctionName, args); | 259 | Script.Exec.ExecuteEvent(FunctionName, args); |
236 | 260 | ||
237 | //Type type = Script.GetType(); | ||
238 | |||
239 | |||
240 | ////foreach (MemberInfo mi in type.GetMembers()) | ||
241 | ////{ | ||
242 | //// Common.SendToDebug("Member found: " + mi.ToString()); | ||
243 | ////} | ||
244 | |||
245 | //m_scriptEngine.Log.Verbose("ScriptEngine", "Invoke: \"" + Script.State() + "_event_" + FunctionName + "\""); | ||
246 | |||
247 | //try | ||
248 | //{ | ||
249 | // type.InvokeMember(Script.State() + "_event_" + FunctionName, BindingFlags.InvokeMethod, null, Script, args); | ||
250 | //} | ||
251 | //catch (Exception e) | ||
252 | //{ | ||
253 | // m_scriptEngine.Log.Error("ScriptEngine", "Exception attempting to executing script function: " + e.ToString()); | ||
254 | //} | ||
255 | |||
256 | |||
257 | |||
258 | } | 261 | } |
259 | 262 | ||
260 | public string RegionName | 263 | public string RegionName |