SceneObjectGroup.Inventory.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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.Reflection;
  29. using libsecondlife;
  30. using log4net;
  31. using OpenSim.Framework;
  32. using OpenSim.Region.Environment.Interfaces;
  33. namespace OpenSim.Region.Environment.Scenes
  34. {
  35. public partial class SceneObjectGroup : EntityBase
  36. {
  37. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  38. /// <summary>
  39. /// Force all task inventories of prims in the scene object to persist
  40. /// </summary>
  41. public void ForceInventoryPersistence()
  42. {
  43. lock (m_parts)
  44. {
  45. foreach (SceneObjectPart part in m_parts.Values)
  46. {
  47. part.ForceInventoryPersistence();
  48. }
  49. }
  50. }
  51. /// <summary>
  52. /// Start the scripts contained in all the prims in this group.
  53. /// </summary>
  54. public void CreateScriptInstances(int startParam, bool postOnRez)
  55. {
  56. // Don't start scripts if they're turned off in the region!
  57. if (!m_scene.RegionInfo.RegionSettings.DisableScripts)
  58. {
  59. foreach (SceneObjectPart part in m_parts.Values)
  60. {
  61. part.CreateScriptInstances(startParam, postOnRez);
  62. }
  63. }
  64. }
  65. /// <summary>
  66. /// Stop the scripts contained in all the prims in this group
  67. /// </summary>
  68. public void RemoveScriptInstances()
  69. {
  70. lock (m_parts)
  71. {
  72. foreach (SceneObjectPart part in m_parts.Values)
  73. {
  74. part.RemoveScriptInstances();
  75. }
  76. }
  77. }
  78. /// <summary>
  79. ///
  80. /// </summary>
  81. /// <param name="remoteClient"></param>
  82. /// <param name="localID"></param>
  83. public bool GetPartInventoryFileName(IClientAPI remoteClient, uint localID)
  84. {
  85. SceneObjectPart part = GetChildPart(localID);
  86. if (part != null)
  87. {
  88. return part.GetInventoryFileName(remoteClient, localID);
  89. }
  90. else
  91. {
  92. m_log.ErrorFormat(
  93. "[PRIM INVENTORY]: " +
  94. "Couldn't find part {0} in object group {1}, {2} to retreive prim inventory",
  95. localID, Name, UUID);
  96. }
  97. return false;
  98. }
  99. /// <summary>
  100. /// Return serialized inventory metadata for the given constituent prim
  101. /// </summary>
  102. /// <param name="localID"></param>
  103. /// <param name="xferManager"></param>
  104. public void RequestInventoryFile(IClientAPI client, uint localID, IXfer xferManager)
  105. {
  106. SceneObjectPart part = GetChildPart(localID);
  107. if (part != null)
  108. {
  109. part.RequestInventoryFile(client, xferManager);
  110. }
  111. else
  112. {
  113. m_log.ErrorFormat(
  114. "[PRIM INVENTORY]: " +
  115. "Couldn't find part {0} in object group {1}, {2} to request inventory data",
  116. localID, Name, UUID);
  117. }
  118. }
  119. /// <summary>
  120. /// Add an inventory item to a prim in this group.
  121. /// </summary>
  122. /// <param name="remoteClient"></param>
  123. /// <param name="localID"></param>
  124. /// <param name="item"></param>
  125. /// <param name="copyItemID">The item UUID that should be used by the new item.</param>
  126. /// <returns></returns>
  127. public bool AddInventoryItem(IClientAPI remoteClient, uint localID,
  128. InventoryItemBase item, LLUUID copyItemID)
  129. {
  130. LLUUID newItemId = (copyItemID != LLUUID.Zero) ? copyItemID : item.ID;
  131. SceneObjectPart part = GetChildPart(localID);
  132. if (part != null)
  133. {
  134. TaskInventoryItem taskItem = new TaskInventoryItem();
  135. taskItem.ItemID = newItemId;
  136. taskItem.AssetID = item.AssetID;
  137. taskItem.Name = item.Name;
  138. taskItem.Description = item.Description;
  139. taskItem.OwnerID = item.Owner;
  140. taskItem.CreatorID = item.Creator;
  141. taskItem.Type = item.AssetType;
  142. taskItem.InvType = item.InvType;
  143. taskItem.BaseMask = item.BasePermissions;
  144. taskItem.OwnerMask = item.CurrentPermissions;
  145. // FIXME: ignoring group permissions for now as they aren't stored in item
  146. taskItem.EveryoneMask = item.EveryOnePermissions;
  147. taskItem.NextOwnerMask = item.NextPermissions;
  148. taskItem.Flags = item.Flags;
  149. // TODO: These are pending addition of those fields to TaskInventoryItem
  150. // taskItem.SalePrice = item.SalePrice;
  151. // taskItem.SaleType = item.SaleType;
  152. taskItem.CreationDate = (uint)item.CreationDate;
  153. part.AddInventoryItem(taskItem);
  154. return true;
  155. }
  156. else
  157. {
  158. m_log.ErrorFormat(
  159. "[PRIM INVENTORY]: " +
  160. "Couldn't find prim local ID {0} in group {1}, {2} to add inventory item ID {3}",
  161. localID, Name, UUID, newItemId);
  162. }
  163. return false;
  164. }
  165. /// <summary>
  166. /// Returns an existing inventory item. Returns the original, so any changes will be live.
  167. /// </summary>
  168. /// <param name="primID"></param>
  169. /// <param name="itemID"></param>
  170. /// <returns>null if the item does not exist</returns>
  171. public TaskInventoryItem GetInventoryItem(uint primID, LLUUID itemID)
  172. {
  173. SceneObjectPart part = GetChildPart(primID);
  174. if (part != null)
  175. {
  176. return part.GetInventoryItem(itemID);
  177. }
  178. else
  179. {
  180. m_log.ErrorFormat(
  181. "[PRIM INVENTORY]: " +
  182. "Couldn't find prim local ID {0} in prim {1}, {2} to get inventory item ID {3}",
  183. primID, part.Name, part.UUID, itemID);
  184. }
  185. return null;
  186. }
  187. /// <summary>
  188. /// Update an existing inventory item.
  189. /// </summary>
  190. /// <param name="item">The updated item. An item with the same id must already exist
  191. /// in this prim's inventory</param>
  192. /// <returns>false if the item did not exist, true if the update occurred succesfully</returns>
  193. public bool UpdateInventoryItem(TaskInventoryItem item)
  194. {
  195. SceneObjectPart part = GetChildPart(item.ParentPartID);
  196. if (part != null)
  197. {
  198. part.UpdateInventoryItem(item);
  199. return true;
  200. }
  201. else
  202. {
  203. m_log.ErrorFormat(
  204. "[PRIM INVENTORY]: " +
  205. "Couldn't find prim ID {0} to update item {1}, {2}",
  206. item.ParentPartID, item.Name, item.ItemID);
  207. }
  208. return false;
  209. }
  210. public int RemoveInventoryItem(uint localID, LLUUID itemID)
  211. {
  212. SceneObjectPart part = GetChildPart(localID);
  213. if (part != null)
  214. {
  215. int type = part.RemoveInventoryItem(itemID);
  216. return type;
  217. }
  218. return -1;
  219. }
  220. public uint GetEffectivePermissions()
  221. {
  222. uint perms=(uint)(PermissionMask.Modify |
  223. PermissionMask.Copy |
  224. PermissionMask.Move |
  225. PermissionMask.Transfer) | 7;
  226. foreach (SceneObjectPart part in m_parts.Values)
  227. perms &= part.MaskEffectivePermissions();
  228. if ((RootPart.OwnerMask & (uint)PermissionMask.Modify) == 0)
  229. perms &= ~(uint)PermissionMask.Modify;
  230. if ((RootPart.OwnerMask & (uint)PermissionMask.Copy) == 0)
  231. perms &= ~(uint)PermissionMask.Copy;
  232. if ((RootPart.OwnerMask & (uint)PermissionMask.Transfer) == 0)
  233. perms &= ~(uint)PermissionMask.Transfer;
  234. if ((RootPart.OwnerMask & RootPart.NextOwnerMask & (uint)PermissionMask.Modify) == 0)
  235. perms &= ~((uint)PermissionMask.Modify >> 13);
  236. if ((RootPart.OwnerMask & RootPart.NextOwnerMask & (uint)PermissionMask.Copy) == 0)
  237. perms &= ~((uint)PermissionMask.Copy >> 13);
  238. if ((RootPart.OwnerMask & RootPart.NextOwnerMask & (uint)PermissionMask.Transfer) == 0)
  239. perms &= ~((uint)PermissionMask.Transfer >> 13);
  240. return perms;
  241. }
  242. public void ApplyNextOwnerPermissions()
  243. {
  244. foreach (SceneObjectPart part in m_parts.Values)
  245. part.ApplyNextOwnerPermissions();
  246. }
  247. }
  248. }