Scene.Inventory.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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. */
  28. using Axiom.Math;
  29. using libsecondlife;
  30. using libsecondlife.Packets;
  31. using OpenSim.Framework;
  32. using OpenSim.Framework.Communications.Cache;
  33. using OpenSim.Region.Physics.Manager;
  34. namespace OpenSim.Region.Environment.Scenes
  35. {
  36. public partial class Scene
  37. {
  38. //split these method into this partial as a lot of these (hopefully) are only temporary and won't be needed once Caps is more complete
  39. // or at least some of they can be moved somewhere else
  40. public void AddInventoryItem(LLUUID avatarId, InventoryItemBase item)
  41. {
  42. ScenePresence avatar;
  43. if (TryGetAvatar(avatarId, out avatar))
  44. {
  45. AddInventoryItem(avatar.ControllingClient, item);
  46. }
  47. }
  48. public void AddInventoryItem(IClientAPI remoteClient, InventoryItemBase item)
  49. {
  50. CachedUserInfo userInfo = CommsManager.UserProfileCache.GetUserDetails(remoteClient.AgentId);
  51. if (userInfo != null)
  52. {
  53. userInfo.AddItem(remoteClient.AgentId, item);
  54. remoteClient.SendInventoryItemUpdate(item);
  55. }
  56. }
  57. public LLUUID CapsUpdateInventoryItemAsset(LLUUID avatarId, LLUUID itemID, byte[] data)
  58. {
  59. ScenePresence avatar;
  60. if (TryGetAvatar(avatarId, out avatar))
  61. {
  62. return CapsUpdateInventoryItemAsset(avatar.ControllingClient, itemID, data);
  63. }
  64. return LLUUID.Zero;
  65. }
  66. public LLUUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, LLUUID itemID, byte[] data)
  67. {
  68. CachedUserInfo userInfo = CommsManager.UserProfileCache.GetUserDetails(remoteClient.AgentId);
  69. if (userInfo != null)
  70. {
  71. if (userInfo.RootFolder != null)
  72. {
  73. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  74. if (item != null)
  75. {
  76. AssetBase asset;
  77. asset = new AssetBase();
  78. asset.FullID = LLUUID.Random();
  79. asset.Type = (sbyte) item.assetType;
  80. asset.InvType = (sbyte) item.invType;
  81. asset.Name = item.inventoryName;
  82. asset.Data = data;
  83. AssetCache.AddAsset(asset);
  84. item.assetID = asset.FullID;
  85. userInfo.UpdateItem(remoteClient.AgentId, item);
  86. // remoteClient.SendInventoryItemUpdate(item);
  87. if (item.invType == 7)
  88. {
  89. //do we want to know about updated note cards?
  90. }
  91. else if (item.invType == 10)
  92. {
  93. // do we want to know about updated scripts
  94. }
  95. return (asset.FullID);
  96. }
  97. }
  98. }
  99. return LLUUID.Zero;
  100. }
  101. public void UDPUpdateInventoryItemAsset(IClientAPI remoteClient, LLUUID transactionID, LLUUID assetID,
  102. LLUUID itemID)
  103. {
  104. CachedUserInfo userInfo = CommsManager.UserProfileCache.GetUserDetails(remoteClient.AgentId);
  105. if (userInfo != null)
  106. {
  107. if (userInfo.RootFolder != null)
  108. {
  109. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  110. if (item != null)
  111. {
  112. AgentAssetTransactions transactions =
  113. CommsManager.TransactionsManager.GetUserTransActions(remoteClient.AgentId);
  114. if (transactions != null)
  115. {
  116. AssetBase asset = null;
  117. bool addToCache = false;
  118. asset = AssetCache.GetAsset(assetID);
  119. if (asset == null)
  120. {
  121. asset = transactions.GetTransactionAsset(transactionID);
  122. addToCache = true;
  123. }
  124. if (asset != null)
  125. {
  126. if (asset.FullID == assetID)
  127. {
  128. asset.Name = item.inventoryName;
  129. asset.Description = item.inventoryDescription;
  130. asset.InvType = (sbyte) item.invType;
  131. asset.Type = (sbyte) item.assetType;
  132. item.assetID = asset.FullID;
  133. if (addToCache)
  134. {
  135. AssetCache.AddAsset(asset);
  136. }
  137. userInfo.UpdateItem(remoteClient.AgentId, item);
  138. }
  139. }
  140. }
  141. }
  142. }
  143. }
  144. }
  145. /// <summary>
  146. /// temporary method to test out creating new inventory items
  147. /// </summary>
  148. /// <param name="remoteClient"></param>
  149. /// <param name="transActionID"></param>
  150. /// <param name="folderID"></param>
  151. /// <param name="callbackID"></param>
  152. /// <param name="description"></param>
  153. /// <param name="name"></param>
  154. /// <param name="invType"></param>
  155. /// <param name="type"></param>
  156. /// <param name="wearableType"></param>
  157. /// <param name="nextOwnerMask"></param>
  158. public void CreateNewInventoryItem(IClientAPI remoteClient, LLUUID transActionID, LLUUID folderID,
  159. uint callbackID, string description, string name, sbyte invType, sbyte type,
  160. byte wearableType, uint nextOwnerMask)
  161. {
  162. if (transActionID == LLUUID.Zero)
  163. {
  164. CachedUserInfo userInfo = CommsManager.UserProfileCache.GetUserDetails(remoteClient.AgentId);
  165. if (userInfo != null)
  166. {
  167. AssetBase asset = new AssetBase();
  168. asset.Name = name;
  169. asset.Description = description;
  170. asset.InvType = invType;
  171. asset.Type = type;
  172. asset.FullID = LLUUID.Random();
  173. asset.Data = new byte[1];
  174. AssetCache.AddAsset(asset);
  175. InventoryItemBase item = new InventoryItemBase();
  176. item.avatarID = remoteClient.AgentId;
  177. item.creatorsID = remoteClient.AgentId;
  178. item.inventoryID = LLUUID.Random();
  179. item.assetID = asset.FullID;
  180. item.inventoryDescription = description;
  181. item.inventoryName = name;
  182. item.assetType = invType;
  183. item.invType = invType;
  184. item.parentFolderID = folderID;
  185. item.inventoryCurrentPermissions = 2147483647;
  186. item.inventoryNextPermissions = nextOwnerMask;
  187. userInfo.AddItem(remoteClient.AgentId, item);
  188. remoteClient.SendInventoryItemUpdate(item);
  189. }
  190. }
  191. else
  192. {
  193. CommsManager.TransactionsManager.HandleInventoryFromTransaction(remoteClient, transActionID, folderID,
  194. callbackID, description, name, invType,
  195. type, wearableType, nextOwnerMask);
  196. //System.Console.WriteLine("request to create inventory item from transaction " + transActionID);
  197. }
  198. }
  199. /// <summary>
  200. ///
  201. /// </summary>
  202. /// <param name="remoteClient"></param>
  203. /// <param name="primLocalID"></param>
  204. public void RequestTaskInventory(IClientAPI remoteClient, uint primLocalID)
  205. {
  206. bool hasPrim = false;
  207. foreach (EntityBase ent in Entities.Values)
  208. {
  209. if (ent is SceneObjectGroup)
  210. {
  211. hasPrim = ((SceneObjectGroup) ent).HasChildPrim(primLocalID);
  212. if (hasPrim != false)
  213. {
  214. bool fileChange = ((SceneObjectGroup) ent).GetPartInventoryFileName(remoteClient, primLocalID);
  215. if (fileChange)
  216. {
  217. if (XferManager != null)
  218. {
  219. ((SceneObjectGroup) ent).RequestInventoryFile(primLocalID, XferManager);
  220. }
  221. }
  222. break;
  223. }
  224. }
  225. }
  226. }
  227. public void RemoveTaskInventory(IClientAPI remoteClient, LLUUID itemID, uint localID)
  228. {
  229. bool hasPrim = false;
  230. foreach (EntityBase ent in Entities.Values)
  231. {
  232. if (ent is SceneObjectGroup)
  233. {
  234. hasPrim = ((SceneObjectGroup) ent).HasChildPrim(localID);
  235. if (hasPrim != false)
  236. {
  237. int type = ((SceneObjectGroup) ent).RemoveInventoryItem(remoteClient, localID, itemID);
  238. ((SceneObjectGroup) ent).GetProperites(remoteClient);
  239. if (type == 10)
  240. {
  241. EventManager.TriggerRemoveScript(localID, itemID);
  242. }
  243. }
  244. }
  245. }
  246. }
  247. public void RezScript(IClientAPI remoteClient, LLUUID itemID, uint localID)
  248. {
  249. CachedUserInfo userInfo = CommsManager.UserProfileCache.GetUserDetails(remoteClient.AgentId);
  250. LLUUID copyID = LLUUID.Random();
  251. if (userInfo != null)
  252. {
  253. if (userInfo.RootFolder != null)
  254. {
  255. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  256. if (item != null)
  257. {
  258. bool isTexture = false;
  259. bool rezzed = false;
  260. if (item.invType == 0)
  261. {
  262. isTexture = true;
  263. }
  264. AssetBase rezAsset = AssetCache.GetAsset(item.assetID, isTexture);
  265. if (rezAsset != null)
  266. {
  267. string script = Util.FieldToString(rezAsset.Data);
  268. //Console.WriteLine("rez script "+script);
  269. EventManager.TriggerRezScript(localID, copyID, script);
  270. rezzed = true;
  271. }
  272. else
  273. {
  274. //lets try once more incase the asset cache is being slow getting the asset from server
  275. rezAsset = AssetCache.GetAsset(item.assetID, isTexture);
  276. if (rezAsset != null)
  277. {
  278. string script = Util.FieldToString(rezAsset.Data);
  279. // Console.WriteLine("rez script " + script);
  280. EventManager.TriggerRezScript(localID, copyID, script);
  281. rezzed = true;
  282. }
  283. }
  284. if (rezzed)
  285. {
  286. bool hasPrim = false;
  287. foreach (EntityBase ent in Entities.Values)
  288. {
  289. if (ent is SceneObjectGroup)
  290. {
  291. hasPrim = ((SceneObjectGroup) ent).HasChildPrim(localID);
  292. if (hasPrim != false)
  293. {
  294. bool added =
  295. ((SceneObjectGroup) ent).AddInventoryItem(remoteClient, localID, item,
  296. copyID);
  297. ((SceneObjectGroup) ent).GetProperites(remoteClient);
  298. }
  299. }
  300. }
  301. }
  302. }
  303. }
  304. }
  305. }
  306. /// <summary>
  307. ///
  308. /// </summary>
  309. /// <param name="packet"></param>
  310. /// <param name="simClient"></param>
  311. public void DeRezObject(Packet packet, IClientAPI remoteClient)
  312. {
  313. DeRezObjectPacket DeRezPacket = (DeRezObjectPacket) packet;
  314. if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero)
  315. {
  316. //currently following code not used (or don't know of any case of destination being zero
  317. }
  318. else
  319. {
  320. foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData)
  321. {
  322. EntityBase selectedEnt = null;
  323. //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LocalID:" + Data.ObjectLocalID.ToString());
  324. foreach (EntityBase ent in Entities.Values)
  325. {
  326. if (ent.LocalId == Data.ObjectLocalID)
  327. {
  328. selectedEnt = ent;
  329. break;
  330. }
  331. }
  332. if (selectedEnt != null)
  333. {
  334. if (PermissionsMngr.CanDeRezObject(remoteClient.AgentId, ((SceneObjectGroup) selectedEnt).UUID))
  335. {
  336. string sceneObjectXml = ((SceneObjectGroup) selectedEnt).ToXmlString();
  337. CachedUserInfo userInfo = CommsManager.UserProfileCache.GetUserDetails(remoteClient.AgentId);
  338. if (userInfo != null)
  339. {
  340. AssetBase asset = new AssetBase();
  341. asset.Name = ((SceneObjectGroup) selectedEnt).GetPartName(selectedEnt.LocalId);
  342. asset.Description =
  343. ((SceneObjectGroup) selectedEnt).GetPartDescription(selectedEnt.LocalId);
  344. asset.InvType = 6;
  345. asset.Type = 6;
  346. asset.FullID = LLUUID.Random();
  347. asset.Data = Helpers.StringToField(sceneObjectXml);
  348. AssetCache.AddAsset(asset);
  349. InventoryItemBase item = new InventoryItemBase();
  350. item.avatarID = remoteClient.AgentId;
  351. item.creatorsID = remoteClient.AgentId;
  352. item.inventoryID = LLUUID.Random();
  353. item.assetID = asset.FullID;
  354. item.inventoryDescription = asset.Description;
  355. item.inventoryName = asset.Name;
  356. item.assetType = asset.Type;
  357. item.invType = asset.InvType;
  358. item.parentFolderID = DeRezPacket.AgentBlock.DestinationID;
  359. item.inventoryCurrentPermissions = 2147483647;
  360. item.inventoryNextPermissions = 2147483647;
  361. userInfo.AddItem(remoteClient.AgentId, item);
  362. remoteClient.SendInventoryItemUpdate(item);
  363. }
  364. DeleteSceneObjectGroup((SceneObjectGroup) selectedEnt);
  365. }
  366. }
  367. }
  368. }
  369. }
  370. public void DeleteSceneObjectGroup(SceneObjectGroup group)
  371. {
  372. SceneObjectPart rootPart = (group).GetChildPart(group.UUID);
  373. if (rootPart.PhysActor != null)
  374. {
  375. phyScene.RemovePrim(rootPart.PhysActor);
  376. rootPart.PhysActor = null;
  377. }
  378. m_storageManager.DataStore.RemoveObject(group.UUID, m_regInfo.RegionID);
  379. group.DeleteGroup();
  380. lock (Entities)
  381. {
  382. Entities.Remove(group.UUID);
  383. }
  384. group.DeleteParts();
  385. }
  386. public void RezObject(IClientAPI remoteClient, LLUUID itemID, LLVector3 pos)
  387. {
  388. CachedUserInfo userInfo = CommsManager.UserProfileCache.GetUserDetails(remoteClient.AgentId);
  389. if (userInfo != null)
  390. {
  391. if (userInfo.RootFolder != null)
  392. {
  393. InventoryItemBase item = userInfo.RootFolder.HasItem(itemID);
  394. if (item != null)
  395. {
  396. AssetBase rezAsset = AssetCache.GetAsset(item.assetID, false);
  397. if (rezAsset != null)
  398. {
  399. AddRezObject(Util.FieldToString(rezAsset.Data), pos);
  400. userInfo.DeleteItem(remoteClient.AgentId, item);
  401. remoteClient.SendRemoveInventoryItem(itemID);
  402. }
  403. else
  404. {
  405. //lets try once more incase the asset cache is being slow getting the asset from server
  406. rezAsset = AssetCache.GetAsset(item.assetID, false);
  407. if (rezAsset != null)
  408. {
  409. AddRezObject(Util.FieldToString(rezAsset.Data), pos);
  410. userInfo.DeleteItem(remoteClient.AgentId, item);
  411. remoteClient.SendRemoveInventoryItem(itemID);
  412. }
  413. }
  414. }
  415. }
  416. }
  417. }
  418. private void AddRezObject(string xmlData, LLVector3 pos)
  419. {
  420. SceneObjectGroup group = new SceneObjectGroup(this, m_regionHandle, xmlData);
  421. AddEntity(group);
  422. group.AbsolutePosition = pos;
  423. SceneObjectPart rootPart = group.GetChildPart(group.UUID);
  424. bool UsePhysics = ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Physics) > 0);
  425. if ((rootPart.ObjectFlags & (uint) LLObject.ObjectFlags.Phantom) == 0)
  426. {
  427. PrimitiveBaseShape pbs = rootPart.Shape;
  428. rootPart.PhysActor = phyScene.AddPrimShape(
  429. rootPart.Name,
  430. pbs,
  431. new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y,
  432. rootPart.AbsolutePosition.Z),
  433. new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z),
  434. new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X,
  435. rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics);
  436. }
  437. }
  438. }
  439. }