aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs')
-rw-r--r--OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs138
1 files changed, 138 insertions, 0 deletions
diff --git a/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs b/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs
new file mode 100644
index 0000000..a97979f
--- /dev/null
+++ b/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs
@@ -0,0 +1,138 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System.Collections.Generic;
29using OpenSim.Framework.Console;
30using OpenSim.Region.Environment;
31using OpenSim.Region.Environment.Scenes;
32using OpenSim.Region.Environment.Interfaces;
33using OpenSim.Region.ExtensionsScriptModule.CSharp;
34using OpenSim.Region.ExtensionsScriptModule.JScript;
35using OpenSim.Region.ExtensionsScriptModule.JVMEngine;
36
37namespace OpenSim.Region.ExtensionsScriptModule
38{
39 public class ScriptManager : IRegionModule
40 {
41 List<IScript> scripts = new List<IScript>();
42 Scene m_scene;
43 Dictionary<string, IScriptCompiler> compilers = new Dictionary<string, IScriptCompiler>();
44
45 private void LoadFromCompiler(Dictionary<string, IScript> compiledscripts)
46 {
47 foreach (KeyValuePair<string, IScript> script in compiledscripts)
48 {
49 ScriptInfo scriptInfo = new ScriptInfo(m_scene); // Since each script could potentially corrupt their access with a stray assignment, making a new one for each script.
50 MainLog.Instance.Verbose("Loading " + script.Key);
51 script.Value.Initialise(scriptInfo);
52 scripts.Add(script.Value);
53 }
54 MainLog.Instance.Verbose("Finished loading " + compiledscripts.Count.ToString() + " script(s)");
55 }
56
57 public ScriptManager()
58 {
59 // Default Engines
60 CSharpScriptEngine csharpCompiler = new CSharpScriptEngine();
61 compilers.Add(csharpCompiler.FileExt(),csharpCompiler);
62
63 JScriptEngine jscriptCompiler = new JScriptEngine();
64 compilers.Add(jscriptCompiler.FileExt(), jscriptCompiler);
65
66 JavaEngine javaCompiler = new JavaEngine();
67 compilers.Add(javaCompiler.FileExt(), javaCompiler);
68 }
69
70 public void Initialise(Scene scene)
71 {
72 System.Console.WriteLine("Initialising Extensions Scripting Module");
73 m_scene = scene;
74
75 m_scene.RegisterAPIMethod("API_CompileExtensionScript", new ModuleAPIMethod<bool, string, int>(Compile));
76 m_scene.RegisterAPIMethod("API_AddExtensionScript", new ModuleAPIMethod<bool, IScript, int>(AddPreCompiledScript));
77 }
78
79 public void PostInitialise()
80 {
81
82 }
83
84 public void CloseDown()
85 {
86
87 }
88
89 public string GetName()
90 {
91 return "ExtensionsScriptingModule";
92 }
93
94 public bool Compile(string filename, int dummyParam)
95 {
96 foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers)
97 {
98 if (filename.EndsWith(compiler.Key))
99 {
100 LoadFromCompiler(compiler.Value.compile(filename));
101 break;
102 }
103 }
104
105 return true;
106 }
107
108 public void RunScriptCmd(string[] args)
109 {
110 switch (args[0])
111 {
112 case "load":
113 Compile(args[1], 0);
114 break;
115
116 default:
117 MainLog.Instance.Error("Unknown script command");
118 break;
119 }
120 }
121
122 public bool AddPreCompiledScript(IScript script, int dummyParam)
123 {
124 MainLog.Instance.Verbose("Loading script " + script.Name);
125 ScriptInfo scriptInfo = new ScriptInfo(m_scene); // Since each script could potentially corrupt their access with a stray assignment, making a new one for each script.
126 script.Initialise(scriptInfo);
127 scripts.Add(script);
128
129 return true;
130 }
131 }
132
133 interface IScriptCompiler
134 {
135 Dictionary<string,IScript> compile(string filename);
136 string FileExt();
137 }
138}