SceneObjectPart.Inventory.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  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 OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using libsecondlife;
  31. using log4net;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Communications.Cache;
  34. using OpenSim.Region.Environment.Interfaces;
  35. using OpenSim.Region.Environment.Scenes.Scripting;
  36. namespace OpenSim.Region.Environment.Scenes
  37. {
  38. public partial class SceneObjectPart : IScriptHost
  39. {
  40. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  41. private string m_inventoryFileName = String.Empty;
  42. private int m_inventoryFileNameSerial = 0;
  43. /// <summary>
  44. /// Exposing this is not particularly good, but it's one of the least evils at the moment to see
  45. /// folder id from prim inventory item data, since it's not (yet) actually stored with the prim.
  46. /// </summary>
  47. public LLUUID FolderID
  48. {
  49. get { return UUID; }
  50. set { } // Don't allow assignment, or legacy prims wil b0rk
  51. }
  52. /// <summary>
  53. /// Serial count for inventory file , used to tell if inventory has changed
  54. /// no need for this to be part of Database backup
  55. /// </summary>
  56. protected uint m_inventorySerial = 0;
  57. public uint InventorySerial
  58. {
  59. get { return m_inventorySerial; }
  60. set { m_inventorySerial = value; }
  61. }
  62. /// <summary>
  63. /// Holds in memory prim inventory
  64. /// </summary>
  65. protected TaskInventoryDictionary m_taskInventory = new TaskInventoryDictionary();
  66. public TaskInventoryDictionary TaskInventory
  67. {
  68. get { return m_taskInventory; }
  69. set { m_taskInventory = value; }
  70. }
  71. /// <summary>
  72. /// Tracks whether inventory has changed since the last persistent backup
  73. /// </summary>
  74. private bool HasInventoryChanged;
  75. /// <summary>
  76. /// Reset LLUUIDs for all the items in the prim's inventory. This involves either generating
  77. /// new ones or setting existing UUIDs to the correct parent UUIDs.
  78. ///
  79. /// If this method is called and there are inventory items, then we regard the inventory as having changed.
  80. /// </summary>
  81. /// <param name="linkNum">Link number for the part</param>
  82. public void ResetInventoryIDs()
  83. {
  84. lock (TaskInventory)
  85. {
  86. if (0 == TaskInventory.Count)
  87. {
  88. return;
  89. }
  90. HasInventoryChanged = true;
  91. ParentGroup.HasGroupChanged = true;
  92. IList<TaskInventoryItem> items = new List<TaskInventoryItem>(TaskInventory.Values);
  93. TaskInventory.Clear();
  94. foreach (TaskInventoryItem item in items)
  95. {
  96. item.ResetIDs(UUID);
  97. TaskInventory.Add(item.ItemID, item);
  98. }
  99. }
  100. }
  101. public void ChangeInventoryOwner(LLUUID ownerId)
  102. {
  103. lock (TaskInventory)
  104. {
  105. if (0 == TaskInventory.Count)
  106. {
  107. return;
  108. }
  109. HasInventoryChanged = true;
  110. ParentGroup.HasGroupChanged = true;
  111. IList<TaskInventoryItem> items = new List<TaskInventoryItem>(TaskInventory.Values);
  112. foreach (TaskInventoryItem item in items)
  113. {
  114. if (ownerId != item.OwnerID)
  115. {
  116. item.LastOwnerID = item.OwnerID;
  117. item.OwnerID = ownerId;
  118. }
  119. }
  120. }
  121. }
  122. /// <summary>
  123. /// Start all the scripts contained in this prim's inventory
  124. /// </summary>
  125. public void StartScripts()
  126. {
  127. lock (m_taskInventory)
  128. {
  129. foreach (TaskInventoryItem item in m_taskInventory.Values)
  130. {
  131. // XXX more hardcoding badness. Should be an enum in TaskInventoryItem
  132. if (10 == item.Type)
  133. {
  134. StartScript(item);
  135. }
  136. }
  137. }
  138. }
  139. /// <summary>
  140. /// Stop all the scripts in this prim.
  141. /// </summary>
  142. public void StopScripts()
  143. {
  144. lock (m_taskInventory)
  145. {
  146. foreach (TaskInventoryItem item in m_taskInventory.Values)
  147. {
  148. if (10 == item.Type)
  149. {
  150. StopScript(item.ItemID);
  151. RemoveScriptEvents(item.ItemID);
  152. }
  153. }
  154. }
  155. }
  156. /// <summary>
  157. /// Start a script which is in this prim's inventory.
  158. /// </summary>
  159. /// <param name="item"></param>
  160. /// <returns></returns>
  161. public void StartScript(TaskInventoryItem item)
  162. {
  163. // m_log.InfoFormat(
  164. // "[PRIM INVENTORY]: " +
  165. // "Starting script {0}, {1} in prim {2}, {3}",
  166. // item.Name, item.ItemID, Name, UUID);
  167. AddFlag(LLObject.ObjectFlags.Scripted);
  168. if (!((m_parentGroup.Scene.RegionInfo.EstateSettings.regionFlags & Simulator.RegionFlags.SkipScripts) == Simulator.RegionFlags.SkipScripts))
  169. {
  170. AssetCache cache = m_parentGroup.Scene.AssetCache;
  171. cache.GetAsset(item.AssetID, delegate(LLUUID assetID, AssetBase asset)
  172. {
  173. if (null == asset)
  174. {
  175. m_log.ErrorFormat(
  176. "[PRIM INVENTORY]: " +
  177. "Couldn't start script {0}, {1} since asset ID {2} could not be found",
  178. item.Name, item.ItemID, item.AssetID);
  179. }
  180. else
  181. {
  182. string script = Helpers.FieldToUTF8String(asset.Data);
  183. m_parentGroup.Scene.EventManager.TriggerRezScript(LocalId,item.ItemID,script);
  184. m_parentGroup.AddActiveScriptCount(1);
  185. ScheduleFullUpdate();
  186. }
  187. }, false);
  188. }
  189. }
  190. /// <summary>
  191. /// Start a script which is in this prim's inventory.
  192. /// </summary>
  193. /// <param name="itemId">
  194. /// A <see cref="LLUUID"/>
  195. /// </param>
  196. public void StartScript(LLUUID itemId)
  197. {
  198. lock (m_taskInventory)
  199. {
  200. if (m_taskInventory.ContainsKey(itemId))
  201. {
  202. StartScript(m_taskInventory[itemId]);
  203. }
  204. else
  205. {
  206. m_log.ErrorFormat(
  207. "[PRIM INVENTORY]: " +
  208. "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2}",
  209. itemId, Name, UUID);
  210. }
  211. }
  212. }
  213. /// <summary>
  214. /// Stop a script which is in this prim's inventory.
  215. /// </summary>
  216. /// <param name="itemId"></param>
  217. public void StopScript(LLUUID itemId)
  218. {
  219. if (m_taskInventory.ContainsKey(itemId))
  220. {
  221. m_parentGroup.Scene.EventManager.TriggerRemoveScript(LocalId, itemId);
  222. m_parentGroup.AddActiveScriptCount(-1);
  223. }
  224. else
  225. {
  226. m_log.ErrorFormat(
  227. "[PRIM INVENTORY]: " +
  228. "Couldn't stop script with ID {0} since it couldn't be found for prim {1}, {2}",
  229. itemId, Name, UUID);
  230. }
  231. }
  232. // Assumes a lock is held on the inventory
  233. private bool InventoryContainsName(string name)
  234. {
  235. foreach (TaskInventoryItem item in m_taskInventory.Values)
  236. {
  237. if (item.Name == name)
  238. return true;
  239. }
  240. return false;
  241. }
  242. private string FindAvailableInventoryName(string name)
  243. {
  244. if (!InventoryContainsName(name))
  245. return name;
  246. int suffix=1;
  247. while (suffix < 256)
  248. {
  249. string tryName=String.Format("{0} {1}", name, suffix);
  250. if (!InventoryContainsName(tryName))
  251. return tryName;
  252. suffix++;
  253. }
  254. return String.Empty;
  255. }
  256. /// <summary>
  257. /// Add an item to this prim's inventory.
  258. /// </summary>
  259. /// <param name="item"></param>
  260. public void AddInventoryItem(TaskInventoryItem item)
  261. {
  262. item.ParentID = UUID;
  263. item.ParentPartID = UUID;
  264. string name=FindAvailableInventoryName(item.Name);
  265. if (name == String.Empty)
  266. return;
  267. item.Name=name;
  268. lock (m_taskInventory)
  269. {
  270. m_taskInventory.Add(item.ItemID, item);
  271. TriggerScriptChangedEvent(Changed.INVENTORY);
  272. }
  273. m_inventorySerial++;
  274. //m_inventorySerial += 2;
  275. HasInventoryChanged = true;
  276. ParentGroup.HasGroupChanged = true;
  277. }
  278. /// <summary>
  279. /// Restore a whole collection of items to the prim's inventory at once.
  280. /// We assume that the items already have all their fields correctly filled out.
  281. /// The items are not flagged for persistence to the database, since they are being restored
  282. /// from persistence rather than being newly added.
  283. /// </summary>
  284. /// <param name="items"></param>
  285. public void RestoreInventoryItems(ICollection<TaskInventoryItem> items)
  286. {
  287. lock (m_taskInventory)
  288. {
  289. foreach (TaskInventoryItem item in items)
  290. {
  291. m_taskInventory.Add(item.ItemID, item);
  292. TriggerScriptChangedEvent(Changed.INVENTORY);
  293. }
  294. }
  295. m_inventorySerial++;
  296. }
  297. /// <summary>
  298. /// Returns an existing inventory item. Returns the original, so any changes will be live.
  299. /// </summary>
  300. /// <param name="itemID"></param>
  301. /// <returns>null if the item does not exist</returns>
  302. public TaskInventoryItem GetInventoryItem(LLUUID itemID)
  303. {
  304. lock (m_taskInventory)
  305. {
  306. if (m_taskInventory.ContainsKey(itemID))
  307. {
  308. // m_log.DebugFormat(
  309. // "[PRIM INVENTORY]: Retrieved task inventory item {0}, {1} from prim {2}, {3}",
  310. // m_taskInventory[itemID].Name, itemID, Name, UUID);
  311. return m_taskInventory[itemID];
  312. }
  313. else
  314. {
  315. m_log.ErrorFormat(
  316. "[PRIM INVENTORY]: " +
  317. "Tried to retrieve item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
  318. itemID, Name, UUID);
  319. }
  320. }
  321. return null;
  322. }
  323. /// <summary>
  324. /// Update an existing inventory item.
  325. /// </summary>
  326. /// <param name="item">The updated item. An item with the same id must already exist
  327. /// in this prim's inventory.</param>
  328. /// <returns>false if the item did not exist, true if the update occurred succesfully</returns>
  329. public bool UpdateInventoryItem(TaskInventoryItem item)
  330. {
  331. lock (m_taskInventory)
  332. {
  333. if (m_taskInventory.ContainsKey(item.ItemID))
  334. {
  335. item.ParentID = UUID;
  336. item.ParentPartID = UUID;
  337. item.Flags=m_taskInventory[item.ItemID].Flags;
  338. m_taskInventory[item.ItemID] = item;
  339. m_inventorySerial++;
  340. TriggerScriptChangedEvent(Changed.INVENTORY);
  341. HasInventoryChanged = true;
  342. ParentGroup.HasGroupChanged = true;
  343. return true;
  344. }
  345. else
  346. {
  347. m_log.ErrorFormat(
  348. "[PRIM INVENTORY]: " +
  349. "Tried to retrieve item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
  350. item.ItemID, Name, UUID);
  351. }
  352. }
  353. return false;
  354. }
  355. public void AddScriptLPS(int count)
  356. {
  357. m_parentGroup.AddScriptLPS(count);
  358. }
  359. /// <summary>
  360. /// Remove an item from this prim's inventory
  361. /// </summary>
  362. /// <param name="itemID"></param>
  363. /// <returns>Numeric asset type of the item removed. Returns -1 if the item did not exist
  364. /// in this prim's inventory.</returns>
  365. public int RemoveInventoryItem(LLUUID itemID)
  366. {
  367. lock (m_taskInventory)
  368. {
  369. if (m_taskInventory.ContainsKey(itemID))
  370. {
  371. int type = m_taskInventory[itemID].InvType;
  372. m_taskInventory.Remove(itemID);
  373. m_inventorySerial++;
  374. TriggerScriptChangedEvent(Changed.INVENTORY);
  375. HasInventoryChanged = true;
  376. ParentGroup.HasGroupChanged = true;
  377. int scriptcount = 0;
  378. lock (m_taskInventory)
  379. {
  380. foreach (TaskInventoryItem item in m_taskInventory.Values)
  381. {
  382. if (item.Type == 10)
  383. {
  384. scriptcount++;
  385. }
  386. }
  387. }
  388. if (scriptcount <= 0)
  389. {
  390. RemFlag(LLObject.ObjectFlags.Scripted);
  391. ScheduleFullUpdate();
  392. }
  393. ScheduleFullUpdate();
  394. return type;
  395. }
  396. else
  397. {
  398. m_log.ErrorFormat(
  399. "[PRIM INVENTORY]: " +
  400. "Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
  401. itemID, Name, UUID);
  402. }
  403. }
  404. return -1;
  405. }
  406. public string GetInventoryFileName()
  407. {
  408. if (m_inventoryFileName == String.Empty)
  409. m_inventoryFileName = "inventory_" + LLUUID.Random().ToString() + ".tmp";
  410. if (m_inventoryFileNameSerial < m_inventorySerial)
  411. {
  412. m_inventoryFileName = "inventory_" + LLUUID.Random().ToString() + ".tmp";
  413. }
  414. return m_inventoryFileName;
  415. }
  416. /// <summary>
  417. /// Return the name with which a client can request a xfer of this prim's inventory metadata
  418. /// </summary>
  419. /// <param name="client"></param>
  420. /// <param name="localID"></param>
  421. public bool GetInventoryFileName(IClientAPI client, uint localID)
  422. {
  423. // m_log.DebugFormat(
  424. // "[PRIM INVENTORY]: Received request from client {0} for inventory file name of {1}, {2}",
  425. // client.AgentId, Name, UUID);
  426. if (m_inventorySerial > 0)
  427. {
  428. client.SendTaskInventory(m_uuid, (short)m_inventorySerial,
  429. Helpers.StringToField(GetInventoryFileName()));
  430. return true;
  431. }
  432. else
  433. {
  434. client.SendTaskInventory(m_uuid, 0, new byte[0]);
  435. return false;
  436. }
  437. }
  438. /// <summary>
  439. /// Serialize all the metadata for the items in this prim's inventory ready for sending to the client
  440. /// </summary>
  441. /// <param name="xferManager"></param>
  442. public void RequestInventoryFile(IClientAPI client, IXfer xferManager)
  443. {
  444. byte[] fileData = new byte[0];
  445. // Confusingly, the folder item has to be the object id, while the 'parent id' has to be zero. This matches
  446. // what appears to happen in the Second Life protocol. If this isn't the case. then various functionality
  447. // isn't available (such as drag from prim inventory to agent inventory)
  448. InventoryStringBuilder invString = new InventoryStringBuilder(UUID, LLUUID.Zero);
  449. lock (m_taskInventory)
  450. {
  451. foreach (TaskInventoryItem item in m_taskInventory.Values)
  452. {
  453. LLUUID ownerID = item.OwnerID;
  454. uint everyoneMask = 0;
  455. uint baseMask = item.BaseMask;
  456. uint ownerMask = item.OwnerMask;
  457. if (item.InvType == 10) // Script
  458. {
  459. if ((item.OwnerID != client.AgentId) && m_parentGroup.Scene.ExternalChecks.ExternalChecksCanViewScript(item.ItemID, UUID, client.AgentId))
  460. {
  461. ownerID = client.AgentId;
  462. baseMask = 0x7fffffff;
  463. ownerMask = 0x7fffffff;
  464. everyoneMask = (uint)(PermissionMask.Move | PermissionMask.Transfer);
  465. }
  466. if ((item.OwnerID != client.AgentId) && m_parentGroup.Scene.ExternalChecks.ExternalChecksCanEditScript(item.ItemID, UUID, client.AgentId))
  467. {
  468. ownerID = client.AgentId;
  469. baseMask = 0x7fffffff;
  470. ownerMask = 0x7fffffff;
  471. everyoneMask = (uint)(PermissionMask.Move | PermissionMask.Transfer | PermissionMask.Modify);
  472. }
  473. }
  474. invString.AddItemStart();
  475. invString.AddNameValueLine("item_id", item.ItemID.ToString());
  476. invString.AddNameValueLine("parent_id", UUID.ToString());
  477. invString.AddPermissionsStart();
  478. invString.AddNameValueLine("base_mask", Helpers.UIntToHexString(baseMask));
  479. invString.AddNameValueLine("owner_mask", Helpers.UIntToHexString(ownerMask));
  480. invString.AddNameValueLine("group_mask", Helpers.UIntToHexString(0));
  481. invString.AddNameValueLine("everyone_mask", Helpers.UIntToHexString(everyoneMask));
  482. invString.AddNameValueLine("next_owner_mask", Helpers.UIntToHexString(item.NextOwnerMask));
  483. invString.AddNameValueLine("creator_id", item.CreatorID.ToString());
  484. invString.AddNameValueLine("owner_id", ownerID.ToString());
  485. invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString());
  486. invString.AddNameValueLine("group_id", item.GroupID.ToString());
  487. invString.AddSectionEnd();
  488. invString.AddNameValueLine("asset_id", item.AssetID.ToString());
  489. invString.AddNameValueLine("type", TaskInventoryItem.Types[item.Type]);
  490. invString.AddNameValueLine("inv_type", TaskInventoryItem.InvTypes[item.InvType]);
  491. invString.AddNameValueLine("flags", Helpers.UIntToHexString(item.Flags));
  492. invString.AddSaleStart();
  493. invString.AddNameValueLine("sale_type", "not");
  494. invString.AddNameValueLine("sale_price", "0");
  495. invString.AddSectionEnd();
  496. invString.AddNameValueLine("name", item.Name + "|");
  497. invString.AddNameValueLine("desc", item.Description + "|");
  498. invString.AddNameValueLine("creation_date", item.CreationDate.ToString());
  499. invString.AddSectionEnd();
  500. }
  501. }
  502. fileData = Helpers.StringToField(invString.BuildString);
  503. //Console.WriteLine(Helpers.FieldToUTF8String(fileData));
  504. //m_log.Debug("[PRIM INVENTORY]: RequestInventoryFile fileData: " + Helpers.FieldToUTF8String(fileData));
  505. if (fileData.Length > 2)
  506. {
  507. xferManager.AddNewFile(m_inventoryFileName, fileData);
  508. }
  509. }
  510. /// <summary>
  511. /// Process inventory backup
  512. /// </summary>
  513. /// <param name="datastore"></param>
  514. public void ProcessInventoryBackup(IRegionDataStore datastore)
  515. {
  516. if (HasInventoryChanged)
  517. {
  518. lock (TaskInventory)
  519. {
  520. datastore.StorePrimInventory(UUID, TaskInventory.Values);
  521. }
  522. HasInventoryChanged = false;
  523. }
  524. }
  525. public class InventoryStringBuilder
  526. {
  527. public string BuildString = String.Empty;
  528. public InventoryStringBuilder(LLUUID folderID, LLUUID parentID)
  529. {
  530. BuildString += "\tinv_object\t0\n\t{\n";
  531. AddNameValueLine("obj_id", folderID.ToString());
  532. AddNameValueLine("parent_id", parentID.ToString());
  533. AddNameValueLine("type", "category");
  534. AddNameValueLine("name", "Contents|");
  535. AddSectionEnd();
  536. }
  537. public void AddItemStart()
  538. {
  539. BuildString += "\tinv_item\t0\n";
  540. AddSectionStart();
  541. }
  542. public void AddPermissionsStart()
  543. {
  544. BuildString += "\tpermissions 0\n";
  545. AddSectionStart();
  546. }
  547. public void AddSaleStart()
  548. {
  549. BuildString += "\tsale_info\t0\n";
  550. AddSectionStart();
  551. }
  552. protected void AddSectionStart()
  553. {
  554. BuildString += "\t{\n";
  555. }
  556. public void AddSectionEnd()
  557. {
  558. BuildString += "\t}\n";
  559. }
  560. public void AddLine(string addLine)
  561. {
  562. BuildString += addLine;
  563. }
  564. public void AddNameValueLine(string name, string value)
  565. {
  566. BuildString += "\t\t";
  567. BuildString += name + "\t";
  568. BuildString += value + "\n";
  569. }
  570. public void Close()
  571. {
  572. }
  573. }
  574. public uint MaskEffectivePermissions()
  575. {
  576. uint mask=0x7fffffff;
  577. foreach (TaskInventoryItem item in m_taskInventory.Values)
  578. {
  579. if (item.InvType != 6)
  580. {
  581. if ((item.OwnerMask & item.NextOwnerMask & (uint)PermissionMask.Copy) == 0)
  582. mask &= ~((uint)PermissionMask.Copy >> 13);
  583. if ((item.OwnerMask & item.NextOwnerMask & (uint)PermissionMask.Transfer) == 0)
  584. mask &= ~((uint)PermissionMask.Transfer >> 13);
  585. if ((item.OwnerMask & item.NextOwnerMask & (uint)PermissionMask.Modify) == 0)
  586. mask &= ~((uint)PermissionMask.Modify >> 13);
  587. }
  588. else
  589. {
  590. if ((item.OwnerMask & ((uint)PermissionMask.Copy >> 13)) == 0)
  591. mask &= ~((uint)PermissionMask.Copy >> 13);
  592. if ((item.OwnerMask & ((uint)PermissionMask.Transfer >> 13)) == 0)
  593. mask &= ~((uint)PermissionMask.Transfer >> 13);
  594. if ((item.OwnerMask & ((uint)PermissionMask.Modify >> 13)) == 0)
  595. mask &= ~((uint)PermissionMask.Modify >> 13);
  596. }
  597. if ((item.OwnerMask & (uint)PermissionMask.Copy) == 0)
  598. mask &= ~(uint)PermissionMask.Copy;
  599. if ((item.OwnerMask & (uint)PermissionMask.Transfer) == 0)
  600. mask &= ~(uint)PermissionMask.Transfer;
  601. if ((item.OwnerMask & (uint)PermissionMask.Modify) == 0)
  602. mask &= ~(uint)PermissionMask.Modify;
  603. }
  604. return mask;
  605. }
  606. public void ApplyNextOwnerPermissions()
  607. {
  608. BaseMask &= NextOwnerMask;
  609. OwnerMask &= NextOwnerMask;
  610. EveryoneMask &= NextOwnerMask;
  611. foreach (TaskInventoryItem item in m_taskInventory.Values)
  612. {
  613. if (item.InvType == 6)
  614. {
  615. if ((item.OwnerMask & ((uint)PermissionMask.Copy >> 13)) == 0)
  616. item.OwnerMask &= ~(uint)PermissionMask.Copy;
  617. if ((item.OwnerMask & ((uint)PermissionMask.Transfer >> 13)) == 0)
  618. item.OwnerMask &= ~(uint)PermissionMask.Transfer;
  619. if ((item.OwnerMask & ((uint)PermissionMask.Modify >> 13)) == 0)
  620. item.OwnerMask &= ~(uint)PermissionMask.Modify;
  621. }
  622. item.OwnerMask &= item.NextOwnerMask;
  623. item.BaseMask &= item.NextOwnerMask;
  624. item.EveryoneMask &= item.NextOwnerMask;
  625. }
  626. TriggerScriptChangedEvent(Changed.OWNER);
  627. }
  628. public bool ContainsScripts()
  629. {
  630. foreach (TaskInventoryItem item in m_taskInventory.Values)
  631. {
  632. if (item.InvType == 10)
  633. {
  634. return true;
  635. }
  636. }
  637. return false;
  638. }
  639. }
  640. }