ScriptInstance.cs 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  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. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Globalization;
  31. using System.IO;
  32. using System.Reflection;
  33. using System.Runtime.Remoting;
  34. using System.Runtime.Remoting.Lifetime;
  35. using System.Security.Policy;
  36. using System.Text;
  37. using System.Threading;
  38. using System.Xml;
  39. using OpenMetaverse;
  40. using log4net;
  41. using Nini.Config;
  42. using Amib.Threading;
  43. using OpenSim.Framework;
  44. using OpenSim.Region.CoreModules;
  45. using OpenSim.Region.Framework.Scenes;
  46. using OpenSim.Region.Framework.Interfaces;
  47. using OpenSim.Region.ScriptEngine.Shared;
  48. using OpenSim.Region.ScriptEngine.Shared.Api;
  49. using OpenSim.Region.ScriptEngine.Shared.Api.Runtime;
  50. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  51. using OpenSim.Region.ScriptEngine.Shared.CodeTools;
  52. using OpenSim.Region.ScriptEngine.Interfaces;
  53. using System.Diagnostics; //for [DebuggerNonUserCode]
  54. namespace OpenSim.Region.ScriptEngine.Shared.Instance
  55. {
  56. public class ScriptInstance : MarshalByRefObject, IScriptInstance
  57. {
  58. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  59. public bool StatePersistedHere { get { return m_AttachedAvatar == UUID.Zero; } }
  60. /// <summary>
  61. /// The current work item if an event for this script is running or waiting to run,
  62. /// </summary>
  63. /// <remarks>
  64. /// Null if there is no running or waiting to run event. Must be changed only under an EventQueue lock.
  65. /// </remarks>
  66. private IScriptWorkItem m_CurrentWorkItem;
  67. private IScript m_Script;
  68. private DetectParams[] m_DetectParams;
  69. private bool m_TimerQueued;
  70. private DateTime m_EventStart;
  71. private bool m_InEvent;
  72. private string m_assemblyPath;
  73. private string m_dataPath;
  74. private string m_CurrentEvent = String.Empty;
  75. private bool m_InSelfDelete;
  76. private int m_MaxScriptQueue;
  77. private bool m_SaveState;
  78. private int m_ControlEventsInQueue;
  79. private int m_LastControlLevel;
  80. private bool m_CollisionInQueue;
  81. private bool m_StateChangeInProgress;
  82. // The following is for setting a minimum delay between events
  83. private double m_minEventDelay;
  84. private long m_eventDelayTicks;
  85. private long m_nextEventTimeTicks;
  86. private bool m_startOnInit = true;
  87. private UUID m_AttachedAvatar;
  88. private StateSource m_stateSource;
  89. private bool m_postOnRez;
  90. private bool m_startedFromSavedState;
  91. private UUID m_CurrentStateHash;
  92. private UUID m_RegionID;
  93. public int DebugLevel { get; set; }
  94. public WaitHandle CoopWaitHandle { get; private set; }
  95. public Stopwatch ExecutionTimer { get; private set; }
  96. public Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> LineMap { get; set; }
  97. private Dictionary<string,IScriptApi> m_Apis = new Dictionary<string,IScriptApi>();
  98. public Object[] PluginData = new Object[0];
  99. /// <summary>
  100. /// Used by llMinEventDelay to suppress events happening any faster than this speed.
  101. /// This currently restricts all events in one go. Not sure if each event type has
  102. /// its own check so take the simple route first.
  103. /// </summary>
  104. public double MinEventDelay
  105. {
  106. get { return m_minEventDelay; }
  107. set
  108. {
  109. if (value > 0.001)
  110. m_minEventDelay = value;
  111. else
  112. m_minEventDelay = 0.0;
  113. m_eventDelayTicks = (long)(m_minEventDelay * 10000000L);
  114. m_nextEventTimeTicks = DateTime.Now.Ticks;
  115. }
  116. }
  117. public bool Running
  118. {
  119. get { return m_running; }
  120. set
  121. {
  122. m_running = value;
  123. if (m_running)
  124. StayStopped = false;
  125. }
  126. }
  127. private bool m_running;
  128. public bool Suspended
  129. {
  130. get { return m_Suspended; }
  131. set
  132. {
  133. // Need to do this inside a lock in order to avoid races with EventProcessor()
  134. lock (m_Script)
  135. {
  136. bool wasSuspended = m_Suspended;
  137. m_Suspended = value;
  138. if (wasSuspended && !m_Suspended)
  139. {
  140. lock (EventQueue)
  141. {
  142. // Need to place ourselves back in a work item if there are events to process
  143. if (EventQueue.Count > 0 && Running && !ShuttingDown)
  144. m_CurrentWorkItem = Engine.QueueEventHandler(this);
  145. }
  146. }
  147. }
  148. }
  149. }
  150. private bool m_Suspended;
  151. public bool ShuttingDown { get; set; }
  152. public string State { get; set; }
  153. public bool StayStopped { get; set; }
  154. public IScriptEngine Engine { get; private set; }
  155. public UUID AppDomain { get; set; }
  156. public SceneObjectPart Part { get; private set; }
  157. public string PrimName { get; private set; }
  158. public string ScriptName { get; private set; }
  159. public UUID ItemID { get; private set; }
  160. public UUID ObjectID { get { return Part.UUID; } }
  161. public uint LocalID { get { return Part.LocalId; } }
  162. public UUID RootObjectID { get { return Part.ParentGroup.UUID; } }
  163. public uint RootLocalID { get { return Part.ParentGroup.LocalId; } }
  164. public UUID AssetID { get; private set; }
  165. public Queue EventQueue { get; private set; }
  166. public long EventsQueued
  167. {
  168. get
  169. {
  170. lock (EventQueue)
  171. return EventQueue.Count;
  172. }
  173. }
  174. public long EventsProcessed { get; private set; }
  175. public int StartParam { get; set; }
  176. public TaskInventoryItem ScriptTask { get; private set; }
  177. public DateTime TimeStarted { get; private set; }
  178. public MetricsCollectorTime ExecutionTime { get; private set; }
  179. private static readonly int MeasurementWindow = 30 * 1000; // show the *recent* time used by the script, to find currently active scripts
  180. private bool m_coopTermination;
  181. private EventWaitHandle m_coopSleepHandle;
  182. public void ClearQueue()
  183. {
  184. m_TimerQueued = false;
  185. m_StateChangeInProgress = false;
  186. EventQueue.Clear();
  187. }
  188. public ScriptInstance(
  189. IScriptEngine engine, SceneObjectPart part, TaskInventoryItem item,
  190. int startParam, bool postOnRez,
  191. int maxScriptQueue)
  192. {
  193. State = "default";
  194. EventQueue = new Queue(32);
  195. ExecutionTimer = new Stopwatch();
  196. Engine = engine;
  197. Part = part;
  198. ScriptTask = item;
  199. // This is currently only here to allow regression tests to get away without specifying any inventory
  200. // item when they are testing script logic that doesn't require an item.
  201. if (ScriptTask != null)
  202. {
  203. ScriptName = ScriptTask.Name;
  204. ItemID = ScriptTask.ItemID;
  205. AssetID = ScriptTask.AssetID;
  206. }
  207. PrimName = part.ParentGroup.Name;
  208. StartParam = startParam;
  209. m_MaxScriptQueue = maxScriptQueue;
  210. m_postOnRez = postOnRez;
  211. m_AttachedAvatar = part.ParentGroup.AttachedAvatar;
  212. m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID;
  213. m_SaveState = StatePersistedHere;
  214. ExecutionTime = new MetricsCollectorTime(MeasurementWindow, 10);
  215. // m_log.DebugFormat(
  216. // "[SCRIPT INSTANCE]: Instantiated script instance {0} (id {1}) in part {2} (id {3}) in object {4} attached avatar {5} in {6}",
  217. // ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, m_AttachedAvatar, Engine.World.Name);
  218. }
  219. /// <summary>
  220. /// Load the script from an assembly into an AppDomain.
  221. /// </summary>
  222. /// <param name='dom'></param>
  223. /// <param name='assembly'></param>
  224. /// <param name='dataPath'>
  225. /// Path for all script associated data (state, etc.). In a multi-region set up
  226. /// with all scripts loading into the same AppDomain this may not be the same place as the DLL itself.
  227. /// </param>
  228. /// <param name='stateSource'></param>
  229. /// <returns>false if load failed, true if suceeded</returns>
  230. public bool Load(
  231. IScript script, EventWaitHandle coopSleepHandle, string assemblyPath,
  232. string dataPath, StateSource stateSource, bool coopTermination)
  233. {
  234. m_Script = script;
  235. m_coopSleepHandle = coopSleepHandle;
  236. m_assemblyPath = assemblyPath;
  237. m_dataPath = dataPath;
  238. m_stateSource = stateSource;
  239. m_coopTermination = coopTermination;
  240. if (m_coopTermination)
  241. CoopWaitHandle = coopSleepHandle;
  242. else
  243. CoopWaitHandle = null;
  244. ApiManager am = new ApiManager();
  245. foreach (string api in am.GetApis())
  246. {
  247. m_Apis[api] = am.CreateApi(api);
  248. m_Apis[api].Initialize(Engine, Part, ScriptTask);
  249. }
  250. try
  251. {
  252. foreach (KeyValuePair<string,IScriptApi> kv in m_Apis)
  253. {
  254. m_Script.InitApi(kv.Key, kv.Value);
  255. }
  256. // // m_log.Debug("[Script] Script instance created");
  257. Part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State));
  258. }
  259. catch (Exception e)
  260. {
  261. m_log.ErrorFormat(
  262. "[SCRIPT INSTANCE]: Not starting script {0} (id {1}) in part {2} (id {3}) in object {4} in {5}. Error initializing script instance. Exception {6}{7}",
  263. ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, Engine.World.Name, e.Message, e.StackTrace);
  264. return false;
  265. }
  266. // For attachments, XEngine saves the state into a .state file when XEngine.SetXMLState() is called.
  267. string savedState = Path.Combine(m_dataPath, ItemID.ToString() + ".state");
  268. if (File.Exists(savedState))
  269. {
  270. // m_log.DebugFormat(
  271. // "[SCRIPT INSTANCE]: Found state for script {0} for {1} ({2}) at {3} in {4}",
  272. // ItemID, savedState, Part.Name, Part.ParentGroup.Name, Part.ParentGroup.Scene.Name);
  273. string xml = String.Empty;
  274. try
  275. {
  276. FileInfo fi = new FileInfo(savedState);
  277. int size = (int)fi.Length;
  278. if (size < 512000)
  279. {
  280. using (FileStream fs = File.Open(savedState,
  281. FileMode.Open, FileAccess.Read, FileShare.None))
  282. {
  283. Byte[] data = new Byte[size];
  284. fs.Read(data, 0, size);
  285. xml = Encoding.UTF8.GetString(data);
  286. ScriptSerializer.Deserialize(xml, this);
  287. AsyncCommandManager.CreateFromData(Engine,
  288. LocalID, ItemID, ObjectID,
  289. PluginData);
  290. // m_log.DebugFormat("[Script] Successfully retrieved state for script {0}.{1}", PrimName, m_ScriptName);
  291. Part.SetScriptEvents(ItemID,
  292. (int)m_Script.GetStateEventFlags(State));
  293. if (!Running)
  294. m_startOnInit = false;
  295. Running = false;
  296. // we get new rez events on sim restart, too
  297. // but if there is state, then we fire the change
  298. // event
  299. // We loaded state, don't force a re-save
  300. m_SaveState = false;
  301. m_startedFromSavedState = true;
  302. }
  303. // If this script is in an attachment then we no longer need the state file.
  304. if (!StatePersistedHere)
  305. RemoveState();
  306. }
  307. // else
  308. // {
  309. // m_log.WarnFormat(
  310. // "[SCRIPT INSTANCE]: Not starting script {0} (id {1}) in part {2} (id {3}) in object {4} in {5}. Unable to load script state file {6}. Memory limit exceeded.",
  311. // ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, Engine.World.Name, savedState);
  312. // }
  313. }
  314. catch (Exception e)
  315. {
  316. m_log.ErrorFormat(
  317. "[SCRIPT INSTANCE]: Not starting script {0} (id {1}) in part {2} (id {3}) in object {4} in {5}. Unable to load script state file {6}. XML is {7}. Exception {8}{9}",
  318. ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, Engine.World.Name, savedState, xml, e.Message, e.StackTrace);
  319. }
  320. }
  321. // else
  322. // {
  323. // m_log.DebugFormat(
  324. // "[SCRIPT INSTANCE]: Did not find state for script {0} for {1} ({2}) at {3} in {4}",
  325. // ItemID, savedState, Part.Name, Part.ParentGroup.Name, Part.ParentGroup.Scene.Name);
  326. // }
  327. return true;
  328. }
  329. public void Init()
  330. {
  331. if (ShuttingDown)
  332. return;
  333. if (m_startedFromSavedState)
  334. {
  335. if (m_startOnInit)
  336. Start();
  337. if (m_postOnRez)
  338. {
  339. PostEvent(new EventParams("on_rez",
  340. new Object[] {new LSL_Types.LSLInteger(StartParam)}, new DetectParams[0]));
  341. }
  342. if (m_stateSource == StateSource.AttachedRez)
  343. {
  344. PostEvent(new EventParams("attach",
  345. new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0]));
  346. }
  347. else if (m_stateSource == StateSource.RegionStart)
  348. {
  349. //m_log.Debug("[Script] Posted changed(CHANGED_REGION_RESTART) to script");
  350. PostEvent(new EventParams("changed",
  351. new Object[] { new LSL_Types.LSLInteger((int)Changed.REGION_RESTART) }, new DetectParams[0]));
  352. }
  353. else if (m_stateSource == StateSource.PrimCrossing || m_stateSource == StateSource.Teleporting)
  354. {
  355. // CHANGED_REGION
  356. PostEvent(new EventParams("changed",
  357. new Object[] { new LSL_Types.LSLInteger((int)Changed.REGION) }, new DetectParams[0]));
  358. // CHANGED_TELEPORT
  359. if (m_stateSource == StateSource.Teleporting)
  360. PostEvent(new EventParams("changed",
  361. new Object[] { new LSL_Types.LSLInteger((int)Changed.TELEPORT) }, new DetectParams[0]));
  362. }
  363. }
  364. else
  365. {
  366. if (m_startOnInit)
  367. Start();
  368. PostEvent(new EventParams("state_entry",
  369. new Object[0], new DetectParams[0]));
  370. if (m_postOnRez)
  371. {
  372. PostEvent(new EventParams("on_rez",
  373. new Object[] {new LSL_Types.LSLInteger(StartParam)}, new DetectParams[0]));
  374. }
  375. if (m_stateSource == StateSource.AttachedRez)
  376. {
  377. PostEvent(new EventParams("attach",
  378. new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0]));
  379. }
  380. }
  381. }
  382. private void ReleaseControls()
  383. {
  384. SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
  385. if (part != null)
  386. {
  387. int permsMask;
  388. UUID permsGranter;
  389. part.TaskInventory.LockItemsForRead(true);
  390. if (!part.TaskInventory.ContainsKey(ItemID))
  391. {
  392. part.TaskInventory.LockItemsForRead(false);
  393. return;
  394. }
  395. permsGranter = part.TaskInventory[ItemID].PermsGranter;
  396. permsMask = part.TaskInventory[ItemID].PermsMask;
  397. part.TaskInventory.LockItemsForRead(false);
  398. if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
  399. {
  400. ScenePresence presence = Engine.World.GetScenePresence(permsGranter);
  401. if (presence != null)
  402. presence.UnRegisterControlEventsToScript(LocalID, ItemID);
  403. }
  404. }
  405. }
  406. public void DestroyScriptInstance()
  407. {
  408. ReleaseControls();
  409. AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
  410. }
  411. public void RemoveState()
  412. {
  413. string savedState = Path.Combine(m_dataPath, ItemID.ToString() + ".state");
  414. // m_log.DebugFormat(
  415. // "[SCRIPT INSTANCE]: Deleting state {0} for script {1} (id {2}) in part {3} (id {4}) in object {5} in {6}.",
  416. // savedState, ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, Engine.World.Name);
  417. try
  418. {
  419. File.Delete(savedState);
  420. }
  421. catch (Exception e)
  422. {
  423. m_log.Warn(
  424. string.Format(
  425. "[SCRIPT INSTANCE]: Could not delete script state {0} for script {1} (id {2}) in part {3} (id {4}) in object {5} in {6}. Exception ",
  426. savedState, ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, Engine.World.Name),
  427. e);
  428. }
  429. }
  430. public void VarDump(Dictionary<string, object> vars)
  431. {
  432. // m_log.Info("Variable dump for script "+ ItemID.ToString());
  433. // foreach (KeyValuePair<string, object> v in vars)
  434. // {
  435. // m_log.Info("Variable: "+v.Key+" = "+v.Value.ToString());
  436. // }
  437. }
  438. public void Start()
  439. {
  440. lock (EventQueue)
  441. {
  442. if (Running)
  443. return;
  444. Running = true;
  445. TimeStarted = DateTime.Now;
  446. // Note: we don't reset ExecutionTime. The reason is that runaway scripts are stopped and restarted
  447. // automatically, and we *do* want to show that they had high CPU in that case. If we had reset
  448. // ExecutionTime here then runaway scripts, paradoxically, would never show up in the "Top Scripts" dialog.
  449. if (EventQueue.Count > 0)
  450. {
  451. if (m_CurrentWorkItem == null)
  452. m_CurrentWorkItem = Engine.QueueEventHandler(this);
  453. // else
  454. // m_log.Error("[Script] Tried to start a script that was already queued");
  455. }
  456. }
  457. }
  458. public bool Stop(int timeout, bool clearEventQueue = false)
  459. {
  460. if (DebugLevel >= 1)
  461. m_log.DebugFormat(
  462. "[SCRIPT INSTANCE]: Stopping script {0} {1} in {2} {3} with timeout {4} {5} {6}",
  463. ScriptName, ItemID, PrimName, ObjectID, timeout, m_InSelfDelete, DateTime.Now.Ticks);
  464. IScriptWorkItem workItem;
  465. lock (EventQueue)
  466. {
  467. if (clearEventQueue)
  468. ClearQueue();
  469. if (!Running)
  470. return true;
  471. // If we're not running or waiting to run an event then we can safely stop.
  472. if (m_CurrentWorkItem == null)
  473. {
  474. Running = false;
  475. return true;
  476. }
  477. // If we are waiting to run an event then we can try to cancel it.
  478. if (m_CurrentWorkItem.Cancel())
  479. {
  480. m_CurrentWorkItem = null;
  481. Running = false;
  482. return true;
  483. }
  484. workItem = m_CurrentWorkItem;
  485. Running = false;
  486. }
  487. // Wait for the current event to complete.
  488. if (!m_InSelfDelete)
  489. {
  490. if (!m_coopTermination)
  491. {
  492. // If we're not co-operative terminating then try and wait for the event to complete before stopping
  493. if (workItem.Wait(timeout))
  494. return true;
  495. }
  496. else
  497. {
  498. if (DebugLevel >= 1)
  499. m_log.DebugFormat(
  500. "[SCRIPT INSTANCE]: Co-operatively stopping script {0} {1} in {2} {3}",
  501. ScriptName, ItemID, PrimName, ObjectID);
  502. // This will terminate the event on next handle check by the script.
  503. m_coopSleepHandle.Set();
  504. // For now, we will wait forever since the event should always cleanly terminate once LSL loop
  505. // checking is implemented. May want to allow a shorter timeout option later.
  506. if (workItem.Wait(Timeout.Infinite))
  507. {
  508. if (DebugLevel >= 1)
  509. m_log.DebugFormat(
  510. "[SCRIPT INSTANCE]: Co-operatively stopped script {0} {1} in {2} {3}",
  511. ScriptName, ItemID, PrimName, ObjectID);
  512. return true;
  513. }
  514. }
  515. }
  516. lock (EventQueue)
  517. {
  518. workItem = m_CurrentWorkItem;
  519. }
  520. if (workItem == null)
  521. return true;
  522. // If the event still hasn't stopped and we the stop isn't the result of script or object removal, then
  523. // forcibly abort the work item (this aborts the underlying thread).
  524. // Co-operative termination should never reach this point.
  525. if (!m_InSelfDelete)
  526. {
  527. m_log.DebugFormat(
  528. "[SCRIPT INSTANCE]: Aborting unstopped script {0} {1} in prim {2}, localID {3}, timeout was {4} ms",
  529. ScriptName, ItemID, PrimName, LocalID, timeout);
  530. workItem.Abort();
  531. }
  532. lock (EventQueue)
  533. {
  534. m_CurrentWorkItem = null;
  535. }
  536. return true;
  537. }
  538. [DebuggerNonUserCode] //Prevents the debugger from farting in this function
  539. public void SetState(string state)
  540. {
  541. if (state == State)
  542. return;
  543. EventParams lastTimerEv = null;
  544. lock (EventQueue)
  545. {
  546. // Remove all queued events, remembering the last timer event
  547. while (EventQueue.Count > 0)
  548. {
  549. EventParams tempv = (EventParams)EventQueue.Dequeue();
  550. if (tempv.EventName == "timer") lastTimerEv = tempv;
  551. }
  552. // Post events
  553. PostEvent(new EventParams("state_exit", new Object[0],
  554. new DetectParams[0]));
  555. PostEvent(new EventParams("state", new Object[] { state },
  556. new DetectParams[0]));
  557. PostEvent(new EventParams("state_entry", new Object[0],
  558. new DetectParams[0]));
  559. // Requeue the timer event after the state changing events
  560. if (lastTimerEv != null) EventQueue.Enqueue(lastTimerEv);
  561. // This will stop events from being queued and processed
  562. // until the new state is started
  563. m_StateChangeInProgress = true;
  564. }
  565. throw new EventAbortException();
  566. }
  567. /// <summary>
  568. /// Post an event to this script instance.
  569. /// </summary>
  570. /// <remarks>
  571. /// The request to run the event is sent
  572. /// </remarks>
  573. /// <param name="data"></param>
  574. public void PostEvent(EventParams data)
  575. {
  576. // m_log.DebugFormat("[Script] Posted event {2} in state {3} to {0}.{1}",
  577. // PrimName, ScriptName, data.EventName, State);
  578. if (!Running)
  579. return;
  580. // If min event delay is set then ignore any events untill the time has expired
  581. // This currently only allows 1 event of any type in the given time period.
  582. // This may need extending to allow for a time for each individual event type.
  583. if (m_eventDelayTicks != 0 &&
  584. data.EventName != "state" && data.EventName != "state_entry" && data.EventName != "state_exit"
  585. && data.EventName != "run_time_permissions" && data.EventName != "http_request" && data.EventName != "link_message")
  586. {
  587. if (DateTime.Now.Ticks < m_nextEventTimeTicks)
  588. return;
  589. m_nextEventTimeTicks = DateTime.Now.Ticks + m_eventDelayTicks;
  590. }
  591. lock (EventQueue)
  592. {
  593. // The only events that persist across state changes are timers
  594. if (m_StateChangeInProgress && data.EventName != "timer")
  595. return;
  596. if (EventQueue.Count >= m_MaxScriptQueue)
  597. return;
  598. if (data.EventName == "timer")
  599. {
  600. if (m_TimerQueued)
  601. return;
  602. m_TimerQueued = true;
  603. }
  604. if (data.EventName == "control")
  605. {
  606. int held = ((LSL_Types.LSLInteger)data.Params[1]).value;
  607. // int changed = ((LSL_Types.LSLInteger)data.Params[2]).value;
  608. // If the last message was a 0 (nothing held)
  609. // and this one is also nothing held, drop it
  610. //
  611. if (m_LastControlLevel == held && held == 0)
  612. return;
  613. // If there is one or more queued, then queue
  614. // only changed ones, else queue unconditionally
  615. //
  616. if (m_ControlEventsInQueue > 0)
  617. {
  618. if (m_LastControlLevel == held)
  619. return;
  620. }
  621. m_LastControlLevel = held;
  622. m_ControlEventsInQueue++;
  623. }
  624. if (data.EventName == "collision")
  625. {
  626. if (m_CollisionInQueue)
  627. return;
  628. if (data.DetectParams == null)
  629. return;
  630. m_CollisionInQueue = true;
  631. }
  632. EventQueue.Enqueue(data);
  633. if (m_CurrentWorkItem == null)
  634. {
  635. m_CurrentWorkItem = Engine.QueueEventHandler(this);
  636. }
  637. }
  638. }
  639. /// <summary>
  640. /// Process the next event queued for this script
  641. /// </summary>
  642. /// <returns></returns>
  643. public object EventProcessor()
  644. {
  645. // We check here as the thread stopping this instance from running may itself hold the m_Script lock.
  646. if (!Running)
  647. return 0;
  648. lock (m_Script)
  649. {
  650. // m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName);
  651. if (Suspended)
  652. return 0;
  653. ExecutionTimer.Restart();
  654. try
  655. {
  656. return EventProcessorInt();
  657. }
  658. finally
  659. {
  660. ExecutionTimer.Stop();
  661. ExecutionTime.AddSample(ExecutionTimer);
  662. Part.ParentGroup.Scene.AddScriptExecutionTime(ExecutionTimer.ElapsedTicks);
  663. }
  664. }
  665. }
  666. private object EventProcessorInt()
  667. {
  668. EventParams data = null;
  669. lock (EventQueue)
  670. {
  671. data = (EventParams)EventQueue.Dequeue();
  672. if (data == null)
  673. {
  674. // check if a null event was enqueued or if its really empty
  675. if (EventQueue.Count > 0 && Running && !ShuttingDown && !m_InSelfDelete)
  676. {
  677. m_CurrentWorkItem = Engine.QueueEventHandler(this);
  678. }
  679. else
  680. {
  681. m_CurrentWorkItem = null;
  682. }
  683. return 0;
  684. }
  685. if (data.EventName == "timer")
  686. m_TimerQueued = false;
  687. if (data.EventName == "control")
  688. {
  689. if (m_ControlEventsInQueue > 0)
  690. m_ControlEventsInQueue--;
  691. }
  692. if (data.EventName == "collision")
  693. m_CollisionInQueue = false;
  694. }
  695. if (DebugLevel >= 2)
  696. m_log.DebugFormat(
  697. "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}",
  698. data.EventName,
  699. ScriptName,
  700. Part.Name,
  701. Part.LocalId,
  702. Part.ParentGroup.Name,
  703. Part.ParentGroup.UUID,
  704. Part.AbsolutePosition,
  705. Part.ParentGroup.Scene.Name);
  706. m_DetectParams = data.DetectParams;
  707. if (data.EventName == "state") // Hardcoded state change
  708. {
  709. State = data.Params[0].ToString();
  710. if (DebugLevel >= 1)
  711. m_log.DebugFormat(
  712. "[SCRIPT INSTANCE]: Changing state to {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}",
  713. State,
  714. ScriptName,
  715. Part.Name,
  716. Part.LocalId,
  717. Part.ParentGroup.Name,
  718. Part.ParentGroup.UUID,
  719. Part.AbsolutePosition,
  720. Part.ParentGroup.Scene.Name);
  721. AsyncCommandManager.StateChange(Engine,
  722. LocalID, ItemID);
  723. // we are effectively in the new state now, so we can resume queueing
  724. // and processing other non-timer events
  725. m_StateChangeInProgress = false;
  726. Part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State));
  727. }
  728. else
  729. {
  730. Exception e = null;
  731. if (Engine.World.PipeEventsForScript(LocalID) ||
  732. data.EventName == "control") // Don't freeze avies!
  733. {
  734. // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}",
  735. // PrimName, ScriptName, data.EventName, State);
  736. try
  737. {
  738. m_CurrentEvent = data.EventName;
  739. m_EventStart = DateTime.UtcNow;
  740. m_InEvent = true;
  741. try
  742. {
  743. m_Script.ExecuteEvent(State, data.EventName, data.Params);
  744. }
  745. finally
  746. {
  747. m_InEvent = false;
  748. m_CurrentEvent = String.Empty;
  749. lock (EventQueue)
  750. m_CurrentWorkItem = null; // no longer in a event that can be canceled
  751. }
  752. if (m_SaveState)
  753. {
  754. // This will be the very first event we deliver
  755. // (state_entry) in default state
  756. //
  757. SaveState();
  758. m_SaveState = false;
  759. }
  760. }
  761. catch (Exception exx)
  762. {
  763. e = exx;
  764. }
  765. if(e != null)
  766. {
  767. // m_log.DebugFormat(
  768. // "[SCRIPT] Exception in script {0} {1}: {2}{3}",
  769. // ScriptName, ItemID, e.Message, e.StackTrace);
  770. if ((!(e is TargetInvocationException)
  771. || (!(e.InnerException is SelfDeleteException)
  772. && !(e.InnerException is ScriptDeleteException)
  773. && !(e.InnerException is ScriptCoopStopException)))
  774. && !(e is ThreadAbortException))
  775. {
  776. try
  777. {
  778. if(e.InnerException != null && e.InnerException is ScriptException)
  779. {
  780. string text = e.InnerException.Message +
  781. "(script: " + ScriptName +
  782. " event: " + data.EventName +
  783. " primID:" + Part.UUID.ToString() +
  784. " at " + Part.AbsolutePosition + ")";
  785. if (text.Length > 1000)
  786. text = text.Substring(0, 1000);
  787. Engine.World.SimChat(Utils.StringToBytes(text),
  788. ChatTypeEnum.DebugChannel, 2147483647,
  789. Part.AbsolutePosition,
  790. Part.Name, Part.UUID, false);
  791. m_log.Debug(string.Format(
  792. "[SCRIPT ERROR]: {0} (at event {1}, part {2} {3} at {4} in {5}",
  793. e.InnerException.Message,
  794. data.EventName,
  795. PrimName,
  796. Part.UUID,
  797. Part.AbsolutePosition,
  798. Part.ParentGroup.Scene.Name));
  799. }
  800. else
  801. {
  802. // DISPLAY ERROR INWORLD
  803. string text = FormatException(e);
  804. if (text.Length > 1000)
  805. text = text.Substring(0, 1000);
  806. Engine.World.SimChat(Utils.StringToBytes(text),
  807. ChatTypeEnum.DebugChannel, 2147483647,
  808. Part.AbsolutePosition,
  809. Part.Name, Part.UUID, false);
  810. m_log.Debug(string.Format(
  811. "[SCRIPT ERROR]: Runtime error in script {0} (event {1}), part {2} {3} at {4} in {5} ",
  812. ScriptName,
  813. data.EventName,
  814. PrimName,
  815. Part.UUID,
  816. Part.AbsolutePosition,
  817. Part.ParentGroup.Scene.Name),
  818. e);
  819. }
  820. }
  821. catch (Exception)
  822. {
  823. }
  824. }
  825. else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException))
  826. {
  827. m_InSelfDelete = true;
  828. Engine.World.DeleteSceneObject(Part.ParentGroup, false);
  829. }
  830. else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException))
  831. {
  832. m_InSelfDelete = true;
  833. Part.Inventory.RemoveInventoryItem(ItemID);
  834. }
  835. else if ((e is TargetInvocationException) && (e.InnerException is ScriptCoopStopException))
  836. {
  837. if (DebugLevel >= 1)
  838. m_log.DebugFormat(
  839. "[SCRIPT INSTANCE]: Script {0}.{1} in event {2}, state {3} stopped co-operatively.",
  840. PrimName, ScriptName, data.EventName, State);
  841. }
  842. }
  843. }
  844. }
  845. // If there are more events and we are currently running and not shutting down, then ask the
  846. // script engine to run the next event.
  847. lock (EventQueue)
  848. {
  849. // Increase processed events counter and prevent wrap;
  850. if (++EventsProcessed == 1000000)
  851. EventsProcessed = 100000;
  852. if ((EventsProcessed % 100000) == 0 && DebugLevel > 0)
  853. {
  854. m_log.DebugFormat("[SCRIPT INSTANCE]: Script \"{0}\" (Object \"{1}\" {2} @ {3}.{4}, Item ID {5}, Asset {6}) in event {7}: processed {8:n0} script events",
  855. ScriptTask.Name,
  856. Part.ParentGroup.Name, Part.ParentGroup.UUID, Part.ParentGroup.AbsolutePosition, Part.ParentGroup.Scene.Name,
  857. ScriptTask.ItemID, ScriptTask.AssetID, data.EventName, EventsProcessed);
  858. }
  859. if (EventQueue.Count > 0 && Running && !ShuttingDown && !m_InSelfDelete)
  860. {
  861. m_CurrentWorkItem = Engine.QueueEventHandler(this);
  862. }
  863. else
  864. {
  865. m_CurrentWorkItem = null;
  866. }
  867. }
  868. m_DetectParams = null;
  869. return 0;
  870. }
  871. public int EventTime()
  872. {
  873. if (!m_InEvent)
  874. return 0;
  875. return (DateTime.UtcNow - m_EventStart).Seconds;
  876. }
  877. public void ResetScript(int timeout)
  878. {
  879. if (m_Script == null)
  880. return;
  881. bool running = Running;
  882. RemoveState();
  883. ReleaseControls();
  884. Stop(timeout);
  885. SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
  886. part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
  887. part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
  888. part.CollisionSound = UUID.Zero;
  889. AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
  890. m_TimerQueued = false;
  891. m_StateChangeInProgress = false;
  892. EventQueue.Clear();
  893. m_Script.ResetVars();
  894. StartParam = 0;
  895. State = "default";
  896. part.SetScriptEvents(ItemID,
  897. (int)m_Script.GetStateEventFlags(State));
  898. if (running)
  899. Start();
  900. m_SaveState = StatePersistedHere;
  901. PostEvent(new EventParams("state_entry",
  902. new Object[0], new DetectParams[0]));
  903. }
  904. [DebuggerNonUserCode] //Stops the VS debugger from farting in this function
  905. public void ApiResetScript()
  906. {
  907. // bool running = Running;
  908. RemoveState();
  909. ReleaseControls();
  910. m_Script.ResetVars();
  911. SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
  912. part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
  913. part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
  914. part.CollisionSound = UUID.Zero;
  915. AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
  916. m_TimerQueued = false;
  917. m_StateChangeInProgress = false;
  918. EventQueue.Clear();
  919. m_Script.ResetVars();
  920. string oldState = State;
  921. StartParam = 0;
  922. State = "default";
  923. part.SetScriptEvents(ItemID,
  924. (int)m_Script.GetStateEventFlags(State));
  925. if (m_CurrentEvent != "state_entry" || oldState != "default")
  926. {
  927. m_SaveState = StatePersistedHere;
  928. PostEvent(new EventParams("state_entry",
  929. new Object[0], new DetectParams[0]));
  930. throw new EventAbortException();
  931. }
  932. }
  933. public Dictionary<string, object> GetVars()
  934. {
  935. if (m_Script != null)
  936. return m_Script.GetVars();
  937. else
  938. return new Dictionary<string, object>();
  939. }
  940. public void SetVars(Dictionary<string, object> vars)
  941. {
  942. // foreach (KeyValuePair<string, object> kvp in vars)
  943. // m_log.DebugFormat("[SCRIPT INSTANCE]: Setting var {0}={1}", kvp.Key, kvp.Value);
  944. m_Script.SetVars(vars);
  945. }
  946. public DetectParams GetDetectParams(int idx)
  947. {
  948. if (m_DetectParams == null)
  949. return null;
  950. if (idx < 0 || idx >= m_DetectParams.Length)
  951. return null;
  952. return m_DetectParams[idx];
  953. }
  954. public UUID GetDetectID(int idx)
  955. {
  956. if (m_DetectParams == null)
  957. return UUID.Zero;
  958. if (idx < 0 || idx >= m_DetectParams.Length)
  959. return UUID.Zero;
  960. return m_DetectParams[idx].Key;
  961. }
  962. public void SaveState()
  963. {
  964. if (!Running && !StayStopped)
  965. return;
  966. // We cannot call this inside the EventQueue lock since it will currently take AsyncCommandManager.staticLock.
  967. // This may already be held by AsyncCommandManager.DoOneCmdHandlerPass() which in turn can take EventQueue
  968. // lock via ScriptInstance.PostEvent().
  969. PluginData = AsyncCommandManager.GetSerializationData(Engine, ItemID);
  970. // We need to lock here to avoid any race with a thread that is removing this script.
  971. lock (EventQueue)
  972. {
  973. // Check again to avoid a race with a thread in Stop()
  974. if (!Running && !StayStopped)
  975. return;
  976. // If we're currently in an event, just tell it to save upon return
  977. //
  978. if (m_InEvent)
  979. {
  980. m_SaveState = true;
  981. return;
  982. }
  983. // m_log.DebugFormat(
  984. // "[SCRIPT INSTANCE]: Saving state for script {0} (id {1}) in part {2} (id {3}) in object {4} in {5}",
  985. // ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, Engine.World.Name);
  986. string xml = ScriptSerializer.Serialize(this);
  987. // Compare hash of the state we just just created with the state last written to disk
  988. // If the state is different, update the disk file.
  989. UUID hash = UUID.Parse(Utils.MD5String(xml));
  990. if (hash != m_CurrentStateHash)
  991. {
  992. try
  993. {
  994. using (FileStream fs = File.Create(Path.Combine(m_dataPath, ItemID.ToString() + ".state")))
  995. {
  996. Byte[] buf = Util.UTF8NoBomEncoding.GetBytes(xml);
  997. fs.Write(buf, 0, buf.Length);
  998. }
  999. }
  1000. catch(Exception)
  1001. {
  1002. // m_log.Error("Unable to save xml\n"+e.ToString());
  1003. }
  1004. //if (!File.Exists(Path.Combine(Path.GetDirectoryName(assembly), ItemID.ToString() + ".state")))
  1005. //{
  1006. // throw new Exception("Completed persistence save, but no file was created");
  1007. //}
  1008. m_CurrentStateHash = hash;
  1009. }
  1010. StayStopped = false;
  1011. }
  1012. }
  1013. public IScriptApi GetApi(string name)
  1014. {
  1015. if (m_Apis.ContainsKey(name))
  1016. {
  1017. // m_log.DebugFormat("[SCRIPT INSTANCE]: Found api {0} in {1}@{2}", name, ScriptName, PrimName);
  1018. return m_Apis[name];
  1019. }
  1020. // m_log.DebugFormat("[SCRIPT INSTANCE]: Did not find api {0} in {1}@{2}", name, ScriptName, PrimName);
  1021. return null;
  1022. }
  1023. public override string ToString()
  1024. {
  1025. return String.Format("{0} {1} on {2}", ScriptName, ItemID, PrimName);
  1026. }
  1027. string FormatException(Exception e)
  1028. {
  1029. if (e.InnerException == null) // Not a normal runtime error
  1030. return e.ToString();
  1031. string message = "Runtime error:\n" + e.InnerException.StackTrace;
  1032. string[] lines = message.Split(new char[] {'\n'});
  1033. foreach (string line in lines)
  1034. {
  1035. if (line.Contains("SecondLife.Script"))
  1036. {
  1037. int idx = line.IndexOf(':');
  1038. if (idx != -1)
  1039. {
  1040. string val = line.Substring(idx+1);
  1041. int lineNum = 0;
  1042. if (int.TryParse(val, out lineNum))
  1043. {
  1044. KeyValuePair<int, int> pos =
  1045. Compiler.FindErrorPosition(
  1046. lineNum, 0, LineMap);
  1047. int scriptLine = pos.Key;
  1048. int col = pos.Value;
  1049. if (scriptLine == 0)
  1050. scriptLine++;
  1051. if (col == 0)
  1052. col++;
  1053. message = string.Format("Runtime error:\n" +
  1054. "({0}): {1}", scriptLine - 1,
  1055. e.InnerException.Message);
  1056. return message;
  1057. }
  1058. }
  1059. }
  1060. }
  1061. // m_log.ErrorFormat("Scripting exception:");
  1062. // m_log.ErrorFormat(e.ToString());
  1063. return e.ToString();
  1064. }
  1065. public string GetAssemblyName()
  1066. {
  1067. return m_assemblyPath;
  1068. }
  1069. public string GetXMLState()
  1070. {
  1071. bool run = Running;
  1072. Stop(100);
  1073. Running = run;
  1074. // We should not be doing this, but since we are about to
  1075. // dispose this, it really doesn't make a difference
  1076. // This is meant to work around a Windows only race
  1077. //
  1078. m_InEvent = false;
  1079. // Force an update of the in-memory plugin data
  1080. //
  1081. PluginData = AsyncCommandManager.GetSerializationData(Engine, ItemID);
  1082. return ScriptSerializer.Serialize(this);
  1083. }
  1084. public UUID RegionID
  1085. {
  1086. get { return m_RegionID; }
  1087. }
  1088. public void Suspend()
  1089. {
  1090. Suspended = true;
  1091. }
  1092. public void Resume()
  1093. {
  1094. Suspended = false;
  1095. }
  1096. }
  1097. /// <summary>
  1098. /// Xengine event wait handle.
  1099. /// </summary>
  1100. /// <remarks>
  1101. /// This class exists becase XEngineScriptBase gets a reference to this wait handle. We need to make sure that
  1102. /// when scripts are running in different AppDomains the lease does not expire.
  1103. /// FIXME: Like LSL_Api, etc., this effectively leaks memory since the GC will never collect it. To avoid this,
  1104. /// proper remoting sponsorship needs to be implemented across the board.
  1105. /// </remarks>
  1106. public class XEngineEventWaitHandle : EventWaitHandle
  1107. {
  1108. public XEngineEventWaitHandle(bool initialState, EventResetMode mode) : base(initialState, mode) {}
  1109. public override Object InitializeLifetimeService()
  1110. {
  1111. return null;
  1112. }
  1113. }
  1114. }