From 59f0920a8fc58ea6443768591b762f5673134840 Mon Sep 17 00:00:00 2001 From: Tedd Hansen Date: Sat, 22 Sep 2007 13:15:52 +0000 Subject: [PATCH] Stand Alone ScriptEngine: early framework, ongoing planning (don't touch yet, will go through major reorganizing). Still a LOT of things needs to be solved... --- OpenSim/Grid/ScriptServer/Main.cs | 46 +++++++ .../ScriptServer/Properties/AssemblyInfo.cs | 33 +++++ .../ScriptServer/RegionConnectionManager.cs | 16 +++ .../Grid/ScriptServer/RegionScriptDaemon.cs | 94 +++++++++++++ OpenSim/Grid/ScriptServer/RegionsManager.cs | 19 +++ .../ScriptServer/ScriptEngineInterface.cs | 38 ++++++ .../Grid/ScriptServer/ScriptEngineLoader.cs | 124 ++++++++++++++++++ OpenSim/Grid/ScriptServer/ScriptServer.cs | 27 ++++ OpenSim/Grid/ScriptServer/ScriptServer.csproj | 47 +++++++ .../Scenes/Scripting/ScriptEngineInterface.cs | 9 +- .../Scenes/Scripting/ScriptEngineLoader.cs | 26 ++-- prebuild.xml | 31 +++++ 12 files changed, 492 insertions(+), 18 deletions(-) create mode 100644 OpenSim/Grid/ScriptServer/Main.cs create mode 100644 OpenSim/Grid/ScriptServer/Properties/AssemblyInfo.cs create mode 100644 OpenSim/Grid/ScriptServer/RegionConnectionManager.cs create mode 100644 OpenSim/Grid/ScriptServer/RegionScriptDaemon.cs create mode 100644 OpenSim/Grid/ScriptServer/RegionsManager.cs create mode 100644 OpenSim/Grid/ScriptServer/ScriptEngineInterface.cs create mode 100644 OpenSim/Grid/ScriptServer/ScriptEngineLoader.cs create mode 100644 OpenSim/Grid/ScriptServer/ScriptServer.cs create mode 100644 OpenSim/Grid/ScriptServer/ScriptServer.csproj diff --git a/OpenSim/Grid/ScriptServer/Main.cs b/OpenSim/Grid/ScriptServer/Main.cs new file mode 100644 index 0000000000..9f16ea83fc --- /dev/null +++ b/OpenSim/Grid/ScriptServer/Main.cs @@ -0,0 +1,46 @@ +/* +* Copyright (c) Contributors, http://opensimulator.org/ +* See CONTRIBUTORS.TXT for a full list of copyright holders. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the OpenSim Project nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Grid.ScriptServer +{ + class OpenScript_Main + { + + public static ScriptServer SE; + + static void Main(string[] args) + { + // Application is starting + SE = new ScriptServer(); + } + + } +} diff --git a/OpenSim/Grid/ScriptServer/Properties/AssemblyInfo.cs b/OpenSim/Grid/ScriptServer/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..d60dbb4ade --- /dev/null +++ b/OpenSim/Grid/ScriptServer/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("OpenSim.Grid.ScriptServer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("OpenSim.Grid.ScriptServer")] +[assembly: AssemblyCopyright("Copyright © 2007")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("b6861b87-5203-4040-b756-fd4774932f82")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/OpenSim/Grid/ScriptServer/RegionConnectionManager.cs b/OpenSim/Grid/ScriptServer/RegionConnectionManager.cs new file mode 100644 index 0000000000..6a517e93d4 --- /dev/null +++ b/OpenSim/Grid/ScriptServer/RegionConnectionManager.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Grid.ScriptServer +{ + // Maintains connection and communication to a region + class RegionConnectionManager + { + + public RegionConnectionManager() + { + } + + } +} diff --git a/OpenSim/Grid/ScriptServer/RegionScriptDaemon.cs b/OpenSim/Grid/ScriptServer/RegionScriptDaemon.cs new file mode 100644 index 0000000000..435c09bfc6 --- /dev/null +++ b/OpenSim/Grid/ScriptServer/RegionScriptDaemon.cs @@ -0,0 +1,94 @@ +/* +* Copyright (c) Contributors, http://opensimulator.org/ +* See CONTRIBUTORS.TXT for a full list of copyright holders. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the OpenSim Project nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; + +namespace OpenSim.Grid.ScriptServer +{ + // Waiting for incoming script requests from region + internal class RegionScriptDaemon + { + private Thread listenThread; + + public ScriptServer m_ScriptServer; + public RegionScriptDaemon(ScriptServer scriptServer) + { + m_ScriptServer = scriptServer; + } + ~RegionScriptDaemon() + { + Stop(); + } + + /// + /// Starts listening for region requests + /// + public void Start() + { + // Start listener + Stop(); + listenThread = new Thread(ListenThreadLoop); + listenThread.Name = "listenThread"; + listenThread.IsBackground = true; + listenThread.Start(); + } + /// + /// Stops listening for region requests + /// + public void Stop() + { + // Stop listener, clean up + if (listenThread != null) + { + try + { + if (listenThread.IsAlive) + listenThread.Abort(); + listenThread.Join(1000); // Wait 1 second for thread to shut down + } + catch { } + listenThread = null; + } + } + + private void ListenThreadLoop() + { + // * Listen for requests from regions + // * When a request is received: + // - Authenticate region + // - Authenticate user + // - Have correct scriptengine load script + // ~ ask scriptengines if they will accept script? + // - Add script to shared communication channel towards that region + + } + + } +} diff --git a/OpenSim/Grid/ScriptServer/RegionsManager.cs b/OpenSim/Grid/ScriptServer/RegionsManager.cs new file mode 100644 index 0000000000..0e1fad1450 --- /dev/null +++ b/OpenSim/Grid/ScriptServer/RegionsManager.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Grid.ScriptServer +{ + // Maintains all regions + class RegionsManager + { + private List Regions = new List(); + + public ScriptServer m_ScriptServer; + public RegionsManager(ScriptServer scriptServer) + { + m_ScriptServer = scriptServer; + } + + } +} diff --git a/OpenSim/Grid/ScriptServer/ScriptEngineInterface.cs b/OpenSim/Grid/ScriptServer/ScriptEngineInterface.cs new file mode 100644 index 0000000000..7440bcb934 --- /dev/null +++ b/OpenSim/Grid/ScriptServer/ScriptEngineInterface.cs @@ -0,0 +1,38 @@ +/* +* Copyright (c) Contributors, http://opensimulator.org/ +* See CONTRIBUTORS.TXT for a full list of copyright holders. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the OpenSim Project nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ +using OpenSim.Framework.Console; + +namespace OpenSim.Grid.ScriptServer +{ + public interface ScriptEngineInterface + { + //void InitializeEngine(Scene Sceneworld, LogBase logger); + void Shutdown(); +// void StartScript(string ScriptID, IScriptHost ObjectID); + } +} \ No newline at end of file diff --git a/OpenSim/Grid/ScriptServer/ScriptEngineLoader.cs b/OpenSim/Grid/ScriptServer/ScriptEngineLoader.cs new file mode 100644 index 0000000000..1b5dc399ee --- /dev/null +++ b/OpenSim/Grid/ScriptServer/ScriptEngineLoader.cs @@ -0,0 +1,124 @@ +/* +* Copyright (c) Contributors, http://opensimulator.org/ +* See CONTRIBUTORS.TXT for a full list of copyright holders. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the OpenSim Project nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +*/ +using System; +using System.IO; +using System.Reflection; +using OpenSim.Framework.Console; + +namespace OpenSim.Grid.ScriptServer +{ + public class ScriptEngineLoader + { + private LogBase m_log; + + public ScriptEngineLoader(LogBase logger) + { + m_log = logger; + } + + public ScriptEngineInterface LoadScriptEngine(string EngineName) + { + ScriptEngineInterface ret = null; + try + { + ret = + LoadAndInitAssembly( + Path.Combine("ScriptEngines", "OpenSim.Region.ScriptEngine." + EngineName + ".dll"), + "OpenSim.Region.ScriptEngine." + EngineName + ".ScriptEngine"); + } + catch (Exception e) + { + m_log.Error("ScriptEngine", + "Error loading assembly \"" + EngineName + "\": " + e.Message + ", " + + e.StackTrace.ToString()); + } + return ret; + } + + /// + /// Does actual loading and initialization of script Assembly + /// + /// AppDomain to load script into + /// FileName of script assembly (.dll) + /// + private ScriptEngineInterface LoadAndInitAssembly(string FileName, string NameSpace) + { + //Common.SendToDebug("Loading ScriptEngine Assembly " + FileName); + // Load .Net Assembly (.dll) + // Initialize and return it + + // TODO: Add error handling + + Assembly a; + //try + //{ + + + // Load to default appdomain (temporary) + a = Assembly.LoadFrom(FileName); + // Load to specified appdomain + // TODO: Insert security + //a = FreeAppDomain.Load(FileName); + //} + //catch (Exception e) + //{ + // m_log.Error("ScriptEngine", "Error loading assembly \"" + FileName + "\": " + e.ToString()); + //} + + + //Console.WriteLine("Loading: " + FileName); + //foreach (Type _t in a.GetTypes()) + //{ + // Console.WriteLine("Type: " + _t.ToString()); + //} + + Type t; + //try + //{ + t = a.GetType(NameSpace, true); + //} + //catch (Exception e) + //{ + // m_log.Error("ScriptEngine", "Error initializing type \"" + NameSpace + "\" from \"" + FileName + "\": " + e.ToString()); + //} + + ScriptEngineInterface ret; + //try + //{ + ret = (ScriptEngineInterface) Activator.CreateInstance(t); + //} + //catch (Exception e) + //{ + // m_log.Error("ScriptEngine", "Error initializing type \"" + NameSpace + "\" from \"" + FileName + "\": " + e.ToString()); + //} + + return ret; + } + } +} + diff --git a/OpenSim/Grid/ScriptServer/ScriptServer.cs b/OpenSim/Grid/ScriptServer/ScriptServer.cs new file mode 100644 index 0000000000..2c26027e5e --- /dev/null +++ b/OpenSim/Grid/ScriptServer/ScriptServer.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Grid.ScriptServer +{ + class ScriptServer + { + public RegionScriptDaemon RegionScriptDaemon; // Listen for incoming from region + public RegionsManager RegionManager; // Handle regions + public ScriptEngineLoader ScriptEngineLoader; // Loads scriptengines + + public ScriptServer() + { + RegionScriptDaemon = new RegionScriptDaemon(this); + RegionManager = new RegionsManager(this); + //ScriptEngineLoader = new ScriptEngineLoader(this); + } + + ~ScriptServer() + { + } + + + + } +} diff --git a/OpenSim/Grid/ScriptServer/ScriptServer.csproj b/OpenSim/Grid/ScriptServer/ScriptServer.csproj new file mode 100644 index 0000000000..696884842f --- /dev/null +++ b/OpenSim/Grid/ScriptServer/ScriptServer.csproj @@ -0,0 +1,47 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {8FF1D8B6-9E2F-47AB-A26A-F44CED20CD0E} + Exe + Properties + ScriptServer + ScriptServer + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + \ No newline at end of file diff --git a/OpenSim/Region/Environment/Scenes/Scripting/ScriptEngineInterface.cs b/OpenSim/Region/Environment/Scenes/Scripting/ScriptEngineInterface.cs index 06bedaf38a..5a330f3492 100644 --- a/OpenSim/Region/Environment/Scenes/Scripting/ScriptEngineInterface.cs +++ b/OpenSim/Region/Environment/Scenes/Scripting/ScriptEngineInterface.cs @@ -25,11 +25,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ -/* Original code: Tedd Hansen */ -using OpenSim.Framework.Console; - -//TODO: WHERE TO PLACE THIS? - +using OpenSim.Framework.Console; + +//TODO: WHERE TO PLACE THIS? + namespace OpenSim.Region.Environment.Scenes.Scripting { public interface ScriptEngineInterface diff --git a/OpenSim/Region/Environment/Scenes/Scripting/ScriptEngineLoader.cs b/OpenSim/Region/Environment/Scenes/Scripting/ScriptEngineLoader.cs index 5355388e10..527533dc12 100644 --- a/OpenSim/Region/Environment/Scenes/Scripting/ScriptEngineLoader.cs +++ b/OpenSim/Region/Environment/Scenes/Scripting/ScriptEngineLoader.cs @@ -26,17 +26,17 @@ * */ /* Original code: Tedd Hansen */ -using System; -using System.IO; -using System.Reflection; -using OpenSim.Framework.Console; - +using System; +using System.IO; +using System.Reflection; +using OpenSim.Framework.Console; + namespace OpenSim.Region.Environment.Scenes.Scripting { public class ScriptEngineLoader { - private LogBase m_log; - + private LogBase m_log; + public ScriptEngineLoader(LogBase logger) { m_log = logger; @@ -47,15 +47,15 @@ namespace OpenSim.Region.Environment.Scenes.Scripting ScriptEngineInterface ret = null; try { - ret = - LoadAndInitAssembly( + ret = + LoadAndInitAssembly( Path.Combine("ScriptEngines", "OpenSim.Region.ScriptEngine." + EngineName + ".dll"), "OpenSim.Region.ScriptEngine." + EngineName + ".ScriptEngine"); } catch (Exception e) { - m_log.Error("ScriptEngine", - "Error loading assembly \"" + EngineName + "\": " + e.Message + ", " + + m_log.Error("ScriptEngine", + "Error loading assembly \"" + EngineName + "\": " + e.Message + ", " + e.StackTrace.ToString()); } return ret; @@ -118,7 +118,7 @@ namespace OpenSim.Region.Environment.Scenes.Scripting // m_log.Error("ScriptEngine", "Error initializing type \"" + NameSpace + "\" from \"" + FileName + "\": " + e.ToString()); //} - return ret; - } + return ret; + } } } \ No newline at end of file diff --git a/prebuild.xml b/prebuild.xml index 855a7b34a7..d224013fcc 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -947,6 +947,37 @@ + + + + ../../../bin/ + + + + + ../../../bin/ + + + + ../../../bin/ + + + + + + + + + + + + + + + + + +