From 2a0e157985d790e6cbd83d61690da2709dfab9dd Mon Sep 17 00:00:00 2001 From: Tedd Hansen Date: Wed, 8 Aug 2007 14:05:13 +0000 Subject: Added ScriptEngine.DotNetEngine --- OpenSim/Region/ScriptEngine/DotNetEngine/Common.cs | 58 ++++++ .../ScriptEngine/DotNetEngine/EventManager.cs | 99 +++++++++ .../ScriptEngine/DotNetEngine/EventQueueManager.cs | 136 ++++++++++++ ...OpenSim.Region.ScriptEngine.DotNetEngine.csproj | 59 ++++++ .../OpenSim.Region.ScriptEngine.DotNetEngine.suo | Bin 0 -> 5120 bytes .../DotNetEngine/Properties/AssemblyInfo.cs | 35 ++++ .../ScriptEngine/DotNetEngine/ScriptEngine.cs | 77 +++++++ .../DotNetEngine/ScriptEngineInterface.cs | 40 ++++ .../ScriptEngine/DotNetEngine/ScriptManager.cs | 232 +++++++++++++++++++++ .../DotNetEngine/TempWorldInterface.cs | 15 ++ 10 files changed, 751 insertions(+) create mode 100644 OpenSim/Region/ScriptEngine/DotNetEngine/Common.cs create mode 100644 OpenSim/Region/ScriptEngine/DotNetEngine/EventManager.cs create mode 100644 OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs create mode 100644 OpenSim/Region/ScriptEngine/DotNetEngine/OpenSim.Region.ScriptEngine.DotNetEngine.csproj create mode 100644 OpenSim/Region/ScriptEngine/DotNetEngine/OpenSim.Region.ScriptEngine.DotNetEngine.suo create mode 100644 OpenSim/Region/ScriptEngine/DotNetEngine/Properties/AssemblyInfo.cs create mode 100644 OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs create mode 100644 OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngineInterface.cs create mode 100644 OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs create mode 100644 OpenSim/Region/ScriptEngine/DotNetEngine/TempWorldInterface.cs (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine') 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 @@ +/* +* Copyright (c) Contributors, http://www.openmetaverse.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. +* +*/ +/* Original code: Tedd Hansen */ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Region.ScriptEngine.DotNetEngine +{ + public static class Common + { + static public bool Debug = true; + + public delegate void SendToDebugEventDelegate(string Message); + public delegate void SendToLogEventDelegate(string Message); + static public event SendToDebugEventDelegate SendToDebugEvent; + static public event SendToLogEventDelegate SendToLogEvent; + + static public void SendToDebug(string Message) + { + //if (Debug == true) + Console.WriteLine("SE:Debug: " + Message); + //SendToDebugEvent("\r\n" + DateTime.Now.ToString("[HH:mm:ss] ") + Message); + } + static public void SendToLog(string Message) + { + //if (Debug == true) + Console.WriteLine("SE:LOG: " + Message); + //SendToLogEvent("\r\n" + DateTime.Now.ToString("[HH:mm:ss] ") + Message); + } + } + +} 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 @@ +/* +* Copyright (c) Contributors, http://www.openmetaverse.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. +* +*/ +/* Original code: Tedd Hansen */ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Region.ScriptEngine.DotNetEngine +{ + /// + /// Prepares events so they can be directly executed upon a script by EventQueueManager, then queues it. + /// + class EventManager + { + private ScriptEngine myScriptEngine; + public EventManager(ScriptEngine _ScriptEngine) + { + myScriptEngine = _ScriptEngine; + // TODO: HOOK EVENTS UP TO SERVER! + Common.SendToDebug("EventManager Start"); + + // Hook up a test event to our test form + Common.SendToDebug("EventManager Hooking up dummy-event: touch_start"); + myScriptEngine.World.touch_start += new TempWorldInterfaceEventDelegates.touch_start(touch_start); + } + + public void touch_start(string ObjectID) + { + // Add to queue for all scripts in ObjectID object + Common.SendToDebug("EventManager Event: touch_start"); + myScriptEngine.myEventQueueManager.AddToObjectQueue(ObjectID, "touch_start", new object[] { (UInt32)0 }); + } + + + // TODO: Replace placeholders below + // These needs to be hooked up to OpenSim during init of this class + // then queued in EventQueueManager. + // When queued in EventQueueManager they need to be LSL compatible (name and params) + public void state_entry() { } + public void state_exit() { } + //public void touch_start() { } + public void touch() { } + public void touch_end() { } + public void collision_start() { } + public void collision() { } + public void collision_end() { } + public void land_collision_start() { } + public void land_collision() { } + public void land_collision_end() { } + public void timer() { } + public void listen() { } + public void on_rez() { } + public void sensor() { } + public void no_sensor() { } + public void control() { } + public void money() { } + public void email() { } + public void at_target() { } + public void not_at_target() { } + public void at_rot_target() { } + public void not_at_rot_target() { } + public void run_time_permissions() { } + public void changed() { } + public void attach() { } + public void dataserver() { } + public void link_message() { } + public void moving_start() { } + public void moving_end() { } + public void object_rez() { } + public void remote_data() { } + public void http_response() { } + + } +} 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 @@ +/* +* Copyright (c) Contributors, http://www.openmetaverse.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. +* +*/ +/* Original code: Tedd Hansen */ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Reflection; + +namespace OpenSim.Region.ScriptEngine.DotNetEngine +{ + class EventQueueManager + { + private Thread EventQueueThread; + private int NothingToDoSleepms = 200; + private Queue EventQueue = new Queue(); + private struct QueueItemStruct + { + public string ObjectID; + public string ScriptID; + public string FunctionName; + public object[] param; + } + + private ScriptEngine myScriptEngine; + public EventQueueManager(ScriptEngine _ScriptEngine) + { + myScriptEngine = _ScriptEngine; + Common.SendToDebug("EventQueueManager Start"); + // Start worker thread + EventQueueThread = new Thread(EventQueueThreadLoop); + EventQueueThread.IsBackground = true; + EventQueueThread.Name = "EventQueueManagerThread"; + EventQueueThread.Start(); + } + ~EventQueueManager() + { + // Kill worker thread + if (EventQueueThread != null && EventQueueThread.IsAlive == true) + { + try + { + EventQueueThread.Abort(); + EventQueueThread.Join(); + } + catch (Exception e) + { + Common.SendToDebug("EventQueueManager Exception killing worker thread: " + e.ToString()); + } + } + // Todo: Clean up our queues + + } + + private void EventQueueThreadLoop() + { + Common.SendToDebug("EventQueueManager Worker thread spawned"); + try + { + while (true) + { + if (EventQueue.Count == 0) + { + // Nothing to do? Sleep a bit waiting for something to do + Thread.Sleep(NothingToDoSleepms); + } + else + { + // Something in queue, process + QueueItemStruct QIS = EventQueue.Dequeue(); + Common.SendToDebug("Processing event for ObjectID: " + QIS.ObjectID + ", ScriptID: " + QIS.ScriptID + ", FunctionName: " + QIS.FunctionName); + // TODO: Execute function + myScriptEngine.myScriptManager.ExecuteFunction(QIS.ObjectID, QIS.ScriptID, QIS.FunctionName, QIS.param); + } + } + } + catch (ThreadAbortException tae) + { + Common.SendToDebug("EventQueueManager Worker thread killed: " + tae.Message); + } + } + + public void AddToObjectQueue(string ObjectID, string FunctionName, object[] param) + { + // Determine all scripts in Object and add to their queue + Common.SendToDebug("EventQueueManager Adding ObjectID: " + ObjectID + ", FunctionName: " + FunctionName); + + foreach (string ScriptID in myScriptEngine.myScriptManager.GetScriptKeys(ObjectID)) + { + // Add to each script in that object + // TODO: Some scripts may not subscribe to this event. Should we NOT add it? Does it matter? + + // Create a structure and add data + QueueItemStruct QIS = new QueueItemStruct(); + QIS.ObjectID = ObjectID; + QIS.ScriptID = ScriptID; + QIS.FunctionName = FunctionName; + QIS.param = param; + + // Add it to queue + EventQueue.Enqueue(QIS); + + } + } + //public void AddToScriptQueue(string ObjectID, string FunctionName, object[] param) + //{ + // // Add to script queue + //} + + } +} 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 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {8D47DF28-AAC4-47AB-9A6D-9A104A115817} + Library + Properties + OpenSim.Region.ScriptEngine.DotNetEngine + OpenSim.Region.ScriptEngine.DotNetEngine + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + {E56CB0C4-DBE8-4169-AC21-B6A2E8235A82} + OpenSim.ScriptEngine.DotNetEngine.Compiler.LSL + + + + + \ 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 Binary files /dev/null and b/OpenSim/Region/ScriptEngine/DotNetEngine/OpenSim.Region.ScriptEngine.DotNetEngine.suo 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 @@ +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.Region.ScriptEngine.DotNetEngine")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("OpenSim.Region.ScriptEngine.DotNetEngine")] +[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("2842257e-6fde-4460-9368-4cde57fa9cc4")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[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 @@ +/* +* Copyright (c) Contributors, http://www.openmetaverse.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. +* +*/ +/* Original code: Tedd Hansen */ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Region.ScriptEngine.DotNetEngine +{ + public class ScriptEngine : ScriptEngineInterface + { + // + // This is the root object for ScriptEngine + // + + internal TempWorldInterface World; + internal EventManager myEventManager; // Handles and queues incoming events from OpenSim + internal EventQueueManager myEventQueueManager; // Executes events + internal ScriptManager myScriptManager; // Load, unload and execute scripts + + public ScriptEngine() + { + Common.SendToDebug("ScriptEngine Object Initialized"); + } + + public void InitializeEngine(TempWorldInterface Sceneworld) + { + World = Sceneworld; + Common.SendToDebug("ScriptEngine InitializeEngine()"); + + // Create all objects we'll be using + myEventQueueManager = new EventQueueManager(this); + myEventManager = new EventManager(this); + myScriptManager = new ScriptManager(this); + + // Should we iterate the region for scripts that needs starting? + // Or can we assume we are loaded before anything else so we can use proper events? + } + public void Shutdown() + { + // We are shutting down + } + + // !!!FOR DEBUGGING ONLY!!! (for executing script directly from test app) + [Obsolete("!!!FOR DEBUGGING ONLY!!!")] + public void StartScript(string ScriptID, string ObjectID) + { + Common.SendToDebug("ScriptEngine DEBUG: StartScript: " + ScriptID); + myScriptManager.StartScript(ScriptID, ObjectID); + } + } +} 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 @@ +/* +* Copyright (c) Contributors, http://www.openmetaverse.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. +* +*/ +/* Original code: Tedd Hansen */ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Region.ScriptEngine.DotNetEngine +{ + interface ScriptEngineInterface + { + void InitializeEngine(TempWorldInterface Sceneworld); + void Shutdown(); + } +} 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 @@ +/* +* Copyright (c) Contributors, http://www.openmetaverse.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. +* +*/ +/* Original code: Tedd Hansen */ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Reflection; + +namespace OpenSim.Region.ScriptEngine.DotNetEngine +{ + class ScriptManager + { + + private ScriptEngine myScriptEngine; + public ScriptManager(ScriptEngine _ScriptEngine) + { + myScriptEngine = _ScriptEngine; + Common.SendToDebug("ScriptManager Start"); + } + + + // Object> + internal Dictionary> Scripts = new Dictionary>(); + + + internal Dictionary.KeyCollection GetScriptKeys(string ObjectID) + { + if (Scripts.ContainsKey(ObjectID) == false) + return null; + + Dictionary Obj; + Scripts.TryGetValue(ObjectID, out Obj); + + return Obj.Keys; + + } + + internal OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass GetScript(string ObjectID, string ScriptID) + { + if (Scripts.ContainsKey(ObjectID) == false) + return null; + + Dictionary Obj; + Scripts.TryGetValue(ObjectID, out Obj); + if (Obj.ContainsKey(ScriptID) == false) + return null; + + // Get script + OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script; + Obj.TryGetValue(ScriptID, out Script); + + return Script; + + } + internal void SetScript(string ObjectID, string ScriptID, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script) + { + // Create object if it doesn't exist + if (Scripts.ContainsKey(ObjectID) == false) + Scripts.Add(ObjectID, new Dictionary()); + + // Delete script if it exists + Dictionary Obj; + Scripts.TryGetValue(ObjectID, out Obj); + if (Obj.ContainsKey(ScriptID) == true) + Obj.Remove(ScriptID); + + // Add to object + Obj.Add(ScriptID, Script); + + } + + /// + /// Fetches, loads and hooks up a script to an objects events + /// + /// + /// + public void StartScript(string ScriptID, string ObjectID) + { + Common.SendToDebug("ScriptManager StartScript: ScriptID: " + ScriptID + ", ObjectID: " + ObjectID); + + // We will initialize and start the script. + // It will be up to the script itself to hook up the correct events. + string FileName; + + // * Fetch script from server + // DEBUG - ScriptID is an actual filename during debug + // (therefore we can also check type by looking at extension) + FileName = ScriptID; + + // * Does script need compile? Send it to LSL compiler first. (TODO: Use (and clean) compiler cache) + if (FileName.ToLower().EndsWith(".lso")) + { + Common.SendToDebug("ScriptManager Script is LSO, compiling to .Net Assembly"); + // Create a new instance of the compiler (currently we don't want reuse) + OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Engine LSLCompiler = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Engine(); + // Compile + FileName = LSLCompiler.Compile(FileName); + } + + // * Insert yield into code + FileName = ProcessYield(FileName); + + // * Find next available AppDomain to put it in + AppDomain FreeAppDomain = GetFreeAppDomain(); + + // * Load and start script + OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName); + string FullScriptID = ScriptID + "." + ObjectID; + // Add it to our temporary active script keeper + //Scripts.Add(FullScriptID, Script); + SetScript(ObjectID, ScriptID, Script); + // We need to give (untrusted) assembly a private instance of BuiltIns + // this private copy will contain Read-Only FullScriptID so that it can bring that on to the server whenever needed. + OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BuiltIn_Commands_Interface LSLB = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BuiltIn_Commands_TestImplementation(FullScriptID); + // Start the script - giving it BuiltIns + Common.SendToDebug("ScriptManager initializing script, handing over private builtin command interface"); + Script.Start(LSLB); + + + } + private string ProcessYield(string FileName) + { + // TODO: Create a new assembly and copy old but insert Yield Code + return FileName; + } + + private AppDomain GetFreeAppDomain() + { + // TODO: Find an available AppDomain - if none, create one and add default security + return Thread.GetDomain(); + } + + /// + /// Does actual loading and initialization of script Assembly + /// + /// AppDomain to load script into + /// FileName of script assembly (.dll) + /// + private OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass LoadAndInitAssembly(AppDomain FreeAppDomain, string FileName) + { + Common.SendToDebug("ScriptManager Loading Assembly " + FileName); + // Load .Net Assembly (.dll) + // Initialize and return it + + // TODO: Add error handling + // Script might not follow our rules since users can upload -anything- + + 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) + //{ + //} + + + foreach (Type _t in a.GetTypes()) + { + Console.WriteLine("Type: " + _t.ToString()); + } + + Type t; + //try + //{ + t = a.GetType("LSL_ScriptObject", true); + //} + //catch (Exception e) + //{ + //} + + return (OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass)Activator.CreateInstance(t); + + + } + + internal void ExecuteFunction(string ObjectID, string ScriptID, string FunctionName, object[] args) + { + Common.SendToDebug("Executing Function ObjectID: " + ObjectID + ", ScriptID: " + ScriptID + ", FunctionName: " + FunctionName); + OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = myScriptEngine.myScriptManager.GetScript(ObjectID, ScriptID); + + Type type = Script.GetType(); + //object o = (object)Script; + + //System.Collections.Generic.List Functions = (System.Collections.Generic.List) + //Type type = typeof(OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass); + Common.SendToDebug("Invoke: \"" + Script.State + "_event_" + FunctionName + "\""); + type.InvokeMember(Script.State + "_event_" + FunctionName, BindingFlags.InvokeMethod, null, Script, args); + //System.Collections.Generic.List Functions = (System.Collections.Generic.List)type.InvokeMember("GetFunctions", BindingFlags.InvokeMethod, null, Script, null); + + + //foreach (MemberInfo mi in type.GetMembers()) + //{ + // Common.SendToDebug("Member found: " + mi.ToString()); + //} + + } + + } +} 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 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Region.ScriptEngine.DotNetEngine +{ + public class TempWorldInterfaceEventDelegates + { + public delegate void touch_start(string ObjectID); + } + public interface TempWorldInterface + { + event TempWorldInterfaceEventDelegates.touch_start touch_start; + } +} -- cgit v1.1