From f3aac0fa4af4b503e9fdffe866ca7c179d41f6aa Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Wed, 4 Mar 2009 22:14:40 +0000 Subject: * Fleshed out the MRM Module a little. * Please don't use this yet, it represents a very heavy security risk if you enable it. --- .../OptionalModules/Scripting/Minimodule/Host.cs | 8 ++ .../OptionalModules/Scripting/Minimodule/IHost.cs | 4 +- .../OptionalModules/Scripting/Minimodule/IWorld.cs | 2 +- .../Scripting/Minimodule/MiniModule.cs | 108 +++++++++++++-------- .../Scripting/Minimodule/MiniModuleBase.cs | 6 +- 5 files changed, 84 insertions(+), 44 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs index 41d368d..dcb70b4 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs @@ -1,12 +1,15 @@ using System; using System.Collections.Generic; +using System.Reflection; using System.Text; +using log4net; namespace OpenSim.Region.OptionalModules.Scripting.Minimodule { class Host : IHost { private readonly IObject m_obj; + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public Host(IObject m_obj) { @@ -17,5 +20,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule { get { return m_obj; } } + + public ILog Console + { + get { return m_log; } + } } } diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IHost.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IHost.cs index e47a278..8f95ba7 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IHost.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IHost.cs @@ -1,11 +1,13 @@ using System; using System.Collections.Generic; using System.Text; +using log4net; namespace OpenSim.Region.OptionalModules.Scripting.Minimodule { - interface IHost + public interface IHost { IObject Object { get; } + ILog Console { get; } } } diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs index 087f94f..2f1388e 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs @@ -4,7 +4,7 @@ using System.Text; namespace OpenSim.Region.OptionalModules.Scripting.Minimodule { - interface IWorld + public interface IWorld { IObject[] Objects { get; } IHeightmap Terrain { get; } diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MiniModule.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MiniModule.cs index 2e91142..ae8d632 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MiniModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MiniModule.cs @@ -1,47 +1,65 @@ using System; using System.CodeDom.Compiler; +using System.Collections.Generic; using System.IO; using System.Reflection; using System.Text; using log4net; using Microsoft.CSharp; using Nini.Config; +using OpenMetaverse; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; namespace OpenSim.Region.OptionalModules.Scripting.Minimodule { - class MiniModule : IRegionModule + public class MiniModule : IRegionModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private Scene m_scene; + private readonly Dictionary m_scripts = new Dictionary(); private static readonly CSharpCodeProvider CScodeProvider = new CSharpCodeProvider(); public void Initialise(Scene scene, IConfigSource source) { - m_scene = scene; - scene.EventManager.OnRezScript += EventManager_OnRezScript; + if (source.Configs["MRM"] != null) + { + if (source.Configs["MRM"].GetBoolean("Enabled", false)) + { + m_log.Info("[MRM] Enabling MRM Module"); + m_scene = scene; + scene.EventManager.OnRezScript += EventManager_OnRezScript; + } + else + { + m_log.Info("[MRM] Disabled MRM Module (Express)"); + } + } + else + { + m_log.Info("[MRM] Disabled MRM Module (Omission)"); + } } - void EventManager_OnRezScript(uint localID, OpenMetaverse.UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource) + void EventManager_OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource) { - if(true) - return; - - if(engine == "MiniMod") + if (script.StartsWith("//MiniMod:C#")) { - if(script.StartsWith("//MiniMod:C#")) - { - IWorld m_world = new World(m_scene); - IHost m_host = new Host(new SOPObject(m_scene, localID)); - - MiniModuleBase mmb = (MiniModuleBase) AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap( - CompileFromDotNetText(script, itemID.ToString()), - "OpenSim.MiniModule"); - mmb.InitMiniModule(m_world, m_host); - } + m_log.Info("[MRM] Found C# MRM"); + IWorld m_world = new World(m_scene); + IHost m_host = new Host(new SOPObject(m_scene, localID)); + + MiniModuleBase mmb = (MiniModuleBase) AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap( + CompileFromDotNetText(script, itemID.ToString()), + "OpenSim.MiniModule"); + m_log.Info("[MRM] Created MRM Instance"); + mmb.InitMiniModule(m_world, m_host); + m_scripts[itemID] = mmb; + + m_log.Info("[MRM] Starting MRM"); + mmb.Start(); } } @@ -52,7 +70,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule public void Close() { - + foreach (KeyValuePair pair in m_scripts) + { + pair.Value.Stop(); + } } public string Name @@ -78,8 +99,16 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule // Output assembly name string OutFile = Path.Combine("MiniModules", Path.Combine( - m_scene.RegionInfo.RegionID.ToString(), - FilePrefix + "_compiled_" + uuid + ".dll")); + m_scene.RegionInfo.RegionID.ToString(), + FilePrefix + "_compiled_" + uuid + ".dll")); + + // Create Directories for Assemblies + if (!Directory.Exists("MiniModules")) + Directory.CreateDirectory("MiniModules"); + string tmp = Path.Combine("MiniModules", m_scene.RegionInfo.RegionID.ToString()); + if (!Directory.Exists(tmp)) + Directory.CreateDirectory(tmp); + try { File.Delete(OutFile); @@ -87,26 +116,26 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule catch (IOException e) { throw new Exception("Unable to delete old existing " + - "script-file before writing new. Compile aborted: " + - e); + "script-file before writing new. Compile aborted: " + + e); } // DEBUG - write source to disk - string srcFileName = FilePrefix + "_source_" + - Path.GetFileNameWithoutExtension(OutFile) + ext; - try - { - File.WriteAllText(Path.Combine(Path.Combine( - "MiniModules", - m_scene.RegionInfo.RegionID.ToString()), - srcFileName), Script); - } - catch (Exception ex) //NOTLEGIT - Should be just FileIOException - { - m_log.Error("[Compiler]: Exception while " + - "trying to write script source to file \"" + - srcFileName + "\": " + ex.ToString()); - } + string srcFileName = FilePrefix + "_source_" + + Path.GetFileNameWithoutExtension(OutFile) + ext; + try + { + File.WriteAllText(Path.Combine(Path.Combine( + "MiniModules", + m_scene.RegionInfo.RegionID.ToString()), + srcFileName), Script); + } + catch (Exception ex) //NOTLEGIT - Should be just FileIOException + { + m_log.Error("[Compiler]: Exception while " + + "trying to write script source to file \"" + + srcFileName + "\": " + ex.ToString()); + } // Do actual compile CompilerParameters parameters = new CompilerParameters(); @@ -120,7 +149,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule // TODO: Add Libraries parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.OptionalModules.dll")); - + parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, + "log4net.dll")); parameters.GenerateExecutable = false; parameters.OutputAssembly = OutFile; diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MiniModuleBase.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MiniModuleBase.cs index a886158..9ce4506 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MiniModuleBase.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MiniModuleBase.cs @@ -1,6 +1,6 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule { - abstract class MiniModuleBase + public abstract class MiniModuleBase { private IWorld m_world; private IHost m_host; @@ -21,7 +21,7 @@ get { return m_host; } } - protected abstract void Start(); - protected abstract void Stop(); + public abstract void Start(); + public abstract void Stop(); } } -- cgit v1.1