aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs286
1 files changed, 143 insertions, 143 deletions
diff --git a/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs b/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs
index 27b9c00..ac5ac89 100644
--- a/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs
+++ b/OpenSim/Region/ExtensionsScriptModule/ScriptManager.cs
@@ -1,143 +1,143 @@
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; 30using OpenSim.Region.Environment;
31using OpenSim.Region.Environment.Scenes; 31using OpenSim.Region.Environment.Scenes;
32using OpenSim.Region.Environment.Interfaces; 32using OpenSim.Region.Environment.Interfaces;
33using OpenSim.Region.ExtensionsScriptModule.CSharp; 33using OpenSim.Region.ExtensionsScriptModule.CSharp;
34using OpenSim.Region.ExtensionsScriptModule.JScript; 34using OpenSim.Region.ExtensionsScriptModule.JScript;
35using OpenSim.Region.ExtensionsScriptModule.JVMEngine; 35using OpenSim.Region.ExtensionsScriptModule.JVMEngine;
36 36
37namespace OpenSim.Region.ExtensionsScriptModule 37namespace OpenSim.Region.ExtensionsScriptModule
38{ 38{
39 public class ScriptManager : IRegionModule 39 public class ScriptManager : IRegionModule
40 { 40 {
41 List<IScript> scripts = new List<IScript>(); 41 List<IScript> scripts = new List<IScript>();
42 Scene m_scene; 42 Scene m_scene;
43 Dictionary<string, IScriptCompiler> compilers = new Dictionary<string, IScriptCompiler>(); 43 Dictionary<string, IScriptCompiler> compilers = new Dictionary<string, IScriptCompiler>();
44 44
45 private void LoadFromCompiler(Dictionary<string, IScript> compiledscripts) 45 private void LoadFromCompiler(Dictionary<string, IScript> compiledscripts)
46 { 46 {
47 foreach (KeyValuePair<string, IScript> script in compiledscripts) 47 foreach (KeyValuePair<string, IScript> script in compiledscripts)
48 { 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. 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); 50 MainLog.Instance.Verbose("Loading " + script.Key);
51 script.Value.Initialise(scriptInfo); 51 script.Value.Initialise(scriptInfo);
52 scripts.Add(script.Value); 52 scripts.Add(script.Value);
53 } 53 }
54 MainLog.Instance.Verbose("Finished loading " + compiledscripts.Count.ToString() + " script(s)"); 54 MainLog.Instance.Verbose("Finished loading " + compiledscripts.Count.ToString() + " script(s)");
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.RegisterAPIMethod("API_CompileExtensionScript", new ModuleAPIMethod1<bool, string>(Compile)); 75 m_scene.RegisterAPIMethod("API_CompileExtensionScript", new ModuleAPIMethod1<bool, string>(Compile));
76 m_scene.RegisterAPIMethod("API_AddExtensionScript", new ModuleAPIMethod1<bool, IScript>(AddPreCompiledScript)); 76 m_scene.RegisterAPIMethod("API_AddExtensionScript", new ModuleAPIMethod1<bool, IScript>(AddPreCompiledScript));
77 } 77 }
78 78
79 public void PostInitialise() 79 public void PostInitialise()
80 { 80 {
81 81
82 } 82 }
83 83
84 public void CloseDown() 84 public void CloseDown()
85 { 85 {
86 86
87 } 87 }
88 88
89 public string GetName() 89 public string GetName()
90 { 90 {
91 return "ExtensionsScriptingModule"; 91 return "ExtensionsScriptingModule";
92 } 92 }
93 93
94 public bool IsSharedModule() 94 public bool IsSharedModule()
95 { 95 {
96 return false; 96 return false;
97 } 97 }
98 98
99 public bool Compile(string filename) 99 public bool Compile(string filename)
100 { 100 {
101 foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers) 101 foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers)
102 { 102 {
103 if (filename.EndsWith(compiler.Key)) 103 if (filename.EndsWith(compiler.Key))
104 { 104 {
105 LoadFromCompiler(compiler.Value.compile(filename)); 105 LoadFromCompiler(compiler.Value.compile(filename));
106 break; 106 break;
107 } 107 }
108 } 108 }
109 109
110 return true; 110 return true;
111 } 111 }
112 112
113 public void RunScriptCmd(string[] args) 113 public void RunScriptCmd(string[] args)
114 { 114 {
115 switch (args[0]) 115 switch (args[0])
116 { 116 {
117 case "load": 117 case "load":
118 Compile(args[1]); 118 Compile(args[1]);
119 break; 119 break;
120 120
121 default: 121 default:
122 MainLog.Instance.Error("Unknown script command"); 122 MainLog.Instance.Error("Unknown script command");
123 break; 123 break;
124 } 124 }
125 } 125 }
126 126
127 public bool AddPreCompiledScript(IScript script) 127 public bool AddPreCompiledScript(IScript script)
128 { 128 {
129 MainLog.Instance.Verbose("Loading script " + script.Name); 129 MainLog.Instance.Verbose("Loading script " + script.Name);
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. 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 script.Initialise(scriptInfo); 131 script.Initialise(scriptInfo);
132 scripts.Add(script); 132 scripts.Add(script);
133 133
134 return true; 134 return true;
135 } 135 }
136 } 136 }
137 137
138 interface IScriptCompiler 138 interface IScriptCompiler
139 { 139 {
140 Dictionary<string, IScript> compile(string filename); 140 Dictionary<string, IScript> compile(string filename);
141 string FileExt(); 141 string FileExt();
142 } 142 }
143} 143}