SceneObjectPartInventory.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  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.Xml;
  29. using System.IO;
  30. using System.Collections.Generic;
  31. using System.Collections;
  32. using System.Reflection;
  33. using System.Threading;
  34. using OpenMetaverse;
  35. using log4net;
  36. using OpenSim.Framework;
  37. using OpenSim.Region.Framework.Interfaces;
  38. using OpenSim.Region.Framework.Scenes.Scripting;
  39. using OpenSim.Region.Framework.Scenes.Serialization;
  40. using PermissionMask = OpenSim.Framework.PermissionMask;
  41. namespace OpenSim.Region.Framework.Scenes
  42. {
  43. public class SceneObjectPartInventory : IEntityInventory
  44. {
  45. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  46. private string m_inventoryFileName = String.Empty;
  47. private byte[] m_inventoryFileData = new byte[0];
  48. private uint m_inventoryFileNameSerial = 0;
  49. /// <value>
  50. /// The part to which the inventory belongs.
  51. /// </value>
  52. private SceneObjectPart m_part;
  53. /// <summary>
  54. /// Serial count for inventory file , used to tell if inventory has changed
  55. /// no need for this to be part of Database backup
  56. /// </summary>
  57. protected uint m_inventorySerial = 0;
  58. /// <summary>
  59. /// Holds in memory prim inventory
  60. /// </summary>
  61. protected TaskInventoryDictionary m_items = new TaskInventoryDictionary();
  62. /// <summary>
  63. /// Tracks whether inventory has changed since the last persistent backup
  64. /// </summary>
  65. internal bool HasInventoryChanged;
  66. /// <value>
  67. /// Inventory serial number
  68. /// </value>
  69. protected internal uint Serial
  70. {
  71. get { return m_inventorySerial; }
  72. set { m_inventorySerial = value; }
  73. }
  74. /// <value>
  75. /// Raw inventory data
  76. /// </value>
  77. protected internal TaskInventoryDictionary Items
  78. {
  79. get { return m_items; }
  80. set
  81. {
  82. m_items = value;
  83. m_inventorySerial++;
  84. QueryScriptStates();
  85. }
  86. }
  87. public int Count
  88. {
  89. get
  90. {
  91. lock (m_items)
  92. return m_items.Count;
  93. }
  94. }
  95. /// <summary>
  96. /// Constructor
  97. /// </summary>
  98. /// <param name="part">
  99. /// A <see cref="SceneObjectPart"/>
  100. /// </param>
  101. public SceneObjectPartInventory(SceneObjectPart part)
  102. {
  103. m_part = part;
  104. }
  105. /// <summary>
  106. /// Force the task inventory of this prim to persist at the next update sweep
  107. /// </summary>
  108. public void ForceInventoryPersistence()
  109. {
  110. HasInventoryChanged = true;
  111. }
  112. /// <summary>
  113. /// Reset UUIDs for all the items in the prim's inventory.
  114. /// </summary>
  115. /// <remarks>
  116. /// This involves either generating
  117. /// new ones or setting existing UUIDs to the correct parent UUIDs.
  118. ///
  119. /// If this method is called and there are inventory items, then we regard the inventory as having changed.
  120. /// </remarks>
  121. public void ResetInventoryIDs()
  122. {
  123. if (null == m_part)
  124. return;
  125. lock (m_items)
  126. {
  127. if (0 == m_items.Count)
  128. return;
  129. IList<TaskInventoryItem> items = GetInventoryItems();
  130. m_items.Clear();
  131. foreach (TaskInventoryItem item in items)
  132. {
  133. item.ResetIDs(m_part.UUID);
  134. m_items.Add(item.ItemID, item);
  135. }
  136. }
  137. }
  138. public void ResetObjectID()
  139. {
  140. lock (Items)
  141. {
  142. IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
  143. Items.Clear();
  144. foreach (TaskInventoryItem item in items)
  145. {
  146. item.ParentPartID = m_part.UUID;
  147. item.ParentID = m_part.UUID;
  148. Items.Add(item.ItemID, item);
  149. }
  150. }
  151. }
  152. /// <summary>
  153. /// Change every item in this inventory to a new owner.
  154. /// </summary>
  155. /// <param name="ownerId"></param>
  156. public void ChangeInventoryOwner(UUID ownerId)
  157. {
  158. lock (Items)
  159. {
  160. if (0 == Items.Count)
  161. {
  162. return;
  163. }
  164. }
  165. HasInventoryChanged = true;
  166. m_part.ParentGroup.HasGroupChanged = true;
  167. List<TaskInventoryItem> items = GetInventoryItems();
  168. foreach (TaskInventoryItem item in items)
  169. {
  170. if (ownerId != item.OwnerID)
  171. item.LastOwnerID = item.OwnerID;
  172. item.OwnerID = ownerId;
  173. item.PermsMask = 0;
  174. item.PermsGranter = UUID.Zero;
  175. item.OwnerChanged = true;
  176. }
  177. }
  178. /// <summary>
  179. /// Change every item in this inventory to a new group.
  180. /// </summary>
  181. /// <param name="groupID"></param>
  182. public void ChangeInventoryGroup(UUID groupID)
  183. {
  184. lock (Items)
  185. {
  186. if (0 == Items.Count)
  187. {
  188. return;
  189. }
  190. }
  191. // Don't let this set the HasGroupChanged flag for attachments
  192. // as this happens during rez and we don't want a new asset
  193. // for each attachment each time
  194. if (!m_part.ParentGroup.IsAttachment)
  195. {
  196. HasInventoryChanged = true;
  197. m_part.ParentGroup.HasGroupChanged = true;
  198. }
  199. List<TaskInventoryItem> items = GetInventoryItems();
  200. foreach (TaskInventoryItem item in items)
  201. {
  202. if (groupID != item.GroupID)
  203. item.GroupID = groupID;
  204. }
  205. }
  206. private void QueryScriptStates()
  207. {
  208. if (m_part == null || m_part.ParentGroup == null || m_part.ParentGroup.Scene == null)
  209. return;
  210. lock (Items)
  211. {
  212. foreach (TaskInventoryItem item in Items.Values)
  213. {
  214. bool running;
  215. if (TryGetScriptInstanceRunning(m_part.ParentGroup.Scene, item, out running))
  216. item.ScriptRunning = running;
  217. }
  218. }
  219. }
  220. public bool TryGetScriptInstanceRunning(UUID itemId, out bool running)
  221. {
  222. running = false;
  223. TaskInventoryItem item = GetInventoryItem(itemId);
  224. if (item == null)
  225. return false;
  226. return TryGetScriptInstanceRunning(m_part.ParentGroup.Scene, item, out running);
  227. }
  228. public static bool TryGetScriptInstanceRunning(Scene scene, TaskInventoryItem item, out bool running)
  229. {
  230. running = false;
  231. if (item.InvType != (int)InventoryType.LSL)
  232. return false;
  233. IScriptModule[] engines = scene.RequestModuleInterfaces<IScriptModule>();
  234. if (engines == null) // No engine at all
  235. return false;
  236. foreach (IScriptModule e in engines)
  237. {
  238. if (e.HasScript(item.ItemID, out running))
  239. return true;
  240. }
  241. return false;
  242. }
  243. public int CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource)
  244. {
  245. int scriptsValidForStarting = 0;
  246. List<TaskInventoryItem> scripts = GetInventoryItems(InventoryType.LSL);
  247. foreach (TaskInventoryItem item in scripts)
  248. if (CreateScriptInstance(item, startParam, postOnRez, engine, stateSource))
  249. scriptsValidForStarting++;
  250. return scriptsValidForStarting;
  251. }
  252. public ArrayList GetScriptErrors(UUID itemID)
  253. {
  254. ArrayList ret = new ArrayList();
  255. IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
  256. foreach (IScriptModule e in engines)
  257. {
  258. if (e != null)
  259. {
  260. ArrayList errors = e.GetScriptErrors(itemID);
  261. foreach (Object line in errors)
  262. ret.Add(line);
  263. }
  264. }
  265. return ret;
  266. }
  267. /// <summary>
  268. /// Stop and remove all the scripts in this prim.
  269. /// </summary>
  270. /// <param name="sceneObjectBeingDeleted">
  271. /// Should be true if these scripts are being removed because the scene
  272. /// object is being deleted. This will prevent spurious updates to the client.
  273. /// </param>
  274. public void RemoveScriptInstances(bool sceneObjectBeingDeleted)
  275. {
  276. List<TaskInventoryItem> scripts = GetInventoryItems(InventoryType.LSL);
  277. foreach (TaskInventoryItem item in scripts)
  278. RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
  279. }
  280. /// <summary>
  281. /// Stop all the scripts in this prim.
  282. /// </summary>
  283. public void StopScriptInstances()
  284. {
  285. GetInventoryItems(InventoryType.LSL).ForEach(i => StopScriptInstance(i));
  286. }
  287. /// <summary>
  288. /// Start a script which is in this prim's inventory.
  289. /// </summary>
  290. /// <param name="item"></param>
  291. /// <returns>true if the script instance was created, false otherwise</returns>
  292. public bool CreateScriptInstance(TaskInventoryItem item, int startParam, bool postOnRez, string engine, int stateSource)
  293. {
  294. // m_log.DebugFormat("[PRIM INVENTORY]: Starting script {0} {1} in prim {2} {3} in {4}",
  295. // item.Name, item.ItemID, m_part.Name, m_part.UUID, m_part.ParentGroup.Scene.RegionInfo.RegionName);
  296. if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID))
  297. return false;
  298. m_part.AddFlag(PrimFlags.Scripted);
  299. if (m_part.ParentGroup.Scene.RegionInfo.RegionSettings.DisableScripts)
  300. return false;
  301. if (stateSource == 2 && // Prim crossing
  302. m_part.ParentGroup.Scene.m_trustBinaries)
  303. {
  304. lock (m_items)
  305. {
  306. m_items[item.ItemID].PermsMask = 0;
  307. m_items[item.ItemID].PermsGranter = UUID.Zero;
  308. }
  309. m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
  310. m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource);
  311. m_part.ParentGroup.AddActiveScriptCount(1);
  312. m_part.ScheduleFullUpdate();
  313. return true;
  314. }
  315. AssetBase asset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString());
  316. if (null == asset)
  317. {
  318. m_log.ErrorFormat(
  319. "[PRIM INVENTORY]: Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found",
  320. item.Name, item.ItemID, m_part.AbsolutePosition,
  321. m_part.ParentGroup.Scene.RegionInfo.RegionName, item.AssetID);
  322. return false;
  323. }
  324. else
  325. {
  326. if (m_part.ParentGroup.m_savedScriptState != null)
  327. item.OldItemID = RestoreSavedScriptState(item.LoadedItemID, item.OldItemID, item.ItemID);
  328. lock (m_items)
  329. {
  330. m_items[item.ItemID].OldItemID = item.OldItemID;
  331. m_items[item.ItemID].PermsMask = 0;
  332. m_items[item.ItemID].PermsGranter = UUID.Zero;
  333. }
  334. string script = Utils.BytesToString(asset.Data);
  335. m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
  336. m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource);
  337. if (!item.ScriptRunning)
  338. m_part.ParentGroup.Scene.EventManager.TriggerStopScript(
  339. m_part.LocalId, item.ItemID);
  340. m_part.ParentGroup.AddActiveScriptCount(1);
  341. m_part.ScheduleFullUpdate();
  342. return true;
  343. }
  344. }
  345. private UUID RestoreSavedScriptState(UUID loadedID, UUID oldID, UUID newID)
  346. {
  347. IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
  348. if (engines.Length == 0) // No engine at all
  349. return oldID;
  350. UUID stateID = oldID;
  351. if (!m_part.ParentGroup.m_savedScriptState.ContainsKey(oldID))
  352. stateID = loadedID;
  353. if (m_part.ParentGroup.m_savedScriptState.ContainsKey(stateID))
  354. {
  355. XmlDocument doc = new XmlDocument();
  356. doc.LoadXml(m_part.ParentGroup.m_savedScriptState[stateID]);
  357. ////////// CRUFT WARNING ///////////////////////////////////
  358. //
  359. // Old objects will have <ScriptState><State> ...
  360. // This format is XEngine ONLY
  361. //
  362. // New objects have <State Engine="...." ...><ScriptState>...
  363. // This can be passed to any engine
  364. //
  365. XmlNode n = doc.SelectSingleNode("ScriptState");
  366. if (n != null) // Old format data
  367. {
  368. XmlDocument newDoc = new XmlDocument();
  369. XmlElement rootN = newDoc.CreateElement("", "State", "");
  370. XmlAttribute uuidA = newDoc.CreateAttribute("", "UUID", "");
  371. uuidA.Value = stateID.ToString();
  372. rootN.Attributes.Append(uuidA);
  373. XmlAttribute engineA = newDoc.CreateAttribute("", "Engine", "");
  374. engineA.Value = "XEngine";
  375. rootN.Attributes.Append(engineA);
  376. newDoc.AppendChild(rootN);
  377. XmlNode stateN = newDoc.ImportNode(n, true);
  378. rootN.AppendChild(stateN);
  379. // This created document has only the minimun data
  380. // necessary for XEngine to parse it successfully
  381. m_part.ParentGroup.m_savedScriptState[stateID] = newDoc.OuterXml;
  382. }
  383. foreach (IScriptModule e in engines)
  384. {
  385. if (e != null)
  386. {
  387. if (e.SetXMLState(newID, m_part.ParentGroup.m_savedScriptState[stateID]))
  388. break;
  389. }
  390. }
  391. m_part.ParentGroup.m_savedScriptState.Remove(stateID);
  392. }
  393. return stateID;
  394. }
  395. public bool CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
  396. {
  397. TaskInventoryItem item = GetInventoryItem(itemId);
  398. if (item != null)
  399. {
  400. return CreateScriptInstance(item, startParam, postOnRez, engine, stateSource);
  401. }
  402. else
  403. {
  404. m_log.ErrorFormat(
  405. "[PRIM INVENTORY]: Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}",
  406. itemId, m_part.Name, m_part.UUID,
  407. m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
  408. return false;
  409. }
  410. }
  411. /// <summary>
  412. /// Stop and remove a script which is in this prim's inventory.
  413. /// </summary>
  414. /// <param name="itemId"></param>
  415. /// <param name="sceneObjectBeingDeleted">
  416. /// Should be true if this script is being removed because the scene
  417. /// object is being deleted. This will prevent spurious updates to the client.
  418. /// </param>
  419. public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted)
  420. {
  421. bool scriptPresent = false;
  422. lock (m_items)
  423. {
  424. if (m_items.ContainsKey(itemId))
  425. scriptPresent = true;
  426. }
  427. if (scriptPresent)
  428. {
  429. if (!sceneObjectBeingDeleted)
  430. m_part.RemoveScriptEvents(itemId);
  431. m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemId);
  432. m_part.ParentGroup.AddActiveScriptCount(-1);
  433. }
  434. else
  435. {
  436. m_log.WarnFormat(
  437. "[PRIM INVENTORY]: " +
  438. "Couldn't stop script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}",
  439. itemId, m_part.Name, m_part.UUID,
  440. m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
  441. }
  442. }
  443. /// <summary>
  444. /// Stop a script which is in this prim's inventory.
  445. /// </summary>
  446. /// <param name="itemId"></param>
  447. /// <param name="sceneObjectBeingDeleted">
  448. /// Should be true if this script is being removed because the scene
  449. /// object is being deleted. This will prevent spurious updates to the client.
  450. /// </param>
  451. public void StopScriptInstance(UUID itemId)
  452. {
  453. TaskInventoryItem scriptItem;
  454. lock (m_items)
  455. m_items.TryGetValue(itemId, out scriptItem);
  456. if (scriptItem != null)
  457. {
  458. StopScriptInstance(scriptItem);
  459. }
  460. else
  461. {
  462. m_log.WarnFormat(
  463. "[PRIM INVENTORY]: " +
  464. "Couldn't stop script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}",
  465. itemId, m_part.Name, m_part.UUID,
  466. m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
  467. }
  468. }
  469. /// <summary>
  470. /// Stop a script which is in this prim's inventory.
  471. /// </summary>
  472. /// <param name="itemId"></param>
  473. /// <param name="sceneObjectBeingDeleted">
  474. /// Should be true if this script is being removed because the scene
  475. /// object is being deleted. This will prevent spurious updates to the client.
  476. /// </param>
  477. public void StopScriptInstance(TaskInventoryItem item)
  478. {
  479. if (m_part.ParentGroup.Scene != null)
  480. m_part.ParentGroup.Scene.EventManager.TriggerStopScript(m_part.LocalId, item.ItemID);
  481. // At the moment, even stopped scripts are counted as active, which is probably wrong.
  482. // m_part.ParentGroup.AddActiveScriptCount(-1);
  483. }
  484. /// <summary>
  485. /// Check if the inventory holds an item with a given name.
  486. /// </summary>
  487. /// <param name="name"></param>
  488. /// <returns></returns>
  489. private bool InventoryContainsName(string name)
  490. {
  491. lock (m_items)
  492. {
  493. foreach (TaskInventoryItem item in m_items.Values)
  494. {
  495. if (item.Name == name)
  496. return true;
  497. }
  498. }
  499. return false;
  500. }
  501. /// <summary>
  502. /// For a given item name, return that name if it is available. Otherwise, return the next available
  503. /// similar name (which is currently the original name with the next available numeric suffix).
  504. /// </summary>
  505. /// <param name="name"></param>
  506. /// <returns></returns>
  507. private string FindAvailableInventoryName(string name)
  508. {
  509. if (!InventoryContainsName(name))
  510. return name;
  511. int suffix=1;
  512. while (suffix < 256)
  513. {
  514. string tryName=String.Format("{0} {1}", name, suffix);
  515. if (!InventoryContainsName(tryName))
  516. return tryName;
  517. suffix++;
  518. }
  519. return String.Empty;
  520. }
  521. /// <summary>
  522. /// Add an item to this prim's inventory. If an item with the same name already exists, then an alternative
  523. /// name is chosen.
  524. /// </summary>
  525. /// <param name="item"></param>
  526. public void AddInventoryItem(TaskInventoryItem item, bool allowedDrop)
  527. {
  528. AddInventoryItem(item.Name, item, allowedDrop);
  529. }
  530. /// <summary>
  531. /// Add an item to this prim's inventory. If an item with the same name already exists, it is replaced.
  532. /// </summary>
  533. /// <param name="item"></param>
  534. public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop)
  535. {
  536. List<TaskInventoryItem> il = GetInventoryItems();
  537. foreach (TaskInventoryItem i in il)
  538. {
  539. if (i.Name == item.Name)
  540. {
  541. if (i.InvType == (int)InventoryType.LSL)
  542. RemoveScriptInstance(i.ItemID, false);
  543. RemoveInventoryItem(i.ItemID);
  544. break;
  545. }
  546. }
  547. AddInventoryItem(item.Name, item, allowedDrop);
  548. }
  549. /// <summary>
  550. /// Add an item to this prim's inventory.
  551. /// </summary>
  552. /// <param name="name">The name that the new item should have.</param>
  553. /// <param name="item">
  554. /// The item itself. The name within this structure is ignored in favour of the name
  555. /// given in this method's arguments
  556. /// </param>
  557. /// <param name="allowedDrop">
  558. /// Item was only added to inventory because AllowedDrop is set
  559. /// </param>
  560. protected void AddInventoryItem(string name, TaskInventoryItem item, bool allowedDrop)
  561. {
  562. name = FindAvailableInventoryName(name);
  563. if (name == String.Empty)
  564. return;
  565. item.ParentID = m_part.UUID;
  566. item.ParentPartID = m_part.UUID;
  567. item.Name = name;
  568. item.GroupID = m_part.GroupID;
  569. lock (m_items)
  570. m_items.Add(item.ItemID, item);
  571. if (allowedDrop)
  572. m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP);
  573. else
  574. m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
  575. m_inventorySerial++;
  576. //m_inventorySerial += 2;
  577. HasInventoryChanged = true;
  578. m_part.ParentGroup.HasGroupChanged = true;
  579. }
  580. /// <summary>
  581. /// Restore a whole collection of items to the prim's inventory at once.
  582. /// We assume that the items already have all their fields correctly filled out.
  583. /// The items are not flagged for persistence to the database, since they are being restored
  584. /// from persistence rather than being newly added.
  585. /// </summary>
  586. /// <param name="items"></param>
  587. public void RestoreInventoryItems(ICollection<TaskInventoryItem> items)
  588. {
  589. lock (m_items)
  590. {
  591. foreach (TaskInventoryItem item in items)
  592. {
  593. m_items.Add(item.ItemID, item);
  594. // m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
  595. }
  596. m_inventorySerial++;
  597. }
  598. }
  599. /// <summary>
  600. /// Returns an existing inventory item. Returns the original, so any changes will be live.
  601. /// </summary>
  602. /// <param name="itemID"></param>
  603. /// <returns>null if the item does not exist</returns>
  604. public TaskInventoryItem GetInventoryItem(UUID itemId)
  605. {
  606. TaskInventoryItem item;
  607. lock (m_items)
  608. m_items.TryGetValue(itemId, out item);
  609. return item;
  610. }
  611. public TaskInventoryItem GetInventoryItem(string name)
  612. {
  613. lock (m_items)
  614. {
  615. foreach (TaskInventoryItem item in m_items.Values)
  616. {
  617. if (item.Name == name)
  618. return item;
  619. }
  620. }
  621. return null;
  622. }
  623. public List<TaskInventoryItem> GetInventoryItems(string name)
  624. {
  625. List<TaskInventoryItem> items = new List<TaskInventoryItem>();
  626. lock (m_items)
  627. {
  628. foreach (TaskInventoryItem item in m_items.Values)
  629. {
  630. if (item.Name == name)
  631. items.Add(item);
  632. }
  633. }
  634. return items;
  635. }
  636. public bool GetRezReadySceneObjects(TaskInventoryItem item, out List<SceneObjectGroup> objlist, out List<Vector3> veclist)
  637. {
  638. AssetBase rezAsset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString());
  639. if (null == rezAsset)
  640. {
  641. m_log.WarnFormat(
  642. "[PRIM INVENTORY]: Could not find asset {0} for inventory item {1} in {2}",
  643. item.AssetID, item.Name, m_part.Name);
  644. objlist = null;
  645. veclist = null;
  646. return false;
  647. }
  648. Vector3 bbox;
  649. float offsetHeight;
  650. bool single = m_part.ParentGroup.Scene.GetObjectsToRez(rezAsset.Data, false, out objlist, out veclist, out bbox, out offsetHeight);
  651. for (int i = 0; i < objlist.Count; i++)
  652. {
  653. SceneObjectGroup group = objlist[i];
  654. group.ResetIDs();
  655. SceneObjectPart rootPart = group.GetPart(group.UUID);
  656. // Since renaming the item in the inventory does not affect the name stored
  657. // in the serialization, transfer the correct name from the inventory to the
  658. // object itself before we rez.
  659. // Only do these for the first object if we are rezzing a coalescence.
  660. if (i == 0)
  661. {
  662. rootPart.Name = item.Name;
  663. rootPart.Description = item.Description;
  664. }
  665. group.SetGroup(m_part.GroupID, null);
  666. foreach (SceneObjectPart part in group.Parts)
  667. {
  668. // Convert between InventoryItem classes. You can never have too many similar but slightly different classes :)
  669. InventoryItemBase dest = new InventoryItemBase(item.ItemID, item.OwnerID);
  670. dest.BasePermissions = item.BasePermissions;
  671. dest.CurrentPermissions = item.CurrentPermissions;
  672. dest.EveryOnePermissions = item.EveryonePermissions;
  673. dest.GroupPermissions = item.GroupPermissions;
  674. dest.NextPermissions = item.NextPermissions;
  675. dest.Flags = item.Flags;
  676. part.ApplyPermissionsOnRez(dest, false, m_part.ParentGroup.Scene);
  677. }
  678. rootPart.TrimPermissions();
  679. }
  680. return true;
  681. }
  682. /// <summary>
  683. /// Update an existing inventory item.
  684. /// </summary>
  685. /// <param name="item">The updated item. An item with the same id must already exist
  686. /// in this prim's inventory.</param>
  687. /// <returns>false if the item did not exist, true if the update occurred successfully</returns>
  688. public bool UpdateInventoryItem(TaskInventoryItem item)
  689. {
  690. return UpdateInventoryItem(item, true, true);
  691. }
  692. public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents)
  693. {
  694. return UpdateInventoryItem(item, fireScriptEvents, true);
  695. }
  696. public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents, bool considerChanged)
  697. {
  698. TaskInventoryItem it = GetInventoryItem(item.ItemID);
  699. if (it != null)
  700. {
  701. // m_log.DebugFormat("[PRIM INVENTORY]: Updating item {0} in {1}", item.Name, m_part.Name);
  702. item.ParentID = m_part.UUID;
  703. item.ParentPartID = m_part.UUID;
  704. // If group permissions have been set on, check that the groupID is up to date in case it has
  705. // changed since permissions were last set.
  706. if (item.GroupPermissions != (uint)PermissionMask.None)
  707. item.GroupID = m_part.GroupID;
  708. if (item.AssetID == UUID.Zero)
  709. item.AssetID = it.AssetID;
  710. lock (m_items)
  711. {
  712. m_items[item.ItemID] = item;
  713. m_inventorySerial++;
  714. }
  715. if (fireScriptEvents)
  716. m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
  717. if (considerChanged)
  718. {
  719. HasInventoryChanged = true;
  720. m_part.ParentGroup.HasGroupChanged = true;
  721. }
  722. return true;
  723. }
  724. else
  725. {
  726. m_log.ErrorFormat(
  727. "[PRIM INVENTORY]: " +
  728. "Tried to retrieve item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory",
  729. item.ItemID, m_part.Name, m_part.UUID,
  730. m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
  731. }
  732. return false;
  733. }
  734. /// <summary>
  735. /// Remove an item from this prim's inventory
  736. /// </summary>
  737. /// <param name="itemID"></param>
  738. /// <returns>Numeric asset type of the item removed. Returns -1 if the item did not exist
  739. /// in this prim's inventory.</returns>
  740. public int RemoveInventoryItem(UUID itemID)
  741. {
  742. TaskInventoryItem item = GetInventoryItem(itemID);
  743. if (item != null)
  744. {
  745. int type = m_items[itemID].InvType;
  746. if (type == 10) // Script
  747. {
  748. m_part.RemoveScriptEvents(itemID);
  749. m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID);
  750. }
  751. m_items.Remove(itemID);
  752. m_inventorySerial++;
  753. m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
  754. HasInventoryChanged = true;
  755. m_part.ParentGroup.HasGroupChanged = true;
  756. if (!ContainsScripts())
  757. m_part.RemFlag(PrimFlags.Scripted);
  758. m_part.ScheduleFullUpdate();
  759. return type;
  760. }
  761. else
  762. {
  763. m_log.ErrorFormat(
  764. "[PRIM INVENTORY]: " +
  765. "Tried to remove item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory",
  766. itemID, m_part.Name, m_part.UUID,
  767. m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
  768. }
  769. return -1;
  770. }
  771. private bool CreateInventoryFile()
  772. {
  773. // m_log.DebugFormat(
  774. // "[PRIM INVENTORY]: Creating inventory file for {0} {1} {2}, serial {3}",
  775. // m_part.Name, m_part.UUID, m_part.LocalId, m_inventorySerial);
  776. if (m_inventoryFileName == String.Empty ||
  777. m_inventoryFileNameSerial < m_inventorySerial)
  778. {
  779. // Something changed, we need to create a new file
  780. m_inventoryFileName = "inventory_" + UUID.Random().ToString() + ".tmp";
  781. m_inventoryFileNameSerial = m_inventorySerial;
  782. InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero);
  783. lock (m_items)
  784. {
  785. foreach (TaskInventoryItem item in m_items.Values)
  786. {
  787. // m_log.DebugFormat(
  788. // "[PRIM INVENTORY]: Adding item {0} {1} for serial {2} on prim {3} {4} {5}",
  789. // item.Name, item.ItemID, m_inventorySerial, m_part.Name, m_part.UUID, m_part.LocalId);
  790. UUID ownerID = item.OwnerID;
  791. uint everyoneMask = 0;
  792. uint baseMask = item.BasePermissions;
  793. uint ownerMask = item.CurrentPermissions;
  794. uint groupMask = item.GroupPermissions;
  795. invString.AddItemStart();
  796. invString.AddNameValueLine("item_id", item.ItemID.ToString());
  797. invString.AddNameValueLine("parent_id", m_part.UUID.ToString());
  798. invString.AddPermissionsStart();
  799. invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask));
  800. invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask));
  801. invString.AddNameValueLine("group_mask", Utils.UIntToHexString(groupMask));
  802. invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask));
  803. invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions));
  804. invString.AddNameValueLine("creator_id", item.CreatorID.ToString());
  805. invString.AddNameValueLine("owner_id", ownerID.ToString());
  806. invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString());
  807. invString.AddNameValueLine("group_id", item.GroupID.ToString());
  808. invString.AddSectionEnd();
  809. invString.AddNameValueLine("asset_id", item.AssetID.ToString());
  810. invString.AddNameValueLine("type", Utils.AssetTypeToString((AssetType)item.Type));
  811. invString.AddNameValueLine("inv_type", Utils.InventoryTypeToString((InventoryType)item.InvType));
  812. invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags));
  813. invString.AddSaleStart();
  814. invString.AddNameValueLine("sale_type", "not");
  815. invString.AddNameValueLine("sale_price", "0");
  816. invString.AddSectionEnd();
  817. invString.AddNameValueLine("name", item.Name + "|");
  818. invString.AddNameValueLine("desc", item.Description + "|");
  819. invString.AddNameValueLine("creation_date", item.CreationDate.ToString());
  820. invString.AddSectionEnd();
  821. }
  822. }
  823. m_inventoryFileData = Utils.StringToBytes(invString.BuildString);
  824. return true;
  825. }
  826. // No need to recreate, the existing file is fine
  827. return false;
  828. }
  829. /// <summary>
  830. /// Serialize all the metadata for the items in this prim's inventory ready for sending to the client
  831. /// </summary>
  832. /// <param name="xferManager"></param>
  833. public void RequestInventoryFile(IClientAPI client, IXfer xferManager)
  834. {
  835. lock (m_items)
  836. {
  837. // Don't send a inventory xfer name if there are no items. Doing so causes viewer 3 to crash when rezzing
  838. // a new script if any previous deletion has left the prim inventory empty.
  839. if (m_items.Count == 0) // No inventory
  840. {
  841. // m_log.DebugFormat(
  842. // "[PRIM INVENTORY]: Not sending inventory data for part {0} {1} {2} for {3} since no items",
  843. // m_part.Name, m_part.LocalId, m_part.UUID, client.Name);
  844. client.SendTaskInventory(m_part.UUID, 0, new byte[0]);
  845. return;
  846. }
  847. CreateInventoryFile();
  848. // In principle, we should only do the rest if the inventory changed;
  849. // by sending m_inventorySerial to the client, it ought to know
  850. // that nothing changed and that it doesn't need to request the file.
  851. // Unfortunately, it doesn't look like the client optimizes this;
  852. // the client seems to always come back and request the Xfer,
  853. // no matter what value m_inventorySerial has.
  854. // FIXME: Could probably be > 0 here rather than > 2
  855. if (m_inventoryFileData.Length > 2)
  856. {
  857. // Add the file for Xfer
  858. // m_log.DebugFormat(
  859. // "[PRIM INVENTORY]: Adding inventory file {0} (length {1}) for transfer on {2} {3} {4}",
  860. // m_inventoryFileName, m_inventoryFileData.Length, m_part.Name, m_part.UUID, m_part.LocalId);
  861. xferManager.AddNewFile(m_inventoryFileName, m_inventoryFileData);
  862. }
  863. // Tell the client we're ready to Xfer the file
  864. client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial,
  865. Util.StringToBytes256(m_inventoryFileName));
  866. }
  867. }
  868. /// <summary>
  869. /// Process inventory backup
  870. /// </summary>
  871. /// <param name="datastore"></param>
  872. public void ProcessInventoryBackup(ISimulationDataService datastore)
  873. {
  874. if (HasInventoryChanged)
  875. {
  876. HasInventoryChanged = false;
  877. List<TaskInventoryItem> items = GetInventoryItems();
  878. datastore.StorePrimInventory(m_part.UUID, items);
  879. }
  880. }
  881. public class InventoryStringBuilder
  882. {
  883. public string BuildString = String.Empty;
  884. public InventoryStringBuilder(UUID folderID, UUID parentID)
  885. {
  886. BuildString += "\tinv_object\t0\n\t{\n";
  887. AddNameValueLine("obj_id", folderID.ToString());
  888. AddNameValueLine("parent_id", parentID.ToString());
  889. AddNameValueLine("type", "category");
  890. AddNameValueLine("name", "Contents|");
  891. AddSectionEnd();
  892. }
  893. public void AddItemStart()
  894. {
  895. BuildString += "\tinv_item\t0\n";
  896. AddSectionStart();
  897. }
  898. public void AddPermissionsStart()
  899. {
  900. BuildString += "\tpermissions 0\n";
  901. AddSectionStart();
  902. }
  903. public void AddSaleStart()
  904. {
  905. BuildString += "\tsale_info\t0\n";
  906. AddSectionStart();
  907. }
  908. protected void AddSectionStart()
  909. {
  910. BuildString += "\t{\n";
  911. }
  912. public void AddSectionEnd()
  913. {
  914. BuildString += "\t}\n";
  915. }
  916. public void AddLine(string addLine)
  917. {
  918. BuildString += addLine;
  919. }
  920. public void AddNameValueLine(string name, string value)
  921. {
  922. BuildString += "\t\t";
  923. BuildString += name + "\t";
  924. BuildString += value + "\n";
  925. }
  926. public void Close()
  927. {
  928. }
  929. }
  930. public uint MaskEffectivePermissions()
  931. {
  932. uint mask=0x7fffffff;
  933. lock (m_items)
  934. {
  935. foreach (TaskInventoryItem item in m_items.Values)
  936. {
  937. if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0)
  938. mask &= ~((uint)PermissionMask.Copy >> 13);
  939. if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0)
  940. mask &= ~((uint)PermissionMask.Transfer >> 13);
  941. if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0)
  942. mask &= ~((uint)PermissionMask.Modify >> 13);
  943. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  944. mask &= ~(uint)PermissionMask.Copy;
  945. if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
  946. mask &= ~(uint)PermissionMask.Transfer;
  947. if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
  948. mask &= ~(uint)PermissionMask.Modify;
  949. }
  950. }
  951. return mask;
  952. }
  953. public void ApplyNextOwnerPermissions()
  954. {
  955. lock (m_items)
  956. {
  957. foreach (TaskInventoryItem item in m_items.Values)
  958. {
  959. // m_log.DebugFormat (
  960. // "[SCENE OBJECT PART INVENTORY]: Applying next permissions {0} to {1} in {2} with current {3}, base {4}, everyone {5}",
  961. // item.NextPermissions, item.Name, m_part.Name, item.CurrentPermissions, item.BasePermissions, item.EveryonePermissions);
  962. if (item.InvType == (int)InventoryType.Object)
  963. {
  964. uint perms = item.CurrentPermissions;
  965. PermissionsUtil.ApplyFoldedPermissions(perms, ref perms);
  966. item.CurrentPermissions = perms;
  967. }
  968. item.CurrentPermissions &= item.NextPermissions;
  969. item.BasePermissions &= item.NextPermissions;
  970. item.EveryonePermissions &= item.NextPermissions;
  971. item.OwnerChanged = true;
  972. item.PermsMask = 0;
  973. item.PermsGranter = UUID.Zero;
  974. }
  975. }
  976. }
  977. public void ApplyGodPermissions(uint perms)
  978. {
  979. lock (m_items)
  980. {
  981. foreach (TaskInventoryItem item in m_items.Values)
  982. {
  983. item.CurrentPermissions = perms;
  984. item.BasePermissions = perms;
  985. }
  986. }
  987. m_inventorySerial++;
  988. HasInventoryChanged = true;
  989. }
  990. /// <summary>
  991. /// Returns true if this part inventory contains any scripts. False otherwise.
  992. /// </summary>
  993. /// <returns></returns>
  994. public bool ContainsScripts()
  995. {
  996. lock (m_items)
  997. {
  998. foreach (TaskInventoryItem item in m_items.Values)
  999. {
  1000. if (item.InvType == (int)InventoryType.LSL)
  1001. {
  1002. return true;
  1003. }
  1004. }
  1005. }
  1006. return false;
  1007. }
  1008. /// <summary>
  1009. /// Returns the count of scripts in this parts inventory.
  1010. /// </summary>
  1011. /// <returns></returns>
  1012. public int ScriptCount()
  1013. {
  1014. int count = 0;
  1015. lock (m_items)
  1016. {
  1017. foreach (TaskInventoryItem item in m_items.Values)
  1018. {
  1019. if (item.InvType == (int)InventoryType.LSL)
  1020. {
  1021. count++;
  1022. }
  1023. }
  1024. }
  1025. return count;
  1026. }
  1027. /// <summary>
  1028. /// Returns the count of running scripts in this parts inventory.
  1029. /// </summary>
  1030. /// <returns></returns>
  1031. public int RunningScriptCount()
  1032. {
  1033. IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
  1034. if (engines.Length == 0)
  1035. return 0;
  1036. int count = 0;
  1037. List<TaskInventoryItem> scripts = GetInventoryItems(InventoryType.LSL);
  1038. foreach (TaskInventoryItem item in scripts)
  1039. {
  1040. foreach (IScriptModule engine in engines)
  1041. {
  1042. if (engine != null)
  1043. {
  1044. if (engine.GetScriptState(item.ItemID))
  1045. {
  1046. count++;
  1047. }
  1048. }
  1049. }
  1050. }
  1051. return count;
  1052. }
  1053. public List<UUID> GetInventoryList()
  1054. {
  1055. List<UUID> ret = new List<UUID>();
  1056. lock (m_items)
  1057. {
  1058. foreach (TaskInventoryItem item in m_items.Values)
  1059. ret.Add(item.ItemID);
  1060. }
  1061. return ret;
  1062. }
  1063. public List<TaskInventoryItem> GetInventoryItems()
  1064. {
  1065. List<TaskInventoryItem> ret = new List<TaskInventoryItem>();
  1066. lock (m_items)
  1067. ret = new List<TaskInventoryItem>(m_items.Values);
  1068. return ret;
  1069. }
  1070. public List<TaskInventoryItem> GetInventoryItems(InventoryType type)
  1071. {
  1072. List<TaskInventoryItem> ret = new List<TaskInventoryItem>();
  1073. lock (m_items)
  1074. {
  1075. foreach (TaskInventoryItem item in m_items.Values)
  1076. if (item.InvType == (int)type)
  1077. ret.Add(item);
  1078. }
  1079. return ret;
  1080. }
  1081. public Dictionary<UUID, string> GetScriptStates()
  1082. {
  1083. Dictionary<UUID, string> ret = new Dictionary<UUID, string>();
  1084. if (m_part.ParentGroup.Scene == null) // Group not in a scene
  1085. return ret;
  1086. IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
  1087. if (engines.Length == 0) // No engine at all
  1088. return ret;
  1089. List<TaskInventoryItem> scripts = GetInventoryItems(InventoryType.LSL);
  1090. foreach (TaskInventoryItem item in scripts)
  1091. {
  1092. foreach (IScriptModule e in engines)
  1093. {
  1094. if (e != null)
  1095. {
  1096. // m_log.DebugFormat(
  1097. // "[PRIM INVENTORY]: Getting script state from engine {0} for {1} in part {2} in group {3} in {4}",
  1098. // e.Name, item.Name, m_part.Name, m_part.ParentGroup.Name, m_part.ParentGroup.Scene.Name);
  1099. string n = e.GetXMLState(item.ItemID);
  1100. if (n != String.Empty)
  1101. {
  1102. if (!ret.ContainsKey(item.ItemID))
  1103. ret[item.ItemID] = n;
  1104. break;
  1105. }
  1106. }
  1107. }
  1108. }
  1109. return ret;
  1110. }
  1111. public void ResumeScripts()
  1112. {
  1113. IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
  1114. if (engines.Length == 0)
  1115. return;
  1116. List<TaskInventoryItem> scripts = GetInventoryItems(InventoryType.LSL);
  1117. foreach (TaskInventoryItem item in scripts)
  1118. {
  1119. foreach (IScriptModule engine in engines)
  1120. {
  1121. if (engine != null)
  1122. {
  1123. // m_log.DebugFormat(
  1124. // "[PRIM INVENTORY]: Resuming script {0} {1} for {2}, OwnerChanged {3}",
  1125. // item.Name, item.ItemID, item.OwnerID, item.OwnerChanged);
  1126. engine.ResumeScript(item.ItemID);
  1127. if (item.OwnerChanged)
  1128. engine.PostScriptEvent(item.ItemID, "changed", new Object[] { (int)Changed.OWNER });
  1129. item.OwnerChanged = false;
  1130. }
  1131. }
  1132. }
  1133. }
  1134. }
  1135. }