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.cs152
1 files changed, 0 insertions, 152 deletions
diff --git a/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs b/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs
deleted file mode 100644
index 48ebf86..0000000
--- a/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs
+++ /dev/null
@@ -1,152 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.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 System.Reflection;
30using log4net;
31using Nini.Config;
32using OpenSim.Region.Environment.Interfaces;
33using OpenSim.Region.Environment.Scenes;
34using OpenSim.Region.ExtensionsScriptModule.Engines.CSharp;
35using OpenSim.Region.ExtensionsScriptModule.Engines.JScript;
36using OpenSim.Region.ExtensionsScriptModule.Engines.JVMEngine;
37
38namespace OpenSim.Region.ExtensionsScriptModule
39{
40 public class ScriptManager : IRegionModule, IExtensionScriptModule
41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
44 private readonly List<IScript> scripts = new List<IScript>();
45 private Scene m_scene;
46 private readonly Dictionary<string, IScriptCompiler> compilers = new Dictionary<string, IScriptCompiler>();
47
48 private void LoadFromCompiler(Dictionary<string, IScript> compiledscripts)
49 {
50 foreach (KeyValuePair<string, IScript> script in compiledscripts)
51 {
52 ScriptInfo scriptInfo = new ScriptInfo(m_scene);
53 // Since each script could potentially corrupt their access with a stray assignment, making a new one for each script.
54 m_log.Info("[SCRIPT]: Loading " + script.Key);
55 script.Value.Initialise(scriptInfo);
56 scripts.Add(script.Value);
57 }
58
59 m_log.Info("[SCRIPT]: " + string.Format("Finished loading {0} script(s)", compiledscripts.Count));
60 }
61
62 public ScriptManager()
63 {
64 // Default Engines
65 CSharpScriptEngine csharpCompiler = new CSharpScriptEngine();
66 compilers.Add(csharpCompiler.FileExt(), csharpCompiler);
67
68 JScriptEngine jscriptCompiler = new JScriptEngine();
69 compilers.Add(jscriptCompiler.FileExt(), jscriptCompiler);
70
71 JavaEngine javaCompiler = new JavaEngine();
72 compilers.Add(javaCompiler.FileExt(), javaCompiler);
73 }
74
75 public void Initialise(Scene scene, IConfigSource config)
76 {
77 m_log.Info("[SCRIPTMODULE]: Initialising Extensions Scripting Module");
78 m_scene = scene;
79
80 m_scene.RegisterModuleInterface<IExtensionScriptModule>(this);
81 }
82
83 public void PostInitialise()
84 {
85 }
86
87 public void Close()
88 {
89 }
90
91 public string Name
92 {
93 get { return "ExtensionsScriptingModule"; }
94 }
95
96 public bool IsSharedModule
97 {
98 get { return false; }
99 }
100
101 public bool Compile(string filename)
102 {
103 foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers)
104 {
105 if (filename.EndsWith(compiler.Key))
106 {
107 LoadFromCompiler(compiler.Value.compile(filename));
108 break;
109 }
110 }
111
112 return true;
113 }
114
115 public void RunScriptCmd(string[] args)
116 {
117 switch (args[0])
118 {
119 case "load":
120 Compile(args[1]);
121 break;
122
123 default:
124 m_log.Error("Unknown script command");
125 break;
126 }
127 }
128
129 public bool AddPreCompiledScript(IScript script)
130 {
131 m_log.Info("[SCRIPT]: Loading script " + script.Name);
132 ScriptInfo scriptInfo = new ScriptInfo(m_scene);
133 // Since each script could potentially corrupt their access with a stray assignment, making a new one for each script.
134 script.Initialise(scriptInfo);
135 scripts.Add(script);
136
137 return true;
138 }
139 }
140
141 public interface IExtensionScriptModule
142 {
143 bool Compile(string filename);
144 bool AddPreCompiledScript(IScript script);
145 }
146
147 internal interface IScriptCompiler
148 {
149 Dictionary<string, IScript> compile(string filename);
150 string FileExt();
151 }
152}