aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine/XEngine.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs104
1 files changed, 85 insertions, 19 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 0a6de60..1b49baa 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -314,8 +314,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
314 { 314 {
315 assembly = m_Compiler.PerformScriptCompile(script, 315 assembly = m_Compiler.PerformScriptCompile(script,
316 assetID.ToString()); 316 assetID.ToString());
317 m_log.DebugFormat("[XEngine] Loaded script {0}.{1}",
318 part.ParentGroup.RootPart.Name, item.Name);
319 } 317 }
320 catch (Exception e) 318 catch (Exception e)
321 { 319 {
@@ -387,8 +385,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine
387 m_DomainScripts[appDomain].Add(itemID); 385 m_DomainScripts[appDomain].Add(itemID);
388 386
389 XScriptInstance instance = new XScriptInstance(this,localID, 387 XScriptInstance instance = new XScriptInstance(this,localID,
390 part.UUID, itemID, assetID, assembly, 388 part.UUID, itemID, assetID, assembly,
391 m_AppDomains[appDomain]); 389 m_AppDomains[appDomain],
390 part.ParentGroup.RootPart.Name,
391 item.Name);
392
393 m_log.DebugFormat("[XEngine] Loaded script {0}.{1}",
394 part.ParentGroup.RootPart.Name, item.Name);
392 395
393 instance.AppDomain = appDomain; 396 instance.AppDomain = appDomain;
394 397
@@ -450,6 +453,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
450 UnloadAppDomain(instance.AppDomain); 453 UnloadAppDomain(instance.AppDomain);
451 } 454 }
452 455
456 instance.RemoveState();
457
453 instance = null; 458 instance = null;
454 459
455 CleanAssemblies(); 460 CleanAssemblies();
@@ -706,6 +711,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
706 private bool m_TimerQueued; 711 private bool m_TimerQueued;
707 private DateTime m_EventStart; 712 private DateTime m_EventStart;
708 private bool m_InEvent; 713 private bool m_InEvent;
714 private string m_PrimName;
715 private string m_ScriptName;
716 private string m_Assembly;
709 717
710 // Script state 718 // Script state
711 private string m_State="default"; 719 private string m_State="default";
@@ -715,6 +723,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
715 public bool Running 723 public bool Running
716 { 724 {
717 get { return m_RunEvents; } 725 get { return m_RunEvents; }
726 set { m_RunEvents = value; }
718 } 727 }
719 728
720 public string State 729 public string State
@@ -734,6 +743,16 @@ namespace OpenSim.Region.ScriptEngine.XEngine
734 set { m_AppDomain = value; } 743 set { m_AppDomain = value; }
735 } 744 }
736 745
746 public string PrimName
747 {
748 get { return m_PrimName; }
749 }
750
751 public string ScriptName
752 {
753 get { return m_ScriptName; }
754 }
755
737 public LLUUID ItemID 756 public LLUUID ItemID
738 { 757 {
739 get { return m_ItemID; } 758 get { return m_ItemID; }
@@ -766,7 +785,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
766 } 785 }
767 786
768 public XScriptInstance(XEngine engine, uint localID, LLUUID objectID, 787 public XScriptInstance(XEngine engine, uint localID, LLUUID objectID,
769 LLUUID itemID, LLUUID assetID, string assembly, AppDomain dom) 788 LLUUID itemID, LLUUID assetID, string assembly, AppDomain dom,
789 string primName, string scriptName)
770 { 790 {
771 m_Engine = engine; 791 m_Engine = engine;
772 792
@@ -774,6 +794,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
774 m_ObjectID = objectID; 794 m_ObjectID = objectID;
775 m_ItemID = itemID; 795 m_ItemID = itemID;
776 m_AssetID = assetID; 796 m_AssetID = assetID;
797 m_PrimName = primName;
798 m_ScriptName = scriptName;
799 m_Assembly = assembly;
777 800
778 SceneObjectPart part=engine.World.GetSceneObjectPart(localID); 801 SceneObjectPart part=engine.World.GetSceneObjectPart(localID);
779 if (part == null) 802 if (part == null)
@@ -811,10 +834,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
811 } 834 }
812 catch (Exception e) 835 catch (Exception e)
813 { 836 {
814 m_Engine.Log.Error("Error loading script instance\n"+e.ToString()); 837 m_Engine.Log.Error("[XEngine] Error loading script instance\n"+e.ToString());
838 return;
815 } 839 }
816 840
817 string savedState = assembly + ".state"; 841 string savedState = Path.Combine(Path.GetDirectoryName(assembly),
842 m_ItemID.ToString() + ".state");
818 if (File.Exists(savedState)) 843 if (File.Exists(savedState))
819 { 844 {
820 string xml = String.Empty; 845 string xml = String.Empty;
@@ -841,28 +866,53 @@ namespace OpenSim.Region.ScriptEngine.XEngine
841 m_Engine.m_ASYNCLSLCommandManager.CreateFromData( 866 m_Engine.m_ASYNCLSLCommandManager.CreateFromData(
842 m_LocalID, m_ItemID, m_ObjectID, 867 m_LocalID, m_ItemID, m_ObjectID,
843 PluginData); 868 PluginData);
869
870 m_Engine.Log.DebugFormat("[XEngine] Successfully retrieved state for script {0}.{1}", m_PrimName, m_ScriptName);
871
872 if(m_RunEvents)
873 {
874 m_RunEvents = false;
875 Start();
876 }
844 } 877 }
845 } 878 }
846 else 879 else
847 { 880 {
848 m_Engine.Log.Error("Unable to load script state: Memory limit exceeded"); 881 m_Engine.Log.Error("[XEngine] Unable to load script state: Memory limit exceeded");
849 PostEvent(new XEventParams("state_entry", 882 PostEvent(new XEventParams("state_entry",
850 new Object[0], new XDetectParams[0])); 883 new Object[0], new XDetectParams[0]));
884 Start();
851 } 885 }
852 } 886 }
853 catch (Exception e) 887 catch (Exception e)
854 { 888 {
855 m_Engine.Log.ErrorFormat("Unable to load script state from xml: {0}\n"+e.ToString(), xml); 889 m_Engine.Log.ErrorFormat("[XEngine] Unable to load script state from xml: {0}\n"+e.ToString(), xml);
856 PostEvent(new XEventParams("state_entry", 890 PostEvent(new XEventParams("state_entry",
857 new Object[0], new XDetectParams[0])); 891 new Object[0], new XDetectParams[0]));
892 Start();
858 } 893 }
859 } 894 }
860 else 895 else
861 { 896 {
897 m_Engine.Log.ErrorFormat("[XEngine] Unable to load script state, file not found");
862 PostEvent(new XEventParams("state_entry", 898 PostEvent(new XEventParams("state_entry",
863 new Object[0], new XDetectParams[0])); 899 new Object[0], new XDetectParams[0]));
900 Start();
901 }
902 }
903
904 public void RemoveState()
905 {
906 string savedState = Path.Combine(Path.GetDirectoryName(m_Assembly),
907 m_ItemID.ToString() + ".state");
908
909 try
910 {
911 File.Delete(savedState);
912 }
913 catch(Exception)
914 {
864 } 915 }
865 Start();
866 } 916 }
867 917
868 public void VarDump(Dictionary<string, object> vars) 918 public void VarDump(Dictionary<string, object> vars)
@@ -935,16 +985,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
935 985
936 result.Abort(); 986 result.Abort();
937 987
938 if (SmartThreadPool.WaitAll(new IWorkItemResult[] {result}, new TimeSpan((long)10000000), false)) 988 lock (m_EventQueue)
939 { 989 {
940 lock (m_EventQueue) 990 m_CurrentResult = null;
941 {
942 m_CurrentResult = null;
943 }
944 return true;
945 } 991 }
946 992
947 m_Engine.Log.Error("[XEngine] Failed to reliably stop script");
948 return true; 993 return true;
949 } 994 }
950 995
@@ -960,6 +1005,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
960 1005
961 public void PostEvent(XEventParams data) 1006 public void PostEvent(XEventParams data)
962 { 1007 {
1008// m_Engine.Log.DebugFormat("[XEngine] Posted event {2} in state {3} to {0}.{1}",
1009// m_PrimName, m_ScriptName, data.EventName, m_State);
963 lock (m_EventQueue) 1010 lock (m_EventQueue)
964 { 1011 {
965 if (m_EventQueue.Count >= m_Engine.MaxScriptQueue) 1012 if (m_EventQueue.Count >= m_Engine.MaxScriptQueue)
@@ -1003,6 +1050,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1003 1050
1004 if (data.EventName == "state") // Hardcoded state change 1051 if (data.EventName == "state") // Hardcoded state change
1005 { 1052 {
1053// m_Engine.Log.DebugFormat("[XEngine] Script {0}.{1} state set to {2}",
1054// m_PrimName, m_ScriptName, data.Params[0].ToString());
1006 m_State=data.Params[0].ToString(); 1055 m_State=data.Params[0].ToString();
1007 m_Engine.m_ASYNCLSLCommandManager.RemoveScript( 1056 m_Engine.m_ASYNCLSLCommandManager.RemoveScript(
1008 m_LocalID, m_ItemID); 1057 m_LocalID, m_ItemID);
@@ -1020,6 +1069,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1020// m_Engine.Log.DebugFormat("[XEngine] Processed event {0}", data.EventName); 1069// m_Engine.Log.DebugFormat("[XEngine] Processed event {0}", data.EventName);
1021 SceneObjectPart part = m_Engine.World.GetSceneObjectPart( 1070 SceneObjectPart part = m_Engine.World.GetSceneObjectPart(
1022 m_LocalID); 1071 m_LocalID);
1072// m_Engine.Log.DebugFormat("[XEngine] Delivered event {2} in state {3} to {0}.{1}",
1073// m_PrimName, m_ScriptName, data.EventName, m_State);
1074
1023 try 1075 try
1024 { 1076 {
1025 m_EventStart = DateTime.Now; 1077 m_EventStart = DateTime.Now;
@@ -1148,14 +1200,19 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1148 1200
1149 try 1201 try
1150 { 1202 {
1151 FileStream fs = File.Create(assembly + ".state"); 1203 FileStream fs = File.Create(Path.Combine(Path.GetDirectoryName(assembly), m_ItemID.ToString() + ".state"));
1152 System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); 1204 System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
1153 Byte[] buf = enc.GetBytes(xml); 1205 Byte[] buf = enc.GetBytes(xml);
1154 fs.Write(buf, 0, buf.Length); 1206 fs.Write(buf, 0, buf.Length);
1155 fs.Close(); 1207 fs.Close();
1156 } 1208 }
1157 catch(Exception) 1209 catch(Exception e)
1210 {
1211 Console.WriteLine("Unable to save xml\n"+e.ToString());
1212 }
1213 if(!File.Exists(Path.Combine(Path.GetDirectoryName(assembly), m_ItemID.ToString() + ".state")))
1158 { 1214 {
1215 throw new Exception("Completed persistence save, but no file was created");
1159 } 1216 }
1160 } 1217 }
1161 } 1218 }
@@ -1181,6 +1238,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1181 1238
1182 rootElement.AppendChild(state); 1239 rootElement.AppendChild(state);
1183 1240
1241 XmlElement running = xmldoc.CreateElement("", "Running", "");
1242 running.AppendChild(xmldoc.CreateTextNode(
1243 instance.Running.ToString()));
1244
1245 rootElement.AppendChild(running);
1246
1184 Dictionary<string, Object> vars = instance.GetVars(); 1247 Dictionary<string, Object> vars = instance.GetVars();
1185 1248
1186 XmlElement variables = xmldoc.CreateElement("", "Variables", ""); 1249 XmlElement variables = xmldoc.CreateElement("", "Variables", "");
@@ -1277,6 +1340,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1277 case "State": 1340 case "State":
1278 instance.State=part.InnerText; 1341 instance.State=part.InnerText;
1279 break; 1342 break;
1343 case "Running":
1344 instance.Running=bool.Parse(part.InnerText);
1345 break;
1280 case "Variables": 1346 case "Variables":
1281 XmlNodeList varL = part.ChildNodes; 1347 XmlNodeList varL = part.ChildNodes;
1282 foreach (XmlNode var in varL) 1348 foreach (XmlNode var in varL)