aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager_ScriptLoadUnload.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager_ScriptLoadUnload.cs287
1 files changed, 0 insertions, 287 deletions
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager_ScriptLoadUnload.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager_ScriptLoadUnload.cs
deleted file mode 100644
index dd72dbf..0000000
--- a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager_ScriptLoadUnload.cs
+++ /dev/null
@@ -1,287 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Globalization;
31using System.Reflection;
32using System.Text;
33using System.Threading;
34using log4net;
35using OpenMetaverse;
36using OpenSim.Framework;
37using OpenSim.Region.Framework.Scenes;
38using OpenSim.Region.ScriptEngine.Interfaces;
39using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
40using OpenSim.ScriptEngine.Shared;
41
42namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler
43{
44 public partial class ScriptManager
45 {
46 private Queue<LoadUnloadStructure> LUQueue = new Queue<LoadUnloadStructure>();
47 private int LoadUnloadMaxQueueSize = 500;
48 private Object scriptLock = new Object();
49 //private Dictionary<InstanceData, DetectParams[]> detparms = new Dictionary<InstanceData, DetectParams[]>();
50
51 // Load/Unload structure
52
53
54 public void AddScript(ScriptStructure script)
55 {
56 lock (LUQueue)
57 {
58 if ((LUQueue.Count >= LoadUnloadMaxQueueSize))
59 {
60 m_log.ErrorFormat("[{0}] ERROR: Load queue count is at {1} of max {2}. Ignoring load request for script LocalID: {3}, ItemID: {4}.",
61 Name, LUQueue.Count, LoadUnloadMaxQueueSize, script.LocalID, script.ItemID);
62 return;
63 }
64
65 LoadUnloadStructure ls = new LoadUnloadStructure();
66 ls.Script = script;
67 ls.Action = LoadUnloadStructure.LUType.Load;
68 LUQueue.Enqueue(ls);
69 }
70
71 }
72 public void RemoveScript(uint localID, UUID itemID)
73 {
74 LoadUnloadStructure ls = new LoadUnloadStructure();
75
76 // See if we can find script
77 if (!TryGetScript(localID, itemID, ref ls.Script))
78 {
79 // Set manually
80 ls.Script.LocalID = localID;
81 ls.Script.ItemID = itemID;
82 }
83 ls.Script.StartParam = 0;
84
85 ls.Action = LoadUnloadStructure.LUType.Unload;
86 ls.PostOnRez = false;
87
88 lock (LUQueue)
89 {
90 LUQueue.Enqueue(ls);
91 }
92 }
93
94 internal bool DoScriptLoadUnload()
95 {
96 bool ret = false;
97 // if (!m_started)
98 // return;
99
100 lock (LUQueue)
101 {
102 if (LUQueue.Count > 0)
103 {
104 LoadUnloadStructure item = LUQueue.Dequeue();
105 ret = true;
106
107 if (item.Action == LoadUnloadStructure.LUType.Unload)
108 {
109 _StopScript(item.Script.LocalID, item.Script.ItemID);
110 RemoveScript(item.Script.LocalID, item.Script.ItemID);
111 }
112 else if (item.Action == LoadUnloadStructure.LUType.Load)
113 {
114 m_log.DebugFormat("[{0}] Loading script", Name);
115 _StartScript(item);
116 }
117 }
118 }
119 return ret;
120 }
121
122 //public void _StartScript(uint localID, UUID itemID, string Script, int startParam, bool postOnRez)
123 private void _StartScript(LoadUnloadStructure ScriptObject)
124 {
125 m_log.DebugFormat(
126 "[{0}]: ScriptManager StartScript: localID: {1}, itemID: {2}",
127 Name, ScriptObject.Script.LocalID, ScriptObject.Script.ItemID);
128
129 // We will initialize and start the script.
130 // It will be up to the script itself to hook up the correct events.
131
132 SceneObjectPart m_host = ScriptObject.Script.RegionInfo.Scene.GetSceneObjectPart(ScriptObject.Script.LocalID);
133
134 if (null == m_host)
135 {
136 m_log.ErrorFormat(
137 "[{0}]: Could not find scene object part corresponding " +
138 "to localID {1} to start script",
139 Name, ScriptObject.Script.LocalID);
140
141 return;
142 }
143
144 //UUID assetID = UUID.Zero;
145 TaskInventoryItem taskInventoryItem = new TaskInventoryItem();
146 //if (m_host.TaskInventory.TryGetValue(ScriptObject.Script.ItemID, out taskInventoryItem))
147 // assetID = taskInventoryItem.AssetID;
148
149 ScenePresence presence =
150 ScriptObject.Script.RegionInfo.Scene.GetScenePresence(taskInventoryItem.OwnerID);
151
152 CultureInfo USCulture = new CultureInfo("en-US");
153 Thread.CurrentThread.CurrentCulture = USCulture;
154
155 try
156 {
157 //
158 // Compile script to an assembly
159 //
160 //TODO: DEBUG
161 BaseClassFactory.MakeBaseClass(ScriptObject.Script);
162
163 m_log.DebugFormat("[{0}] Compiling script {1}", Name, ScriptObject.Script.Name);
164
165 string fileName = "";
166 try
167 {
168 IScriptCompiler compiler =
169 ScriptObject.Script.RegionInfo.FindCompiler(ScriptObject.Script.ScriptMetaData);
170 //RegionInfoStructure currentRegionInfo = ScriptObject.Script.RegionInfo;
171 fileName = compiler.Compile(ScriptObject.Script.ScriptMetaData,
172 ref ScriptObject.Script.Source);
173 ScriptObject.Script.AssemblyFileName = fileName;
174 }
175 catch (Exception e)
176 {
177 m_log.ErrorFormat("[{0}] Internal error while compiling \"{1}\": {2}", Name, ScriptObject.Script.Name, e.ToString());
178 }
179 m_log.DebugFormat("[{0}] Compiled \"{1}\" to assembly: \"{2}\".", Name, ScriptObject.Script.Name, fileName);
180
181 // Add it to our script memstruct
182 MemAddScript(ScriptObject.Script);
183
184 ScriptAssemblies.IScript CompiledScript;
185 CompiledScript = CurrentRegion.ScriptLoader.LoadScript(ScriptObject.Script);
186 ScriptObject.Script.State = "default";
187 ScriptObject.Script.ScriptObject = CompiledScript;
188 ScriptObject.Script.Disabled = false;
189 ScriptObject.Script.Running = true;
190 //id.LineMap = LSLCompiler.LineMap();
191 //id.Script = CompiledScript;
192 //id.Source = item.Script.Script;
193 //item.StartParam = startParam;
194
195
196
197 // TODO: Fire the first start-event
198 //int eventFlags =
199 // m_scriptEngine.m_ScriptManager.GetStateEventFlags(
200 // localID, itemID);
201
202 //m_host.SetScriptEvents(itemID, eventFlags);
203 ScriptObject.Script.RegionInfo.Executors_Execute(ScriptObject.Script,
204 new EventParams(ScriptObject.Script.LocalID, ScriptObject.Script.ItemID, "state_entry", new object[] { }, new Region.ScriptEngine.Shared.DetectParams[0])
205 );
206
207 if (ScriptObject.PostOnRez)
208 {
209 ScriptObject.Script.RegionInfo.Executors_Execute(ScriptObject.Script,
210 new EventParams(ScriptObject.Script.LocalID, "on_rez", new object[]
211 {new Region.ScriptEngine.Shared.LSL_Types.LSLInteger(ScriptObject.StartParam)
212 }, new Region.ScriptEngine.Shared.DetectParams[0]));
213 }
214 }
215 catch (Exception e) // LEGIT: User Scripting
216 {
217 if (presence != null && (!ScriptObject.PostOnRez))
218 presence.ControllingClient.SendAgentAlertMessage(
219 "Script saved with errors, check debug window!",
220 false);
221 try
222 {
223 // DISPLAY ERROR INWORLD
224 string text = "Error compiling script:\n" +
225 e.Message.ToString();
226 if (text.Length > 1100)
227 text = text.Substring(0, 1099);
228
229 ScriptObject.Script.RegionInfo.Scene.SimChat(Utils.StringToBytes(text),
230 ChatTypeEnum.DebugChannel, 2147483647,
231 m_host.AbsolutePosition, m_host.Name, m_host.UUID,
232 false);
233 }
234 catch (Exception e2) // LEGIT: User Scripting
235 {
236 m_log.Error("[" +
237 Name +
238 "]: Error displaying error in-world: " +
239 e2.ToString());
240 m_log.Error("[" +
241 Name + "]: " +
242 "Errormessage: Error compiling script:\r\n" +
243 e2.Message.ToString());
244 }
245 }
246 }
247
248
249
250 public void _StopScript(uint localID, UUID itemID)
251 {
252 ScriptStructure ss = new ScriptStructure();
253 if (!TryGetScript(localID, itemID, ref ss))
254 return;
255
256 m_log.DebugFormat("[{0}] Unloading script", Name);
257
258 // Stop long command on script
259 //AsyncCommandManager.RemoveScript(ss);
260
261 try
262 {
263 // Get AppDomain
264 // Tell script not to accept new requests
265 ss.Running = false;
266 ss.Disabled = true;
267 //AppDomain ad = ss.AppDomain;
268
269 // Remove from internal structure
270 MemRemoveScript(localID, itemID);
271
272 // TODO: Tell AppDomain that we have stopped script
273
274 }
275 catch (Exception e) // LEGIT: User Scripting
276 {
277 m_log.Error("[" +
278 Name +
279 "]: Exception stopping script localID: " +
280 localID + " LLUID: " + itemID.ToString() +
281 ": " + e.ToString());
282 }
283 }
284
285
286 }
287}