diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules')
6 files changed, 81 insertions, 3 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/ExtensionHandler.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/ExtensionHandler.cs new file mode 100644 index 0000000..bc159eb --- /dev/null +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/ExtensionHandler.cs | |||
@@ -0,0 +1,39 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces; | ||
5 | |||
6 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | ||
7 | { | ||
8 | class ExtensionHandler : IExtension | ||
9 | { | ||
10 | private readonly Dictionary<Type, object> m_instances; | ||
11 | |||
12 | public ExtensionHandler(Dictionary<Type, object> instances) | ||
13 | { | ||
14 | m_instances = instances; | ||
15 | } | ||
16 | |||
17 | public T Get<T>() | ||
18 | { | ||
19 | return (T) m_instances[typeof (T)]; | ||
20 | } | ||
21 | |||
22 | public bool TryGet<T>(out T extension) | ||
23 | { | ||
24 | if (!m_instances.ContainsKey(typeof(T))) | ||
25 | { | ||
26 | extension = default(T); | ||
27 | return false; | ||
28 | } | ||
29 | |||
30 | extension = Get<T>(); | ||
31 | return true; | ||
32 | } | ||
33 | |||
34 | public bool Has<T>() | ||
35 | { | ||
36 | return m_instances.ContainsKey(typeof (T)); | ||
37 | } | ||
38 | } | ||
39 | } | ||
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs index b7f67dd..94796e4 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs | |||
@@ -28,6 +28,7 @@ | |||
28 | using System.Reflection; | 28 | using System.Reflection; |
29 | using log4net; | 29 | using log4net; |
30 | using OpenSim.Region.Framework.Scenes; | 30 | using OpenSim.Region.Framework.Scenes; |
31 | using OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces; | ||
31 | 32 | ||
32 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | 33 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule |
33 | { | 34 | { |
@@ -36,11 +37,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | |||
36 | private readonly IObject m_obj; | 37 | private readonly IObject m_obj; |
37 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 38 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
38 | private readonly IGraphics m_graphics; | 39 | private readonly IGraphics m_graphics; |
40 | private readonly IExtension m_extend; | ||
39 | //private Scene m_scene; | 41 | //private Scene m_scene; |
40 | 42 | ||
41 | public Host(IObject m_obj, Scene m_scene) | 43 | public Host(IObject m_obj, Scene m_scene, IExtension m_extend) |
42 | { | 44 | { |
43 | this.m_obj = m_obj; | 45 | this.m_obj = m_obj; |
46 | this.m_extend = m_extend; | ||
44 | //this.m_scene = m_scene; | 47 | //this.m_scene = m_scene; |
45 | 48 | ||
46 | m_graphics = new Graphics(m_scene); | 49 | m_graphics = new Graphics(m_scene); |
@@ -60,5 +63,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | |||
60 | { | 63 | { |
61 | get { return m_graphics; } | 64 | get { return m_graphics; } |
62 | } | 65 | } |
66 | |||
67 | public IExtension Extensions | ||
68 | { | ||
69 | get { return m_extend; } | ||
70 | } | ||
63 | } | 71 | } |
64 | } | 72 | } |
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IMRMModule.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IMRMModule.cs new file mode 100644 index 0000000..4c37a44 --- /dev/null +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IMRMModule.cs | |||
@@ -0,0 +1,7 @@ | |||
1 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | ||
2 | { | ||
3 | public interface IMRMModule | ||
4 | { | ||
5 | void RegisterExtension<T>(T instance); | ||
6 | } | ||
7 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IExtension.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IExtension.cs new file mode 100644 index 0000000..b58e600 --- /dev/null +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IExtension.cs | |||
@@ -0,0 +1,13 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces | ||
6 | { | ||
7 | public interface IExtension | ||
8 | { | ||
9 | T Get<T>(); | ||
10 | bool TryGet<T>(out T extension); | ||
11 | bool Has<T>(); | ||
12 | } | ||
13 | } | ||
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IHost.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IHost.cs index 6c76919..fd73ffd 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IHost.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Interfaces/IHost.cs | |||
@@ -29,6 +29,7 @@ using System; | |||
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Text; | 30 | using System.Text; |
31 | using log4net; | 31 | using log4net; |
32 | using OpenSim.Region.OptionalModules.Scripting.Minimodule.Interfaces; | ||
32 | 33 | ||
33 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | 34 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule |
34 | { | 35 | { |
@@ -37,5 +38,6 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | |||
37 | IObject Object { get; } | 38 | IObject Object { get; } |
38 | ILog Console { get; } | 39 | ILog Console { get; } |
39 | IGraphics Graphics { get; } | 40 | IGraphics Graphics { get; } |
41 | IExtension Extensions { get; } | ||
40 | } | 42 | } |
41 | } | 43 | } |
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs index 0572fc7..b0fe222 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs | |||
@@ -41,15 +41,22 @@ using OpenSim.Region.Framework.Scenes; | |||
41 | 41 | ||
42 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | 42 | namespace OpenSim.Region.OptionalModules.Scripting.Minimodule |
43 | { | 43 | { |
44 | public class MRMModule : IRegionModule | 44 | public class MRMModule : IRegionModule, IMRMModule |
45 | { | 45 | { |
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
47 | private Scene m_scene; | 47 | private Scene m_scene; |
48 | 48 | ||
49 | private readonly Dictionary<UUID,MRMBase> m_scripts = new Dictionary<UUID, MRMBase>(); | 49 | private readonly Dictionary<UUID,MRMBase> m_scripts = new Dictionary<UUID, MRMBase>(); |
50 | 50 | ||
51 | private readonly Dictionary<Type,object> m_extensions = new Dictionary<Type, object>(); | ||
52 | |||
51 | private static readonly CSharpCodeProvider CScodeProvider = new CSharpCodeProvider(); | 53 | private static readonly CSharpCodeProvider CScodeProvider = new CSharpCodeProvider(); |
52 | 54 | ||
55 | public void RegisterExtension<T>(T instance) | ||
56 | { | ||
57 | m_extensions[typeof (T)] = instance; | ||
58 | } | ||
59 | |||
53 | public void Initialise(Scene scene, IConfigSource source) | 60 | public void Initialise(Scene scene, IConfigSource source) |
54 | { | 61 | { |
55 | if (source.Configs["MRM"] != null) | 62 | if (source.Configs["MRM"] != null) |
@@ -59,6 +66,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | |||
59 | m_log.Info("[MRM] Enabling MRM Module"); | 66 | m_log.Info("[MRM] Enabling MRM Module"); |
60 | m_scene = scene; | 67 | m_scene = scene; |
61 | scene.EventManager.OnRezScript += EventManager_OnRezScript; | 68 | scene.EventManager.OnRezScript += EventManager_OnRezScript; |
69 | |||
70 | scene.RegisterModuleInterface<IMRMModule>(this); | ||
62 | } | 71 | } |
63 | else | 72 | else |
64 | { | 73 | { |
@@ -82,7 +91,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | |||
82 | { | 91 | { |
83 | m_log.Info("[MRM] Found C# MRM"); | 92 | m_log.Info("[MRM] Found C# MRM"); |
84 | IWorld m_world = new World(m_scene); | 93 | IWorld m_world = new World(m_scene); |
85 | IHost m_host = new Host(new SOPObject(m_scene, localID), m_scene); | 94 | IHost m_host = new Host(new SOPObject(m_scene, localID), m_scene, new ExtensionHandler(m_extensions)); |
86 | 95 | ||
87 | MRMBase mmb = (MRMBase)AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap( | 96 | MRMBase mmb = (MRMBase)AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap( |
88 | CompileFromDotNetText(script, itemID.ToString()), | 97 | CompileFromDotNetText(script, itemID.ToString()), |