Scene.Inventory.cs 111 KB

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