29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Globalization;
34 using System.Reflection;
35 using System.Security;
36 using System.Security.Policy;
38 using System.Threading;
41 using OpenMetaverse.StructuredData;
46 using OpenSim.Framework;
47 using OpenSim.Framework.Console;
48 using OpenSim.Region.Framework.Scenes;
49 using OpenSim.Region.Framework.Interfaces;
50 using OpenSim.Region.ScriptEngine.Interfaces;
51 using OpenSim.Region.ScriptEngine.Shared;
52 using OpenSim.Region.ScriptEngine.Shared.CodeTools;
53 using OpenSim.Region.ScriptEngine.Shared.Instance;
54 using OpenSim.Region.ScriptEngine.Shared.Api;
55 using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
56 using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
57 using OpenSim.Region.ScriptEngine.XEngine.ScriptBase;
62 namespace OpenSim.
Region.ScriptEngine.XEngine
64 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"XEngine")]
67 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
75 public int DebugLevel {
get; set; }
81 public bool HaveNotifiedLogOfScriptStopMistmatch {
get;
private set; }
84 private int m_MaxScriptQueue;
85 private Scene m_Scene;
86 private IConfig m_ScriptConfig = null;
87 private IConfigSource m_ConfigSource = null;
89 private int m_MinThreads;
90 private int m_MaxThreads;
95 private int m_StartDelay;
101 private bool m_coopTermination;
103 private int m_IdleTimeout;
104 private int m_StackSize;
105 private int m_SleepTime;
106 private int m_SaveTime;
107 private ThreadPriority m_Prio;
108 private bool m_Enabled =
false;
109 private bool m_InitialStartup =
true;
110 private int m_ScriptFailCount;
111 private string m_ScriptErrorMessage;
112 private bool m_AppDomainLoading;
113 private Dictionary<UUID,ArrayList> m_ScriptErrors =
114 new Dictionary<UUID,ArrayList>();
118 #pragma warning disable 414
120 #pragma warning restore 414
122 private int m_EventLimit;
123 private bool m_KillTimedOutScripts;
140 private int m_WaitForEventCompletionOnScriptStop = 1000;
142 private string m_ScriptEnginesPath = null;
144 private ExpiringCache<UUID, bool> m_runFlags =
new ExpiringCache<UUID, bool>();
149 private bool m_SimulatorShuttingDown;
151 private static List<XEngine> m_ScriptEngines =
156 private Dictionary<uint, List<UUID> > m_PrimObjects =
157 new Dictionary<uint, List<UUID> >();
161 private Dictionary<UUID, IScriptInstance> m_Scripts =
162 new Dictionary<UUID, IScriptInstance>();
166 private Dictionary<UUID, string> m_Assemblies =
167 new Dictionary<UUID, string>();
169 private Dictionary<string, int> m_AddingAssemblies =
170 new Dictionary<string, int>();
174 private Dictionary<UUID, AppDomain> m_AppDomains =
175 new Dictionary<UUID, AppDomain>();
179 private Dictionary<UUID, List<UUID> > m_DomainScripts =
180 new Dictionary<UUID, List<UUID> >();
183 IWorkItemResult m_CurrentCompile = null;
184 private Dictionary<UUID, int> m_CompileDict =
new Dictionary<UUID, int>();
188 public string ScriptEngineName
190 get {
return "XEngine"; }
193 public string ScriptClassName {
get;
private set; }
195 public string ScriptBaseClassName {
get;
private set; }
197 public ParameterInfo[] ScriptBaseClassParameters {
get;
private set; }
199 public string[] ScriptReferencedAssemblies {
get;
private set; }
203 get {
return m_Scene; }
206 public static List<XEngine> ScriptEngines
208 get {
return m_ScriptEngines; }
223 public IConfig Config
225 get {
return m_ScriptConfig; }
228 public string ScriptEnginePath
230 get {
return m_ScriptEnginesPath; }
233 public IConfigSource ConfigSource
235 get {
return m_ConfigSource; }
250 if (configSource.Configs[
"XEngine"] == null)
253 m_ScriptConfig = configSource.Configs[
"XEngine"];
254 m_ConfigSource = configSource;
256 string rawScriptStopStrategy = m_ScriptConfig.GetString(
"ScriptStopStrategy",
"co-op");
258 m_log.InfoFormat(
"[XEngine]: Script stop strategy is {0}", rawScriptStopStrategy);
260 if (rawScriptStopStrategy ==
"co-op")
262 m_coopTermination =
true;
263 ScriptClassName =
"XEngineScript";
265 ScriptBaseClassParameters = typeof(
XEngineScriptBase).GetConstructor(
new Type[] { typeof(WaitHandle) }).GetParameters();
266 ScriptReferencedAssemblies =
new string[] { Path.GetFileName(typeof(
XEngineScriptBase).Assembly.Location) };
270 ScriptClassName =
"Script";
279 if (m_ScriptConfig == null)
282 m_ScriptFailCount = 0;
283 m_ScriptErrorMessage = String.Empty;
285 m_Enabled = m_ScriptConfig.GetBoolean(
"Enabled",
true);
290 AppDomain.CurrentDomain.AssemblyResolve +=
294 m_log.InfoFormat(
"[XEngine]: Initializing scripts in region {0}", m_Scene.RegionInfo.RegionName);
296 m_MinThreads = m_ScriptConfig.GetInt(
"MinThreads", 2);
297 m_MaxThreads = m_ScriptConfig.GetInt(
"MaxThreads", 100);
298 m_IdleTimeout = m_ScriptConfig.GetInt(
"IdleTimeout", 60);
299 string priority = m_ScriptConfig.GetString(
"Priority",
"BelowNormal");
300 m_StartDelay = m_ScriptConfig.GetInt(
"StartDelay", 15000);
301 m_MaxScriptQueue = m_ScriptConfig.GetInt(
"MaxScriptEventQueue",300);
302 m_StackSize = m_ScriptConfig.GetInt(
"ThreadStackSize", 262144);
303 m_SleepTime = m_ScriptConfig.GetInt(
"MaintenanceInterval", 10) * 1000;
304 m_AppDomainLoading = m_ScriptConfig.GetBoolean(
"AppDomainLoading",
true);
306 m_EventLimit = m_ScriptConfig.GetInt(
"EventLimit", 30);
307 m_KillTimedOutScripts = m_ScriptConfig.GetBoolean(
"KillTimedOutScripts",
false);
308 m_SaveTime = m_ScriptConfig.GetInt(
"SaveInterval", 120) * 1000;
309 m_WaitForEventCompletionOnScriptStop
310 = m_ScriptConfig.GetInt(
"WaitForEventCompletionOnScriptStop", m_WaitForEventCompletionOnScriptStop);
312 m_ScriptEnginesPath = m_ScriptConfig.GetString(
"ScriptEnginesPath",
"ScriptEngines");
314 m_Prio = ThreadPriority.BelowNormal;
318 m_Prio = ThreadPriority.Lowest;
321 m_Prio = ThreadPriority.BelowNormal;
324 m_Prio = ThreadPriority.Normal;
327 m_Prio = ThreadPriority.AboveNormal;
330 m_Prio = ThreadPriority.Highest;
333 m_log.ErrorFormat(
"[XEngine] Invalid thread priority: '{0}'. Assuming BelowNormal", priority);
337 lock (m_ScriptEngines)
339 m_ScriptEngines.Add(
this);
344 m_Scene.EventManager.OnRezScript += OnRezScript;
348 SetupEngine(m_MinThreads, m_MaxThreads, m_IdleTimeout, m_Prio,
349 m_MaxScriptQueue, m_StackSize);
353 m_XmlRpcRouter = m_Scene.RequestModuleInterface<
IXmlRpcRouter>();
354 if (m_XmlRpcRouter != null)
361 m_consoleCommands.RegisterCommands();
363 MainConsole.Instance.Commands.AddCommand(
364 "Scripts",
false,
"xengine status",
"xengine status",
"Show status information",
365 "Show status information on the script engine.",
368 MainConsole.Instance.Commands.AddCommand(
369 "Scripts",
false,
"scripts show",
"scripts show [<script-item-uuid>+]",
"Show script information",
370 "Show information on all scripts known to the script engine.\n"
371 +
"If one or more <script-item-uuid>s are given then only information on that script will be shown.",
374 MainConsole.Instance.Commands.AddCommand(
375 "Scripts",
false,
"show scripts",
"show scripts [<script-item-uuid>+]",
"Show script information",
376 "Synonym for scripts show command", HandleShowScripts);
378 MainConsole.Instance.Commands.AddCommand(
379 "Scripts",
false,
"scripts suspend",
"scripts suspend [<script-item-uuid>+]",
"Suspends all running scripts",
380 "Suspends all currently running scripts. This only suspends event delivery, it will not suspend a"
381 +
" script that is currently processing an event.\n"
382 +
"Suspended scripts will continue to accumulate events but won't process them.\n"
383 +
"If one or more <script-item-uuid>s are given then only that script will be suspended. Otherwise, all suitable scripts are suspended.",
384 (module, cmdparams) => HandleScriptsAction(cmdparams, HandleSuspendScript));
386 MainConsole.Instance.Commands.AddCommand(
387 "Scripts",
false,
"scripts resume",
"scripts resume [<script-item-uuid>+]",
"Resumes all suspended scripts",
388 "Resumes all currently suspended scripts.\n"
389 +
"Resumed scripts will process all events accumulated whilst suspended.\n"
390 +
"If one or more <script-item-uuid>s are given then only that script will be resumed. Otherwise, all suitable scripts are resumed.",
391 (module, cmdparams) => HandleScriptsAction(cmdparams, HandleResumeScript));
393 MainConsole.Instance.Commands.AddCommand(
394 "Scripts",
false,
"scripts stop",
"scripts stop [<script-item-uuid>+]",
"Stops all running scripts",
395 "Stops all running scripts.\n"
396 +
"If one or more <script-item-uuid>s are given then only that script will be stopped. Otherwise, all suitable scripts are stopped.",
397 (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStopScript));
399 MainConsole.Instance.Commands.AddCommand(
400 "Scripts",
false,
"scripts start",
"scripts start [<script-item-uuid>+]",
"Starts all stopped scripts",
401 "Starts all stopped scripts.\n"
402 +
"If one or more <script-item-uuid>s are given then only that script will be started. Otherwise, all suitable scripts are started.",
403 (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStartScript));
405 MainConsole.Instance.Commands.AddCommand(
406 "Debug",
false,
"debug scripts log",
"debug scripts log <item-id> <log-level>",
"Extra debug logging for a particular script.",
407 "Activates or deactivates extra debug logging for the given script.\n"
408 +
"Level == 0, deactivate extra debug logging.\n"
409 +
"Level >= 1, log state changes.\n"
410 +
"Level >= 2, log event invocations.\n",
411 HandleDebugScriptLogCommand);
413 MainConsole.Instance.Commands.AddCommand(
414 "Debug",
false,
"debug xengine log",
"debug xengine log [<level>]",
415 "Turn on detailed xengine debugging.",
416 "If level <= 0, then no extra logging is done.\n"
417 +
"If level >= 1, then we log every time that a script is started.",
418 HandleDebugLevelCommand);
421 private void HandleDebugScriptLogCommand(
string module,
string[] args)
426 if (args.Length != 5)
428 MainConsole.Instance.Output(
"Usage: debug script log <item-id> <log-level>");
448 if (!m_Scripts.TryGetValue(itemId, out si))
452 si.DebugLevel = newLevel;
453 MainConsole.Instance.OutputFormat(
"Set debug level of {0} {1} to {2}", si.ScriptName, si.ItemID, newLevel);
461 private void HandleDebugLevelCommand(
string module,
string[] args)
463 if (args.Length >= 4)
468 DebugLevel = newDebug;
469 MainConsole.Instance.OutputFormat(
"Debug level set to {0} in XEngine for region {1}", newDebug, m_Scene.Name);
472 else if (args.Length == 3)
474 MainConsole.Instance.OutputFormat(
"Current debug level is {0}", DebugLevel);
478 MainConsole.Instance.Output(
"Usage: debug xengine log <level>");
488 private void HandleScriptsAction(
string[] cmdparams, Action<IScriptInstance> action)
490 HandleScriptsAction<object>(cmdparams, action, null);
499 private void HandleScriptsAction<TKey>(
500 string[] cmdparams, Action<IScriptInstance> action, System.Func<
IScriptInstance, TKey> keySelector)
508 UUID itemId = UUID.Zero;
510 if (cmdparams.Length == 2)
514 if (keySelector != null)
515 scripts = scripts.OrderBy<IScriptInstance, TKey>(keySelector);
517 foreach (IScriptInstance instance
in scripts)
523 for (
int i = 2; i < cmdparams.Length; i++)
525 rawItemId = cmdparams[i];
527 if (!
UUID.TryParse(rawItemId, out itemId))
529 MainConsole.Instance.OutputFormat(
"ERROR: {0} is not a valid UUID", rawItemId);
533 if (itemId !=
UUID.Zero)
535 IScriptInstance instance = GetInstance(itemId);
536 if (instance == null)
553 private void HandleShowStatus(
string module,
string[] cmdparams)
558 MainConsole.Instance.Output(GetStatusReport());
563 StringBuilder sb =
new StringBuilder();
564 sb.AppendFormat(
"Status of XEngine instance for {0}\n", m_Scene.RegionInfo.RegionName);
566 long scriptsLoaded, eventsQueued = 0, eventsProcessed = 0;
570 scriptsLoaded = m_Scripts.Count;
572 foreach (IScriptInstance si
in m_Scripts.Values)
574 eventsQueued += si.EventsQueued;
575 eventsProcessed += si.EventsProcessed;
579 sb.AppendFormat(
"Scripts loaded : {0}\n", scriptsLoaded);
580 sb.AppendFormat(
"Scripts waiting for load : {0}\n", m_CompileQueue.Count);
581 sb.AppendFormat(
"Max threads : {0}\n", m_ThreadPool.MaxThreads);
582 sb.AppendFormat(
"Min threads : {0}\n", m_ThreadPool.MinThreads);
583 sb.AppendFormat(
"Allocated threads : {0}\n", m_ThreadPool.ActiveThreads);
584 sb.AppendFormat(
"In use threads : {0}\n", m_ThreadPool.InUseThreads);
585 sb.AppendFormat(
"Work items waiting : {0}\n", m_ThreadPool.WaitingCallbacks);
587 sb.AppendFormat(
"Events queued : {0}\n", eventsQueued);
588 sb.AppendFormat(
"Events processed : {0}\n", eventsProcessed);
590 SensorRepeat sr = AsyncCommandManager.GetSensorRepeatPlugin(
this);
591 sb.AppendFormat(
"Sensors : {0}\n", sr != null ? sr.SensorsCount : 0);
593 Dataserver ds = AsyncCommandManager.GetDataserverPlugin(
this);
594 sb.AppendFormat(
"Dataserver requests : {0}\n", ds != null ? ds.DataserverRequestsCount : 0);
596 Timer t = AsyncCommandManager.GetTimerPlugin(
this);
597 sb.AppendFormat(
"Timers : {0}\n", t != null ? t.TimersCount : 0);
599 Listener l = AsyncCommandManager.GetListenerPlugin(
this);
600 sb.AppendFormat(
"Listeners : {0}\n", l != null ? l.ListenerCount : 0);
602 return sb.ToString();
610 if (cmdparams.Length == 2)
614 MainConsole.Instance.OutputFormat(
615 "Showing {0} scripts in {1}", m_Scripts.Count, m_Scene.RegionInfo.RegionName);
619 HandleScriptsAction<long>(cmdparams, HandleShowScript, si => si.EventsProcessed);
622 private void HandleShowScript(IScriptInstance instance)
629 status =
"shutting down";
633 status =
"suspended";
644 StringBuilder sb =
new StringBuilder();
646 sb.AppendFormat(
"Script name : {0}\n", instance.ScriptName);
647 sb.AppendFormat(
"Status : {0}\n", status);
648 sb.AppendFormat(
"Queued events : {0}\n", instance.EventsQueued);
649 sb.AppendFormat(
"Processed events : {0}\n", instance.EventsProcessed);
650 sb.AppendFormat(
"Item UUID : {0}\n", instance.ItemID);
651 sb.AppendFormat(
"Asset UUID : {0}\n", instance.AssetID);
652 sb.AppendFormat(
"Containing part name: {0}\n", instance.PrimName);
653 sb.AppendFormat(
"Containing part UUID: {0}\n", instance.ObjectID);
654 sb.AppendFormat(
"Position : {0}\n", sop.AbsolutePosition);
656 MainConsole.Instance.Output(sb.ToString());
659 private void HandleSuspendScript(IScriptInstance instance)
666 MainConsole.Instance.OutputFormat(
667 "Suspended {0}.{1}, item UUID {2}, prim UUID {3} @ {4}",
668 instance.PrimName, instance.ScriptName, instance.ItemID, instance.ObjectID, sop.AbsolutePosition);
672 private void HandleResumeScript(IScriptInstance instance)
679 MainConsole.Instance.OutputFormat(
680 "Resumed {0}.{1}, item UUID {2}, prim UUID {3} @ {4}",
681 instance.PrimName, instance.ScriptName, instance.ItemID, instance.ObjectID, sop.AbsolutePosition);
685 private void HandleStartScript(IScriptInstance instance)
692 MainConsole.Instance.OutputFormat(
693 "Started {0}.{1}, item UUID {2}, prim UUID {3} @ {4}",
694 instance.PrimName, instance.ScriptName, instance.ItemID, instance.ObjectID, sop.AbsolutePosition);
698 private void HandleStopScript(IScriptInstance instance)
702 instance.StayStopped =
true;
707 MainConsole.Instance.OutputFormat(
708 "Stopped {0}.{1}, item UUID {2}, prim UUID {3} @ {4}",
709 instance.PrimName, instance.ScriptName, instance.ItemID, instance.ObjectID, sop.AbsolutePosition);
721 "[XEngine]: Shutting down {0} scripts in {1}", m_Scripts.Count, m_Scene.RegionInfo.RegionName);
723 foreach (IScriptInstance instance
in m_Scripts.Values)
730 instance.SaveState();
736 "[XEngine]: Failed final state save for script {0}.{1}, item UUID {2}, prim UUID {3} in {4}. Exception ",
737 instance.PrimName, instance.ScriptName, instance.ItemID, instance.ObjectID, World.Name)
743 instance.Stop(0,
true);
747 instance.DestroyScriptInstance();
754 if (!m_SimulatorShuttingDown)
756 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
757 if (m_DomainScripts[instance.
AppDomain].Count == 0)
759 m_DomainScripts.Remove(instance.AppDomain);
766 m_PrimObjects.Clear();
767 m_Assemblies.Clear();
768 m_DomainScripts.Clear();
770 lock (m_ScriptEngines)
772 m_ScriptEngines.Remove(
this);
785 m_Scene.EventManager.OnRemoveScript += OnRemoveScript;
786 m_Scene.EventManager.OnScriptReset += OnScriptReset;
787 m_Scene.EventManager.OnStartScript += OnStartScript;
788 m_Scene.EventManager.OnStopScript += OnStopScript;
789 m_Scene.EventManager.OnGetScriptRunning += OnGetScriptRunning;
790 m_Scene.EventManager.OnShutdown += OnShutdown;
794 m_Scene.EventManager.OnRegionReadyStatusChange += s => {
if (s.Ready) m_InitialStartup =
false; };
798 m_ThreadPool.QueueWorkItem(
new WorkItemCallback(this.DoMaintenance),
799 new Object[]{ m_SleepTime });
804 m_ThreadPool.QueueWorkItem(
new WorkItemCallback(this.DoBackup),
805 new Object[] { m_SaveTime });
811 m_ThreadPool.Start();
819 lock (m_ScriptEngines)
821 if (m_ScriptEngines.Contains(
this))
822 m_ScriptEngines.Remove(
this);
829 int saveTime = (int)p[0];
832 System.Threading.Thread.Sleep(saveTime);
836 List<IScriptInstance> instances =
new List<IScriptInstance>();
840 foreach (IScriptInstance instance
in m_Scripts.Values)
848 instances.Add(instance);
853 foreach (IScriptInstance i
in instances)
863 "[XEngine]: Failed to save state of script {0}.{1}, item UUID {2}, prim UUID {3} in {4}. Exception ",
864 i.PrimName, i.ScriptName, i.ItemID, i.ObjectID, World.Name)
870 m_ThreadPool.QueueWorkItem(
new WorkItemCallback(this.DoBackup),
871 new Object[] { saveTime });
878 DoBackup(
new object[] { 0 });
883 object[] parms = (
object[])p;
884 int sleepTime = (int)parms[0];
886 foreach (IScriptInstance inst
in m_Scripts.Values)
891 if (!m_KillTimedOutScripts)
896 System.Threading.Thread.Sleep(sleepTime);
898 m_ThreadPool.QueueWorkItem(
new WorkItemCallback(this.DoMaintenance),
899 new Object[]{ sleepTime });
904 public Type ReplaceableInterface
911 get {
return "XEngine"; }
914 public void OnRezScript(uint localID, UUID itemID,
string script,
int startParam,
bool postOnRez,
string engine,
int stateSource)
920 if (script.StartsWith(
"//MRM:"))
923 List<IScriptModule> engines =
new List<IScriptModule>(m_Scene.RequestModuleInterfaces<
IScriptModule>());
925 List<string> names =
new List<string>();
927 names.Add(m.ScriptEngineName);
929 int lineEnd = script.IndexOf(
'\n');
933 string firstline = script.Substring(0, lineEnd).Trim();
935 int colon = firstline.IndexOf(
':');
936 if (firstline.Length > 2 && firstline.Substring(0, 2) ==
"//" && colon != -1)
938 string engineName = firstline.Substring(2, colon - 2);
940 if (names.Contains(engineName))
943 script =
"//" + script.Substring(colon + 1);
947 if (engine == ScriptEngineName)
965 bool warnRunningInXEngine =
false;
966 string restOfFirstLine = firstline.Substring(colon + 1);
969 if (restOfFirstLine.StartsWith(
"c#")
970 || restOfFirstLine.StartsWith(
"vb")
971 || restOfFirstLine.StartsWith(
"lsl")
972 || restOfFirstLine.Length == 0)
973 warnRunningInXEngine =
true;
975 if (warnRunningInXEngine)
978 m_Scene.GetSceneObjectPart(
982 part.Inventory.GetInventoryItem(itemID);
985 m_Scene.GetScenePresence(
988 if (presence != null)
990 presence.ControllingClient.SendAgentAlertMessage(
991 "Selected engine unavailable. "+
992 "Running script on "+
1002 if (engine != ScriptEngineName)
1007 if (stateSource == (
int)StateSource.ScriptedRez)
1009 lock (m_CompileDict)
1011 m_CompileDict[itemID] = 0;
1014 DoOnRezScript(parms);
1018 lock (m_CompileDict)
1019 m_CompileDict[itemID] = 0;
1023 m_CompileQueue.Enqueue(parms);
1027 if (m_CurrentCompile == null)
1034 lock (m_CompileQueue)
1036 if (m_CurrentCompile == null)
1037 m_CurrentCompile = m_ThreadPool.QueueWorkItem(DoOnRezScriptQueue, null);
1047 if (m_InitialStartup)
1051 System.Threading.Thread.Sleep(m_StartDelay);
1053 m_log.InfoFormat(
"[XEngine]: Performing initial script startup on {0}", m_Scene.Name);
1058 int scriptsStarted = 0;
1060 while (m_CompileQueue.Dequeue(out o))
1064 if (DoOnRezScript(o))
1068 if (m_InitialStartup)
1069 if (scriptsStarted % 50 == 0)
1071 "[XEngine]: Started {0} scripts in {1}", scriptsStarted, m_Scene.Name);
1078 "[XEngine]: Failure in DoOnRezScriptQueue() for item {0} in {1}. Continuing. Exception ",
1079 o[1], m_Scene.Name),
1084 if (m_InitialStartup)
1086 "[XEngine]: Completed starting {0} scripts on {1}", scriptsStarted, m_Scene.Name);
1092 string.Format(
"[XEngine]: Failure in DoOnRezScriptQueue() in {0}. Exception ", m_Scene.Name), e);
1098 m_Scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptFailCount,
1099 m_ScriptErrorMessage);
1101 m_ScriptFailCount = 0;
1102 m_InitialStartup =
false;
1109 lock (m_CompileQueue)
1111 m_CurrentCompile = null;
1116 if (m_CompileQueue.Count > 0)
1117 m_CurrentCompile = m_ThreadPool.QueueWorkItem(DoOnRezScriptQueue, null);
1124 private bool DoOnRezScript(
object[] parms)
1127 uint localID = (uint)p[0];
1129 string script =(string)p[2];
1130 int startParam = (int)p[3];
1131 bool postOnRez = (bool)p[4];
1136 lock (m_CompileDict)
1138 if (!m_CompileDict.ContainsKey(itemID))
1140 m_CompileDict.Remove(itemID);
1152 m_log.ErrorFormat(
"[Script]: SceneObjectPart with localID {0} unavailable. Script NOT started.", localID);
1153 m_ScriptErrorMessage +=
"SceneObjectPart unavailable. Script NOT started.\n";
1154 m_ScriptFailCount++;
1161 m_ScriptErrorMessage +=
"Can't find script inventory item.\n";
1162 m_ScriptFailCount++;
1168 "[XEngine]: Loading script {0}.{1}, item UUID {2}, prim UUID {3} @ {4}.{5}",
1169 part.ParentGroup.RootPart.Name, item.Name, itemID, part.UUID,
1170 part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName);
1172 UUID assetID = item.AssetID;
1174 ScenePresence presence = m_Scene.GetScenePresence(item.OwnerID);
1176 string assemblyPath =
"";
1178 Culture.SetCurrentCulture();
1180 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap;
1182 lock (m_ScriptErrors)
1186 lock (m_AddingAssemblies)
1188 m_Compiler.PerformScriptCompile(script, assetID.ToString(), item.
OwnerID, out assemblyPath, out linemap);
1194 if (!m_AddingAssemblies.ContainsKey(assemblyPath)) {
1195 m_AddingAssemblies[assemblyPath] = 1;
1197 m_AddingAssemblies[assemblyPath]++;
1201 string[] warnings = m_Compiler.GetWarnings();
1203 if (warnings != null && warnings.Length != 0)
1205 foreach (
string warning
in warnings)
1207 if (!m_ScriptErrors.ContainsKey(itemID))
1208 m_ScriptErrors[itemID] =
new ArrayList();
1210 m_ScriptErrors[itemID].Add(warning);
1249 if (!m_ScriptErrors.ContainsKey(itemID))
1250 m_ScriptErrors[itemID] =
new ArrayList();
1254 m_ScriptFailCount++;
1255 m_ScriptErrors[itemID].Add(e.Message.ToString());
1288 if ((!m_Scripts.ContainsKey(itemID)) ||
1289 (m_Scripts[itemID].AssetID != assetID))
1291 UUID appDomain = assetID;
1294 appDomain = part.ParentGroup.RootPart.UUID;
1296 if (!m_AppDomains.ContainsKey(appDomain))
1300 AppDomainSetup appSetup =
new AppDomainSetup();
1301 appSetup.PrivateBinPath = Path.Combine(
1302 m_ScriptEnginesPath,
1303 m_Scene.RegionInfo.RegionID.ToString());
1305 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
1306 Evidence evidence =
new Evidence(baseEvidence);
1309 if (m_AppDomainLoading)
1311 sandbox = AppDomain.CreateDomain(
1312 m_Scene.RegionInfo.RegionID.ToString(),
1313 evidence, appSetup);
1314 sandbox.AssemblyResolve +=
1315 new ResolveEventHandler(
1320 sandbox = AppDomain.CurrentDomain;
1331 m_AppDomains[appDomain] = sandbox;
1333 m_DomainScripts[appDomain] =
new List<UUID>();
1337 m_log.ErrorFormat(
"[XEngine] Exception creating app domain:\n {0}", e.ToString());
1338 m_ScriptErrorMessage +=
"Exception creating app domain:\n";
1339 m_ScriptFailCount++;
1340 lock (m_AddingAssemblies)
1342 m_AddingAssemblies[assemblyPath]--;
1347 m_DomainScripts[appDomain].Add(itemID);
1350 EventWaitHandle coopSleepHandle;
1351 bool coopTerminationForThisScript;
1354 AssemblyName assemblyName =
new AssemblyName(Path.GetFileNameWithoutExtension(assemblyPath));
1355 assemblyName.CodeBase = Path.GetDirectoryName(assemblyPath);
1357 if (m_coopTermination)
1364 = (
IScript)m_AppDomains[appDomain].CreateInstanceAndUnwrap(
1365 assemblyName.FullName,
1366 "SecondLife.XEngineScript",
1368 BindingFlags.Default,
1370 new object[] { coopSleepHandle },
1374 coopTerminationForThisScript =
true;
1376 catch (TypeLoadException)
1378 coopSleepHandle = null;
1383 = (
IScript)m_AppDomains[appDomain].CreateInstanceAndUnwrap(
1384 assemblyName.FullName,
1385 "SecondLife.Script",
1387 BindingFlags.Default,
1393 catch (Exception e2)
1397 "[XENGINE]: Could not load previous SecondLife.Script from assembly {0} in {1}. Not starting. Exception ",
1398 assemblyName.FullName, World.Name),
1404 coopTerminationForThisScript =
false;
1412 = (
IScript)m_AppDomains[appDomain].CreateInstanceAndUnwrap(
1413 assemblyName.FullName,
1414 "SecondLife.Script",
1416 BindingFlags.Default,
1422 coopSleepHandle = null;
1423 coopTerminationForThisScript =
false;
1425 catch (TypeLoadException)
1432 = (
IScript)m_AppDomains[appDomain].CreateInstanceAndUnwrap(
1433 assemblyName.FullName,
1434 "SecondLife.XEngineScript",
1436 BindingFlags.Default,
1438 new object[] { coopSleepHandle },
1442 catch (Exception e2)
1446 "[XENGINE]: Could not load previous SecondLife.XEngineScript from assembly {0} in {1}. Not starting. Exception ",
1447 assemblyName.FullName, World.Name),
1453 coopTerminationForThisScript =
true;
1457 if (m_coopTermination != coopTerminationForThisScript && !HaveNotifiedLogOfScriptStopMistmatch)
1463 "[XEngine]: At least one existing compiled script DLL in {0} has {1} as ScriptStopStrategy whereas config setting is {2}."
1464 +
"\nContinuing with script compiled strategy but to remove this message please set [XEngine] DeleteScriptsOnStartup = true for one simulator session to remove old script DLLs (script state will not be lost).",
1465 World.Name, coopTerminationForThisScript ?
"co-op" :
"abort", m_coopTermination ?
"co-op" :
"abort");
1467 HaveNotifiedLogOfScriptStopMistmatch =
true;
1472 startParam, postOnRez,
1477 scriptObj, coopSleepHandle, assemblyPath,
1478 Path.Combine(ScriptEnginePath,
World.RegionInfo.RegionID.ToString()), stateSource, coopTerminationForThisScript))
1487 if (presence != null)
1489 ShowScriptSaveResponse(item.
OwnerID,
1490 assetID,
"Compile successful",
true);
1493 instance.AppDomain = appDomain;
1494 instance.LineMap = linemap;
1496 m_Scripts[itemID] = instance;
1500 lock (m_PrimObjects)
1502 if (!m_PrimObjects.ContainsKey(localID))
1503 m_PrimObjects[localID] =
new List<UUID>();
1505 if (!m_PrimObjects[localID].Contains(itemID))
1506 m_PrimObjects[localID].
Add(itemID);
1509 if (!m_Assemblies.ContainsKey(assetID))
1510 m_Assemblies[assetID] = assemblyPath;
1512 lock (m_AddingAssemblies)
1514 m_AddingAssemblies[assemblyPath]--;
1517 if (instance != null)
1521 if (m_runFlags.TryGetValue(itemID, out runIt))
1525 m_runFlags.Remove(itemID);
1534 lock (m_CompileDict)
1536 if (m_CompileDict.ContainsKey(itemID))
1537 m_CompileDict.Remove(itemID);
1540 IScriptInstance instance = null;
1545 if (!m_Scripts.ContainsKey(itemID))
1548 instance = m_Scripts[itemID];
1549 m_Scripts.Remove(itemID);
1552 instance.Stop(m_WaitForEventCompletionOnScriptStop,
true);
1554 lock (m_PrimObjects)
1557 if (m_PrimObjects.ContainsKey(localID))
1560 if (m_PrimObjects[localID].Contains(itemID))
1561 m_PrimObjects[localID].Remove(itemID);
1564 if (m_PrimObjects[localID].Count == 0)
1565 m_PrimObjects.Remove(localID);
1570 instance.RemoveState();
1572 instance.DestroyScriptInstance();
1574 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
1575 if (m_DomainScripts[instance.
AppDomain].Count == 0)
1577 m_DomainScripts.Remove(instance.AppDomain);
1582 if (handlerObjectRemoved != null)
1583 handlerObjectRemoved(instance.
ObjectID);
1586 if (handlerScriptRemoved != null)
1587 handlerScriptRemoved(itemID);
1592 ResetScript(itemID);
1597 StartScript(itemID);
1605 private void CleanAssemblies()
1607 List<UUID> assetIDList =
new List<UUID>(m_Assemblies.Keys);
1609 foreach (IScriptInstance i
in m_Scripts.Values)
1611 if (assetIDList.Contains(i.
AssetID))
1612 assetIDList.Remove(i.
AssetID);
1615 lock (m_AddingAssemblies)
1617 foreach (UUID assetID
in assetIDList)
1621 if (!m_AddingAssemblies.ContainsKey(m_Assemblies[assetID])
1622 || m_AddingAssemblies[m_Assemblies[assetID]] == 0)
1627 if (
File.Exists(m_Assemblies[assetID]))
1628 File.Delete(m_Assemblies[assetID]);
1630 if (
File.Exists(m_Assemblies[assetID]+
".text"))
1631 File.Delete(m_Assemblies[assetID]+
".text");
1633 if (
File.Exists(m_Assemblies[assetID]+
".mdb"))
1634 File.Delete(m_Assemblies[assetID]+
".mdb");
1636 if (
File.Exists(m_Assemblies[assetID]+
".map"))
1637 File.Delete(m_Assemblies[assetID]+
".map");
1642 m_Assemblies.Remove(assetID);
1648 private void UnloadAppDomain(UUID
id)
1650 if (m_AppDomains.ContainsKey(
id))
1652 AppDomain domain = m_AppDomains[id];
1653 m_AppDomains.Remove(id);
1655 if (domain != AppDomain.CurrentDomain)
1656 AppDomain.Unload(domain);
1665 private void SetupEngine(
int minThreads,
int maxThreads,
1666 int idleTimeout, ThreadPriority threadPriority,
1667 int maxScriptQueue,
int stackSize)
1669 m_MaxScriptQueue = maxScriptQueue;
1671 STPStartInfo startInfo =
new STPStartInfo();
1672 startInfo.ThreadPoolName =
"XEngine";
1673 startInfo.IdleTimeout = idleTimeout * 1000;
1674 startInfo.MaxWorkerThreads = maxThreads;
1675 startInfo.MinWorkerThreads = minThreads;
1676 startInfo.ThreadPriority = threadPriority;;
1677 startInfo.MaxStackSize = stackSize;
1678 startInfo.StartSuspended =
true;
1688 return new XWorkItem(m_ThreadPool.QueueWorkItem(
1689 new WorkItemCallback(this.ProcessEventHandler),
1698 private object ProcessEventHandler(
object parms)
1700 Culture.SetCurrentCulture();
1706 return instance.EventProcessor();
1717 bool result =
false;
1718 List<UUID> uuids = null;
1720 lock (m_PrimObjects)
1722 if (!m_PrimObjects.ContainsKey(localID))
1725 uuids = m_PrimObjects[localID];
1727 foreach (
UUID itemID
in uuids)
1729 IScriptInstance instance = null;
1732 if (m_Scripts.ContainsKey(itemID))
1733 instance = m_Scripts[itemID];
1737 if (instance != null)
1739 instance.PostEvent(p);
1756 if (m_Scripts.ContainsKey(itemID))
1758 IScriptInstance instance = m_Scripts[itemID];
1759 if (instance != null)
1760 instance.PostEvent(p);
1769 for (
int i = 0; i < p.Length ; i++)
1773 else if (p[i] is
string)
1775 else if (p[i] is Vector3)
1777 else if (p[i] is Quaternion)
1779 else if (p[i] is
float)
1795 for (
int i = 0; i < p.Length ; i++)
1799 else if (p[i] is
string)
1801 else if (p[i] is Vector3)
1803 else if (p[i] is Quaternion)
1805 else if (p[i] is
float)
1815 ResolveEventArgs args)
1817 if (!(sender is System.AppDomain))
1820 string[] pathList =
new string[] {
"bin", m_ScriptEnginesPath,
1821 Path.Combine(m_ScriptEnginesPath,
1822 m_Scene.RegionInfo.RegionID.ToString())};
1824 string assemblyName = args.Name;
1825 if (assemblyName.IndexOf(
",") != -1)
1826 assemblyName = args.Name.Substring(0, args.Name.IndexOf(
","));
1828 foreach (
string s
in pathList)
1830 string path = Path.Combine(Directory.GetCurrentDirectory(),
1831 Path.Combine(s, assemblyName))+
".dll";
1835 if (
File.Exists(path))
1836 return Assembly.LoadFrom(path);
1842 private IScriptInstance GetInstance(UUID itemID)
1844 IScriptInstance instance;
1847 if (!m_Scripts.ContainsKey(itemID))
1849 instance = m_Scripts[itemID];
1856 IScriptInstance instance = GetInstance(itemID);
1857 if (instance != null)
1868 IScriptInstance instance = GetInstance(itemID);
1869 return instance != null && instance.Running;
1874 IScriptInstance instance = GetInstance(itemID);
1875 if (instance != null)
1876 instance.ApiResetScript();
1882 m_Scene.setThreadCount(m_ThreadPool.InUseThreads);
1887 IScriptInstance instance = GetInstance(itemID);
1888 if (instance != null)
1889 instance.ResetScript(m_WaitForEventCompletionOnScriptStop);
1895 m_Scene.setThreadCount(m_ThreadPool.InUseThreads);
1900 IScriptInstance instance = GetInstance(itemID);
1901 if (instance != null)
1904 m_runFlags.AddOrUpdate(itemID,
true, 240);
1910 m_Scene.setThreadCount(m_ThreadPool.InUseThreads);
1915 IScriptInstance instance = GetInstance(itemID);
1917 if (instance != null)
1920 instance.StayStopped =
true;
1922 instance.Stop(m_WaitForEventCompletionOnScriptStop);
1927 m_runFlags.AddOrUpdate(itemID,
false, 240);
1934 m_Scene.setThreadCount(m_ThreadPool.InUseThreads);
1939 IScriptInstance instance = GetInstance(itemID);
1940 return instance != null ? instance.GetDetectParams(idx) : null;
1945 IScriptInstance instance = GetInstance(itemID);
1946 if (instance != null)
1947 instance.MinEventDelay = delay;
1952 IScriptInstance instance = GetInstance(itemID);
1953 return instance != null ? instance.GetDetectID(idx) :
UUID.Zero;
1958 IScriptInstance instance = GetInstance(itemID);
1959 if (instance == null)
1961 instance.SetState(newState);
1966 IScriptInstance instance = GetInstance(itemID);
1967 return instance == null ? 0 : instance.StartParam;
1972 m_SimulatorShuttingDown =
true;
1974 List<IScriptInstance> instances =
new List<IScriptInstance>();
1978 foreach (IScriptInstance instance
in m_Scripts.Values)
1979 instances.Add(instance);
1982 foreach (IScriptInstance i
in instances)
1989 bool prevRunning = i.Running;
1991 i.ShuttingDown =
true;
1992 i.Running = prevRunning;
1995 DoBackup(
new Object[] {0});
2000 IScriptInstance instance = GetInstance(itemID);
2001 return instance == null ? null : instance.GetApi(name);
2006 IScriptInstance instance = GetInstance(itemID);
2007 if (instance == null)
2012 controllingClient.SendScriptRunningReply(objectID, itemID,
2013 GetScriptState(itemID));
2017 eq.Enqueue(eq.ScriptRunningEvent(objectID, itemID, GetScriptState(itemID),
true),
2026 IScriptInstance instance = GetInstance(itemID);
2027 if (instance == null)
2033 string xml = instance.GetXMLState();
2035 XmlDocument sdoc =
new XmlDocument();
2036 bool loadedState =
true;
2041 catch (System.Xml.XmlException)
2043 loadedState =
false;
2046 XmlNodeList rootL = null;
2047 XmlNode rootNode = null;
2050 rootL = sdoc.GetElementsByTagName(
"ScriptState");
2051 rootNode = rootL[0];
2055 XmlDocument doc =
new XmlDocument();
2056 XmlElement stateData = doc.CreateElement(
"",
"State",
"");
2057 XmlAttribute stateID = doc.CreateAttribute(
"",
"UUID",
"");
2058 stateID.Value = itemID.ToString();
2059 stateData.Attributes.Append(stateID);
2060 XmlAttribute assetID = doc.CreateAttribute(
"",
"Asset",
"");
2061 assetID.Value = instance.AssetID.ToString();
2062 stateData.Attributes.Append(assetID);
2063 XmlAttribute engineName = doc.CreateAttribute(
"",
"Engine",
"");
2064 engineName.Value = ScriptEngineName;
2065 stateData.Attributes.Append(engineName);
2066 doc.AppendChild(stateData);
2068 XmlNode xmlstate = null;
2073 xmlstate = doc.ImportNode(rootNode,
true);
2077 xmlstate = doc.CreateElement(
"",
"ScriptState",
"");
2080 stateData.AppendChild(xmlstate);
2082 string assemName = instance.GetAssemblyName();
2084 string fn = Path.GetFileName(assemName);
2086 string assem = String.Empty;
2088 if (
File.Exists(assemName +
".text"))
2090 FileInfo tfi =
new FileInfo(assemName +
".text");
2094 Byte[] tdata =
new Byte[tfi.Length];
2098 using (FileStream tfs = File.Open(assemName +
".text",
2099 FileMode.Open, FileAccess.Read))
2101 tfs.Read(tdata, 0, tdata.Length);
2104 assem = Encoding.ASCII.GetString(tdata);
2109 "[XEngine]: Unable to open script textfile {0}{1}, reason: {2}",
2110 assemName,
".text", e.Message);
2116 FileInfo fi =
new FileInfo(assemName);
2120 Byte[] data =
new Byte[fi.Length];
2124 using (FileStream fs = File.Open(assemName, FileMode.Open, FileAccess.Read))
2126 fs.Read(data, 0, data.Length);
2129 assem = System.Convert.ToBase64String(data);
2134 "[XEngine]: Unable to open script assembly {0}, reason: {1}", assemName, e.Message);
2139 string map = String.Empty;
2141 if (
File.Exists(fn +
".map"))
2143 using (FileStream mfs = File.Open(fn +
".map", FileMode.Open, FileAccess.Read))
2145 using (StreamReader msr =
new StreamReader(mfs))
2147 map = msr.ReadToEnd();
2152 XmlElement assemblyData = doc.CreateElement(
"",
"Assembly",
"");
2153 XmlAttribute assemblyName = doc.CreateAttribute(
"",
"Filename",
"");
2155 assemblyName.Value = fn;
2156 assemblyData.Attributes.Append(assemblyName);
2158 assemblyData.InnerText = assem;
2160 stateData.AppendChild(assemblyData);
2162 XmlElement mapData = doc.CreateElement(
"",
"LineMap",
"");
2163 XmlAttribute mapName = doc.CreateAttribute(
"",
"Filename",
"");
2165 mapName.Value = fn +
".map";
2166 mapData.Attributes.Append(mapName);
2168 mapData.InnerText = map;
2170 stateData.AppendChild(mapData);
2174 return doc.InnerXml;
2177 private bool ShowScriptSaveResponse(UUID ownerID, UUID assetID,
string text,
bool compiled)
2189 XmlDocument doc =
new XmlDocument();
2197 m_log.Error(
"[XEngine]: Exception decoding XML data from region transfer");
2201 XmlNodeList rootL = doc.GetElementsByTagName(
"State");
2202 if (rootL.Count < 1)
2205 XmlElement rootE = (XmlElement)rootL[0];
2207 if (rootE.GetAttribute(
"Engine") != ScriptEngineName)
2216 XmlNodeList stateL = rootE.GetElementsByTagName(
"ScriptState");
2218 if (stateL.Count != 1)
2221 XmlElement stateE = (XmlElement)stateL[0];
2223 if (
World.m_trustBinaries)
2225 XmlNodeList assemL = rootE.GetElementsByTagName(
"Assembly");
2227 if (assemL.Count != 1)
2230 XmlElement assemE = (XmlElement)assemL[0];
2232 string fn = assemE.GetAttribute(
"Filename");
2233 string base64 = assemE.InnerText;
2235 string path = Path.Combine(m_ScriptEnginesPath, World.RegionInfo.RegionID.ToString());
2236 path = Path.Combine(path, fn);
2238 if (!
File.Exists(path))
2240 Byte[] filedata = Convert.FromBase64String(base64);
2244 using (FileStream fs = File.Create(path))
2248 fs.Write(filedata, 0, filedata.Length);
2251 catch (IOException ex)
2254 m_log.ErrorFormat(
"[XEngine]: Error whilst writing assembly file {0}, {1}", path, ex.Message);
2257 string textpath = path +
".text";
2260 using (FileStream fs = File.Create(textpath))
2262 using (StreamWriter sw =
new StreamWriter(fs))
2270 catch (IOException ex)
2273 m_log.ErrorFormat(
"[XEngine]: Error whilst writing .text file {0}, {1}", textpath, ex.Message);
2277 XmlNodeList mapL = rootE.GetElementsByTagName(
"LineMap");
2280 XmlElement mapE = (XmlElement)mapL[0];
2282 string mappath = Path.Combine(m_ScriptEnginesPath, World.RegionInfo.RegionID.ToString());
2283 mappath = Path.Combine(mappath, mapE.GetAttribute(
"Filename"));
2287 using (FileStream mfs = File.Create(mappath))
2289 using (StreamWriter msw =
new StreamWriter(mfs))
2293 msw.Write(mapE.InnerText);
2297 catch (IOException ex)
2301 string.Format(
"[XEngine]: Linemap file {0} could not be written. Exception ", mappath), ex);
2306 string statepath = Path.Combine(m_ScriptEnginesPath, World.RegionInfo.RegionID.ToString());
2307 statepath = Path.Combine(statepath, itemID.ToString() +
".state");
2311 using (FileStream sfs = File.Create(statepath))
2313 using (StreamWriter ssw =
new StreamWriter(sfs))
2317 ssw.Write(stateE.OuterXml);
2321 catch (IOException ex)
2324 m_log.ErrorFormat(
"[XEngine]: Error whilst writing state file {0}, {1}", statepath, ex.Message);
2335 System.Threading.Thread.Sleep(1000);
2337 lock (m_ScriptErrors)
2339 if (m_ScriptErrors.ContainsKey(itemID))
2341 ArrayList ret = m_ScriptErrors[itemID];
2342 m_ScriptErrors.Remove(itemID);
2345 return new ArrayList();
2351 Dictionary<uint, float> topScripts =
new Dictionary<uint, float>();
2355 foreach (IScriptInstance si
in m_Scripts.Values)
2357 if (!topScripts.ContainsKey(si.
LocalID))
2360 topScripts[si.
RootLocalID] += GetExectionTime(si);
2369 if (itemIDs == null|| itemIDs.Count == 0)
2377 foreach (
UUID id in itemIDs)
2379 si = GetInstance(
id);
2382 time += GetExectionTime(si);
2388 private float GetExectionTime(IScriptInstance si)
2390 return (
float)si.ExecutionTime.GetSumTime().TotalMilliseconds;
2397 IScriptInstance instance = GetInstance(itemID);
2398 if (instance != null)
2407 m_Scene.setThreadCount(m_ThreadPool.InUseThreads);
2414 IScriptInstance instance = GetInstance(itemID);
2415 if (instance != null)
2424 m_Scene.setThreadCount(m_ThreadPool.InUseThreads);
2431 IScriptInstance instance = GetInstance(itemID);
2432 if (instance == null)
2435 running = instance.Running;
2441 IScriptInstance instance = GetInstance(itemID);
2442 if (instance == null)
2445 instance.ExecutionTimer.Stop();
2455 Thread.Sleep(delay);
2460 instance.ExecutionTimer.Start();
bool PostObjectEvent(uint localID, EventParams p)
Post event to an entire prim
void HandleShowScripts(string module, string[] cmdparams)
static bool TryParseConsoleUuid(ICommandConsole console, string rawUuid, out UUID uuid)
Try to parse a console UUID from the console.
void OnRemoveScript(uint localID, UUID itemID)
void SetState(UUID itemID, string newState)
bool HasScript(UUID itemID, out bool running)
bool PostScriptEvent(UUID itemID, string name, Object[] p)
Post a script event to a single script.
WaitHandle CoopWaitHandle
void SetScriptState(UUID itemID, bool running)
static bool TryParseConsoleInt(ICommandConsole console, string rawConsoleInt, out int i)
Convert a console input to an int, automatically complaining if a console is given.
void OnScriptReset(uint localID, UUID itemID)
uint RootLocalID
Local id of the root object for the linkset that the script is in.
bool GetScriptState(UUID itemID)
Returns true if a script is running.
UUID GetDetectID(UUID itemID, int idx)
void Initialise(IConfigSource configSource)
This is called to initialize the region module. For shared modules, this is called exactly once...
void StopScript(UUID itemID)
bool SetXMLState(UUID itemID, string xml)
Represents an item in a task inventory
void ResetScript(UUID itemID)
int GetStartParameter(UUID itemID)
static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
Object DoOnRezScriptQueue(Object dummy)
bool ShuttingDown
Is the script shutting down?
OpenSim.Region.ScriptEngine.Shared.Api.Plugins.Timer Timer
bool PostObjectEvent(UUID itemID, string name, Object[] p)
bool Load(IScript script, EventWaitHandle coopSleepHandle, string assemblyPath, string dataPath, StateSource stateSource, bool coopTermination)
Load the script from an assembly into an AppDomain.
Used to signal when the script is stopping in co-operation with the script engine (instead of through...
float GetScriptExecutionTime(List< UUID > itemIDs)
Get the execution times of all scripts in the given array if they are currently running.
DetectParams GetDetectParams(UUID itemID, int idx)
An interface for a script API module to communicate with the engine it's running under ...
void ApiResetScript(UUID itemID)
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
delegate void ObjectRemoved(UUID prim)
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
Prepares events so they can be directly executed upon a script by EventQueueManager, then queues it.
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void OnStopScript(uint localID, UUID itemID)
static ICommandConsole Instance
Dictionary< uint, float > GetObjectScriptsExecutionTimes()
Get the execution times of all scripts in each object.
void StartProcessing()
Starts the processing threads.
void SleepScript(UUID itemID, int delay)
void SuspendScript(UUID itemID)
Suspends a script.
OpenSim.Framework.LocklessQueue< object[]> ScriptCompileQueue
Xengine event wait handle.
IScriptWorkItem QueueEventHandler(object parms)
Queue an event for execution
void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource)
bool Suspended
Is the script suspended?
static bool TryParseConsoleNaturalInt(ICommandConsole console, string rawConsoleInt, out int i)
Convert a console integer to a natural int, automatically complaining if a console is given...
System.Collections.IEnumerable IEnumerable
Interface for interaction with a particular script instance
SceneObjectGroup ParentGroup
void OnGetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID)
bool StatePersistedHere
If true then the engine is responsible for persisted state. If false then some other component may pe...
ArrayList GetScriptErrors(UUID itemID)
Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
delegate void ScriptRemoved(UUID script)
void ResumeScript(UUID itemID)
Resumes a script.
ObjectRemoved OnObjectRemoved
Event fired after the script engine has finished removing a script from an object.
object DoMaintenance(object p)
IScriptApi GetApi(UUID itemID, string name)
void SetMinEventDelay(UUID itemID, double delay)
bool PostScriptEvent(UUID itemID, EventParams p)
Post an event to a single script
string GetXMLState(UUID itemID)
Holds all the data required to execute a scripting event.
object DoBackup(object o)
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void StartScript(UUID itemID)
void OnStartScript(uint localID, UUID itemID)
ScriptRemoved OnScriptRemoved
Event fired after the script engine has finished removing a script.
bool IsAttachment
Is this scene object acting as an attachment?
bool Running
Is the script currently running?