diff options
-rw-r--r-- | OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs | 263 |
1 files changed, 132 insertions, 131 deletions
diff --git a/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs b/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs index 61541e8..2aca347 100644 --- a/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs +++ b/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs | |||
@@ -1,30 +1,30 @@ | |||
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 | */ |
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using OpenSim.Framework.Console; | 29 | using OpenSim.Framework.Console; |
30 | using OpenSim.Region.Environment.Interfaces; | 30 | using OpenSim.Region.Environment.Interfaces; |
@@ -33,118 +33,119 @@ using OpenSim.Region.ExtensionsScriptModule.CSharp; | |||
33 | using OpenSim.Region.ExtensionsScriptModule.JScript; | 33 | using OpenSim.Region.ExtensionsScriptModule.JScript; |
34 | using OpenSim.Region.ExtensionsScriptModule.JVMEngine; | 34 | using OpenSim.Region.ExtensionsScriptModule.JVMEngine; |
35 | 35 | ||
36 | namespace OpenSim.Region.ExtensionsScriptModule | 36 | namespace OpenSim.Region.ExtensionsScriptModule |
37 | { | 37 | { |
38 | public class ScriptManager : IRegionModule, IExtensionScriptModule | 38 | public class ScriptManager : IRegionModule, IExtensionScriptModule |
39 | { | 39 | { |
40 | readonly List<IScript> scripts = new List<IScript>(); | 40 | readonly List<IScript> scripts = new List<IScript>(); |
41 | Scene m_scene; | 41 | Scene m_scene; |
42 | readonly Dictionary<string, IScriptCompiler> compilers = new Dictionary<string, IScriptCompiler>(); | 42 | readonly Dictionary<string, IScriptCompiler> compilers = new Dictionary<string, IScriptCompiler>(); |
43 | 43 | ||
44 | private void LoadFromCompiler(Dictionary<string, IScript> compiledscripts) | 44 | private void LoadFromCompiler(Dictionary<string, IScript> compiledscripts) |
45 | { | 45 | { |
46 | foreach (KeyValuePair<string, IScript> script in compiledscripts) | 46 | foreach (KeyValuePair<string, IScript> script in compiledscripts) |
47 | { | 47 | { |
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 | 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. |
49 | MainLog.Instance.Verbose("Loading " + script.Key); | 49 | MainLog.Instance.Verbose("Loading " + script.Key); |
50 | script.Value.Initialise(scriptInfo); | 50 | script.Value.Initialise(scriptInfo); |
51 | scripts.Add(script.Value); | 51 | scripts.Add(script.Value); |
52 | } | 52 | } |
53 | MainLog.Instance.Verbose("Finished loading " + compiledscripts.Count.ToString() + " script(s)"); | 53 | |
54 | } | 54 | MainLog.Instance.Verbose(string.Format("Finished loading {0} script(s)", compiledscripts.Count)); |
55 | 55 | } | |
56 | public ScriptManager() | 56 | |
57 | { | 57 | public ScriptManager() |
58 | // Default Engines | 58 | { |
59 | CSharpScriptEngine csharpCompiler = new CSharpScriptEngine(); | 59 | // Default Engines |
60 | compilers.Add(csharpCompiler.FileExt(), csharpCompiler); | 60 | CSharpScriptEngine csharpCompiler = new CSharpScriptEngine(); |
61 | 61 | compilers.Add(csharpCompiler.FileExt(), csharpCompiler); | |
62 | JScriptEngine jscriptCompiler = new JScriptEngine(); | 62 | |
63 | compilers.Add(jscriptCompiler.FileExt(), jscriptCompiler); | 63 | JScriptEngine jscriptCompiler = new JScriptEngine(); |
64 | 64 | compilers.Add(jscriptCompiler.FileExt(), jscriptCompiler); | |
65 | JavaEngine javaCompiler = new JavaEngine(); | 65 | |
66 | compilers.Add(javaCompiler.FileExt(), javaCompiler); | 66 | JavaEngine javaCompiler = new JavaEngine(); |
67 | compilers.Add(javaCompiler.FileExt(), javaCompiler); | ||
67 | } | 68 | } |
68 | 69 | ||
69 | public delegate TResult ModuleAPIMethod1<TResult, TParam0>(TParam0 param0); | 70 | public delegate TResult ModuleAPIMethod1<TResult, TParam0>(TParam0 param0); |
70 | public delegate TResult ModuleAPIMethod2<TResult, TParam0, TParam1>(TParam0 param0, TParam1 param1); | 71 | public delegate TResult ModuleAPIMethod2<TResult, TParam0, TParam1>(TParam0 param0, TParam1 param1); |
71 | 72 | ||
72 | public void Initialise(Scene scene) | 73 | public void Initialise(Scene scene) |
73 | { | 74 | { |
74 | System.Console.WriteLine("Initialising Extensions Scripting Module"); | 75 | System.Console.WriteLine("Initialising Extensions Scripting Module"); |
75 | m_scene = scene; | 76 | m_scene = scene; |
76 | 77 | ||
77 | m_scene.RegisterModuleInterface<IExtensionScriptModule>(this); | 78 | m_scene.RegisterModuleInterface<IExtensionScriptModule>(this); |
78 | } | 79 | } |
79 | 80 | ||
80 | public void PostInitialise() | 81 | public void PostInitialise() |
81 | { | 82 | { |
82 | 83 | ||
83 | } | 84 | } |
84 | 85 | ||
85 | public void CloseDown() | 86 | public void CloseDown() |
86 | { | 87 | { |
87 | 88 | ||
88 | } | 89 | } |
89 | 90 | ||
90 | public string GetName() | 91 | public string GetName() |
91 | { | 92 | { |
92 | return "ExtensionsScriptingModule"; | 93 | return "ExtensionsScriptingModule"; |
93 | } | 94 | } |
94 | 95 | ||
95 | public bool IsSharedModule() | 96 | public bool IsSharedModule() |
96 | { | 97 | { |
97 | return false; | 98 | return false; |
98 | } | 99 | } |
99 | 100 | ||
100 | public bool Compile(string filename) | 101 | public bool Compile(string filename) |
101 | { | 102 | { |
102 | foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers) | 103 | foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers) |
103 | { | 104 | { |
104 | if (filename.EndsWith(compiler.Key)) | 105 | if (filename.EndsWith(compiler.Key)) |
105 | { | 106 | { |
106 | LoadFromCompiler(compiler.Value.compile(filename)); | 107 | LoadFromCompiler(compiler.Value.compile(filename)); |
107 | break; | 108 | break; |
108 | } | 109 | } |
109 | } | 110 | } |
110 | 111 | ||
111 | return true; | 112 | return true; |
112 | } | 113 | } |
113 | 114 | ||
114 | public void RunScriptCmd(string[] args) | 115 | public void RunScriptCmd(string[] args) |
115 | { | 116 | { |
116 | switch (args[0]) | 117 | switch (args[0]) |
117 | { | 118 | { |
118 | case "load": | 119 | case "load": |
119 | Compile(args[1]); | 120 | Compile(args[1]); |
120 | break; | 121 | break; |
121 | 122 | ||
122 | default: | 123 | default: |
123 | MainLog.Instance.Error("Unknown script command"); | 124 | MainLog.Instance.Error("Unknown script command"); |
124 | break; | 125 | break; |
125 | } | 126 | } |
126 | } | 127 | } |
127 | 128 | ||
128 | public bool AddPreCompiledScript(IScript script) | 129 | public bool AddPreCompiledScript(IScript script) |
129 | { | 130 | { |
130 | MainLog.Instance.Verbose("Loading script " + script.Name); | 131 | MainLog.Instance.Verbose("Loading script " + script.Name); |
131 | 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. | 132 | 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. |
132 | script.Initialise(scriptInfo); | 133 | script.Initialise(scriptInfo); |
133 | scripts.Add(script); | 134 | scripts.Add(script); |
134 | 135 | ||
135 | return true; | 136 | return true; |
136 | } | 137 | } |
137 | } | 138 | } |
138 | 139 | ||
139 | public interface IExtensionScriptModule | 140 | public interface IExtensionScriptModule |
140 | { | 141 | { |
141 | bool Compile(string filename); | 142 | bool Compile(string filename); |
142 | bool AddPreCompiledScript(IScript script); | 143 | bool AddPreCompiledScript(IScript script); |
143 | } | 144 | } |
144 | 145 | ||
145 | interface IScriptCompiler | 146 | interface IScriptCompiler |
146 | { | 147 | { |
147 | Dictionary<string, IScript> compile(string filename); | 148 | Dictionary<string, IScript> compile(string filename); |
148 | string FileExt(); | 149 | string FileExt(); |
149 | } | 150 | } |
150 | } | 151 | } |