diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine/XEngine.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 146 |
1 files changed, 101 insertions, 45 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index eeb125e..01021c9 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | |||
@@ -63,6 +63,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
63 | { | 63 | { |
64 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 64 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
65 | 65 | ||
66 | /// <summary> | ||
67 | /// Control the printing of certain debug messages. | ||
68 | /// </summary> | ||
69 | /// <remarks> | ||
70 | /// If DebugLevel >= 1, then we log every time that a script is started. | ||
71 | /// </remarks> | ||
72 | // public int DebugLevel { get; set; } | ||
73 | |||
66 | private SmartThreadPool m_ThreadPool; | 74 | private SmartThreadPool m_ThreadPool; |
67 | private int m_MaxScriptQueue; | 75 | private int m_MaxScriptQueue; |
68 | private Scene m_Scene; | 76 | private Scene m_Scene; |
@@ -284,9 +292,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
284 | AppDomain.CurrentDomain.AssemblyResolve += | 292 | AppDomain.CurrentDomain.AssemblyResolve += |
285 | OnAssemblyResolve; | 293 | OnAssemblyResolve; |
286 | 294 | ||
287 | m_log.InfoFormat("[XEngine] Initializing scripts in region {0}", | ||
288 | scene.RegionInfo.RegionName); | ||
289 | m_Scene = scene; | 295 | m_Scene = scene; |
296 | m_log.InfoFormat("[XEngine]: Initializing scripts in region {0}", m_Scene.RegionInfo.RegionName); | ||
290 | 297 | ||
291 | m_MinThreads = m_ScriptConfig.GetInt("MinThreads", 2); | 298 | m_MinThreads = m_ScriptConfig.GetInt("MinThreads", 2); |
292 | m_MaxThreads = m_ScriptConfig.GetInt("MaxThreads", 100); | 299 | m_MaxThreads = m_ScriptConfig.GetInt("MaxThreads", 100); |
@@ -389,9 +396,42 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
389 | "Starts all stopped scripts." | 396 | "Starts all stopped scripts." |
390 | + "If a <script-item-uuid> is given then only that script will be started. Otherwise, all suitable scripts are started.", | 397 | + "If a <script-item-uuid> is given then only that script will be started. Otherwise, all suitable scripts are started.", |
391 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStartScript)); | 398 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStartScript)); |
399 | |||
400 | // MainConsole.Instance.Commands.AddCommand( | ||
401 | // "Debug", false, "debug xengine", "debug xengine [<level>]", | ||
402 | // "Turn on detailed xengine debugging.", | ||
403 | // "If level <= 0, then no extra logging is done.\n" | ||
404 | // + "If level >= 1, then we log every time that a script is started.", | ||
405 | // HandleDebugLevelCommand); | ||
392 | } | 406 | } |
393 | 407 | ||
394 | /// <summary> | 408 | /// <summary> |
409 | /// Change debug level | ||
410 | /// </summary> | ||
411 | /// <param name="module"></param> | ||
412 | /// <param name="args"></param> | ||
413 | // private void HandleDebugLevelCommand(string module, string[] args) | ||
414 | // { | ||
415 | // if (args.Length == 3) | ||
416 | // { | ||
417 | // int newDebug; | ||
418 | // if (int.TryParse(args[2], out newDebug)) | ||
419 | // { | ||
420 | // DebugLevel = newDebug; | ||
421 | // MainConsole.Instance.OutputFormat("Debug level set to {0}", newDebug); | ||
422 | // } | ||
423 | // } | ||
424 | // else if (args.Length == 2) | ||
425 | // { | ||
426 | // MainConsole.Instance.OutputFormat("Current debug level is {0}", DebugLevel); | ||
427 | // } | ||
428 | // else | ||
429 | // { | ||
430 | // MainConsole.Instance.Output("Usage: debug xengine 0..1"); | ||
431 | // } | ||
432 | // } | ||
433 | |||
434 | /// <summary> | ||
395 | /// Parse the raw item id into a script instance from the command params if it's present. | 435 | /// Parse the raw item id into a script instance from the command params if it's present. |
396 | /// </summary> | 436 | /// </summary> |
397 | /// <param name="cmdparams"></param> | 437 | /// <param name="cmdparams"></param> |
@@ -892,8 +932,23 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
892 | } | 932 | } |
893 | 933 | ||
894 | object[] o; | 934 | object[] o; |
935 | |||
936 | int scriptsStarted = 0; | ||
937 | |||
895 | while (m_CompileQueue.Dequeue(out o)) | 938 | while (m_CompileQueue.Dequeue(out o)) |
896 | DoOnRezScript(o); | 939 | { |
940 | if (DoOnRezScript(o)) | ||
941 | { | ||
942 | scriptsStarted++; | ||
943 | |||
944 | // if (scriptsStarted % 50 == 0) | ||
945 | // m_log.DebugFormat( | ||
946 | // "[XEngine]: Started {0} scripts in {1}", scriptsStarted, m_Scene.RegionInfo.RegionName); | ||
947 | } | ||
948 | } | ||
949 | |||
950 | // m_log.DebugFormat( | ||
951 | // "[XEngine]: Completed starting {0} scripts on {1}", scriptsStarted, m_Scene.RegionInfo.RegionName); | ||
897 | 952 | ||
898 | // NOTE: Despite having a lockless queue, this lock is required | 953 | // NOTE: Despite having a lockless queue, this lock is required |
899 | // to make sure there is never no compile thread while there | 954 | // to make sure there is never no compile thread while there |
@@ -1749,14 +1804,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1749 | FileMode.Open, FileAccess.Read)) | 1804 | FileMode.Open, FileAccess.Read)) |
1750 | { | 1805 | { |
1751 | tfs.Read(tdata, 0, tdata.Length); | 1806 | tfs.Read(tdata, 0, tdata.Length); |
1752 | tfs.Close(); | ||
1753 | } | 1807 | } |
1754 | 1808 | ||
1755 | assem = new System.Text.ASCIIEncoding().GetString(tdata); | 1809 | assem = new System.Text.ASCIIEncoding().GetString(tdata); |
1756 | } | 1810 | } |
1757 | catch (Exception e) | 1811 | catch (Exception e) |
1758 | { | 1812 | { |
1759 | m_log.DebugFormat("[XEngine]: Unable to open script textfile {0}, reason: {1}", assemName+".text", e.Message); | 1813 | m_log.ErrorFormat( |
1814 | "[XEngine]: Unable to open script textfile {0}{1}, reason: {2}", | ||
1815 | assemName, ".text", e.Message); | ||
1760 | } | 1816 | } |
1761 | } | 1817 | } |
1762 | } | 1818 | } |
@@ -1773,16 +1829,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1773 | using (FileStream fs = File.Open(assemName, FileMode.Open, FileAccess.Read)) | 1829 | using (FileStream fs = File.Open(assemName, FileMode.Open, FileAccess.Read)) |
1774 | { | 1830 | { |
1775 | fs.Read(data, 0, data.Length); | 1831 | fs.Read(data, 0, data.Length); |
1776 | fs.Close(); | ||
1777 | } | 1832 | } |
1778 | 1833 | ||
1779 | assem = System.Convert.ToBase64String(data); | 1834 | assem = System.Convert.ToBase64String(data); |
1780 | } | 1835 | } |
1781 | catch (Exception e) | 1836 | catch (Exception e) |
1782 | { | 1837 | { |
1783 | m_log.DebugFormat("[XEngine]: Unable to open script assembly {0}, reason: {1}", assemName, e.Message); | 1838 | m_log.ErrorFormat( |
1839 | "[XEngine]: Unable to open script assembly {0}, reason: {1}", assemName, e.Message); | ||
1784 | } | 1840 | } |
1785 | |||
1786 | } | 1841 | } |
1787 | } | 1842 | } |
1788 | 1843 | ||
@@ -1795,9 +1850,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1795 | using (StreamReader msr = new StreamReader(mfs)) | 1850 | using (StreamReader msr = new StreamReader(mfs)) |
1796 | { | 1851 | { |
1797 | map = msr.ReadToEnd(); | 1852 | map = msr.ReadToEnd(); |
1798 | msr.Close(); | ||
1799 | } | 1853 | } |
1800 | mfs.Close(); | ||
1801 | } | 1854 | } |
1802 | } | 1855 | } |
1803 | 1856 | ||
@@ -1833,6 +1886,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1833 | 1886 | ||
1834 | public bool SetXMLState(UUID itemID, string xml) | 1887 | public bool SetXMLState(UUID itemID, string xml) |
1835 | { | 1888 | { |
1889 | // m_log.DebugFormat("[XEngine]: Writing state for script item with ID {0}", itemID); | ||
1890 | |||
1836 | if (xml == String.Empty) | 1891 | if (xml == String.Empty) |
1837 | return false; | 1892 | return false; |
1838 | 1893 | ||
@@ -1893,14 +1948,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1893 | { | 1948 | { |
1894 | using (FileStream fs = File.Create(path)) | 1949 | using (FileStream fs = File.Create(path)) |
1895 | { | 1950 | { |
1951 | // m_log.DebugFormat("[XEngine]: Writing assembly file {0}", path); | ||
1952 | |||
1896 | fs.Write(filedata, 0, filedata.Length); | 1953 | fs.Write(filedata, 0, filedata.Length); |
1897 | fs.Close(); | ||
1898 | } | 1954 | } |
1899 | } | 1955 | } |
1900 | catch (IOException ex) | 1956 | catch (IOException ex) |
1901 | { | 1957 | { |
1902 | // if there already exists a file at that location, it may be locked. | 1958 | // if there already exists a file at that location, it may be locked. |
1903 | m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", path, ex.Message); | 1959 | m_log.ErrorFormat("[XEngine]: Error whilst writing assembly file {0}, {1}", path, ex.Message); |
1904 | } | 1960 | } |
1905 | 1961 | ||
1906 | string textpath = path + ".text"; | 1962 | string textpath = path + ".text"; |
@@ -1910,16 +1966,43 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1910 | { | 1966 | { |
1911 | using (StreamWriter sw = new StreamWriter(fs)) | 1967 | using (StreamWriter sw = new StreamWriter(fs)) |
1912 | { | 1968 | { |
1969 | // m_log.DebugFormat("[XEngine]: Writing .text file {0}", textpath); | ||
1970 | |||
1913 | sw.Write(base64); | 1971 | sw.Write(base64); |
1914 | sw.Close(); | ||
1915 | } | 1972 | } |
1916 | fs.Close(); | ||
1917 | } | 1973 | } |
1918 | } | 1974 | } |
1919 | catch (IOException ex) | 1975 | catch (IOException ex) |
1920 | { | 1976 | { |
1921 | // if there already exists a file at that location, it may be locked. | 1977 | // if there already exists a file at that location, it may be locked. |
1922 | m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", textpath, ex.Message); | 1978 | m_log.ErrorFormat("[XEngine]: Error whilst writing .text file {0}, {1}", textpath, ex.Message); |
1979 | } | ||
1980 | } | ||
1981 | |||
1982 | XmlNodeList mapL = rootE.GetElementsByTagName("LineMap"); | ||
1983 | if (mapL.Count > 0) | ||
1984 | { | ||
1985 | XmlElement mapE = (XmlElement)mapL[0]; | ||
1986 | |||
1987 | string mappath = Path.Combine(m_ScriptEnginesPath, World.RegionInfo.RegionID.ToString()); | ||
1988 | mappath = Path.Combine(mappath, mapE.GetAttribute("Filename")); | ||
1989 | |||
1990 | try | ||
1991 | { | ||
1992 | using (FileStream mfs = File.Create(mappath)) | ||
1993 | { | ||
1994 | using (StreamWriter msw = new StreamWriter(mfs)) | ||
1995 | { | ||
1996 | // m_log.DebugFormat("[XEngine]: Writing linemap file {0}", mappath); | ||
1997 | |||
1998 | msw.Write(mapE.InnerText); | ||
1999 | } | ||
2000 | } | ||
2001 | } | ||
2002 | catch (IOException ex) | ||
2003 | { | ||
2004 | // if there already exists a file at that location, it may be locked. | ||
2005 | m_log.ErrorFormat("[XEngine]: Linemap file {0} already exists! {1}", mappath, ex.Message); | ||
1923 | } | 2006 | } |
1924 | } | 2007 | } |
1925 | } | 2008 | } |
@@ -1933,43 +2016,16 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
1933 | { | 2016 | { |
1934 | using (StreamWriter ssw = new StreamWriter(sfs)) | 2017 | using (StreamWriter ssw = new StreamWriter(sfs)) |
1935 | { | 2018 | { |
2019 | // m_log.DebugFormat("[XEngine]: Writing state file {0}", statepath); | ||
2020 | |||
1936 | ssw.Write(stateE.OuterXml); | 2021 | ssw.Write(stateE.OuterXml); |
1937 | ssw.Close(); | ||
1938 | } | 2022 | } |
1939 | sfs.Close(); | ||
1940 | } | 2023 | } |
1941 | } | 2024 | } |
1942 | catch (IOException ex) | 2025 | catch (IOException ex) |
1943 | { | 2026 | { |
1944 | // if there already exists a file at that location, it may be locked. | 2027 | // if there already exists a file at that location, it may be locked. |
1945 | m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", statepath, ex.Message); | 2028 | m_log.ErrorFormat("[XEngine]: Error whilst writing state file {0}, {1}", statepath, ex.Message); |
1946 | } | ||
1947 | |||
1948 | XmlNodeList mapL = rootE.GetElementsByTagName("LineMap"); | ||
1949 | if (mapL.Count > 0) | ||
1950 | { | ||
1951 | XmlElement mapE = (XmlElement)mapL[0]; | ||
1952 | |||
1953 | string mappath = Path.Combine(m_ScriptEnginesPath, World.RegionInfo.RegionID.ToString()); | ||
1954 | mappath = Path.Combine(mappath, mapE.GetAttribute("Filename")); | ||
1955 | |||
1956 | try | ||
1957 | { | ||
1958 | using (FileStream mfs = File.Create(mappath)) | ||
1959 | { | ||
1960 | using (StreamWriter msw = new StreamWriter(mfs)) | ||
1961 | { | ||
1962 | msw.Write(mapE.InnerText); | ||
1963 | msw.Close(); | ||
1964 | } | ||
1965 | mfs.Close(); | ||
1966 | } | ||
1967 | } | ||
1968 | catch (IOException ex) | ||
1969 | { | ||
1970 | // if there already exists a file at that location, it may be locked. | ||
1971 | m_log.ErrorFormat("[XEngine]: File {0} already exists! {1}", mappath, ex.Message); | ||
1972 | } | ||
1973 | } | 2029 | } |
1974 | 2030 | ||
1975 | return true; | 2031 | return true; |