aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-07-11 00:03:02 +0100
committerJustin Clark-Casey (justincc)2014-07-11 00:03:02 +0100
commitd7b92604963c7ecbddf76db37eabb84ed36fcfde (patch)
tree0f75eca56190522c477f2e53574e47ce9019f26b /OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
parentrefactor: use existing Compiler.CreateScriptsDirectory() (renamed to CheckOrC... (diff)
downloadopensim-SC-d7b92604963c7ecbddf76db37eabb84ed36fcfde.zip
opensim-SC-d7b92604963c7ecbddf76db37eabb84ed36fcfde.tar.gz
opensim-SC-d7b92604963c7ecbddf76db37eabb84ed36fcfde.tar.bz2
opensim-SC-d7b92604963c7ecbddf76db37eabb84ed36fcfde.tar.xz
If [XEngine] ScriptStopStrategy is changed between abort and co-op, for the existing session use the previous strategy for that script rather than not starting the script at all.
We have to do this since we can't unload existing DLLs if they're all in the same AppDomain. But we can still update the underlying DLL which will be used in the next simulator session.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs57
1 files changed, 21 insertions, 36 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index c5d0752..979c84a 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -237,12 +237,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
237 m_postOnRez = postOnRez; 237 m_postOnRez = postOnRez;
238 m_AttachedAvatar = Part.ParentGroup.AttachedAvatar; 238 m_AttachedAvatar = Part.ParentGroup.AttachedAvatar;
239 m_RegionID = Part.ParentGroup.Scene.RegionInfo.RegionID; 239 m_RegionID = Part.ParentGroup.Scene.RegionInfo.RegionID;
240
241 if (Engine.Config.GetString("ScriptStopStrategy", "abort") == "co-op")
242 {
243 m_coopTermination = true;
244 m_coopSleepHandle = new XEngineEventWaitHandle(false, EventResetMode.AutoReset);
245 }
246 } 240 }
247 241
248 /// <summary> 242 /// <summary>
@@ -252,54 +246,38 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
252 /// <param name='assembly'></param> 246 /// <param name='assembly'></param>
253 /// <param name='stateSource'></param> 247 /// <param name='stateSource'></param>
254 /// <returns>false if load failed, true if suceeded</returns> 248 /// <returns>false if load failed, true if suceeded</returns>
255 public bool Load(AppDomain dom, string assembly, StateSource stateSource) 249 public bool Load(AppDomain dom, Assembly scriptAssembly, StateSource stateSource)
256 { 250 {
257 m_Assembly = assembly; 251 //m_Assembly = scriptAssembly.CodeBase;
252 m_Assembly = scriptAssembly.Location;
258 m_stateSource = stateSource; 253 m_stateSource = stateSource;
259
260 ApiManager am = new ApiManager();
261
262 foreach (string api in am.GetApis())
263 {
264 m_Apis[api] = am.CreateApi(api);
265 m_Apis[api].Initialize(Engine, Part, ScriptTask, m_coopSleepHandle);
266 }
267 254
268 try 255 try
269 { 256 {
270 object[] constructorParams; 257 object[] constructorParams;
271
272 Assembly scriptAssembly = dom.Load(Path.GetFileNameWithoutExtension(assembly));
273 Type scriptType = scriptAssembly.GetType("SecondLife.XEngineScript"); 258 Type scriptType = scriptAssembly.GetType("SecondLife.XEngineScript");
274 259
275 if (scriptType != null) 260 if (scriptType != null)
276 { 261 {
262 m_coopTermination = true;
263 m_coopSleepHandle = new XEngineEventWaitHandle(false, EventResetMode.AutoReset);
277 constructorParams = new object[] { m_coopSleepHandle }; 264 constructorParams = new object[] { m_coopSleepHandle };
278 } 265 }
279 else if (!m_coopTermination) 266 else
280 { 267 {
268 m_coopTermination = false;
281 scriptType = scriptAssembly.GetType("SecondLife.Script"); 269 scriptType = scriptAssembly.GetType("SecondLife.Script");
282 constructorParams = null; 270 constructorParams = null;
283 } 271 }
284 else
285 {
286 m_log.ErrorFormat(
287 "[SCRIPT INSTANCE]: Not starting script {0} (id {1}) in part {2} (id {3}) in object {4} in {5}. You must remove all existing {6}* script DLL files before using enabling co-op termination"
288 + ", either by setting DeleteScriptsOnStartup = true in [XEngine] for one run"
289 + " or by deleting these files manually.",
290 ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, Engine.World.Name, assembly);
291
292 return false;
293 }
294 272
295// m_log.DebugFormat( 273// m_log.DebugFormat(
296// "[SCRIPT INSTANCE]: Looking to load {0} from assembly {1} in {2}", 274// "[SCRIPT INSTANCE]: Looking to load {0} from assembly {1} in {2}",
297// scriptType.FullName, Path.GetFileNameWithoutExtension(assembly), Engine.World.Name); 275// scriptType.FullName, m_Assembly, Engine.World.Name);
298 276
299 if (dom != System.AppDomain.CurrentDomain) 277 if (dom != System.AppDomain.CurrentDomain)
300 m_Script 278 m_Script
301 = (IScript)dom.CreateInstanceAndUnwrap( 279 = (IScript)dom.CreateInstanceAndUnwrap(
302 Path.GetFileNameWithoutExtension(assembly), 280 Path.GetFileNameWithoutExtension(m_Assembly),
303 scriptType.FullName, 281 scriptType.FullName,
304 false, 282 false,
305 BindingFlags.Default, 283 BindingFlags.Default,
@@ -327,11 +305,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
327 { 305 {
328 m_log.ErrorFormat( 306 m_log.ErrorFormat(
329 "[SCRIPT INSTANCE]: Not starting script {0} (id {1}) in part {2} (id {3}) in object {4} in {5}. Error loading assembly {6}. Exception {7}{8}", 307 "[SCRIPT INSTANCE]: Not starting script {0} (id {1}) in part {2} (id {3}) in object {4} in {5}. Error loading assembly {6}. Exception {7}{8}",
330 ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, Engine.World.Name, assembly, e.Message, e.StackTrace); 308 ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, Engine.World.Name, m_Assembly, e.Message, e.StackTrace);
331 309
332 return false; 310 return false;
333 } 311 }
334 312
313 ApiManager am = new ApiManager();
314
315 foreach (string api in am.GetApis())
316 {
317 m_Apis[api] = am.CreateApi(api);
318 m_Apis[api].Initialize(Engine, Part, ScriptTask, m_coopSleepHandle);
319 }
320
335 try 321 try
336 { 322 {
337 foreach (KeyValuePair<string,IScriptApi> kv in m_Apis) 323 foreach (KeyValuePair<string,IScriptApi> kv in m_Apis)
@@ -341,8 +327,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
341 327
342// // m_log.Debug("[Script] Script instance created"); 328// // m_log.Debug("[Script] Script instance created");
343 329
344 Part.SetScriptEvents(ItemID, 330 Part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State));
345 (int)m_Script.GetStateEventFlags(State));
346 } 331 }
347 catch (Exception e) 332 catch (Exception e)
348 { 333 {
@@ -355,8 +340,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
355 340
356 m_SaveState = true; 341 m_SaveState = true;
357 342
358 string savedState = Path.Combine(Path.GetDirectoryName(assembly), 343 string savedState = Path.Combine(Path.GetDirectoryName(m_Assembly), ItemID.ToString() + ".state");
359 ItemID.ToString() + ".state"); 344
360 if (File.Exists(savedState)) 345 if (File.Exists(savedState))
361 { 346 {
362 string xml = String.Empty; 347 string xml = String.Empty;