Scene.Inventory.cs 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Collections;
  30. using System.Reflection;
  31. using System.Text;
  32. using System.Timers;
  33. using OpenMetaverse;
  34. using OpenMetaverse.Packets;
  35. using log4net;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Communications.Cache;
  38. using OpenSim.Region.Framework;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes.Serialization;
  41. namespace OpenSim.Region.Framework.Scenes
  42. {
  43. public partial class Scene
  44. {
  45. private static readonly ILog m_log
  46. = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  47. /// <summary>
  48. /// Allows asynchronous derezzing of objects from the scene into a client's inventory.
  49. /// </summary>
  50. protected AsyncSceneObjectGroupDeleter m_asyncSceneObjectDeleter;
  51. /// <summary>
  52. /// Start all the scripts in the scene which should be started.
  53. /// </summary>
  54. public void CreateScriptInstances()
  55. {
  56. m_log.Info("[PRIM INVENTORY]: Starting scripts in scene");
  57. foreach (EntityBase group in Entities)
  58. {
  59. if (group is SceneObjectGroup)
  60. {
  61. ((SceneObjectGroup) group).CreateScriptInstances(0, false, DefaultScriptEngine, 0);
  62. }
  63. }
  64. }
  65. public void AddUploadedInventoryItem(UUID agentID, InventoryItemBase item)
  66. {
  67. IMoneyModule money=RequestModuleInterface<IMoneyModule>();
  68. if (money != null)
  69. {
  70. money.ApplyUploadCharge(agentID);
  71. }
  72. AddInventoryItem(agentID, item);
  73. }
  74. public bool AddInventoryItemReturned(UUID AgentId, InventoryItemBase item)
  75. {
  76. if (InventoryService.AddItem(item))
  77. return true;
  78. else
  79. {
  80. m_log.WarnFormat(
  81. "[AGENT INVENTORY]: Unable to add item {1} to agent {2} inventory", item.Name, AgentId);
  82. return false;
  83. }
  84. }
  85. public void AddInventoryItem(UUID AgentID, InventoryItemBase item)
  86. {
  87. if (InventoryService.AddItem(item))
  88. {
  89. int userlevel = 0;
  90. if (Permissions.IsGod(AgentID))
  91. {
  92. userlevel = 1;
  93. }
  94. // TODO: remove this cruft once MasterAvatar is fully deprecated
  95. //
  96. if (m_regInfo.MasterAvatarAssignedUUID == AgentID)
  97. {
  98. userlevel = 2;
  99. }
  100. EventManager.TriggerOnNewInventoryItemUploadComplete(AgentID, item.AssetID, item.Name, userlevel);
  101. }
  102. else
  103. {
  104. m_log.WarnFormat(
  105. "[AGENT INVENTORY]: Agent {1} could not add item {2} {3}",
  106. AgentID, item.Name, item.ID);
  107. return;
  108. }
  109. }
  110. /// <summary>
  111. /// Add an inventory item to an avatar's inventory.
  112. /// </summary>
  113. /// <param name="remoteClient">The remote client controlling the avatar</param>
  114. /// <param name="item">The item. This structure contains all the item metadata, including the folder
  115. /// in which the item is to be placed.</param>
  116. public void AddInventoryItem(IClientAPI remoteClient, InventoryItemBase item)
  117. {
  118. AddInventoryItem(remoteClient.AgentId, item);
  119. remoteClient.SendInventoryItemCreateUpdate(item, 0);
  120. }
  121. /// <summary>
  122. /// Capability originating call to update the asset of an item in an agent's inventory
  123. /// </summary>
  124. /// <param name="remoteClient"></param>
  125. /// <param name="itemID"></param>
  126. /// <param name="data"></param>
  127. /// <returns></returns>
  128. public virtual UUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, UUID itemID, byte[] data)
  129. {
  130. InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
  131. item = InventoryService.GetItem(item);
  132. if (item != null)
  133. {
  134. if ((InventoryType)item.InvType == InventoryType.Notecard)
  135. {
  136. if (!Permissions.CanEditNotecard(itemID, UUID.Zero, remoteClient.AgentId))
  137. {
  138. remoteClient.SendAgentAlertMessage("Insufficient permissions to edit notecard", false);
  139. return UUID.Zero;
  140. }
  141. remoteClient.SendAgentAlertMessage("Notecard saved", false);
  142. }
  143. else if ((InventoryType)item.InvType == InventoryType.LSL)
  144. {
  145. if (!Permissions.CanEditScript(itemID, UUID.Zero, remoteClient.AgentId))
  146. {
  147. remoteClient.SendAgentAlertMessage("Insufficient permissions to edit script", false);
  148. return UUID.Zero;
  149. }
  150. remoteClient.SendAgentAlertMessage("Script saved", false);
  151. }
  152. AssetBase asset =
  153. CreateAsset(item.Name, item.Description, (sbyte)item.AssetType, data);
  154. item.AssetID = asset.FullID;
  155. AssetService.Store(asset);
  156. InventoryService.UpdateItem(item);
  157. // remoteClient.SendInventoryItemCreateUpdate(item);
  158. return (asset.FullID);
  159. }
  160. else
  161. {
  162. m_log.ErrorFormat(
  163. "[AGENT INVENTORY]: Could not find item {0} for caps inventory update",
  164. itemID);
  165. }
  166. return UUID.Zero;
  167. }
  168. /// <summary>
  169. /// <see>CapsUpdatedInventoryItemAsset(IClientAPI, UUID, byte[])</see>
  170. /// </summary>
  171. public UUID CapsUpdateInventoryItemAsset(UUID avatarId, UUID itemID, byte[] data)
  172. {
  173. ScenePresence avatar;
  174. if (TryGetAvatar(avatarId, out avatar))
  175. {
  176. return CapsUpdateInventoryItemAsset(avatar.ControllingClient, itemID, data);
  177. }
  178. else
  179. {
  180. m_log.ErrorFormat(
  181. "[AGENT INVENTORY]: " +
  182. "Avatar {0} cannot be found to update its inventory item asset",
  183. avatarId);
  184. }
  185. return UUID.Zero;
  186. }
  187. /// <summary>
  188. /// Capability originating call to update the asset of a script in a prim's (task's) inventory
  189. /// </summary>
  190. /// <param name="remoteClient"></param>
  191. /// <param name="itemID"></param>
  192. /// <param name="primID">The prim which contains the item to update</param>
  193. /// <param name="isScriptRunning">Indicates whether the script to update is currently running</param>
  194. /// <param name="data"></param>
  195. public ArrayList CapsUpdateTaskInventoryScriptAsset(IClientAPI remoteClient, UUID itemId,
  196. UUID primId, bool isScriptRunning, byte[] data)
  197. {
  198. if (!Permissions.CanEditScript(itemId, primId, remoteClient.AgentId))
  199. {
  200. remoteClient.SendAgentAlertMessage("Insufficient permissions to edit script", false);
  201. return new ArrayList();
  202. }
  203. // Retrieve group
  204. SceneObjectPart part = GetSceneObjectPart(primId);
  205. SceneObjectGroup group = part.ParentGroup;
  206. if (null == group)
  207. {
  208. m_log.ErrorFormat(
  209. "[PRIM INVENTORY]: " +
  210. "Prim inventory update requested for item ID {0} in prim ID {1} but this prim does not exist",
  211. itemId, primId);
  212. return new ArrayList();
  213. }
  214. // Retrieve item
  215. TaskInventoryItem item = group.GetInventoryItem(part.LocalId, itemId);
  216. if (null == item)
  217. {
  218. m_log.ErrorFormat(
  219. "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for caps script update "
  220. + " but the item does not exist in this inventory",
  221. itemId, part.Name, part.UUID);
  222. return new ArrayList();
  223. }
  224. AssetBase asset = CreateAsset(item.Name, item.Description, (sbyte)AssetType.LSLText, data);
  225. AssetService.Store(asset);
  226. if (isScriptRunning)
  227. {
  228. part.Inventory.RemoveScriptInstance(item.ItemID);
  229. }
  230. // Update item with new asset
  231. item.AssetID = asset.FullID;
  232. group.UpdateInventoryItem(item);
  233. part.GetProperties(remoteClient);
  234. // Trigger rerunning of script (use TriggerRezScript event, see RezScript)
  235. ArrayList errors = new ArrayList();
  236. if (isScriptRunning)
  237. {
  238. // Needs to determine which engine was running it and use that
  239. //
  240. part.Inventory.CreateScriptInstance(item.ItemID, 0, false, DefaultScriptEngine, 0);
  241. errors = part.Inventory.GetScriptErrors(item.ItemID);
  242. }
  243. else
  244. {
  245. remoteClient.SendAgentAlertMessage("Script saved", false);
  246. }
  247. return errors;
  248. }
  249. /// <summary>
  250. /// <see>CapsUpdateTaskInventoryScriptAsset(IClientAPI, UUID, UUID, bool, byte[])</see>
  251. /// </summary>
  252. public ArrayList CapsUpdateTaskInventoryScriptAsset(UUID avatarId, UUID itemId,
  253. UUID primId, bool isScriptRunning, byte[] data)
  254. {
  255. ScenePresence avatar;
  256. if (TryGetAvatar(avatarId, out avatar))
  257. {
  258. return CapsUpdateTaskInventoryScriptAsset(
  259. avatar.ControllingClient, itemId, primId, isScriptRunning, data);
  260. }
  261. else
  262. {
  263. m_log.ErrorFormat(
  264. "[PRIM INVENTORY]: " +
  265. "Avatar {0} cannot be found to update its prim item asset",
  266. avatarId);
  267. return new ArrayList();
  268. }
  269. }
  270. /// <summary>
  271. /// Update an item which is either already in the client's inventory or is within
  272. /// a transaction
  273. /// </summary>
  274. /// <param name="remoteClient"></param>
  275. /// <param name="transactionID">The transaction ID. If this is UUID.Zero we will
  276. /// assume that we are not in a transaction</param>
  277. /// <param name="itemID">The ID of the updated item</param>
  278. /// <param name="name">The name of the updated item</param>
  279. /// <param name="description">The description of the updated item</param>
  280. /// <param name="nextOwnerMask">The permissions of the updated item</param>
  281. /* public void UpdateInventoryItemAsset(IClientAPI remoteClient, UUID transactionID,
  282. UUID itemID, string name, string description,
  283. uint nextOwnerMask)*/
  284. public void UpdateInventoryItemAsset(IClientAPI remoteClient, UUID transactionID,
  285. UUID itemID, InventoryItemBase itemUpd)
  286. {
  287. InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
  288. item = InventoryService.GetItem(item);
  289. if (item != null)
  290. {
  291. if (UUID.Zero == transactionID)
  292. {
  293. item.Name = itemUpd.Name;
  294. item.Description = itemUpd.Description;
  295. item.NextPermissions = itemUpd.NextPermissions;
  296. item.CurrentPermissions |= 8; // Slam!
  297. item.EveryOnePermissions = itemUpd.EveryOnePermissions;
  298. item.GroupPermissions = itemUpd.GroupPermissions;
  299. item.GroupID = itemUpd.GroupID;
  300. item.GroupOwned = itemUpd.GroupOwned;
  301. item.CreationDate = itemUpd.CreationDate;
  302. // The client sends zero if its newly created?
  303. if (itemUpd.CreationDate == 0)
  304. item.CreationDate = Util.UnixTimeSinceEpoch();
  305. else
  306. item.CreationDate = itemUpd.CreationDate;
  307. // TODO: Check if folder changed and move item
  308. //item.NextPermissions = itemUpd.Folder;
  309. item.InvType = itemUpd.InvType;
  310. item.SalePrice = itemUpd.SalePrice;
  311. item.SaleType = itemUpd.SaleType;
  312. item.Flags = itemUpd.Flags;
  313. InventoryService.UpdateItem(item);
  314. }
  315. else
  316. {
  317. IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
  318. if (agentTransactions != null)
  319. {
  320. agentTransactions.HandleItemUpdateFromTransaction(
  321. remoteClient, transactionID, item);
  322. }
  323. }
  324. }
  325. else
  326. {
  327. m_log.Error(
  328. "[AGENTINVENTORY]: Item ID " + itemID + " not found for an inventory item update.");
  329. }
  330. }
  331. /// <summary>
  332. /// Give an inventory item from one user to another
  333. /// </summary>
  334. /// <param name="recipientClient"></param>
  335. /// <param name="senderId">ID of the sender of the item</param>
  336. /// <param name="itemId"></param>
  337. public virtual void GiveInventoryItem(IClientAPI recipientClient, UUID senderId, UUID itemId)
  338. {
  339. InventoryItemBase itemCopy = GiveInventoryItem(recipientClient.AgentId, senderId, itemId);
  340. if (itemCopy != null)
  341. recipientClient.SendBulkUpdateInventory(itemCopy);
  342. }
  343. /// <summary>
  344. /// Give an inventory item from one user to another
  345. /// </summary>
  346. /// <param name="recipient"></param>
  347. /// <param name="senderId">ID of the sender of the item</param>
  348. /// <param name="itemId"></param>
  349. /// <returns>The inventory item copy given, null if the give was unsuccessful</returns>
  350. public virtual InventoryItemBase GiveInventoryItem(UUID recipient, UUID senderId, UUID itemId)
  351. {
  352. return GiveInventoryItem(recipient, senderId, itemId, UUID.Zero);
  353. }
  354. /// <summary>
  355. /// Give an inventory item from one user to another
  356. /// </summary>
  357. /// <param name="recipient"></param>
  358. /// <param name="senderId">ID of the sender of the item</param>
  359. /// <param name="itemId"></param>
  360. /// <param name="recipientFolderId">
  361. /// The id of the folder in which the copy item should go. If UUID.Zero then the item is placed in the most
  362. /// appropriate default folder.
  363. /// </param>
  364. /// <returns>
  365. /// The inventory item copy given, null if the give was unsuccessful
  366. /// </returns>
  367. public virtual InventoryItemBase GiveInventoryItem(
  368. UUID recipient, UUID senderId, UUID itemId, UUID recipientFolderId)
  369. {
  370. //Console.WriteLine("Scene.Inventory.cs: GiveInventoryItem");
  371. InventoryItemBase item = new InventoryItemBase(itemId, senderId);
  372. item = InventoryService.GetItem(item);
  373. if ((item != null) && (item.Owner == senderId))
  374. {
  375. if (!Permissions.BypassPermissions())
  376. {
  377. if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
  378. return null;
  379. }
  380. // Insert a copy of the item into the recipient
  381. InventoryItemBase itemCopy = new InventoryItemBase();
  382. itemCopy.Owner = recipient;
  383. itemCopy.CreatorId = item.CreatorId;
  384. itemCopy.ID = UUID.Random();
  385. itemCopy.AssetID = item.AssetID;
  386. itemCopy.Description = item.Description;
  387. itemCopy.Name = item.Name;
  388. itemCopy.AssetType = item.AssetType;
  389. itemCopy.InvType = item.InvType;
  390. itemCopy.Folder = recipientFolderId;
  391. if (Permissions.PropagatePermissions())
  392. {
  393. if (item.InvType == (int)InventoryType.Object)
  394. {
  395. itemCopy.BasePermissions &= ~(uint)(PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer);
  396. itemCopy.BasePermissions |= (item.CurrentPermissions & 7) << 13;
  397. }
  398. else
  399. {
  400. itemCopy.BasePermissions = item.BasePermissions & item.NextPermissions;
  401. }
  402. itemCopy.CurrentPermissions = itemCopy.BasePermissions;
  403. if ((item.CurrentPermissions & 8) != 0) // Propagate slam bit
  404. {
  405. itemCopy.BasePermissions &= item.NextPermissions;
  406. itemCopy.CurrentPermissions = itemCopy.BasePermissions;
  407. itemCopy.CurrentPermissions |= 8;
  408. }
  409. itemCopy.NextPermissions = item.NextPermissions;
  410. itemCopy.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions;
  411. itemCopy.GroupPermissions = item.GroupPermissions & item.NextPermissions;
  412. }
  413. else
  414. {
  415. itemCopy.CurrentPermissions = item.CurrentPermissions;
  416. itemCopy.NextPermissions = item.NextPermissions;
  417. itemCopy.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions;
  418. itemCopy.GroupPermissions = item.GroupPermissions & item.NextPermissions;
  419. itemCopy.BasePermissions = item.BasePermissions;
  420. }
  421. itemCopy.GroupID = UUID.Zero;
  422. itemCopy.GroupOwned = false;
  423. itemCopy.Flags = item.Flags;
  424. itemCopy.SalePrice = item.SalePrice;
  425. itemCopy.SaleType = item.SaleType;
  426. if (InventoryService.AddItem(itemCopy))
  427. TransferInventoryAssets(itemCopy, senderId, recipient);
  428. if (!Permissions.BypassPermissions())
  429. {
  430. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  431. {
  432. List<UUID> items = new List<UUID>();
  433. items.Add(itemId);
  434. InventoryService.DeleteItems(senderId, items);
  435. }
  436. }
  437. return itemCopy;
  438. }
  439. else
  440. {
  441. m_log.WarnFormat("[AGENT INVENTORY]: Failed to find item {0} or item does not belong to giver ", itemId);
  442. return null;
  443. }
  444. }
  445. protected virtual void TransferInventoryAssets(InventoryItemBase item, UUID sender, UUID receiver)
  446. {
  447. }
  448. /// <summary>
  449. /// Give an entire inventory folder from one user to another. The entire contents (including all descendent
  450. /// folders) is given.
  451. /// </summary>
  452. /// <param name="recipientId"></param>
  453. /// <param name="senderId">ID of the sender of the item</param>
  454. /// <param name="folderId"></param>
  455. /// <param name="recipientParentFolderId">
  456. /// The id of the receipient folder in which the send folder should be placed. If UUID.Zero then the
  457. /// recipient folder is the root folder
  458. /// </param>
  459. /// <returns>
  460. /// The inventory folder copy given, null if the copy was unsuccessful
  461. /// </returns>
  462. public virtual InventoryFolderBase GiveInventoryFolder(
  463. UUID recipientId, UUID senderId, UUID folderId, UUID recipientParentFolderId)
  464. {
  465. //// Retrieve the folder from the sender
  466. InventoryFolderBase folder = InventoryService.GetFolder(new InventoryFolderBase(folderId));
  467. if (null == folder)
  468. {
  469. m_log.ErrorFormat(
  470. "[AGENT INVENTORY]: Could not find inventory folder {0} to give", folderId);
  471. return null;
  472. }
  473. if (recipientParentFolderId == UUID.Zero)
  474. {
  475. InventoryFolderBase recipientRootFolder = InventoryService.GetRootFolder(recipientId);
  476. if (recipientRootFolder != null)
  477. recipientParentFolderId = recipientRootFolder.ID;
  478. else
  479. {
  480. m_log.WarnFormat("[AGENT INVENTORY]: Unable to find root folder for receiving agent");
  481. return null;
  482. }
  483. }
  484. UUID newFolderId = UUID.Random();
  485. InventoryFolderBase newFolder
  486. = new InventoryFolderBase(
  487. newFolderId, folder.Name, recipientId, folder.Type, recipientParentFolderId, folder.Version);
  488. InventoryService.AddFolder(newFolder);
  489. // Give all the subfolders
  490. InventoryCollection contents = InventoryService.GetFolderContent(senderId, folderId);
  491. foreach (InventoryFolderBase childFolder in contents.Folders)
  492. {
  493. GiveInventoryFolder(recipientId, senderId, childFolder.ID, newFolder.ID);
  494. }
  495. // Give all the items
  496. foreach (InventoryItemBase item in contents.Items)
  497. {
  498. GiveInventoryItem(recipientId, senderId, item.ID, newFolder.ID);
  499. }
  500. return newFolder;
  501. }
  502. public void CopyInventoryItem(IClientAPI remoteClient, uint callbackID, UUID oldAgentID, UUID oldItemID,
  503. UUID newFolderID, string newName)
  504. {
  505. m_log.DebugFormat(
  506. "[AGENT INVENTORY]: CopyInventoryItem received by {0} with oldAgentID {1}, oldItemID {2}, new FolderID {3}, newName {4}",
  507. remoteClient.AgentId, oldAgentID, oldItemID, newFolderID, newName);
  508. InventoryItemBase item = CommsManager.UserProfileCacheService.LibraryRoot.FindItem(oldItemID);
  509. if (item == null)
  510. {
  511. item = new InventoryItemBase(oldItemID, remoteClient.AgentId);
  512. item = InventoryService.GetItem(item);
  513. if (item == null)
  514. {
  515. m_log.Error("[AGENT INVENTORY]: Failed to find item " + oldItemID.ToString());
  516. return;
  517. }
  518. }
  519. AssetBase asset = AssetService.Get(item.AssetID.ToString());
  520. if (asset != null)
  521. {
  522. if (newName != String.Empty)
  523. {
  524. asset.Name = newName;
  525. }
  526. else
  527. {
  528. newName = item.Name;
  529. }
  530. if (remoteClient.AgentId == oldAgentID)
  531. {
  532. CreateNewInventoryItem(
  533. remoteClient, item.CreatorId, newFolderID, newName, item.Flags, callbackID, asset, (sbyte)item.InvType,
  534. item.BasePermissions, item.CurrentPermissions, item.EveryOnePermissions, item.NextPermissions, item.GroupPermissions, Util.UnixTimeSinceEpoch());
  535. }
  536. else
  537. {
  538. CreateNewInventoryItem(
  539. remoteClient, item.CreatorId, newFolderID, newName, item.Flags, callbackID, asset, (sbyte)item.InvType,
  540. item.NextPermissions, item.NextPermissions, item.EveryOnePermissions & item.NextPermissions, item.NextPermissions, item.GroupPermissions, Util.UnixTimeSinceEpoch());
  541. }
  542. }
  543. else
  544. {
  545. m_log.ErrorFormat(
  546. "[AGENT INVENTORY]: Could not copy item {0} since asset {1} could not be found",
  547. item.Name, item.AssetID);
  548. }
  549. }
  550. /// <summary>
  551. /// Create a new asset data structure.
  552. /// </summary>
  553. /// <param name="name"></param>
  554. /// <param name="description"></param>
  555. /// <param name="invType"></param>
  556. /// <param name="assetType"></param>
  557. /// <param name="data"></param>
  558. /// <returns></returns>
  559. private AssetBase CreateAsset(string name, string description, sbyte assetType, byte[] data)
  560. {
  561. AssetBase asset = new AssetBase(UUID.Random(), name, assetType);
  562. asset.Description = description;
  563. asset.Data = (data == null) ? new byte[1] : data;
  564. return asset;
  565. }
  566. /// <summary>
  567. /// Move an item within the agent's inventory.
  568. /// </summary>
  569. /// <param name="remoteClient"></param>
  570. /// <param name="folderID"></param>
  571. /// <param name="itemID"></param>
  572. /// <param name="length"></param>
  573. /// <param name="newName"></param>
  574. public void MoveInventoryItem(IClientAPI remoteClient, List<InventoryItemBase> items)
  575. {
  576. m_log.DebugFormat(
  577. "[AGENT INVENTORY]: Moving {0} items for user {1}", items.Count, remoteClient.AgentId);
  578. if (!InventoryService.MoveItems(remoteClient.AgentId, items))
  579. m_log.Warn("[AGENT INVENTORY]: Failed to move items for user " + remoteClient.AgentId);
  580. }
  581. /// <summary>
  582. /// Create a new inventory item.
  583. /// </summary>
  584. /// <param name="remoteClient"></param>
  585. /// <param name="folderID"></param>
  586. /// <param name="callbackID"></param>
  587. /// <param name="asset"></param>
  588. /// <param name="invType"></param>
  589. /// <param name="nextOwnerMask"></param>
  590. private void CreateNewInventoryItem(IClientAPI remoteClient, string creatorID, UUID folderID, string name, uint flags, uint callbackID,
  591. AssetBase asset, sbyte invType, uint nextOwnerMask, int creationDate)
  592. {
  593. CreateNewInventoryItem(
  594. remoteClient, creatorID, folderID, name, flags, callbackID, asset, invType,
  595. (uint)PermissionMask.All, (uint)PermissionMask.All, 0, nextOwnerMask, 0, creationDate);
  596. }
  597. /// <summary>
  598. /// Create a new Inventory Item
  599. /// </summary>
  600. /// <param name="remoteClient"></param>
  601. /// <param name="folderID"></param>
  602. /// <param name="callbackID"></param>
  603. /// <param name="asset"></param>
  604. /// <param name="invType"></param>
  605. /// <param name="nextOwnerMask"></param>
  606. /// <param name="creationDate"></param>
  607. private void CreateNewInventoryItem(
  608. IClientAPI remoteClient, string creatorID, UUID folderID, string name, uint flags, uint callbackID, AssetBase asset, sbyte invType,
  609. uint baseMask, uint currentMask, uint everyoneMask, uint nextOwnerMask, uint groupMask, int creationDate)
  610. {
  611. InventoryItemBase item = new InventoryItemBase();
  612. item.Owner = remoteClient.AgentId;
  613. item.CreatorId = creatorID;
  614. item.ID = UUID.Random();
  615. item.AssetID = asset.FullID;
  616. item.Description = asset.Description;
  617. item.Name = name;
  618. item.Flags = flags;
  619. item.AssetType = asset.Type;
  620. item.InvType = invType;
  621. item.Folder = folderID;
  622. item.CurrentPermissions = currentMask;
  623. item.NextPermissions = nextOwnerMask;
  624. item.EveryOnePermissions = everyoneMask;
  625. item.GroupPermissions = groupMask;
  626. item.BasePermissions = baseMask;
  627. item.CreationDate = creationDate;
  628. if (InventoryService.AddItem(item))
  629. remoteClient.SendInventoryItemCreateUpdate(item, callbackID);
  630. else
  631. {
  632. m_dialogModule.SendAlertToUser(remoteClient, "Failed to create item");
  633. m_log.WarnFormat(
  634. "Failed to add item for {0} in CreateNewInventoryItem!",
  635. remoteClient.Name);
  636. }
  637. }
  638. /// <summary>
  639. /// Create a new inventory item. Called when the client creates a new item directly within their
  640. /// inventory (e.g. by selecting a context inventory menu option).
  641. /// </summary>
  642. /// <param name="remoteClient"></param>
  643. /// <param name="transactionID"></param>
  644. /// <param name="folderID"></param>
  645. /// <param name="callbackID"></param>
  646. /// <param name="description"></param>
  647. /// <param name="name"></param>
  648. /// <param name="invType"></param>
  649. /// <param name="type"></param>
  650. /// <param name="wearableType"></param>
  651. /// <param name="nextOwnerMask"></param>
  652. public void CreateNewInventoryItem(IClientAPI remoteClient, UUID transactionID, UUID folderID,
  653. uint callbackID, string description, string name, sbyte invType,
  654. sbyte assetType,
  655. byte wearableType, uint nextOwnerMask, int creationDate)
  656. {
  657. m_log.DebugFormat("[AGENT INVENTORY]: Received request to create inventory item {0} in folder {1}", name, folderID);
  658. if (!Permissions.CanCreateUserInventory(invType, remoteClient.AgentId))
  659. return;
  660. if (transactionID == UUID.Zero)
  661. {
  662. CachedUserInfo userInfo
  663. = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  664. if (userInfo != null)
  665. {
  666. ScenePresence presence;
  667. TryGetAvatar(remoteClient.AgentId, out presence);
  668. byte[] data = null;
  669. if (invType == (sbyte)InventoryType.Landmark && presence != null)
  670. {
  671. Vector3 pos = presence.AbsolutePosition;
  672. string strdata = String.Format(
  673. "Landmark version 2\nregion_id {0}\nlocal_pos {1} {2} {3}\nregion_handle {4}\n",
  674. presence.Scene.RegionInfo.RegionID,
  675. pos.X, pos.Y, pos.Z,
  676. presence.RegionHandle);
  677. data = Encoding.ASCII.GetBytes(strdata);
  678. }
  679. AssetBase asset = CreateAsset(name, description, assetType, data);
  680. AssetService.Store(asset);
  681. CreateNewInventoryItem(remoteClient, remoteClient.AgentId.ToString(), folderID, asset.Name, 0, callbackID, asset, invType, nextOwnerMask, creationDate);
  682. }
  683. else
  684. {
  685. m_log.ErrorFormat(
  686. "userInfo for agent uuid {0} unexpectedly null in CreateNewInventoryItem",
  687. remoteClient.AgentId);
  688. }
  689. }
  690. else
  691. {
  692. IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
  693. if (agentTransactions != null)
  694. {
  695. agentTransactions.HandleItemCreationFromTransaction(
  696. remoteClient, transactionID, folderID, callbackID, description,
  697. name, invType, assetType, wearableType, nextOwnerMask);
  698. }
  699. }
  700. }
  701. /// <summary>
  702. /// Remove an inventory item for the client's inventory
  703. /// </summary>
  704. /// <param name="remoteClient"></param>
  705. /// <param name="itemID"></param>
  706. private void RemoveInventoryItem(IClientAPI remoteClient, List<UUID> itemIDs)
  707. {
  708. //m_log.Debug("[SCENE INVENTORY]: user " + remoteClient.AgentId);
  709. InventoryService.DeleteItems(remoteClient.AgentId, itemIDs);
  710. }
  711. /// <summary>
  712. /// Removes an inventory folder. This packet is sent when the user
  713. /// right-clicks a folder that's already in trash and chooses "purge"
  714. /// </summary>
  715. /// <param name="remoteClient"></param>
  716. /// <param name="folderID"></param>
  717. private void RemoveInventoryFolder(IClientAPI remoteClient, List<UUID> folderIDs)
  718. {
  719. m_log.DebugFormat("[SCENE INVENTORY]: RemoveInventoryFolders count {0}", folderIDs.Count);
  720. InventoryService.DeleteFolders(remoteClient.AgentId, folderIDs);
  721. }
  722. /// <summary>
  723. /// Send the details of a prim's inventory to the client.
  724. /// </summary>
  725. /// <param name="remoteClient"></param>
  726. /// <param name="primLocalID"></param>
  727. public void RequestTaskInventory(IClientAPI remoteClient, uint primLocalID)
  728. {
  729. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  730. if (group != null)
  731. {
  732. bool fileChange = group.GetPartInventoryFileName(remoteClient, primLocalID);
  733. if (fileChange)
  734. {
  735. if (XferManager != null)
  736. {
  737. group.RequestInventoryFile(remoteClient, primLocalID, XferManager);
  738. }
  739. }
  740. }
  741. else
  742. {
  743. m_log.ErrorFormat(
  744. "[PRIM INVENTORY]: Inventory requested of prim {0} which doesn't exist", primLocalID);
  745. }
  746. }
  747. /// <summary>
  748. /// Remove an item from a prim (task) inventory
  749. /// </summary>
  750. /// <param name="remoteClient">Unused at the moment but retained since the avatar ID might
  751. /// be necessary for a permissions check at some stage.</param>
  752. /// <param name="itemID"></param>
  753. /// <param name="localID"></param>
  754. public void RemoveTaskInventory(IClientAPI remoteClient, UUID itemID, uint localID)
  755. {
  756. SceneObjectPart part = GetSceneObjectPart(localID);
  757. SceneObjectGroup group = part.ParentGroup;
  758. if (group != null)
  759. {
  760. TaskInventoryItem item = group.GetInventoryItem(localID, itemID);
  761. if (item == null)
  762. return;
  763. if (item.Type == 10)
  764. {
  765. EventManager.TriggerRemoveScript(localID, itemID);
  766. }
  767. group.RemoveInventoryItem(localID, itemID);
  768. part.GetProperties(remoteClient);
  769. }
  770. else
  771. {
  772. m_log.ErrorFormat(
  773. "[PRIM INVENTORY]: " +
  774. "Removal of item {0} requested of prim {1} but this prim does not exist",
  775. itemID,
  776. localID);
  777. }
  778. }
  779. private InventoryItemBase CreateAgentInventoryItemFromTask(UUID destAgent, SceneObjectPart part, UUID itemId)
  780. {
  781. Console.WriteLine("CreateAgentInventoryItemFromTask");
  782. TaskInventoryItem taskItem = part.Inventory.GetInventoryItem(itemId);
  783. if (null == taskItem)
  784. {
  785. m_log.ErrorFormat(
  786. "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for creating an avatar"
  787. + " inventory item from a prim's inventory item "
  788. + " but the required item does not exist in the prim's inventory",
  789. itemId, part.Name, part.UUID);
  790. return null;
  791. }
  792. if ((destAgent != taskItem.OwnerID) && ((taskItem.CurrentPermissions & (uint)PermissionMask.Transfer) == 0))
  793. {
  794. return null;
  795. }
  796. InventoryItemBase agentItem = new InventoryItemBase();
  797. agentItem.ID = UUID.Random();
  798. agentItem.CreatorId = taskItem.CreatorID.ToString();
  799. agentItem.Owner = destAgent;
  800. agentItem.AssetID = taskItem.AssetID;
  801. agentItem.Description = taskItem.Description;
  802. agentItem.Name = taskItem.Name;
  803. agentItem.AssetType = taskItem.Type;
  804. agentItem.InvType = taskItem.InvType;
  805. agentItem.Flags = taskItem.Flags;
  806. if ((part.OwnerID != destAgent) && Permissions.PropagatePermissions())
  807. {
  808. if (taskItem.InvType == (int)InventoryType.Object)
  809. agentItem.BasePermissions = taskItem.BasePermissions & ((taskItem.CurrentPermissions & 7) << 13);
  810. else
  811. agentItem.BasePermissions = taskItem.BasePermissions;
  812. agentItem.BasePermissions &= taskItem.NextPermissions;
  813. agentItem.CurrentPermissions = agentItem.BasePermissions | 8;
  814. agentItem.NextPermissions = taskItem.NextPermissions;
  815. agentItem.EveryOnePermissions = taskItem.EveryonePermissions & taskItem.NextPermissions;
  816. agentItem.GroupPermissions = taskItem.GroupPermissions & taskItem.NextPermissions;
  817. }
  818. else
  819. {
  820. agentItem.BasePermissions = taskItem.BasePermissions;
  821. agentItem.CurrentPermissions = taskItem.CurrentPermissions;
  822. agentItem.NextPermissions = taskItem.NextPermissions;
  823. agentItem.EveryOnePermissions = taskItem.EveryonePermissions;
  824. agentItem.GroupPermissions = taskItem.GroupPermissions;
  825. }
  826. if (!Permissions.BypassPermissions())
  827. {
  828. if ((taskItem.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  829. part.Inventory.RemoveInventoryItem(itemId);
  830. }
  831. return agentItem;
  832. }
  833. /// <summary>
  834. /// Move the given item in the given prim to a folder in the client's inventory
  835. /// </summary>
  836. /// <param name="remoteClient"></param>
  837. /// <param name="folderID"></param>
  838. /// <param name="part"></param>
  839. /// <param name="itemID"></param>
  840. public InventoryItemBase MoveTaskInventoryItem(IClientAPI remoteClient, UUID folderId, SceneObjectPart part, UUID itemId)
  841. {
  842. m_log.Info("Adding task inventory");
  843. InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(remoteClient.AgentId, part, itemId);
  844. if (agentItem == null)
  845. return null;
  846. agentItem.Folder = folderId;
  847. AddInventoryItem(remoteClient, agentItem);
  848. return agentItem;
  849. }
  850. /// <summary>
  851. /// <see>ClientMoveTaskInventoryItem</see>
  852. /// </summary>
  853. /// <param name="remoteClient"></param>
  854. /// <param name="folderID"></param>
  855. /// <param name="primLocalID"></param>
  856. /// <param name="itemID"></param>
  857. public void ClientMoveTaskInventoryItem(IClientAPI remoteClient, UUID folderId, uint primLocalId, UUID itemId)
  858. {
  859. SceneObjectPart part = GetSceneObjectPart(primLocalId);
  860. if (null == part)
  861. {
  862. m_log.WarnFormat(
  863. "[PRIM INVENTORY]: " +
  864. "Move of inventory item {0} from prim with local id {1} failed because the prim could not be found",
  865. itemId, primLocalId);
  866. return;
  867. }
  868. TaskInventoryItem taskItem = part.Inventory.GetInventoryItem(itemId);
  869. if (null == taskItem)
  870. {
  871. m_log.WarnFormat("[PRIM INVENTORY]: Move of inventory item {0} from prim with local id {1} failed"
  872. + " because the inventory item could not be found",
  873. itemId, primLocalId);
  874. return;
  875. }
  876. // Only owner can copy
  877. if (remoteClient.AgentId != taskItem.OwnerID)
  878. return;
  879. MoveTaskInventoryItem(remoteClient, folderId, part, itemId);
  880. }
  881. /// <summary>
  882. /// <see>MoveTaskInventoryItem</see>
  883. /// </summary>
  884. /// <param name="remoteClient"></param>
  885. /// <param name="folderID"></param>
  886. /// <param name="part"></param>
  887. /// <param name="itemID"></param>
  888. public InventoryItemBase MoveTaskInventoryItem(UUID avatarId, UUID folderId, SceneObjectPart part, UUID itemId)
  889. {
  890. ScenePresence avatar;
  891. if (TryGetAvatar(avatarId, out avatar))
  892. {
  893. return MoveTaskInventoryItem(avatar.ControllingClient, folderId, part, itemId);
  894. }
  895. else
  896. {
  897. InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(avatarId, part, itemId);
  898. if (agentItem == null)
  899. return null;
  900. agentItem.Folder = folderId;
  901. AddInventoryItem(avatarId, agentItem);
  902. return agentItem;
  903. }
  904. }
  905. /// <summary>
  906. /// Copy a task (prim) inventory item to another task (prim)
  907. /// </summary>
  908. /// <param name="destId"></param>
  909. /// <param name="part"></param>
  910. /// <param name="itemId"></param>
  911. public void MoveTaskInventoryItem(UUID destId, SceneObjectPart part, UUID itemId)
  912. {
  913. TaskInventoryItem srcTaskItem = part.Inventory.GetInventoryItem(itemId);
  914. if (srcTaskItem == null)
  915. {
  916. m_log.ErrorFormat(
  917. "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for moving"
  918. + " but the item does not exist in this inventory",
  919. itemId, part.Name, part.UUID);
  920. return;
  921. }
  922. SceneObjectPart destPart = GetSceneObjectPart(destId);
  923. if (destPart == null)
  924. {
  925. m_log.ErrorFormat(
  926. "[PRIM INVENTORY]: " +
  927. "Could not find prim for ID {0}",
  928. destId);
  929. return;
  930. }
  931. // Can't transfer this
  932. //
  933. if ((part.OwnerID != destPart.OwnerID) && ((srcTaskItem.CurrentPermissions & (uint)PermissionMask.Transfer) == 0))
  934. return;
  935. if (part.OwnerID != destPart.OwnerID && (part.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) == 0)
  936. {
  937. // object cannot copy items to an object owned by a different owner
  938. // unless llAllowInventoryDrop has been called
  939. return;
  940. }
  941. // must have both move and modify permission to put an item in an object
  942. if ((part.OwnerMask & ((uint)PermissionMask.Move | (uint)PermissionMask.Modify)) == 0)
  943. {
  944. return;
  945. }
  946. TaskInventoryItem destTaskItem = new TaskInventoryItem();
  947. destTaskItem.ItemID = UUID.Random();
  948. destTaskItem.CreatorID = srcTaskItem.CreatorID;
  949. destTaskItem.AssetID = srcTaskItem.AssetID;
  950. destTaskItem.GroupID = destPart.GroupID;
  951. destTaskItem.OwnerID = destPart.OwnerID;
  952. destTaskItem.ParentID = destPart.UUID;
  953. destTaskItem.ParentPartID = destPart.UUID;
  954. destTaskItem.BasePermissions = srcTaskItem.BasePermissions;
  955. destTaskItem.EveryonePermissions = srcTaskItem.EveryonePermissions;
  956. destTaskItem.GroupPermissions = srcTaskItem.GroupPermissions;
  957. destTaskItem.CurrentPermissions = srcTaskItem.CurrentPermissions;
  958. destTaskItem.NextPermissions = srcTaskItem.NextPermissions;
  959. destTaskItem.Flags = srcTaskItem.Flags;
  960. if (destPart.OwnerID != part.OwnerID)
  961. {
  962. if (Permissions.PropagatePermissions())
  963. {
  964. destTaskItem.CurrentPermissions = srcTaskItem.CurrentPermissions &
  965. srcTaskItem.NextPermissions;
  966. destTaskItem.GroupPermissions = srcTaskItem.GroupPermissions &
  967. srcTaskItem.NextPermissions;
  968. destTaskItem.EveryonePermissions = srcTaskItem.EveryonePermissions &
  969. srcTaskItem.NextPermissions;
  970. destTaskItem.BasePermissions = srcTaskItem.BasePermissions &
  971. srcTaskItem.NextPermissions;
  972. destTaskItem.CurrentPermissions |= 8; // Slam!
  973. }
  974. }
  975. destTaskItem.Description = srcTaskItem.Description;
  976. destTaskItem.Name = srcTaskItem.Name;
  977. destTaskItem.InvType = srcTaskItem.InvType;
  978. destTaskItem.Type = srcTaskItem.Type;
  979. destPart.Inventory.AddInventoryItem(destTaskItem, part.OwnerID != destPart.OwnerID);
  980. if ((srcTaskItem.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  981. part.Inventory.RemoveInventoryItem(itemId);
  982. ScenePresence avatar;
  983. if (TryGetAvatar(srcTaskItem.OwnerID, out avatar))
  984. {
  985. destPart.GetProperties(avatar.ControllingClient);
  986. }
  987. }
  988. public UUID MoveTaskInventoryItems(UUID destID, string category, SceneObjectPart host, List<UUID> items)
  989. {
  990. InventoryFolderBase rootFolder = InventoryService.GetRootFolder(destID);
  991. UUID newFolderID = UUID.Random();
  992. InventoryFolderBase newFolder = new InventoryFolderBase(newFolderID, category, destID, -1, rootFolder.ID, rootFolder.Version);
  993. InventoryService.AddFolder(newFolder);
  994. foreach (UUID itemID in items)
  995. {
  996. InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(destID, host, itemID);
  997. if (agentItem != null)
  998. {
  999. agentItem.Folder = newFolderID;
  1000. AddInventoryItem(destID, agentItem);
  1001. }
  1002. }
  1003. ScenePresence avatar = null;
  1004. if (TryGetAvatar(destID, out avatar))
  1005. {
  1006. //profile.SendInventoryDecendents(avatar.ControllingClient,
  1007. // profile.RootFolder.ID, true, false);
  1008. //profile.SendInventoryDecendents(avatar.ControllingClient,
  1009. // newFolderID, false, true);
  1010. SendInventoryUpdate(avatar.ControllingClient, rootFolder, true, false);
  1011. SendInventoryUpdate(avatar.ControllingClient, newFolder, false, true);
  1012. }
  1013. return newFolderID;
  1014. }
  1015. private void SendInventoryUpdate(IClientAPI client, InventoryFolderBase folder, bool fetchFolders, bool fetchItems)
  1016. {
  1017. m_log.DebugFormat("[AGENT INVENTORY]: Send Inventory Folder {0} Update to {1} {2}", folder.Name, client.FirstName, client.LastName);
  1018. InventoryCollection contents = InventoryService.GetFolderContent(client.AgentId, folder.ID);
  1019. InventoryFolderBase containingFolder = new InventoryFolderBase();
  1020. containingFolder.ID = folder.ID;
  1021. containingFolder.Owner = client.AgentId;
  1022. containingFolder = InventoryService.GetFolder(containingFolder);
  1023. int version = containingFolder.Version;
  1024. client.SendInventoryFolderDetails(client.AgentId, folder.ID, contents.Items, contents.Folders, version, fetchFolders, fetchItems);
  1025. }
  1026. /// <summary>
  1027. /// Update an item in a prim (task) inventory.
  1028. /// This method does not handle scripts, <see>RezScript(IClientAPI, UUID, unit)</see>
  1029. /// </summary>
  1030. /// <param name="remoteClient"></param>
  1031. /// <param name="transactionID"></param>
  1032. /// <param name="itemInfo"></param>
  1033. /// <param name="primLocalID"></param>
  1034. public void UpdateTaskInventory(IClientAPI remoteClient, UUID transactionID, TaskInventoryItem itemInfo,
  1035. uint primLocalID)
  1036. {
  1037. UUID itemID = itemInfo.ItemID;
  1038. // Find the prim we're dealing with
  1039. SceneObjectPart part = GetSceneObjectPart(primLocalID);
  1040. if (part != null)
  1041. {
  1042. TaskInventoryItem currentItem = part.Inventory.GetInventoryItem(itemID);
  1043. bool allowInventoryDrop = (part.GetEffectiveObjectFlags()
  1044. & (uint)PrimFlags.AllowInventoryDrop) != 0;
  1045. // Explicity allow anyone to add to the inventory if the
  1046. // AllowInventoryDrop flag has been set. Don't however let
  1047. // them update an item unless they pass the external checks
  1048. //
  1049. if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId)
  1050. && (currentItem != null || !allowInventoryDrop))
  1051. return;
  1052. if (currentItem == null)
  1053. {
  1054. UUID copyID = UUID.Random();
  1055. if (itemID != UUID.Zero)
  1056. {
  1057. InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
  1058. item = InventoryService.GetItem(item);
  1059. // Try library
  1060. if (null == item)
  1061. {
  1062. item = CommsManager.UserProfileCacheService.LibraryRoot.FindItem(itemID);
  1063. }
  1064. if (item != null)
  1065. {
  1066. part.ParentGroup.AddInventoryItem(remoteClient, primLocalID, item, copyID);
  1067. m_log.InfoFormat(
  1068. "[PRIM INVENTORY]: Update with item {0} requested of prim {1} for {2}",
  1069. item.Name, primLocalID, remoteClient.Name);
  1070. part.GetProperties(remoteClient);
  1071. if (!Permissions.BypassPermissions())
  1072. {
  1073. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  1074. {
  1075. List<UUID> uuids = new List<UUID>();
  1076. uuids.Add(itemID);
  1077. RemoveInventoryItem(remoteClient, uuids);
  1078. }
  1079. }
  1080. }
  1081. else
  1082. {
  1083. m_log.ErrorFormat(
  1084. "[PRIM INVENTORY]: Could not find inventory item {0} to update for {1}!",
  1085. itemID, remoteClient.Name);
  1086. }
  1087. }
  1088. }
  1089. else // Updating existing item with new perms etc
  1090. {
  1091. IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
  1092. if (agentTransactions != null)
  1093. {
  1094. agentTransactions.HandleTaskItemUpdateFromTransaction(
  1095. remoteClient, part, transactionID, currentItem);
  1096. }
  1097. if (part.Inventory.UpdateInventoryItem(itemInfo))
  1098. part.GetProperties(remoteClient);
  1099. }
  1100. }
  1101. else
  1102. {
  1103. m_log.WarnFormat(
  1104. "[PRIM INVENTORY]: " +
  1105. "Update with item {0} requested of prim {1} for {2} but this prim does not exist",
  1106. itemID, primLocalID, remoteClient.Name);
  1107. }
  1108. }
  1109. /// <summary>
  1110. /// Rez a script into a prim's inventory, either ex nihilo or from an existing avatar inventory
  1111. /// </summary>
  1112. /// <param name="remoteClient"></param>
  1113. /// <param name="itemID"> </param>
  1114. /// <param name="localID"></param>
  1115. public void RezScript(IClientAPI remoteClient, InventoryItemBase itemBase, UUID transactionID, uint localID)
  1116. {
  1117. UUID itemID = itemBase.ID;
  1118. UUID copyID = UUID.Random();
  1119. if (itemID != UUID.Zero) // transferred from an avatar inventory to the prim's inventory
  1120. {
  1121. InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
  1122. item = InventoryService.GetItem(item);
  1123. // Try library
  1124. // XXX clumsy, possibly should be one call
  1125. if (null == item)
  1126. {
  1127. item = CommsManager.UserProfileCacheService.LibraryRoot.FindItem(itemID);
  1128. }
  1129. if (item != null)
  1130. {
  1131. SceneObjectPart part = GetSceneObjectPart(localID);
  1132. if (part != null)
  1133. {
  1134. if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId))
  1135. return;
  1136. part.ParentGroup.AddInventoryItem(remoteClient, localID, item, copyID);
  1137. // TODO: switch to posting on_rez here when scripts
  1138. // have state in inventory
  1139. part.Inventory.CreateScriptInstance(copyID, 0, false, DefaultScriptEngine, 0);
  1140. // m_log.InfoFormat("[PRIMINVENTORY]: " +
  1141. // "Rezzed script {0} into prim local ID {1} for user {2}",
  1142. // item.inventoryName, localID, remoteClient.Name);
  1143. part.GetProperties(remoteClient);
  1144. }
  1145. else
  1146. {
  1147. m_log.ErrorFormat(
  1148. "[PRIM INVENTORY]: " +
  1149. "Could not rez script {0} into prim local ID {1} for user {2}"
  1150. + " because the prim could not be found in the region!",
  1151. item.Name, localID, remoteClient.Name);
  1152. }
  1153. }
  1154. else
  1155. {
  1156. m_log.ErrorFormat(
  1157. "[PRIM INVENTORY]: Could not find script inventory item {0} to rez for {1}!",
  1158. itemID, remoteClient.Name);
  1159. }
  1160. }
  1161. else // script has been rezzed directly into a prim's inventory
  1162. {
  1163. SceneObjectPart part = GetSceneObjectPart(itemBase.Folder);
  1164. if (part == null)
  1165. return;
  1166. if (part.OwnerID != remoteClient.AgentId)
  1167. {
  1168. // Group permissions
  1169. if ((part.GroupID == UUID.Zero) || (remoteClient.GetGroupPowers(part.GroupID) == 0) || ((part.GroupMask & (uint)PermissionMask.Modify) == 0))
  1170. return;
  1171. } else {
  1172. if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
  1173. return;
  1174. }
  1175. if (!Permissions.CanCreateObjectInventory(
  1176. itemBase.InvType, part.UUID, remoteClient.AgentId))
  1177. return;
  1178. AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType, Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"));
  1179. AssetService.Store(asset);
  1180. TaskInventoryItem taskItem = new TaskInventoryItem();
  1181. taskItem.ResetIDs(itemBase.Folder);
  1182. taskItem.ParentID = itemBase.Folder;
  1183. taskItem.CreationDate = (uint)itemBase.CreationDate;
  1184. taskItem.Name = itemBase.Name;
  1185. taskItem.Description = itemBase.Description;
  1186. taskItem.Type = itemBase.AssetType;
  1187. taskItem.InvType = itemBase.InvType;
  1188. taskItem.OwnerID = itemBase.Owner;
  1189. taskItem.CreatorID = itemBase.CreatorIdAsUuid;
  1190. taskItem.BasePermissions = itemBase.BasePermissions;
  1191. taskItem.CurrentPermissions = itemBase.CurrentPermissions;
  1192. taskItem.EveryonePermissions = itemBase.EveryOnePermissions;
  1193. taskItem.GroupPermissions = itemBase.GroupPermissions;
  1194. taskItem.NextPermissions = itemBase.NextPermissions;
  1195. taskItem.GroupID = itemBase.GroupID;
  1196. taskItem.GroupPermissions = 0;
  1197. taskItem.Flags = itemBase.Flags;
  1198. taskItem.PermsGranter = UUID.Zero;
  1199. taskItem.PermsMask = 0;
  1200. taskItem.AssetID = asset.FullID;
  1201. part.Inventory.AddInventoryItem(taskItem, false);
  1202. part.GetProperties(remoteClient);
  1203. part.Inventory.CreateScriptInstance(taskItem, 0, false, DefaultScriptEngine, 0);
  1204. }
  1205. }
  1206. /// <summary>
  1207. /// Rez a script into a prim's inventory from another prim
  1208. /// </summary>
  1209. /// <param name="remoteClient"></param>
  1210. /// <param name="itemID"> </param>
  1211. /// <param name="localID"></param>
  1212. public void RezScript(UUID srcId, SceneObjectPart srcPart, UUID destId, int pin, int running, int start_param)
  1213. {
  1214. TaskInventoryItem srcTaskItem = srcPart.Inventory.GetInventoryItem(srcId);
  1215. if (srcTaskItem == null)
  1216. {
  1217. m_log.ErrorFormat(
  1218. "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for rezzing a script but the "
  1219. + " item does not exist in this inventory",
  1220. srcId, srcPart.Name, srcPart.UUID);
  1221. return;
  1222. }
  1223. SceneObjectPart destPart = GetSceneObjectPart(destId);
  1224. if (destPart == null)
  1225. {
  1226. m_log.ErrorFormat(
  1227. "[PRIM INVENTORY]: " +
  1228. "Could not find script for ID {0}",
  1229. destId);
  1230. return;
  1231. }
  1232. // Must own the object, and have modify rights
  1233. if (srcPart.OwnerID != destPart.OwnerID)
  1234. {
  1235. // Group permissions
  1236. if ((destPart.GroupID == UUID.Zero) || (destPart.GroupID != srcPart.GroupID) ||
  1237. ((destPart.GroupMask & (uint)PermissionMask.Modify) == 0))
  1238. return;
  1239. } else {
  1240. if ((destPart.OwnerMask & (uint)PermissionMask.Modify) == 0)
  1241. return;
  1242. }
  1243. if (destPart.ScriptAccessPin != pin)
  1244. {
  1245. m_log.WarnFormat(
  1246. "[PRIM INVENTORY]: " +
  1247. "Script in object {0} : {1}, attempted to load script {2} : {3} into object {4} : {5} with invalid pin {6}",
  1248. srcPart.Name, srcId, srcTaskItem.Name, srcTaskItem.ItemID, destPart.Name, destId, pin);
  1249. // the LSL Wiki says we are supposed to shout on the DEBUG_CHANNEL -
  1250. // "Object: Task Object trying to illegally load script onto task Other_Object!"
  1251. // How do we shout from in here?
  1252. return;
  1253. }
  1254. TaskInventoryItem destTaskItem = new TaskInventoryItem();
  1255. destTaskItem.ItemID = UUID.Random();
  1256. destTaskItem.CreatorID = srcTaskItem.CreatorID;
  1257. destTaskItem.AssetID = srcTaskItem.AssetID;
  1258. destTaskItem.GroupID = destPart.GroupID;
  1259. destTaskItem.OwnerID = destPart.OwnerID;
  1260. destTaskItem.ParentID = destPart.UUID;
  1261. destTaskItem.ParentPartID = destPart.UUID;
  1262. destTaskItem.BasePermissions = srcTaskItem.BasePermissions;
  1263. destTaskItem.EveryonePermissions = srcTaskItem.EveryonePermissions;
  1264. destTaskItem.GroupPermissions = srcTaskItem.GroupPermissions;
  1265. destTaskItem.CurrentPermissions = srcTaskItem.CurrentPermissions;
  1266. destTaskItem.NextPermissions = srcTaskItem.NextPermissions;
  1267. destTaskItem.Flags = srcTaskItem.Flags;
  1268. if (destPart.OwnerID != srcPart.OwnerID)
  1269. {
  1270. if (Permissions.PropagatePermissions())
  1271. {
  1272. destTaskItem.CurrentPermissions = srcTaskItem.CurrentPermissions &
  1273. srcTaskItem.NextPermissions;
  1274. destTaskItem.GroupPermissions = srcTaskItem.GroupPermissions &
  1275. srcTaskItem.NextPermissions;
  1276. destTaskItem.EveryonePermissions = srcTaskItem.EveryonePermissions &
  1277. srcTaskItem.NextPermissions;
  1278. destTaskItem.BasePermissions = srcTaskItem.BasePermissions &
  1279. srcTaskItem.NextPermissions;
  1280. destTaskItem.CurrentPermissions |= 8; // Slam!
  1281. }
  1282. }
  1283. destTaskItem.Description = srcTaskItem.Description;
  1284. destTaskItem.Name = srcTaskItem.Name;
  1285. destTaskItem.InvType = srcTaskItem.InvType;
  1286. destTaskItem.Type = srcTaskItem.Type;
  1287. destPart.Inventory.AddInventoryItemExclusive(destTaskItem, false);
  1288. if (running > 0)
  1289. {
  1290. destPart.Inventory.CreateScriptInstance(destTaskItem, start_param, false, DefaultScriptEngine, 0);
  1291. }
  1292. ScenePresence avatar;
  1293. if (TryGetAvatar(srcTaskItem.OwnerID, out avatar))
  1294. {
  1295. destPart.GetProperties(avatar.ControllingClient);
  1296. }
  1297. }
  1298. /// <summary>
  1299. /// Called when one or more objects are removed from the environment into inventory.
  1300. /// </summary>
  1301. /// <param name="remoteClient"></param>
  1302. /// <param name="localID"></param>
  1303. /// <param name="groupID"></param>
  1304. /// <param name="action"></param>
  1305. /// <param name="destinationID"></param>
  1306. public virtual void DeRezObject(IClientAPI remoteClient, List<uint> localIDs,
  1307. UUID groupID, DeRezAction action, UUID destinationID)
  1308. {
  1309. foreach (uint localID in localIDs)
  1310. {
  1311. DeRezObject(remoteClient, localID, groupID, action, destinationID);
  1312. }
  1313. }
  1314. /// <summary>
  1315. /// Called when an object is removed from the environment into inventory.
  1316. /// </summary>
  1317. /// <param name="remoteClient"></param>
  1318. /// <param name="localID"></param>
  1319. /// <param name="groupID"></param>
  1320. /// <param name="action"></param>
  1321. /// <param name="destinationID"></param>
  1322. public virtual void DeRezObject(IClientAPI remoteClient, uint localID,
  1323. UUID groupID, DeRezAction action, UUID destinationID)
  1324. {
  1325. SceneObjectPart part = GetSceneObjectPart(localID);
  1326. if (part == null)
  1327. return;
  1328. if (part.ParentGroup == null || part.ParentGroup.IsDeleted)
  1329. return;
  1330. // Can't delete child prims
  1331. if (part != part.ParentGroup.RootPart)
  1332. return;
  1333. SceneObjectGroup grp = part.ParentGroup;
  1334. //force a database backup/update on this SceneObjectGroup
  1335. //So that we know the database is upto date, for when deleting the object from it
  1336. ForceSceneObjectBackup(grp);
  1337. bool permissionToTake = false;
  1338. bool permissionToDelete = false;
  1339. if (action == DeRezAction.SaveToExistingUserInventoryItem)
  1340. {
  1341. if (grp.OwnerID == remoteClient.AgentId && grp.RootPart.FromUserInventoryItemID != UUID.Zero)
  1342. {
  1343. permissionToTake = true;
  1344. permissionToDelete = false;
  1345. }
  1346. }
  1347. else if (action == DeRezAction.TakeCopy)
  1348. {
  1349. permissionToTake =
  1350. Permissions.CanTakeCopyObject(
  1351. grp.UUID,
  1352. remoteClient.AgentId);
  1353. }
  1354. else if (action == DeRezAction.GodTakeCopy)
  1355. {
  1356. permissionToTake =
  1357. Permissions.IsGod(
  1358. remoteClient.AgentId);
  1359. }
  1360. else if (action == DeRezAction.Take)
  1361. {
  1362. permissionToTake =
  1363. Permissions.CanTakeObject(
  1364. grp.UUID,
  1365. remoteClient.AgentId);
  1366. //If they can take, they can delete!
  1367. permissionToDelete = permissionToTake;
  1368. }
  1369. else if (action == DeRezAction.Delete)
  1370. {
  1371. permissionToTake =
  1372. Permissions.CanDeleteObject(
  1373. grp.UUID,
  1374. remoteClient.AgentId);
  1375. permissionToDelete = permissionToTake;
  1376. }
  1377. else if (action == DeRezAction.Return)
  1378. {
  1379. if (remoteClient != null)
  1380. {
  1381. permissionToTake =
  1382. Permissions.CanReturnObject(
  1383. grp.UUID,
  1384. remoteClient.AgentId);
  1385. permissionToDelete = permissionToTake;
  1386. if (permissionToDelete)
  1387. {
  1388. AddReturn(grp.OwnerID, grp.Name, grp.AbsolutePosition, "parcel owner return");
  1389. }
  1390. }
  1391. else // Auto return passes through here with null agent
  1392. {
  1393. permissionToTake = true;
  1394. permissionToDelete = true;
  1395. }
  1396. }
  1397. else
  1398. {
  1399. m_log.DebugFormat(
  1400. "[AGENT INVENTORY]: Ignoring unexpected derez action {0} for {1}", action, remoteClient.Name);
  1401. return;
  1402. }
  1403. if (permissionToTake)
  1404. {
  1405. m_asyncSceneObjectDeleter.DeleteToInventory(
  1406. action, destinationID, grp, remoteClient,
  1407. permissionToDelete);
  1408. }
  1409. else if (permissionToDelete)
  1410. {
  1411. DeleteSceneObject(grp, false);
  1412. }
  1413. }
  1414. /// <summary>
  1415. /// Delete a scene object from a scene and place in the given avatar's inventory.
  1416. /// Returns the UUID of the newly created asset.
  1417. /// </summary>
  1418. /// <param name="action"></param>
  1419. /// <param name="folderID"></param>
  1420. /// <param name="objectGroup"></param>
  1421. /// <param name="remoteClient"> </param>
  1422. public virtual UUID DeleteToInventory(DeRezAction action, UUID folderID,
  1423. SceneObjectGroup objectGroup, IClientAPI remoteClient)
  1424. {
  1425. UUID assetID = UUID.Zero;
  1426. Vector3 inventoryStoredPosition = new Vector3
  1427. (((objectGroup.AbsolutePosition.X > (int)Constants.RegionSize)
  1428. ? 250
  1429. : objectGroup.AbsolutePosition.X)
  1430. ,
  1431. (objectGroup.AbsolutePosition.X > (int)Constants.RegionSize)
  1432. ? 250
  1433. : objectGroup.AbsolutePosition.X,
  1434. objectGroup.AbsolutePosition.Z);
  1435. Vector3 originalPosition = objectGroup.AbsolutePosition;
  1436. objectGroup.AbsolutePosition = inventoryStoredPosition;
  1437. string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(objectGroup);
  1438. objectGroup.AbsolutePosition = originalPosition;
  1439. // Get the user info of the item destination
  1440. //
  1441. UUID userID = UUID.Zero;
  1442. if (action == DeRezAction.Take || action == DeRezAction.TakeCopy ||
  1443. action == DeRezAction.SaveToExistingUserInventoryItem)
  1444. {
  1445. // Take or take copy require a taker
  1446. // Saving changes requires a local user
  1447. //
  1448. if (remoteClient == null)
  1449. return UUID.Zero;
  1450. userID = remoteClient.AgentId;
  1451. }
  1452. else
  1453. {
  1454. // All returns / deletes go to the object owner
  1455. //
  1456. userID = objectGroup.RootPart.OwnerID;
  1457. }
  1458. if (userID == UUID.Zero) // Can't proceed
  1459. {
  1460. return UUID.Zero;
  1461. }
  1462. // If we're returning someone's item, it goes back to the
  1463. // owner's Lost And Found folder.
  1464. // Delete is treated like return in this case
  1465. // Deleting your own items makes them go to trash
  1466. //
  1467. InventoryFolderBase folder = null;
  1468. InventoryItemBase item = null;
  1469. if (DeRezAction.SaveToExistingUserInventoryItem == action)
  1470. {
  1471. item = new InventoryItemBase(objectGroup.RootPart.FromUserInventoryItemID, userID);
  1472. item = InventoryService.GetItem(item);
  1473. //item = userInfo.RootFolder.FindItem(
  1474. // objectGroup.RootPart.FromUserInventoryItemID);
  1475. if (null == item)
  1476. {
  1477. m_log.DebugFormat(
  1478. "[AGENT INVENTORY]: Object {0} {1} scheduled for save to inventory has already been deleted.",
  1479. objectGroup.Name, objectGroup.UUID);
  1480. return UUID.Zero;
  1481. }
  1482. }
  1483. else
  1484. {
  1485. // Folder magic
  1486. //
  1487. if (action == DeRezAction.Delete)
  1488. {
  1489. // Deleting someone else's item
  1490. //
  1491. if (remoteClient == null ||
  1492. objectGroup.OwnerID != remoteClient.AgentId)
  1493. {
  1494. // Folder skeleton may not be loaded and we
  1495. // have to wait for the inventory to find
  1496. // the destination folder
  1497. //
  1498. folder = InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
  1499. }
  1500. else
  1501. {
  1502. // Assume inventory skeleton was loaded during login
  1503. // and all folders can be found
  1504. //
  1505. folder = InventoryService.GetFolderForType(userID, AssetType.TrashFolder);
  1506. }
  1507. }
  1508. else if (action == DeRezAction.Return)
  1509. {
  1510. // Dump to lost + found unconditionally
  1511. //
  1512. folder = InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
  1513. }
  1514. if (folderID == UUID.Zero && folder == null)
  1515. {
  1516. if (action == DeRezAction.Delete)
  1517. {
  1518. // Deletes go to trash by default
  1519. //
  1520. folder = InventoryService.GetFolderForType(userID, AssetType.TrashFolder);
  1521. }
  1522. else
  1523. {
  1524. // Catch all. Use lost & found
  1525. //
  1526. folder = InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
  1527. }
  1528. }
  1529. if (folder == null) // None of the above
  1530. {
  1531. //folder = userInfo.RootFolder.FindFolder(folderID);
  1532. folder = new InventoryFolderBase(folderID);
  1533. if (folder == null) // Nowhere to put it
  1534. {
  1535. return UUID.Zero;
  1536. }
  1537. }
  1538. item = new InventoryItemBase();
  1539. item.CreatorId = objectGroup.RootPart.CreatorID.ToString();
  1540. item.ID = UUID.Random();
  1541. item.InvType = (int)InventoryType.Object;
  1542. item.Folder = folder.ID;
  1543. item.Owner = userID;
  1544. }
  1545. AssetBase asset = CreateAsset(
  1546. objectGroup.GetPartName(objectGroup.RootPart.LocalId),
  1547. objectGroup.GetPartDescription(objectGroup.RootPart.LocalId),
  1548. (sbyte)AssetType.Object,
  1549. Utils.StringToBytes(sceneObjectXml));
  1550. AssetService.Store(asset);
  1551. assetID = asset.FullID;
  1552. if (DeRezAction.SaveToExistingUserInventoryItem == action)
  1553. {
  1554. item.AssetID = asset.FullID;
  1555. InventoryService.UpdateItem(item);
  1556. }
  1557. else
  1558. {
  1559. item.AssetID = asset.FullID;
  1560. if (remoteClient != null && (remoteClient.AgentId != objectGroup.RootPart.OwnerID) && Permissions.PropagatePermissions())
  1561. {
  1562. uint perms=objectGroup.GetEffectivePermissions();
  1563. uint nextPerms=(perms & 7) << 13;
  1564. if ((nextPerms & (uint)PermissionMask.Copy) == 0)
  1565. perms &= ~(uint)PermissionMask.Copy;
  1566. if ((nextPerms & (uint)PermissionMask.Transfer) == 0)
  1567. perms &= ~(uint)PermissionMask.Transfer;
  1568. if ((nextPerms & (uint)PermissionMask.Modify) == 0)
  1569. perms &= ~(uint)PermissionMask.Modify;
  1570. item.BasePermissions = perms & objectGroup.RootPart.NextOwnerMask;
  1571. item.CurrentPermissions = item.BasePermissions;
  1572. item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
  1573. item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask & objectGroup.RootPart.NextOwnerMask;
  1574. item.GroupPermissions = objectGroup.RootPart.GroupMask & objectGroup.RootPart.NextOwnerMask;
  1575. item.CurrentPermissions |= 8; // Slam!
  1576. }
  1577. else
  1578. {
  1579. item.BasePermissions = objectGroup.GetEffectivePermissions();
  1580. item.CurrentPermissions = objectGroup.GetEffectivePermissions();
  1581. item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
  1582. item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask;
  1583. item.GroupPermissions = objectGroup.RootPart.GroupMask;
  1584. item.CurrentPermissions |= 8; // Slam!
  1585. }
  1586. // TODO: add the new fields (Flags, Sale info, etc)
  1587. item.CreationDate = Util.UnixTimeSinceEpoch();
  1588. item.Description = asset.Description;
  1589. item.Name = asset.Name;
  1590. item.AssetType = asset.Type;
  1591. InventoryService.AddItem(item);
  1592. if (remoteClient != null && item.Owner == remoteClient.AgentId)
  1593. {
  1594. remoteClient.SendInventoryItemCreateUpdate(item, 0);
  1595. }
  1596. else
  1597. {
  1598. ScenePresence notifyUser = GetScenePresence(item.Owner);
  1599. if (notifyUser != null)
  1600. {
  1601. notifyUser.ControllingClient.SendInventoryItemCreateUpdate(item, 0);
  1602. }
  1603. }
  1604. }
  1605. return assetID;
  1606. }
  1607. public void UpdateKnownItem(IClientAPI remoteClient, SceneObjectGroup grp, UUID itemID, UUID agentID)
  1608. {
  1609. SceneObjectGroup objectGroup = grp;
  1610. if (objectGroup != null)
  1611. {
  1612. if (!grp.HasGroupChanged)
  1613. {
  1614. m_log.InfoFormat("[ATTACHMENT]: Save request for {0} which is unchanged", grp.UUID);
  1615. return;
  1616. }
  1617. m_log.InfoFormat(
  1618. "[ATTACHMENT]: Updating asset for attachment {0}, attachpoint {1}",
  1619. grp.UUID, grp.GetAttachmentPoint());
  1620. string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(objectGroup);
  1621. InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
  1622. item = InventoryService.GetItem(item);
  1623. if (item != null)
  1624. {
  1625. AssetBase asset = CreateAsset(
  1626. objectGroup.GetPartName(objectGroup.LocalId),
  1627. objectGroup.GetPartDescription(objectGroup.LocalId),
  1628. (sbyte)AssetType.Object,
  1629. Utils.StringToBytes(sceneObjectXml));
  1630. AssetService.Store(asset);
  1631. item.AssetID = asset.FullID;
  1632. item.Description = asset.Description;
  1633. item.Name = asset.Name;
  1634. item.AssetType = asset.Type;
  1635. item.InvType = (int)InventoryType.Object;
  1636. InventoryService.UpdateItem(item);
  1637. // this gets called when the agent loggs off!
  1638. if (remoteClient != null)
  1639. {
  1640. remoteClient.SendInventoryItemCreateUpdate(item, 0);
  1641. }
  1642. }
  1643. }
  1644. }
  1645. public UUID attachObjectAssetStore(IClientAPI remoteClient, SceneObjectGroup grp, UUID AgentId, out UUID itemID)
  1646. {
  1647. itemID = UUID.Zero;
  1648. if (grp != null)
  1649. {
  1650. Vector3 inventoryStoredPosition = new Vector3
  1651. (((grp.AbsolutePosition.X > (int)Constants.RegionSize)
  1652. ? 250
  1653. : grp.AbsolutePosition.X)
  1654. ,
  1655. (grp.AbsolutePosition.X > (int)Constants.RegionSize)
  1656. ? 250
  1657. : grp.AbsolutePosition.X,
  1658. grp.AbsolutePosition.Z);
  1659. Vector3 originalPosition = grp.AbsolutePosition;
  1660. grp.AbsolutePosition = inventoryStoredPosition;
  1661. string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp);
  1662. grp.AbsolutePosition = originalPosition;
  1663. AssetBase asset = CreateAsset(
  1664. grp.GetPartName(grp.LocalId),
  1665. grp.GetPartDescription(grp.LocalId),
  1666. (sbyte)AssetType.Object,
  1667. Utils.StringToBytes(sceneObjectXml));
  1668. AssetService.Store(asset);
  1669. InventoryItemBase item = new InventoryItemBase();
  1670. item.CreatorId = grp.RootPart.CreatorID.ToString();
  1671. item.Owner = remoteClient.AgentId;
  1672. item.ID = UUID.Random();
  1673. item.AssetID = asset.FullID;
  1674. item.Description = asset.Description;
  1675. item.Name = asset.Name;
  1676. item.AssetType = asset.Type;
  1677. item.InvType = (int)InventoryType.Object;
  1678. item.Folder = UUID.Zero; // Objects folder!
  1679. if ((remoteClient.AgentId != grp.RootPart.OwnerID) && Permissions.PropagatePermissions())
  1680. {
  1681. item.BasePermissions = grp.RootPart.NextOwnerMask;
  1682. item.CurrentPermissions = grp.RootPart.NextOwnerMask;
  1683. item.NextPermissions = grp.RootPart.NextOwnerMask;
  1684. item.EveryOnePermissions = grp.RootPart.EveryoneMask & grp.RootPart.NextOwnerMask;
  1685. item.GroupPermissions = grp.RootPart.GroupMask & grp.RootPart.NextOwnerMask;
  1686. }
  1687. else
  1688. {
  1689. item.BasePermissions = grp.RootPart.BaseMask;
  1690. item.CurrentPermissions = grp.RootPart.OwnerMask;
  1691. item.NextPermissions = grp.RootPart.NextOwnerMask;
  1692. item.EveryOnePermissions = grp.RootPart.EveryoneMask;
  1693. item.GroupPermissions = grp.RootPart.GroupMask;
  1694. }
  1695. item.CreationDate = Util.UnixTimeSinceEpoch();
  1696. // sets itemID so client can show item as 'attached' in inventory
  1697. grp.SetFromItemID(item.ID);
  1698. if (InventoryService.AddItem(item))
  1699. remoteClient.SendInventoryItemCreateUpdate(item, 0);
  1700. else
  1701. m_dialogModule.SendAlertToUser(remoteClient, "Operation failed");
  1702. itemID = item.ID;
  1703. return item.AssetID;
  1704. }
  1705. return UUID.Zero;
  1706. }
  1707. /// <summary>
  1708. /// Event Handler Rez an object into a scene
  1709. /// Calls the non-void event handler
  1710. /// </summary>
  1711. /// <param name="remoteClient"></param>
  1712. /// <param name="itemID"></param>
  1713. /// <param name="RayEnd"></param>
  1714. /// <param name="RayStart"></param>
  1715. /// <param name="RayTargetID"></param>
  1716. /// <param name="BypassRayCast"></param>
  1717. /// <param name="RayEndIsIntersection"></param>
  1718. /// <param name="EveryoneMask"></param>
  1719. /// <param name="GroupMask"></param>
  1720. /// <param name="RezSelected"></param>
  1721. /// <param name="RemoveItem"></param>
  1722. /// <param name="fromTaskID"></param>
  1723. public virtual void RezObject(IClientAPI remoteClient, UUID itemID, Vector3 RayEnd, Vector3 RayStart,
  1724. UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
  1725. bool RezSelected, bool RemoveItem, UUID fromTaskID)
  1726. {
  1727. RezObject(
  1728. remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection,
  1729. RezSelected, RemoveItem, fromTaskID, false);
  1730. }
  1731. /// <summary>
  1732. /// Rez an object into the scene from the user's inventory
  1733. /// </summary>
  1734. /// <param name="remoteClient"></param>
  1735. /// <param name="itemID"></param>
  1736. /// <param name="RayEnd"></param>
  1737. /// <param name="RayStart"></param>
  1738. /// <param name="RayTargetID"></param>
  1739. /// <param name="BypassRayCast"></param>
  1740. /// <param name="RayEndIsIntersection"></param>
  1741. /// <param name="RezSelected"></param>
  1742. /// <param name="RemoveItem"></param>
  1743. /// <param name="fromTaskID"></param>
  1744. /// <param name="attachment"></param>
  1745. /// <returns>The SceneObjectGroup rezzed or null if rez was unsuccessful.</returns>
  1746. public virtual SceneObjectGroup RezObject(IClientAPI remoteClient, UUID itemID, Vector3 RayEnd, Vector3 RayStart,
  1747. UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
  1748. bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment)
  1749. {
  1750. // Work out position details
  1751. byte bRayEndIsIntersection = (byte)0;
  1752. if (RayEndIsIntersection)
  1753. {
  1754. bRayEndIsIntersection = (byte)1;
  1755. }
  1756. else
  1757. {
  1758. bRayEndIsIntersection = (byte)0;
  1759. }
  1760. Vector3 scale = new Vector3(0.5f, 0.5f, 0.5f);
  1761. Vector3 pos = GetNewRezLocation(
  1762. RayStart, RayEnd, RayTargetID, Quaternion.Identity,
  1763. BypassRayCast, bRayEndIsIntersection,true,scale, false);
  1764. // Rez object
  1765. InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
  1766. item = InventoryService.GetItem(item);
  1767. if (item != null)
  1768. {
  1769. AssetBase rezAsset = AssetService.Get(item.AssetID.ToString());
  1770. if (rezAsset != null)
  1771. {
  1772. UUID itemId = UUID.Zero;
  1773. // If we have permission to copy then link the rezzed object back to the user inventory
  1774. // item that it came from. This allows us to enable 'save object to inventory'
  1775. if (!Permissions.BypassPermissions())
  1776. {
  1777. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == (uint)PermissionMask.Copy)
  1778. {
  1779. itemId = item.ID;
  1780. }
  1781. }
  1782. else
  1783. {
  1784. // Brave new fullperm world
  1785. //
  1786. itemId = item.ID;
  1787. }
  1788. string xmlData = Utils.BytesToString(rezAsset.Data);
  1789. SceneObjectGroup group
  1790. = SceneObjectSerializer.FromOriginalXmlFormat(itemId, xmlData);
  1791. if (!Permissions.CanRezObject(
  1792. group.Children.Count, remoteClient.AgentId, pos)
  1793. && !attachment)
  1794. {
  1795. // The client operates in no fail mode. It will
  1796. // have already removed the item from the folder
  1797. // if it's no copy.
  1798. // Put it back if it's not an attachment
  1799. //
  1800. if (((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) && (!attachment))
  1801. remoteClient.SendBulkUpdateInventory(item);
  1802. return null;
  1803. }
  1804. group.ResetIDs();
  1805. if (attachment)
  1806. {
  1807. group.RootPart.ObjectFlags |= (uint)PrimFlags.Phantom;
  1808. group.RootPart.IsAttachment = true;
  1809. }
  1810. AddNewSceneObject(group, true);
  1811. // m_log.InfoFormat("ray end point for inventory rezz is {0} {1} {2} ", RayEnd.X, RayEnd.Y, RayEnd.Z);
  1812. // if attachment we set it's asset id so object updates can reflect that
  1813. // if not, we set it's position in world.
  1814. if (!attachment)
  1815. {
  1816. float offsetHeight = 0;
  1817. pos = GetNewRezLocation(
  1818. RayStart, RayEnd, RayTargetID, Quaternion.Identity,
  1819. BypassRayCast, bRayEndIsIntersection, true, group.GetAxisAlignedBoundingBox(out offsetHeight), false);
  1820. pos.Z += offsetHeight;
  1821. group.AbsolutePosition = pos;
  1822. // m_log.InfoFormat("rezx point for inventory rezz is {0} {1} {2} and offsetheight was {3}", pos.X, pos.Y, pos.Z, offsetHeight);
  1823. }
  1824. else
  1825. {
  1826. group.SetFromItemID(itemID);
  1827. }
  1828. SceneObjectPart rootPart = null;
  1829. try
  1830. {
  1831. rootPart = group.GetChildPart(group.UUID);
  1832. }
  1833. catch (NullReferenceException)
  1834. {
  1835. string isAttachment = "";
  1836. if (attachment)
  1837. isAttachment = " Object was an attachment";
  1838. m_log.Error("[AGENT INVENTORY]: Error rezzing ItemID: " + itemID + " object has no rootpart." + isAttachment);
  1839. }
  1840. // Since renaming the item in the inventory does not affect the name stored
  1841. // in the serialization, transfer the correct name from the inventory to the
  1842. // object itself before we rez.
  1843. rootPart.Name = item.Name;
  1844. rootPart.Description = item.Description;
  1845. List<SceneObjectPart> partList = new List<SceneObjectPart>(group.Children.Values);
  1846. group.SetGroup(remoteClient.ActiveGroupId, remoteClient);
  1847. if (rootPart.OwnerID != item.Owner)
  1848. {
  1849. //Need to kill the for sale here
  1850. rootPart.ObjectSaleType = 0;
  1851. rootPart.SalePrice = 10;
  1852. if (Permissions.PropagatePermissions())
  1853. {
  1854. if ((item.CurrentPermissions & 8) != 0)
  1855. {
  1856. foreach (SceneObjectPart part in partList)
  1857. {
  1858. part.EveryoneMask = item.EveryOnePermissions;
  1859. part.NextOwnerMask = item.NextPermissions;
  1860. part.GroupMask = 0; // DO NOT propagate here
  1861. }
  1862. }
  1863. group.ApplyNextOwnerPermissions();
  1864. }
  1865. }
  1866. foreach (SceneObjectPart part in partList)
  1867. {
  1868. if (part.OwnerID != item.Owner)
  1869. {
  1870. part.LastOwnerID = part.OwnerID;
  1871. part.OwnerID = item.Owner;
  1872. part.Inventory.ChangeInventoryOwner(item.Owner);
  1873. }
  1874. else if (((item.CurrentPermissions & 8) != 0) && (!attachment)) // Slam!
  1875. {
  1876. part.EveryoneMask = item.EveryOnePermissions;
  1877. part.NextOwnerMask = item.NextPermissions;
  1878. part.GroupMask = 0; // DO NOT propagate here
  1879. }
  1880. }
  1881. rootPart.TrimPermissions();
  1882. if (!attachment)
  1883. {
  1884. if (group.RootPart.Shape.PCode == (byte)PCode.Prim)
  1885. {
  1886. group.ClearPartAttachmentData();
  1887. }
  1888. }
  1889. if (!attachment)
  1890. {
  1891. // Fire on_rez
  1892. group.CreateScriptInstances(0, true, DefaultScriptEngine, 0);
  1893. rootPart.ScheduleFullUpdate();
  1894. }
  1895. if (!Permissions.BypassPermissions())
  1896. {
  1897. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  1898. {
  1899. // If this is done on attachments, no
  1900. // copy ones will be lost, so avoid it
  1901. //
  1902. if (!attachment)
  1903. {
  1904. List<UUID> uuids = new List<UUID>();
  1905. uuids.Add(item.ID);
  1906. InventoryService.DeleteItems(item.Owner, uuids);
  1907. }
  1908. }
  1909. }
  1910. return rootPart.ParentGroup;
  1911. }
  1912. }
  1913. return null;
  1914. }
  1915. /// <summary>
  1916. /// Rez an object into the scene from a prim's inventory.
  1917. /// </summary>
  1918. /// <param name="sourcePart"></param>
  1919. /// <param name="item"></param>
  1920. /// <param name="pos"></param>
  1921. /// <param name="rot"></param>
  1922. /// <param name="vel"></param>
  1923. /// <param name="param"></param>
  1924. /// <returns>The SceneObjectGroup rezzed or null if rez was unsuccessful</returns>
  1925. public virtual SceneObjectGroup RezObject(
  1926. SceneObjectPart sourcePart, TaskInventoryItem item,
  1927. Vector3 pos, Quaternion rot, Vector3 vel, int param)
  1928. {
  1929. // Rez object
  1930. if (item != null)
  1931. {
  1932. UUID ownerID = item.OwnerID;
  1933. AssetBase rezAsset = AssetService.Get(item.AssetID.ToString());
  1934. if (rezAsset != null)
  1935. {
  1936. string xmlData = Utils.BytesToString(rezAsset.Data);
  1937. SceneObjectGroup group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
  1938. if (!Permissions.CanRezObject(group.Children.Count, ownerID, pos))
  1939. {
  1940. return null;
  1941. }
  1942. group.ResetIDs();
  1943. AddNewSceneObject(group, true);
  1944. // we set it's position in world.
  1945. group.AbsolutePosition = pos;
  1946. SceneObjectPart rootPart = group.GetChildPart(group.UUID);
  1947. // Since renaming the item in the inventory does not affect the name stored
  1948. // in the serialization, transfer the correct name from the inventory to the
  1949. // object itself before we rez.
  1950. rootPart.Name = item.Name;
  1951. rootPart.Description = item.Description;
  1952. List<SceneObjectPart> partList = new List<SceneObjectPart>(group.Children.Values);
  1953. group.SetGroup(sourcePart.GroupID, null);
  1954. if (rootPart.OwnerID != item.OwnerID)
  1955. {
  1956. if (Permissions.PropagatePermissions())
  1957. {
  1958. if ((item.CurrentPermissions & 8) != 0)
  1959. {
  1960. foreach (SceneObjectPart part in partList)
  1961. {
  1962. part.EveryoneMask = item.EveryonePermissions;
  1963. part.NextOwnerMask = item.NextPermissions;
  1964. }
  1965. }
  1966. group.ApplyNextOwnerPermissions();
  1967. }
  1968. }
  1969. foreach (SceneObjectPart part in partList)
  1970. {
  1971. if (part.OwnerID != item.OwnerID)
  1972. {
  1973. part.LastOwnerID = part.OwnerID;
  1974. part.OwnerID = item.OwnerID;
  1975. part.Inventory.ChangeInventoryOwner(item.OwnerID);
  1976. }
  1977. else if ((item.CurrentPermissions & 8) != 0) // Slam!
  1978. {
  1979. part.EveryoneMask = item.EveryonePermissions;
  1980. part.NextOwnerMask = item.NextPermissions;
  1981. }
  1982. }
  1983. rootPart.TrimPermissions();
  1984. if (group.RootPart.Shape.PCode == (byte)PCode.Prim)
  1985. {
  1986. group.ClearPartAttachmentData();
  1987. }
  1988. group.UpdateGroupRotationR(rot);
  1989. //group.ApplyPhysics(m_physicalPrim);
  1990. if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical && vel != Vector3.Zero)
  1991. {
  1992. group.RootPart.ApplyImpulse((vel * group.GetMass()), false);
  1993. group.Velocity = vel;
  1994. rootPart.ScheduleFullUpdate();
  1995. }
  1996. group.CreateScriptInstances(param, true, DefaultScriptEngine, 2);
  1997. rootPart.ScheduleFullUpdate();
  1998. if (!Permissions.BypassPermissions())
  1999. {
  2000. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  2001. sourcePart.Inventory.RemoveInventoryItem(item.ItemID);
  2002. }
  2003. return rootPart.ParentGroup;
  2004. }
  2005. }
  2006. return null;
  2007. }
  2008. public virtual bool returnObjects(SceneObjectGroup[] returnobjects, UUID AgentId)
  2009. {
  2010. foreach (SceneObjectGroup grp in returnobjects)
  2011. {
  2012. AddReturn(grp.OwnerID, grp.Name, grp.AbsolutePosition, "parcel owner return");
  2013. DeRezObject(null, grp.RootPart.LocalId,
  2014. grp.RootPart.GroupID, DeRezAction.Return, UUID.Zero);
  2015. }
  2016. return true;
  2017. }
  2018. public void SetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID, bool running)
  2019. {
  2020. SceneObjectPart part = GetSceneObjectPart(objectID);
  2021. if (part == null)
  2022. return;
  2023. if (running)
  2024. EventManager.TriggerStartScript(part.LocalId, itemID);
  2025. else
  2026. EventManager.TriggerStopScript(part.LocalId, itemID);
  2027. }
  2028. internal void SendAttachEvent(uint localID, UUID itemID, UUID avatarID)
  2029. {
  2030. EventManager.TriggerOnAttach(localID, itemID, avatarID);
  2031. }
  2032. public UUID RezSingleAttachment(IClientAPI remoteClient, UUID itemID,
  2033. uint AttachmentPt)
  2034. {
  2035. SceneObjectGroup att = m_sceneGraph.RezSingleAttachment(remoteClient, itemID, AttachmentPt);
  2036. if (att == null)
  2037. {
  2038. DetachSingleAttachmentToInv(itemID, remoteClient);
  2039. return UUID.Zero;
  2040. }
  2041. return RezSingleAttachment(att, remoteClient, itemID, AttachmentPt);
  2042. }
  2043. public UUID RezSingleAttachment(SceneObjectGroup att,
  2044. IClientAPI remoteClient, UUID itemID, uint AttachmentPt)
  2045. {
  2046. if (!att.IsDeleted)
  2047. AttachmentPt = att.RootPart.AttachmentPoint;
  2048. ScenePresence presence;
  2049. if (TryGetAvatar(remoteClient.AgentId, out presence))
  2050. {
  2051. InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
  2052. item = InventoryService.GetItem(item);
  2053. presence.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID /*att.UUID*/);
  2054. }
  2055. return att.UUID;
  2056. }
  2057. public void RezMultipleAttachments(IClientAPI remoteClient, RezMultipleAttachmentsFromInvPacket.HeaderDataBlock header,
  2058. RezMultipleAttachmentsFromInvPacket.ObjectDataBlock[] objects)
  2059. {
  2060. foreach (RezMultipleAttachmentsFromInvPacket.ObjectDataBlock obj in objects)
  2061. {
  2062. RezSingleAttachment(remoteClient, obj.ItemID, obj.AttachmentPt);
  2063. }
  2064. }
  2065. public void AttachObject(IClientAPI controllingClient, uint localID, uint attachPoint, Quaternion rot, Vector3 pos, bool silent)
  2066. {
  2067. m_sceneGraph.AttachObject(controllingClient, localID, attachPoint, rot, pos, silent);
  2068. }
  2069. public void AttachObject(IClientAPI remoteClient, uint AttachmentPt, UUID itemID, SceneObjectGroup att)
  2070. {
  2071. if (UUID.Zero == itemID)
  2072. {
  2073. m_log.Error("[SCENE INVENTORY]: Unable to save attachment. Error inventory item ID.");
  2074. return;
  2075. }
  2076. if (0 == AttachmentPt)
  2077. {
  2078. m_log.Error("[SCENE INVENTORY]: Unable to save attachment. Error attachment point.");
  2079. return;
  2080. }
  2081. if (null == att.RootPart)
  2082. {
  2083. m_log.Error("[SCENE INVENTORY]: Unable to save attachment for a prim without the rootpart!");
  2084. return;
  2085. }
  2086. ScenePresence presence;
  2087. if (TryGetAvatar(remoteClient.AgentId, out presence))
  2088. {
  2089. // XXYY!!
  2090. InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
  2091. item = InventoryService.GetItem(item);
  2092. presence.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID /*att.UUID*/);
  2093. if (m_AvatarFactory != null)
  2094. {
  2095. m_AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
  2096. }
  2097. }
  2098. }
  2099. public void DetachSingleAttachmentToGround(UUID itemID, IClientAPI remoteClient)
  2100. {
  2101. SceneObjectPart part = GetSceneObjectPart(itemID);
  2102. if (part == null || part.ParentGroup == null)
  2103. return;
  2104. UUID inventoryID = part.ParentGroup.GetFromItemID();
  2105. ScenePresence presence;
  2106. if (TryGetAvatar(remoteClient.AgentId, out presence))
  2107. {
  2108. if (!Permissions.CanRezObject(part.ParentGroup.Children.Count, remoteClient.AgentId, presence.AbsolutePosition))
  2109. return;
  2110. presence.Appearance.DetachAttachment(itemID);
  2111. IAvatarFactory ava = RequestModuleInterface<IAvatarFactory>();
  2112. if (ava != null)
  2113. {
  2114. ava.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
  2115. }
  2116. part.ParentGroup.DetachToGround();
  2117. List<UUID> uuids = new List<UUID>();
  2118. uuids.Add(inventoryID);
  2119. InventoryService.DeleteItems(remoteClient.AgentId, uuids);
  2120. remoteClient.SendRemoveInventoryItem(inventoryID);
  2121. }
  2122. SendAttachEvent(part.ParentGroup.LocalId, itemID, UUID.Zero);
  2123. }
  2124. public void DetachSingleAttachmentToInv(UUID itemID, IClientAPI remoteClient)
  2125. {
  2126. ScenePresence presence;
  2127. if (TryGetAvatar(remoteClient.AgentId, out presence))
  2128. {
  2129. presence.Appearance.DetachAttachment(itemID);
  2130. // Save avatar attachment information
  2131. if (m_AvatarFactory != null)
  2132. {
  2133. m_log.Info("[SCENE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId + ", ItemID: " + itemID);
  2134. m_AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
  2135. }
  2136. }
  2137. m_sceneGraph.DetachSingleAttachmentToInv(itemID, remoteClient);
  2138. }
  2139. public void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID)
  2140. {
  2141. EventManager.TriggerGetScriptRunning(controllingClient, objectID, itemID);
  2142. }
  2143. void ObjectOwner(IClientAPI remoteClient, UUID ownerID, UUID groupID, List<uint> localIDs)
  2144. {
  2145. if (!Permissions.IsGod(remoteClient.AgentId))
  2146. {
  2147. if (ownerID != UUID.Zero)
  2148. return;
  2149. if (!Permissions.CanDeedObject(remoteClient.AgentId, groupID))
  2150. return;
  2151. }
  2152. List<SceneObjectGroup> groups = new List<SceneObjectGroup>();
  2153. foreach (uint localID in localIDs)
  2154. {
  2155. SceneObjectPart part = GetSceneObjectPart(localID);
  2156. if (!groups.Contains(part.ParentGroup))
  2157. groups.Add(part.ParentGroup);
  2158. }
  2159. foreach (SceneObjectGroup sog in groups)
  2160. {
  2161. if (ownerID != UUID.Zero)
  2162. {
  2163. sog.SetOwnerId(ownerID);
  2164. sog.SetGroup(groupID, remoteClient);
  2165. foreach (SceneObjectPart child in sog.Children.Values)
  2166. child.Inventory.ChangeInventoryOwner(ownerID);
  2167. }
  2168. else
  2169. {
  2170. if (!Permissions.CanEditObject(sog.UUID, remoteClient.AgentId))
  2171. continue;
  2172. if (sog.GroupID != groupID)
  2173. continue;
  2174. foreach (SceneObjectPart child in sog.Children.Values)
  2175. {
  2176. child.LastOwnerID = child.OwnerID;
  2177. child.Inventory.ChangeInventoryOwner(groupID);
  2178. }
  2179. sog.SetOwnerId(groupID);
  2180. sog.ApplyNextOwnerPermissions();
  2181. }
  2182. }
  2183. foreach (uint localID in localIDs)
  2184. {
  2185. SceneObjectPart part = GetSceneObjectPart(localID);
  2186. part.GetProperties(remoteClient);
  2187. }
  2188. }
  2189. }
  2190. }