* Fleshed out the MRM Module a little.
* Please don't use this yet, it represents a very heavy security risk if you enable it.0.6.4-rc1
parent
f18400fcfb
commit
f3aac0fa4a
|
@ -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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ using System.Text;
|
|||
|
||||
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
|
||||
{
|
||||
interface IWorld
|
||||
public interface IWorld
|
||||
{
|
||||
IObject[] Objects { get; }
|
||||
IHeightmap Terrain { get; }
|
||||
|
|
|
@ -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<UUID,MiniModuleBase> m_scripts = new Dictionary<UUID, MiniModuleBase>();
|
||||
|
||||
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));
|
||||
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");
|
||||
mmb.InitMiniModule(m_world, m_host);
|
||||
}
|
||||
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<UUID, MiniModuleBase> 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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1058,3 +1058,6 @@ InterregionComms = "RESTComms"
|
|||
; - the second number indicates how many scrips failed to compile
|
||||
; - "oar error" if supplied, provides the error message from the OAR load
|
||||
channel_notify = -800
|
||||
|
||||
[MRM]
|
||||
Enabled = false ; Enables the Mini Region Modules Script Engine. WARNING: SECURITY RISK.
|
Loading…
Reference in New Issue