From 240712ca9fc726653e2a03b944baa8b6f8155b07 Mon Sep 17 00:00:00 2001 From: Tedd Hansen Date: Sat, 18 Aug 2007 22:09:07 +0000 Subject: Scripts are working again. Scripts are now loaded into limited AppDomains (no security yet). *phew* that only took me 12 hours of coding... --- OpenSim/Region/ScriptEngine/Common/Executor.cs | 10 ++ .../DotNetEngine/Compiler/LSL/Compiler.cs | 2 +- .../DotNetEngine/Compiler/LSL/LSL_BaseClass.cs | 29 ++++++ .../ScriptEngine/DotNetEngine/ScriptManager.cs | 110 +++++++++++---------- 4 files changed, 98 insertions(+), 53 deletions(-) create mode 100644 OpenSim/Region/ScriptEngine/Common/Executor.cs diff --git a/OpenSim/Region/ScriptEngine/Common/Executor.cs b/OpenSim/Region/ScriptEngine/Common/Executor.cs new file mode 100644 index 0000000..2ae6a60 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Common/Executor.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Region.ScriptEngine.Common +{ + class Executor + { + } +} diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs index 435ee08..ad2717c 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs @@ -61,7 +61,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL string rootPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); string rootPathSE = Path.GetDirectoryName(this.GetType().Assembly.Location); - Console.WriteLine("Assembly location: " + rootPath); + //Console.WriteLine("Assembly location: " + rootPath); parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Common.dll")); parameters.ReferencedAssemblies.Add(Path.Combine(rootPathSE, "OpenSim.Region.ScriptEngine.DotNetEngine.dll")); diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs index 84fa9eb..7334e6f 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs @@ -4,6 +4,8 @@ using System.Text; using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler; using OpenSim.Region.ScriptEngine.Common; using System.Threading; +using System.Reflection; + namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL { @@ -46,6 +48,33 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL return; } + public void ExecuteEvent(string FunctionName, object[] args) + { + //foreach (MemberInfo mi in this.GetType().GetMembers()) + //{ + //if (mi.ToString().ToLower().Contains("default")) + //{ + // Console.WriteLine("Member found: " + mi.ToString()); + //} + //} + + Type type = this.GetType(); + + Console.WriteLine("ScriptEngine Invoke: \"" + this.State() + "_event_" + FunctionName + "\""); + + try + { + type.InvokeMember(this.State() + "_event_" + FunctionName, BindingFlags.InvokeMethod, null, this, args); + } + catch (Exception e) + { + // TODO: Send to correct place + Console.WriteLine("ScriptEngine Exception attempting to executing script function: " + e.ToString()); + } + + + } + // diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs index 8e0b277..602ac9f 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs @@ -226,97 +226,103 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine { //LSL_BaseClass mbrt = (LSL_BaseClass)FreeAppDomain.CreateInstanceAndUnwrap(FileName, "SecondLife.Script"); - Console.WriteLine("Base directory: " + AppDomain.CurrentDomain.BaseDirectory); + //Console.WriteLine("Base directory: " + AppDomain.CurrentDomain.BaseDirectory); - //LSL_BaseClass mbrt = (LSL_BaseClass)FreeAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script"); - LSL_BuiltIn_Commands_Interface mbrt = (LSL_BuiltIn_Commands_Interface)FreeAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script"); + LSL_BaseClass mbrt = (LSL_BaseClass)FreeAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script"); + //LSL_BuiltIn_Commands_Interface mbrt = (LSL_BuiltIn_Commands_Interface)FreeAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script"); Type mytype = mbrt.GetType(); Console.WriteLine("is proxy={0}", RemotingServices.IsTransparentProxy(mbrt)); //mbrt.Start(); - return (LSL_BaseClass)mbrt; + return mbrt; + //return (LSL_BaseClass)mbrt; - //myScriptEngine.m_logger.Verbose("ScriptEngine", "ScriptManager Loading Assembly " + FileName); - // Load .Net Assembly (.dll) - // Initialize and return it +// //myScriptEngine.m_logger.Verbose("ScriptEngine", "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- +// // TODO: Add error handling +// // Script might not follow our rules since users can upload -anything- - Assembly a; - //try - //{ +// 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) - //{ - //} +// // 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()); - //} +// //foreach (Type _t in a.GetTypes()) +// //{ +// // Console.WriteLine("Type: " + _t.ToString()); +// //} - Type t; - //try - //{ - t = a.GetType("SecondLife.Script", true); - //} - //catch (Exception e) - //{ - //} +// Type t; +// //try +// //{ +// t = a.GetType("SecondLife.Script", true); +// //} +// //catch (Exception e) +// //{ +// //} - // Create constructor arguments - object[] args = new object[] - { -// this, -// host - }; +// // Create constructor arguments +// object[] args = new object[] +// { +//// this, +//// host +// }; - return (OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass)Activator.CreateInstance(t, args ); +// return (OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass)Activator.CreateInstance(t, args ); } internal void ExecuteFunction(IScriptHost ObjectID, string ScriptID, string FunctionName, object[] args) { + + // Execute a function in the script m_scriptEngine.Log.Verbose("ScriptEngine", "Executing Function ObjectID: " + ObjectID + ", ScriptID: " + ScriptID + ", FunctionName: " + FunctionName); OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = m_scriptEngine.myScriptManager.GetScript(ObjectID, ScriptID); - Type type = Script.GetType(); + Script.ExecuteEvent(FunctionName, args); + //Type type = Script.GetType(); - m_scriptEngine.Log.Verbose("ScriptEngine", "Invoke: \"" + Script.State() + "_event_" + FunctionName + "\""); - try - { - type.InvokeMember(Script.State() + "_event_" + FunctionName, BindingFlags.InvokeMethod, null, Script, args); - } - catch (Exception e) - { - m_scriptEngine.Log.Error("ScriptEngine", "Exception attempting to executing script function: " + e.ToString()); - } + ////foreach (MemberInfo mi in type.GetMembers()) + ////{ + //// Common.SendToDebug("Member found: " + mi.ToString()); + ////} + //m_scriptEngine.Log.Verbose("ScriptEngine", "Invoke: \"" + Script.State() + "_event_" + FunctionName + "\""); - //foreach (MemberInfo mi in type.GetMembers()) + //try + //{ + // type.InvokeMember(Script.State() + "_event_" + FunctionName, BindingFlags.InvokeMethod, null, Script, args); + //} + //catch (Exception e) //{ - // Common.SendToDebug("Member found: " + mi.ToString()); + // m_scriptEngine.Log.Error("ScriptEngine", "Exception attempting to executing script function: " + e.ToString()); //} + + } public string RegionName -- cgit v1.1