aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting/Minimodule
diff options
context:
space:
mode:
authorAdam Frisby2009-03-04 22:14:40 +0000
committerAdam Frisby2009-03-04 22:14:40 +0000
commitf3aac0fa4af4b503e9fdffe866ca7c179d41f6aa (patch)
treeb896779b8a5b2809e15b5d6ca309c7c149fcf96c /OpenSim/Region/OptionalModules/Scripting/Minimodule
parent* For now, restore file extension for default oar name I accidentally removed... (diff)
downloadopensim-SC_OLD-f3aac0fa4af4b503e9fdffe866ca7c179d41f6aa.zip
opensim-SC_OLD-f3aac0fa4af4b503e9fdffe866ca7c179d41f6aa.tar.gz
opensim-SC_OLD-f3aac0fa4af4b503e9fdffe866ca7c179d41f6aa.tar.bz2
opensim-SC_OLD-f3aac0fa4af4b503e9fdffe866ca7c179d41f6aa.tar.xz
* Fleshed out the MRM Module a little.
* Please don't use this yet, it represents a very heavy security risk if you enable it.
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting/Minimodule')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs8
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/IHost.cs4
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs2
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/MiniModule.cs108
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/MiniModuleBase.cs6
5 files changed, 84 insertions, 44 deletions
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 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Reflection;
3using System.Text; 4using System.Text;
5using log4net;
4 6
5namespace OpenSim.Region.OptionalModules.Scripting.Minimodule 7namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
6{ 8{
7 class Host : IHost 9 class Host : IHost
8 { 10 {
9 private readonly IObject m_obj; 11 private readonly IObject m_obj;
12 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
10 13
11 public Host(IObject m_obj) 14 public Host(IObject m_obj)
12 { 15 {
@@ -17,5 +20,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
17 { 20 {
18 get { return m_obj; } 21 get { return m_obj; }
19 } 22 }
23
24 public ILog Console
25 {
26 get { return m_log; }
27 }
20 } 28 }
21} 29}
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 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Text; 3using System.Text;
4using log4net;
4 5
5namespace OpenSim.Region.OptionalModules.Scripting.Minimodule 6namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
6{ 7{
7 interface IHost 8 public interface IHost
8 { 9 {
9 IObject Object { get; } 10 IObject Object { get; }
11 ILog Console { get; }
10 } 12 }
11} 13}
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;
4 4
5namespace OpenSim.Region.OptionalModules.Scripting.Minimodule 5namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
6{ 6{
7 interface IWorld 7 public interface IWorld
8 { 8 {
9 IObject[] Objects { get; } 9 IObject[] Objects { get; }
10 IHeightmap Terrain { get; } 10 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 @@
1using System; 1using System;
2using System.CodeDom.Compiler; 2using System.CodeDom.Compiler;
3using System.Collections.Generic;
3using System.IO; 4using System.IO;
4using System.Reflection; 5using System.Reflection;
5using System.Text; 6using System.Text;
6using log4net; 7using log4net;
7using Microsoft.CSharp; 8using Microsoft.CSharp;
8using Nini.Config; 9using Nini.Config;
10using OpenMetaverse;
9using OpenSim.Region.Framework.Interfaces; 11using OpenSim.Region.Framework.Interfaces;
10using OpenSim.Region.Framework.Scenes; 12using OpenSim.Region.Framework.Scenes;
11 13
12namespace OpenSim.Region.OptionalModules.Scripting.Minimodule 14namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
13{ 15{
14 class MiniModule : IRegionModule 16 public class MiniModule : IRegionModule
15 { 17 {
16 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 18 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
17 private Scene m_scene; 19 private Scene m_scene;
18 20
21 private readonly Dictionary<UUID,MiniModuleBase> m_scripts = new Dictionary<UUID, MiniModuleBase>();
19 22
20 private static readonly CSharpCodeProvider CScodeProvider = new CSharpCodeProvider(); 23 private static readonly CSharpCodeProvider CScodeProvider = new CSharpCodeProvider();
21 24
22 public void Initialise(Scene scene, IConfigSource source) 25 public void Initialise(Scene scene, IConfigSource source)
23 { 26 {
24 m_scene = scene; 27 if (source.Configs["MRM"] != null)
25 scene.EventManager.OnRezScript += EventManager_OnRezScript; 28 {
29 if (source.Configs["MRM"].GetBoolean("Enabled", false))
30 {
31 m_log.Info("[MRM] Enabling MRM Module");
32 m_scene = scene;
33 scene.EventManager.OnRezScript += EventManager_OnRezScript;
34 }
35 else
36 {
37 m_log.Info("[MRM] Disabled MRM Module (Express)");
38 }
39 }
40 else
41 {
42 m_log.Info("[MRM] Disabled MRM Module (Omission)");
43 }
26 } 44 }
27 45
28 void EventManager_OnRezScript(uint localID, OpenMetaverse.UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource) 46 void EventManager_OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource)
29 { 47 {
30 if(true) 48 if (script.StartsWith("//MiniMod:C#"))
31 return;
32
33 if(engine == "MiniMod")
34 { 49 {
35 if(script.StartsWith("//MiniMod:C#")) 50 m_log.Info("[MRM] Found C# MRM");
36 { 51 IWorld m_world = new World(m_scene);
37 IWorld m_world = new World(m_scene); 52 IHost m_host = new Host(new SOPObject(m_scene, localID));
38 IHost m_host = new Host(new SOPObject(m_scene, localID)); 53
39 54 MiniModuleBase mmb = (MiniModuleBase) AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap(
40 MiniModuleBase mmb = (MiniModuleBase) AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap( 55 CompileFromDotNetText(script, itemID.ToString()),
41 CompileFromDotNetText(script, itemID.ToString()), 56 "OpenSim.MiniModule");
42 "OpenSim.MiniModule"); 57 m_log.Info("[MRM] Created MRM Instance");
43 mmb.InitMiniModule(m_world, m_host); 58 mmb.InitMiniModule(m_world, m_host);
44 } 59 m_scripts[itemID] = mmb;
60
61 m_log.Info("[MRM] Starting MRM");
62 mmb.Start();
45 } 63 }
46 } 64 }
47 65
@@ -52,7 +70,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
52 70
53 public void Close() 71 public void Close()
54 { 72 {
55 73 foreach (KeyValuePair<UUID, MiniModuleBase> pair in m_scripts)
74 {
75 pair.Value.Stop();
76 }
56 } 77 }
57 78
58 public string Name 79 public string Name
@@ -78,8 +99,16 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
78 99
79 // Output assembly name 100 // Output assembly name
80 string OutFile = Path.Combine("MiniModules", Path.Combine( 101 string OutFile = Path.Combine("MiniModules", Path.Combine(
81 m_scene.RegionInfo.RegionID.ToString(), 102 m_scene.RegionInfo.RegionID.ToString(),
82 FilePrefix + "_compiled_" + uuid + ".dll")); 103 FilePrefix + "_compiled_" + uuid + ".dll"));
104
105 // Create Directories for Assemblies
106 if (!Directory.Exists("MiniModules"))
107 Directory.CreateDirectory("MiniModules");
108 string tmp = Path.Combine("MiniModules", m_scene.RegionInfo.RegionID.ToString());
109 if (!Directory.Exists(tmp))
110 Directory.CreateDirectory(tmp);
111
83 try 112 try
84 { 113 {
85 File.Delete(OutFile); 114 File.Delete(OutFile);
@@ -87,26 +116,26 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
87 catch (IOException e) 116 catch (IOException e)
88 { 117 {
89 throw new Exception("Unable to delete old existing " + 118 throw new Exception("Unable to delete old existing " +
90 "script-file before writing new. Compile aborted: " + 119 "script-file before writing new. Compile aborted: " +
91 e); 120 e);
92 } 121 }
93 122
94 // DEBUG - write source to disk 123 // DEBUG - write source to disk
95 string srcFileName = FilePrefix + "_source_" + 124 string srcFileName = FilePrefix + "_source_" +
96 Path.GetFileNameWithoutExtension(OutFile) + ext; 125 Path.GetFileNameWithoutExtension(OutFile) + ext;
97 try 126 try
98 { 127 {
99 File.WriteAllText(Path.Combine(Path.Combine( 128 File.WriteAllText(Path.Combine(Path.Combine(
100 "MiniModules", 129 "MiniModules",
101 m_scene.RegionInfo.RegionID.ToString()), 130 m_scene.RegionInfo.RegionID.ToString()),
102 srcFileName), Script); 131 srcFileName), Script);
103 } 132 }
104 catch (Exception ex) //NOTLEGIT - Should be just FileIOException 133 catch (Exception ex) //NOTLEGIT - Should be just FileIOException
105 { 134 {
106 m_log.Error("[Compiler]: Exception while " + 135 m_log.Error("[Compiler]: Exception while " +
107 "trying to write script source to file \"" + 136 "trying to write script source to file \"" +
108 srcFileName + "\": " + ex.ToString()); 137 srcFileName + "\": " + ex.ToString());
109 } 138 }
110 139
111 // Do actual compile 140 // Do actual compile
112 CompilerParameters parameters = new CompilerParameters(); 141 CompilerParameters parameters = new CompilerParameters();
@@ -120,7 +149,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
120 // TODO: Add Libraries 149 // TODO: Add Libraries
121 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, 150 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
122 "OpenSim.Region.OptionalModules.dll")); 151 "OpenSim.Region.OptionalModules.dll"));
123 152 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
153 "log4net.dll"));
124 154
125 parameters.GenerateExecutable = false; 155 parameters.GenerateExecutable = false;
126 parameters.OutputAssembly = OutFile; 156 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 @@
1namespace OpenSim.Region.OptionalModules.Scripting.Minimodule 1namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
2{ 2{
3 abstract class MiniModuleBase 3 public abstract class MiniModuleBase
4 { 4 {
5 private IWorld m_world; 5 private IWorld m_world;
6 private IHost m_host; 6 private IHost m_host;
@@ -21,7 +21,7 @@
21 get { return m_host; } 21 get { return m_host; }
22 } 22 }
23 23
24 protected abstract void Start(); 24 public abstract void Start();
25 protected abstract void Stop(); 25 public abstract void Stop();
26 } 26 }
27} 27}