1
0

Scene.Inventory.cs 103 KB

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