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.cs297
1 files changed, 149 insertions, 148 deletions
diff --git a/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs b/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs
index a818155..be27a0b 100644
--- a/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs
+++ b/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs
@@ -1,148 +1,149 @@
1/* 1/*
2* Copyright (c) Contributors, http://opensimulator.org/ 2* Copyright (c) Contributors, http://opensimulator.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28using System.Collections.Generic; 28using System.Collections.Generic;
29using OpenSim.Framework.Console; 29using OpenSim.Framework.Console;
30using OpenSim.Region.Environment.Interfaces; 30using OpenSim.Region.Environment.Interfaces;
31using OpenSim.Region.Environment.Scenes; 31using OpenSim.Region.Environment.Scenes;
32using OpenSim.Region.ExtensionsScriptModule.CSharp; 32using OpenSim.Region.ExtensionsScriptModule.CSharp;
33using OpenSim.Region.ExtensionsScriptModule.JScript; 33using OpenSim.Region.ExtensionsScriptModule.JScript;
34using OpenSim.Region.ExtensionsScriptModule.JVMEngine; 34using OpenSim.Region.ExtensionsScriptModule.JVMEngine;
35 35using Nini.Config;
36namespace OpenSim.Region.ExtensionsScriptModule 36
37{ 37namespace OpenSim.Region.ExtensionsScriptModule
38 public class ScriptManager : IRegionModule, IExtensionScriptModule 38{
39 { 39 public class ScriptManager : IRegionModule, IExtensionScriptModule
40 readonly List<IScript> scripts = new List<IScript>(); 40 {
41 Scene m_scene; 41 readonly List<IScript> scripts = new List<IScript>();
42 readonly Dictionary<string, IScriptCompiler> compilers = new Dictionary<string, IScriptCompiler>(); 42 Scene m_scene;
43 43 readonly Dictionary<string, IScriptCompiler> compilers = new Dictionary<string, IScriptCompiler>();
44 private void LoadFromCompiler(Dictionary<string, IScript> compiledscripts) 44
45 { 45 private void LoadFromCompiler(Dictionary<string, IScript> compiledscripts)
46 foreach (KeyValuePair<string, IScript> script in compiledscripts) 46 {
47 { 47 foreach (KeyValuePair<string, IScript> script in compiledscripts)
48 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. 48 {
49 MainLog.Instance.Verbose("Loading " + script.Key); 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 script.Value.Initialise(scriptInfo); 50 MainLog.Instance.Verbose("Loading " + script.Key);
51 scripts.Add(script.Value); 51 script.Value.Initialise(scriptInfo);
52 } 52 scripts.Add(script.Value);
53 53 }
54 MainLog.Instance.Verbose(string.Format("Finished loading {0} script(s)", compiledscripts.Count)); 54
55 } 55 MainLog.Instance.Verbose(string.Format("Finished loading {0} script(s)", compiledscripts.Count));
56 56 }
57 public ScriptManager() 57
58 { 58 public ScriptManager()
59 // Default Engines 59 {
60 CSharpScriptEngine csharpCompiler = new CSharpScriptEngine(); 60 // Default Engines
61 compilers.Add(csharpCompiler.FileExt(), csharpCompiler); 61 CSharpScriptEngine csharpCompiler = new CSharpScriptEngine();
62 62 compilers.Add(csharpCompiler.FileExt(), csharpCompiler);
63 JScriptEngine jscriptCompiler = new JScriptEngine(); 63
64 compilers.Add(jscriptCompiler.FileExt(), jscriptCompiler); 64 JScriptEngine jscriptCompiler = new JScriptEngine();
65 65 compilers.Add(jscriptCompiler.FileExt(), jscriptCompiler);
66 JavaEngine javaCompiler = new JavaEngine(); 66
67 compilers.Add(javaCompiler.FileExt(), javaCompiler); 67 JavaEngine javaCompiler = new JavaEngine();
68 } 68 compilers.Add(javaCompiler.FileExt(), javaCompiler);
69 69 }
70 public void Initialise(Scene scene) 70
71 { 71 public void Initialise(Scene scene, IConfigSource config)
72 System.Console.WriteLine("Initialising Extensions Scripting Module"); 72 {
73 m_scene = scene; 73 System.Console.WriteLine("Initialising Extensions Scripting Module");
74 74 m_scene = scene;
75 m_scene.RegisterModuleInterface<IExtensionScriptModule>(this); 75
76 } 76 m_scene.RegisterModuleInterface<IExtensionScriptModule>(this);
77 77 }
78 public void PostInitialise() 78
79 { 79 public void PostInitialise()
80 80 {
81 } 81
82 82 }
83 public void Close() 83
84 { 84 public void Close()
85 85 {
86 } 86
87 87 }
88 public string Name 88
89 { 89 public string Name
90 get { return "ExtensionsScriptingModule"; } 90 {
91 } 91 get { return "ExtensionsScriptingModule"; }
92 92 }
93 public bool IsSharedModule 93
94{ 94 public bool IsSharedModule
95 get { return false; } 95{
96 } 96 get { return false; }
97 97 }
98 public bool Compile(string filename) 98
99 { 99 public bool Compile(string filename)
100 foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers) 100 {
101 { 101 foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers)
102 if (filename.EndsWith(compiler.Key)) 102 {
103 { 103 if (filename.EndsWith(compiler.Key))
104 LoadFromCompiler(compiler.Value.compile(filename)); 104 {
105 break; 105 LoadFromCompiler(compiler.Value.compile(filename));
106 } 106 break;
107 } 107 }
108 108 }
109 return true; 109
110 } 110 return true;
111 111 }
112 public void RunScriptCmd(string[] args) 112
113 { 113 public void RunScriptCmd(string[] args)
114 switch (args[0]) 114 {
115 { 115 switch (args[0])
116 case "load": 116 {
117 Compile(args[1]); 117 case "load":
118 break; 118 Compile(args[1]);
119 119 break;
120 default: 120
121 MainLog.Instance.Error("Unknown script command"); 121 default:
122 break; 122 MainLog.Instance.Error("Unknown script command");
123 } 123 break;
124 } 124 }
125 125 }
126 public bool AddPreCompiledScript(IScript script) 126
127 { 127 public bool AddPreCompiledScript(IScript script)
128 MainLog.Instance.Verbose("Loading script " + script.Name); 128 {
129 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. 129 MainLog.Instance.Verbose("Loading script " + script.Name);
130 script.Initialise(scriptInfo); 130 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.
131 scripts.Add(script); 131 script.Initialise(scriptInfo);
132 132 scripts.Add(script);
133 return true; 133
134 } 134 return true;
135 } 135 }
136 136 }
137 public interface IExtensionScriptModule 137
138 { 138 public interface IExtensionScriptModule
139 bool Compile(string filename); 139 {
140 bool AddPreCompiledScript(IScript script); 140 bool Compile(string filename);
141 } 141 bool AddPreCompiledScript(IScript script);
142 142 }
143 interface IScriptCompiler 143
144 { 144 interface IScriptCompiler
145 Dictionary<string, IScript> compile(string filename); 145 {
146 string FileExt(); 146 Dictionary<string, IScript> compile(string filename);
147 } 147 string FileExt();
148} 148 }
149}