diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs | 296 |
1 files changed, 148 insertions, 148 deletions
diff --git a/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs b/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs index 61e9114..a818155 100644 --- a/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs +++ b/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs | |||
@@ -1,148 +1,148 @@ | |||
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; |
31 | using OpenSim.Region.Environment.Scenes; | 31 | using OpenSim.Region.Environment.Scenes; |
32 | using OpenSim.Region.ExtensionsScriptModule.CSharp; | 32 | 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 | 53 | ||
54 | MainLog.Instance.Verbose(string.Format("Finished loading {0} script(s)", compiledscripts.Count)); | 54 | MainLog.Instance.Verbose(string.Format("Finished loading {0} script(s)", compiledscripts.Count)); |
55 | } | 55 | } |
56 | 56 | ||
57 | public ScriptManager() | 57 | public ScriptManager() |
58 | { | 58 | { |
59 | // Default Engines | 59 | // Default Engines |
60 | CSharpScriptEngine csharpCompiler = new CSharpScriptEngine(); | 60 | CSharpScriptEngine csharpCompiler = new CSharpScriptEngine(); |
61 | compilers.Add(csharpCompiler.FileExt(), csharpCompiler); | 61 | compilers.Add(csharpCompiler.FileExt(), csharpCompiler); |
62 | 62 | ||
63 | JScriptEngine jscriptCompiler = new JScriptEngine(); | 63 | JScriptEngine jscriptCompiler = new JScriptEngine(); |
64 | compilers.Add(jscriptCompiler.FileExt(), jscriptCompiler); | 64 | compilers.Add(jscriptCompiler.FileExt(), jscriptCompiler); |
65 | 65 | ||
66 | JavaEngine javaCompiler = new JavaEngine(); | 66 | JavaEngine javaCompiler = new JavaEngine(); |
67 | compilers.Add(javaCompiler.FileExt(), javaCompiler); | 67 | compilers.Add(javaCompiler.FileExt(), javaCompiler); |
68 | } | 68 | } |
69 | 69 | ||
70 | public void Initialise(Scene scene) | 70 | public void Initialise(Scene scene) |
71 | { | 71 | { |
72 | System.Console.WriteLine("Initialising Extensions Scripting Module"); | 72 | System.Console.WriteLine("Initialising Extensions Scripting Module"); |
73 | m_scene = scene; | 73 | m_scene = scene; |
74 | 74 | ||
75 | m_scene.RegisterModuleInterface<IExtensionScriptModule>(this); | 75 | m_scene.RegisterModuleInterface<IExtensionScriptModule>(this); |
76 | } | 76 | } |
77 | 77 | ||
78 | public void PostInitialise() | 78 | public void PostInitialise() |
79 | { | 79 | { |
80 | 80 | ||
81 | } | 81 | } |
82 | 82 | ||
83 | public void CloseDown() | 83 | public void Close() |
84 | { | 84 | { |
85 | 85 | ||
86 | } | 86 | } |
87 | 87 | ||
88 | public string GetName() | 88 | public string Name |
89 | { | 89 | { |
90 | return "ExtensionsScriptingModule"; | 90 | get { return "ExtensionsScriptingModule"; } |
91 | } | 91 | } |
92 | 92 | ||
93 | public bool IsSharedModule() | 93 | public bool IsSharedModule |
94 | { | 94 | { |
95 | return false; | 95 | get { return false; } |
96 | } | 96 | } |
97 | 97 | ||
98 | public bool Compile(string filename) | 98 | public bool Compile(string filename) |
99 | { | 99 | { |
100 | foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers) | 100 | foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers) |
101 | { | 101 | { |
102 | if (filename.EndsWith(compiler.Key)) | 102 | if (filename.EndsWith(compiler.Key)) |
103 | { | 103 | { |
104 | LoadFromCompiler(compiler.Value.compile(filename)); | 104 | LoadFromCompiler(compiler.Value.compile(filename)); |
105 | break; | 105 | break; |
106 | } | 106 | } |
107 | } | 107 | } |
108 | 108 | ||
109 | return true; | 109 | return true; |
110 | } | 110 | } |
111 | 111 | ||
112 | public void RunScriptCmd(string[] args) | 112 | public void RunScriptCmd(string[] args) |
113 | { | 113 | { |
114 | switch (args[0]) | 114 | switch (args[0]) |
115 | { | 115 | { |
116 | case "load": | 116 | case "load": |
117 | Compile(args[1]); | 117 | Compile(args[1]); |
118 | break; | 118 | break; |
119 | 119 | ||
120 | default: | 120 | default: |
121 | MainLog.Instance.Error("Unknown script command"); | 121 | MainLog.Instance.Error("Unknown script command"); |
122 | break; | 122 | break; |
123 | } | 123 | } |
124 | } | 124 | } |
125 | 125 | ||
126 | public bool AddPreCompiledScript(IScript script) | 126 | public bool AddPreCompiledScript(IScript script) |
127 | { | 127 | { |
128 | MainLog.Instance.Verbose("Loading script " + script.Name); | 128 | MainLog.Instance.Verbose("Loading script " + script.Name); |
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 | 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. |
130 | script.Initialise(scriptInfo); | 130 | script.Initialise(scriptInfo); |
131 | scripts.Add(script); | 131 | scripts.Add(script); |
132 | 132 | ||
133 | return true; | 133 | return true; |
134 | } | 134 | } |
135 | } | 135 | } |
136 | 136 | ||
137 | public interface IExtensionScriptModule | 137 | public interface IExtensionScriptModule |
138 | { | 138 | { |
139 | bool Compile(string filename); | 139 | bool Compile(string filename); |
140 | bool AddPreCompiledScript(IScript script); | 140 | bool AddPreCompiledScript(IScript script); |
141 | } | 141 | } |
142 | 142 | ||
143 | interface IScriptCompiler | 143 | interface IScriptCompiler |
144 | { | 144 | { |
145 | Dictionary<string, IScript> compile(string filename); | 145 | Dictionary<string, IScript> compile(string filename); |
146 | string FileExt(); | 146 | string FileExt(); |
147 | } | 147 | } |
148 | } | 148 | } |