diff options
author | Tedd Hansen | 2008-11-08 17:35:48 +0000 |
---|---|---|
committer | Tedd Hansen | 2008-11-08 17:35:48 +0000 |
commit | 9511a8c76370f21e839114007dcd2b25c69b009a (patch) | |
tree | b63323dfd96ecd1cc3cd560939bd66bb43ec9c1c /OpenSim/ScriptEngine/Shared | |
parent | * Added IClientIM to IClientCore interfaces (diff) | |
download | opensim-SC-9511a8c76370f21e839114007dcd2b25c69b009a.zip opensim-SC-9511a8c76370f21e839114007dcd2b25c69b009a.tar.gz opensim-SC-9511a8c76370f21e839114007dcd2b25c69b009a.tar.bz2 opensim-SC-9511a8c76370f21e839114007dcd2b25c69b009a.tar.xz |
Work in progress on SECS stuff. Have been holding it off until after 0.6 release. Still messy as hell and doesn't really work yet. Will undergo dramatic changes. AND MOST IMPORTANTLY: Will be conformed to work in coop with todays DNE and XEngine, hopefully one day providing a common interface for all components.
Diffstat (limited to '')
18 files changed, 591 insertions, 44 deletions
diff --git a/OpenSim/ScriptEngine/Shared.Script/ICommandProvider.cs b/OpenSim/ScriptEngine/Shared.Script/ICommandProvider.cs new file mode 100644 index 0000000..fefb5f9 --- /dev/null +++ b/OpenSim/ScriptEngine/Shared.Script/ICommandProvider.cs | |||
@@ -0,0 +1,12 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace ScriptAssemblies | ||
6 | { | ||
7 | public interface ICommandProvider | ||
8 | { | ||
9 | void ExecuteCommand(string functionName, params object[] args); | ||
10 | string Name { get; } | ||
11 | } | ||
12 | } | ||
diff --git a/OpenSim/ScriptEngine/Shared.Script/IScript.cs b/OpenSim/ScriptEngine/Shared.Script/IScript.cs new file mode 100644 index 0000000..5a3d3f3 --- /dev/null +++ b/OpenSim/ScriptEngine/Shared.Script/IScript.cs | |||
@@ -0,0 +1,11 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace ScriptAssemblies | ||
6 | { | ||
7 | public interface IScript | ||
8 | { | ||
9 | void ExecuteFunction(string functionName, params object[] args); | ||
10 | } | ||
11 | } \ No newline at end of file | ||
diff --git a/OpenSim/ScriptEngine/Shared.Script/Properties/AssemblyInfo.cs b/OpenSim/ScriptEngine/Shared.Script/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..96b6c0c --- /dev/null +++ b/OpenSim/ScriptEngine/Shared.Script/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,36 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | |||
5 | // General Information about an assembly is controlled through the following | ||
6 | // set of attributes. Change these attribute values to modify the information | ||
7 | // associated with an assembly. | ||
8 | [assembly: AssemblyTitle("OpenSim.ScriptEngine.Shared.Script")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("Microsoft")] | ||
12 | [assembly: AssemblyProduct("OpenSim.ScriptEngine.Shared.Script")] | ||
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2008")] | ||
14 | [assembly: AssemblyTrademark("")] | ||
15 | [assembly: AssemblyCulture("")] | ||
16 | |||
17 | // Setting ComVisible to false makes the types in this assembly not visible | ||
18 | // to COM components. If you need to access a type in this assembly from | ||
19 | // COM, set the ComVisible attribute to true on that type. | ||
20 | [assembly: ComVisible(false)] | ||
21 | |||
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
23 | [assembly: Guid("ea77002b-c967-4368-ace9-6533f8147d4b")] | ||
24 | |||
25 | // Version information for an assembly consists of the following four values: | ||
26 | // | ||
27 | // Major Version | ||
28 | // Minor Version | ||
29 | // Build Number | ||
30 | // Revision | ||
31 | // | ||
32 | // You can specify all the values or you can default the Build and Revision Numbers | ||
33 | // by using the '*' as shown below: | ||
34 | // [assembly: AssemblyVersion("1.0.*")] | ||
35 | [assembly: AssemblyVersion("1.0.0.0")] | ||
36 | [assembly: AssemblyFileVersion("1.0.0.0")] | ||
diff --git a/OpenSim/ScriptEngine/Shared.Script/ScriptBase.cs b/OpenSim/ScriptEngine/Shared.Script/ScriptBase.cs new file mode 100644 index 0000000..587314f --- /dev/null +++ b/OpenSim/ScriptEngine/Shared.Script/ScriptBase.cs | |||
@@ -0,0 +1,45 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Reflection; | ||
4 | using System.Runtime.Remoting.Lifetime; | ||
5 | using System.Text; | ||
6 | |||
7 | namespace ScriptAssemblies | ||
8 | { | ||
9 | public class ScriptBase : MarshalByRefObject, IScript | ||
10 | { | ||
11 | |||
12 | #region AppDomain Serialization Keep-Alive | ||
13 | // | ||
14 | // Never expire this object | ||
15 | // | ||
16 | public override Object InitializeLifetimeService() | ||
17 | { | ||
18 | ILease lease = (ILease)base.InitializeLifetimeService(); | ||
19 | |||
20 | if (lease.CurrentState == LeaseState.Initial) | ||
21 | { | ||
22 | lease.InitialLeaseTime = TimeSpan.Zero; | ||
23 | } | ||
24 | return lease; | ||
25 | } | ||
26 | #endregion | ||
27 | |||
28 | public delegate void ExecuteFunctionEventDelegate(string functionName, params object[] args); | ||
29 | public event ExecuteFunctionEventDelegate OnExecuteFunction; | ||
30 | |||
31 | private List<ICommandProvider> CommandProviders = new List<ICommandProvider>(); | ||
32 | |||
33 | public ScriptBase() | ||
34 | { | ||
35 | } | ||
36 | |||
37 | public void ExecuteFunction(string functionName, params object[] args) | ||
38 | { | ||
39 | // We got a new command, fire event | ||
40 | if (OnExecuteFunction != null) | ||
41 | OnExecuteFunction(functionName, args); | ||
42 | |||
43 | } | ||
44 | } | ||
45 | } | ||
diff --git a/OpenSim/ScriptEngine/Shared/EventParams.cs b/OpenSim/ScriptEngine/Shared/EventParams.cs new file mode 100644 index 0000000..661086e --- /dev/null +++ b/OpenSim/ScriptEngine/Shared/EventParams.cs | |||
@@ -0,0 +1,47 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenMetaverse; | ||
5 | using OpenSim.Region.ScriptEngine.Shared; | ||
6 | |||
7 | namespace OpenSim.ScriptEngine.Shared | ||
8 | { | ||
9 | /// <summary> | ||
10 | /// Holds all the data required to execute a scripting event. | ||
11 | /// </summary> | ||
12 | public class EventParams | ||
13 | { | ||
14 | public string EventName; | ||
15 | public Object[] Params; | ||
16 | public Region.ScriptEngine.Shared.DetectParams[] DetectParams; | ||
17 | public uint LocalID; | ||
18 | public UUID ItemID; | ||
19 | |||
20 | public EventParams(uint localID, UUID itemID, string eventName, Object[] eventParams, DetectParams[] detectParams) | ||
21 | { | ||
22 | LocalID = localID; | ||
23 | ItemID = itemID; | ||
24 | EventName = eventName; | ||
25 | Params = eventParams; | ||
26 | DetectParams = detectParams; | ||
27 | } | ||
28 | public EventParams(uint localID, string eventName, Object[] eventParams, DetectParams[] detectParams) | ||
29 | { | ||
30 | LocalID = localID; | ||
31 | EventName = eventName; | ||
32 | Params = eventParams; | ||
33 | DetectParams = detectParams; | ||
34 | } | ||
35 | public void test(params object[] args) | ||
36 | { | ||
37 | string functionName = "test"; | ||
38 | test2(functionName, args); | ||
39 | } | ||
40 | public void test2(string functionName, params object[] args) | ||
41 | { | ||
42 | System.Console.WriteLine(functionName, args); | ||
43 | } | ||
44 | |||
45 | |||
46 | } | ||
47 | } \ No newline at end of file | ||
diff --git a/OpenSim/ScriptEngine/Shared/IScriptCommandProvider.cs b/OpenSim/ScriptEngine/Shared/IScriptCommandProvider.cs new file mode 100644 index 0000000..f37fcaf --- /dev/null +++ b/OpenSim/ScriptEngine/Shared/IScriptCommandProvider.cs | |||
@@ -0,0 +1,10 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.ScriptEngine.Shared | ||
6 | { | ||
7 | public interface IScriptCommandProvider : ScriptAssemblies.ICommandProvider | ||
8 | { | ||
9 | } | ||
10 | } | ||
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/Components/EventBase.cs b/OpenSim/ScriptEngine/Shared/IScriptCompiler.cs index 1c0fd52..3bc0c03 100644 --- a/OpenSim/ApplicationPlugins/ScriptEngine/Components/EventBase.cs +++ b/OpenSim/ScriptEngine/Shared/IScriptCompiler.cs | |||
@@ -26,20 +26,15 @@ | |||
26 | */ | 26 | */ |
27 | using System; | 27 | using System; |
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using System.Reflection; | ||
29 | using System.Text; | 30 | using System.Text; |
31 | using ScriptAssemblies; | ||
30 | 32 | ||
31 | namespace OpenSim.ApplicationPlugins.ScriptEngine.Components | 33 | namespace OpenSim.ScriptEngine.Shared |
32 | { | 34 | { |
33 | public abstract class EventBase : ComponentBase | 35 | public interface IScriptCompiler : IScriptEngineComponent |
34 | { | 36 | { |
35 | //public override iProviderBase CreateInstance() | 37 | string Compile(ScriptMetaData scriptMetaData, ref string script); |
36 | //{ | 38 | string PreProcessScript(ref string script); |
37 | // throw new NotImplementedException(); | ||
38 | //} | ||
39 | |||
40 | //public override void Start() | ||
41 | //{ | ||
42 | // throw new NotImplementedException(); | ||
43 | //} | ||
44 | } | 39 | } |
45 | } \ No newline at end of file | 40 | } \ No newline at end of file |
diff --git a/OpenSim/ScriptEngine/Shared/IScriptEngine.cs b/OpenSim/ScriptEngine/Shared/IScriptEngine.cs new file mode 100644 index 0000000..6148d8d --- /dev/null +++ b/OpenSim/ScriptEngine/Shared/IScriptEngine.cs | |||
@@ -0,0 +1,49 @@ | |||
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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | using Nini.Config; | ||
31 | using OpenSim.Region.Environment.Interfaces; | ||
32 | using OpenSim.Region.Environment.Scenes; | ||
33 | |||
34 | namespace OpenSim.ScriptEngine.Shared | ||
35 | { | ||
36 | public interface IScriptEngine | ||
37 | { | ||
38 | //string[] ComponentNames { get; } | ||
39 | //Dictionary<string, IScriptEngineComponent> Components { get; } | ||
40 | //void InitializeComponents(); | ||
41 | void Initialise(Scene scene, IConfigSource source); | ||
42 | void PostInitialise(); | ||
43 | void Close(); | ||
44 | string Name { get; } | ||
45 | // string Name { get; } | ||
46 | //void Initialize(); | ||
47 | //void Close(); | ||
48 | } | ||
49 | } \ No newline at end of file | ||
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/Components/CommandBase.cs b/OpenSim/ScriptEngine/Shared/IScriptEngineComponent.cs index 4708554..3c977a5 100644 --- a/OpenSim/ApplicationPlugins/ScriptEngine/Components/CommandBase.cs +++ b/OpenSim/ScriptEngine/Shared/IScriptEngineComponent.cs | |||
@@ -28,18 +28,9 @@ using System; | |||
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using System.Text; | 29 | using System.Text; |
30 | 30 | ||
31 | namespace OpenSim.ApplicationPlugins.ScriptEngine.Components | 31 | namespace OpenSim.ScriptEngine.Shared |
32 | { | 32 | { |
33 | public abstract class CommandBase: ComponentBase | 33 | public interface IScriptEngineComponent |
34 | { | 34 | { |
35 | //public override iProviderBase CreateInstance() | ||
36 | //{ | ||
37 | // throw new NotImplementedException(); | ||
38 | //} | ||
39 | |||
40 | //public override void Start() | ||
41 | //{ | ||
42 | // throw new NotImplementedException(); | ||
43 | //} | ||
44 | } | 35 | } |
45 | } \ No newline at end of file | 36 | } \ No newline at end of file |
diff --git a/OpenSim/ScriptEngine/Shared/IScriptEngineRegionComponent.cs b/OpenSim/ScriptEngine/Shared/IScriptEngineRegionComponent.cs new file mode 100644 index 0000000..a8d779d --- /dev/null +++ b/OpenSim/ScriptEngine/Shared/IScriptEngineRegionComponent.cs | |||
@@ -0,0 +1,7 @@ | |||
1 | namespace OpenSim.ScriptEngine.Shared | ||
2 | { | ||
3 | public interface IScriptEngineRegionComponent | ||
4 | { | ||
5 | void Initialize(RegionInfoStructure currentRegion); | ||
6 | } | ||
7 | } | ||
diff --git a/OpenSim/ScriptEngine/Shared/IScriptEventProvider.cs b/OpenSim/ScriptEngine/Shared/IScriptEventProvider.cs new file mode 100644 index 0000000..a290ba4 --- /dev/null +++ b/OpenSim/ScriptEngine/Shared/IScriptEventProvider.cs | |||
@@ -0,0 +1,11 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.ScriptEngine.Shared | ||
6 | { | ||
7 | public interface IScriptEventProvider : IScriptEngineComponent, IScriptEngineRegionComponent | ||
8 | { | ||
9 | |||
10 | } | ||
11 | } \ No newline at end of file | ||
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/Components/CompilerBase.cs b/OpenSim/ScriptEngine/Shared/IScriptExecutor.cs index e62d1f2..77bea13 100644 --- a/OpenSim/ApplicationPlugins/ScriptEngine/Components/CompilerBase.cs +++ b/OpenSim/ScriptEngine/Shared/IScriptExecutor.cs | |||
@@ -27,19 +27,13 @@ | |||
27 | using System; | 27 | using System; |
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using System.Text; | 29 | using System.Text; |
30 | using OpenSim.ScriptEngine.Shared; | ||
30 | 31 | ||
31 | namespace OpenSim.ApplicationPlugins.ScriptEngine.Components | 32 | namespace OpenSim.ScriptEngine.Shared |
32 | { | 33 | { |
33 | public abstract class CompilerBase: ComponentBase | 34 | public interface IScriptExecutor : IScriptEngineComponent, IScriptEngineRegionComponent |
34 | { | 35 | { |
35 | //public override iProviderBase CreateInstance() | 36 | void ExecuteCommand(ref ScriptStructure scriptContainer, EventParams p); |
36 | //{ | 37 | void ExecuteCommand(EventParams p); |
37 | // throw new NotImplementedException(); | ||
38 | //} | ||
39 | |||
40 | //public override void Start() | ||
41 | //{ | ||
42 | // throw new NotImplementedException(); | ||
43 | //} | ||
44 | } | 38 | } |
45 | } \ No newline at end of file | 39 | } \ No newline at end of file |
diff --git a/OpenSim/ScriptEngine/Shared/IScriptLoader.cs b/OpenSim/ScriptEngine/Shared/IScriptLoader.cs new file mode 100644 index 0000000..15f7443 --- /dev/null +++ b/OpenSim/ScriptEngine/Shared/IScriptLoader.cs | |||
@@ -0,0 +1,9 @@ | |||
1 | using OpenSim.ScriptEngine.Shared; | ||
2 | |||
3 | namespace OpenSim.ScriptEngine.Shared | ||
4 | { | ||
5 | public interface IScriptLoader: IScriptEngineComponent | ||
6 | { | ||
7 | ScriptAssemblies.IScript LoadScript(ScriptStructure script); | ||
8 | } | ||
9 | } \ No newline at end of file | ||
diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/Components/SchedulerBase.cs b/OpenSim/ScriptEngine/Shared/IScriptScheduler.cs index 9d5aff0..3e56c12 100644 --- a/OpenSim/ApplicationPlugins/ScriptEngine/Components/SchedulerBase.cs +++ b/OpenSim/ScriptEngine/Shared/IScriptScheduler.cs | |||
@@ -27,19 +27,15 @@ | |||
27 | using System; | 27 | using System; |
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using System.Text; | 29 | using System.Text; |
30 | using OpenMetaverse; | ||
31 | using OpenSim.ScriptEngine.Shared; | ||
30 | 32 | ||
31 | namespace OpenSim.ApplicationPlugins.ScriptEngine.Components | 33 | namespace OpenSim.ScriptEngine.Shared |
32 | { | 34 | { |
33 | public abstract class SchedulerBase: ComponentBase | 35 | public interface IScriptScheduler : IScriptEngineComponent |
34 | { | 36 | { |
35 | //public override iProviderBase CreateInstance() | 37 | void AddScript(ScriptStructure script); |
36 | //{ | 38 | void Removecript(uint id, UUID itemID); |
37 | // throw new NotImplementedException(); | 39 | void Close(); |
38 | //} | ||
39 | |||
40 | //public override void Start() | ||
41 | //{ | ||
42 | // throw new NotImplementedException(); | ||
43 | //} | ||
44 | } | 40 | } |
45 | } \ No newline at end of file | 41 | } \ No newline at end of file |
diff --git a/OpenSim/ScriptEngine/Shared/Properties/AssemblyInfo.cs b/OpenSim/ScriptEngine/Shared/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..06a3461 --- /dev/null +++ b/OpenSim/ScriptEngine/Shared/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,36 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | |||
5 | // General Information about an assembly is controlled through the following | ||
6 | // set of attributes. Change these attribute values to modify the information | ||
7 | // associated with an assembly. | ||
8 | [assembly: AssemblyTitle("OpenSim.ScriptEngine.Shared")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("Microsoft")] | ||
12 | [assembly: AssemblyProduct("OpenSim.ScriptEngine.Shared")] | ||
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2008")] | ||
14 | [assembly: AssemblyTrademark("")] | ||
15 | [assembly: AssemblyCulture("")] | ||
16 | |||
17 | // Setting ComVisible to false makes the types in this assembly not visible | ||
18 | // to COM components. If you need to access a type in this assembly from | ||
19 | // COM, set the ComVisible attribute to true on that type. | ||
20 | [assembly: ComVisible(false)] | ||
21 | |||
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
23 | [assembly: Guid("ea77002b-c967-4368-ace9-6533f8147d4b")] | ||
24 | |||
25 | // Version information for an assembly consists of the following four values: | ||
26 | // | ||
27 | // Major Version | ||
28 | // Minor Version | ||
29 | // Build Number | ||
30 | // Revision | ||
31 | // | ||
32 | // You can specify all the values or you can default the Build and Revision Numbers | ||
33 | // by using the '*' as shown below: | ||
34 | // [assembly: AssemblyVersion("1.0.*")] | ||
35 | [assembly: AssemblyVersion("1.0.0.0")] | ||
36 | [assembly: AssemblyFileVersion("1.0.0.0")] | ||
diff --git a/OpenSim/ScriptEngine/Shared/RegionInfoStructure.cs b/OpenSim/ScriptEngine/Shared/RegionInfoStructure.cs new file mode 100644 index 0000000..834fac3 --- /dev/null +++ b/OpenSim/ScriptEngine/Shared/RegionInfoStructure.cs | |||
@@ -0,0 +1,94 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Reflection; | ||
4 | using log4net; | ||
5 | using Nini.Config; | ||
6 | using OpenSim.Region.Environment.Scenes; | ||
7 | using OpenSim.Region.ScriptEngine.Shared; | ||
8 | using OpenSim.ScriptEngine.Shared; | ||
9 | using EventParams=OpenSim.ScriptEngine.Shared.EventParams; | ||
10 | |||
11 | namespace OpenSim.ScriptEngine.Shared | ||
12 | { | ||
13 | public struct RegionInfoStructure | ||
14 | { | ||
15 | public Scene Scene; | ||
16 | public IConfigSource ConfigSource; | ||
17 | |||
18 | public IScriptLoader ScriptLoader; | ||
19 | public Dictionary<string, IScriptEventProvider> EventProviders; | ||
20 | public Dictionary<string, IScriptExecutor> Executors; | ||
21 | public Dictionary<string, IScriptCompiler> Compilers; | ||
22 | public Dictionary<string, IScriptScheduler> Schedulers; | ||
23 | public Dictionary<string, IScriptCommandProvider> CommandProviders; | ||
24 | public ILog Logger; | ||
25 | |||
26 | public void Executors_Execute(EventParams p) | ||
27 | { | ||
28 | // Execute a command on all executors | ||
29 | lock (Executors) | ||
30 | { | ||
31 | foreach (IScriptExecutor exec in Executors.Values) | ||
32 | { | ||
33 | exec.ExecuteCommand(p); | ||
34 | } | ||
35 | } | ||
36 | } | ||
37 | public void Executors_Execute(ScriptStructure scriptContainer, EventParams p) | ||
38 | { | ||
39 | // Execute a command on all executors | ||
40 | lock (Executors) | ||
41 | { | ||
42 | foreach (IScriptExecutor exec in Executors.Values) | ||
43 | { | ||
44 | exec.ExecuteCommand(ref scriptContainer, p); | ||
45 | } | ||
46 | } | ||
47 | } | ||
48 | |||
49 | public IScriptCompiler FindCompiler(ScriptMetaData scriptMetaData) | ||
50 | { | ||
51 | string compiler = "Compiler_LSL"; | ||
52 | if (scriptMetaData.ContainsKey("Compiler")) | ||
53 | compiler = scriptMetaData["Compiler"]; | ||
54 | |||
55 | lock (Compilers) | ||
56 | { | ||
57 | if (!Compilers.ContainsKey(compiler)) | ||
58 | throw new Exception("Requested script compiler \"" + compiler + "\" does not exist."); | ||
59 | |||
60 | return Compilers[compiler]; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | public IScriptScheduler FindScheduler(ScriptMetaData scriptMetaData) | ||
65 | { | ||
66 | string scheduler = "Scheduler"; | ||
67 | if (scriptMetaData.ContainsKey("Scheduler")) | ||
68 | scheduler = scriptMetaData["Scheduler"]; | ||
69 | |||
70 | lock (Schedulers) | ||
71 | { | ||
72 | if (!Schedulers.ContainsKey(scheduler)) | ||
73 | throw new Exception("Requested script scheduler \"" + scheduler + "\" does not exist."); | ||
74 | |||
75 | return Schedulers[scheduler]; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | //public Assembly[] GetCommandProviderAssemblies() | ||
80 | //{ | ||
81 | // lock (CommandProviders) | ||
82 | // { | ||
83 | // Assembly[] ass = new Assembly[CommandProviders.Count]; | ||
84 | // int i = 0; | ||
85 | // foreach (string key in CommandProviders.Keys) | ||
86 | // { | ||
87 | // ass[i] = CommandProviders[key].GetType().Assembly; | ||
88 | // i++; | ||
89 | // } | ||
90 | // return ass; | ||
91 | // } | ||
92 | //} | ||
93 | } | ||
94 | } \ No newline at end of file | ||
diff --git a/OpenSim/ScriptEngine/Shared/ScriptMetaData.cs b/OpenSim/ScriptEngine/Shared/ScriptMetaData.cs new file mode 100644 index 0000000..462f2d4 --- /dev/null +++ b/OpenSim/ScriptEngine/Shared/ScriptMetaData.cs | |||
@@ -0,0 +1,95 @@ | |||
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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | |||
30 | namespace OpenSim.ScriptEngine.Shared | ||
31 | { | ||
32 | public class ScriptMetaData: Dictionary<string, string> | ||
33 | { | ||
34 | private static readonly char[] LineSeparator = "\r\n".ToCharArray(); | ||
35 | private static readonly char[] Separator = { ':' }; | ||
36 | public static ScriptMetaData Extract(ref string Script) | ||
37 | { | ||
38 | ScriptMetaData ret = new ScriptMetaData(); | ||
39 | if (string.IsNullOrEmpty(Script)) | ||
40 | return ret; | ||
41 | |||
42 | // Process it line by line | ||
43 | string Line = ""; | ||
44 | for (int i = 0; i < Script.Length + 1; i++) | ||
45 | { | ||
46 | // Found a line separator? | ||
47 | if (i < Script.Length | ||
48 | && Script[i] != LineSeparator[0] | ||
49 | && Script[i] != LineSeparator[1]) | ||
50 | { | ||
51 | // No, not end of line. Add to current line | ||
52 | Line += Script[i]; | ||
53 | } | ||
54 | else | ||
55 | { | ||
56 | // Extract MetaData from this line. Returns False if not found. | ||
57 | if (!_GetMetaFromLine(ret, Line)) | ||
58 | continue; | ||
59 | // Empty for next round | ||
60 | Line = ""; | ||
61 | } | ||
62 | } | ||
63 | return ret; | ||
64 | } | ||
65 | |||
66 | private static bool _GetMetaFromLine(ScriptMetaData ret, string line) | ||
67 | { | ||
68 | line = line.Trim(); | ||
69 | |||
70 | // Empty line? We may find more later | ||
71 | if (line == "") | ||
72 | return true; | ||
73 | |||
74 | // Is this a comment? If not, then return false | ||
75 | if (!line.StartsWith("//")) | ||
76 | return false; | ||
77 | |||
78 | // It is a comment | ||
79 | string[] keyval = line.Split(Separator, 2, StringSplitOptions.None); | ||
80 | keyval[0] = keyval[0].Substring(2, keyval[0].Length - 2).Trim(); | ||
81 | keyval[1] = keyval[1].Trim(); | ||
82 | |||
83 | // Add it | ||
84 | if (keyval[0] != "") | ||
85 | if (!ret.ContainsKey(keyval[0])) | ||
86 | { | ||
87 | //m_log.DebugFormat("[DotNetEngine] Script metadata: Key: \"{0}\", Value: \"{1}\".", keyval[0], keyval[1]); | ||
88 | ret.Add(keyval[0], keyval[1]); | ||
89 | } | ||
90 | |||
91 | return true; | ||
92 | } | ||
93 | |||
94 | } | ||
95 | } \ No newline at end of file | ||
diff --git a/OpenSim/ScriptEngine/Shared/ScriptStructure.cs b/OpenSim/ScriptEngine/Shared/ScriptStructure.cs new file mode 100644 index 0000000..cbf333b --- /dev/null +++ b/OpenSim/ScriptEngine/Shared/ScriptStructure.cs | |||
@@ -0,0 +1,109 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Reflection; | ||
4 | using System.Text; | ||
5 | using OpenMetaverse; | ||
6 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
7 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | ||
8 | using OpenSim.ScriptEngine.Shared; | ||
9 | |||
10 | namespace OpenSim.ScriptEngine.Shared | ||
11 | { | ||
12 | public struct ScriptStructure | ||
13 | { | ||
14 | public RegionInfoStructure RegionInfo; | ||
15 | public ScriptMetaData ScriptMetaData; | ||
16 | |||
17 | public ScriptAssemblies.IScript ScriptObject; | ||
18 | public string State; | ||
19 | public bool Running; | ||
20 | public bool Disabled; | ||
21 | public string Source; | ||
22 | public int StartParam; | ||
23 | public AppDomain AppDomain; | ||
24 | public Dictionary<string, IScriptApi> Apis; | ||
25 | public Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> LineMap; | ||
26 | public uint LocalID; | ||
27 | public UUID ItemID; | ||
28 | public string AssemblyFileName; | ||
29 | |||
30 | public string ScriptID { get { return LocalID.ToString() + "." + ItemID.ToString(); } } | ||
31 | public string Name { get { return "Script:" + ScriptID; } } | ||
32 | private bool Initialized; | ||
33 | private Dictionary<string, Delegate> InternalFunctions; | ||
34 | public string AssemblyName; | ||
35 | |||
36 | public void ExecuteEvent(EventParams p) | ||
37 | { | ||
38 | ExecuteMethod(p, true); | ||
39 | } | ||
40 | |||
41 | public void ExecuteMethod(EventParams p) | ||
42 | { | ||
43 | ExecuteMethod(p, false); | ||
44 | } | ||
45 | private void ExecuteMethod(EventParams p, bool isEvent) | ||
46 | { | ||
47 | // First time initialization? | ||
48 | if (!Initialized) | ||
49 | { | ||
50 | Initialized = true; | ||
51 | CacheInternalFunctions(); | ||
52 | } | ||
53 | |||
54 | lock (InternalFunctions) | ||
55 | { | ||
56 | // Make function name | ||
57 | string FunctionName; | ||
58 | if (isEvent) | ||
59 | FunctionName = State + "_event_" + p.EventName; | ||
60 | else | ||
61 | FunctionName = p.EventName; | ||
62 | |||
63 | // Check if this function exist | ||
64 | if (!InternalFunctions.ContainsKey(FunctionName)) | ||
65 | { | ||
66 | // TODO: Send message in-world | ||
67 | //RegionInfo.Scene. | ||
68 | RegionInfo.Logger.ErrorFormat("[{0}] Script function \"{1}\" was not found.", Name, FunctionName); | ||
69 | return; | ||
70 | } | ||
71 | |||
72 | // Execute script function | ||
73 | try | ||
74 | { | ||
75 | InternalFunctions[FunctionName].DynamicInvoke(p.Params); | ||
76 | } | ||
77 | catch (Exception e) | ||
78 | { | ||
79 | RegionInfo.Logger.ErrorFormat("[{0}] Execute \"{1}\" failed: {2}", Name, FunctionName, e.ToString()); | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | |||
84 | /// <summary> | ||
85 | /// Cache functions into a dictionary with delegates. Should be faster than reflection. | ||
86 | /// </summary> | ||
87 | private void CacheInternalFunctions() | ||
88 | { | ||
89 | Type scriptObjectType = ScriptObject.GetType(); | ||
90 | InternalFunctions = new Dictionary<string, Delegate>(); | ||
91 | |||
92 | MethodInfo[] methods = scriptObjectType.GetMethods(); | ||
93 | lock (InternalFunctions) | ||
94 | { | ||
95 | // Read all methods into a dictionary | ||
96 | foreach (MethodInfo mi in methods) | ||
97 | { | ||
98 | // TODO: We don't support overloading | ||
99 | if (!InternalFunctions.ContainsKey(mi.Name)) | ||
100 | InternalFunctions.Add(mi.Name, Delegate.CreateDelegate(scriptObjectType, ScriptObject, mi)); | ||
101 | else | ||
102 | RegionInfo.Logger.ErrorFormat("[{0}] Error: Script function \"{1}\" is already added. We do not support overloading.", | ||
103 | Name, mi.Name); | ||
104 | } | ||
105 | } | ||
106 | } | ||
107 | |||
108 | } | ||
109 | } \ No newline at end of file | ||