Scene.Inventory.cs 107 KB

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