Scene.Inventory.cs 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  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 (SceneObjectGroup group in Entities.Values)
  50. {
  51. group.StartScripts();
  52. }
  53. }
  54. /// <summary>
  55. /// Add an inventory item to an avatar's inventory.
  56. /// </summary>
  57. /// <param name="remoteClient">The remote client controlling the avatar</param>
  58. /// <param name="item">The item. This structure contains all the item metadata, including the folder
  59. /// in which the item is to be placed.</param>
  60. public void AddInventoryItem(IClientAPI remoteClient, InventoryItemBase item)
  61. {
  62. CachedUserInfo userInfo
  63. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  64. if (userInfo != null)
  65. {
  66. userInfo.AddItem(remoteClient.AgentId, item);
  67. remoteClient.SendInventoryItemCreateUpdate(item);
  68. int userlevel = 0;
  69. if (PermissionsMngr.IsEstateManager(remoteClient.AgentId))
  70. {
  71. userlevel = 1;
  72. }
  73. if (m_regInfo.MasterAvatarAssignedUUID == remoteClient.AgentId)
  74. {
  75. userlevel = 2;
  76. }
  77. EventManager.TriggerOnNewInventoryItemUploadComplete(remoteClient.AgentId, item.AssetID, item.Name, userlevel);
  78. }
  79. else
  80. {
  81. m_log.ErrorFormat(
  82. "[AGENT INVENTORY]: Agent {0} {1} was not found for add of item {2} {3}",
  83. remoteClient.Name, remoteClient.AgentId, item.Name, item.ID);
  84. return;
  85. }
  86. }
  87. /// <summary>
  88. /// <see>AddInventoryItem(LLUUID, InventoryItemBase)</see>
  89. /// </summary>
  90. /// <param name="avatarId">The ID of the avatar</param>
  91. /// <param name="item">The item. This structure contains all the item metadata, including the folder
  92. /// in which the item is to be placed.</param>
  93. public void AddInventoryItem(LLUUID avatarId, InventoryItemBase item)
  94. {
  95. ScenePresence avatar;
  96. if (!TryGetAvatar(avatarId, out avatar))
  97. {
  98. m_log.ErrorFormat(
  99. "[AGENT INVENTORY]: Could not find avatar {0} to add inventory item", avatarId);
  100. return;
  101. }
  102. AddInventoryItem(avatar.ControllingClient, item);
  103. }
  104. /// <summary>
  105. /// Capability originating call to update the asset of an item in an agent's inventory
  106. /// </summary>
  107. /// <param name="remoteClient"></param>
  108. /// <param name="itemID"></param>
  109. /// <param name="data"></param>
  110. /// <returns></returns>
  111. public LLUUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, LLUUID itemID, byte[] data)
  112. {
  113. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  114. if (userInfo != null)
  115. {
  116. if (userInfo.RootFolder != null)
  117. {
  118. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  119. if (item != null)
  120. {
  121. AssetBase asset =
  122. CreateAsset(item.Name, item.Description, (sbyte) item.InvType,
  123. (sbyte) item.AssetType, data);
  124. AssetCache.AddAsset(asset);
  125. item.AssetID = asset.FullID;
  126. userInfo.UpdateItem(remoteClient.AgentId, item);
  127. // remoteClient.SendInventoryItemCreateUpdate(item);
  128. if ((InventoryType) item.InvType == InventoryType.Notecard)
  129. {
  130. //do we want to know about updated note cards?
  131. }
  132. else if ((InventoryType) item.InvType == InventoryType.LSL)
  133. {
  134. // do we want to know about updated scripts
  135. }
  136. return (asset.FullID);
  137. }
  138. }
  139. }
  140. return LLUUID.Zero;
  141. }
  142. /// <summary>
  143. /// <see>CapsUpdatedInventoryItemAsset(IClientAPI, LLUUID, byte[])</see>
  144. /// </summary>
  145. private LLUUID CapsUpdateInventoryItemAsset(LLUUID avatarId, LLUUID itemID, byte[] data)
  146. {
  147. ScenePresence avatar;
  148. if (TryGetAvatar(avatarId, out avatar))
  149. {
  150. return CapsUpdateInventoryItemAsset(avatar.ControllingClient, itemID, data);
  151. }
  152. else
  153. {
  154. m_log.ErrorFormat(
  155. "[AGENT INVENTORY]: " +
  156. "Avatar {0} cannot be found to update its inventory item asset",
  157. avatarId);
  158. }
  159. return LLUUID.Zero;
  160. }
  161. /// <summary>
  162. /// Capability originating call to update the asset of a script in a prim's (task's) inventory
  163. /// </summary>
  164. /// <param name="remoteClient"></param>
  165. /// <param name="itemID"></param>
  166. /// <param name="primID">The prim which contains the item to update</param>
  167. /// <param name="isScriptRunning">Indicates whether the script to update is currently running</param>
  168. /// <param name="data"></param>
  169. public void CapsUpdateTaskInventoryScriptAsset(IClientAPI remoteClient, LLUUID itemId,
  170. LLUUID primId, bool isScriptRunning, byte[] data)
  171. {
  172. // Retrieve group
  173. SceneObjectPart part = GetSceneObjectPart(primId);
  174. SceneObjectGroup group = part.ParentGroup;
  175. if (null == group)
  176. {
  177. m_log.ErrorFormat(
  178. "[PRIM INVENTORY]: " +
  179. "Prim inventory update requested for item ID {0} in prim ID {1} but this prim does not exist",
  180. itemId, primId);
  181. return;
  182. }
  183. // Retrieve item
  184. TaskInventoryItem item = group.GetInventoryItem(part.LocalId, itemId);
  185. if (null == item)
  186. {
  187. return;
  188. }
  189. // Create new asset
  190. // XXX Hardcoding the numbers is a temporary measure - need an enumeration for this
  191. // There may well be one in libsecondlife
  192. AssetBase asset = CreateAsset(item.Name, item.Description, 10, 10, data);
  193. AssetCache.AddAsset(asset);
  194. // Update item with new asset
  195. item.AssetID = asset.FullID;
  196. group.UpdateInventoryItem(item);
  197. group.GetProperties(remoteClient);
  198. // Trigger rerunning of script (use TriggerRezScript event, see RezScript)
  199. if (isScriptRunning)
  200. {
  201. group.StopScript(part.LocalId, item.ItemID);
  202. group.StartScript(part.LocalId, item.ItemID);
  203. }
  204. }
  205. /// <summary>
  206. /// <see>CapsUpdateTaskInventoryScriptAsset(IClientAPI, LLUUID, LLUUID, bool, byte[])</see>
  207. /// </summary>
  208. private void CapsUpdateTaskInventoryScriptAsset(LLUUID avatarId, LLUUID itemId,
  209. LLUUID primId, bool isScriptRunning, byte[] data)
  210. {
  211. ScenePresence avatar;
  212. if (TryGetAvatar(avatarId, out avatar))
  213. {
  214. CapsUpdateTaskInventoryScriptAsset(
  215. avatar.ControllingClient, itemId, primId, isScriptRunning, data);
  216. }
  217. else
  218. {
  219. m_log.ErrorFormat(
  220. "[PRIM INVENTORY]: " +
  221. "Avatar {0} cannot be found to update its prim item asset",
  222. avatarId);
  223. }
  224. }
  225. /// <summary>
  226. /// Update an item which is either already in the client's inventory or is within
  227. /// a transaction
  228. /// </summary>
  229. /// <param name="remoteClient"></param>
  230. /// <param name="transactionID">The transaction ID. If this is LLUUID.Zero we will
  231. /// assume that we are not in a transaction</param>
  232. /// <param name="itemID">The ID of the updated item</param>
  233. /// <param name="name">The name of the updated item</param>
  234. /// <param name="description">The description of the updated item</param>
  235. /// <param name="nextOwnerMask">The permissions of the updated item</param>
  236. /* public void UpdateInventoryItemAsset(IClientAPI remoteClient, LLUUID transactionID,
  237. LLUUID itemID, string name, string description,
  238. uint nextOwnerMask)*/
  239. public void UpdateInventoryItemAsset(IClientAPI remoteClient, LLUUID transactionID,
  240. LLUUID itemID, InventoryItemBase itemUpd)
  241. {
  242. CachedUserInfo userInfo
  243. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  244. if (userInfo != null && userInfo.RootFolder != null)
  245. {
  246. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  247. if (item != null)
  248. {
  249. if (LLUUID.Zero == transactionID)
  250. {
  251. item.Name = itemUpd.Name;
  252. item.Description = itemUpd.Description;
  253. item.NextPermissions = itemUpd.NextPermissions;
  254. item.EveryOnePermissions = itemUpd.EveryOnePermissions;
  255. // TODO: Requires sanity checks
  256. //item.GroupID = itemUpd.GroupID;
  257. //item.GroupOwned = itemUpd.GroupOwned;
  258. //item.CreationDate = itemUpd.CreationDate;
  259. // TODO: Check if folder changed and move item
  260. //item.NextPermissions = itemUpd.Folder;
  261. item.InvType = itemUpd.InvType;
  262. item.SalePrice = itemUpd.SalePrice;
  263. item.SaleType = itemUpd.SaleType;
  264. item.Flags = itemUpd.Flags;
  265. userInfo.UpdateItem(remoteClient.AgentId, item);
  266. }
  267. else
  268. {
  269. IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
  270. if (agentTransactions != null)
  271. {
  272. agentTransactions.HandleItemUpdateFromTransaction(
  273. remoteClient, transactionID, item);
  274. }
  275. }
  276. }
  277. else
  278. {
  279. m_log.Error(
  280. "[AGENTINVENTORY]: Item ID " + itemID + " not found for an inventory item update.");
  281. }
  282. }
  283. else
  284. {
  285. m_log.Error(
  286. "[AGENT INVENTORY]: Agent ID " + remoteClient.AgentId + " not found for an inventory item update.");
  287. }
  288. }
  289. /// <summary>
  290. /// Give an inventory item from one avatar to another
  291. /// </summary>
  292. /// <param name="recipientClient"></param>
  293. /// <param name="senderId">ID of the sender of the item</param>
  294. /// <param name="itemId"></param>
  295. public void GiveInventoryItem(IClientAPI recipientClient, LLUUID senderId, LLUUID itemId)
  296. {
  297. // Retrieve the item from the sender
  298. CachedUserInfo senderUserInfo = CommsManager.UserProfileCacheService.GetUserDetails(senderId);
  299. if (senderUserInfo == null)
  300. {
  301. m_log.ErrorFormat(
  302. "[AGENT INVENTORY]: Failed to find sending user {0} for item {1}", senderId, itemId);
  303. return;
  304. }
  305. if (senderUserInfo.RootFolder != null)
  306. {
  307. InventoryItemBase item = senderUserInfo.RootFolder.HasItem(itemId);
  308. if (item != null)
  309. {
  310. // TODO get recipient's root folder
  311. CachedUserInfo recipientUserInfo
  312. = CommsManager.UserProfileCacheService.GetUserDetails(recipientClient.AgentId);
  313. if (recipientUserInfo != null)
  314. {
  315. // Insert a copy of the item into the recipient
  316. InventoryItemBase itemCopy = new InventoryItemBase();
  317. itemCopy.Owner = recipientClient.AgentId;
  318. itemCopy.Creator = senderId;
  319. itemCopy.ID = LLUUID.Random();
  320. itemCopy.AssetID = item.AssetID;
  321. itemCopy.Description = item.Description;
  322. itemCopy.Name = item.Name;
  323. itemCopy.AssetType = item.AssetType;
  324. itemCopy.InvType = item.InvType;
  325. itemCopy.Folder = recipientUserInfo.RootFolder.ID;
  326. itemCopy.CurrentPermissions = 2147483647;
  327. itemCopy.NextPermissions = 2147483647;
  328. itemCopy.EveryOnePermissions = item.EveryOnePermissions;
  329. itemCopy.BasePermissions = item.BasePermissions;
  330. itemCopy.CurrentPermissions = item.CurrentPermissions;
  331. itemCopy.GroupID = item.GroupID;
  332. itemCopy.GroupOwned = item.GroupOwned;
  333. itemCopy.Flags = item.Flags;
  334. itemCopy.SalePrice = item.SalePrice;
  335. itemCopy.SaleType = item.SaleType;
  336. recipientUserInfo.AddItem(recipientClient.AgentId, itemCopy);
  337. // Let the recipient client know about this new item
  338. recipientClient.SendBulkUpdateInventory(itemCopy);
  339. }
  340. else
  341. {
  342. m_log.ErrorFormat(
  343. "[AGENT INVENTORY]: Could not find userinfo for recipient user {0}, {1} of item {2}, {3} from {4}",
  344. recipientClient.Name, recipientClient.AgentId, item.Name,
  345. item.ID, senderId);
  346. }
  347. }
  348. else
  349. {
  350. m_log.ErrorFormat(
  351. "[AGENT INVENTORY]: Failed to find item {0} to give to {1}", itemId, senderId);
  352. return;
  353. }
  354. }
  355. else
  356. {
  357. m_log.Error("[AGENT INVENTORY]: Failed to find item " + itemId.ToString() + ", no root folder");
  358. return;
  359. }
  360. }
  361. public void CopyInventoryItem(IClientAPI remoteClient, uint callbackID, LLUUID oldAgentID, LLUUID oldItemID,
  362. LLUUID newFolderID, string newName)
  363. {
  364. m_log.DebugFormat(
  365. "[AGENT INVENTORY]: CopyInventoryItem received by {0} with oldAgentID {1}, oldItemID {2}, new FolderID {3}, newName {4}",
  366. remoteClient.AgentId, oldAgentID, oldItemID, newFolderID, newName);
  367. InventoryItemBase item = CommsManager.UserProfileCacheService.libraryRoot.HasItem(oldItemID);
  368. if (item == null)
  369. {
  370. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(oldAgentID);
  371. if (userInfo == null)
  372. {
  373. m_log.Error("[AGENT INVENTORY]: Failed to find user " + oldAgentID.ToString());
  374. return;
  375. }
  376. if (userInfo.RootFolder != null)
  377. {
  378. item = userInfo.RootFolder.HasItem(oldItemID);
  379. if (item == null)
  380. {
  381. m_log.Error("[AGENT INVENTORY]: Failed to find item " + oldItemID.ToString());
  382. return;
  383. }
  384. }
  385. else
  386. {
  387. m_log.Error("[AGENT INVENTORY]: Failed to find item " + oldItemID.ToString());
  388. return;
  389. }
  390. }
  391. AssetBase asset
  392. = AssetCache.GetAsset(
  393. item.AssetID, (item.AssetType == (int)AssetType.Texture ? true : false));
  394. if (asset != null)
  395. {
  396. // TODO: preserve current permissions?
  397. CreateNewInventoryItem(
  398. remoteClient, newFolderID, callbackID, asset, item.NextPermissions);
  399. }
  400. else
  401. {
  402. m_log.ErrorFormat(
  403. "[AGENT INVENTORY]: Could not copy item {0} since asset {1} could not be found",
  404. item.Name, item.AssetID);
  405. }
  406. }
  407. private AssetBase CreateAsset(string name, string description, sbyte invType, sbyte assetType, byte[] data)
  408. {
  409. AssetBase asset = new AssetBase();
  410. asset.Name = name;
  411. asset.Description = description;
  412. asset.InvType = invType;
  413. asset.Type = assetType;
  414. asset.FullID = LLUUID.Random();
  415. asset.Data = (data == null) ? new byte[1] : data;
  416. return asset;
  417. }
  418. public void MoveInventoryItem(IClientAPI remoteClient, LLUUID folderID, LLUUID itemID, int length,
  419. string newName)
  420. {
  421. m_log.DebugFormat(
  422. "[AGENT INVENTORY]: Moving item {0} to {1} for {2}", itemID, folderID, remoteClient.AgentId);
  423. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  424. if (userInfo == null)
  425. {
  426. m_log.Error("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString());
  427. return;
  428. }
  429. if (userInfo.RootFolder != null)
  430. {
  431. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  432. if (item != null)
  433. {
  434. if (newName != String.Empty)
  435. {
  436. item.Name = newName;
  437. }
  438. item.Folder = folderID;
  439. userInfo.DeleteItem(remoteClient.AgentId, item);
  440. // TODO: preserve current permissions?
  441. AddInventoryItem(remoteClient, item);
  442. }
  443. else
  444. {
  445. m_log.Error("[AGENT INVENTORY]: Failed to find item " + itemID.ToString());
  446. return;
  447. }
  448. }
  449. else
  450. {
  451. m_log.Error("[AGENT INVENTORY]: Failed to find item " + itemID.ToString() + ", no root folder");
  452. return;
  453. }
  454. }
  455. /// <summary>
  456. /// Create a new inventory item.
  457. /// </summary>
  458. /// <param name="remoteClient"></param>
  459. /// <param name="folderID"></param>
  460. /// <param name="callbackID"></param>
  461. /// <param name="asset"></param>
  462. /// <param name="nextOwnerMask"></param>
  463. private void CreateNewInventoryItem(IClientAPI remoteClient, LLUUID folderID, uint callbackID,
  464. AssetBase asset, uint nextOwnerMask)
  465. {
  466. CachedUserInfo userInfo
  467. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  468. if (userInfo != null)
  469. {
  470. InventoryItemBase item = new InventoryItemBase();
  471. item.Owner = remoteClient.AgentId;
  472. item.Creator = remoteClient.AgentId;
  473. item.ID = LLUUID.Random();
  474. item.AssetID = asset.FullID;
  475. item.Description = asset.Description;
  476. item.Name = asset.Name;
  477. item.AssetType = asset.Type;
  478. item.InvType = asset.InvType;
  479. item.Folder = folderID;
  480. item.CurrentPermissions = 2147483647;
  481. item.NextPermissions = nextOwnerMask;
  482. userInfo.AddItem(remoteClient.AgentId, item);
  483. remoteClient.SendInventoryItemCreateUpdate(item);
  484. }
  485. else
  486. {
  487. m_log.WarnFormat(
  488. "No user details associated with client {0} uuid {1} in CreateNewInventoryItem!",
  489. remoteClient.Name, remoteClient.AgentId);
  490. }
  491. }
  492. /// <summary>
  493. /// Create a new inventory item. Called when the client creates a new item directly within their
  494. /// inventory (e.g. by selecting a context inventory menu option).
  495. /// </summary>
  496. /// <param name="remoteClient"></param>
  497. /// <param name="transactionID"></param>
  498. /// <param name="folderID"></param>
  499. /// <param name="callbackID"></param>
  500. /// <param name="description"></param>
  501. /// <param name="name"></param>
  502. /// <param name="invType"></param>
  503. /// <param name="type"></param>
  504. /// <param name="wearableType"></param>
  505. /// <param name="nextOwnerMask"></param>
  506. public void CreateNewInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
  507. uint callbackID, string description, string name, sbyte invType,
  508. sbyte assetType,
  509. byte wearableType, uint nextOwnerMask)
  510. {
  511. // m_log.DebugFormat("[AGENT INVENTORY]: Received request to create inventory item {0} in folder {1}", name, folderID);
  512. if (transactionID == LLUUID.Zero)
  513. {
  514. CachedUserInfo userInfo
  515. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  516. if (userInfo != null)
  517. {
  518. ScenePresence presence;
  519. TryGetAvatar(remoteClient.AgentId, out presence);
  520. byte[] data = null;
  521. if(invType == 3 && presence != null) // libsecondlife.asset.assettype.landmark = 3 - needs to be turned into an enum
  522. {
  523. LLVector3 pos=presence.AbsolutePosition;
  524. string strdata=String.Format("Landmark version 2\nregion_id {0}\nlocal_pos {1} {2} {3}\nregion_handle {4}\n",
  525. presence.Scene.RegionInfo.RegionID,
  526. pos.X, pos.Y, pos.Z,
  527. presence.RegionHandle);
  528. data=Encoding.ASCII.GetBytes(strdata);
  529. }
  530. AssetBase asset = CreateAsset(name, description, invType, assetType, data);
  531. AssetCache.AddAsset(asset);
  532. CreateNewInventoryItem(remoteClient, folderID, callbackID, asset, nextOwnerMask);
  533. }
  534. else
  535. {
  536. m_log.ErrorFormat(
  537. "userInfo for agent uuid {0} unexpectedly null in CreateNewInventoryItem",
  538. remoteClient.AgentId);
  539. }
  540. }
  541. else
  542. {
  543. IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
  544. if (agentTransactions != null)
  545. {
  546. agentTransactions.HandleItemCreationFromTransaction(
  547. remoteClient, transactionID, folderID, callbackID, description,
  548. name, invType, assetType, wearableType, nextOwnerMask);
  549. }
  550. }
  551. }
  552. private void RemoveInventoryItem(IClientAPI remoteClient, LLUUID itemID)
  553. {
  554. CachedUserInfo userInfo
  555. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  556. if (userInfo == null)
  557. {
  558. m_log.Error("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString());
  559. return;
  560. }
  561. // is going through the root folder really the best way?
  562. // this triggers a tree walk to find and remove the item. 8-(
  563. // since this only happens in Trash (in theory) shouldn't we grab
  564. // the trash folder directly instead of RootFolder?
  565. if (userInfo.RootFolder != null)
  566. {
  567. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  568. if (item != null)
  569. {
  570. userInfo.DeleteItem(remoteClient.AgentId, item);
  571. }
  572. }
  573. }
  574. private void RemoveInventoryFolder(IClientAPI remoteClient, LLUUID folderID)
  575. {
  576. CachedUserInfo userInfo
  577. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  578. if (userInfo == null)
  579. {
  580. m_log.Error("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString());
  581. return;
  582. }
  583. if (userInfo.RootFolder != null)
  584. {
  585. InventoryItemBase folder = userInfo.RootFolder.HasItem(folderID);
  586. if (folder != null)
  587. {
  588. // doesn't work just yet, commented out. will fix in next patch.
  589. // userInfo.DeleteItem(remoteClient.AgentId, folder);
  590. }
  591. }
  592. }
  593. private SceneObjectGroup GetGroupByPrim(uint localID)
  594. {
  595. List<EntityBase> EntitieList = GetEntities();
  596. foreach (EntityBase ent in EntitieList)
  597. {
  598. if (ent is SceneObjectGroup)
  599. {
  600. if (((SceneObjectGroup) ent).HasChildPrim(localID))
  601. return (SceneObjectGroup) ent;
  602. }
  603. }
  604. return null;
  605. }
  606. /// <summary>
  607. /// Send the details of a prim's inventory to the client.
  608. /// </summary>
  609. /// <param name="remoteClient"></param>
  610. /// <param name="primLocalID"></param>
  611. public void RequestTaskInventory(IClientAPI remoteClient, uint primLocalID)
  612. {
  613. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  614. if (group != null)
  615. {
  616. bool fileChange = group.GetPartInventoryFileName(remoteClient, primLocalID);
  617. if (fileChange)
  618. {
  619. if (XferManager != null)
  620. {
  621. group.RequestInventoryFile(primLocalID, XferManager);
  622. }
  623. }
  624. }
  625. else
  626. {
  627. m_log.ErrorFormat(
  628. "[PRIM INVENTORY]: Inventory requested of prim {0} which doesn't exist", primLocalID);
  629. }
  630. }
  631. /// <summary>
  632. /// Remove an item from a prim (task) inventory
  633. /// </summary>
  634. /// <param name="remoteClient">Unused at the moment but retained since the avatar ID might
  635. /// be necessary for a permissions check at some stage.</param>
  636. /// <param name="itemID"></param>
  637. /// <param name="localID"></param>
  638. public void RemoveTaskInventory(IClientAPI remoteClient, LLUUID itemID, uint localID)
  639. {
  640. SceneObjectGroup group = GetGroupByPrim(localID);
  641. if (group != null)
  642. {
  643. int type = group.RemoveInventoryItem(localID, itemID);
  644. group.GetProperties(remoteClient);
  645. if (type == 10)
  646. {
  647. EventManager.TriggerRemoveScript(localID, itemID);
  648. }
  649. }
  650. else
  651. {
  652. m_log.ErrorFormat(
  653. "[PRIM INVENTORY]: " +
  654. "Removal of item {0} requested of prim {1} but this prim does not exist",
  655. itemID,
  656. localID);
  657. }
  658. }
  659. /// <summary>
  660. /// Move the given item in the given prim to a folder in the client's inventory
  661. /// </summary>
  662. /// <param name="remoteClient"></param>
  663. /// <param name="folderID"></param>
  664. /// <param name="primLocalID"></param>
  665. /// <param name="itemID"></param>
  666. public void MoveTaskInventoryItem(IClientAPI remoteClient, LLUUID folderId, uint primLocalId, LLUUID itemId)
  667. {
  668. SceneObjectGroup group = GetGroupByPrim(primLocalId);
  669. if (null == group)
  670. {
  671. m_log.WarnFormat(
  672. "[PRIM INVENTORY]: " +
  673. "Move of inventory item {0} from prim with local id {1} failed because the prim could not be found",
  674. itemId, primLocalId);
  675. return;
  676. }
  677. TaskInventoryItem taskItem = group.GetInventoryItem(primLocalId, itemId);
  678. if (null == taskItem)
  679. {
  680. // Console already notified of error in GetInventoryItem
  681. return;
  682. }
  683. // bool permission;
  684. // permission = PermissionsMngr.CanCopyObject(remoteClient.AgentId,
  685. // ((SceneObjectGroup) selectedEnt).UUID);
  686. // Pending resolving upstream problems with permissions, we just won't allow anybody who is not the owner
  687. // to copy
  688. if (remoteClient.AgentId != taskItem.OwnerID)
  689. {
  690. m_log.InfoFormat(
  691. "[PRIM INVENTORY]: Attempt made by {0} {1} to copy inventory item {2} {3} in prim {4} {5},"
  692. + " but temporarily not allowed pending upstream bugfixes/feature implementation",
  693. remoteClient.Name, remoteClient.AgentId, taskItem.Name, taskItem.ItemID, group.Name, group.UUID);
  694. return;
  695. }
  696. InventoryItemBase agentItem = new InventoryItemBase();
  697. agentItem.ID = LLUUID.Random();
  698. agentItem.Creator = taskItem.CreatorID;
  699. agentItem.Owner = remoteClient.AgentId;
  700. agentItem.AssetID = taskItem.AssetID;
  701. agentItem.Description = taskItem.Description;
  702. agentItem.Name = taskItem.Name;
  703. agentItem.AssetType = taskItem.Type;
  704. agentItem.InvType = taskItem.InvType;
  705. agentItem.Folder = folderId;
  706. agentItem.EveryOnePermissions = taskItem.EveryoneMask;
  707. if (remoteClient.AgentId != taskItem.OwnerID) {
  708. agentItem.BasePermissions = taskItem.NextOwnerMask;
  709. agentItem.CurrentPermissions = taskItem.NextOwnerMask;
  710. agentItem.NextPermissions = taskItem.NextOwnerMask;
  711. }
  712. else
  713. {
  714. agentItem.BasePermissions = taskItem.BaseMask;
  715. agentItem.CurrentPermissions = taskItem.OwnerMask;
  716. agentItem.NextPermissions = taskItem.NextOwnerMask;
  717. }
  718. AddInventoryItem(remoteClient, agentItem);
  719. }
  720. /// <summary>
  721. /// Update an item in a prim (task) inventory.
  722. /// This method does not handle scripts, <see>RezScript(IClientAPI, LLUUID, unit)</see>
  723. /// </summary>
  724. /// <param name="remoteClient"></param>
  725. /// <param name="itemID"></param>
  726. /// <param name="folderID"></param>
  727. /// <param name="primLocalID"></param>
  728. public void UpdateTaskInventory(IClientAPI remoteClient, LLUUID itemID, LLUUID folderID,
  729. uint primLocalID)
  730. {
  731. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  732. if (group != null)
  733. {
  734. LLUUID copyID = LLUUID.Random();
  735. if (itemID != LLUUID.Zero)
  736. {
  737. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  738. if (userInfo != null && userInfo.RootFolder != null)
  739. {
  740. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  741. // Try library
  742. // XXX clumsy, possibly should be one call
  743. if (null == item)
  744. {
  745. item = CommsManager.UserProfileCacheService.libraryRoot.HasItem(itemID);
  746. }
  747. if (item != null)
  748. {
  749. group.AddInventoryItem(remoteClient, primLocalID, item, copyID);
  750. m_log.InfoFormat(
  751. "[PRIM INVENTORY]: Update with item {0} requested of prim {1} for {2}",
  752. item.Name, primLocalID, remoteClient.Name);
  753. group.GetProperties(remoteClient);
  754. }
  755. else
  756. {
  757. m_log.ErrorFormat(
  758. "[PRIM INVENTORY]: Could not find inventory item {0} to update for {1}!",
  759. itemID, remoteClient.Name);
  760. }
  761. }
  762. }
  763. }
  764. else
  765. {
  766. m_log.WarnFormat(
  767. "[PRIM INVENTORY]: " +
  768. "Update with item {0} requested of prim {1} for {2} but this prim does not exist",
  769. itemID, primLocalID, remoteClient.Name);
  770. }
  771. }
  772. /// <summary>
  773. /// Rez a script into a prim's inventory
  774. /// </summary>
  775. /// <param name="remoteClient"></param>
  776. /// <param name="itemID"> </param>
  777. /// <param name="localID"></param>
  778. public void RezScript(IClientAPI remoteClient, LLUUID itemID, uint localID)
  779. {
  780. LLUUID copyID = LLUUID.Random();
  781. if (itemID != LLUUID.Zero)
  782. {
  783. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  784. if (userInfo != null && userInfo.RootFolder != null)
  785. {
  786. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  787. // Try library
  788. // XXX clumsy, possibly should be one call
  789. if (null == item)
  790. {
  791. item = CommsManager.UserProfileCacheService.libraryRoot.HasItem(itemID);
  792. }
  793. if (item != null)
  794. {
  795. SceneObjectGroup group = GetGroupByPrim(localID);
  796. if (group != null)
  797. {
  798. group.AddInventoryItem(remoteClient, localID, item, copyID);
  799. group.StartScript(localID, copyID);
  800. group.GetProperties(remoteClient);
  801. // m_log.InfoFormat("[PRIMINVENTORY]: " +
  802. // "Rezzed script {0} into prim local ID {1} for user {2}",
  803. // item.inventoryName, localID, remoteClient.Name);
  804. }
  805. else
  806. {
  807. m_log.ErrorFormat(
  808. "[PRIM INVENTORY]: " +
  809. "Could not rez script {0} into prim local ID {1} for user {2}"
  810. + " because the prim could not be found in the region!",
  811. item.Name, localID, remoteClient.Name);
  812. }
  813. }
  814. else
  815. {
  816. m_log.ErrorFormat(
  817. "[PRIM INVENTORY]: Could not find script inventory item {0} to rez for {1}!",
  818. itemID, remoteClient.Name);
  819. }
  820. }
  821. }
  822. else // If the itemID is zero then the script has been rezzed directly in an object's inventory
  823. {
  824. // not yet implemented
  825. // TODO Need to get more details from original RezScript packet
  826. // XXX jc tmp
  827. // AssetBase asset = CreateAsset("chimney sweep", "sailor.lsl", 10, 10, null);
  828. // AssetCache.AddAsset(asset);
  829. }
  830. }
  831. /// <summary>
  832. /// Called when an object is removed from the environment into inventory.
  833. /// </summary>
  834. /// <param name="packet"></param>
  835. /// <param name="simClient"></param>
  836. public virtual void DeRezObject(Packet packet, IClientAPI remoteClient)
  837. {
  838. DeRezObjectPacket DeRezPacket = (DeRezObjectPacket) packet;
  839. if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero)
  840. {
  841. //currently following code not used (or don't know of any case of destination being zero
  842. }
  843. else
  844. {
  845. foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData)
  846. {
  847. // m_log.DebugFormat(
  848. // "[AGENT INVENTORY]: Received request to derez {0} into folder {1}",
  849. // Data.ObjectLocalID, DeRezPacket.AgentBlock.DestinationID);
  850. EntityBase selectedEnt = null;
  851. //m_log.Info("[CLIENT]: LocalID:" + Data.ObjectLocalID.ToString());
  852. List<EntityBase> EntitieList = GetEntities();
  853. foreach (EntityBase ent in EntitieList)
  854. {
  855. if (ent.LocalId == Data.ObjectLocalID)
  856. {
  857. selectedEnt = ent;
  858. break;
  859. }
  860. }
  861. if (selectedEnt != null)
  862. {
  863. bool permission;
  864. if (DeRezPacket.AgentBlock.Destination == 1)
  865. { // Take Copy
  866. permission = PermissionsMngr.CanCopyObject(remoteClient.AgentId,
  867. ((SceneObjectGroup) selectedEnt).UUID);
  868. }
  869. else
  870. { // Take
  871. permission = PermissionsMngr.CanDeRezObject(remoteClient.AgentId,
  872. ((SceneObjectGroup) selectedEnt).UUID);
  873. }
  874. if (permission)
  875. {
  876. SceneObjectGroup objectGroup = (SceneObjectGroup) selectedEnt;
  877. string sceneObjectXml = objectGroup.ToXmlString();
  878. CachedUserInfo userInfo =
  879. CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  880. if (userInfo != null)
  881. {
  882. AssetBase asset = CreateAsset(
  883. ((SceneObjectGroup) selectedEnt).GetPartName(selectedEnt.LocalId),
  884. ((SceneObjectGroup) selectedEnt).GetPartDescription(selectedEnt.LocalId),
  885. (sbyte) InventoryType.Object,
  886. (sbyte) AssetType.Object,
  887. Helpers.StringToField(sceneObjectXml));
  888. AssetCache.AddAsset(asset);
  889. InventoryItemBase item = new InventoryItemBase();
  890. item.Creator = objectGroup.RootPart.CreatorID;
  891. item.Owner = remoteClient.AgentId;
  892. item.ID = LLUUID.Random();
  893. item.AssetID = asset.FullID;
  894. item.Description = asset.Description;
  895. item.Name = asset.Name;
  896. item.AssetType = asset.Type;
  897. item.InvType = asset.InvType;
  898. item.Folder = DeRezPacket.AgentBlock.DestinationID;
  899. item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask;
  900. if (remoteClient.AgentId != objectGroup.RootPart.OwnerID) {
  901. item.BasePermissions = objectGroup.RootPart.NextOwnerMask;
  902. item.CurrentPermissions = objectGroup.RootPart.NextOwnerMask;
  903. item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
  904. }
  905. else
  906. {
  907. item.BasePermissions = objectGroup.RootPart.BaseMask;
  908. item.CurrentPermissions = objectGroup.RootPart.OwnerMask;
  909. item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
  910. }
  911. // TODO: add the new fields (Flags, Sale info, etc)
  912. userInfo.AddItem(remoteClient.AgentId, item);
  913. remoteClient.SendInventoryItemCreateUpdate(item);
  914. }
  915. // FIXME: Nasty hardcoding. If Destination is 1 then client wants us to take a copy
  916. if (DeRezPacket.AgentBlock.Destination != 1)
  917. {
  918. DeleteSceneObjectGroup(objectGroup);
  919. }
  920. }
  921. }
  922. }
  923. }
  924. }
  925. public void updateKnownAsset(IClientAPI remoteClient, SceneObjectGroup grp, LLUUID assetID, LLUUID agentID)
  926. {
  927. SceneObjectGroup objectGroup = grp;
  928. if (objectGroup != null)
  929. {
  930. string sceneObjectXml = objectGroup.ToXmlString();
  931. CachedUserInfo userInfo =
  932. CommsManager.UserProfileCacheService.GetUserDetails(agentID);
  933. if (userInfo != null)
  934. {
  935. Queue<InventoryFolderImpl> searchfolders = new Queue<InventoryFolderImpl>();
  936. searchfolders.Enqueue(userInfo.RootFolder);
  937. LLUUID foundFolder = userInfo.RootFolder.ID;
  938. // search through folders to find the asset.
  939. while (searchfolders.Count > 0)
  940. {
  941. InventoryFolderImpl fld = searchfolders.Dequeue();
  942. lock (fld)
  943. {
  944. if (fld != null)
  945. {
  946. if (fld.Items.ContainsKey(assetID))
  947. {
  948. foundFolder = fld.ID;
  949. searchfolders.Clear();
  950. break;
  951. }
  952. else
  953. {
  954. foreach (InventoryFolderImpl subfld in fld.SubFolders.Values)
  955. {
  956. searchfolders.Enqueue(subfld);
  957. }
  958. }
  959. }
  960. }
  961. }
  962. AssetBase asset = CreateAsset(
  963. objectGroup.GetPartName(objectGroup.LocalId),
  964. objectGroup.GetPartDescription(objectGroup.LocalId),
  965. (sbyte)InventoryType.Object,
  966. (sbyte)AssetType.Object,
  967. Helpers.StringToField(sceneObjectXml));
  968. AssetCache.AddAsset(asset);
  969. InventoryItemBase item = new InventoryItemBase();
  970. item.Creator = objectGroup.RootPart.CreatorID;
  971. item.Owner = agentID;
  972. item.ID = assetID;
  973. item.AssetID = asset.FullID;
  974. item.Description = asset.Description;
  975. item.Name = asset.Name;
  976. item.AssetType = asset.Type;
  977. item.InvType = asset.InvType;
  978. // Sticking it in root folder for now.. objects folder later?
  979. item.Folder = foundFolder;// DeRezPacket.AgentBlock.DestinationID;
  980. item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask;
  981. if (agentID != objectGroup.RootPart.OwnerID)
  982. {
  983. item.BasePermissions = objectGroup.RootPart.NextOwnerMask;
  984. item.CurrentPermissions = objectGroup.RootPart.NextOwnerMask;
  985. item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
  986. }
  987. else
  988. {
  989. item.BasePermissions = objectGroup.RootPart.BaseMask;
  990. item.CurrentPermissions = objectGroup.RootPart.OwnerMask;
  991. item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
  992. }
  993. userInfo.AddItem(agentID, item);
  994. // this gets called when the agent loggs off!
  995. if (remoteClient != null)
  996. {
  997. remoteClient.SendInventoryItemCreateUpdate(item);
  998. }
  999. }
  1000. }
  1001. }
  1002. public LLUUID attachObjectAssetStore(IClientAPI remoteClient, SceneObjectGroup grp, LLUUID AgentId)
  1003. {
  1004. SceneObjectGroup objectGroup = grp;
  1005. if (objectGroup != null)
  1006. {
  1007. string sceneObjectXml = objectGroup.ToXmlString();
  1008. CachedUserInfo userInfo =
  1009. CommsManager.UserProfileCacheService.GetUserDetails(AgentId);
  1010. if (userInfo != null)
  1011. {
  1012. AssetBase asset = CreateAsset(
  1013. objectGroup.GetPartName(objectGroup.LocalId),
  1014. objectGroup.GetPartDescription(objectGroup.LocalId),
  1015. (sbyte)InventoryType.Object,
  1016. (sbyte)AssetType.Object,
  1017. Helpers.StringToField(sceneObjectXml));
  1018. AssetCache.AddAsset(asset);
  1019. InventoryItemBase item = new InventoryItemBase();
  1020. item.Creator = objectGroup.RootPart.CreatorID;
  1021. item.Owner = remoteClient.AgentId;
  1022. item.ID = LLUUID.Random();
  1023. item.AssetID = asset.FullID;
  1024. item.Description = asset.Description;
  1025. item.Name = asset.Name;
  1026. item.AssetType = asset.Type;
  1027. item.InvType = asset.InvType;
  1028. // Sticking it in root folder for now.. objects folder later?
  1029. item.Folder = userInfo.RootFolder.ID;// DeRezPacket.AgentBlock.DestinationID;
  1030. item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask;
  1031. if (remoteClient.AgentId != objectGroup.RootPart.OwnerID)
  1032. {
  1033. item.BasePermissions = objectGroup.RootPart.NextOwnerMask;
  1034. item.CurrentPermissions = objectGroup.RootPart.NextOwnerMask;
  1035. item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
  1036. }
  1037. else
  1038. {
  1039. item.BasePermissions = objectGroup.RootPart.BaseMask;
  1040. item.CurrentPermissions = objectGroup.RootPart.OwnerMask;
  1041. item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
  1042. }
  1043. userInfo.AddItem(remoteClient.AgentId, item);
  1044. remoteClient.SendInventoryItemCreateUpdate(item);
  1045. return item.AssetID;
  1046. }
  1047. return LLUUID.Zero;
  1048. }
  1049. return LLUUID.Zero;
  1050. }
  1051. /// <summary>
  1052. /// Event Handler Rez an object into a scene
  1053. /// Calls the non-void event handler
  1054. /// </summary>
  1055. /// <param name="remoteClient"></param>
  1056. /// <param name="itemID"></param>
  1057. /// <param name="RayEnd"></param>
  1058. /// <param name="RayStart"></param>
  1059. /// <param name="RayTargetID"></param>
  1060. /// <param name="BypassRayCast"></param>
  1061. /// <param name="RayEndIsIntersection"></param>
  1062. /// <param name="EveryoneMask"></param>
  1063. /// <param name="GroupMask"></param>
  1064. /// <param name="NextOwnerMask"></param>
  1065. /// <param name="ItemFlags"></param>
  1066. /// <param name="RezSelected"></param>
  1067. /// <param name="RemoveItem"></param>
  1068. /// <param name="fromTaskID"></param>
  1069. public virtual void RezObject(IClientAPI remoteClient, LLUUID itemID, LLVector3 RayEnd, LLVector3 RayStart,
  1070. LLUUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
  1071. uint EveryoneMask, uint GroupMask, uint NextOwnerMask, uint ItemFlags,
  1072. bool RezSelected, bool RemoveItem, LLUUID fromTaskID)
  1073. {
  1074. SceneObjectGroup sog = RezObject(remoteClient, itemID, RayEnd, RayStart,
  1075. RayTargetID, BypassRayCast, RayEndIsIntersection,
  1076. EveryoneMask, GroupMask, NextOwnerMask, ItemFlags,
  1077. RezSelected, RemoveItem, fromTaskID, false);
  1078. }
  1079. /// <summary>
  1080. /// Returns SceneObjectGroup or null from asset request.
  1081. /// </summary>
  1082. /// <param name="remoteClient"></param>
  1083. /// <param name="itemID"></param>
  1084. /// <param name="RayEnd"></param>
  1085. /// <param name="RayStart"></param>
  1086. /// <param name="RayTargetID"></param>
  1087. /// <param name="BypassRayCast"></param>
  1088. /// <param name="RayEndIsIntersection"></param>
  1089. /// <param name="EveryoneMask"></param>
  1090. /// <param name="GroupMask"></param>
  1091. /// <param name="NextOwnerMask"></param>
  1092. /// <param name="ItemFlags"></param>
  1093. /// <param name="RezSelected"></param>
  1094. /// <param name="RemoveItem"></param>
  1095. /// <param name="fromTaskID"></param>
  1096. /// <param name="difference"></param>
  1097. /// <returns></returns>
  1098. public virtual SceneObjectGroup RezObject(IClientAPI remoteClient, LLUUID itemID, LLVector3 RayEnd, LLVector3 RayStart,
  1099. LLUUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
  1100. uint EveryoneMask, uint GroupMask, uint NextOwnerMask, uint ItemFlags,
  1101. bool RezSelected, bool RemoveItem, LLUUID fromTaskID, bool attachment)
  1102. {
  1103. // Work out position details
  1104. byte bRayEndIsIntersection = (byte)0;
  1105. if (RayEndIsIntersection)
  1106. {
  1107. bRayEndIsIntersection = (byte)1;
  1108. }
  1109. else
  1110. {
  1111. bRayEndIsIntersection = (byte)0;
  1112. }
  1113. LLVector3 scale = new LLVector3(0.5f, 0.5f, 0.5f);
  1114. LLVector3 pos = GetNewRezLocation(
  1115. RayStart, RayEnd, RayTargetID, new LLQuaternion(0, 0, 0, 1),
  1116. BypassRayCast, bRayEndIsIntersection,true,scale, false);
  1117. if (!PermissionsMngr.CanRezObject(remoteClient.AgentId, pos) && !attachment)
  1118. {
  1119. return null;
  1120. }
  1121. // Rez object
  1122. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  1123. if (userInfo != null)
  1124. {
  1125. if (userInfo.RootFolder != null)
  1126. {
  1127. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  1128. if (item != null)
  1129. {
  1130. AssetBase rezAsset = AssetCache.GetAsset(item.AssetID, false);
  1131. if (rezAsset != null)
  1132. {
  1133. string xmlData = Helpers.FieldToUTF8String(rezAsset.Data);
  1134. SceneObjectGroup group = new SceneObjectGroup(this, m_regionHandle, xmlData);
  1135. group.ResetIDs();
  1136. AddEntity(group);
  1137. // if attachment we set it's asset id so object updates can reflect that
  1138. // if not, we set it's position in world.
  1139. if (!attachment)
  1140. {
  1141. pos = GetNewRezLocation(
  1142. RayStart, RayEnd, RayTargetID, new LLQuaternion(0, 0, 0, 1),
  1143. BypassRayCast, bRayEndIsIntersection, true, group.GroupScale(), false);
  1144. group.AbsolutePosition = pos;
  1145. }
  1146. else
  1147. {
  1148. group.SetFromAssetID(itemID);
  1149. }
  1150. SceneObjectPart rootPart = group.GetChildPart(group.UUID);
  1151. // Since renaming the item in the inventory does not affect the name stored
  1152. // in the serialization, transfer the correct name from the inventory to the
  1153. // object itself before we rez.
  1154. rootPart.Name = item.Name;
  1155. rootPart.Description = item.Description;
  1156. List<SceneObjectPart> partList = new List<SceneObjectPart>(group.Children.Values);
  1157. foreach (SceneObjectPart part in partList)
  1158. {
  1159. if (part.OwnerID != item.Owner)
  1160. {
  1161. part.LastOwnerID = part.OwnerID;
  1162. part.OwnerID = item.Owner;
  1163. part.EveryoneMask = item.EveryOnePermissions;
  1164. part.BaseMask = item.BasePermissions;
  1165. part.OwnerMask = item.CurrentPermissions;
  1166. part.NextOwnerMask = item.NextPermissions;
  1167. part.ChangeInventoryOwner(item.Owner);
  1168. }
  1169. }
  1170. rootPart.TrimPermissions();
  1171. if (!attachment)
  1172. {
  1173. if (group.RootPart.Shape.PCode == (byte)PCode.Prim)
  1174. {
  1175. group.ClearPartAttachmentData();
  1176. }
  1177. group.ApplyPhysics(m_physicalPrim);
  1178. }
  1179. group.StartScripts();
  1180. if (!attachment)
  1181. rootPart.ScheduleFullUpdate();
  1182. return rootPart.ParentGroup;
  1183. }
  1184. }
  1185. }
  1186. }
  1187. return null;
  1188. }
  1189. }
  1190. }