SceneObjectGroup.Inventory.cs 10 KB

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