InventoryItemBase.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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.Text;
  29. using OpenMetaverse;
  30. namespace OpenSim.Framework
  31. {
  32. /// <summary>
  33. /// Inventory Item - contains all the properties associated with an individual inventory piece.
  34. /// </summary>
  35. public class InventoryItemBase : InventoryNodeBase, ICloneable
  36. {
  37. /// <value>
  38. /// The inventory type of the item. This is slightly different from the asset type in some situations.
  39. /// </value>
  40. public int InvType
  41. {
  42. get
  43. {
  44. return m_invType;
  45. }
  46. set
  47. {
  48. m_invType = value;
  49. }
  50. }
  51. protected int m_invType;
  52. /// <value>
  53. /// The folder this item is contained in
  54. /// </value>
  55. public UUID Folder
  56. {
  57. get
  58. {
  59. return m_folder;
  60. }
  61. set
  62. {
  63. m_folder = value;
  64. }
  65. }
  66. protected UUID m_folder;
  67. /// <value>
  68. /// The creator of this item
  69. /// </value>
  70. public string CreatorId
  71. {
  72. get
  73. {
  74. return m_creatorId;
  75. }
  76. set
  77. {
  78. m_creatorId = value;
  79. if ((m_creatorId == null) || !UUID.TryParse(m_creatorId, out m_creatorIdAsUuid))
  80. m_creatorIdAsUuid = UUID.Zero;
  81. }
  82. }
  83. protected string m_creatorId;
  84. /// <value>
  85. /// The CreatorId expressed as a UUID.
  86. /// </value>
  87. public UUID CreatorIdAsUuid
  88. {
  89. get
  90. {
  91. if (UUID.Zero == m_creatorIdAsUuid)
  92. {
  93. UUID.TryParse(CreatorId, out m_creatorIdAsUuid);
  94. }
  95. return m_creatorIdAsUuid;
  96. }
  97. }
  98. protected UUID m_creatorIdAsUuid = UUID.Zero;
  99. /// <summary>
  100. /// Extended creator information of the form <profile url>;<name>
  101. /// </summary>
  102. public string CreatorData // = <profile url>;<name>
  103. {
  104. get { return m_creatorData; }
  105. set { m_creatorData = value; }
  106. }
  107. protected string m_creatorData = string.Empty;
  108. /// <summary>
  109. /// Used by the DB layer to retrieve / store the entire user identification.
  110. /// The identification can either be a simple UUID or a string of the form
  111. /// uuid[;profile_url[;name]]
  112. /// </summary>
  113. public string CreatorIdentification
  114. {
  115. get
  116. {
  117. if (!string.IsNullOrEmpty(m_creatorData))
  118. return m_creatorId + ';' + m_creatorData;
  119. else
  120. return m_creatorId;
  121. }
  122. set
  123. {
  124. if ((value == null) || (value != null && value == string.Empty))
  125. {
  126. m_creatorData = string.Empty;
  127. return;
  128. }
  129. if (!value.Contains(";")) // plain UUID
  130. {
  131. m_creatorId = value;
  132. }
  133. else // <uuid>[;<endpoint>[;name]]
  134. {
  135. string name = "Unknown User";
  136. string[] parts = value.Split(';');
  137. if (parts.Length >= 1)
  138. m_creatorId = parts[0];
  139. if (parts.Length >= 2)
  140. m_creatorData = parts[1];
  141. if (parts.Length >= 3)
  142. name = parts[2];
  143. m_creatorData += ';' + name;
  144. }
  145. }
  146. }
  147. /// <value>
  148. /// The description of the inventory item (must be less than 64 characters)
  149. /// </value>
  150. public string Description
  151. {
  152. get
  153. {
  154. return m_description;
  155. }
  156. set
  157. {
  158. m_description = value;
  159. }
  160. }
  161. protected string m_description = String.Empty;
  162. /// <value>
  163. ///
  164. /// </value>
  165. public uint NextPermissions
  166. {
  167. get
  168. {
  169. return m_nextPermissions;
  170. }
  171. set
  172. {
  173. m_nextPermissions = value;
  174. }
  175. }
  176. protected uint m_nextPermissions;
  177. /// <value>
  178. /// A mask containing permissions for the current owner (cannot be enforced)
  179. /// </value>
  180. public uint CurrentPermissions
  181. {
  182. get
  183. {
  184. return m_currentPermissions;
  185. }
  186. set
  187. {
  188. m_currentPermissions = value;
  189. }
  190. }
  191. protected uint m_currentPermissions;
  192. /// <value>
  193. ///
  194. /// </value>
  195. public uint BasePermissions
  196. {
  197. get
  198. {
  199. return m_basePermissions;
  200. }
  201. set
  202. {
  203. m_basePermissions = value;
  204. }
  205. }
  206. protected uint m_basePermissions;
  207. /// <value>
  208. ///
  209. /// </value>
  210. public uint EveryOnePermissions
  211. {
  212. get
  213. {
  214. return m_everyonePermissions;
  215. }
  216. set
  217. {
  218. m_everyonePermissions = value;
  219. }
  220. }
  221. protected uint m_everyonePermissions;
  222. /// <value>
  223. ///
  224. /// </value>
  225. public uint GroupPermissions
  226. {
  227. get
  228. {
  229. return m_groupPermissions;
  230. }
  231. set
  232. {
  233. m_groupPermissions = value;
  234. }
  235. }
  236. protected uint m_groupPermissions;
  237. /// <value>
  238. /// This is an enumerated value determining the type of asset (eg Notecard, Sound, Object, etc)
  239. /// </value>
  240. public int AssetType
  241. {
  242. get
  243. {
  244. return m_assetType;
  245. }
  246. set
  247. {
  248. m_assetType = value;
  249. }
  250. }
  251. protected int m_assetType;
  252. /// <value>
  253. /// The UUID of the associated asset on the asset server
  254. /// </value>
  255. public UUID AssetID
  256. {
  257. get
  258. {
  259. return m_assetID;
  260. }
  261. set
  262. {
  263. m_assetID = value;
  264. }
  265. }
  266. protected UUID m_assetID;
  267. /// <value>
  268. ///
  269. /// </value>
  270. public UUID GroupID
  271. {
  272. get
  273. {
  274. return m_groupID;
  275. }
  276. set
  277. {
  278. m_groupID = value;
  279. }
  280. }
  281. protected UUID m_groupID;
  282. /// <value>
  283. ///
  284. /// </value>
  285. public bool GroupOwned
  286. {
  287. get
  288. {
  289. return m_groupOwned;
  290. }
  291. set
  292. {
  293. m_groupOwned = value;
  294. }
  295. }
  296. protected bool m_groupOwned;
  297. /// <value>
  298. ///
  299. /// </value>
  300. public int SalePrice
  301. {
  302. get
  303. {
  304. return m_salePrice;
  305. }
  306. set
  307. {
  308. m_salePrice = value;
  309. }
  310. }
  311. protected int m_salePrice;
  312. /// <value>
  313. ///
  314. /// </value>
  315. public byte SaleType
  316. {
  317. get
  318. {
  319. return m_saleType;
  320. }
  321. set
  322. {
  323. m_saleType = value;
  324. }
  325. }
  326. protected byte m_saleType;
  327. /// <value>
  328. ///
  329. /// </value>
  330. public uint Flags
  331. {
  332. get
  333. {
  334. return m_flags;
  335. }
  336. set
  337. {
  338. m_flags = value;
  339. }
  340. }
  341. protected uint m_flags;
  342. /// <value>
  343. ///
  344. /// </value>
  345. public int CreationDate
  346. {
  347. get
  348. {
  349. return m_creationDate;
  350. }
  351. set
  352. {
  353. m_creationDate = value;
  354. }
  355. }
  356. protected int m_creationDate = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
  357. public InventoryItemBase()
  358. {
  359. }
  360. public InventoryItemBase(UUID id)
  361. {
  362. ID = id;
  363. }
  364. public InventoryItemBase(UUID id, UUID owner)
  365. {
  366. ID = id;
  367. Owner = owner;
  368. }
  369. public object Clone()
  370. {
  371. return MemberwiseClone();
  372. }
  373. public void ToLLSDxml(StringBuilder lsl, uint flagsMask = 0xffffffff)
  374. {
  375. LLSDxmlEncode.AddMap(lsl);
  376. LLSDxmlEncode.AddElem("parent_id", Folder, lsl);
  377. LLSDxmlEncode.AddElem("asset_id", AssetID, lsl);
  378. LLSDxmlEncode.AddElem("item_id", ID, lsl);
  379. LLSDxmlEncode.AddMap("permissions",lsl);
  380. LLSDxmlEncode.AddElem("creator_id", CreatorIdAsUuid, lsl);
  381. LLSDxmlEncode.AddElem("owner_id", Owner, lsl);
  382. LLSDxmlEncode.AddElem("group_id", GroupID, lsl);
  383. LLSDxmlEncode.AddElem("base_mask", (int)CurrentPermissions, lsl);
  384. LLSDxmlEncode.AddElem("owner_mask", (int)CurrentPermissions, lsl);
  385. LLSDxmlEncode.AddElem("group_mask", (int)GroupPermissions, lsl);
  386. LLSDxmlEncode.AddElem("everyone_mask", (int)EveryOnePermissions, lsl);
  387. LLSDxmlEncode.AddElem("next_owner_mask", (int)NextPermissions, lsl);
  388. LLSDxmlEncode.AddElem("is_owner_group", GroupOwned, lsl);
  389. LLSDxmlEncode.AddEndMap(lsl);
  390. LLSDxmlEncode.AddElem("type", AssetType, lsl);
  391. LLSDxmlEncode.AddElem("inv_type", InvType, lsl);
  392. LLSDxmlEncode.AddElem("flags", (int)(Flags & flagsMask), lsl);
  393. LLSDxmlEncode.AddMap("sale_info",lsl);
  394. LLSDxmlEncode.AddElem("sale_price", SalePrice, lsl);
  395. LLSDxmlEncode.AddElem("sale_type", SaleType, lsl);
  396. LLSDxmlEncode.AddEndMap(lsl);
  397. LLSDxmlEncode.AddElem("name", Name, lsl);
  398. LLSDxmlEncode.AddElem("desc", Description, lsl);
  399. LLSDxmlEncode.AddElem("created_at", CreationDate, lsl);
  400. LLSDxmlEncode.AddEndMap(lsl);
  401. }
  402. }
  403. }