From 88842edc95bafeb9f3b2f2ea0ab09394028a0916 Mon Sep 17 00:00:00 2001
From: Melanie
Date: Thu, 26 Nov 2009 12:08:20 +0000
Subject: Remove GetAssemblyName and friends from the SE interface. It's now
 handled internally

---
 OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 95 +++++++++++++++++++++++---
 1 file changed, 86 insertions(+), 9 deletions(-)

(limited to 'OpenSim/Region/ScriptEngine/XEngine/XEngine.cs')

diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index a60c0ba..0a9af2c 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -1245,20 +1245,97 @@ namespace OpenSim.Region.ScriptEngine.XEngine
             }
         }
 
-        public string GetAssemblyName(UUID itemID)
-        {
-            IScriptInstance instance = GetInstance(itemID);
-            if (instance == null)
-                return "";
-            return instance.GetAssemblyName();
-        }
-
         public string GetXMLState(UUID itemID)
         {
             IScriptInstance instance = GetInstance(itemID);
             if (instance == null)
                 return "";
-            return instance.GetXMLState();
+            string xml = instance.GetXMLState();
+
+            XmlDocument sdoc = new XmlDocument();
+            sdoc.LoadXml(xml);
+            XmlNodeList rootL = sdoc.GetElementsByTagName("ScriptState");
+            XmlNode rootNode = rootL[0];
+
+            // Create <State UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx">
+            XmlDocument doc = new XmlDocument();
+            XmlElement stateData = doc.CreateElement("", "State", "");
+            XmlAttribute stateID = doc.CreateAttribute("", "UUID", "");
+            stateID.Value = itemID.ToString();
+            stateData.Attributes.Append(stateID);
+            XmlAttribute assetID = doc.CreateAttribute("", "Asset", "");
+            assetID.Value = instance.AssetID.ToString();
+            stateData.Attributes.Append(assetID);
+            doc.AppendChild(stateData);
+
+            // Add <ScriptState>...</ScriptState>
+            XmlNode xmlstate = doc.ImportNode(rootNode, true);
+            stateData.AppendChild(xmlstate);
+
+            string assemName = instance.GetAssemblyName();
+
+            string fn = Path.GetFileName(assemName);
+
+            string assem = String.Empty;
+
+            if (File.Exists(assemName + ".text"))
+            {
+                FileInfo tfi = new FileInfo(assemName + ".text");
+
+                if (tfi != null)
+                {
+                    Byte[] tdata = new Byte[tfi.Length];
+
+                    try
+                    {
+                        FileStream tfs = File.Open(assemName + ".text",
+                                FileMode.Open, FileAccess.Read);
+                        tfs.Read(tdata, 0, tdata.Length);
+                        tfs.Close();
+
+                        assem = new System.Text.ASCIIEncoding().GetString(tdata);
+                    }
+                    catch (Exception e)
+                    {
+                         m_log.DebugFormat("[XEngine]: Unable to open script textfile {0}, reason: {1}", assemName+".text", e.Message);
+                    }
+                }
+            }
+            else
+            {
+                FileInfo fi = new FileInfo(assemName);
+
+                if (fi != null)
+                {
+                    Byte[] data = new Byte[fi.Length];
+
+                    try
+                    {
+                        FileStream fs = File.Open(assemName, FileMode.Open, FileAccess.Read);
+                        fs.Read(data, 0, data.Length);
+                        fs.Close();
+
+                        assem = System.Convert.ToBase64String(data);
+                    }
+                    catch (Exception e)
+                    {
+                        m_log.DebugFormat("[XEngine]: Unable to open script assembly {0}, reason: {1}", assemName, e.Message);
+                    }
+
+                }
+            }
+
+            XmlElement assemblyData = doc.CreateElement("", "Assembly", "");
+            XmlAttribute assemblyName = doc.CreateAttribute("", "Filename", "");
+
+            assemblyName.Value = fn;
+            assemblyData.Attributes.Append(assemblyName);
+
+            assemblyData.InnerText = assem;
+
+            stateData.AppendChild(assemblyData);
+
+            return doc.InnerXml;
         }
 
         public bool CanBeDeleted(UUID itemID)
-- 
cgit v1.1


From 9d63f90467dbc60622a49f564a56fdd20de90f51 Mon Sep 17 00:00:00 2001
From: Melanie
Date: Thu, 26 Nov 2009 17:03:09 +0000
Subject: Remove the old (Remoting) region crossing code. Fix the new code to
 pass script state and assembly again properly. Reintroduce respecting tht
 TrustBinaries flag. Changes the interregion protocol! No version bump because
 it was broken anyway, so with a version mismatch it will simply stay broken,
 but not crash. Region corssing still doesn't work because there is still
 monkey business with both rezzed prims being pushed across a border and
 attached prims when walking across a border. Teleport is untested by may
 work.

---
 OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 124 +++++++++++++++++++++++--
 1 file changed, 116 insertions(+), 8 deletions(-)

(limited to 'OpenSim/Region/ScriptEngine/XEngine/XEngine.cs')

diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 0a9af2c..b099177 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -1325,6 +1325,19 @@ namespace OpenSim.Region.ScriptEngine.XEngine
                 }
             }
 
+            string map = String.Empty;
+
+            if (File.Exists(fn + ".map"))
+            {
+                FileStream mfs = File.Open(fn + ".map", FileMode.Open, FileAccess.Read);
+                StreamReader msr = new StreamReader(mfs);
+
+                map = msr.ReadToEnd();
+
+                msr.Close();
+                mfs.Close();
+            }
+
             XmlElement assemblyData = doc.CreateElement("", "Assembly", "");
             XmlAttribute assemblyName = doc.CreateAttribute("", "Filename", "");
 
@@ -1335,21 +1348,116 @@ namespace OpenSim.Region.ScriptEngine.XEngine
 
             stateData.AppendChild(assemblyData);
 
-            return doc.InnerXml;
-        }
+            XmlElement mapData = doc.CreateElement("", "LineMap", "");
+            XmlAttribute mapName = doc.CreateAttribute("", "Filename", "");
 
-        public bool CanBeDeleted(UUID itemID)
-        {
-            IScriptInstance instance = GetInstance(itemID);
-            if (instance == null)
-                return true;
+            mapName.Value = fn + ".map";
+            mapData.Attributes.Append(mapName);
 
-            return instance.CanBeDeleted();
+            mapData.InnerText = map;
+
+            stateData.AppendChild(mapData);
+            return doc.InnerXml;
         }
 
         private bool ShowScriptSaveResponse(UUID ownerID, UUID assetID, string text, bool compiled)
         {
             return false;
         }
+
+        public void SetXMLState(UUID itemID, string xml)
+        {
+            if (xml == String.Empty)
+                return;
+
+            XmlDocument doc = new XmlDocument();
+
+            try
+            {
+                doc.LoadXml(xml);
+            }
+            catch (Exception)
+            {
+                m_log.Error("[XEngine]: Exception decoding XML data from region transfer");
+                return;
+            }
+
+            XmlNodeList rootL = doc.GetElementsByTagName("State");
+            if (rootL.Count < 1)
+                return;
+
+            XmlElement rootE = (XmlElement)rootL[0];
+
+            if (rootE.GetAttribute("UUID") != itemID.ToString())
+                return;
+
+            string assetID = rootE.GetAttribute("Asset");
+
+            XmlNodeList stateL = rootE.GetElementsByTagName("ScriptState");
+
+            if (stateL.Count != 1)
+                return;
+
+            XmlElement stateE = (XmlElement)stateL[0];
+
+            if (World.m_trustBinaries)
+            {
+                XmlNodeList assemL = rootE.GetElementsByTagName("Assembly");
+
+                if (assemL.Count != 1)
+                    return;
+
+                XmlElement assemE = (XmlElement)assemL[0];
+
+                string fn = assemE.GetAttribute("Filename");
+                string base64 = assemE.InnerText;
+
+                string path = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString());
+                path = Path.Combine(path, fn);
+
+                if (!File.Exists(path))
+                {
+                    Byte[] filedata = Convert.FromBase64String(base64);
+
+                    FileStream fs = File.Create(path);
+                    fs.Write(filedata, 0, filedata.Length);
+                    fs.Close();
+
+                    fs = File.Create(path + ".text");
+                    StreamWriter sw = new StreamWriter(fs);
+
+                    sw.Write(base64);
+
+                    sw.Close();
+                    fs.Close();
+                }
+            }
+
+            string statepath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString());
+            statepath = Path.Combine(statepath, itemID.ToString() + ".state");
+
+            FileStream sfs = File.Create(statepath);
+            StreamWriter ssw = new StreamWriter(sfs);
+
+            ssw.Write(stateE.OuterXml);
+
+            ssw.Close();
+            sfs.Close();
+
+            XmlNodeList mapL = rootE.GetElementsByTagName("LineMap");
+            
+            XmlElement mapE = (XmlElement)mapL[0];
+
+            string mappath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString());
+            mappath = Path.Combine(mappath, mapE.GetAttribute("Filename"));
+
+            FileStream mfs = File.Create(mappath);
+            StreamWriter msw = new StreamWriter(sfs);
+
+            msw.Write(mapE.InnerText);
+
+            msw.Close();
+            mfs.Close();
+        }
     }
 }
-- 
cgit v1.1


From c6bfecccaa3b1128c6d670bdedc13275732e738b Mon Sep 17 00:00:00 2001
From: Melanie
Date: Thu, 26 Nov 2009 17:16:02 +0000
Subject: Fix a small bug. Trusted script crossings now work again

---
 OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'OpenSim/Region/ScriptEngine/XEngine/XEngine.cs')

diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index b099177..5584f87 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -1452,7 +1452,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
             mappath = Path.Combine(mappath, mapE.GetAttribute("Filename"));
 
             FileStream mfs = File.Create(mappath);
-            StreamWriter msw = new StreamWriter(sfs);
+            StreamWriter msw = new StreamWriter(mfs);
 
             msw.Write(mapE.InnerText);
 
-- 
cgit v1.1