Scene.Inventory.cs 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824
  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.Collections.Generic;
  29. using System.Reflection;
  30. using System.Text;
  31. using libsecondlife;
  32. using libsecondlife.Packets;
  33. using log4net;
  34. using OpenSim.Framework;
  35. using OpenSim.Framework.Communications.Cache;
  36. using OpenSim.Region.Environment.Interfaces;
  37. namespace OpenSim.Region.Environment.Scenes
  38. {
  39. public partial class Scene
  40. {
  41. private static readonly ILog m_log
  42. = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  43. /// <summary>
  44. /// Start all the scripts in the scene which should be started.
  45. /// </summary>
  46. public void StartScripts()
  47. {
  48. m_log.Info("[PRIM INVENTORY]: Starting scripts in scene");
  49. foreach (EntityBase group in Entities.Values)
  50. {
  51. if (group is SceneObjectGroup)
  52. {
  53. ((SceneObjectGroup) group).StartScripts();
  54. }
  55. }
  56. }
  57. public void AddUploadedInventoryItem(LLUUID agentID, InventoryItemBase item)
  58. {
  59. IMoneyModule money=RequestModuleInterface<IMoneyModule>();
  60. if (money != null)
  61. {
  62. money.ApplyUploadCharge(agentID);
  63. }
  64. AddInventoryItem(agentID, item);
  65. }
  66. public bool AddInventoryItemReturned(LLUUID AgentId, InventoryItemBase item)
  67. {
  68. CachedUserInfo userInfo
  69. = CommsManager.UserProfileCacheService.GetUserDetails(AgentId);
  70. if (userInfo != null)
  71. {
  72. userInfo.AddItem(item);
  73. return true;
  74. }
  75. else
  76. {
  77. m_log.ErrorFormat(
  78. "[AGENT INVENTORY]: Agent was not found for add of item {1} {2}", item.Name, item.ID);
  79. return false;
  80. }
  81. }
  82. /// <summary>
  83. /// Add an inventory item to an avatar's inventory.
  84. /// </summary>
  85. /// <param name="remoteClient">The remote client controlling the avatar</param>
  86. /// <param name="item">The item. This structure contains all the item metadata, including the folder
  87. /// in which the item is to be placed.</param>
  88. public void AddInventoryItem(IClientAPI remoteClient, InventoryItemBase item)
  89. {
  90. CachedUserInfo userInfo
  91. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  92. if (userInfo != null)
  93. {
  94. userInfo.AddItem(item);
  95. remoteClient.SendInventoryItemCreateUpdate(item);
  96. int userlevel = 0;
  97. if (ExternalChecks.ExternalChecksCanBeGodLike(remoteClient.AgentId))
  98. {
  99. userlevel = 1;
  100. }
  101. if (m_regInfo.MasterAvatarAssignedUUID == remoteClient.AgentId)
  102. {
  103. userlevel = 2;
  104. }
  105. EventManager.TriggerOnNewInventoryItemUploadComplete(remoteClient.AgentId, item.AssetID, item.Name, userlevel);
  106. }
  107. else
  108. {
  109. m_log.ErrorFormat(
  110. "[AGENT INVENTORY]: Agent {0} {1} was not found for add of item {2} {3}",
  111. remoteClient.Name, remoteClient.AgentId, item.Name, item.ID);
  112. return;
  113. }
  114. }
  115. /// <summary>
  116. /// <see>AddInventoryItem(LLUUID, InventoryItemBase)</see>
  117. /// </summary>
  118. /// <param name="avatarId">The ID of the avatar</param>
  119. /// <param name="item">The item. This structure contains all the item metadata, including the folder
  120. /// in which the item is to be placed.</param>
  121. public void AddInventoryItem(LLUUID avatarId, InventoryItemBase item)
  122. {
  123. ScenePresence avatar;
  124. if (!TryGetAvatar(avatarId, out avatar))
  125. {
  126. m_log.ErrorFormat(
  127. "[AGENT INVENTORY]: Could not find avatar {0} to add inventory item", avatarId);
  128. return;
  129. }
  130. AddInventoryItem(avatar.ControllingClient, item);
  131. }
  132. /// <summary>
  133. /// Capability originating call to update the asset of an item in an agent's inventory
  134. /// </summary>
  135. /// <param name="remoteClient"></param>
  136. /// <param name="itemID"></param>
  137. /// <param name="data"></param>
  138. /// <returns></returns>
  139. public LLUUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, LLUUID itemID, byte[] data)
  140. {
  141. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  142. if (userInfo != null)
  143. {
  144. if (userInfo.RootFolder != null)
  145. {
  146. InventoryItemBase item = userInfo.RootFolder.FindItem(itemID);
  147. if (item != null)
  148. {
  149. AssetBase asset =
  150. CreateAsset(item.Name, item.Description, (sbyte) item.InvType,
  151. (sbyte) item.AssetType, data);
  152. AssetCache.AddAsset(asset);
  153. item.AssetID = asset.FullID;
  154. userInfo.UpdateItem(item);
  155. // remoteClient.SendInventoryItemCreateUpdate(item);
  156. if ((InventoryType) item.InvType == InventoryType.Notecard)
  157. {
  158. //do we want to know about updated note cards?
  159. }
  160. else if ((InventoryType) item.InvType == InventoryType.LSL)
  161. {
  162. // do we want to know about updated scripts
  163. }
  164. return (asset.FullID);
  165. }
  166. }
  167. }
  168. return LLUUID.Zero;
  169. }
  170. /// <summary>
  171. /// <see>CapsUpdatedInventoryItemAsset(IClientAPI, LLUUID, byte[])</see>
  172. /// </summary>
  173. private LLUUID CapsUpdateInventoryItemAsset(LLUUID avatarId, LLUUID itemID, byte[] data)
  174. {
  175. ScenePresence avatar;
  176. if (TryGetAvatar(avatarId, out avatar))
  177. {
  178. return CapsUpdateInventoryItemAsset(avatar.ControllingClient, itemID, data);
  179. }
  180. else
  181. {
  182. m_log.ErrorFormat(
  183. "[AGENT INVENTORY]: " +
  184. "Avatar {0} cannot be found to update its inventory item asset",
  185. avatarId);
  186. }
  187. return LLUUID.Zero;
  188. }
  189. /// <summary>
  190. /// Capability originating call to update the asset of a script in a prim's (task's) inventory
  191. /// </summary>
  192. /// <param name="remoteClient"></param>
  193. /// <param name="itemID"></param>
  194. /// <param name="primID">The prim which contains the item to update</param>
  195. /// <param name="isScriptRunning">Indicates whether the script to update is currently running</param>
  196. /// <param name="data"></param>
  197. public void CapsUpdateTaskInventoryScriptAsset(IClientAPI remoteClient, LLUUID itemId,
  198. LLUUID primId, bool isScriptRunning, byte[] data)
  199. {
  200. // Retrieve group
  201. SceneObjectPart part = GetSceneObjectPart(primId);
  202. SceneObjectGroup group = part.ParentGroup;
  203. if (null == group)
  204. {
  205. m_log.ErrorFormat(
  206. "[PRIM INVENTORY]: " +
  207. "Prim inventory update requested for item ID {0} in prim ID {1} but this prim does not exist",
  208. itemId, primId);
  209. return;
  210. }
  211. // Retrieve item
  212. TaskInventoryItem item = group.GetInventoryItem(part.LocalId, itemId);
  213. if (null == item)
  214. {
  215. return;
  216. }
  217. // Create new asset
  218. // XXX Hardcoding the numbers is a temporary measure - need an enumeration for this
  219. // There may well be one in libsecondlife
  220. AssetBase asset = CreateAsset(item.Name, item.Description, 10, 10, data);
  221. AssetCache.AddAsset(asset);
  222. // Update item with new asset
  223. item.AssetID = asset.FullID;
  224. group.UpdateInventoryItem(item);
  225. part.GetProperties(remoteClient);
  226. // Trigger rerunning of script (use TriggerRezScript event, see RezScript)
  227. if (isScriptRunning)
  228. {
  229. group.StopScript(part.LocalId, item.ItemID);
  230. group.StartScript(part.LocalId, item.ItemID);
  231. }
  232. }
  233. /// <summary>
  234. /// <see>CapsUpdateTaskInventoryScriptAsset(IClientAPI, LLUUID, LLUUID, bool, byte[])</see>
  235. /// </summary>
  236. private void CapsUpdateTaskInventoryScriptAsset(LLUUID avatarId, LLUUID itemId,
  237. LLUUID primId, bool isScriptRunning, byte[] data)
  238. {
  239. ScenePresence avatar;
  240. if (TryGetAvatar(avatarId, out avatar))
  241. {
  242. CapsUpdateTaskInventoryScriptAsset(
  243. avatar.ControllingClient, itemId, primId, isScriptRunning, data);
  244. }
  245. else
  246. {
  247. m_log.ErrorFormat(
  248. "[PRIM INVENTORY]: " +
  249. "Avatar {0} cannot be found to update its prim item asset",
  250. avatarId);
  251. }
  252. }
  253. /// <summary>
  254. /// Update an item which is either already in the client's inventory or is within
  255. /// a transaction
  256. /// </summary>
  257. /// <param name="remoteClient"></param>
  258. /// <param name="transactionID">The transaction ID. If this is LLUUID.Zero we will
  259. /// assume that we are not in a transaction</param>
  260. /// <param name="itemID">The ID of the updated item</param>
  261. /// <param name="name">The name of the updated item</param>
  262. /// <param name="description">The description of the updated item</param>
  263. /// <param name="nextOwnerMask">The permissions of the updated item</param>
  264. /* public void UpdateInventoryItemAsset(IClientAPI remoteClient, LLUUID transactionID,
  265. LLUUID itemID, string name, string description,
  266. uint nextOwnerMask)*/
  267. public void UpdateInventoryItemAsset(IClientAPI remoteClient, LLUUID transactionID,
  268. LLUUID itemID, InventoryItemBase itemUpd)
  269. {
  270. CachedUserInfo userInfo
  271. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  272. if (userInfo != null && userInfo.RootFolder != null)
  273. {
  274. InventoryItemBase item = userInfo.RootFolder.FindItem(itemID);
  275. if (item != null)
  276. {
  277. if (LLUUID.Zero == transactionID)
  278. {
  279. item.Name = itemUpd.Name;
  280. item.Description = itemUpd.Description;
  281. item.NextPermissions = itemUpd.NextPermissions;
  282. item.CurrentPermissions |= 8; // Slam!
  283. item.EveryOnePermissions = itemUpd.EveryOnePermissions;
  284. // TODO: Requires sanity checks
  285. //item.GroupID = itemUpd.GroupID;
  286. //item.GroupOwned = itemUpd.GroupOwned;
  287. //item.CreationDate = itemUpd.CreationDate;
  288. // TODO: Check if folder changed and move item
  289. //item.NextPermissions = itemUpd.Folder;
  290. item.InvType = itemUpd.InvType;
  291. item.SalePrice = itemUpd.SalePrice;
  292. item.SaleType = itemUpd.SaleType;
  293. item.Flags = itemUpd.Flags;
  294. userInfo.UpdateItem(item);
  295. }
  296. else
  297. {
  298. IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
  299. if (agentTransactions != null)
  300. {
  301. agentTransactions.HandleItemUpdateFromTransaction(
  302. remoteClient, transactionID, item);
  303. }
  304. }
  305. }
  306. else
  307. {
  308. m_log.Error(
  309. "[AGENTINVENTORY]: Item ID " + itemID + " not found for an inventory item update.");
  310. }
  311. }
  312. else
  313. {
  314. m_log.Error(
  315. "[AGENT INVENTORY]: Agent ID " + remoteClient.AgentId + " not found for an inventory item update.");
  316. }
  317. }
  318. /// <summary>
  319. /// Give an inventory item from one avatar to another
  320. /// </summary>
  321. /// <param name="recipientClient"></param>
  322. /// <param name="senderId">ID of the sender of the item</param>
  323. /// <param name="itemId"></param>
  324. public void GiveInventoryItem(IClientAPI recipientClient, LLUUID senderId, LLUUID itemId)
  325. {
  326. // Retrieve the item from the sender
  327. CachedUserInfo senderUserInfo = CommsManager.UserProfileCacheService.GetUserDetails(senderId);
  328. if (senderUserInfo == null)
  329. {
  330. m_log.ErrorFormat(
  331. "[AGENT INVENTORY]: Failed to find sending user {0} for item {1}", senderId, itemId);
  332. return;
  333. }
  334. if (senderUserInfo.RootFolder != null)
  335. {
  336. InventoryItemBase item = senderUserInfo.RootFolder.FindItem(itemId);
  337. if (item != null)
  338. {
  339. if (!ExternalChecks.ExternalChecksBypassPermissions())
  340. {
  341. if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
  342. return;
  343. }
  344. // TODO get recipient's root folder
  345. CachedUserInfo recipientUserInfo
  346. = CommsManager.UserProfileCacheService.GetUserDetails(recipientClient.AgentId);
  347. if (recipientUserInfo != null)
  348. {
  349. // Insert a copy of the item into the recipient
  350. InventoryItemBase itemCopy = new InventoryItemBase();
  351. itemCopy.Owner = recipientClient.AgentId;
  352. itemCopy.Creator = senderId;
  353. itemCopy.ID = LLUUID.Random();
  354. itemCopy.AssetID = item.AssetID;
  355. itemCopy.Description = item.Description;
  356. itemCopy.Name = item.Name;
  357. itemCopy.AssetType = item.AssetType;
  358. itemCopy.InvType = item.InvType;
  359. itemCopy.Folder = LLUUID.Zero;
  360. if (ExternalChecks.ExternalChecksPropagatePermissions())
  361. {
  362. if (item.InvType == 6)
  363. {
  364. itemCopy.BasePermissions &= ~(uint)(PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer);
  365. itemCopy.BasePermissions |= (item.CurrentPermissions & 7) << 13;
  366. }
  367. else
  368. {
  369. Console.WriteLine("Non-Prim item ==>");
  370. itemCopy.BasePermissions = item.BasePermissions & item.NextPermissions;
  371. }
  372. itemCopy.CurrentPermissions = itemCopy.BasePermissions;
  373. if ((item.CurrentPermissions & 8) != 0) // Propagate slam bit
  374. {
  375. itemCopy.CurrentPermissions = item.NextPermissions;
  376. itemCopy.BasePermissions=itemCopy.CurrentPermissions;
  377. itemCopy.CurrentPermissions |= 8;
  378. }
  379. itemCopy.NextPermissions = item.NextPermissions;
  380. itemCopy.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions;
  381. }
  382. else
  383. {
  384. itemCopy.CurrentPermissions = item.CurrentPermissions;
  385. itemCopy.NextPermissions = item.NextPermissions;
  386. itemCopy.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions;
  387. itemCopy.BasePermissions = item.BasePermissions;
  388. }
  389. itemCopy.GroupID = item.GroupID;
  390. itemCopy.GroupOwned = item.GroupOwned;
  391. itemCopy.Flags = item.Flags;
  392. itemCopy.SalePrice = item.SalePrice;
  393. itemCopy.SaleType = item.SaleType;
  394. recipientUserInfo.AddItem(itemCopy);
  395. if (!ExternalChecks.ExternalChecksBypassPermissions())
  396. {
  397. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  398. senderUserInfo.DeleteItem(itemId);
  399. }
  400. // Let the recipient client know about this new item
  401. recipientClient.SendBulkUpdateInventory(itemCopy);
  402. }
  403. else
  404. {
  405. m_log.ErrorFormat(
  406. "[AGENT INVENTORY]: Could not find userinfo for recipient user {0}, {1} of item {2}, {3} from {4}",
  407. recipientClient.Name, recipientClient.AgentId, item.Name,
  408. item.ID, senderId);
  409. }
  410. }
  411. else
  412. {
  413. m_log.ErrorFormat(
  414. "[AGENT INVENTORY]: Failed to find item {0} to give to {1}", itemId, senderId);
  415. return;
  416. }
  417. }
  418. else
  419. {
  420. m_log.Error("[AGENT INVENTORY]: Failed to find item " + itemId.ToString() + ", no root folder");
  421. return;
  422. }
  423. }
  424. public void CopyInventoryItem(IClientAPI remoteClient, uint callbackID, LLUUID oldAgentID, LLUUID oldItemID,
  425. LLUUID newFolderID, string newName)
  426. {
  427. m_log.DebugFormat(
  428. "[AGENT INVENTORY]: CopyInventoryItem received by {0} with oldAgentID {1}, oldItemID {2}, new FolderID {3}, newName {4}",
  429. remoteClient.AgentId, oldAgentID, oldItemID, newFolderID, newName);
  430. InventoryItemBase item = CommsManager.UserProfileCacheService.libraryRoot.FindItem(oldItemID);
  431. if (item == null)
  432. {
  433. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(oldAgentID);
  434. if (userInfo == null)
  435. {
  436. m_log.Error("[AGENT INVENTORY]: Failed to find user " + oldAgentID.ToString());
  437. return;
  438. }
  439. if (userInfo.RootFolder != null)
  440. {
  441. item = userInfo.RootFolder.FindItem(oldItemID);
  442. if (item == null)
  443. {
  444. m_log.Error("[AGENT INVENTORY]: Failed to find item " + oldItemID.ToString());
  445. return;
  446. }
  447. }
  448. else
  449. {
  450. m_log.Error("[AGENT INVENTORY]: Failed to find item " + oldItemID.ToString());
  451. return;
  452. }
  453. }
  454. AssetBase asset
  455. = AssetCache.GetAsset(
  456. item.AssetID, (item.AssetType == (int)AssetType.Texture ? true : false));
  457. if (asset != null)
  458. {
  459. if (remoteClient.AgentId == oldAgentID)
  460. {
  461. CreateNewInventoryItem(
  462. remoteClient, newFolderID, callbackID, asset, item.BasePermissions, item.CurrentPermissions, item.EveryOnePermissions, item.NextPermissions);
  463. }
  464. else
  465. {
  466. CreateNewInventoryItem(
  467. remoteClient, newFolderID, callbackID, asset, item.NextPermissions, item.NextPermissions, item.EveryOnePermissions & item.NextPermissions, item.NextPermissions);
  468. }
  469. }
  470. else
  471. {
  472. m_log.ErrorFormat(
  473. "[AGENT INVENTORY]: Could not copy item {0} since asset {1} could not be found",
  474. item.Name, item.AssetID);
  475. }
  476. }
  477. private AssetBase CreateAsset(string name, string description, sbyte invType, sbyte assetType, byte[] data)
  478. {
  479. AssetBase asset = new AssetBase();
  480. asset.Name = name;
  481. asset.Description = description;
  482. asset.InvType = invType;
  483. asset.Type = assetType;
  484. asset.FullID = LLUUID.Random();
  485. asset.Data = (data == null) ? new byte[1] : data;
  486. return asset;
  487. }
  488. /// <summary>
  489. /// Move an item within the agent's inventory.
  490. /// </summary>
  491. /// <param name="remoteClient"></param>
  492. /// <param name="folderID"></param>
  493. /// <param name="itemID"></param>
  494. /// <param name="length"></param>
  495. /// <param name="newName"></param>
  496. public void MoveInventoryItem(IClientAPI remoteClient, LLUUID folderID, LLUUID itemID, int length,
  497. string newName)
  498. {
  499. m_log.DebugFormat(
  500. "[AGENT INVENTORY]: Moving item {0} to {1} for {2}", itemID, folderID, remoteClient.AgentId);
  501. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  502. if (userInfo == null)
  503. {
  504. m_log.Error("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString());
  505. return;
  506. }
  507. if (userInfo.RootFolder != null)
  508. {
  509. InventoryItemBase item = userInfo.RootFolder.FindItem(itemID);
  510. if (item != null)
  511. {
  512. if (newName != String.Empty)
  513. {
  514. item.Name = newName;
  515. }
  516. item.Folder = folderID;
  517. userInfo.DeleteItem(item.ID);
  518. AddInventoryItem(remoteClient, item);
  519. }
  520. else
  521. {
  522. m_log.Error("[AGENT INVENTORY]: Failed to find item " + itemID.ToString());
  523. return;
  524. }
  525. }
  526. else
  527. {
  528. m_log.Error("[AGENT INVENTORY]: Failed to find item " + itemID.ToString() + ", no root folder");
  529. return;
  530. }
  531. }
  532. private void CreateNewInventoryItem(IClientAPI remoteClient, LLUUID folderID, uint callbackID,
  533. AssetBase asset, uint nextOwnerMask)
  534. {
  535. CreateNewInventoryItem(remoteClient, folderID, callbackID, asset, (uint)PermissionMask.All, (uint)PermissionMask.All, 0, nextOwnerMask);
  536. }
  537. /// <summary>
  538. /// Create a new inventory item.
  539. /// </summary>
  540. /// <param name="remoteClient"></param>
  541. /// <param name="folderID"></param>
  542. /// <param name="callbackID"></param>
  543. /// <param name="asset"></param>
  544. /// <param name="nextOwnerMask"></param>
  545. private void CreateNewInventoryItem(IClientAPI remoteClient, LLUUID folderID, uint callbackID,
  546. AssetBase asset, uint baseMask, uint currentMask, uint everyoneMask, uint nextOwnerMask)
  547. {
  548. CachedUserInfo userInfo
  549. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  550. if (userInfo != null)
  551. {
  552. InventoryItemBase item = new InventoryItemBase();
  553. item.Owner = remoteClient.AgentId;
  554. item.Creator = remoteClient.AgentId;
  555. item.ID = LLUUID.Random();
  556. item.AssetID = asset.FullID;
  557. item.Description = asset.Description;
  558. item.Name = asset.Name;
  559. item.AssetType = asset.Type;
  560. item.InvType = asset.InvType;
  561. item.Folder = folderID;
  562. item.CurrentPermissions = currentMask;
  563. item.NextPermissions = nextOwnerMask;
  564. item.EveryOnePermissions = everyoneMask;
  565. item.BasePermissions = baseMask;
  566. userInfo.AddItem(item);
  567. remoteClient.SendInventoryItemCreateUpdate(item);
  568. }
  569. else
  570. {
  571. m_log.WarnFormat(
  572. "No user details associated with client {0} uuid {1} in CreateNewInventoryItem!",
  573. remoteClient.Name, remoteClient.AgentId);
  574. }
  575. }
  576. /// <summary>
  577. /// Create a new inventory item. Called when the client creates a new item directly within their
  578. /// inventory (e.g. by selecting a context inventory menu option).
  579. /// </summary>
  580. /// <param name="remoteClient"></param>
  581. /// <param name="transactionID"></param>
  582. /// <param name="folderID"></param>
  583. /// <param name="callbackID"></param>
  584. /// <param name="description"></param>
  585. /// <param name="name"></param>
  586. /// <param name="invType"></param>
  587. /// <param name="type"></param>
  588. /// <param name="wearableType"></param>
  589. /// <param name="nextOwnerMask"></param>
  590. public void CreateNewInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
  591. uint callbackID, string description, string name, sbyte invType,
  592. sbyte assetType,
  593. byte wearableType, uint nextOwnerMask)
  594. {
  595. // m_log.DebugFormat("[AGENT INVENTORY]: Received request to create inventory item {0} in folder {1}", name, folderID);
  596. if (transactionID == LLUUID.Zero)
  597. {
  598. CachedUserInfo userInfo
  599. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  600. if (userInfo != null)
  601. {
  602. ScenePresence presence;
  603. TryGetAvatar(remoteClient.AgentId, out presence);
  604. byte[] data = null;
  605. if (invType == 3 && presence != null) // libsecondlife.asset.assettype.landmark = 3 - needs to be turned into an enum
  606. {
  607. LLVector3 pos=presence.AbsolutePosition;
  608. string strdata=String.Format("Landmark version 2\nregion_id {0}\nlocal_pos {1} {2} {3}\nregion_handle {4}\n",
  609. presence.Scene.RegionInfo.RegionID,
  610. pos.X, pos.Y, pos.Z,
  611. presence.RegionHandle);
  612. data=Encoding.ASCII.GetBytes(strdata);
  613. }
  614. AssetBase asset = CreateAsset(name, description, invType, assetType, data);
  615. AssetCache.AddAsset(asset);
  616. CreateNewInventoryItem(remoteClient, folderID, callbackID, asset, nextOwnerMask);
  617. }
  618. else
  619. {
  620. m_log.ErrorFormat(
  621. "userInfo for agent uuid {0} unexpectedly null in CreateNewInventoryItem",
  622. remoteClient.AgentId);
  623. }
  624. }
  625. else
  626. {
  627. IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
  628. if (agentTransactions != null)
  629. {
  630. agentTransactions.HandleItemCreationFromTransaction(
  631. remoteClient, transactionID, folderID, callbackID, description,
  632. name, invType, assetType, wearableType, nextOwnerMask);
  633. }
  634. }
  635. }
  636. /// <summary>
  637. /// Remove an inventory item for the client's inventory
  638. /// </summary>
  639. /// <param name="remoteClient"></param>
  640. /// <param name="itemID"></param>
  641. private void RemoveInventoryItem(IClientAPI remoteClient, LLUUID itemID)
  642. {
  643. CachedUserInfo userInfo
  644. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  645. if (userInfo == null)
  646. {
  647. m_log.WarnFormat(
  648. "[AGENT INVENTORY]: Failed to find user {0} {1} to delete inventory item {2}",
  649. remoteClient.Name, remoteClient.AgentId, itemID);
  650. return;
  651. }
  652. userInfo.DeleteItem(itemID);
  653. }
  654. /// <summary>
  655. /// Removes an inventory folder. Although there is a packet in the Linden protocol for this, it may be
  656. /// legacy and not currently used (purge folder is used to remove folders from trash instead).
  657. /// </summary>
  658. /// <param name="remoteClient"></param>
  659. /// <param name="folderID"></param>
  660. private void RemoveInventoryFolder(IClientAPI remoteClient, LLUUID folderID)
  661. {
  662. CachedUserInfo userInfo
  663. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  664. if (userInfo == null)
  665. {
  666. m_log.Warn("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString());
  667. return;
  668. }
  669. if (userInfo.RootFolder != null)
  670. {
  671. InventoryItemBase folder = userInfo.RootFolder.FindItem(folderID);
  672. if (folder != null)
  673. {
  674. m_log.WarnFormat(
  675. "[AGENT INVENTORY]: Remove folder not implemented in request by {0} {1} for {2}",
  676. remoteClient.Name, remoteClient.AgentId, folderID);
  677. // doesn't work just yet, commented out. will fix in next patch.
  678. // userInfo.DeleteItem(folder);
  679. }
  680. }
  681. }
  682. private SceneObjectGroup GetGroupByPrim(uint localID)
  683. {
  684. List<EntityBase> EntityList = GetEntities();
  685. foreach (EntityBase ent in EntityList)
  686. {
  687. if (ent is SceneObjectGroup)
  688. {
  689. if (((SceneObjectGroup) ent).HasChildPrim(localID))
  690. return (SceneObjectGroup) ent;
  691. }
  692. }
  693. return null;
  694. }
  695. /// <summary>
  696. /// Send the details of a prim's inventory to the client.
  697. /// </summary>
  698. /// <param name="remoteClient"></param>
  699. /// <param name="primLocalID"></param>
  700. public void RequestTaskInventory(IClientAPI remoteClient, uint primLocalID)
  701. {
  702. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  703. if (group != null)
  704. {
  705. bool fileChange = group.GetPartInventoryFileName(remoteClient, primLocalID);
  706. if (fileChange)
  707. {
  708. if (XferManager != null)
  709. {
  710. group.RequestInventoryFile(remoteClient, primLocalID, XferManager);
  711. }
  712. }
  713. }
  714. else
  715. {
  716. m_log.ErrorFormat(
  717. "[PRIM INVENTORY]: Inventory requested of prim {0} which doesn't exist", primLocalID);
  718. }
  719. }
  720. /// <summary>
  721. /// Remove an item from a prim (task) inventory
  722. /// </summary>
  723. /// <param name="remoteClient">Unused at the moment but retained since the avatar ID might
  724. /// be necessary for a permissions check at some stage.</param>
  725. /// <param name="itemID"></param>
  726. /// <param name="localID"></param>
  727. public void RemoveTaskInventory(IClientAPI remoteClient, LLUUID itemID, uint localID)
  728. {
  729. SceneObjectPart part = GetSceneObjectPart(localID);
  730. SceneObjectGroup group = part.ParentGroup;
  731. if (group != null)
  732. {
  733. int type = group.RemoveInventoryItem(localID, itemID);
  734. part.GetProperties(remoteClient);
  735. if (type == 10)
  736. {
  737. EventManager.TriggerRemoveScript(localID, itemID);
  738. }
  739. }
  740. else
  741. {
  742. m_log.ErrorFormat(
  743. "[PRIM INVENTORY]: " +
  744. "Removal of item {0} requested of prim {1} but this prim does not exist",
  745. itemID,
  746. localID);
  747. }
  748. }
  749. /// <summary>
  750. /// Move the given item in the given prim to a folder in the client's inventory
  751. /// </summary>
  752. /// <param name="remoteClient"></param>
  753. /// <param name="folderID"></param>
  754. /// <param name="primLocalID"></param>
  755. /// <param name="itemID"></param>
  756. public void MoveTaskInventoryItem(IClientAPI remoteClient, LLUUID folderId, uint primLocalId, LLUUID itemId)
  757. {
  758. SceneObjectPart part = GetSceneObjectPart(primLocalId);
  759. if (null == part)
  760. {
  761. m_log.WarnFormat(
  762. "[PRIM INVENTORY]: " +
  763. "Move of inventory item {0} from prim with local id {1} failed because the prim could not be found",
  764. itemId, primLocalId);
  765. return;
  766. }
  767. TaskInventoryItem taskItem = part.GetInventoryItem(itemId);
  768. if (null == taskItem)
  769. {
  770. // Console already notified of error in GetInventoryItem
  771. return;
  772. }
  773. // Only owner can copy
  774. if (remoteClient.AgentId != taskItem.OwnerID)
  775. {
  776. return;
  777. }
  778. InventoryItemBase agentItem = new InventoryItemBase();
  779. agentItem.ID = LLUUID.Random();
  780. agentItem.Creator = taskItem.CreatorID;
  781. agentItem.Owner = remoteClient.AgentId;
  782. agentItem.AssetID = taskItem.AssetID;
  783. agentItem.Description = taskItem.Description;
  784. agentItem.Name = taskItem.Name;
  785. agentItem.AssetType = taskItem.Type;
  786. agentItem.InvType = taskItem.InvType;
  787. agentItem.Folder = folderId;
  788. if ((remoteClient.AgentId != taskItem.OwnerID) && ExternalChecks.ExternalChecksPropagatePermissions())
  789. {
  790. agentItem.BasePermissions = taskItem.NextOwnerMask;
  791. agentItem.CurrentPermissions = taskItem.NextOwnerMask;
  792. agentItem.NextPermissions = taskItem.NextOwnerMask;
  793. agentItem.EveryOnePermissions = taskItem.EveryoneMask & taskItem.NextOwnerMask;
  794. }
  795. else
  796. {
  797. agentItem.BasePermissions = taskItem.BaseMask;
  798. agentItem.CurrentPermissions = taskItem.OwnerMask;
  799. agentItem.NextPermissions = taskItem.NextOwnerMask;
  800. agentItem.EveryOnePermissions = taskItem.EveryoneMask;
  801. }
  802. AddInventoryItem(remoteClient, agentItem);
  803. if (!ExternalChecks.ExternalChecksBypassPermissions())
  804. {
  805. if ((taskItem.OwnerMask & (uint)PermissionMask.Copy) == 0)
  806. part.RemoveInventoryItem(itemId);
  807. }
  808. }
  809. /// <summary>
  810. /// Update an item in a prim (task) inventory.
  811. /// This method does not handle scripts, <see>RezScript(IClientAPI, LLUUID, unit)</see>
  812. /// </summary>
  813. /// <param name="remoteClient"></param>
  814. /// <param name="transactionID"></param>
  815. /// <param name="itemInfo"></param>
  816. /// <param name="primLocalID"></param>
  817. public void UpdateTaskInventory(IClientAPI remoteClient, LLUUID transactionID, TaskInventoryItem itemInfo,
  818. uint primLocalID)
  819. {
  820. LLUUID itemID=itemInfo.ItemID;
  821. LLUUID folderID=itemInfo.ParentID;
  822. // Find the prim we're dealing with
  823. SceneObjectPart part = GetSceneObjectPart(primLocalID);
  824. if (part != null)
  825. {
  826. TaskInventoryItem currentItem=part.GetInventoryItem(itemID);
  827. if (currentItem == null)
  828. {
  829. LLUUID copyID = LLUUID.Random();
  830. if (itemID != LLUUID.Zero)
  831. {
  832. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  833. if (userInfo != null && userInfo.RootFolder != null)
  834. {
  835. InventoryItemBase item = userInfo.RootFolder.FindItem(itemID);
  836. // Try library
  837. // XXX clumsy, possibly should be one call
  838. if (null == item)
  839. {
  840. item = CommsManager.UserProfileCacheService.libraryRoot.FindItem(itemID);
  841. }
  842. if (item != null)
  843. {
  844. part.ParentGroup.AddInventoryItem(remoteClient, primLocalID, item, copyID);
  845. m_log.InfoFormat(
  846. "[PRIM INVENTORY]: Update with item {0} requested of prim {1} for {2}",
  847. item.Name, primLocalID, remoteClient.Name);
  848. part.GetProperties(remoteClient);
  849. if (!ExternalChecks.ExternalChecksBypassPermissions())
  850. {
  851. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  852. RemoveInventoryItem(remoteClient, itemID);
  853. }
  854. }
  855. else
  856. {
  857. m_log.ErrorFormat(
  858. "[PRIM INVENTORY]: Could not find inventory item {0} to update for {1}!",
  859. itemID, remoteClient.Name);
  860. }
  861. }
  862. }
  863. }
  864. else // Updating existing item with new perms etc
  865. {
  866. TaskInventoryItem prevItem=part.GetInventoryItem(itemID);
  867. itemInfo.AssetID = prevItem.AssetID;
  868. if (part.UpdateInventoryItem(itemInfo))
  869. part.GetProperties(remoteClient);
  870. }
  871. }
  872. else
  873. {
  874. m_log.WarnFormat(
  875. "[PRIM INVENTORY]: " +
  876. "Update with item {0} requested of prim {1} for {2} but this prim does not exist",
  877. itemID, primLocalID, remoteClient.Name);
  878. }
  879. }
  880. /// <summary>
  881. /// Rez a script into a prim's inventory
  882. /// </summary>
  883. /// <param name="remoteClient"></param>
  884. /// <param name="itemID"> </param>
  885. /// <param name="localID"></param>
  886. public void RezScript(IClientAPI remoteClient, InventoryItemBase itemBase, LLUUID transactionID, uint localID)
  887. {
  888. LLUUID itemID=itemBase.ID;
  889. LLUUID copyID = LLUUID.Random();
  890. if (itemID != LLUUID.Zero)
  891. {
  892. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  893. if (userInfo != null && userInfo.RootFolder != null)
  894. {
  895. InventoryItemBase item = userInfo.RootFolder.FindItem(itemID);
  896. // Try library
  897. // XXX clumsy, possibly should be one call
  898. if (null == item)
  899. {
  900. item = CommsManager.UserProfileCacheService.libraryRoot.FindItem(itemID);
  901. }
  902. if (item != null)
  903. {
  904. SceneObjectPart part = GetSceneObjectPart(localID);
  905. if (part != null)
  906. {
  907. if (ExternalChecks.ExternalChecksCanRunScript(item.ID, part.UUID, remoteClient.AgentId))
  908. {
  909. part.ParentGroup.AddInventoryItem(remoteClient, localID, item, copyID);
  910. part.ParentGroup.StartScript(localID, copyID);
  911. part.GetProperties(remoteClient);
  912. // m_log.InfoFormat("[PRIMINVENTORY]: " +
  913. // "Rezzed script {0} into prim local ID {1} for user {2}",
  914. // item.inventoryName, localID, remoteClient.Name);
  915. }
  916. }
  917. else
  918. {
  919. m_log.ErrorFormat(
  920. "[PRIM INVENTORY]: " +
  921. "Could not rez script {0} into prim local ID {1} for user {2}"
  922. + " because the prim could not be found in the region!",
  923. item.Name, localID, remoteClient.Name);
  924. }
  925. }
  926. else
  927. {
  928. m_log.ErrorFormat(
  929. "[PRIM INVENTORY]: Could not find script inventory item {0} to rez for {1}!",
  930. itemID, remoteClient.Name);
  931. }
  932. }
  933. }
  934. else // If the itemID is zero then the script has been rezzed directly in an object's inventory
  935. {
  936. SceneObjectPart part=GetSceneObjectPart(itemBase.Folder);
  937. if (part == null)
  938. return;
  939. AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.InvType, (sbyte)itemBase.AssetType, Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"));
  940. AssetCache.AddAsset(asset);
  941. TaskInventoryItem taskItem=new TaskInventoryItem();
  942. taskItem.ResetIDs(itemBase.Folder);
  943. taskItem.ParentID = itemBase.Folder;
  944. taskItem.CreationDate = (uint)itemBase.CreationDate;
  945. taskItem.Name = itemBase.Name;
  946. taskItem.Description = itemBase.Description;
  947. taskItem.Type = itemBase.AssetType;
  948. taskItem.InvType = itemBase.InvType;
  949. taskItem.OwnerID = itemBase.Owner;
  950. taskItem.CreatorID = itemBase.Creator;
  951. taskItem.BaseMask = itemBase.BasePermissions;
  952. taskItem.OwnerMask = itemBase.CurrentPermissions;
  953. taskItem.EveryoneMask = itemBase.EveryOnePermissions;
  954. taskItem.NextOwnerMask = itemBase.NextPermissions;
  955. taskItem.GroupID = itemBase.GroupID;
  956. taskItem.GroupMask = 0;
  957. taskItem.Flags = itemBase.Flags;
  958. taskItem.PermsGranter = LLUUID.Zero;
  959. taskItem.PermsMask = 0;
  960. taskItem.AssetID = asset.ID;
  961. part.AddInventoryItem(taskItem);
  962. part.GetProperties(remoteClient);
  963. if (ExternalChecks.ExternalChecksCanRunScript(taskItem.AssetID, part.UUID, remoteClient.AgentId))
  964. {
  965. part.StartScript(taskItem);
  966. }
  967. }
  968. }
  969. /// <summary>
  970. /// Called when an object is removed from the environment into inventory.
  971. /// </summary>
  972. /// <param name="packet"></param>
  973. /// <param name="simClient"></param>
  974. public virtual void DeRezObject(Packet packet, IClientAPI remoteClient)
  975. {
  976. DeRezObjectPacket DeRezPacket = (DeRezObjectPacket) packet;
  977. LLUUID folderID = LLUUID.Zero;
  978. foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData)
  979. {
  980. // m_log.DebugFormat(
  981. // "[AGENT INVENTORY]: Received request to derez {0} into folder {1}",
  982. // Data.ObjectLocalID, DeRezPacket.AgentBlock.DestinationID);
  983. EntityBase selectedEnt = null;
  984. //m_log.Info("[CLIENT]: LocalID:" + Data.ObjectLocalID.ToString());
  985. List<EntityBase> EntityList = GetEntities();
  986. foreach (EntityBase ent in EntityList)
  987. {
  988. if (ent.LocalId == Data.ObjectLocalID)
  989. {
  990. selectedEnt = ent;
  991. break;
  992. }
  993. }
  994. if (selectedEnt != null)
  995. {
  996. bool permissionToTake = false;
  997. bool permissionToDelete = false;
  998. if (DeRezPacket.AgentBlock.Destination == 1)// Take Copy
  999. {
  1000. permissionToTake = ExternalChecks.ExternalChecksCanTakeCopyObject(((SceneObjectGroup)selectedEnt).UUID, remoteClient.AgentId);
  1001. permissionToDelete = false; //Just taking copy!
  1002. }
  1003. else if (DeRezPacket.AgentBlock.Destination == 4) //Take
  1004. {
  1005. // Take
  1006. permissionToTake = ExternalChecks.ExternalChecksCanTakeObject(((SceneObjectGroup)selectedEnt).UUID, remoteClient.AgentId);
  1007. permissionToDelete = permissionToTake; //If they can take, they can delete!
  1008. }
  1009. else if (DeRezPacket.AgentBlock.Destination == 6) //Delete
  1010. {
  1011. permissionToTake = ExternalChecks.ExternalChecksCanDeleteObject(((SceneObjectGroup)selectedEnt).UUID, remoteClient.AgentId);
  1012. permissionToDelete = ExternalChecks.ExternalChecksCanDeleteObject(((SceneObjectGroup)selectedEnt).UUID, remoteClient.AgentId);
  1013. }
  1014. else if (DeRezPacket.AgentBlock.Destination == 9) //Return
  1015. {
  1016. permissionToTake = ExternalChecks.ExternalChecksCanDeleteObject(((SceneObjectGroup)selectedEnt).UUID, remoteClient.AgentId);
  1017. permissionToDelete = ExternalChecks.ExternalChecksCanDeleteObject(((SceneObjectGroup)selectedEnt).UUID, remoteClient.AgentId);
  1018. }
  1019. SceneObjectGroup objectGroup = (SceneObjectGroup)selectedEnt;
  1020. if (permissionToTake)
  1021. {
  1022. string sceneObjectXml = objectGroup.ToXmlString();
  1023. CachedUserInfo userInfo =
  1024. CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  1025. if (userInfo != null)
  1026. {
  1027. string searchFolder = "";
  1028. if (DeRezPacket.AgentBlock.Destination == 6)
  1029. searchFolder = "Trash";
  1030. else if (DeRezPacket.AgentBlock.Destination == 9)
  1031. searchFolder = "Lost And Found";
  1032. // If we're deleting someone else's item, it goes back to their deleted items folder
  1033. // If we're returning someone's item, it goes back to the owner's Lost And Found folder.
  1034. if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero || (DeRezPacket.AgentBlock.Destination == 6 && objectGroup.OwnerID != remoteClient.AgentId))
  1035. {
  1036. List<InventoryFolderBase> subrootfolders = userInfo.RootFolder.RequestListOfFolders();
  1037. foreach (InventoryFolderBase flder in subrootfolders)
  1038. {
  1039. if (flder.Name == "Lost And Found")
  1040. {
  1041. folderID = flder.ID;
  1042. break;
  1043. }
  1044. }
  1045. if (folderID == LLUUID.Zero)
  1046. {
  1047. folderID = userInfo.RootFolder.ID;
  1048. }
  1049. //currently following code not used (or don't know of any case of destination being zero
  1050. }
  1051. else
  1052. {
  1053. folderID = DeRezPacket.AgentBlock.DestinationID;
  1054. }
  1055. AssetBase asset = CreateAsset(
  1056. ((SceneObjectGroup) selectedEnt).GetPartName(selectedEnt.LocalId),
  1057. ((SceneObjectGroup) selectedEnt).GetPartDescription(selectedEnt.LocalId),
  1058. (sbyte) InventoryType.Object,
  1059. (sbyte) AssetType.Object,
  1060. Helpers.StringToField(sceneObjectXml));
  1061. AssetCache.AddAsset(asset);
  1062. InventoryItemBase item = new InventoryItemBase();
  1063. item.Creator = objectGroup.RootPart.CreatorID;
  1064. if (DeRezPacket.AgentBlock.Destination == 1 || DeRezPacket.AgentBlock.Destination == 4)// Take / Copy
  1065. item.Owner = remoteClient.AgentId;
  1066. else // Delete / Return
  1067. item.Owner = objectGroup.OwnerID;
  1068. item.ID = LLUUID.Random();
  1069. item.AssetID = asset.FullID;
  1070. item.Description = asset.Description;
  1071. item.Name = asset.Name;
  1072. item.AssetType = asset.Type;
  1073. item.InvType = asset.InvType;
  1074. item.Folder = folderID;
  1075. if ((remoteClient.AgentId != objectGroup.RootPart.OwnerID) && ExternalChecks.ExternalChecksPropagatePermissions())
  1076. {
  1077. uint perms=objectGroup.GetEffectivePermissions();
  1078. uint nextPerms=(perms & 7) << 13;
  1079. if ((nextPerms & (uint)PermissionMask.Copy) == 0)
  1080. perms &= ~(uint)PermissionMask.Copy;
  1081. if ((nextPerms & (uint)PermissionMask.Transfer) == 0)
  1082. perms &= ~(uint)PermissionMask.Transfer;
  1083. if ((nextPerms & (uint)PermissionMask.Modify) == 0)
  1084. perms &= ~(uint)PermissionMask.Modify;
  1085. item.BasePermissions = perms & objectGroup.RootPart.NextOwnerMask;
  1086. item.CurrentPermissions = item.BasePermissions;
  1087. item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
  1088. item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask & objectGroup.RootPart.NextOwnerMask;
  1089. item.CurrentPermissions |= 8; // Slam!
  1090. }
  1091. else
  1092. {
  1093. item.BasePermissions = objectGroup.GetEffectivePermissions();
  1094. item.CurrentPermissions = objectGroup.GetEffectivePermissions();
  1095. item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
  1096. item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask;
  1097. }
  1098. // TODO: add the new fields (Flags, Sale info, etc)
  1099. userInfo.AddItem(item);
  1100. if (item.Owner == remoteClient.AgentId)
  1101. {
  1102. remoteClient.SendInventoryItemCreateUpdate(item);
  1103. }
  1104. else
  1105. {
  1106. ScenePresence notifyUser = GetScenePresence(item.Owner);
  1107. if (notifyUser != null)
  1108. {
  1109. notifyUser.ControllingClient.SendInventoryItemCreateUpdate(item);
  1110. }
  1111. }
  1112. }
  1113. }
  1114. if (permissionToDelete)
  1115. {
  1116. DeleteSceneObject(objectGroup);
  1117. }
  1118. }
  1119. }
  1120. }
  1121. public void updateKnownAsset(IClientAPI remoteClient, SceneObjectGroup grp, LLUUID assetID, LLUUID agentID)
  1122. {
  1123. SceneObjectGroup objectGroup = grp;
  1124. if (objectGroup != null)
  1125. {
  1126. string sceneObjectXml = objectGroup.ToXmlString();
  1127. CachedUserInfo userInfo =
  1128. CommsManager.UserProfileCacheService.GetUserDetails(agentID);
  1129. if (userInfo != null)
  1130. {
  1131. Queue<InventoryFolderImpl> searchfolders = new Queue<InventoryFolderImpl>();
  1132. searchfolders.Enqueue(userInfo.RootFolder);
  1133. LLUUID foundFolder = userInfo.RootFolder.ID;
  1134. // search through folders to find the asset.
  1135. while (searchfolders.Count > 0)
  1136. {
  1137. InventoryFolderImpl fld = searchfolders.Dequeue();
  1138. lock (fld)
  1139. {
  1140. if (fld != null)
  1141. {
  1142. if (fld.Items.ContainsKey(assetID))
  1143. {
  1144. foundFolder = fld.ID;
  1145. searchfolders.Clear();
  1146. break;
  1147. }
  1148. else
  1149. {
  1150. foreach (InventoryFolderImpl subfld in fld.SubFolders.Values)
  1151. {
  1152. searchfolders.Enqueue(subfld);
  1153. }
  1154. }
  1155. }
  1156. }
  1157. }
  1158. AssetBase asset = CreateAsset(
  1159. objectGroup.GetPartName(objectGroup.LocalId),
  1160. objectGroup.GetPartDescription(objectGroup.LocalId),
  1161. (sbyte)InventoryType.Object,
  1162. (sbyte)AssetType.Object,
  1163. Helpers.StringToField(sceneObjectXml));
  1164. AssetCache.AddAsset(asset);
  1165. InventoryItemBase item = new InventoryItemBase();
  1166. item.Creator = objectGroup.RootPart.CreatorID;
  1167. item.Owner = agentID;
  1168. item.ID = assetID;
  1169. item.AssetID = asset.FullID;
  1170. item.Description = asset.Description;
  1171. item.Name = asset.Name;
  1172. item.AssetType = asset.Type;
  1173. item.InvType = asset.InvType;
  1174. // Sticking it in root folder for now.. objects folder later?
  1175. item.Folder = foundFolder;// DeRezPacket.AgentBlock.DestinationID;
  1176. if ((agentID != objectGroup.RootPart.OwnerID) && ExternalChecks.ExternalChecksPropagatePermissions())
  1177. {
  1178. item.BasePermissions = objectGroup.RootPart.NextOwnerMask;
  1179. item.CurrentPermissions = objectGroup.RootPart.NextOwnerMask;
  1180. item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
  1181. item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask & objectGroup.RootPart.NextOwnerMask;
  1182. }
  1183. else
  1184. {
  1185. item.BasePermissions = objectGroup.GetEffectivePermissions();
  1186. item.CurrentPermissions = objectGroup.GetEffectivePermissions();
  1187. item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
  1188. item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask;
  1189. }
  1190. userInfo.AddItem(item);
  1191. // this gets called when the agent loggs off!
  1192. if (remoteClient != null)
  1193. {
  1194. remoteClient.SendInventoryItemCreateUpdate(item);
  1195. }
  1196. }
  1197. }
  1198. }
  1199. public LLUUID attachObjectAssetStore(IClientAPI remoteClient, SceneObjectGroup grp, LLUUID AgentId)
  1200. {
  1201. SceneObjectGroup objectGroup = grp;
  1202. if (objectGroup != null)
  1203. {
  1204. string sceneObjectXml = objectGroup.ToXmlString();
  1205. CachedUserInfo userInfo =
  1206. CommsManager.UserProfileCacheService.GetUserDetails(AgentId);
  1207. if (userInfo != null)
  1208. {
  1209. AssetBase asset = CreateAsset(
  1210. objectGroup.GetPartName(objectGroup.LocalId),
  1211. objectGroup.GetPartDescription(objectGroup.LocalId),
  1212. (sbyte)InventoryType.Object,
  1213. (sbyte)AssetType.Object,
  1214. Helpers.StringToField(sceneObjectXml));
  1215. AssetCache.AddAsset(asset);
  1216. InventoryItemBase item = new InventoryItemBase();
  1217. item.Creator = objectGroup.RootPart.CreatorID;
  1218. item.Owner = remoteClient.AgentId;
  1219. item.ID = LLUUID.Random();
  1220. item.AssetID = asset.FullID;
  1221. item.Description = asset.Description;
  1222. item.Name = asset.Name;
  1223. item.AssetType = asset.Type;
  1224. item.InvType = asset.InvType;
  1225. // Sticking it in root folder for now.. objects folder later?
  1226. item.Folder = userInfo.RootFolder.ID;// DeRezPacket.AgentBlock.DestinationID;
  1227. if ((remoteClient.AgentId != objectGroup.RootPart.OwnerID) && ExternalChecks.ExternalChecksPropagatePermissions())
  1228. {
  1229. item.BasePermissions = objectGroup.RootPart.NextOwnerMask;
  1230. item.CurrentPermissions = objectGroup.RootPart.NextOwnerMask;
  1231. item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
  1232. item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask & objectGroup.RootPart.NextOwnerMask;
  1233. }
  1234. else
  1235. {
  1236. item.BasePermissions = objectGroup.RootPart.BaseMask;
  1237. item.CurrentPermissions = objectGroup.RootPart.OwnerMask;
  1238. item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
  1239. item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask;
  1240. }
  1241. userInfo.AddItem(item);
  1242. remoteClient.SendInventoryItemCreateUpdate(item);
  1243. return item.AssetID;
  1244. }
  1245. return LLUUID.Zero;
  1246. }
  1247. return LLUUID.Zero;
  1248. }
  1249. /// <summary>
  1250. /// Event Handler Rez an object into a scene
  1251. /// Calls the non-void event handler
  1252. /// </summary>
  1253. /// <param name="remoteClient"></param>
  1254. /// <param name="itemID"></param>
  1255. /// <param name="RayEnd"></param>
  1256. /// <param name="RayStart"></param>
  1257. /// <param name="RayTargetID"></param>
  1258. /// <param name="BypassRayCast"></param>
  1259. /// <param name="RayEndIsIntersection"></param>
  1260. /// <param name="EveryoneMask"></param>
  1261. /// <param name="GroupMask"></param>
  1262. /// <param name="NextOwnerMask"></param>
  1263. /// <param name="ItemFlags"></param>
  1264. /// <param name="RezSelected"></param>
  1265. /// <param name="RemoveItem"></param>
  1266. /// <param name="fromTaskID"></param>
  1267. public virtual void RezObject(IClientAPI remoteClient, LLUUID itemID, LLVector3 RayEnd, LLVector3 RayStart,
  1268. LLUUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
  1269. uint EveryoneMask, uint GroupMask, uint NextOwnerMask, uint ItemFlags,
  1270. bool RezSelected, bool RemoveItem, LLUUID fromTaskID)
  1271. {
  1272. RezObject(
  1273. remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection,
  1274. EveryoneMask, GroupMask, NextOwnerMask, ItemFlags, RezSelected, RemoveItem, fromTaskID, false);
  1275. }
  1276. /// <summary>
  1277. /// Returns SceneObjectGroup or null from asset request.
  1278. /// </summary>
  1279. /// <param name="remoteClient"></param>
  1280. /// <param name="itemID"></param>
  1281. /// <param name="RayEnd"></param>
  1282. /// <param name="RayStart"></param>
  1283. /// <param name="RayTargetID"></param>
  1284. /// <param name="BypassRayCast"></param>
  1285. /// <param name="RayEndIsIntersection"></param>
  1286. /// <param name="EveryoneMask"></param>
  1287. /// <param name="GroupMask"></param>
  1288. /// <param name="NextOwnerMask"></param>
  1289. /// <param name="ItemFlags"></param>
  1290. /// <param name="RezSelected"></param>
  1291. /// <param name="RemoveItem"></param>
  1292. /// <param name="fromTaskID"></param>
  1293. /// <param name="difference"></param>
  1294. /// <returns></returns>
  1295. public virtual SceneObjectGroup RezObject(IClientAPI remoteClient, LLUUID itemID, LLVector3 RayEnd, LLVector3 RayStart,
  1296. LLUUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
  1297. uint EveryoneMask, uint GroupMask, uint NextOwnerMask, uint ItemFlags,
  1298. bool RezSelected, bool RemoveItem, LLUUID fromTaskID, bool attachment)
  1299. {
  1300. // Work out position details
  1301. byte bRayEndIsIntersection = (byte)0;
  1302. if (RayEndIsIntersection)
  1303. {
  1304. bRayEndIsIntersection = (byte)1;
  1305. }
  1306. else
  1307. {
  1308. bRayEndIsIntersection = (byte)0;
  1309. }
  1310. LLVector3 scale = new LLVector3(0.5f, 0.5f, 0.5f);
  1311. LLVector3 pos = GetNewRezLocation(
  1312. RayStart, RayEnd, RayTargetID, new LLQuaternion(0, 0, 0, 1),
  1313. BypassRayCast, bRayEndIsIntersection,true,scale, false);
  1314. // Rez object
  1315. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  1316. if (userInfo != null)
  1317. {
  1318. if (userInfo.RootFolder != null)
  1319. {
  1320. InventoryItemBase item = userInfo.RootFolder.FindItem(itemID);
  1321. if (item != null)
  1322. {
  1323. AssetBase rezAsset = AssetCache.GetAsset(item.AssetID, false);
  1324. if (rezAsset != null)
  1325. {
  1326. string xmlData = Helpers.FieldToUTF8String(rezAsset.Data);
  1327. SceneObjectGroup group = new SceneObjectGroup(this, m_regionHandle, xmlData);
  1328. if (!ExternalChecks.ExternalChecksCanRezObject(group.Children.Count,remoteClient.AgentId, pos) && !attachment)
  1329. {
  1330. return null;
  1331. }
  1332. group.ResetIDs();
  1333. AddSceneObject(group);
  1334. // if attachment we set it's asset id so object updates can reflect that
  1335. // if not, we set it's position in world.
  1336. if (!attachment)
  1337. {
  1338. pos = GetNewRezLocation(
  1339. RayStart, RayEnd, RayTargetID, new LLQuaternion(0, 0, 0, 1),
  1340. BypassRayCast, bRayEndIsIntersection, true, group.GroupScale(), false);
  1341. group.AbsolutePosition = pos;
  1342. }
  1343. else
  1344. {
  1345. group.SetFromAssetID(itemID);
  1346. }
  1347. SceneObjectPart rootPart = null;
  1348. try
  1349. {
  1350. rootPart = group.GetChildPart(group.UUID);
  1351. }
  1352. catch (NullReferenceException)
  1353. {
  1354. string isAttachment = "";
  1355. if (attachment)
  1356. isAttachment = " Object was an attachment";
  1357. m_log.Error("[OJECTREZ]: Error rezzing ItemID: " + itemID + " object has no rootpart." + isAttachment);
  1358. }
  1359. // Since renaming the item in the inventory does not affect the name stored
  1360. // in the serialization, transfer the correct name from the inventory to the
  1361. // object itself before we rez.
  1362. rootPart.Name = item.Name;
  1363. rootPart.Description = item.Description;
  1364. List<SceneObjectPart> partList = new List<SceneObjectPart>(group.Children.Values);
  1365. if (rootPart.OwnerID != item.Owner)
  1366. {
  1367. if ((item.CurrentPermissions & 8) != 0)
  1368. {
  1369. foreach (SceneObjectPart part in partList)
  1370. {
  1371. part.EveryoneMask = item.EveryOnePermissions;
  1372. part.NextOwnerMask = item.NextPermissions;
  1373. }
  1374. }
  1375. group.ApplyNextOwnerPermissions();
  1376. }
  1377. foreach (SceneObjectPart part in partList)
  1378. {
  1379. if (part.OwnerID != item.Owner)
  1380. {
  1381. part.LastOwnerID = part.OwnerID;
  1382. part.OwnerID = item.Owner;
  1383. part.ChangeInventoryOwner(item.Owner);
  1384. }
  1385. else if (((item.CurrentPermissions & 8) != 0) && (!attachment)) // Slam!
  1386. {
  1387. part.EveryoneMask = item.EveryOnePermissions;
  1388. part.NextOwnerMask = item.NextPermissions;
  1389. }
  1390. }
  1391. rootPart.TrimPermissions();
  1392. if (!attachment)
  1393. {
  1394. if (group.RootPart.Shape.PCode == (byte)PCode.Prim)
  1395. {
  1396. group.ClearPartAttachmentData();
  1397. }
  1398. group.ApplyPhysics(m_physicalPrim);
  1399. }
  1400. group.StartScripts();
  1401. if (!attachment)
  1402. rootPart.ScheduleFullUpdate();
  1403. return rootPart.ParentGroup;
  1404. }
  1405. }
  1406. }
  1407. }
  1408. return null;
  1409. }
  1410. public virtual SceneObjectGroup RezObject(TaskInventoryItem item, LLVector3 pos, LLQuaternion rot, LLVector3 vel, int param)
  1411. {
  1412. // Rez object
  1413. if (item != null)
  1414. {
  1415. LLUUID ownerID = item.OwnerID;
  1416. AssetBase rezAsset = AssetCache.GetAsset(item.AssetID, false);
  1417. if (rezAsset != null)
  1418. {
  1419. string xmlData = Helpers.FieldToUTF8String(rezAsset.Data);
  1420. SceneObjectGroup group = new SceneObjectGroup(this, m_regionHandle, xmlData);
  1421. if (!ExternalChecks.ExternalChecksCanRezObject(group.Children.Count, ownerID, pos))
  1422. {
  1423. return null;
  1424. }
  1425. group.ResetIDs();
  1426. AddSceneObject(group);
  1427. // Set the startup parameter for on_rez event and llGetStartParameter() function
  1428. group.StartParameter = param;
  1429. // we set it's position in world.
  1430. group.AbsolutePosition = pos;
  1431. SceneObjectPart rootPart = group.GetChildPart(group.UUID);
  1432. // Since renaming the item in the inventory does not affect the name stored
  1433. // in the serialization, transfer the correct name from the inventory to the
  1434. // object itself before we rez.
  1435. rootPart.Name = item.Name;
  1436. rootPart.Description = item.Description;
  1437. List<SceneObjectPart> partList = new List<SceneObjectPart>(group.Children.Values);
  1438. if (rootPart.OwnerID != item.OwnerID)
  1439. {
  1440. if ((item.OwnerMask & 8) != 0)
  1441. {
  1442. foreach (SceneObjectPart part in partList)
  1443. {
  1444. part.EveryoneMask = item.EveryoneMask;
  1445. part.NextOwnerMask = item.NextOwnerMask;
  1446. }
  1447. }
  1448. group.ApplyNextOwnerPermissions();
  1449. }
  1450. foreach (SceneObjectPart part in partList)
  1451. {
  1452. if (part.OwnerID != item.OwnerID)
  1453. {
  1454. part.LastOwnerID = part.OwnerID;
  1455. part.OwnerID = item.OwnerID;
  1456. part.ChangeInventoryOwner(item.OwnerID);
  1457. }
  1458. else if ((item.OwnerMask & 8) != 0) // Slam!
  1459. {
  1460. part.EveryoneMask = item.EveryoneMask;
  1461. part.NextOwnerMask = item.NextOwnerMask;
  1462. }
  1463. }
  1464. rootPart.TrimPermissions();
  1465. if (group.RootPart.Shape.PCode == (byte)PCode.Prim)
  1466. {
  1467. group.ClearPartAttachmentData();
  1468. }
  1469. group.UpdateGroupRotation(rot);
  1470. group.ApplyPhysics(m_physicalPrim);
  1471. group.Velocity = vel;
  1472. group.StartScripts();
  1473. rootPart.ScheduleFullUpdate();
  1474. return rootPart.ParentGroup;
  1475. }
  1476. }
  1477. return null;
  1478. }
  1479. public virtual bool returnObjects(SceneObjectGroup[] returnobjects, LLUUID AgentId)
  1480. {
  1481. string message = "";
  1482. if (returnobjects.Length <= 0)
  1483. return false;
  1484. // for the moment we're going to store them individually.. however, in the future, the rezObject
  1485. // will be able to have more items.
  1486. //string returnstring = "";
  1487. //returnstring += "<scene>\n";
  1488. //for (int i = 0; i < returnobjects.Length; i++)
  1489. //{
  1490. // returnstring += grp.ToXmlString2();
  1491. //}
  1492. //returnstring += "</scene>\n";
  1493. bool permissionToDelete = false;
  1494. for (int i = 0; i < returnobjects.Length; i++)
  1495. {
  1496. CachedUserInfo userInfo =
  1497. CommsManager.UserProfileCacheService.GetUserDetails(returnobjects[i].OwnerID);
  1498. if (userInfo == null)
  1499. {
  1500. CommsManager.UserProfileCacheService.AddNewUser(returnobjects[i].OwnerID);
  1501. }
  1502. if (userInfo != null)
  1503. {
  1504. if (userInfo.HasInventory)
  1505. {
  1506. LLUUID folderID = LLUUID.Zero;
  1507. List<InventoryFolderBase> subrootfolders = userInfo.RootFolder.RequestListOfFolders();
  1508. foreach (InventoryFolderBase flder in subrootfolders)
  1509. {
  1510. if (flder.Name == "Lost And Found")
  1511. {
  1512. folderID = flder.ID;
  1513. break;
  1514. }
  1515. }
  1516. if (folderID == LLUUID.Zero)
  1517. {
  1518. folderID = userInfo.RootFolder.ID;
  1519. }
  1520. permissionToDelete = ExternalChecks.ExternalChecksCanDeleteObject(returnobjects[i].UUID, AgentId);
  1521. // If the user doesn't have permission, go on to the next one.
  1522. if (!permissionToDelete)
  1523. continue;
  1524. string sceneObjectXml = returnobjects[i].ToXmlString2();
  1525. AssetBase asset = CreateAsset(
  1526. returnobjects[i].GetPartName(returnobjects[i].LocalId),
  1527. returnobjects[i].GetPartDescription(returnobjects[i].LocalId),
  1528. (sbyte)InventoryType.Object,
  1529. (sbyte)AssetType.Object,
  1530. Helpers.StringToField(sceneObjectXml));
  1531. AssetCache.AddAsset(asset);
  1532. InventoryItemBase item = new InventoryItemBase();
  1533. item.Creator = returnobjects[i].RootPart.CreatorID;
  1534. item.Owner = returnobjects[i].OwnerID;
  1535. item.ID = LLUUID.Random();
  1536. item.AssetID = asset.FullID;
  1537. item.Description = asset.Description;
  1538. item.Name = asset.Name;
  1539. item.AssetType = asset.Type;
  1540. item.InvType = asset.InvType;
  1541. item.Folder = folderID;
  1542. if ((AgentId != returnobjects[i].RootPart.OwnerID) && ExternalChecks.ExternalChecksPropagatePermissions())
  1543. {
  1544. uint perms = returnobjects[i].GetEffectivePermissions();
  1545. uint nextPerms = (perms & 7) << 13;
  1546. if ((nextPerms & (uint)PermissionMask.Copy) == 0)
  1547. perms &= ~(uint)PermissionMask.Copy;
  1548. if ((nextPerms & (uint)PermissionMask.Transfer) == 0)
  1549. perms &= ~(uint)PermissionMask.Transfer;
  1550. if ((nextPerms & (uint)PermissionMask.Modify) == 0)
  1551. perms &= ~(uint)PermissionMask.Modify;
  1552. item.BasePermissions = perms & returnobjects[i].RootPart.NextOwnerMask;
  1553. item.CurrentPermissions = item.BasePermissions;
  1554. item.NextPermissions = returnobjects[i].RootPart.NextOwnerMask;
  1555. item.EveryOnePermissions = returnobjects[i].RootPart.EveryoneMask & returnobjects[i].RootPart.NextOwnerMask;
  1556. item.CurrentPermissions |= 8; // Slam!
  1557. }
  1558. else
  1559. {
  1560. item.BasePermissions = returnobjects[i].GetEffectivePermissions();
  1561. item.CurrentPermissions = returnobjects[i].GetEffectivePermissions();
  1562. item.NextPermissions = returnobjects[i].RootPart.NextOwnerMask;
  1563. item.EveryOnePermissions = returnobjects[i].RootPart.EveryoneMask;
  1564. }
  1565. // TODO: add the new fields (Flags, Sale info, etc)
  1566. userInfo.AddItem(item);
  1567. ScenePresence notifyUser = GetScenePresence(item.Owner);
  1568. if (notifyUser != null)
  1569. {
  1570. notifyUser.ControllingClient.SendInventoryItemCreateUpdate(item);
  1571. }
  1572. SceneObjectGroup ObjectDeleting = returnobjects[i];
  1573. returnobjects[i] = null;
  1574. DeleteSceneObject(ObjectDeleting);
  1575. ObjectDeleting = null;
  1576. }
  1577. else
  1578. {
  1579. CommsManager.UserProfileCacheService.RequestInventoryForUser(returnobjects[i].OwnerID);
  1580. message = "Still waiting on the inventory service, some of the items won't be returned until the inventory services completes it's task. Try again shortly.";
  1581. }
  1582. }
  1583. else
  1584. {
  1585. message = "Still waiting on the inventory service, some of the items won't be returned until the inventory services completes it's task. Try again shortly.";
  1586. }
  1587. //return true;
  1588. }
  1589. if (message.Length != 0)
  1590. {
  1591. ScenePresence returningavatar = GetScenePresence(AgentId);
  1592. if (returningavatar != null)
  1593. {
  1594. returningavatar.ControllingClient.SendAlertMessage(message);
  1595. }
  1596. return false;
  1597. }
  1598. return true;
  1599. }
  1600. }
  1601. }