* 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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using log4net;
|
||||||
|
|
||||||
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
|
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
|
||||||
{
|
{
|
||||||
class Host : IHost
|
class Host : IHost
|
||||||
{
|
{
|
||||||
private readonly IObject m_obj;
|
private readonly IObject m_obj;
|
||||||
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
public Host(IObject m_obj)
|
public Host(IObject m_obj)
|
||||||
{
|
{
|
||||||
|
@ -17,5 +20,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
|
||||||
{
|
{
|
||||||
get { return m_obj; }
|
get { return m_obj; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ILog Console
|
||||||
|
{
|
||||||
|
get { return m_log; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using log4net;
|
||||||
|
|
||||||
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
|
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
|
||||||
{
|
{
|
||||||
interface IHost
|
public interface IHost
|
||||||
{
|
{
|
||||||
IObject Object { get; }
|
IObject Object { get; }
|
||||||
|
ILog Console { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ using System.Text;
|
||||||
|
|
||||||
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
|
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
|
||||||
{
|
{
|
||||||
interface IWorld
|
public interface IWorld
|
||||||
{
|
{
|
||||||
IObject[] Objects { get; }
|
IObject[] Objects { get; }
|
||||||
IHeightmap Terrain { get; }
|
IHeightmap Terrain { get; }
|
||||||
|
|
|
@ -1,47 +1,65 @@
|
||||||
using System;
|
using System;
|
||||||
using System.CodeDom.Compiler;
|
using System.CodeDom.Compiler;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using log4net;
|
using log4net;
|
||||||
using Microsoft.CSharp;
|
using Microsoft.CSharp;
|
||||||
using Nini.Config;
|
using Nini.Config;
|
||||||
|
using OpenMetaverse;
|
||||||
using OpenSim.Region.Framework.Interfaces;
|
using OpenSim.Region.Framework.Interfaces;
|
||||||
using OpenSim.Region.Framework.Scenes;
|
using OpenSim.Region.Framework.Scenes;
|
||||||
|
|
||||||
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
|
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 static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
private Scene m_scene;
|
private Scene m_scene;
|
||||||
|
|
||||||
|
private readonly Dictionary<UUID,MiniModuleBase> m_scripts = new Dictionary<UUID, MiniModuleBase>();
|
||||||
|
|
||||||
private static readonly CSharpCodeProvider CScodeProvider = new CSharpCodeProvider();
|
private static readonly CSharpCodeProvider CScodeProvider = new CSharpCodeProvider();
|
||||||
|
|
||||||
public void Initialise(Scene scene, IConfigSource source)
|
public void Initialise(Scene scene, IConfigSource source)
|
||||||
{
|
{
|
||||||
m_scene = scene;
|
if (source.Configs["MRM"] != null)
|
||||||
scene.EventManager.OnRezScript += EventManager_OnRezScript;
|
{
|
||||||
|
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)
|
if (script.StartsWith("//MiniMod:C#"))
|
||||||
return;
|
|
||||||
|
|
||||||
if(engine == "MiniMod")
|
|
||||||
{
|
{
|
||||||
if(script.StartsWith("//MiniMod:C#"))
|
m_log.Info("[MRM] Found C# MRM");
|
||||||
{
|
IWorld m_world = new World(m_scene);
|
||||||
IWorld m_world = new World(m_scene);
|
IHost m_host = new Host(new SOPObject(m_scene, localID));
|
||||||
IHost m_host = new Host(new SOPObject(m_scene, localID));
|
|
||||||
|
|
||||||
MiniModuleBase mmb = (MiniModuleBase) AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap(
|
MiniModuleBase mmb = (MiniModuleBase) AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap(
|
||||||
CompileFromDotNetText(script, itemID.ToString()),
|
CompileFromDotNetText(script, itemID.ToString()),
|
||||||
"OpenSim.MiniModule");
|
"OpenSim.MiniModule");
|
||||||
mmb.InitMiniModule(m_world, m_host);
|
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()
|
public void Close()
|
||||||
{
|
{
|
||||||
|
foreach (KeyValuePair<UUID, MiniModuleBase> pair in m_scripts)
|
||||||
|
{
|
||||||
|
pair.Value.Stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
|
@ -78,8 +99,16 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
|
||||||
|
|
||||||
// Output assembly name
|
// Output assembly name
|
||||||
string OutFile = Path.Combine("MiniModules", Path.Combine(
|
string OutFile = Path.Combine("MiniModules", Path.Combine(
|
||||||
m_scene.RegionInfo.RegionID.ToString(),
|
m_scene.RegionInfo.RegionID.ToString(),
|
||||||
FilePrefix + "_compiled_" + uuid + ".dll"));
|
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
|
try
|
||||||
{
|
{
|
||||||
File.Delete(OutFile);
|
File.Delete(OutFile);
|
||||||
|
@ -87,26 +116,26 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
throw new Exception("Unable to delete old existing " +
|
throw new Exception("Unable to delete old existing " +
|
||||||
"script-file before writing new. Compile aborted: " +
|
"script-file before writing new. Compile aborted: " +
|
||||||
e);
|
e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEBUG - write source to disk
|
// DEBUG - write source to disk
|
||||||
string srcFileName = FilePrefix + "_source_" +
|
string srcFileName = FilePrefix + "_source_" +
|
||||||
Path.GetFileNameWithoutExtension(OutFile) + ext;
|
Path.GetFileNameWithoutExtension(OutFile) + ext;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.WriteAllText(Path.Combine(Path.Combine(
|
File.WriteAllText(Path.Combine(Path.Combine(
|
||||||
"MiniModules",
|
"MiniModules",
|
||||||
m_scene.RegionInfo.RegionID.ToString()),
|
m_scene.RegionInfo.RegionID.ToString()),
|
||||||
srcFileName), Script);
|
srcFileName), Script);
|
||||||
}
|
}
|
||||||
catch (Exception ex) //NOTLEGIT - Should be just FileIOException
|
catch (Exception ex) //NOTLEGIT - Should be just FileIOException
|
||||||
{
|
{
|
||||||
m_log.Error("[Compiler]: Exception while " +
|
m_log.Error("[Compiler]: Exception while " +
|
||||||
"trying to write script source to file \"" +
|
"trying to write script source to file \"" +
|
||||||
srcFileName + "\": " + ex.ToString());
|
srcFileName + "\": " + ex.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do actual compile
|
// Do actual compile
|
||||||
CompilerParameters parameters = new CompilerParameters();
|
CompilerParameters parameters = new CompilerParameters();
|
||||||
|
@ -120,7 +149,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
|
||||||
// TODO: Add Libraries
|
// TODO: Add Libraries
|
||||||
parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
|
parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
|
||||||
"OpenSim.Region.OptionalModules.dll"));
|
"OpenSim.Region.OptionalModules.dll"));
|
||||||
|
parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
|
||||||
|
"log4net.dll"));
|
||||||
|
|
||||||
parameters.GenerateExecutable = false;
|
parameters.GenerateExecutable = false;
|
||||||
parameters.OutputAssembly = OutFile;
|
parameters.OutputAssembly = OutFile;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
|
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
|
||||||
{
|
{
|
||||||
abstract class MiniModuleBase
|
public abstract class MiniModuleBase
|
||||||
{
|
{
|
||||||
private IWorld m_world;
|
private IWorld m_world;
|
||||||
private IHost m_host;
|
private IHost m_host;
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
get { return m_host; }
|
get { return m_host; }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void Start();
|
public abstract void Start();
|
||||||
protected abstract void Stop();
|
public abstract void Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1058,3 +1058,6 @@ InterregionComms = "RESTComms"
|
||||||
; - the second number indicates how many scrips failed to compile
|
; - the second number indicates how many scrips failed to compile
|
||||||
; - "oar error" if supplied, provides the error message from the OAR load
|
; - "oar error" if supplied, provides the error message from the OAR load
|
||||||
channel_notify = -800
|
channel_notify = -800
|
||||||
|
|
||||||
|
[MRM]
|
||||||
|
Enabled = false ; Enables the Mini Region Modules Script Engine. WARNING: SECURITY RISK.
|
Loading…
Reference in New Issue