aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorTedd Hansen2007-08-18 23:24:38 +0000
committerTedd Hansen2007-08-18 23:24:38 +0000
commit37446b0392ba423894952f81aa0f938d2bd2de22 (patch)
tree674be11acb7037c8d98fb6de34bd12e547a6c175 /OpenSim/Region
parentstarting to add bits and pieces to physics prims that we will eventually need... (diff)
downloadopensim-SC-37446b0392ba423894952f81aa0f938d2bd2de22.zip
opensim-SC-37446b0392ba423894952f81aa0f938d2bd2de22.tar.gz
opensim-SC-37446b0392ba423894952f81aa0f938d2bd2de22.tar.bz2
opensim-SC-37446b0392ba423894952f81aa0f938d2bd2de22.tar.xz
Moved in-AppDomain event execution from Script to OpenSim.Region.ScriptEngine.Executor. Script no longer responsible for handling event calls to itself (and we can create reference cache in Executor).
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/Executor.cs48
-rw-r--r--OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands_Interface.cs1
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs66
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs38
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/Server_API/LSL_BuiltIn_Commands.cs7
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs80
8 files changed, 107 insertions, 137 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/Executor.cs b/OpenSim/Region/ScriptEngine/Common/Executor.cs
index 2ae6a60..ca6459b 100644
--- a/OpenSim/Region/ScriptEngine/Common/Executor.cs
+++ b/OpenSim/Region/ScriptEngine/Common/Executor.cs
@@ -1,10 +1,56 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Text; 3using System.Text;
4using System.Reflection;
4 5
5namespace OpenSim.Region.ScriptEngine.Common 6namespace OpenSim.Region.ScriptEngine.Common
6{ 7{
7 class Executor 8 public class Executor: MarshalByRefObject
8 { 9 {
10 /* TODO:
11 *
12 * Needs to be common for all AppDomains - share memory too?
13 * Needs to have an instance in each AppDomain, and some way of referring it.
14 * Need to know what AppDomain a script is in so we know where to find our instance.
15 *
16 */
17
18 private IScript m_Script;
19
20 public Executor(IScript Script)
21 {
22 m_Script = Script;
23 }
24 public void ExecuteEvent(string FunctionName, object[] args)
25 {
26 // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory.
27 // Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead!
28
29 //foreach (MemberInfo mi in this.GetType().GetMembers())
30 //{
31 //if (mi.ToString().ToLower().Contains("default"))
32 //{
33 // Console.WriteLine("Member found: " + mi.ToString());
34 //}
35 //}
36
37 Type type = m_Script.GetType();
38
39 Console.WriteLine("ScriptEngine Executor.ExecuteEvent: \"" + m_Script.State() + "_event_" + FunctionName + "\"");
40
41 try
42 {
43 type.InvokeMember(m_Script.State() + "_event_" + FunctionName, BindingFlags.InvokeMethod, null, m_Script, args);
44 }
45 catch (Exception e)
46 {
47 // TODO: Send to correct place
48 Console.WriteLine("ScriptEngine Exception attempting to executing script function: " + e.ToString());
49 }
50
51
52 }
53
54
9 } 55 }
10} 56}
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands_Interface.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands_Interface.cs
index beddbc5..f80898b 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands_Interface.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands_Interface.cs
@@ -34,6 +34,7 @@ namespace OpenSim.Region.ScriptEngine.Common
34{ 34{
35 public interface LSL_BuiltIn_Commands_Interface 35 public interface LSL_BuiltIn_Commands_Interface
36 { 36 {
37
37 string State(); 38 string State();
38 39
39 double llSin(double f); 40 double llSin(double f);
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs
index f80ebac..33e95d3 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs
@@ -12,9 +12,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
12 { 12 {
13 private int MaxScriptsPerAppDomain = 1; 13 private int MaxScriptsPerAppDomain = 1;
14 /// <summary> 14 /// <summary>
15 /// List of all AppDomains 15 /// Internal list of all AppDomains
16 /// </summary> 16 /// </summary>
17 private List<AppDomainStructure> AppDomains = new List<AppDomainStructure>(); 17 private List<AppDomainStructure> AppDomains = new List<AppDomainStructure>();
18 /// <summary>
19 /// Structure to keep track of data around AppDomain
20 /// </summary>
18 private struct AppDomainStructure 21 private struct AppDomainStructure
19 { 22 {
20 /// <summary> 23 /// <summary>
@@ -37,10 +40,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
37 private object GetLock = new object(); // Mutex 40 private object GetLock = new object(); // Mutex
38 private object FreeLock = new object(); // Mutex 41 private object FreeLock = new object(); // Mutex
39 42
40 private ScriptEngine m_scriptEngine; 43 //private ScriptEngine m_scriptEngine;
41 public AppDomainManager(ScriptEngine scriptEngine) 44 //public AppDomainManager(ScriptEngine scriptEngine)
45 public AppDomainManager()
42 { 46 {
43 m_scriptEngine = scriptEngine; 47 //m_scriptEngine = scriptEngine;
44 } 48 }
45 49
46 /// <summary> 50 /// <summary>
@@ -54,6 +58,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
54 // Current full? 58 // Current full?
55 if (CurrentAD.ScriptsLoaded >= MaxScriptsPerAppDomain) 59 if (CurrentAD.ScriptsLoaded >= MaxScriptsPerAppDomain)
56 { 60 {
61 // Add it to AppDomains list and empty current
57 AppDomains.Add(CurrentAD); 62 AppDomains.Add(CurrentAD);
58 CurrentAD = new AppDomainStructure(); 63 CurrentAD = new AppDomainStructure();
59 } 64 }
@@ -68,7 +73,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
68 73
69 } 74 }
70 75
71 // Increase number of scripts loaded 76 // Increase number of scripts loaded into this
77 // TODO:
78 // - We assume that every time someone wants an AppDomain they will load into it
79 // if this assumption is wrong we end up with a miscount and will never unload it.
80 //
72 CurrentAD.ScriptsLoaded++; 81 CurrentAD.ScriptsLoaded++;
73 // Return AppDomain 82 // Return AppDomain
74 return CurrentAD.CurrentAppDomain; 83 return CurrentAD.CurrentAppDomain;
@@ -84,46 +93,19 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
84 { 93 {
85 // Create and prepare a new AppDomain 94 // Create and prepare a new AppDomain
86 AppDomainNameCount++; 95 AppDomainNameCount++;
87 // TODO: Currently security and configuration match current appdomain 96 // TODO: Currently security match current appdomain
88 97
89 // Construct and initialize settings for a second AppDomain. 98 // Construct and initialize settings for a second AppDomain.
90 AppDomainSetup ads = new AppDomainSetup(); 99 AppDomainSetup ads = new AppDomainSetup();
91 ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory; 100 ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
92 //Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ScriptEngines");
93 //ads.ApplicationName = "DotNetScriptEngine";
94 //ads.DynamicBase = ads.ApplicationBase;
95
96 //Console.WriteLine("AppDomain BaseDirectory: " + ads.ApplicationBase);
97 ads.DisallowBindingRedirects = false; 101 ads.DisallowBindingRedirects = false;
98 ads.DisallowCodeDownload = true; 102 ads.DisallowCodeDownload = true;
99 ads.ShadowCopyFiles = "true"; 103 ads.ShadowCopyFiles = "true"; // Enabled shadowing
100 104 ads.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
101 ads.ConfigurationFile =
102 AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
103 105
104 AppDomain AD = AppDomain.CreateDomain("ScriptAppDomain_" + AppDomainNameCount, null, ads); 106 AppDomain AD = AppDomain.CreateDomain("ScriptAppDomain_" + AppDomainNameCount, null, ads);
105 //foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
106 //{
107 // //Console.WriteLine("Loading: " + a.GetName(true));
108 // try
109 // {
110 // //AD.Load(a.GetName(true));
111
112 // }
113 // catch (Exception e)
114 // {
115 // //Console.WriteLine("FAILED load");
116 // }
117
118 //}
119 107
120 //Console.WriteLine("Assembly file: " + this.GetType().Assembly.CodeBase); 108 // Return the new AppDomain
121 //Console.WriteLine("Assembly name: " + this.GetType().ToString());
122 //AD.CreateInstanceFrom(this.GetType().Assembly.CodeBase, "OpenSim.Region.ScriptEngine.DotNetEngine.ScriptEngine");
123
124 //AD.Load(this.GetType().Assembly.CodeBase);
125
126 Console.WriteLine("Done preparing new AppDomain.");
127 return AD; 109 return AD;
128 110
129 } 111 }
@@ -135,14 +117,19 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
135 { 117 {
136 lock (FreeLock) 118 lock (FreeLock)
137 { 119 {
120 // Go through all
138 foreach (AppDomainStructure ads in new System.Collections.ArrayList(AppDomains)) 121 foreach (AppDomainStructure ads in new System.Collections.ArrayList(AppDomains))
139 { 122 {
123 // Don't process current AppDomain
140 if (ads.CurrentAppDomain != CurrentAD.CurrentAppDomain) 124 if (ads.CurrentAppDomain != CurrentAD.CurrentAppDomain)
141 { 125 {
142 // Not current AppDomain 126 // Not current AppDomain
143 if (ads.ScriptsLoaded == ads.ScriptsWaitingUnload) 127 // Is number of unloaded bigger or equal to number of loaded?
128 if (ads.ScriptsLoaded <= ads.ScriptsWaitingUnload)
144 { 129 {
130 // Remove from internal list
145 AppDomains.Remove(ads); 131 AppDomains.Remove(ads);
132 // Unload
146 AppDomain.Unload(ads.CurrentAppDomain); 133 AppDomain.Unload(ads.CurrentAppDomain);
147 } 134 }
148 } 135 }
@@ -159,16 +146,20 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
159 { 146 {
160 lock (FreeLock) 147 lock (FreeLock)
161 { 148 {
149 // Check if it is current AppDomain
162 if (CurrentAD.CurrentAppDomain == ad) 150 if (CurrentAD.CurrentAppDomain == ad)
163 { 151 {
152 // Yes - increase
164 CurrentAD.ScriptsWaitingUnload++; 153 CurrentAD.ScriptsWaitingUnload++;
165 return; 154 return;
166 } 155 }
167 156
157 // Lopp through all AppDomains
168 foreach (AppDomainStructure ads in new System.Collections.ArrayList(AppDomains)) 158 foreach (AppDomainStructure ads in new System.Collections.ArrayList(AppDomains))
169 { 159 {
170 if (ads.CurrentAppDomain == ad) 160 if (ads.CurrentAppDomain == ad)
171 { 161 {
162 // Found it - messy code to increase structure
172 AppDomainStructure ads2 = ads; 163 AppDomainStructure ads2 = ads;
173 ads2.ScriptsWaitingUnload++; 164 ads2.ScriptsWaitingUnload++;
174 AppDomains.Remove(ads); 165 AppDomains.Remove(ads);
@@ -178,5 +169,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
178 } // foreach 169 } // foreach
179 } // lock 170 } // lock
180 } 171 }
172
181 } 173 }
182} 174}
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs
index 7334e6f..bfb8913 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs
@@ -9,8 +9,17 @@ using System.Reflection;
9 9
10namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL 10namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
11{ 11{
12 public class LSL_BaseClass : MarshalByRefObject, LSL_BuiltIn_Commands_Interface 12 public class LSL_BaseClass : MarshalByRefObject, LSL_BuiltIn_Commands_Interface, IScript
13 { 13 {
14 private Executor m_Exec;
15 public Executor Exec {
16 get
17 {
18 if (m_Exec == null)
19 m_Exec = new Executor(this);
20 return m_Exec;
21 }
22 }
14 23
15 public LSL_BuiltIn_Commands_Interface m_LSL_Functions; 24 public LSL_BuiltIn_Commands_Interface m_LSL_Functions;
16 25
@@ -48,33 +57,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
48 return; 57 return;
49 } 58 }
50 59
51 public void ExecuteEvent(string FunctionName, object[] args)
52 {
53 //foreach (MemberInfo mi in this.GetType().GetMembers())
54 //{
55 //if (mi.ToString().ToLower().Contains("default"))
56 //{
57 // Console.WriteLine("Member found: " + mi.ToString());
58 //}
59 //}
60
61 Type type = this.GetType();
62
63 Console.WriteLine("ScriptEngine Invoke: \"" + this.State() + "_event_" + FunctionName + "\"");
64
65 try
66 {
67 type.InvokeMember(this.State() + "_event_" + FunctionName, BindingFlags.InvokeMethod, null, this, args);
68 }
69 catch (Exception e)
70 {
71 // TODO: Send to correct place
72 Console.WriteLine("ScriptEngine Exception attempting to executing script function: " + e.ToString());
73 }
74
75
76 }
77
78 60
79 61
80 // 62 //
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/Server_API/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/Server_API/LSL_BuiltIn_Commands.cs
index 297a45c..8982bb6 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/Server_API/LSL_BuiltIn_Commands.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/Server_API/LSL_BuiltIn_Commands.cs
@@ -16,6 +16,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler
16 /// </summary> 16 /// </summary>
17 public class LSL_BuiltIn_Commands: MarshalByRefObject, LSL_BuiltIn_Commands_Interface 17 public class LSL_BuiltIn_Commands: MarshalByRefObject, LSL_BuiltIn_Commands_Interface
18 { 18 {
19
19 private System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); 20 private System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
20 private ScriptManager m_manager; 21 private ScriptManager m_manager;
21 private IScriptHost m_host; 22 private IScriptHost m_host;
@@ -74,7 +75,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler
74 public void llWhisper(int channelID, string text) 75 public void llWhisper(int channelID, string text)
75 { 76 {
76 //Common.SendToDebug("INTERNAL FUNCTION llWhisper(" + channelID + ", \"" + text + "\");"); 77 //Common.SendToDebug("INTERNAL FUNCTION llWhisper(" + channelID + ", \"" + text + "\");");
77 Console.WriteLine("llWhisper Channel " + channelID + ", Text: \"" + text + "\""); 78 //Console.WriteLine("llWhisper Channel " + channelID + ", Text: \"" + text + "\"");
78 //type for whisper is 0 79 //type for whisper is 0
79 World.SimChat(Helpers.StringToField(text), 80 World.SimChat(Helpers.StringToField(text),
80 0, m_host.AbsolutePosition, m_host.Name, m_host.UUID); 81 0, m_host.AbsolutePosition, m_host.Name, m_host.UUID);
@@ -86,7 +87,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler
86 { 87 {
87 //TODO: DO SOMETHING USEFUL HERE 88 //TODO: DO SOMETHING USEFUL HERE
88 //Common.SendToDebug("INTERNAL FUNCTION llSay(" + (int)channelID + ", \"" + (string)text + "\");"); 89 //Common.SendToDebug("INTERNAL FUNCTION llSay(" + (int)channelID + ", \"" + (string)text + "\");");
89 Console.WriteLine("llSay Channel " + channelID + ", Text: \"" + text + "\""); 90 //Console.WriteLine("llSay Channel " + channelID + ", Text: \"" + text + "\"");
90 //type for say is 1 91 //type for say is 1
91 92
92 World.SimChat(Helpers.StringToField(text), 93 World.SimChat(Helpers.StringToField(text),
@@ -95,7 +96,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler
95 96
96 public void llShout(int channelID, string text) 97 public void llShout(int channelID, string text)
97 { 98 {
98 Console.WriteLine("llShout Channel " + channelID + ", Text: \"" + text + "\""); 99 //Console.WriteLine("llShout Channel " + channelID + ", Text: \"" + text + "\"");
99 //type for shout is 2 100 //type for shout is 2
100 World.SimChat(Helpers.StringToField(text), 101 World.SimChat(Helpers.StringToField(text),
101 2, m_host.AbsolutePosition, m_host.Name, m_host.UUID); 102 2, m_host.AbsolutePosition, m_host.Name, m_host.UUID);
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
index c20a8b0..311d32b 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
@@ -101,7 +101,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
101 QueueItemStruct QIS = EventQueue.Dequeue(); 101 QueueItemStruct QIS = EventQueue.Dequeue();
102 //myScriptEngine.m_logger.Verbose("ScriptEngine", "Processing event for ObjectID: " + QIS.ObjectID + ", ScriptID: " + QIS.ScriptID + ", FunctionName: " + QIS.FunctionName); 102 //myScriptEngine.m_logger.Verbose("ScriptEngine", "Processing event for ObjectID: " + QIS.ObjectID + ", ScriptID: " + QIS.ScriptID + ", FunctionName: " + QIS.FunctionName);
103 // TODO: Execute function 103 // TODO: Execute function
104 myScriptEngine.myScriptManager.ExecuteFunction(QIS.ObjectID, QIS.ScriptID, QIS.FunctionName, QIS.param); 104 myScriptEngine.myScriptManager.ExecuteEvent(QIS.ObjectID, QIS.ScriptID, QIS.FunctionName, QIS.param);
105 } 105 }
106 } 106 }
107 } 107 }
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs
index d08fc32..9b8cff0 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs
@@ -72,7 +72,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
72 myEventQueueManager = new EventQueueManager(this); 72 myEventQueueManager = new EventQueueManager(this);
73 myEventManager = new EventManager(this); 73 myEventManager = new EventManager(this);
74 myScriptManager = new ScriptManager(this); 74 myScriptManager = new ScriptManager(this);
75 myAppDomainManager = new AppDomainManager(this); 75 myAppDomainManager = new AppDomainManager();
76 76
77 // Should we iterate the region for scripts that needs starting? 77 // Should we iterate the region for scripts that needs starting?
78 // Or can we assume we are loaded before anything else so we can use proper events? 78 // Or can we assume we are loaded before anything else so we can use proper events?
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
index 602ac9f..926ec74 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
@@ -42,7 +42,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
42 /// <summary> 42 /// <summary>
43 /// Loads scripts 43 /// Loads scripts
44 /// Compiles them if necessary 44 /// Compiles them if necessary
45 /// Execute functions for EventQueueManager 45 /// Execute functions for EventQueueManager (Sends them to script on other AppDomain for execution)
46 /// </summary> 46 /// </summary>
47 [Serializable] 47 [Serializable]
48 public class ScriptManager 48 public class ScriptManager
@@ -182,18 +182,15 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
182 //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName, ObjectID); 182 //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName, ObjectID);
183 OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName, ObjectID); 183 OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName, ObjectID);
184 184
185 //string FullScriptID = ScriptID + "." + ObjectID;
186 // Add it to our temporary active script keeper 185 // Add it to our temporary active script keeper
187 //Scripts.Add(FullScriptID, Script); 186 //Scripts.Add(FullScriptID, Script);
188 SetScript(ObjectID, ScriptID, Script); 187 SetScript(ObjectID, ScriptID, Script);
189 // We need to give (untrusted) assembly a private instance of BuiltIns 188 // We need to give (untrusted) assembly a private instance of BuiltIns
190 // this private copy will contain Read-Only FullScriptID so that it can bring that on to the server whenever needed. 189 // this private copy will contain Read-Only FullScriptID so that it can bring that on to the server whenever needed.
191 //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL_BuiltIn_Commands_Interface LSLB = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL_BuiltIn_Commands_TestImplementation(FullScriptID); 190 OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL_BuiltIn_Commands LSLB = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL_BuiltIn_Commands(this, ObjectID);
192 191
193 // Start the script - giving it BuiltIns 192 // Start the script - giving it BuiltIns
194 //myScriptEngine.m_logger.Verbose("ScriptEngine", "ScriptManager initializing script, handing over private builtin command interface"); 193 Script.Start(LSLB);
195
196 Script.Start(new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL_BuiltIn_Commands(this, ObjectID));
197 194
198 } 195 }
199 catch (Exception e) 196 catch (Exception e)
@@ -210,12 +207,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
210 return FileName; 207 return FileName;
211 } 208 }
212 209
213 //private AppDomain GetFreeAppDomain()
214 //{
215 // // TODO: Find an available AppDomain - if none, create one and add default security
216 // return Thread.GetDomain();
217 //}
218
219 /// <summary> 210 /// <summary>
220 /// Does actual loading and initialization of script Assembly 211 /// Does actual loading and initialization of script Assembly
221 /// </summary> 212 /// </summary>
@@ -239,68 +230,25 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
239 return mbrt; 230 return mbrt;
240 //return (LSL_BaseClass)mbrt; 231 //return (LSL_BaseClass)mbrt;
241 232
242
243
244
245
246
247// //myScriptEngine.m_logger.Verbose("ScriptEngine", "ScriptManager Loading Assembly " + FileName);
248// // Load .Net Assembly (.dll)
249// // Initialize and return it
250
251// // TODO: Add error handling
252// // Script might not follow our rules since users can upload -anything-
253
254// Assembly a;
255// //try
256// //{
257
258
259// // Load to default appdomain (temporary)
260// a = Assembly.LoadFrom(FileName);
261// // Load to specified appdomain
262// // TODO: Insert security
263// //a = FreeAppDomain.Load(FileName);
264// //}
265// //catch (Exception e)
266// //{
267// //}
268
269
270// //foreach (Type _t in a.GetTypes())
271// //{
272// // Console.WriteLine("Type: " + _t.ToString());
273// //}
274
275// Type t;
276// //try
277// //{
278// t = a.GetType("SecondLife.Script", true);
279// //}
280// //catch (Exception e)
281// //{
282// //}
283
284// // Create constructor arguments
285// object[] args = new object[]
286// {
287//// this,
288//// host
289// };
290
291// return (OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass)Activator.CreateInstance(t, args );
292
293
294 } 233 }
295 234
296 internal void ExecuteFunction(IScriptHost ObjectID, string ScriptID, string FunctionName, object[] args) 235 /// <summary>
236 /// Execute a LL-event-function in Script
237 /// </summary>
238 /// <param name="ObjectID">Object the script is located in</param>
239 /// <param name="ScriptID">Script ID</param>
240 /// <param name="FunctionName">Name of function</param>
241 /// <param name="args">Arguments to pass to function</param>
242 internal void ExecuteEvent(IScriptHost ObjectID, string ScriptID, string FunctionName, object[] args)
297 { 243 {
298 244
299 // Execute a function in the script 245 // Execute a function in the script
300 m_scriptEngine.Log.Verbose("ScriptEngine", "Executing Function ObjectID: " + ObjectID + ", ScriptID: " + ScriptID + ", FunctionName: " + FunctionName); 246 m_scriptEngine.Log.Verbose("ScriptEngine", "Executing Function ObjectID: " + ObjectID + ", ScriptID: " + ScriptID + ", FunctionName: " + FunctionName);
301 OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = m_scriptEngine.myScriptManager.GetScript(ObjectID, ScriptID); 247 OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = m_scriptEngine.myScriptManager.GetScript(ObjectID, ScriptID);
302 248
303 Script.ExecuteEvent(FunctionName, args); 249 // Must be done in correct AppDomain, so leaving it up to the script itself
250
251 Script.Exec.ExecuteEvent(FunctionName, args);
304 252
305 //Type type = Script.GetType(); 253 //Type type = Script.GetType();
306 254