SceneObjectGroup.Inventory.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. /// Start a given script.
  40. /// </summary>
  41. /// <param name="localID">
  42. /// A <see cref="System.UInt32"/>
  43. /// </param>
  44. public void StartScript(uint localID, LLUUID itemID)
  45. {
  46. SceneObjectPart part = GetChildPart(localID);
  47. if (part != null)
  48. {
  49. part.StartScript(itemID);
  50. }
  51. else
  52. {
  53. m_log.ErrorFormat(
  54. "[PRIM INVENTORY]: " +
  55. "Couldn't find part {0} in object group {1}, {2} to start script with ID {3}",
  56. localID, Name, UUID, itemID);
  57. }
  58. }
  59. // /// Start a given script.
  60. // /// </summary>
  61. // /// <param name="localID">
  62. // /// A <see cref="System.UInt32"/>
  63. // /// </param>
  64. // public void StartScript(LLUUID partID, LLUUID itemID)
  65. // {
  66. // SceneObjectPart part = GetChildPart(partID);
  67. // if (part != null)
  68. // {
  69. // part.StartScript(itemID);
  70. // }
  71. // else
  72. // {
  73. // m_log.ErrorFormat(
  74. // "[PRIM INVENTORY]: " +
  75. // "Couldn't find part {0} in object group {1}, {2} to start script with ID {3}",
  76. // localID, Name, UUID, itemID);
  77. // }
  78. // }
  79. /// <summary>
  80. /// Start the scripts contained in all the prims in this group.
  81. /// </summary>
  82. public void StartScripts()
  83. {
  84. // Don't start scripts if they're turned off in the region!
  85. if (!((m_scene.RegionInfo.EstateSettings.regionFlags & Simulator.RegionFlags.SkipScripts) == Simulator.RegionFlags.SkipScripts))
  86. {
  87. foreach (SceneObjectPart part in m_parts.Values)
  88. {
  89. part.StartScripts();
  90. }
  91. }
  92. }
  93. public void StopScripts()
  94. {
  95. lock (m_parts)
  96. {
  97. foreach (SceneObjectPart part in m_parts.Values)
  98. {
  99. part.StopScripts();
  100. }
  101. }
  102. }
  103. /// Start a given script.
  104. /// </summary>
  105. /// <param name="localID">
  106. /// A <see cref="System.UInt32"/>
  107. /// </param>
  108. public void StopScript(uint partID, LLUUID itemID)
  109. {
  110. SceneObjectPart part = GetChildPart(partID);
  111. if (part != null)
  112. {
  113. part.StopScript(itemID);
  114. part.RemoveScriptEvents(itemID);
  115. }
  116. else
  117. {
  118. m_log.ErrorFormat(
  119. "[PRIM INVENTORY]: " +
  120. "Couldn't find part {0} in object group {1}, {2} to stop script with ID {3}",
  121. partID, Name, UUID, itemID);
  122. }
  123. }
  124. /// <summary>
  125. ///
  126. /// </summary>
  127. /// <param name="remoteClient"></param>
  128. /// <param name="localID"></param>
  129. public bool GetPartInventoryFileName(IClientAPI remoteClient, uint localID)
  130. {
  131. SceneObjectPart part = GetChildPart(localID);
  132. if (part != null)
  133. {
  134. return part.GetInventoryFileName(remoteClient, localID);
  135. }
  136. else
  137. {
  138. m_log.ErrorFormat(
  139. "[PRIM INVENTORY]: " +
  140. "Couldn't find part {0} in object group {1}, {2} to retreive prim inventory",
  141. localID, Name, UUID);
  142. }
  143. return false;
  144. }
  145. /// <summary>
  146. /// Return serialized inventory metadata for the given constituent prim
  147. /// </summary>
  148. /// <param name="localID"></param>
  149. /// <param name="xferManager"></param>
  150. public void RequestInventoryFile(IClientAPI client, uint localID, IXfer xferManager)
  151. {
  152. SceneObjectPart part = GetChildPart(localID);
  153. if (part != null)
  154. {
  155. part.RequestInventoryFile(client, xferManager);
  156. }
  157. else
  158. {
  159. m_log.ErrorFormat(
  160. "[PRIM INVENTORY]: " +
  161. "Couldn't find part {0} in object group {1}, {2} to request inventory data",
  162. localID, Name, UUID);
  163. }
  164. }
  165. /// <summary>
  166. /// Add an inventory item to a prim in this group.
  167. /// </summary>
  168. /// <param name="remoteClient"></param>
  169. /// <param name="localID"></param>
  170. /// <param name="item"></param>
  171. /// <param name="copyItemID">The item UUID that should be used by the new item.</param>
  172. /// <returns></returns>
  173. public bool AddInventoryItem(IClientAPI remoteClient, uint localID,
  174. InventoryItemBase item, LLUUID copyItemID)
  175. {
  176. LLUUID newItemId = (copyItemID != LLUUID.Zero) ? copyItemID : item.ID;
  177. SceneObjectPart part = GetChildPart(localID);
  178. if (part != null)
  179. {
  180. TaskInventoryItem taskItem = new TaskInventoryItem();
  181. taskItem.ItemID = newItemId;
  182. taskItem.AssetID = item.AssetID;
  183. taskItem.Name = item.Name;
  184. taskItem.Description = item.Description;
  185. taskItem.OwnerID = item.Owner;
  186. taskItem.CreatorID = item.Creator;
  187. taskItem.Type = item.AssetType;
  188. taskItem.InvType = item.InvType;
  189. taskItem.BaseMask = item.BasePermissions;
  190. taskItem.OwnerMask = item.CurrentPermissions;
  191. // FIXME: ignoring group permissions for now as they aren't stored in item
  192. taskItem.EveryoneMask = item.EveryOnePermissions;
  193. taskItem.NextOwnerMask = item.NextPermissions;
  194. taskItem.Flags = item.Flags;
  195. // TODO: These are pending addition of those fields to TaskInventoryItem
  196. // taskItem.SalePrice = item.SalePrice;
  197. // taskItem.SaleType = item.SaleType;
  198. taskItem.CreationDate = (uint)item.CreationDate;
  199. part.AddInventoryItem(taskItem);
  200. return true;
  201. }
  202. else
  203. {
  204. m_log.ErrorFormat(
  205. "[PRIM INVENTORY]: " +
  206. "Couldn't find prim local ID {0} in group {1}, {2} to add inventory item ID {3}",
  207. localID, Name, UUID, newItemId);
  208. }
  209. return false;
  210. }
  211. /// <summary>
  212. /// Returns an existing inventory item. Returns the original, so any changes will be live.
  213. /// </summary>
  214. /// <param name="primID"></param>
  215. /// <param name="itemID"></param>
  216. /// <returns>null if the item does not exist</returns>
  217. public TaskInventoryItem GetInventoryItem(uint primID, LLUUID itemID)
  218. {
  219. SceneObjectPart part = GetChildPart(primID);
  220. if (part != null)
  221. {
  222. return part.GetInventoryItem(itemID);
  223. }
  224. else
  225. {
  226. m_log.ErrorFormat(
  227. "[PRIM INVENTORY]: " +
  228. "Couldn't find prim local ID {0} in prim {1}, {2} to get inventory item ID {3}",
  229. primID, part.Name, part.UUID, itemID);
  230. }
  231. return null;
  232. }
  233. /// <summary>
  234. /// Update an existing inventory item.
  235. /// </summary>
  236. /// <param name="item">The updated item. An item with the same id must already exist
  237. /// in this prim's inventory</param>
  238. /// <returns>false if the item did not exist, true if the update occurred succesfully</returns>
  239. public bool UpdateInventoryItem(TaskInventoryItem item)
  240. {
  241. SceneObjectPart part = GetChildPart(item.ParentPartID);
  242. if (part != null)
  243. {
  244. part.UpdateInventoryItem(item);
  245. return true;
  246. }
  247. else
  248. {
  249. m_log.ErrorFormat(
  250. "[PRIM INVENTORY]: " +
  251. "Couldn't find prim ID {0} to update item {1}, {2}",
  252. item.ParentPartID, item.Name, item.ItemID);
  253. }
  254. return false;
  255. }
  256. public int RemoveInventoryItem(uint localID, LLUUID itemID)
  257. {
  258. SceneObjectPart part = GetChildPart(localID);
  259. if (part != null)
  260. {
  261. int type = part.RemoveInventoryItem(itemID);
  262. return type;
  263. }
  264. return -1;
  265. }
  266. public uint GetEffectivePermissions()
  267. {
  268. uint perms=(uint)(PermissionMask.Modify |
  269. PermissionMask.Copy |
  270. PermissionMask.Move |
  271. PermissionMask.Transfer) | 7;
  272. foreach (SceneObjectPart part in m_parts.Values)
  273. perms &= part.MaskEffectivePermissions();
  274. if ((RootPart.OwnerMask & (uint)PermissionMask.Modify) == 0)
  275. perms &= ~(uint)PermissionMask.Modify;
  276. if ((RootPart.OwnerMask & (uint)PermissionMask.Copy) == 0)
  277. perms &= ~(uint)PermissionMask.Copy;
  278. if ((RootPart.OwnerMask & (uint)PermissionMask.Transfer) == 0)
  279. perms &= ~(uint)PermissionMask.Transfer;
  280. if ((RootPart.OwnerMask & RootPart.NextOwnerMask & (uint)PermissionMask.Modify) == 0)
  281. perms &= ~((uint)PermissionMask.Modify >> 13);
  282. if ((RootPart.OwnerMask & RootPart.NextOwnerMask & (uint)PermissionMask.Copy) == 0)
  283. perms &= ~((uint)PermissionMask.Copy >> 13);
  284. if ((RootPart.OwnerMask & RootPart.NextOwnerMask & (uint)PermissionMask.Transfer) == 0)
  285. perms &= ~((uint)PermissionMask.Transfer >> 13);
  286. return perms;
  287. }
  288. public void ApplyNextOwnerPermissions()
  289. {
  290. foreach (SceneObjectPart part in m_parts.Values)
  291. part.ApplyNextOwnerPermissions();
  292. }
  293. }
  294. }