aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs50
1 files changed, 32 insertions, 18 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 5e68d69..8d92ba5 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -26,16 +26,17 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Globalization;
29using System.IO; 32using System.IO;
30using System.Diagnostics; //for [DebuggerNonUserCode] 33using System.Diagnostics; //for [DebuggerNonUserCode]
34using System.Reflection;
31using System.Runtime.Remoting; 35using System.Runtime.Remoting;
32using System.Runtime.Remoting.Lifetime; 36using System.Runtime.Remoting.Lifetime;
33using System.Threading;
34using System.Collections;
35using System.Collections.Generic;
36using System.Security.Policy; 37using System.Security.Policy;
37using System.Reflection; 38using System.Text;
38using System.Globalization; 39using System.Threading;
39using System.Xml; 40using System.Xml;
40using OpenMetaverse; 41using OpenMetaverse;
41using log4net; 42using log4net;
@@ -121,6 +122,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
121 122
122 public bool Running { get; set; } 123 public bool Running { get; set; }
123 124
125 public bool Run { get; set; }
126
124 public bool Suspended 127 public bool Suspended
125 { 128 {
126 get { return m_Suspended; } 129 get { return m_Suspended; }
@@ -216,6 +219,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
216 m_postOnRez = postOnRez; 219 m_postOnRez = postOnRez;
217 m_AttachedAvatar = part.ParentGroup.AttachedAvatar; 220 m_AttachedAvatar = part.ParentGroup.AttachedAvatar;
218 m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID; 221 m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID;
222 Run = true;
219 223
220 if (part != null) 224 if (part != null)
221 { 225 {
@@ -232,7 +236,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
232 foreach (string api in am.GetApis()) 236 foreach (string api in am.GetApis())
233 { 237 {
234 m_Apis[api] = am.CreateApi(api); 238 m_Apis[api] = am.CreateApi(api);
235 m_Apis[api].Initialize(engine, part, LocalID, itemID); 239 m_Apis[api].Initialize(engine, part, ScriptTask);
236 } 240 }
237 241
238 try 242 try
@@ -295,13 +299,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
295 using (FileStream fs = File.Open(savedState, 299 using (FileStream fs = File.Open(savedState,
296 FileMode.Open, FileAccess.Read, FileShare.None)) 300 FileMode.Open, FileAccess.Read, FileShare.None))
297 { 301 {
298 System.Text.UTF8Encoding enc =
299 new System.Text.UTF8Encoding();
300
301 Byte[] data = new Byte[size]; 302 Byte[] data = new Byte[size];
302 fs.Read(data, 0, size); 303 fs.Read(data, 0, size);
303 304
304 xml = enc.GetString(data); 305 xml = Encoding.UTF8.GetString(data);
305 306
306 ScriptSerializer.Deserialize(xml, this); 307 ScriptSerializer.Deserialize(xml, this);
307 308
@@ -330,16 +331,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
330 } 331 }
331 else 332 else
332 { 333 {
333 m_log.ErrorFormat( 334 m_log.WarnFormat(
334 "[SCRIPT INSTANCE]: Unable to load script state from assembly {0}: Memory limit exceeded", 335 "[SCRIPT INSTANCE]: Unable to load script state file {0} for script {1} {2} in {3} {4} (assembly {5}). Memory limit exceeded",
335 assembly); 336 savedState, ScriptName, ItemID, PrimName, ObjectID, assembly);
336 } 337 }
337 } 338 }
338 catch (Exception e) 339 catch (Exception e)
339 { 340 {
340 m_log.ErrorFormat( 341 m_log.ErrorFormat(
341 "[SCRIPT INSTANCE]: Unable to load script state from assembly {0}. XML is {1}. Exception {2}{3}", 342 "[SCRIPT INSTANCE]: Unable to load script state file {0} for script {1} {2} in {3} {4} (assembly {5}). XML is {6}. Exception {7}{8}",
342 assembly, xml, e.Message, e.StackTrace); 343 savedState, ScriptName, ItemID, PrimName, ObjectID, assembly, xml, e.Message, e.StackTrace);
343 } 344 }
344 } 345 }
345// else 346// else
@@ -354,10 +355,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
354 355
355 public void Init() 356 public void Init()
356 { 357 {
357 if (!m_startOnInit) return; 358 if (!m_startOnInit)
359 return;
358 360
359 if (m_startedFromSavedState) 361 if (m_startedFromSavedState)
360 { 362 {
363 if (!Run)
364 return;
365
361 Start(); 366 Start();
362 if (m_postOnRez) 367 if (m_postOnRez)
363 { 368 {
@@ -390,6 +395,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
390 } 395 }
391 else 396 else
392 { 397 {
398 if (!Run)
399 return;
400
393 Start(); 401 Start();
394 PostEvent(new EventParams("state_entry", 402 PostEvent(new EventParams("state_entry",
395 new Object[0], new DetectParams[0])); 403 new Object[0], new DetectParams[0]));
@@ -946,8 +954,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
946 try 954 try
947 { 955 {
948 FileStream fs = File.Create(Path.Combine(Path.GetDirectoryName(assembly), ItemID.ToString() + ".state")); 956 FileStream fs = File.Create(Path.Combine(Path.GetDirectoryName(assembly), ItemID.ToString() + ".state"));
949 System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); 957 Byte[] buf = Util.UTF8NoBomEncoding.GetBytes(xml);
950 Byte[] buf = enc.GetBytes(xml);
951 fs.Write(buf, 0, buf.Length); 958 fs.Write(buf, 0, buf.Length);
952 fs.Close(); 959 fs.Close();
953 } 960 }
@@ -966,7 +973,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
966 public IScriptApi GetApi(string name) 973 public IScriptApi GetApi(string name)
967 { 974 {
968 if (m_Apis.ContainsKey(name)) 975 if (m_Apis.ContainsKey(name))
976 {
977// m_log.DebugFormat("[SCRIPT INSTANCE]: Found api {0} in {1}@{2}", name, ScriptName, PrimName);
978
969 return m_Apis[name]; 979 return m_Apis[name];
980 }
981
982// m_log.DebugFormat("[SCRIPT INSTANCE]: Did not find api {0} in {1}@{2}", name, ScriptName, PrimName);
983
970 return null; 984 return null;
971 } 985 }
972 986