1
0

InventoryItemBase.cs 12 KB

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