aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Terrain.BasicTerrain/TerrainFilter.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/TerrainFilter.cs')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/TerrainFilter.cs103
1 files changed, 103 insertions, 0 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/TerrainFilter.cs b/OpenSim/Region/Terrain.BasicTerrain/TerrainFilter.cs
new file mode 100644
index 0000000..689375d
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/TerrainFilter.cs
@@ -0,0 +1,103 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using System.CodeDom.Compiler;
6using System.CodeDom;
7using Microsoft.CSharp;
8using Microsoft.JScript;
9
10using libTerrain;
11
12namespace OpenSim.Terrain
13{
14 public interface ITerrainFilter
15 {
16 void Filter(Channel heightmap, string[] args);
17 string Register();
18 string Help();
19 }
20
21 public class TestFilter : ITerrainFilter
22 {
23 public void Filter(Channel heightmap, string[] args)
24 {
25 Console.WriteLine("Hello world");
26 }
27
28 public string Register()
29 {
30 return "demofilter";
31 }
32
33 public string Help()
34 {
35 return "demofilter - Does nothing";
36 }
37 }
38
39 public class FilterHost
40 {
41 public Dictionary<string, ITerrainFilter> filters = new Dictionary<string, ITerrainFilter>();
42
43 private void LoadFilter(ICodeCompiler compiler, string filename)
44 {
45 CompilerParameters compilerParams = new CompilerParameters();
46 CompilerResults compilerResults;
47 compilerParams.GenerateExecutable = false;
48 compilerParams.GenerateInMemory = true;
49 compilerParams.IncludeDebugInformation = false;
50 compilerParams.ReferencedAssemblies.Add("libTerrain-BSD.dll");
51 compilerParams.ReferencedAssemblies.Add("OpenSim.Terrain.BasicTerrain.dll");
52 compilerParams.ReferencedAssemblies.Add("System.dll");
53
54 compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
55
56 if (compilerResults.Errors.Count > 0)
57 {
58 Console.WriteLine("Compile errors:");
59 foreach (CompilerError error in compilerResults.Errors)
60 {
61 Console.WriteLine(error.Line.ToString() + ": " + error.ErrorText.ToString());
62 }
63 }
64 else
65 {
66 foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
67 {
68 Type testInterface = pluginType.GetInterface("ITerrainFilter",true);
69
70 if (testInterface != null)
71 {
72 ITerrainFilter filter = (ITerrainFilter)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
73
74 string filterName = filter.Register();
75 Console.WriteLine("Plugin: " + filterName + " loaded.");
76
77 if (!filters.ContainsKey(filterName))
78 {
79 filters.Add(filterName, filter);
80 }
81 else
82 {
83 filters[filterName] = filter;
84 }
85 }
86 }
87 }
88
89 }
90
91 public void LoadFilterCSharp(string filename)
92 {
93 CSharpCodeProvider compiler = new CSharpCodeProvider();
94 LoadFilter(compiler.CreateCompiler(), filename);
95 }
96
97 public void LoadFilterJScript(string filename)
98 {
99 JScriptCodeProvider compiler = new JScriptCodeProvider();
100 LoadFilter(compiler.CreateCompiler(), filename);
101 }
102 }
103}