From 59f0920a8fc58ea6443768591b762f5673134840 Mon Sep 17 00:00:00 2001 From: Tedd Hansen Date: Sat, 22 Sep 2007 13:15:52 +0000 Subject: 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 ++++++++ .../Grid/ScriptServer/Properties/AssemblyInfo.cs | 33 ++++++ .../Grid/ScriptServer/RegionConnectionManager.cs | 16 +++ OpenSim/Grid/ScriptServer/RegionScriptDaemon.cs | 94 ++++++++++++++++ OpenSim/Grid/ScriptServer/RegionsManager.cs | 19 ++++ OpenSim/Grid/ScriptServer/ScriptEngineInterface.cs | 38 +++++++ OpenSim/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 ++--- 11 files changed, 461 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 (limited to 'OpenSim') diff --git a/OpenSim/Grid/ScriptServer/Main.cs b/OpenSim/Grid/ScriptServer/Main.cs new file mode 100644 index 0000000..9f16ea8 --- /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 0000000..d60dbb4 --- /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 0000000..6a517e9 --- /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 0000000..435c09b --- /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 0000000..0e1fad1 --- /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 0000000..7440bcb --- /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 0000000..1b5dc39 --- /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 0000000..2c26027 --- /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 0000000..6968848 --- /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 06bedaf..5a330f3 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 5355388..527533d 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 -- cgit v1.1