/** * @brief Clean up stuff. * We specifically leave m_DescName intact for 'xmr ls' command. */ public void Dispose() { /* * Tell script stop executing next time it calls CheckRun(). */ suspendOnCheckRunHold = true; /* * Don't send us any more events. */ lock (m_RunLock) { if (m_Part != null) { m_Part.RemoveScriptEvents(m_ItemID); AsyncCommandManager.RemoveScript(m_Engine, m_LocalID, m_ItemID); m_Part = null; } } /* * Let script methods get garbage collected if no one else is using * them. */ DecObjCodeRefCount(); }
/** * @brief The script is executing a 'state <newState>;' command. * Tell outer layers to cancel any event triggers, like llListen(), * then tell outer layers which events the new state has handlers for. * We also clear the event queue as per http://wiki.secondlife.com/wiki/State */ public override void StateChange() { /* * Cancel any llListen()s etc. * But llSetTimerEvent() should persist. */ object[] timers = m_XMRLSLApi.acm.TimerPlugin.GetSerializationData(m_ItemID); AsyncCommandManager.RemoveScript(m_Engine, m_LocalID, m_ItemID); m_XMRLSLApi.acm.TimerPlugin.CreateFromData(m_LocalID, m_ItemID, UUID.Zero, timers); /* * Tell whoever cares which event handlers the new state has. */ m_Part.SetScriptEvents(m_ItemID, GetStateEventFlags(stateCode)); /* * Clear out any old events from the queue. */ lock (m_QueueLock) { m_EventQueue.Clear(); for (int i = m_EventCounts.Length; --i >= 0;) { m_EventCounts[i] = 0; } } }
/** * @brief The script called llResetScript() while it was running and * has suspended. We want to reset the script to a never-has- * ever-run-before state. * * Caller must have m_RunLock locked so we know script isn't * running. */ private void ResetLocked(string from) { m_RunOnePhase = "ResetLocked: releasing controls"; ReleaseControlsOrPermissions(true); m_Part.CollisionSound = UUID.Zero; if (m_XMRLSLApi != null) { m_XMRLSLApi.llResetTime(); } m_RunOnePhase = "ResetLocked: removing script"; IUrlModule urlModule = m_Engine.World.RequestModuleInterface <IUrlModule>(); if (urlModule != null) { urlModule.ScriptRemoved(m_ItemID); } AsyncCommandManager.RemoveScript(m_Engine, m_LocalID, m_ItemID); m_RunOnePhase = "ResetLocked: clearing current event"; this.eventCode = ScriptEventCode.None; // not processing an event m_DetectParams = null; // not processing an event m_SleepUntil = DateTime.MinValue; // not doing llSleep() m_ResetCount++; // has been reset once more m_localsHeapUsed = 0; m_arraysHeapUsed = 0; glblVars.Clear(); // Tell next call to 'default state_entry()' to reset all global // vars to their initial values. doGblInit = true; // Throw away all its stack frames. // If the script is resetting itself, there shouldn't be any stack frames. // If the script is being reset by something else, we throw them away cuz we want to start from the beginning of an event handler. stackFrames = null; // Set script to 'default' state and queue call to its // 'state_entry()' event handler. m_RunOnePhase = "ResetLocked: posting default:state_entry() event"; stateCode = 0; m_Part.RemoveScriptTargets(m_ItemID); m_Part.SetScriptEvents(m_ItemID, GetStateEventFlags(0)); PostEvent(new EventParams("state_entry", zeroObjectArray, zeroDetectParams)); // Tell CheckRun() to let script run. suspendOnCheckRunHold = false; suspendOnCheckRunTemp = false; m_RunOnePhase = "ResetLocked: reset complete"; }
public void _StopScript(uint localID, UUID itemID) { InstanceData id = GetScript(localID, itemID); if (id == null) { return; } m_log.DebugFormat("[{0}]: Unloading script", m_scriptEngine.ScriptEngineName); // Stop long command on script AsyncCommandManager.RemoveScript(m_scriptEngine, localID, itemID); try { // Get AppDomain // Tell script not to accept new requests id.Running = false; id.Disabled = true; AppDomain ad = id.AppDomain; // Remove from internal structure RemoveScript(localID, itemID); // Tell AppDomain that we have stopped script m_scriptEngine.m_AppDomainManager.StopScript(ad); } catch (Exception e) // LEGIT: User Scripting { m_log.Error("[" + m_scriptEngine.ScriptEngineName + "]: Exception stopping script localID: " + localID + " LLUID: " + itemID.ToString() + ": " + e.ToString()); } }