Scene.Inventory.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  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 Axiom.Math;
  30. using libsecondlife;
  31. using libsecondlife.Packets;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Communications.Cache;
  34. using OpenSim.Framework.Console;
  35. using System.IO;
  36. using System.Text;
  37. using System.Xml;
  38. using OpenSim.Region.Environment.Interfaces;
  39. namespace OpenSim.Region.Environment.Scenes
  40. {
  41. public partial class Scene
  42. {
  43. private static readonly log4net.ILog m_log
  44. = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  45. /// <summary>
  46. /// Start all the scripts in the scene which should be started.
  47. /// </summary>
  48. public void StartScripts()
  49. {
  50. m_log.Info("[PRIM INVENTORY]: Starting scripts in scene");
  51. foreach (SceneObjectGroup group in Entities.Values)
  52. {
  53. group.StartScripts();
  54. }
  55. }
  56. /// <summary>
  57. /// Add an inventory item to an avatar's inventory.
  58. /// </summary>
  59. /// <param name="remoteClient">The remote client controlling the avatar</param>
  60. /// <param name="item">The item. This structure contains all the item metadata, including the folder
  61. /// in which the item is to be placed.</param>
  62. public void AddInventoryItem(IClientAPI remoteClient, InventoryItemBase item)
  63. {
  64. CachedUserInfo userInfo
  65. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  66. if (userInfo != null)
  67. {
  68. userInfo.AddItem(remoteClient.AgentId, item);
  69. remoteClient.SendInventoryItemCreateUpdate(item);
  70. }
  71. }
  72. /// <summary>
  73. /// <see>AddInventoryItem(LLUUID, InventoryItemBase)</see>
  74. /// </summary>
  75. /// <param name="avatarId">The ID of the avatar</param>
  76. /// <param name="item">The item. This structure contains all the item metadata, including the folder
  77. /// in which the item is to be placed.</param>
  78. public void AddInventoryItem(LLUUID avatarId, InventoryItemBase item)
  79. {
  80. ScenePresence avatar;
  81. if (!TryGetAvatar(avatarId, out avatar))
  82. {
  83. m_log.ErrorFormat(
  84. "[AGENT INVENTORY]: Could not find avatar {0} to add inventory item", avatarId);
  85. return;
  86. }
  87. AddInventoryItem(avatar.ControllingClient, item);
  88. }
  89. /// <summary>
  90. /// Capability originating call to update the asset of an item in an agent's inventory
  91. /// </summary>
  92. /// <param name="remoteClient"></param>
  93. /// <param name="itemID"></param>
  94. /// <param name="data"></param>
  95. /// <returns></returns>
  96. public LLUUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, LLUUID itemID, byte[] data)
  97. {
  98. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  99. if (userInfo != null)
  100. {
  101. if (userInfo.RootFolder != null)
  102. {
  103. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  104. if (item != null)
  105. {
  106. AssetBase asset =
  107. CreateAsset(item.inventoryName, item.inventoryDescription, (sbyte) item.invType,
  108. (sbyte) item.assetType, data);
  109. AssetCache.AddAsset(asset);
  110. item.assetID = asset.FullID;
  111. userInfo.UpdateItem(remoteClient.AgentId, item);
  112. // remoteClient.SendInventoryItemCreateUpdate(item);
  113. if ((InventoryType) item.invType == InventoryType.Notecard)
  114. {
  115. //do we want to know about updated note cards?
  116. }
  117. else if ((InventoryType) item.invType == InventoryType.LSL)
  118. {
  119. // do we want to know about updated scripts
  120. }
  121. return (asset.FullID);
  122. }
  123. }
  124. }
  125. return LLUUID.Zero;
  126. }
  127. /// <summary>
  128. /// <see>CapsUpdatedInventoryItemAsset(IClientAPI, LLUUID, byte[])</see>
  129. /// </summary>
  130. private LLUUID CapsUpdateInventoryItemAsset(LLUUID avatarId, LLUUID itemID, byte[] data)
  131. {
  132. ScenePresence avatar;
  133. if (TryGetAvatar(avatarId, out avatar))
  134. {
  135. return CapsUpdateInventoryItemAsset(avatar.ControllingClient, itemID, data);
  136. }
  137. else
  138. {
  139. m_log.ErrorFormat(
  140. "[AGENT INVENTORY]: " +
  141. "Avatar {0} cannot be found to update its inventory item asset",
  142. avatarId);
  143. }
  144. return LLUUID.Zero;
  145. }
  146. /// <summary>
  147. /// Capability originating call to update the asset of a script in a prim's (task's) inventory
  148. /// </summary>
  149. /// <param name="remoteClient"></param>
  150. /// <param name="itemID"></param>
  151. /// <param name="primID">The prim which contains the item to update</param>
  152. /// <param name="isScriptRunning">Indicates whether the script to update is currently running</param>
  153. /// <param name="data"></param>
  154. public void CapsUpdateTaskInventoryScriptAsset(IClientAPI remoteClient, LLUUID itemId,
  155. LLUUID primId, bool isScriptRunning, byte[] data)
  156. {
  157. // Retrieve group
  158. SceneObjectPart part = GetSceneObjectPart(primId);
  159. SceneObjectGroup group = part.ParentGroup;
  160. if (null == group)
  161. {
  162. m_log.ErrorFormat(
  163. "[PRIM INVENTORY]: " +
  164. "Prim inventory update requested for item ID {0} in prim ID {1} but this prim does not exist",
  165. itemId, primId);
  166. return;
  167. }
  168. // Retrieve item
  169. TaskInventoryItem item = group.GetInventoryItem(part.LocalId, itemId);
  170. if (null == item)
  171. {
  172. return;
  173. }
  174. // Create new asset
  175. // XXX Hardcoding the numbers is a temporary measure - need an enumeration for this
  176. // There may well be one in libsecondlife
  177. AssetBase asset = CreateAsset(item.Name, item.Description, 10, 10, data);
  178. AssetCache.AddAsset(asset);
  179. // Update item with new asset
  180. item.AssetID = asset.FullID;
  181. group.UpdateInventoryItem(item);
  182. group.GetProperties(remoteClient);
  183. // Trigger rerunning of script (use TriggerRezScript event, see RezScript)
  184. if (isScriptRunning)
  185. {
  186. group.StopScript(part.LocalId, item.ItemID);
  187. group.StartScript(part.LocalId, item.ItemID);
  188. }
  189. }
  190. /// <summary>
  191. /// <see>CapsUpdateTaskInventoryScriptAsset(IClientAPI, LLUUID, LLUUID, bool, byte[])</see>
  192. /// </summary>
  193. private void CapsUpdateTaskInventoryScriptAsset(LLUUID avatarId, LLUUID itemId,
  194. LLUUID primId, bool isScriptRunning, byte[] data)
  195. {
  196. ScenePresence avatar;
  197. if (TryGetAvatar(avatarId, out avatar))
  198. {
  199. CapsUpdateTaskInventoryScriptAsset(
  200. avatar.ControllingClient, itemId, primId, isScriptRunning, data);
  201. }
  202. else
  203. {
  204. m_log.ErrorFormat(
  205. "[PRIM INVENTORY]: " +
  206. "Avatar {0} cannot be found to update its prim item asset",
  207. avatarId);
  208. }
  209. }
  210. /// <summary>
  211. /// Update an item which is either already in the client's inventory or is within
  212. /// a transaction
  213. /// </summary>
  214. /// <param name="remoteClient"></param>
  215. /// <param name="transactionID">The transaction ID. If this is LLUUID.Zero we will
  216. /// assume that we are not in a transaction</param>
  217. /// <param name="itemID">The ID of the updated item</param>
  218. /// <param name="name">The name of the updated item</param>
  219. /// <param name="description">The description of the updated item</param>
  220. /// <param name="nextOwnerMask">The permissions of the updated item</param>
  221. public void UpdateInventoryItemAsset(IClientAPI remoteClient, LLUUID transactionID,
  222. LLUUID itemID, string name, string description,
  223. uint nextOwnerMask)
  224. {
  225. CachedUserInfo userInfo
  226. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  227. if (userInfo != null && userInfo.RootFolder != null)
  228. {
  229. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  230. if (item != null)
  231. {
  232. if (LLUUID.Zero == transactionID)
  233. {
  234. item.inventoryName = name;
  235. item.inventoryDescription = description;
  236. item.inventoryNextPermissions = nextOwnerMask;
  237. userInfo.UpdateItem(remoteClient.AgentId, item);
  238. }
  239. else
  240. {
  241. IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
  242. if (agentTransactions != null)
  243. {
  244. agentTransactions.HandleItemUpdateFromTransaction(
  245. remoteClient, transactionID, item);
  246. }
  247. }
  248. }
  249. else
  250. {
  251. m_log.Error(
  252. "[AGENTINVENTORY]: Item ID " + itemID + " not found for an inventory item update.");
  253. }
  254. }
  255. else
  256. {
  257. m_log.Error(
  258. "[AGENT INVENTORY]: Agent ID " + remoteClient.AgentId + " not found for an inventory item update.");
  259. }
  260. }
  261. public void CopyInventoryItem(IClientAPI remoteClient, uint callbackID, LLUUID oldAgentID, LLUUID oldItemID,
  262. LLUUID newFolderID, string newName)
  263. {
  264. InventoryItemBase item = CommsManager.UserProfileCacheService.libraryRoot.HasItem(oldItemID);
  265. if (item == null)
  266. {
  267. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(oldAgentID);
  268. if (userInfo == null)
  269. {
  270. m_log.Error("[AGENT INVENTORY]: Failed to find user " + oldAgentID.ToString());
  271. return;
  272. }
  273. if (userInfo.RootFolder != null)
  274. {
  275. item = userInfo.RootFolder.HasItem(oldItemID);
  276. if (item == null)
  277. {
  278. m_log.Error("[AGENT INVENTORY]: Failed to find item " + oldItemID.ToString());
  279. return;
  280. }
  281. }
  282. else
  283. {
  284. m_log.Error("[AGENT INVENTORY]: Failed to find item " + oldItemID.ToString());
  285. return;
  286. }
  287. }
  288. AssetBase asset
  289. = AssetCache.GetAsset(
  290. item.assetID, (item.assetType == (int)AssetType.Texture ? true : false));
  291. if (asset != null)
  292. {
  293. // TODO: preserve current permissions?
  294. CreateNewInventoryItem(
  295. remoteClient, newFolderID, callbackID, asset, item.inventoryNextPermissions);
  296. }
  297. else
  298. {
  299. m_log.ErrorFormat(
  300. "[AGENT INVENTORY]: Could not copy item {0} since asset {1} could not be found",
  301. item.inventoryName, item.assetID);
  302. }
  303. }
  304. private AssetBase CreateAsset(string name, string description, sbyte invType, sbyte assetType, byte[] data)
  305. {
  306. AssetBase asset = new AssetBase();
  307. asset.Name = name;
  308. asset.Description = description;
  309. asset.InvType = invType;
  310. asset.Type = assetType;
  311. asset.FullID = LLUUID.Random();
  312. asset.Data = (data == null) ? new byte[1] : data;
  313. return asset;
  314. }
  315. public void MoveInventoryItem(IClientAPI remoteClient, LLUUID folderID, LLUUID itemID, int length,
  316. string newName)
  317. {
  318. m_log.Info(
  319. "[AGENT INVENTORY]: " +
  320. "Moving item for " + remoteClient.AgentId.ToString());
  321. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  322. if (userInfo == null)
  323. {
  324. m_log.Error("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString());
  325. return;
  326. }
  327. if (userInfo.RootFolder != null)
  328. {
  329. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  330. if (item != null)
  331. {
  332. if (newName != System.String.Empty)
  333. {
  334. item.inventoryName = newName;
  335. }
  336. item.parentFolderID = folderID;
  337. userInfo.DeleteItem(remoteClient.AgentId, item);
  338. // TODO: preserve current permissions?
  339. AddInventoryItem(remoteClient, item);
  340. }
  341. else
  342. {
  343. m_log.Error("[AGENT INVENTORY]: Failed to find item " + itemID.ToString());
  344. return;
  345. }
  346. }
  347. else
  348. {
  349. m_log.Error("[AGENT INVENTORY]: Failed to find item " + itemID.ToString() + ", no root folder");
  350. return;
  351. }
  352. }
  353. /// <summary>
  354. /// Create a new inventory item.
  355. /// </summary>
  356. /// <param name="remoteClient"></param>
  357. /// <param name="folderID"></param>
  358. /// <param name="callbackID"></param>
  359. /// <param name="asset"></param>
  360. /// <param name="nextOwnerMask"></param>
  361. private void CreateNewInventoryItem(IClientAPI remoteClient, LLUUID folderID, uint callbackID,
  362. AssetBase asset, uint nextOwnerMask)
  363. {
  364. CachedUserInfo userInfo
  365. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  366. if (userInfo != null)
  367. {
  368. InventoryItemBase item = new InventoryItemBase();
  369. item.avatarID = remoteClient.AgentId;
  370. item.creatorsID = remoteClient.AgentId;
  371. item.inventoryID = LLUUID.Random();
  372. item.assetID = asset.FullID;
  373. item.inventoryDescription = asset.Description;
  374. item.inventoryName = asset.Name;
  375. item.assetType = asset.Type;
  376. item.invType = asset.InvType;
  377. item.parentFolderID = folderID;
  378. item.inventoryCurrentPermissions = 2147483647;
  379. item.inventoryNextPermissions = nextOwnerMask;
  380. userInfo.AddItem(remoteClient.AgentId, item);
  381. remoteClient.SendInventoryItemCreateUpdate(item);
  382. }
  383. else
  384. {
  385. m_log.WarnFormat(
  386. "No user details associated with client {0} uuid {1} in CreateNewInventoryItem!",
  387. remoteClient.Name, remoteClient.AgentId);
  388. }
  389. }
  390. /// <summary>
  391. /// Create a new inventory item.
  392. /// </summary>
  393. /// <param name="remoteClient"></param>
  394. /// <param name="transactionID"></param>
  395. /// <param name="folderID"></param>
  396. /// <param name="callbackID"></param>
  397. /// <param name="description"></param>
  398. /// <param name="name"></param>
  399. /// <param name="invType"></param>
  400. /// <param name="type"></param>
  401. /// <param name="wearableType"></param>
  402. /// <param name="nextOwnerMask"></param>
  403. public void CreateNewInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
  404. uint callbackID, string description, string name, sbyte invType,
  405. sbyte assetType,
  406. byte wearableType, uint nextOwnerMask)
  407. {
  408. if (transactionID == LLUUID.Zero)
  409. {
  410. CachedUserInfo userInfo
  411. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  412. if (userInfo != null)
  413. {
  414. AssetBase asset = CreateAsset(name, description, invType, assetType, null);
  415. AssetCache.AddAsset(asset);
  416. CreateNewInventoryItem(remoteClient, folderID, callbackID, asset, nextOwnerMask);
  417. }
  418. else
  419. {
  420. m_log.ErrorFormat(
  421. "userInfo for agent uuid {0} unexpectedly null in CreateNewInventoryItem",
  422. remoteClient.AgentId);
  423. }
  424. }
  425. else
  426. {
  427. IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
  428. if (agentTransactions != null)
  429. {
  430. agentTransactions.HandleItemCreationFromTransaction(
  431. remoteClient, transactionID, folderID, callbackID, description,
  432. name, invType, assetType, wearableType, nextOwnerMask);
  433. }
  434. }
  435. }
  436. private void RemoveInventoryItem(IClientAPI remoteClient, LLUUID itemID)
  437. {
  438. CachedUserInfo userInfo
  439. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  440. if (userInfo == null)
  441. {
  442. m_log.Error("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString());
  443. return;
  444. }
  445. // is going through the root folder really the best way?
  446. // this triggers a tree walk to find and remove the item. 8-(
  447. // since this only happens in Trash (in theory) shouldn't we grab
  448. // the trash folder directly instead of RootFolder?
  449. if (userInfo.RootFolder != null)
  450. {
  451. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  452. if (item != null)
  453. {
  454. userInfo.DeleteItem(remoteClient.AgentId, item);
  455. }
  456. }
  457. }
  458. private void RemoveInventoryFolder(IClientAPI remoteClient, LLUUID folderID)
  459. {
  460. CachedUserInfo userInfo
  461. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  462. if (userInfo == null)
  463. {
  464. m_log.Error("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString());
  465. return;
  466. }
  467. if (userInfo.RootFolder != null)
  468. {
  469. InventoryItemBase folder = userInfo.RootFolder.HasItem(folderID);
  470. if (folder != null)
  471. {
  472. // doesn't work just yet, commented out. will fix in next patch.
  473. // userInfo.DeleteItem(remoteClient.AgentId, folder);
  474. }
  475. }
  476. }
  477. private SceneObjectGroup GetGroupByPrim(uint localID)
  478. {
  479. List<EntityBase> EntitieList = GetEntities();
  480. foreach (EntityBase ent in EntitieList)
  481. {
  482. if (ent is SceneObjectGroup)
  483. {
  484. if (((SceneObjectGroup) ent).HasChildPrim(localID))
  485. return (SceneObjectGroup) ent;
  486. }
  487. }
  488. return null;
  489. }
  490. /// <summary>
  491. /// Request a prim (task) inventory
  492. /// </summary>
  493. /// <param name="remoteClient"></param>
  494. /// <param name="primLocalID"></param>
  495. public void RequestTaskInventory(IClientAPI remoteClient, uint primLocalID)
  496. {
  497. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  498. if (group != null)
  499. {
  500. bool fileChange = group.GetPartInventoryFileName(remoteClient, primLocalID);
  501. if (fileChange)
  502. {
  503. if (XferManager != null)
  504. {
  505. group.RequestInventoryFile(primLocalID, XferManager);
  506. }
  507. }
  508. }
  509. else
  510. {
  511. m_log.ErrorFormat(
  512. "[PRIM INVENTORY]: Inventory requested of prim {0} which doesn't exist", primLocalID);
  513. }
  514. }
  515. /// <summary>
  516. /// Remove an item from a prim (task) inventory
  517. /// </summary>
  518. /// <param name="remoteClient">Unused at the moment but retained since the avatar ID might
  519. /// be necessary for a permissions check at some stage.</param>
  520. /// <param name="itemID"></param>
  521. /// <param name="localID"></param>
  522. public void RemoveTaskInventory(IClientAPI remoteClient, LLUUID itemID, uint localID)
  523. {
  524. SceneObjectGroup group = GetGroupByPrim(localID);
  525. if (group != null)
  526. {
  527. int type = group.RemoveInventoryItem(localID, itemID);
  528. group.GetProperties(remoteClient);
  529. if (type == 10)
  530. {
  531. EventManager.TriggerRemoveScript(localID, itemID);
  532. }
  533. }
  534. else
  535. {
  536. m_log.ErrorFormat(
  537. "[PRIM INVENTORY]: " +
  538. "Removal of item {0} requested of prim {1} but this prim does not exist",
  539. itemID,
  540. localID);
  541. }
  542. }
  543. /// <summary>
  544. /// Update an item in a prim (task) inventory.
  545. /// This method does not handle scripts, <see>RezScript(IClientAPI, LLUUID, unit)</see>
  546. /// </summary>
  547. /// <param name="remoteClient"></param>
  548. /// <param name="itemID"></param>
  549. /// <param name="folderID"></param>
  550. /// <param name="primLocalID"></param>
  551. public void UpdateTaskInventory(IClientAPI remoteClient, LLUUID itemID, LLUUID folderID,
  552. uint primLocalID)
  553. {
  554. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  555. if (group != null)
  556. {
  557. LLUUID copyID = LLUUID.Random();
  558. if (itemID != LLUUID.Zero)
  559. {
  560. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  561. if (userInfo != null && userInfo.RootFolder != null)
  562. {
  563. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  564. // Try library
  565. // XXX clumsy, possibly should be one call
  566. if (null == item)
  567. {
  568. item = CommsManager.UserProfileCacheService.libraryRoot.HasItem(itemID);
  569. }
  570. if (item != null)
  571. {
  572. if (item.assetType == 0 || item.assetType == 1 || item.assetType == 10)
  573. {
  574. group.AddInventoryItem(remoteClient, primLocalID, item, copyID);
  575. m_log.InfoFormat(
  576. "[PRIM INVENTORY]: Update with item {0} requested of prim {1} for {2}",
  577. item.inventoryName, primLocalID, remoteClient.Name);
  578. group.GetProperties(remoteClient);
  579. }
  580. else
  581. {
  582. // XXX Nasty temporary way of stopping things other than sounds, textures and scripts
  583. // from going in a prim's inventory, since other things will not currently work
  584. // See http://opensimulator.org/mantis/view.php?id=711 for the error caused later on
  585. // - to implement requires changes to TaskInventoryItem (which really requires the current
  586. // nasty way it is done to be changed).
  587. m_log.WarnFormat(
  588. "[PRIM INVENTORY]: Sorry, prim inventory storage of asset type {0} is not yet supported",
  589. item.assetType);
  590. }
  591. }
  592. else
  593. {
  594. m_log.ErrorFormat(
  595. "[PRIM INVENTORY]: Could not find inventory item {0} to update for {1}!",
  596. itemID, remoteClient.Name);
  597. }
  598. }
  599. }
  600. }
  601. else
  602. {
  603. m_log.WarnFormat(
  604. "[PRIM INVENTORY]: " +
  605. "Update with item {0} requested of prim {1} for {2} but this prim does not exist",
  606. itemID, primLocalID, remoteClient.Name);
  607. }
  608. }
  609. /// <summary>
  610. /// Rez a script into a prim's inventory
  611. /// </summary>
  612. /// <param name="remoteClient"></param>
  613. /// <param name="itemID"> </param>
  614. /// <param name="localID"></param>
  615. public void RezScript(IClientAPI remoteClient, LLUUID itemID, uint localID)
  616. {
  617. LLUUID copyID = LLUUID.Random();
  618. if (itemID != LLUUID.Zero)
  619. {
  620. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  621. if (userInfo != null && userInfo.RootFolder != null)
  622. {
  623. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  624. // Try library
  625. // XXX clumsy, possibly should be one call
  626. if (null == item)
  627. {
  628. item = CommsManager.UserProfileCacheService.libraryRoot.HasItem(itemID);
  629. }
  630. if (item != null)
  631. {
  632. SceneObjectGroup group = GetGroupByPrim(localID);
  633. if (group != null)
  634. {
  635. group.AddInventoryItem(remoteClient, localID, item, copyID);
  636. group.StartScript(localID, copyID);
  637. group.GetProperties(remoteClient);
  638. // m_log.InfoFormat("[PRIMINVENTORY]: " +
  639. // "Rezzed script {0} into prim local ID {1} for user {2}",
  640. // item.inventoryName, localID, remoteClient.Name);
  641. }
  642. else
  643. {
  644. m_log.ErrorFormat(
  645. "[PRIM INVENTORY]: " +
  646. "Could not rez script {0} into prim local ID {1} for user {2}"
  647. + " because the prim could not be found in the region!",
  648. item.inventoryName, localID, remoteClient.Name);
  649. }
  650. }
  651. else
  652. {
  653. m_log.ErrorFormat(
  654. "[PRIM INVENTORY]: Could not find script inventory item {0} to rez for {1}!",
  655. itemID, remoteClient.Name);
  656. }
  657. }
  658. }
  659. else // If the itemID is zero then the script has been rezzed directly in an object's inventory
  660. {
  661. // not yet implemented
  662. // TODO Need to get more details from original RezScript packet
  663. // XXX jc tmp
  664. // AssetBase asset = CreateAsset("chimney sweep", "sailor.lsl", 10, 10, null);
  665. // AssetCache.AddAsset(asset);
  666. }
  667. }
  668. /// <summary>
  669. ///
  670. /// </summary>
  671. /// <param name="packet"></param>
  672. /// <param name="simClient"></param>
  673. public virtual void DeRezObject(Packet packet, IClientAPI remoteClient)
  674. {
  675. DeRezObjectPacket DeRezPacket = (DeRezObjectPacket) packet;
  676. if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero)
  677. {
  678. //currently following code not used (or don't know of any case of destination being zero
  679. }
  680. else
  681. {
  682. foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData)
  683. {
  684. EntityBase selectedEnt = null;
  685. //m_log.Info("[CLIENT]: LocalID:" + Data.ObjectLocalID.ToString());
  686. List<EntityBase> EntitieList = GetEntities();
  687. foreach (EntityBase ent in EntitieList)
  688. {
  689. if (ent.LocalId == Data.ObjectLocalID)
  690. {
  691. selectedEnt = ent;
  692. break;
  693. }
  694. }
  695. if (selectedEnt != null)
  696. {
  697. if (PermissionsMngr.CanDeRezObject(remoteClient.AgentId, ((SceneObjectGroup) selectedEnt).UUID))
  698. {
  699. string sceneObjectXml = ((SceneObjectGroup) selectedEnt).ToXmlString();
  700. CachedUserInfo userInfo =
  701. CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  702. if (userInfo != null)
  703. {
  704. AssetBase asset = CreateAsset(
  705. ((SceneObjectGroup) selectedEnt).GetPartName(selectedEnt.LocalId),
  706. ((SceneObjectGroup) selectedEnt).GetPartDescription(selectedEnt.LocalId),
  707. (sbyte) InventoryType.Object,
  708. (sbyte) AssetType.Primitive,
  709. Helpers.StringToField(sceneObjectXml));
  710. AssetCache.AddAsset(asset);
  711. InventoryItemBase item = new InventoryItemBase();
  712. item.avatarID = remoteClient.AgentId;
  713. item.creatorsID = remoteClient.AgentId;
  714. item.inventoryID = LLUUID.Random();
  715. item.assetID = asset.FullID;
  716. item.inventoryDescription = asset.Description;
  717. item.inventoryName = asset.Name;
  718. item.assetType = asset.Type;
  719. item.invType = asset.InvType;
  720. item.parentFolderID = DeRezPacket.AgentBlock.DestinationID;
  721. item.inventoryCurrentPermissions = 2147483647;
  722. item.inventoryNextPermissions = 2147483647;
  723. item.inventoryEveryOnePermissions =
  724. ((SceneObjectGroup) selectedEnt).RootPart.EveryoneMask;
  725. item.inventoryBasePermissions = ((SceneObjectGroup) selectedEnt).RootPart.BaseMask;
  726. item.inventoryCurrentPermissions = ((SceneObjectGroup) selectedEnt).RootPart.OwnerMask;
  727. userInfo.AddItem(remoteClient.AgentId, item);
  728. remoteClient.SendInventoryItemCreateUpdate(item);
  729. }
  730. DeleteSceneObjectGroup((SceneObjectGroup) selectedEnt);
  731. }
  732. }
  733. }
  734. }
  735. }
  736. public virtual void RezObject(IClientAPI remoteClient, LLUUID itemID, LLVector3 RayEnd, LLVector3 RayStart,
  737. LLUUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
  738. uint EveryoneMask, uint GroupMask, uint NextOwnerMask, uint ItemFlags,
  739. bool RezSelected, bool RemoveItem, LLUUID fromTaskID)
  740. {
  741. byte bRayEndIsIntersection = (byte)0;
  742. if (RayEndIsIntersection)
  743. {
  744. bRayEndIsIntersection = (byte)1;
  745. }
  746. else
  747. {
  748. bRayEndIsIntersection = (byte)0;
  749. }
  750. LLVector3 pos = GetNewRezLocation(RayStart, RayEnd, RayTargetID, new LLQuaternion(0, 0, 0, 1), BypassRayCast, bRayEndIsIntersection);
  751. RezObject(remoteClient, itemID, pos);
  752. }
  753. public virtual void RezObject(IClientAPI remoteClient, LLUUID itemID, LLVector3 pos)
  754. {
  755. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  756. if (userInfo != null)
  757. {
  758. if (userInfo.RootFolder != null)
  759. {
  760. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  761. if (item != null)
  762. {
  763. AssetBase rezAsset = AssetCache.GetAsset(item.assetID, false);
  764. if (rezAsset != null)
  765. {
  766. AddRezObject(Helpers.FieldToUTF8String(rezAsset.Data), pos);
  767. //userInfo.DeleteItem(remoteClient.AgentId, item);
  768. //remoteClient.SendRemoveInventoryItem(itemID);
  769. }
  770. }
  771. }
  772. }
  773. }
  774. public void RezSingleAttachment(IClientAPI remoteClient, LLUUID itemID, uint AttachmentPt,
  775. uint ItemFlags, uint NextOwnerMask)
  776. {
  777. System.Console.WriteLine("RezSingleAttachment: unimplemented yet");
  778. }
  779. private void AddRezObject(string xmlData, LLVector3 pos)
  780. {
  781. SceneObjectGroup group = new SceneObjectGroup(this, m_regionHandle, xmlData);
  782. group.ResetIDs();
  783. AddEntity(group);
  784. group.AbsolutePosition = pos;
  785. SceneObjectPart rootPart = group.GetChildPart(group.UUID);
  786. rootPart.TrimPermissions();
  787. group.ApplyPhysics(m_physicalPrim);
  788. group.StartScripts();
  789. //bool UsePhysics = (((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Physics) > 0)&& m_physicalPrim);
  790. //if ((rootPart.ObjectFlags & (uint) LLObject.ObjectFlags.Phantom) == 0)
  791. //{
  792. //PrimitiveBaseShape pbs = rootPart.Shape;
  793. //rootPart.PhysActor = PhysicsScene.AddPrimShape(
  794. //rootPart.Name,
  795. //pbs,
  796. //new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y,
  797. // rootPart.AbsolutePosition.Z),
  798. //new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z),
  799. //new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X,
  800. // rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics);
  801. // rootPart.DoPhysicsPropertyUpdate(UsePhysics, true);
  802. // }
  803. //
  804. rootPart.ScheduleFullUpdate();
  805. }
  806. }
  807. }