From 03984e7304df152f5b415e38c314e39b7a551dc7 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Thu, 9 Apr 2009 13:03:27 +0000 Subject: * Added additional debug testing info to Scene * Corrected issue with MRMs where it would attempt to overwrite an already loaded DLL. (and thus fail with cryptic UnauthorizedAccessException.) * Made DrunkenTextAppreciationModule.cs MRM not crash with StackOverflowException * Added some temporary logging to MRM World.* --- .../Scripting/Minimodule/MRMModule.cs | 44 +++++++++++++++++++++- .../Test/DrunkenTextAppreciationModule.cs | 11 ++++-- .../OptionalModules/Scripting/Minimodule/World.cs | 7 +++- 3 files changed, 56 insertions(+), 6 deletions(-) (limited to 'OpenSim/Region/OptionalModules') diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs index 6fa8a24..71077f2 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs @@ -91,8 +91,23 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule m_log.Info("[MRM] Starting MRM"); mmb.Start(); } + catch (UnauthorizedAccessException e) + { + m_log.Error("[MRM] UAE " + e.Message); + m_log.Error("[MRM] " + e.StackTrace); + + if (e.InnerException != null) + m_log.Error("[MRM] " + e.InnerException); + + m_scene.Broadcast(delegate(IClientAPI user) + { + user.SendAlertMessage( + "MRM UnAuthorizedAccess: " + e); + }); + } catch (Exception e) { + m_log.Info("[MRM] Error: " + e); m_scene.Broadcast(delegate(IClientAPI user) { user.SendAlertMessage( @@ -133,13 +148,15 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule /// internal string CompileFromDotNetText(string Script, string uuid) { + m_log.Info("MRM 1"); const string ext = ".cs"; const string FilePrefix = "MiniModule"; // Output assembly name string OutFile = Path.Combine("MiniModules", Path.Combine( m_scene.RegionInfo.RegionID.ToString(), - FilePrefix + "_compiled_" + uuid + ".dll")); + FilePrefix + "_compiled_" + uuid + "_" + + Util.RandomClass.Next(9000) + ".dll")); // Create Directories for Assemblies if (!Directory.Exists("MiniModules")) @@ -148,10 +165,19 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule if (!Directory.Exists(tmp)) Directory.CreateDirectory(tmp); + + m_log.Info("MRM 2"); + try { File.Delete(OutFile); } + catch (UnauthorizedAccessException e) + { + throw new Exception("Unable to delete old existing " + + "script-file before writing new. Compile aborted: " + + e); + } catch (IOException e) { throw new Exception("Unable to delete old existing " + @@ -159,6 +185,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule e); } + m_log.Info("MRM 3"); + // DEBUG - write source to disk string srcFileName = FilePrefix + "_source_" + Path.GetFileNameWithoutExtension(OutFile) + ext; @@ -176,6 +204,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule srcFileName + "\": " + ex.ToString()); } + m_log.Info("MRM 4"); + // Do actual compile CompilerParameters parameters = new CompilerParameters(); @@ -196,9 +226,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule parameters.IncludeDebugInformation = true; parameters.TreatWarningsAsErrors = false; + m_log.Info("MRM 5"); + CompilerResults results = CScodeProvider.CompileAssemblyFromSource( parameters, Script); + m_log.Info("MRM 6"); + int display = 5; if (results.Errors.Count > 0) { @@ -232,6 +266,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule } } + m_log.Info("MRM 7"); + if (!File.Exists(OutFile)) { string errtext = String.Empty; @@ -256,6 +292,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule throw new Exception(errtext); } + m_log.Info("MRM 8"); + // Convert to base64 // string filetext = Convert.ToBase64String(data); @@ -264,10 +302,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule Byte[] buf = enc.GetBytes(filetext); + m_log.Info("MRM 9"); + FileStream sfs = File.Create(OutFile + ".cil.b64"); sfs.Write(buf, 0, buf.Length); sfs.Close(); + m_log.Info("MRM 10"); + return OutFile; } } diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Test/DrunkenTextAppreciationModule.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Test/DrunkenTextAppreciationModule.cs index 5b1841d..7e8db9c 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Test/DrunkenTextAppreciationModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Test/DrunkenTextAppreciationModule.cs @@ -38,11 +38,14 @@ namespace OpenSim void World_OnChat(IWorld sender, ChatEventArgs e) { - e.Text.Replace("s", "sh"); - e.Text.Replace("S", "Sh"); - e.Text += " ...hic!"; + if(!e.Text.Contains("hic!")) + { + e.Text = e.Text.Replace("s", "sh"); + e.Text = e.Text.Replace("S", "Sh"); + e.Text += " ...hic!"; - Host.Object.Say(e.Text); + Host.Object.Say(e.Text); + } } public override void Stop() diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs index e3553bf..802d984 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs @@ -26,7 +26,10 @@ */ using System.Collections.Generic; +using System.Reflection; +using log4net; using OpenSim.Framework; +using OpenSim.Framework.Client; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; @@ -34,6 +37,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule { public class World : IWorld { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private readonly Scene m_internalScene; private readonly Heightmap m_heights; @@ -100,7 +105,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule return; } // Avatar? - if (chat.SenderObject != null && chat.SenderObject == null) + if (chat.Sender != null && chat.SenderObject == null) { ChatEventArgs e = new ChatEventArgs(); e.Sender = new SPAvatar(m_internalScene, chat.SenderUUID); -- cgit v1.1