diff options
author | Tedd Hansen | 2007-08-08 14:05:13 +0000 |
---|---|---|
committer | Tedd Hansen | 2007-08-08 14:05:13 +0000 |
commit | 2a0e157985d790e6cbd83d61690da2709dfab9dd (patch) | |
tree | e9c38c11773796111fb4ff222429605bdd76fd5e /OpenSim/Region/ScriptEngine/DotNetEngine | |
parent | * Got SimpleApp working again (diff) | |
download | opensim-SC_OLD-2a0e157985d790e6cbd83d61690da2709dfab9dd.zip opensim-SC_OLD-2a0e157985d790e6cbd83d61690da2709dfab9dd.tar.gz opensim-SC_OLD-2a0e157985d790e6cbd83d61690da2709dfab9dd.tar.bz2 opensim-SC_OLD-2a0e157985d790e6cbd83d61690da2709dfab9dd.tar.xz |
Added ScriptEngine.DotNetEngine
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine')
10 files changed, 751 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Common.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Common.cs new file mode 100644 index 0000000..e95d1bb --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Common.cs | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 | */ | ||
28 | /* Original code: Tedd Hansen */ | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | ||
34 | { | ||
35 | public static class Common | ||
36 | { | ||
37 | static public bool Debug = true; | ||
38 | |||
39 | public delegate void SendToDebugEventDelegate(string Message); | ||
40 | public delegate void SendToLogEventDelegate(string Message); | ||
41 | static public event SendToDebugEventDelegate SendToDebugEvent; | ||
42 | static public event SendToLogEventDelegate SendToLogEvent; | ||
43 | |||
44 | static public void SendToDebug(string Message) | ||
45 | { | ||
46 | //if (Debug == true) | ||
47 | Console.WriteLine("SE:Debug: " + Message); | ||
48 | //SendToDebugEvent("\r\n" + DateTime.Now.ToString("[HH:mm:ss] ") + Message); | ||
49 | } | ||
50 | static public void SendToLog(string Message) | ||
51 | { | ||
52 | //if (Debug == true) | ||
53 | Console.WriteLine("SE:LOG: " + Message); | ||
54 | //SendToLogEvent("\r\n" + DateTime.Now.ToString("[HH:mm:ss] ") + Message); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventManager.cs new file mode 100644 index 0000000..46b898a --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/EventManager.cs | |||
@@ -0,0 +1,99 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 | */ | ||
28 | /* Original code: Tedd Hansen */ | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// Prepares events so they can be directly executed upon a script by EventQueueManager, then queues it. | ||
37 | /// </summary> | ||
38 | class EventManager | ||
39 | { | ||
40 | private ScriptEngine myScriptEngine; | ||
41 | public EventManager(ScriptEngine _ScriptEngine) | ||
42 | { | ||
43 | myScriptEngine = _ScriptEngine; | ||
44 | // TODO: HOOK EVENTS UP TO SERVER! | ||
45 | Common.SendToDebug("EventManager Start"); | ||
46 | |||
47 | // Hook up a test event to our test form | ||
48 | Common.SendToDebug("EventManager Hooking up dummy-event: touch_start"); | ||
49 | myScriptEngine.World.touch_start += new TempWorldInterfaceEventDelegates.touch_start(touch_start); | ||
50 | } | ||
51 | |||
52 | public void touch_start(string ObjectID) | ||
53 | { | ||
54 | // Add to queue for all scripts in ObjectID object | ||
55 | Common.SendToDebug("EventManager Event: touch_start"); | ||
56 | myScriptEngine.myEventQueueManager.AddToObjectQueue(ObjectID, "touch_start", new object[] { (UInt32)0 }); | ||
57 | } | ||
58 | |||
59 | |||
60 | // TODO: Replace placeholders below | ||
61 | // These needs to be hooked up to OpenSim during init of this class | ||
62 | // then queued in EventQueueManager. | ||
63 | // When queued in EventQueueManager they need to be LSL compatible (name and params) | ||
64 | public void state_entry() { } | ||
65 | public void state_exit() { } | ||
66 | //public void touch_start() { } | ||
67 | public void touch() { } | ||
68 | public void touch_end() { } | ||
69 | public void collision_start() { } | ||
70 | public void collision() { } | ||
71 | public void collision_end() { } | ||
72 | public void land_collision_start() { } | ||
73 | public void land_collision() { } | ||
74 | public void land_collision_end() { } | ||
75 | public void timer() { } | ||
76 | public void listen() { } | ||
77 | public void on_rez() { } | ||
78 | public void sensor() { } | ||
79 | public void no_sensor() { } | ||
80 | public void control() { } | ||
81 | public void money() { } | ||
82 | public void email() { } | ||
83 | public void at_target() { } | ||
84 | public void not_at_target() { } | ||
85 | public void at_rot_target() { } | ||
86 | public void not_at_rot_target() { } | ||
87 | public void run_time_permissions() { } | ||
88 | public void changed() { } | ||
89 | public void attach() { } | ||
90 | public void dataserver() { } | ||
91 | public void link_message() { } | ||
92 | public void moving_start() { } | ||
93 | public void moving_end() { } | ||
94 | public void object_rez() { } | ||
95 | public void remote_data() { } | ||
96 | public void http_response() { } | ||
97 | |||
98 | } | ||
99 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs new file mode 100644 index 0000000..59f669b --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs | |||
@@ -0,0 +1,136 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 | */ | ||
28 | /* Original code: Tedd Hansen */ | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using System.Threading; | ||
33 | using System.Reflection; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | ||
36 | { | ||
37 | class EventQueueManager | ||
38 | { | ||
39 | private Thread EventQueueThread; | ||
40 | private int NothingToDoSleepms = 200; | ||
41 | private Queue<QueueItemStruct> EventQueue = new Queue<QueueItemStruct>(); | ||
42 | private struct QueueItemStruct | ||
43 | { | ||
44 | public string ObjectID; | ||
45 | public string ScriptID; | ||
46 | public string FunctionName; | ||
47 | public object[] param; | ||
48 | } | ||
49 | |||
50 | private ScriptEngine myScriptEngine; | ||
51 | public EventQueueManager(ScriptEngine _ScriptEngine) | ||
52 | { | ||
53 | myScriptEngine = _ScriptEngine; | ||
54 | Common.SendToDebug("EventQueueManager Start"); | ||
55 | // Start worker thread | ||
56 | EventQueueThread = new Thread(EventQueueThreadLoop); | ||
57 | EventQueueThread.IsBackground = true; | ||
58 | EventQueueThread.Name = "EventQueueManagerThread"; | ||
59 | EventQueueThread.Start(); | ||
60 | } | ||
61 | ~EventQueueManager() | ||
62 | { | ||
63 | // Kill worker thread | ||
64 | if (EventQueueThread != null && EventQueueThread.IsAlive == true) | ||
65 | { | ||
66 | try | ||
67 | { | ||
68 | EventQueueThread.Abort(); | ||
69 | EventQueueThread.Join(); | ||
70 | } | ||
71 | catch (Exception e) | ||
72 | { | ||
73 | Common.SendToDebug("EventQueueManager Exception killing worker thread: " + e.ToString()); | ||
74 | } | ||
75 | } | ||
76 | // Todo: Clean up our queues | ||
77 | |||
78 | } | ||
79 | |||
80 | private void EventQueueThreadLoop() | ||
81 | { | ||
82 | Common.SendToDebug("EventQueueManager Worker thread spawned"); | ||
83 | try | ||
84 | { | ||
85 | while (true) | ||
86 | { | ||
87 | if (EventQueue.Count == 0) | ||
88 | { | ||
89 | // Nothing to do? Sleep a bit waiting for something to do | ||
90 | Thread.Sleep(NothingToDoSleepms); | ||
91 | } | ||
92 | else | ||
93 | { | ||
94 | // Something in queue, process | ||
95 | QueueItemStruct QIS = EventQueue.Dequeue(); | ||
96 | Common.SendToDebug("Processing event for ObjectID: " + QIS.ObjectID + ", ScriptID: " + QIS.ScriptID + ", FunctionName: " + QIS.FunctionName); | ||
97 | // TODO: Execute function | ||
98 | myScriptEngine.myScriptManager.ExecuteFunction(QIS.ObjectID, QIS.ScriptID, QIS.FunctionName, QIS.param); | ||
99 | } | ||
100 | } | ||
101 | } | ||
102 | catch (ThreadAbortException tae) | ||
103 | { | ||
104 | Common.SendToDebug("EventQueueManager Worker thread killed: " + tae.Message); | ||
105 | } | ||
106 | } | ||
107 | |||
108 | public void AddToObjectQueue(string ObjectID, string FunctionName, object[] param) | ||
109 | { | ||
110 | // Determine all scripts in Object and add to their queue | ||
111 | Common.SendToDebug("EventQueueManager Adding ObjectID: " + ObjectID + ", FunctionName: " + FunctionName); | ||
112 | |||
113 | foreach (string ScriptID in myScriptEngine.myScriptManager.GetScriptKeys(ObjectID)) | ||
114 | { | ||
115 | // Add to each script in that object | ||
116 | // TODO: Some scripts may not subscribe to this event. Should we NOT add it? Does it matter? | ||
117 | |||
118 | // Create a structure and add data | ||
119 | QueueItemStruct QIS = new QueueItemStruct(); | ||
120 | QIS.ObjectID = ObjectID; | ||
121 | QIS.ScriptID = ScriptID; | ||
122 | QIS.FunctionName = FunctionName; | ||
123 | QIS.param = param; | ||
124 | |||
125 | // Add it to queue | ||
126 | EventQueue.Enqueue(QIS); | ||
127 | |||
128 | } | ||
129 | } | ||
130 | //public void AddToScriptQueue(string ObjectID, string FunctionName, object[] param) | ||
131 | //{ | ||
132 | // // Add to script queue | ||
133 | //} | ||
134 | |||
135 | } | ||
136 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/OpenSim.Region.ScriptEngine.DotNetEngine.csproj b/OpenSim/Region/ScriptEngine/DotNetEngine/OpenSim.Region.ScriptEngine.DotNetEngine.csproj new file mode 100644 index 0000000..b9ea871 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/OpenSim.Region.ScriptEngine.DotNetEngine.csproj | |||
@@ -0,0 +1,59 @@ | |||
1 | <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
2 | <PropertyGroup> | ||
3 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
4 | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
5 | <ProductVersion>8.0.50727</ProductVersion> | ||
6 | <SchemaVersion>2.0</SchemaVersion> | ||
7 | <ProjectGuid>{8D47DF28-AAC4-47AB-9A6D-9A104A115817}</ProjectGuid> | ||
8 | <OutputType>Library</OutputType> | ||
9 | <AppDesignerFolder>Properties</AppDesignerFolder> | ||
10 | <RootNamespace>OpenSim.Region.ScriptEngine.DotNetEngine</RootNamespace> | ||
11 | <AssemblyName>OpenSim.Region.ScriptEngine.DotNetEngine</AssemblyName> | ||
12 | </PropertyGroup> | ||
13 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
14 | <DebugSymbols>true</DebugSymbols> | ||
15 | <DebugType>full</DebugType> | ||
16 | <Optimize>false</Optimize> | ||
17 | <OutputPath>bin\Debug\</OutputPath> | ||
18 | <DefineConstants>DEBUG;TRACE</DefineConstants> | ||
19 | <ErrorReport>prompt</ErrorReport> | ||
20 | <WarningLevel>4</WarningLevel> | ||
21 | </PropertyGroup> | ||
22 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
23 | <DebugType>pdbonly</DebugType> | ||
24 | <Optimize>true</Optimize> | ||
25 | <OutputPath>bin\Release\</OutputPath> | ||
26 | <DefineConstants>TRACE</DefineConstants> | ||
27 | <ErrorReport>prompt</ErrorReport> | ||
28 | <WarningLevel>4</WarningLevel> | ||
29 | </PropertyGroup> | ||
30 | <ItemGroup> | ||
31 | <Reference Include="System" /> | ||
32 | <Reference Include="System.Data" /> | ||
33 | <Reference Include="System.Xml" /> | ||
34 | </ItemGroup> | ||
35 | <ItemGroup> | ||
36 | <Compile Include="Common.cs" /> | ||
37 | <Compile Include="EventManager.cs" /> | ||
38 | <Compile Include="EventQueueManager.cs" /> | ||
39 | <Compile Include="ScriptEngine.cs" /> | ||
40 | <Compile Include="Properties\AssemblyInfo.cs" /> | ||
41 | <Compile Include="ScriptEngineInterface.cs" /> | ||
42 | <Compile Include="ScriptManager.cs" /> | ||
43 | <Compile Include="TempWorldInterface.cs" /> | ||
44 | </ItemGroup> | ||
45 | <ItemGroup> | ||
46 | <ProjectReference Include="..\DotNetEngine.Compiler.LSL\OpenSim.ScriptEngine.DotNetEngine.Compiler.LSL.csproj"> | ||
47 | <Project>{E56CB0C4-DBE8-4169-AC21-B6A2E8235A82}</Project> | ||
48 | <Name>OpenSim.ScriptEngine.DotNetEngine.Compiler.LSL</Name> | ||
49 | </ProjectReference> | ||
50 | </ItemGroup> | ||
51 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
52 | <!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
53 | Other similar extension points exist, see Microsoft.Common.targets. | ||
54 | <Target Name="BeforeBuild"> | ||
55 | </Target> | ||
56 | <Target Name="AfterBuild"> | ||
57 | </Target> | ||
58 | --> | ||
59 | </Project> \ No newline at end of file | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/OpenSim.Region.ScriptEngine.DotNetEngine.suo b/OpenSim/Region/ScriptEngine/DotNetEngine/OpenSim.Region.ScriptEngine.DotNetEngine.suo new file mode 100644 index 0000000..58ef5c2 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/OpenSim.Region.ScriptEngine.DotNetEngine.suo | |||
Binary files differ | |||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Properties/AssemblyInfo.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..aa76b6a --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,35 @@ | |||
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.Region.ScriptEngine.DotNetEngine")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("")] | ||
12 | [assembly: AssemblyProduct("OpenSim.Region.ScriptEngine.DotNetEngine")] | ||
13 | [assembly: AssemblyCopyright("Copyright © 2007")] | ||
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("2842257e-6fde-4460-9368-4cde57fa9cc4")] | ||
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 Revision and Build Numbers | ||
33 | // by using the '*' as shown below: | ||
34 | [assembly: AssemblyVersion("1.0.0.0")] | ||
35 | [assembly: AssemblyFileVersion("1.0.0.0")] | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs new file mode 100644 index 0000000..35afaf7 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs | |||
@@ -0,0 +1,77 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 | */ | ||
28 | /* Original code: Tedd Hansen */ | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | ||
34 | { | ||
35 | public class ScriptEngine : ScriptEngineInterface | ||
36 | { | ||
37 | // | ||
38 | // This is the root object for ScriptEngine | ||
39 | // | ||
40 | |||
41 | internal TempWorldInterface World; | ||
42 | internal EventManager myEventManager; // Handles and queues incoming events from OpenSim | ||
43 | internal EventQueueManager myEventQueueManager; // Executes events | ||
44 | internal ScriptManager myScriptManager; // Load, unload and execute scripts | ||
45 | |||
46 | public ScriptEngine() | ||
47 | { | ||
48 | Common.SendToDebug("ScriptEngine Object Initialized"); | ||
49 | } | ||
50 | |||
51 | public void InitializeEngine(TempWorldInterface Sceneworld) | ||
52 | { | ||
53 | World = Sceneworld; | ||
54 | Common.SendToDebug("ScriptEngine InitializeEngine()"); | ||
55 | |||
56 | // Create all objects we'll be using | ||
57 | myEventQueueManager = new EventQueueManager(this); | ||
58 | myEventManager = new EventManager(this); | ||
59 | myScriptManager = new ScriptManager(this); | ||
60 | |||
61 | // Should we iterate the region for scripts that needs starting? | ||
62 | // Or can we assume we are loaded before anything else so we can use proper events? | ||
63 | } | ||
64 | public void Shutdown() | ||
65 | { | ||
66 | // We are shutting down | ||
67 | } | ||
68 | |||
69 | // !!!FOR DEBUGGING ONLY!!! (for executing script directly from test app) | ||
70 | [Obsolete("!!!FOR DEBUGGING ONLY!!!")] | ||
71 | public void StartScript(string ScriptID, string ObjectID) | ||
72 | { | ||
73 | Common.SendToDebug("ScriptEngine DEBUG: StartScript: " + ScriptID); | ||
74 | myScriptManager.StartScript(ScriptID, ObjectID); | ||
75 | } | ||
76 | } | ||
77 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngineInterface.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngineInterface.cs new file mode 100644 index 0000000..c561523 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngineInterface.cs | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 | */ | ||
28 | /* Original code: Tedd Hansen */ | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | ||
34 | { | ||
35 | interface ScriptEngineInterface | ||
36 | { | ||
37 | void InitializeEngine(TempWorldInterface Sceneworld); | ||
38 | void Shutdown(); | ||
39 | } | ||
40 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs new file mode 100644 index 0000000..f2080eb --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs | |||
@@ -0,0 +1,232 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 | */ | ||
28 | /* Original code: Tedd Hansen */ | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using System.Threading; | ||
33 | using System.Reflection; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | ||
36 | { | ||
37 | class ScriptManager | ||
38 | { | ||
39 | |||
40 | private ScriptEngine myScriptEngine; | ||
41 | public ScriptManager(ScriptEngine _ScriptEngine) | ||
42 | { | ||
43 | myScriptEngine = _ScriptEngine; | ||
44 | Common.SendToDebug("ScriptManager Start"); | ||
45 | } | ||
46 | |||
47 | |||
48 | // Object<string, Script<string, script>> | ||
49 | internal Dictionary<string, Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass>> Scripts = new Dictionary<string, Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass>>(); | ||
50 | |||
51 | |||
52 | internal Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass>.KeyCollection GetScriptKeys(string ObjectID) | ||
53 | { | ||
54 | if (Scripts.ContainsKey(ObjectID) == false) | ||
55 | return null; | ||
56 | |||
57 | Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass> Obj; | ||
58 | Scripts.TryGetValue(ObjectID, out Obj); | ||
59 | |||
60 | return Obj.Keys; | ||
61 | |||
62 | } | ||
63 | |||
64 | internal OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass GetScript(string ObjectID, string ScriptID) | ||
65 | { | ||
66 | if (Scripts.ContainsKey(ObjectID) == false) | ||
67 | return null; | ||
68 | |||
69 | Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass> Obj; | ||
70 | Scripts.TryGetValue(ObjectID, out Obj); | ||
71 | if (Obj.ContainsKey(ScriptID) == false) | ||
72 | return null; | ||
73 | |||
74 | // Get script | ||
75 | OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script; | ||
76 | Obj.TryGetValue(ScriptID, out Script); | ||
77 | |||
78 | return Script; | ||
79 | |||
80 | } | ||
81 | internal void SetScript(string ObjectID, string ScriptID, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script) | ||
82 | { | ||
83 | // Create object if it doesn't exist | ||
84 | if (Scripts.ContainsKey(ObjectID) == false) | ||
85 | Scripts.Add(ObjectID, new Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass>()); | ||
86 | |||
87 | // Delete script if it exists | ||
88 | Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass> Obj; | ||
89 | Scripts.TryGetValue(ObjectID, out Obj); | ||
90 | if (Obj.ContainsKey(ScriptID) == true) | ||
91 | Obj.Remove(ScriptID); | ||
92 | |||
93 | // Add to object | ||
94 | Obj.Add(ScriptID, Script); | ||
95 | |||
96 | } | ||
97 | |||
98 | /// <summary> | ||
99 | /// Fetches, loads and hooks up a script to an objects events | ||
100 | /// </summary> | ||
101 | /// <param name="ScriptID"></param> | ||
102 | /// <param name="ObjectID"></param> | ||
103 | public void StartScript(string ScriptID, string ObjectID) | ||
104 | { | ||
105 | Common.SendToDebug("ScriptManager StartScript: ScriptID: " + ScriptID + ", ObjectID: " + ObjectID); | ||
106 | |||
107 | // We will initialize and start the script. | ||
108 | // It will be up to the script itself to hook up the correct events. | ||
109 | string FileName; | ||
110 | |||
111 | // * Fetch script from server | ||
112 | // DEBUG - ScriptID is an actual filename during debug | ||
113 | // (therefore we can also check type by looking at extension) | ||
114 | FileName = ScriptID; | ||
115 | |||
116 | // * Does script need compile? Send it to LSL compiler first. (TODO: Use (and clean) compiler cache) | ||
117 | if (FileName.ToLower().EndsWith(".lso")) | ||
118 | { | ||
119 | Common.SendToDebug("ScriptManager Script is LSO, compiling to .Net Assembly"); | ||
120 | // Create a new instance of the compiler (currently we don't want reuse) | ||
121 | OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Engine LSLCompiler = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Engine(); | ||
122 | // Compile | ||
123 | FileName = LSLCompiler.Compile(FileName); | ||
124 | } | ||
125 | |||
126 | // * Insert yield into code | ||
127 | FileName = ProcessYield(FileName); | ||
128 | |||
129 | // * Find next available AppDomain to put it in | ||
130 | AppDomain FreeAppDomain = GetFreeAppDomain(); | ||
131 | |||
132 | // * Load and start script | ||
133 | OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName); | ||
134 | string FullScriptID = ScriptID + "." + ObjectID; | ||
135 | // Add it to our temporary active script keeper | ||
136 | //Scripts.Add(FullScriptID, Script); | ||
137 | SetScript(ObjectID, ScriptID, Script); | ||
138 | // We need to give (untrusted) assembly a private instance of BuiltIns | ||
139 | // this private copy will contain Read-Only FullScriptID so that it can bring that on to the server whenever needed. | ||
140 | OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BuiltIn_Commands_Interface LSLB = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BuiltIn_Commands_TestImplementation(FullScriptID); | ||
141 | // Start the script - giving it BuiltIns | ||
142 | Common.SendToDebug("ScriptManager initializing script, handing over private builtin command interface"); | ||
143 | Script.Start(LSLB); | ||
144 | |||
145 | |||
146 | } | ||
147 | private string ProcessYield(string FileName) | ||
148 | { | ||
149 | // TODO: Create a new assembly and copy old but insert Yield Code | ||
150 | return FileName; | ||
151 | } | ||
152 | |||
153 | private AppDomain GetFreeAppDomain() | ||
154 | { | ||
155 | // TODO: Find an available AppDomain - if none, create one and add default security | ||
156 | return Thread.GetDomain(); | ||
157 | } | ||
158 | |||
159 | /// <summary> | ||
160 | /// Does actual loading and initialization of script Assembly | ||
161 | /// </summary> | ||
162 | /// <param name="FreeAppDomain">AppDomain to load script into</param> | ||
163 | /// <param name="FileName">FileName of script assembly (.dll)</param> | ||
164 | /// <returns></returns> | ||
165 | private OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass LoadAndInitAssembly(AppDomain FreeAppDomain, string FileName) | ||
166 | { | ||
167 | Common.SendToDebug("ScriptManager Loading Assembly " + FileName); | ||
168 | // Load .Net Assembly (.dll) | ||
169 | // Initialize and return it | ||
170 | |||
171 | // TODO: Add error handling | ||
172 | // Script might not follow our rules since users can upload -anything- | ||
173 | |||
174 | Assembly a; | ||
175 | //try | ||
176 | //{ | ||
177 | |||
178 | |||
179 | // Load to default appdomain (temporary) | ||
180 | a = Assembly.LoadFrom(FileName); | ||
181 | // Load to specified appdomain | ||
182 | // TODO: Insert security | ||
183 | //a = FreeAppDomain.Load(FileName); | ||
184 | //} | ||
185 | //catch (Exception e) | ||
186 | //{ | ||
187 | //} | ||
188 | |||
189 | |||
190 | foreach (Type _t in a.GetTypes()) | ||
191 | { | ||
192 | Console.WriteLine("Type: " + _t.ToString()); | ||
193 | } | ||
194 | |||
195 | Type t; | ||
196 | //try | ||
197 | //{ | ||
198 | t = a.GetType("LSL_ScriptObject", true); | ||
199 | //} | ||
200 | //catch (Exception e) | ||
201 | //{ | ||
202 | //} | ||
203 | |||
204 | return (OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass)Activator.CreateInstance(t); | ||
205 | |||
206 | |||
207 | } | ||
208 | |||
209 | internal void ExecuteFunction(string ObjectID, string ScriptID, string FunctionName, object[] args) | ||
210 | { | ||
211 | Common.SendToDebug("Executing Function ObjectID: " + ObjectID + ", ScriptID: " + ScriptID + ", FunctionName: " + FunctionName); | ||
212 | OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = myScriptEngine.myScriptManager.GetScript(ObjectID, ScriptID); | ||
213 | |||
214 | Type type = Script.GetType(); | ||
215 | //object o = (object)Script; | ||
216 | |||
217 | //System.Collections.Generic.List<string> Functions = (System.Collections.Generic.List<string>) | ||
218 | //Type type = typeof(OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass); | ||
219 | Common.SendToDebug("Invoke: \"" + Script.State + "_event_" + FunctionName + "\""); | ||
220 | type.InvokeMember(Script.State + "_event_" + FunctionName, BindingFlags.InvokeMethod, null, Script, args); | ||
221 | //System.Collections.Generic.List<string> Functions = (System.Collections.Generic.List<string>)type.InvokeMember("GetFunctions", BindingFlags.InvokeMethod, null, Script, null); | ||
222 | |||
223 | |||
224 | //foreach (MemberInfo mi in type.GetMembers()) | ||
225 | //{ | ||
226 | // Common.SendToDebug("Member found: " + mi.ToString()); | ||
227 | //} | ||
228 | |||
229 | } | ||
230 | |||
231 | } | ||
232 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/TempWorldInterface.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/TempWorldInterface.cs new file mode 100644 index 0000000..6ba6c07 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/TempWorldInterface.cs | |||
@@ -0,0 +1,15 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | ||
6 | { | ||
7 | public class TempWorldInterfaceEventDelegates | ||
8 | { | ||
9 | public delegate void touch_start(string ObjectID); | ||
10 | } | ||
11 | public interface TempWorldInterface | ||
12 | { | ||
13 | event TempWorldInterfaceEventDelegates.touch_start touch_start; | ||
14 | } | ||
15 | } | ||