Scene.Inventory.cs 110 KB

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