Scene.Inventory.cs 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Collections;
  30. using System.Reflection;
  31. using System.Text;
  32. using System.Timers;
  33. using OpenMetaverse;
  34. using OpenMetaverse.Packets;
  35. using log4net;
  36. using OpenSim.Framework;
  37. using OpenSim.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. /// Allows inventory details to be sent to clients asynchronously
  52. /// </summary>
  53. protected AsyncInventorySender m_asyncInventorySender;
  54. /// <summary>
  55. /// Creates all the scripts in the scene which should be started.
  56. /// </summary>
  57. /// <returns>
  58. /// Number of scripts that were valid for starting. This does not guarantee that all these scripts
  59. /// were actually started, but just that the start could be attempt (e.g. the asset data for the script could be found)
  60. /// </returns>
  61. public int CreateScriptInstances()
  62. {
  63. m_log.InfoFormat("[SCENE]: Initializing script instances in {0}", RegionInfo.RegionName);
  64. int scriptsValidForStarting = 0;
  65. EntityBase[] entities = Entities.GetEntities();
  66. foreach (EntityBase group in entities)
  67. {
  68. if (group is SceneObjectGroup)
  69. {
  70. scriptsValidForStarting
  71. += ((SceneObjectGroup) group).CreateScriptInstances(0, false, DefaultScriptEngine, 0);
  72. ((SceneObjectGroup) group).ResumeScripts();
  73. }
  74. }
  75. m_log.InfoFormat(
  76. "[SCENE]: Initialized {0} script instances in {1}",
  77. scriptsValidForStarting, RegionInfo.RegionName);
  78. return scriptsValidForStarting;
  79. }
  80. /// <summary>
  81. /// Lets the script engines start processing scripts.
  82. /// </summary>
  83. public void StartScripts()
  84. {
  85. m_log.InfoFormat("[SCENE]: Starting scripts in {0}, please wait.", RegionInfo.RegionName);
  86. IScriptModule[] engines = RequestModuleInterfaces<IScriptModule>();
  87. foreach (IScriptModule engine in engines)
  88. engine.StartProcessing();
  89. }
  90. public void AddUploadedInventoryItem(UUID agentID, InventoryItemBase item)
  91. {
  92. IMoneyModule money = RequestModuleInterface<IMoneyModule>();
  93. if (money != null)
  94. {
  95. money.ApplyUploadCharge(agentID, money.UploadCharge, "Asset upload");
  96. }
  97. AddInventoryItem(item);
  98. }
  99. public bool AddInventoryItemReturned(UUID AgentId, InventoryItemBase item)
  100. {
  101. if (AddInventoryItem(item))
  102. return true;
  103. else
  104. {
  105. m_log.WarnFormat(
  106. "[AGENT INVENTORY]: Unable to add item {1} to agent {2} inventory", item.Name, AgentId);
  107. return false;
  108. }
  109. }
  110. /// <summary>
  111. /// Add the given inventory item to a user's inventory.
  112. /// </summary>
  113. /// <param name="item"></param>
  114. public bool AddInventoryItem(InventoryItemBase item)
  115. {
  116. if (UUID.Zero == item.Folder)
  117. {
  118. InventoryFolderBase f = InventoryService.GetFolderForType(item.Owner, (AssetType)item.AssetType);
  119. if (f != null)
  120. {
  121. // m_log.DebugFormat(
  122. // "[LOCAL INVENTORY SERVICES CONNECTOR]: Found folder {0} type {1} for item {2}",
  123. // f.Name, (AssetType)f.Type, item.Name);
  124. item.Folder = f.ID;
  125. }
  126. else
  127. {
  128. f = InventoryService.GetRootFolder(item.Owner);
  129. if (f != null)
  130. {
  131. item.Folder = f.ID;
  132. }
  133. else
  134. {
  135. m_log.WarnFormat(
  136. "[AGENT INVENTORY]: Could not find root folder for {0} when trying to add item {1} with no parent folder specified",
  137. item.Owner, item.Name);
  138. return false;
  139. }
  140. }
  141. }
  142. if (InventoryService.AddItem(item))
  143. {
  144. int userlevel = 0;
  145. if (Permissions.IsGod(item.Owner))
  146. {
  147. userlevel = 1;
  148. }
  149. EventManager.TriggerOnNewInventoryItemUploadComplete(item.Owner, item.AssetID, item.Name, userlevel);
  150. return true;
  151. }
  152. else
  153. {
  154. m_log.WarnFormat(
  155. "[AGENT INVENTORY]: Agent {0} could not add item {1} {2}",
  156. item.Owner, item.Name, item.ID);
  157. return false;
  158. }
  159. }
  160. /// <summary>
  161. /// Add the given inventory item to a user's inventory.
  162. /// </summary>
  163. /// <param name="AgentID">
  164. /// A <see cref="UUID"/>
  165. /// </param>
  166. /// <param name="item">
  167. /// A <see cref="InventoryItemBase"/>
  168. /// </param>
  169. [Obsolete("Use AddInventoryItem(InventoryItemBase item) instead. This was deprecated in OpenSim 0.7.1")]
  170. public void AddInventoryItem(UUID AgentID, InventoryItemBase item)
  171. {
  172. AddInventoryItem(item);
  173. }
  174. /// <summary>
  175. /// Add an inventory item to an avatar's inventory.
  176. /// </summary>
  177. /// <param name="remoteClient">The remote client controlling the avatar</param>
  178. /// <param name="item">The item. This structure contains all the item metadata, including the folder
  179. /// in which the item is to be placed.</param>
  180. public void AddInventoryItem(IClientAPI remoteClient, InventoryItemBase item)
  181. {
  182. AddInventoryItem(item);
  183. remoteClient.SendInventoryItemCreateUpdate(item, 0);
  184. }
  185. /// <summary>
  186. /// <see>CapsUpdatedInventoryItemAsset(IClientAPI, UUID, byte[])</see>
  187. /// </summary>
  188. public UUID CapsUpdateInventoryItemAsset(UUID avatarId, UUID itemID, byte[] data)
  189. {
  190. ScenePresence avatar;
  191. if (TryGetScenePresence(avatarId, out avatar))
  192. {
  193. IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
  194. if (invAccess != null)
  195. return invAccess.CapsUpdateInventoryItemAsset(avatar.ControllingClient, itemID, data);
  196. }
  197. else
  198. {
  199. m_log.ErrorFormat(
  200. "[AGENT INVENTORY]: " +
  201. "Avatar {0} cannot be found to update its inventory item asset",
  202. avatarId);
  203. }
  204. return UUID.Zero;
  205. }
  206. /// <summary>
  207. /// Capability originating call to update the asset of a script in a prim's (task's) inventory
  208. /// </summary>
  209. /// <param name="remoteClient"></param>
  210. /// <param name="itemID"></param>
  211. /// <param name="primID">The prim which contains the item to update</param>
  212. /// <param name="isScriptRunning">Indicates whether the script to update is currently running</param>
  213. /// <param name="data"></param>
  214. public ArrayList CapsUpdateTaskInventoryScriptAsset(IClientAPI remoteClient, UUID itemId,
  215. UUID primId, bool isScriptRunning, byte[] data)
  216. {
  217. if (!Permissions.CanEditScript(itemId, primId, remoteClient.AgentId))
  218. {
  219. remoteClient.SendAgentAlertMessage("Insufficient permissions to edit script", false);
  220. return new ArrayList();
  221. }
  222. // Retrieve group
  223. SceneObjectPart part = GetSceneObjectPart(primId);
  224. if (part == null)
  225. return new ArrayList();
  226. SceneObjectGroup group = part.ParentGroup;
  227. // Retrieve item
  228. TaskInventoryItem item = group.GetInventoryItem(part.LocalId, itemId);
  229. if (null == item)
  230. {
  231. m_log.ErrorFormat(
  232. "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for caps script update "
  233. + " but the item does not exist in this inventory",
  234. itemId, part.Name, part.UUID);
  235. return new ArrayList();
  236. }
  237. AssetBase asset = CreateAsset(item.Name, item.Description, (sbyte)AssetType.LSLText, data, remoteClient.AgentId);
  238. AssetService.Store(asset);
  239. // m_log.DebugFormat(
  240. // "[PRIM INVENTORY]: Stored asset {0} when updating item {1} in prim {2} for {3}",
  241. // asset.ID, item.Name, part.Name, remoteClient.Name);
  242. if (isScriptRunning)
  243. {
  244. part.Inventory.RemoveScriptInstance(item.ItemID, false);
  245. }
  246. // Update item with new asset
  247. item.AssetID = asset.FullID;
  248. if (group.UpdateInventoryItem(item))
  249. remoteClient.SendAgentAlertMessage("Script saved", false);
  250. part.SendPropertiesToClient(remoteClient);
  251. // Trigger rerunning of script (use TriggerRezScript event, see RezScript)
  252. ArrayList errors = new ArrayList();
  253. if (isScriptRunning)
  254. {
  255. // Needs to determine which engine was running it and use that
  256. //
  257. part.Inventory.CreateScriptInstance(item.ItemID, 0, false, DefaultScriptEngine, 0);
  258. errors = part.Inventory.GetScriptErrors(item.ItemID);
  259. }
  260. else
  261. {
  262. remoteClient.SendAgentAlertMessage("Script saved", false);
  263. }
  264. // Tell anyone managing scripts that a script has been reloaded/changed
  265. EventManager.TriggerUpdateScript(remoteClient.AgentId, itemId, primId, isScriptRunning, item.AssetID);
  266. part.ParentGroup.ResumeScripts();
  267. return errors;
  268. }
  269. /// <summary>
  270. /// <see>CapsUpdateTaskInventoryScriptAsset(IClientAPI, UUID, UUID, bool, byte[])</see>
  271. /// </summary>
  272. public ArrayList CapsUpdateTaskInventoryScriptAsset(UUID avatarId, UUID itemId,
  273. UUID primId, bool isScriptRunning, byte[] data)
  274. {
  275. ScenePresence avatar;
  276. if (TryGetScenePresence(avatarId, out avatar))
  277. {
  278. return CapsUpdateTaskInventoryScriptAsset(
  279. avatar.ControllingClient, itemId, primId, isScriptRunning, data);
  280. }
  281. else
  282. {
  283. m_log.ErrorFormat(
  284. "[PRIM INVENTORY]: " +
  285. "Avatar {0} cannot be found to update its prim item asset",
  286. avatarId);
  287. return new ArrayList();
  288. }
  289. }
  290. /// <summary>
  291. /// Update an item which is either already in the client's inventory or is within
  292. /// a transaction
  293. /// </summary>
  294. /// <param name="remoteClient"></param>
  295. /// <param name="transactionID">The transaction ID. If this is UUID.Zero we will
  296. /// assume that we are not in a transaction</param>
  297. /// <param name="itemID">The ID of the updated item</param>
  298. /// <param name="name">The name of the updated item</param>
  299. /// <param name="description">The description of the updated item</param>
  300. /// <param name="nextOwnerMask">The permissions of the updated item</param>
  301. /* public void UpdateInventoryItemAsset(IClientAPI remoteClient, UUID transactionID,
  302. UUID itemID, string name, string description,
  303. uint nextOwnerMask)*/
  304. public void UpdateInventoryItemAsset(IClientAPI remoteClient, UUID transactionID,
  305. UUID itemID, InventoryItemBase itemUpd)
  306. {
  307. // m_log.DebugFormat(
  308. // "[USER INVENTORY]: Updating asset for item {0} {1}, transaction ID {2} for {3}",
  309. // itemID, itemUpd.Name, transactionID, remoteClient.Name);
  310. // This one will let people set next perms on items in agent
  311. // inventory. Rut-Roh. Whatever. Make this secure. Yeah.
  312. //
  313. // Passing something to another avatar or a an object will already
  314. InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
  315. item = InventoryService.GetItem(item);
  316. if (item != null)
  317. {
  318. if (item.Owner != remoteClient.AgentId)
  319. return;
  320. if (UUID.Zero == transactionID)
  321. {
  322. item.Name = itemUpd.Name;
  323. item.Description = itemUpd.Description;
  324. // m_log.DebugFormat(
  325. // "[USER INVENTORY]: itemUpd {0} {1} {2} {3}, item {4} {5} {6} {7}",
  326. // itemUpd.NextPermissions, itemUpd.GroupPermissions, itemUpd.EveryOnePermissions, item.Flags,
  327. // item.NextPermissions, item.GroupPermissions, item.EveryOnePermissions, item.CurrentPermissions);
  328. if (item.NextPermissions != (itemUpd.NextPermissions & item.BasePermissions))
  329. item.Flags |= (uint)InventoryItemFlags.ObjectOverwriteNextOwner;
  330. item.NextPermissions = itemUpd.NextPermissions & item.BasePermissions;
  331. if (item.EveryOnePermissions != (itemUpd.EveryOnePermissions & item.BasePermissions))
  332. item.Flags |= (uint)InventoryItemFlags.ObjectOverwriteEveryone;
  333. item.EveryOnePermissions = itemUpd.EveryOnePermissions & item.BasePermissions;
  334. if (item.GroupPermissions != (itemUpd.GroupPermissions & item.BasePermissions))
  335. item.Flags |= (uint)InventoryItemFlags.ObjectOverwriteGroup;
  336. // m_log.DebugFormat("[USER INVENTORY]: item.Flags {0}", item.Flags);
  337. item.GroupPermissions = itemUpd.GroupPermissions & item.BasePermissions;
  338. item.GroupID = itemUpd.GroupID;
  339. item.GroupOwned = itemUpd.GroupOwned;
  340. item.CreationDate = itemUpd.CreationDate;
  341. // The client sends zero if its newly created?
  342. if (itemUpd.CreationDate == 0)
  343. item.CreationDate = Util.UnixTimeSinceEpoch();
  344. else
  345. item.CreationDate = itemUpd.CreationDate;
  346. // TODO: Check if folder changed and move item
  347. //item.NextPermissions = itemUpd.Folder;
  348. item.InvType = itemUpd.InvType;
  349. if (item.SalePrice != itemUpd.SalePrice ||
  350. item.SaleType != itemUpd.SaleType)
  351. item.Flags |= (uint)InventoryItemFlags.ObjectSlamSale;
  352. item.SalePrice = itemUpd.SalePrice;
  353. item.SaleType = itemUpd.SaleType;
  354. InventoryService.UpdateItem(item);
  355. }
  356. else
  357. {
  358. if (AgentTransactionsModule != null)
  359. {
  360. AgentTransactionsModule.HandleItemUpdateFromTransaction(remoteClient, transactionID, item);
  361. }
  362. }
  363. }
  364. else
  365. {
  366. m_log.ErrorFormat(
  367. "[AGENTINVENTORY]: Item id {0} not found for an inventory item update for {1}.",
  368. itemID, remoteClient.Name);
  369. }
  370. }
  371. /// <summary>
  372. /// Give an inventory item from one user to another
  373. /// </summary>
  374. /// <param name="recipientClient"></param>
  375. /// <param name="senderId">ID of the sender of the item</param>
  376. /// <param name="itemId"></param>
  377. public virtual void GiveInventoryItem(IClientAPI recipientClient, UUID senderId, UUID itemId)
  378. {
  379. InventoryItemBase itemCopy = GiveInventoryItem(recipientClient.AgentId, senderId, itemId);
  380. if (itemCopy != null)
  381. recipientClient.SendBulkUpdateInventory(itemCopy);
  382. }
  383. /// <summary>
  384. /// Give an inventory item from one user to another
  385. /// </summary>
  386. /// <param name="recipient"></param>
  387. /// <param name="senderId">ID of the sender of the item</param>
  388. /// <param name="itemId"></param>
  389. /// <returns>The inventory item copy given, null if the give was unsuccessful</returns>
  390. public virtual InventoryItemBase GiveInventoryItem(UUID recipient, UUID senderId, UUID itemId)
  391. {
  392. return GiveInventoryItem(recipient, senderId, itemId, UUID.Zero);
  393. }
  394. /// <summary>
  395. /// Give an inventory item from one user to another
  396. /// </summary>
  397. /// <param name="recipient"></param>
  398. /// <param name="senderId">ID of the sender of the item</param>
  399. /// <param name="itemId"></param>
  400. /// <param name="recipientFolderId">
  401. /// The id of the folder in which the copy item should go. If UUID.Zero then the item is placed in the most
  402. /// appropriate default folder.
  403. /// </param>
  404. /// <returns>
  405. /// The inventory item copy given, null if the give was unsuccessful
  406. /// </returns>
  407. public virtual InventoryItemBase GiveInventoryItem(
  408. UUID recipient, UUID senderId, UUID itemId, UUID recipientFolderId)
  409. {
  410. //Console.WriteLine("Scene.Inventory.cs: GiveInventoryItem");
  411. InventoryItemBase item = new InventoryItemBase(itemId, senderId);
  412. item = InventoryService.GetItem(item);
  413. if (item == null)
  414. {
  415. m_log.WarnFormat(
  416. "[AGENT INVENTORY]: Failed to find item {0} sent by {1} to {2}", itemId, senderId, recipient);
  417. return null;
  418. }
  419. if (item.Owner != senderId)
  420. {
  421. m_log.WarnFormat(
  422. "[AGENT INVENTORY]: Attempt to send item {0} {1} to {2} failed because sender {3} did not match item owner {4}",
  423. item.Name, item.ID, recipient, senderId, item.Owner);
  424. return null;
  425. }
  426. IUserManagement uman = RequestModuleInterface<IUserManagement>();
  427. if (uman != null)
  428. uman.AddUser(item.CreatorIdAsUuid, item.CreatorData);
  429. if (!Permissions.BypassPermissions())
  430. {
  431. if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
  432. return null;
  433. }
  434. // Insert a copy of the item into the recipient
  435. InventoryItemBase itemCopy = new InventoryItemBase();
  436. itemCopy.Owner = recipient;
  437. itemCopy.CreatorId = item.CreatorId;
  438. itemCopy.CreatorData = item.CreatorData;
  439. itemCopy.ID = UUID.Random();
  440. itemCopy.AssetID = item.AssetID;
  441. itemCopy.Description = item.Description;
  442. itemCopy.Name = item.Name;
  443. itemCopy.AssetType = item.AssetType;
  444. itemCopy.InvType = item.InvType;
  445. itemCopy.Folder = recipientFolderId;
  446. if (Permissions.PropagatePermissions() && recipient != senderId)
  447. {
  448. // Trying to do this right this time. This is evil. If
  449. // you believe in Good, go elsewhere. Vampires and other
  450. // evil creatores only beyond this point. You have been
  451. // warned.
  452. // We're going to mask a lot of things by the next perms
  453. // Tweak the next perms to be nicer to our data
  454. //
  455. // In this mask, all the bits we do NOT want to mess
  456. // with are set. These are:
  457. //
  458. // Transfer
  459. // Copy
  460. // Modufy
  461. uint permsMask = ~ ((uint)PermissionMask.Copy |
  462. (uint)PermissionMask.Transfer |
  463. (uint)PermissionMask.Modify);
  464. // Now, reduce the next perms to the mask bits
  465. // relevant to the operation
  466. uint nextPerms = permsMask | (item.NextPermissions &
  467. ((uint)PermissionMask.Copy |
  468. (uint)PermissionMask.Transfer |
  469. (uint)PermissionMask.Modify));
  470. // nextPerms now has all bits set, except for the actual
  471. // next permission bits.
  472. // This checks for no mod, no copy, no trans.
  473. // This indicates an error or messed up item. Do it like
  474. // SL and assume trans
  475. if (nextPerms == permsMask)
  476. nextPerms |= (uint)PermissionMask.Transfer;
  477. // Inventory owner perms are the logical AND of the
  478. // folded perms and the root prim perms, however, if
  479. // the root prim is mod, the inventory perms will be
  480. // mod. This happens on "take" and is of little concern
  481. // here, save for preventing escalation
  482. // This hack ensures that items previously permalocked
  483. // get unlocked when they're passed or rezzed
  484. uint basePerms = item.BasePermissions |
  485. (uint)PermissionMask.Move;
  486. uint ownerPerms = item.CurrentPermissions;
  487. // If this is an object, root prim perms may be more
  488. // permissive than folded perms. Use folded perms as
  489. // a mask
  490. if (item.InvType == (int)InventoryType.Object)
  491. {
  492. // Create a safe mask for the current perms
  493. uint foldedPerms = (item.CurrentPermissions & 7) << 13;
  494. foldedPerms |= permsMask;
  495. bool isRootMod = (item.CurrentPermissions &
  496. (uint)PermissionMask.Modify) != 0 ?
  497. true : false;
  498. // Mask the owner perms to the folded perms
  499. ownerPerms &= foldedPerms;
  500. basePerms &= foldedPerms;
  501. // If the root was mod, let the mask reflect that
  502. // We also need to adjust the base here, because
  503. // we should be able to edit in-inventory perms
  504. // for the root prim, if it's mod.
  505. if (isRootMod)
  506. {
  507. ownerPerms |= (uint)PermissionMask.Modify;
  508. basePerms |= (uint)PermissionMask.Modify;
  509. }
  510. }
  511. // These will be applied to the root prim at next rez.
  512. // The slam bit (bit 3) and folded permission (bits 0-2)
  513. // are preserved due to the above mangling
  514. ownerPerms &= nextPerms;
  515. // Mask the base permissions. This is a conservative
  516. // approach altering only the three main perms
  517. basePerms &= nextPerms;
  518. // Assign to the actual item. Make sure the slam bit is
  519. // set, if it wasn't set before.
  520. itemCopy.BasePermissions = basePerms;
  521. itemCopy.CurrentPermissions = ownerPerms;
  522. itemCopy.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm;
  523. itemCopy.NextPermissions = item.NextPermissions;
  524. // This preserves "everyone can move"
  525. itemCopy.EveryOnePermissions = item.EveryOnePermissions &
  526. nextPerms;
  527. // Intentionally killing "share with group" here, as
  528. // the recipient will not have the group this is
  529. // set to
  530. itemCopy.GroupPermissions = 0;
  531. }
  532. else
  533. {
  534. itemCopy.CurrentPermissions = item.CurrentPermissions;
  535. itemCopy.NextPermissions = item.NextPermissions;
  536. itemCopy.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions;
  537. itemCopy.GroupPermissions = item.GroupPermissions & item.NextPermissions;
  538. itemCopy.BasePermissions = item.BasePermissions;
  539. }
  540. if (itemCopy.Folder == UUID.Zero)
  541. {
  542. InventoryFolderBase folder = InventoryService.GetFolderForType(recipient, (AssetType)itemCopy.AssetType);
  543. if (folder != null)
  544. {
  545. itemCopy.Folder = folder.ID;
  546. }
  547. else
  548. {
  549. InventoryFolderBase root = InventoryService.GetRootFolder(recipient);
  550. if (root != null)
  551. itemCopy.Folder = root.ID;
  552. else
  553. return null; // No destination
  554. }
  555. }
  556. itemCopy.GroupID = UUID.Zero;
  557. itemCopy.GroupOwned = false;
  558. itemCopy.Flags = item.Flags;
  559. itemCopy.SalePrice = item.SalePrice;
  560. itemCopy.SaleType = item.SaleType;
  561. if (AddInventoryItem(itemCopy))
  562. {
  563. IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
  564. if (invAccess != null)
  565. invAccess.TransferInventoryAssets(itemCopy, senderId, recipient);
  566. }
  567. if (!Permissions.BypassPermissions())
  568. {
  569. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  570. {
  571. List<UUID> items = new List<UUID>();
  572. items.Add(itemId);
  573. InventoryService.DeleteItems(senderId, items);
  574. }
  575. }
  576. return itemCopy;
  577. }
  578. /// <summary>
  579. /// Give an entire inventory folder from one user to another. The entire contents (including all descendent
  580. /// folders) is given.
  581. /// </summary>
  582. /// <param name="recipientId"></param>
  583. /// <param name="senderId">ID of the sender of the item</param>
  584. /// <param name="folderId"></param>
  585. /// <param name="recipientParentFolderId">
  586. /// The id of the receipient folder in which the send folder should be placed. If UUID.Zero then the
  587. /// recipient folder is the root folder
  588. /// </param>
  589. /// <returns>
  590. /// The inventory folder copy given, null if the copy was unsuccessful
  591. /// </returns>
  592. public virtual InventoryFolderBase GiveInventoryFolder(
  593. UUID recipientId, UUID senderId, UUID folderId, UUID recipientParentFolderId)
  594. {
  595. //// Retrieve the folder from the sender
  596. InventoryFolderBase folder = InventoryService.GetFolder(new InventoryFolderBase(folderId));
  597. if (null == folder)
  598. {
  599. m_log.ErrorFormat(
  600. "[AGENT INVENTORY]: Could not find inventory folder {0} to give", folderId);
  601. return null;
  602. }
  603. if (recipientParentFolderId == UUID.Zero)
  604. {
  605. InventoryFolderBase recipientRootFolder = InventoryService.GetRootFolder(recipientId);
  606. if (recipientRootFolder != null)
  607. recipientParentFolderId = recipientRootFolder.ID;
  608. else
  609. {
  610. m_log.WarnFormat("[AGENT INVENTORY]: Unable to find root folder for receiving agent");
  611. return null;
  612. }
  613. }
  614. UUID newFolderId = UUID.Random();
  615. InventoryFolderBase newFolder
  616. = new InventoryFolderBase(
  617. newFolderId, folder.Name, recipientId, folder.Type, recipientParentFolderId, folder.Version);
  618. InventoryService.AddFolder(newFolder);
  619. // Give all the subfolders
  620. InventoryCollection contents = InventoryService.GetFolderContent(senderId, folderId);
  621. foreach (InventoryFolderBase childFolder in contents.Folders)
  622. {
  623. GiveInventoryFolder(recipientId, senderId, childFolder.ID, newFolder.ID);
  624. }
  625. // Give all the items
  626. foreach (InventoryItemBase item in contents.Items)
  627. {
  628. GiveInventoryItem(recipientId, senderId, item.ID, newFolder.ID);
  629. }
  630. return newFolder;
  631. }
  632. public void CopyInventoryItem(IClientAPI remoteClient, uint callbackID, UUID oldAgentID, UUID oldItemID,
  633. UUID newFolderID, string newName)
  634. {
  635. m_log.DebugFormat(
  636. "[AGENT INVENTORY]: CopyInventoryItem received by {0} with oldAgentID {1}, oldItemID {2}, new FolderID {3}, newName {4}",
  637. remoteClient.AgentId, oldAgentID, oldItemID, newFolderID, newName);
  638. InventoryItemBase item = null;
  639. if (LibraryService != null && LibraryService.LibraryRootFolder != null)
  640. item = LibraryService.LibraryRootFolder.FindItem(oldItemID);
  641. if (item == null)
  642. {
  643. item = new InventoryItemBase(oldItemID, remoteClient.AgentId);
  644. item = InventoryService.GetItem(item);
  645. if (item == null)
  646. {
  647. m_log.Error("[AGENT INVENTORY]: Failed to find item " + oldItemID.ToString());
  648. return;
  649. }
  650. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  651. return;
  652. }
  653. AssetBase asset = AssetService.Get(item.AssetID.ToString());
  654. if (asset != null)
  655. {
  656. if (newName != String.Empty)
  657. {
  658. asset.Name = newName;
  659. }
  660. else
  661. {
  662. newName = item.Name;
  663. }
  664. if (remoteClient.AgentId == oldAgentID
  665. || (LibraryService != null
  666. && LibraryService.LibraryRootFolder != null
  667. && oldAgentID == LibraryService.LibraryRootFolder.Owner))
  668. {
  669. CreateNewInventoryItem(
  670. remoteClient, item.CreatorId, item.CreatorData, newFolderID,
  671. newName, item.Description, item.Flags, callbackID, asset, (sbyte)item.InvType,
  672. item.BasePermissions, item.CurrentPermissions, item.EveryOnePermissions,
  673. item.NextPermissions, item.GroupPermissions, Util.UnixTimeSinceEpoch());
  674. }
  675. else
  676. {
  677. // If item is transfer or permissions are off or calling agent is allowed to copy item owner's inventory item.
  678. if (((item.CurrentPermissions & (uint)PermissionMask.Transfer) != 0)
  679. && (m_permissions.BypassPermissions()
  680. || m_permissions.CanCopyUserInventory(remoteClient.AgentId, oldItemID)))
  681. {
  682. CreateNewInventoryItem(
  683. remoteClient, item.CreatorId, item.CreatorData, newFolderID, newName, item.Description, item.Flags, callbackID,
  684. asset, (sbyte) item.InvType,
  685. item.NextPermissions, item.NextPermissions, item.EveryOnePermissions & item.NextPermissions,
  686. item.NextPermissions, item.GroupPermissions, Util.UnixTimeSinceEpoch());
  687. }
  688. }
  689. }
  690. else
  691. {
  692. m_log.ErrorFormat(
  693. "[AGENT INVENTORY]: Could not copy item {0} since asset {1} could not be found",
  694. item.Name, item.AssetID);
  695. }
  696. }
  697. /// <summary>
  698. /// Create a new asset data structure.
  699. /// </summary>
  700. public AssetBase CreateAsset(string name, string description, sbyte assetType, byte[] data, UUID creatorID)
  701. {
  702. AssetBase asset = new AssetBase(UUID.Random(), name, assetType, creatorID.ToString());
  703. asset.Description = description;
  704. asset.Data = (data == null) ? new byte[1] : data;
  705. return asset;
  706. }
  707. /// <summary>
  708. /// Move an item within the agent's inventory.
  709. /// </summary>
  710. /// <param name="remoteClient"></param>
  711. /// <param name="folderID"></param>
  712. /// <param name="itemID"></param>
  713. /// <param name="length"></param>
  714. /// <param name="newName"></param>
  715. public void MoveInventoryItem(IClientAPI remoteClient, List<InventoryItemBase> items)
  716. {
  717. m_log.DebugFormat(
  718. "[AGENT INVENTORY]: Moving {0} items for user {1}", items.Count, remoteClient.AgentId);
  719. if (!InventoryService.MoveItems(remoteClient.AgentId, items))
  720. m_log.Warn("[AGENT INVENTORY]: Failed to move items for user " + remoteClient.AgentId);
  721. }
  722. /// <summary>
  723. /// Create a new inventory item.
  724. /// </summary>
  725. /// <param name="remoteClient">Client creating this inventory item.</param>
  726. /// <param name="creatorID"></param>
  727. /// <param name="creatorData"></param>
  728. /// <param name="folderID">UUID of folder in which this item should be placed.</param>
  729. /// <param name="name">Item name.</para>
  730. /// <param name="description">Item description.</param>
  731. /// <param name="flags">Item flags</param>
  732. /// <param name="callbackID">Generated by the client.</para>
  733. /// <param name="asset">Asset to which this item refers.</param>
  734. /// <param name="invType">Type of inventory item.</param>
  735. /// <param name="nextOwnerMask">Next owner pemrissions mask.</param>
  736. /// <param name="creationDate">Unix timestamp at which this item was created.</param>
  737. public void CreateNewInventoryItem(
  738. IClientAPI remoteClient, string creatorID, string creatorData, UUID folderID,
  739. string name, string description, uint flags, uint callbackID,
  740. AssetBase asset, sbyte invType, uint nextOwnerMask, int creationDate)
  741. {
  742. CreateNewInventoryItem(
  743. remoteClient, creatorID, creatorData, folderID, name, description, flags, callbackID, asset, invType,
  744. (uint)PermissionMask.All, (uint)PermissionMask.All, 0, nextOwnerMask, 0, creationDate);
  745. }
  746. /// <summary>
  747. /// Create a new Inventory Item
  748. /// </summary>
  749. /// <param name="remoteClient">Client creating this inventory item.</param>
  750. /// <param name="creatorID"></param>
  751. /// <param name="creatorData"></param>
  752. /// <param name="folderID">UUID of folder in which this item should be placed.</param>
  753. /// <param name="name">Item name.</para>
  754. /// <param name="description">Item description.</param>
  755. /// <param name="flags">Item flags</param>
  756. /// <param name="callbackID">Generated by the client.</para>
  757. /// <param name="asset">Asset to which this item refers.</param>
  758. /// <param name="invType">Type of inventory item.</param>
  759. /// <param name="baseMask">Base permissions mask.</param>
  760. /// <param name="currentMask">Current permissions mask.</param>
  761. /// <param name="everyoneMask">Everyone permissions mask.</param>
  762. /// <param name="nextOwnerMask">Next owner pemrissions mask.</param>
  763. /// <param name="groupMask">Group permissions mask.</param>
  764. /// <param name="creationDate">Unix timestamp at which this item was created.</param>
  765. private void CreateNewInventoryItem(
  766. IClientAPI remoteClient, string creatorID, string creatorData, UUID folderID,
  767. string name, string description, uint flags, uint callbackID, AssetBase asset, sbyte invType,
  768. uint baseMask, uint currentMask, uint everyoneMask, uint nextOwnerMask, uint groupMask, int creationDate)
  769. {
  770. InventoryItemBase item = new InventoryItemBase();
  771. item.Owner = remoteClient.AgentId;
  772. item.CreatorId = creatorID;
  773. item.CreatorData = creatorData;
  774. item.ID = UUID.Random();
  775. item.AssetID = asset.FullID;
  776. item.Name = name;
  777. item.Description = description;
  778. item.Flags = flags;
  779. item.AssetType = asset.Type;
  780. item.InvType = invType;
  781. item.Folder = folderID;
  782. item.CurrentPermissions = currentMask;
  783. item.NextPermissions = nextOwnerMask;
  784. item.EveryOnePermissions = everyoneMask;
  785. item.GroupPermissions = groupMask;
  786. item.BasePermissions = baseMask;
  787. item.CreationDate = creationDate;
  788. if (AddInventoryItem(item))
  789. {
  790. remoteClient.SendInventoryItemCreateUpdate(item, callbackID);
  791. }
  792. else
  793. {
  794. m_dialogModule.SendAlertToUser(remoteClient, "Failed to create item");
  795. m_log.WarnFormat(
  796. "Failed to add item for {0} in CreateNewInventoryItem!",
  797. remoteClient.Name);
  798. }
  799. }
  800. /// <summary>
  801. /// Link an inventory item to an existing item.
  802. /// </summary>
  803. /// <remarks>
  804. /// The linkee item id is placed in the asset id slot. This appears to be what the viewer expects when
  805. /// it receives inventory information.
  806. /// </remarks>
  807. /// <param name="remoteClient"></param>
  808. /// <param name="transActionID"></param>
  809. /// <param name="folderID"></param>
  810. /// <param name="callbackID"></param>
  811. /// <param name="description"></param>
  812. /// <param name="name"></param>
  813. /// <param name="invType"></param>
  814. /// <param name="type">/param>
  815. /// <param name="olditemID"></param>
  816. private void HandleLinkInventoryItem(IClientAPI remoteClient, UUID transActionID, UUID folderID,
  817. uint callbackID, string description, string name,
  818. sbyte invType, sbyte type, UUID olditemID)
  819. {
  820. // m_log.DebugFormat(
  821. // "[AGENT INVENTORY]: Received request from {0} to create inventory item link {1} in folder {2} pointing to {3}, assetType {4}, inventoryType {5}",
  822. // remoteClient.Name, name, folderID, olditemID, (AssetType)type, (InventoryType)invType);
  823. if (!Permissions.CanCreateUserInventory(invType, remoteClient.AgentId))
  824. return;
  825. ScenePresence presence;
  826. if (TryGetScenePresence(remoteClient.AgentId, out presence))
  827. {
  828. // Disabled the check for duplicate links.
  829. //
  830. // When outfits are being adjusted, the viewer rapidly sends delete link messages followed by
  831. // create links. However, since these are handled asynchronously, the deletes do not complete before
  832. // the creates are handled. Therefore, we cannot enforce a duplicate link check.
  833. // InventoryItemBase existingLink = null;
  834. // List<InventoryItemBase> existingItems = InventoryService.GetFolderItems(remoteClient.AgentId, folderID);
  835. // foreach (InventoryItemBase item in existingItems)
  836. // if (item.AssetID == olditemID)
  837. // existingLink = item;
  838. //
  839. // if (existingLink != null)
  840. // {
  841. // m_log.WarnFormat(
  842. // "[AGENT INVENTORY]: Ignoring request from {0} to create item link {1} in folder {2} pointing to {3} since a link named {4} with id {5} already exists",
  843. // remoteClient.Name, name, folderID, olditemID, existingLink.Name, existingLink.ID);
  844. //
  845. // return;
  846. // }
  847. AssetBase asset = new AssetBase();
  848. asset.FullID = olditemID;
  849. asset.Type = type;
  850. asset.Name = name;
  851. asset.Description = description;
  852. CreateNewInventoryItem(
  853. remoteClient, remoteClient.AgentId.ToString(), string.Empty, folderID,
  854. name, description, 0, callbackID, asset, invType,
  855. (uint)PermissionMask.All, (uint)PermissionMask.All, (uint)PermissionMask.All,
  856. (uint)PermissionMask.All, (uint)PermissionMask.All, Util.UnixTimeSinceEpoch());
  857. }
  858. else
  859. {
  860. m_log.ErrorFormat(
  861. "ScenePresence for agent uuid {0} unexpectedly not found in HandleLinkInventoryItem",
  862. remoteClient.AgentId);
  863. }
  864. }
  865. /// <summary>
  866. /// Remove an inventory item for the client's inventory
  867. /// </summary>
  868. /// <param name="remoteClient"></param>
  869. /// <param name="itemID"></param>
  870. private void RemoveInventoryItem(IClientAPI remoteClient, List<UUID> itemIDs)
  871. {
  872. // m_log.DebugFormat(
  873. // "[AGENT INVENTORY]: Removing inventory items {0} for {1}",
  874. // string.Join(",", itemIDs.ConvertAll<string>(uuid => uuid.ToString()).ToArray()),
  875. // remoteClient.Name);
  876. InventoryService.DeleteItems(remoteClient.AgentId, itemIDs);
  877. }
  878. /// <summary>
  879. /// Removes an inventory folder. This packet is sent when the user
  880. /// right-clicks a folder that's already in trash and chooses "purge"
  881. /// </summary>
  882. /// <param name="remoteClient"></param>
  883. /// <param name="folderID"></param>
  884. private void RemoveInventoryFolder(IClientAPI remoteClient, List<UUID> folderIDs)
  885. {
  886. m_log.DebugFormat("[SCENE INVENTORY]: RemoveInventoryFolders count {0}", folderIDs.Count);
  887. InventoryService.DeleteFolders(remoteClient.AgentId, folderIDs);
  888. }
  889. /// <summary>
  890. /// Send the details of a prim's inventory to the client.
  891. /// </summary>
  892. /// <param name="remoteClient"></param>
  893. /// <param name="primLocalID"></param>
  894. public void RequestTaskInventory(IClientAPI remoteClient, uint primLocalID)
  895. {
  896. SceneObjectPart part = GetSceneObjectPart(primLocalID);
  897. if (part == null)
  898. return;
  899. if (XferManager != null)
  900. part.Inventory.RequestInventoryFile(remoteClient, XferManager);
  901. }
  902. /// <summary>
  903. /// Remove an item from a prim (task) inventory
  904. /// </summary>
  905. /// <param name="remoteClient">Unused at the moment but retained since the avatar ID might
  906. /// be necessary for a permissions check at some stage.</param>
  907. /// <param name="itemID"></param>
  908. /// <param name="localID"></param>
  909. public void RemoveTaskInventory(IClientAPI remoteClient, UUID itemID, uint localID)
  910. {
  911. SceneObjectPart part = GetSceneObjectPart(localID);
  912. SceneObjectGroup group = null;
  913. if (part != null)
  914. {
  915. group = part.ParentGroup;
  916. }
  917. if (part != null && group != null)
  918. {
  919. if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId))
  920. return;
  921. TaskInventoryItem item = group.GetInventoryItem(localID, itemID);
  922. if (item == null)
  923. return;
  924. InventoryFolderBase destFolder = InventoryService.GetFolderForType(remoteClient.AgentId, AssetType.TrashFolder);
  925. // Move the item to trash. If this is a copiable item, only
  926. // a copy will be moved and we will still need to delete
  927. // the item from the prim. If it was no copy, is will be
  928. // deleted by this method.
  929. MoveTaskInventoryItem(remoteClient, destFolder.ID, part, itemID);
  930. if (group.GetInventoryItem(localID, itemID) != null)
  931. {
  932. if (item.Type == 10)
  933. {
  934. part.RemoveScriptEvents(itemID);
  935. EventManager.TriggerRemoveScript(localID, itemID);
  936. }
  937. group.RemoveInventoryItem(localID, itemID);
  938. }
  939. part.SendPropertiesToClient(remoteClient);
  940. }
  941. }
  942. private InventoryItemBase CreateAgentInventoryItemFromTask(UUID destAgent, SceneObjectPart part, UUID itemId)
  943. {
  944. TaskInventoryItem taskItem = part.Inventory.GetInventoryItem(itemId);
  945. if (null == taskItem)
  946. {
  947. m_log.ErrorFormat(
  948. "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for creating an avatar"
  949. + " inventory item from a prim's inventory item "
  950. + " but the required item does not exist in the prim's inventory",
  951. itemId, part.Name, part.UUID);
  952. return null;
  953. }
  954. if ((destAgent != taskItem.OwnerID) && ((taskItem.CurrentPermissions & (uint)PermissionMask.Transfer) == 0))
  955. {
  956. return null;
  957. }
  958. InventoryItemBase agentItem = new InventoryItemBase();
  959. agentItem.ID = UUID.Random();
  960. agentItem.CreatorId = taskItem.CreatorID.ToString();
  961. agentItem.CreatorData = taskItem.CreatorData;
  962. agentItem.Owner = destAgent;
  963. agentItem.AssetID = taskItem.AssetID;
  964. agentItem.Description = taskItem.Description;
  965. agentItem.Name = taskItem.Name;
  966. agentItem.AssetType = taskItem.Type;
  967. agentItem.InvType = taskItem.InvType;
  968. agentItem.Flags = taskItem.Flags;
  969. if ((part.OwnerID != destAgent) && Permissions.PropagatePermissions())
  970. {
  971. agentItem.BasePermissions = taskItem.BasePermissions & (taskItem.NextPermissions | (uint)PermissionMask.Move);
  972. if (taskItem.InvType == (int)InventoryType.Object)
  973. agentItem.CurrentPermissions = agentItem.BasePermissions & (((taskItem.CurrentPermissions & 7) << 13) | (taskItem.CurrentPermissions & (uint)PermissionMask.Move));
  974. else
  975. agentItem.CurrentPermissions = agentItem.BasePermissions & taskItem.CurrentPermissions;
  976. agentItem.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm;
  977. agentItem.NextPermissions = taskItem.NextPermissions;
  978. agentItem.EveryOnePermissions = taskItem.EveryonePermissions & (taskItem.NextPermissions | (uint)PermissionMask.Move);
  979. agentItem.GroupPermissions = taskItem.GroupPermissions & taskItem.NextPermissions;
  980. }
  981. else
  982. {
  983. agentItem.BasePermissions = taskItem.BasePermissions;
  984. agentItem.CurrentPermissions = taskItem.CurrentPermissions;
  985. agentItem.NextPermissions = taskItem.NextPermissions;
  986. agentItem.EveryOnePermissions = taskItem.EveryonePermissions;
  987. agentItem.GroupPermissions = taskItem.GroupPermissions;
  988. }
  989. if (!Permissions.BypassPermissions())
  990. {
  991. if ((taskItem.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  992. {
  993. if (taskItem.Type == 10)
  994. {
  995. part.RemoveScriptEvents(itemId);
  996. EventManager.TriggerRemoveScript(part.LocalId, itemId);
  997. }
  998. part.Inventory.RemoveInventoryItem(itemId);
  999. }
  1000. }
  1001. return agentItem;
  1002. }
  1003. /// <summary>
  1004. /// Move the given item in the given prim to a folder in the client's inventory
  1005. /// </summary>
  1006. /// <param name="remoteClient"></param>
  1007. /// <param name="folderID"></param>
  1008. /// <param name="part"></param>
  1009. /// <param name="itemID"></param>
  1010. public InventoryItemBase MoveTaskInventoryItem(IClientAPI remoteClient, UUID folderId, SceneObjectPart part, UUID itemId)
  1011. {
  1012. m_log.DebugFormat(
  1013. "[PRIM INVENTORY]: Adding item {0} from {1} to folder {2} for {3}",
  1014. itemId, part.Name, folderId, remoteClient.Name);
  1015. InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(remoteClient.AgentId, part, itemId);
  1016. if (agentItem == null)
  1017. return null;
  1018. agentItem.Folder = folderId;
  1019. AddInventoryItem(remoteClient, agentItem);
  1020. return agentItem;
  1021. }
  1022. /// <summary>
  1023. /// <see>ClientMoveTaskInventoryItem</see>
  1024. /// </summary>
  1025. /// <param name="remoteClient"></param>
  1026. /// <param name="folderID"></param>
  1027. /// <param name="primLocalID"></param>
  1028. /// <param name="itemID"></param>
  1029. public void ClientMoveTaskInventoryItem(IClientAPI remoteClient, UUID folderId, uint primLocalId, UUID itemId)
  1030. {
  1031. SceneObjectPart part = GetSceneObjectPart(primLocalId);
  1032. if (null == part)
  1033. {
  1034. m_log.WarnFormat(
  1035. "[PRIM INVENTORY]: " +
  1036. "Move of inventory item {0} from prim with local id {1} failed because the prim could not be found",
  1037. itemId, primLocalId);
  1038. return;
  1039. }
  1040. TaskInventoryItem taskItem = part.Inventory.GetInventoryItem(itemId);
  1041. if (null == taskItem)
  1042. {
  1043. m_log.WarnFormat("[PRIM INVENTORY]: Move of inventory item {0} from prim with local id {1} failed"
  1044. + " because the inventory item could not be found",
  1045. itemId, primLocalId);
  1046. return;
  1047. }
  1048. if ((taskItem.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  1049. {
  1050. // If the item to be moved is no copy, we need to be able to
  1051. // edit the prim.
  1052. if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId))
  1053. return;
  1054. }
  1055. else
  1056. {
  1057. // If the item is copiable, then we just need to have perms
  1058. // on it. The delete check is a pure rights check
  1059. if (!Permissions.CanDeleteObject(part.UUID, remoteClient.AgentId))
  1060. return;
  1061. }
  1062. MoveTaskInventoryItem(remoteClient, folderId, part, itemId);
  1063. }
  1064. /// <summary>
  1065. /// <see>MoveTaskInventoryItem</see>
  1066. /// </summary>
  1067. /// <param name="remoteClient"></param>
  1068. /// <param name="folderID">
  1069. /// The user inventory folder to move (or copy) the item to. If null, then the most
  1070. /// suitable system folder is used (e.g. the Objects folder for objects). If there is no suitable folder, then
  1071. /// the item is placed in the user's root inventory folder
  1072. /// </param>
  1073. /// <param name="part"></param>
  1074. /// <param name="itemID"></param>
  1075. public InventoryItemBase MoveTaskInventoryItem(UUID avatarId, UUID folderId, SceneObjectPart part, UUID itemId)
  1076. {
  1077. ScenePresence avatar;
  1078. if (TryGetScenePresence(avatarId, out avatar))
  1079. {
  1080. return MoveTaskInventoryItem(avatar.ControllingClient, folderId, part, itemId);
  1081. }
  1082. else
  1083. {
  1084. InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(avatarId, part, itemId);
  1085. if (agentItem == null)
  1086. return null;
  1087. agentItem.Folder = folderId;
  1088. AddInventoryItem(agentItem);
  1089. return agentItem;
  1090. }
  1091. }
  1092. /// <summary>
  1093. /// Copy a task (prim) inventory item to another task (prim)
  1094. /// </summary>
  1095. /// <param name="destId">ID of destination part</param>
  1096. /// <param name="part">Source part</param>
  1097. /// <param name="itemId">Source item id to transfer</param>
  1098. public void MoveTaskInventoryItem(UUID destId, SceneObjectPart part, UUID itemId)
  1099. {
  1100. TaskInventoryItem srcTaskItem = part.Inventory.GetInventoryItem(itemId);
  1101. if (srcTaskItem == null)
  1102. {
  1103. m_log.ErrorFormat(
  1104. "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for moving"
  1105. + " but the item does not exist in this inventory",
  1106. itemId, part.Name, part.UUID);
  1107. return;
  1108. }
  1109. SceneObjectPart destPart = GetSceneObjectPart(destId);
  1110. if (destPart == null)
  1111. {
  1112. m_log.ErrorFormat(
  1113. "[PRIM INVENTORY]: " +
  1114. "Could not find prim for ID {0}",
  1115. destId);
  1116. return;
  1117. }
  1118. if (part.OwnerID != destPart.OwnerID)
  1119. {
  1120. // Source must have transfer permissions
  1121. if ((srcTaskItem.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
  1122. return;
  1123. // Object cannot copy items to an object owned by a different owner
  1124. // unless llAllowInventoryDrop has been called on the destination
  1125. if ((destPart.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) == 0)
  1126. return;
  1127. }
  1128. // must have both move and modify permission to put an item in an object
  1129. if ((part.OwnerMask & ((uint)PermissionMask.Move | (uint)PermissionMask.Modify)) == 0)
  1130. return;
  1131. TaskInventoryItem destTaskItem = new TaskInventoryItem();
  1132. destTaskItem.ItemID = UUID.Random();
  1133. destTaskItem.CreatorID = srcTaskItem.CreatorID;
  1134. destTaskItem.CreatorData = srcTaskItem.CreatorData;
  1135. destTaskItem.AssetID = srcTaskItem.AssetID;
  1136. destTaskItem.GroupID = destPart.GroupID;
  1137. destTaskItem.OwnerID = destPart.OwnerID;
  1138. destTaskItem.ParentID = destPart.UUID;
  1139. destTaskItem.ParentPartID = destPart.UUID;
  1140. destTaskItem.BasePermissions = srcTaskItem.BasePermissions;
  1141. destTaskItem.EveryonePermissions = srcTaskItem.EveryonePermissions;
  1142. destTaskItem.GroupPermissions = srcTaskItem.GroupPermissions;
  1143. destTaskItem.CurrentPermissions = srcTaskItem.CurrentPermissions;
  1144. destTaskItem.NextPermissions = srcTaskItem.NextPermissions;
  1145. destTaskItem.Flags = srcTaskItem.Flags;
  1146. if (destPart.OwnerID != part.OwnerID)
  1147. {
  1148. if (Permissions.PropagatePermissions())
  1149. {
  1150. destTaskItem.CurrentPermissions = srcTaskItem.CurrentPermissions &
  1151. (srcTaskItem.NextPermissions | (uint)PermissionMask.Move);
  1152. destTaskItem.GroupPermissions = srcTaskItem.GroupPermissions &
  1153. (srcTaskItem.NextPermissions | (uint)PermissionMask.Move);
  1154. destTaskItem.EveryonePermissions = srcTaskItem.EveryonePermissions &
  1155. (srcTaskItem.NextPermissions | (uint)PermissionMask.Move);
  1156. destTaskItem.BasePermissions = srcTaskItem.BasePermissions &
  1157. (srcTaskItem.NextPermissions | (uint)PermissionMask.Move);
  1158. destTaskItem.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm;
  1159. }
  1160. }
  1161. destTaskItem.Description = srcTaskItem.Description;
  1162. destTaskItem.Name = srcTaskItem.Name;
  1163. destTaskItem.InvType = srcTaskItem.InvType;
  1164. destTaskItem.Type = srcTaskItem.Type;
  1165. destPart.Inventory.AddInventoryItem(destTaskItem, part.OwnerID != destPart.OwnerID);
  1166. if ((srcTaskItem.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  1167. part.Inventory.RemoveInventoryItem(itemId);
  1168. ScenePresence avatar;
  1169. if (TryGetScenePresence(srcTaskItem.OwnerID, out avatar))
  1170. {
  1171. destPart.SendPropertiesToClient(avatar.ControllingClient);
  1172. }
  1173. }
  1174. public UUID MoveTaskInventoryItems(UUID destID, string category, SceneObjectPart host, List<UUID> items)
  1175. {
  1176. InventoryFolderBase rootFolder = InventoryService.GetRootFolder(destID);
  1177. UUID newFolderID = UUID.Random();
  1178. InventoryFolderBase newFolder = new InventoryFolderBase(newFolderID, category, destID, -1, rootFolder.ID, rootFolder.Version);
  1179. InventoryService.AddFolder(newFolder);
  1180. foreach (UUID itemID in items)
  1181. {
  1182. InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(destID, host, itemID);
  1183. if (agentItem != null)
  1184. {
  1185. agentItem.Folder = newFolderID;
  1186. AddInventoryItem(agentItem);
  1187. }
  1188. }
  1189. ScenePresence avatar = null;
  1190. if (TryGetScenePresence(destID, out avatar))
  1191. {
  1192. //profile.SendInventoryDecendents(avatar.ControllingClient,
  1193. // profile.RootFolder.ID, true, false);
  1194. //profile.SendInventoryDecendents(avatar.ControllingClient,
  1195. // newFolderID, false, true);
  1196. SendInventoryUpdate(avatar.ControllingClient, rootFolder, true, false);
  1197. SendInventoryUpdate(avatar.ControllingClient, newFolder, false, true);
  1198. }
  1199. return newFolderID;
  1200. }
  1201. private void SendInventoryUpdate(IClientAPI client, InventoryFolderBase folder, bool fetchFolders, bool fetchItems)
  1202. {
  1203. if (folder == null)
  1204. return;
  1205. // TODO: This code for looking in the folder for the library should be folded somewhere else
  1206. // so that this class doesn't have to know the details (and so that multiple libraries, etc.
  1207. // can be handled transparently).
  1208. InventoryFolderImpl fold = null;
  1209. if (LibraryService != null && LibraryService.LibraryRootFolder != null)
  1210. {
  1211. if ((fold = LibraryService.LibraryRootFolder.FindFolder(folder.ID)) != null)
  1212. {
  1213. client.SendInventoryFolderDetails(
  1214. fold.Owner, folder.ID, fold.RequestListOfItems(),
  1215. fold.RequestListOfFolders(), fold.Version, fetchFolders, fetchItems);
  1216. return;
  1217. }
  1218. }
  1219. // Fetch the folder contents
  1220. InventoryCollection contents = InventoryService.GetFolderContent(client.AgentId, folder.ID);
  1221. // Fetch the folder itself to get its current version
  1222. InventoryFolderBase containingFolder = new InventoryFolderBase(folder.ID, client.AgentId);
  1223. containingFolder = InventoryService.GetFolder(containingFolder);
  1224. // m_log.DebugFormat("[AGENT INVENTORY]: Sending inventory folder contents ({0} nodes) for \"{1}\" to {2} {3}",
  1225. // contents.Folders.Count + contents.Items.Count, containingFolder.Name, client.FirstName, client.LastName);
  1226. if (containingFolder != null)
  1227. {
  1228. // If the folder requested contains links, then we need to send those folders first, otherwise the links
  1229. // will be broken in the viewer.
  1230. HashSet<UUID> linkedItemFolderIdsToSend = new HashSet<UUID>();
  1231. foreach (InventoryItemBase item in contents.Items)
  1232. {
  1233. if (item.AssetType == (int)AssetType.Link)
  1234. {
  1235. InventoryItemBase linkedItem = InventoryService.GetItem(new InventoryItemBase(item.AssetID));
  1236. // Take care of genuinely broken links where the target doesn't exist
  1237. // HACK: Also, don't follow up links that just point to other links. In theory this is legitimate,
  1238. // but no viewer has been observed to set these up and this is the lazy way of avoiding cycles
  1239. // rather than having to keep track of every folder requested in the recursion.
  1240. if (linkedItem != null && linkedItem.AssetType != (int)AssetType.Link)
  1241. {
  1242. // We don't need to send the folder if source and destination of the link are in the same
  1243. // folder.
  1244. if (linkedItem.Folder != containingFolder.ID)
  1245. linkedItemFolderIdsToSend.Add(linkedItem.Folder);
  1246. }
  1247. }
  1248. }
  1249. foreach (UUID linkedItemFolderId in linkedItemFolderIdsToSend)
  1250. SendInventoryUpdate(client, new InventoryFolderBase(linkedItemFolderId), false, true);
  1251. client.SendInventoryFolderDetails(
  1252. client.AgentId, folder.ID, contents.Items, contents.Folders,
  1253. containingFolder.Version, fetchFolders, fetchItems);
  1254. }
  1255. }
  1256. /// <summary>
  1257. /// Update an item in a prim (task) inventory.
  1258. /// This method does not handle scripts, <see>RezScript(IClientAPI, UUID, unit)</see>
  1259. /// </summary>
  1260. /// <param name="remoteClient"></param>
  1261. /// <param name="transactionID"></param>
  1262. /// <param name="itemInfo"></param>
  1263. /// <param name="primLocalID"></param>
  1264. public void UpdateTaskInventory(IClientAPI remoteClient, UUID transactionID, TaskInventoryItem itemInfo,
  1265. uint primLocalID)
  1266. {
  1267. UUID itemID = itemInfo.ItemID;
  1268. // Find the prim we're dealing with
  1269. SceneObjectPart part = GetSceneObjectPart(primLocalID);
  1270. if (part != null)
  1271. {
  1272. TaskInventoryItem currentItem = part.Inventory.GetInventoryItem(itemID);
  1273. bool allowInventoryDrop = (part.GetEffectiveObjectFlags()
  1274. & (uint)PrimFlags.AllowInventoryDrop) != 0;
  1275. // Explicity allow anyone to add to the inventory if the
  1276. // AllowInventoryDrop flag has been set. Don't however let
  1277. // them update an item unless they pass the external checks
  1278. //
  1279. if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId)
  1280. && (currentItem != null || !allowInventoryDrop))
  1281. return;
  1282. if (currentItem == null)
  1283. {
  1284. UUID copyID = UUID.Random();
  1285. if (itemID != UUID.Zero)
  1286. {
  1287. InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
  1288. item = InventoryService.GetItem(item);
  1289. // Try library
  1290. if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null)
  1291. {
  1292. item = LibraryService.LibraryRootFolder.FindItem(itemID);
  1293. }
  1294. // If we've found the item in the user's inventory or in the library
  1295. if (item != null)
  1296. {
  1297. part.ParentGroup.AddInventoryItem(remoteClient.AgentId, primLocalID, item, copyID);
  1298. m_log.InfoFormat(
  1299. "[PRIM INVENTORY]: Update with item {0} requested of prim {1} for {2}",
  1300. item.Name, primLocalID, remoteClient.Name);
  1301. part.SendPropertiesToClient(remoteClient);
  1302. if (!Permissions.BypassPermissions())
  1303. {
  1304. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  1305. {
  1306. List<UUID> uuids = new List<UUID>();
  1307. uuids.Add(itemID);
  1308. RemoveInventoryItem(remoteClient, uuids);
  1309. }
  1310. }
  1311. }
  1312. else
  1313. {
  1314. m_log.ErrorFormat(
  1315. "[PRIM INVENTORY]: Could not find inventory item {0} to update for {1}!",
  1316. itemID, remoteClient.Name);
  1317. }
  1318. }
  1319. }
  1320. else // Updating existing item with new perms etc
  1321. {
  1322. // m_log.DebugFormat(
  1323. // "[PRIM INVENTORY]: Updating item {0} in {1} for UpdateTaskInventory()",
  1324. // currentItem.Name, part.Name);
  1325. // Only look for an uploaded updated asset if we are passed a transaction ID. This is only the
  1326. // case for updates uploded through UDP. Updates uploaded via a capability (e.g. a script update)
  1327. // will not pass in a transaction ID in the update message.
  1328. if (transactionID != UUID.Zero && AgentTransactionsModule != null)
  1329. {
  1330. AgentTransactionsModule.HandleTaskItemUpdateFromTransaction(
  1331. remoteClient, part, transactionID, currentItem);
  1332. if ((InventoryType)itemInfo.InvType == InventoryType.Notecard)
  1333. remoteClient.SendAgentAlertMessage("Notecard saved", false);
  1334. else if ((InventoryType)itemInfo.InvType == InventoryType.LSL)
  1335. remoteClient.SendAgentAlertMessage("Script saved", false);
  1336. else
  1337. remoteClient.SendAgentAlertMessage("Item saved", false);
  1338. }
  1339. // Base ALWAYS has move
  1340. currentItem.BasePermissions |= (uint)PermissionMask.Move;
  1341. itemInfo.Flags = currentItem.Flags;
  1342. // Check if we're allowed to mess with permissions
  1343. if (!Permissions.IsGod(remoteClient.AgentId)) // Not a god
  1344. {
  1345. if (remoteClient.AgentId != part.OwnerID) // Not owner
  1346. {
  1347. // Friends and group members can't change any perms
  1348. itemInfo.BasePermissions = currentItem.BasePermissions;
  1349. itemInfo.EveryonePermissions = currentItem.EveryonePermissions;
  1350. itemInfo.GroupPermissions = currentItem.GroupPermissions;
  1351. itemInfo.NextPermissions = currentItem.NextPermissions;
  1352. itemInfo.CurrentPermissions = currentItem.CurrentPermissions;
  1353. }
  1354. else
  1355. {
  1356. // Owner can't change base, and can change other
  1357. // only up to base
  1358. itemInfo.BasePermissions = currentItem.BasePermissions;
  1359. if (itemInfo.EveryonePermissions != currentItem.EveryonePermissions)
  1360. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteEveryone;
  1361. if (itemInfo.GroupPermissions != currentItem.GroupPermissions)
  1362. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteGroup;
  1363. if (itemInfo.CurrentPermissions != currentItem.CurrentPermissions)
  1364. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteOwner;
  1365. if (itemInfo.NextPermissions != currentItem.NextPermissions)
  1366. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteNextOwner;
  1367. itemInfo.EveryonePermissions &= currentItem.BasePermissions;
  1368. itemInfo.GroupPermissions &= currentItem.BasePermissions;
  1369. itemInfo.CurrentPermissions &= currentItem.BasePermissions;
  1370. itemInfo.NextPermissions &= currentItem.BasePermissions;
  1371. }
  1372. }
  1373. else
  1374. {
  1375. if (itemInfo.BasePermissions != currentItem.BasePermissions)
  1376. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteBase;
  1377. if (itemInfo.EveryonePermissions != currentItem.EveryonePermissions)
  1378. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteEveryone;
  1379. if (itemInfo.GroupPermissions != currentItem.GroupPermissions)
  1380. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteGroup;
  1381. if (itemInfo.CurrentPermissions != currentItem.CurrentPermissions)
  1382. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteOwner;
  1383. if (itemInfo.NextPermissions != currentItem.NextPermissions)
  1384. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteNextOwner;
  1385. }
  1386. // Next ALWAYS has move
  1387. itemInfo.NextPermissions |= (uint)PermissionMask.Move;
  1388. if (part.Inventory.UpdateInventoryItem(itemInfo))
  1389. {
  1390. part.SendPropertiesToClient(remoteClient);
  1391. }
  1392. }
  1393. }
  1394. else
  1395. {
  1396. m_log.WarnFormat(
  1397. "[PRIM INVENTORY]: " +
  1398. "Update with item {0} requested of prim {1} for {2} but this prim does not exist",
  1399. itemID, primLocalID, remoteClient.Name);
  1400. }
  1401. }
  1402. /// <summary>
  1403. /// Rez a script into a prim's inventory, either ex nihilo or from an existing avatar inventory
  1404. /// </summary>
  1405. /// <param name="remoteClient"></param>
  1406. /// <param name="itemBase"> </param>
  1407. /// <param name="transactionID"></param>
  1408. /// <param name="localID"></param>
  1409. public void RezScript(IClientAPI remoteClient, InventoryItemBase itemBase, UUID transactionID, uint localID)
  1410. {
  1411. SceneObjectPart partWhereRezzed;
  1412. if (itemBase.ID != UUID.Zero)
  1413. partWhereRezzed = RezScriptFromAgentInventory(remoteClient.AgentId, itemBase.ID, localID);
  1414. else
  1415. partWhereRezzed = RezNewScript(remoteClient.AgentId, itemBase);
  1416. if (partWhereRezzed != null)
  1417. partWhereRezzed.SendPropertiesToClient(remoteClient);
  1418. }
  1419. /// <summary>
  1420. /// Rez a script into a prim from an agent inventory.
  1421. /// </summary>
  1422. /// <param name="agentID"></param>
  1423. /// <param name="fromItemID"></param>
  1424. /// <param name="localID"></param>
  1425. /// <returns>The part where the script was rezzed if successful. False otherwise.</returns>
  1426. public SceneObjectPart RezScriptFromAgentInventory(UUID agentID, UUID fromItemID, uint localID)
  1427. {
  1428. UUID copyID = UUID.Random();
  1429. InventoryItemBase item = new InventoryItemBase(fromItemID, agentID);
  1430. item = InventoryService.GetItem(item);
  1431. // Try library
  1432. // XXX clumsy, possibly should be one call
  1433. if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null)
  1434. {
  1435. item = LibraryService.LibraryRootFolder.FindItem(fromItemID);
  1436. }
  1437. if (item != null)
  1438. {
  1439. SceneObjectPart part = GetSceneObjectPart(localID);
  1440. if (part != null)
  1441. {
  1442. if (!Permissions.CanEditObjectInventory(part.UUID, agentID))
  1443. return null;
  1444. part.ParentGroup.AddInventoryItem(agentID, localID, item, copyID);
  1445. // TODO: switch to posting on_rez here when scripts
  1446. // have state in inventory
  1447. part.Inventory.CreateScriptInstance(copyID, 0, false, DefaultScriptEngine, 0);
  1448. // tell anyone watching that there is a new script in town
  1449. EventManager.TriggerNewScript(agentID, part, copyID);
  1450. // m_log.InfoFormat("[PRIMINVENTORY]: " +
  1451. // "Rezzed script {0} into prim local ID {1} for user {2}",
  1452. // item.inventoryName, localID, remoteClient.Name);
  1453. part.ParentGroup.ResumeScripts();
  1454. return part;
  1455. }
  1456. else
  1457. {
  1458. m_log.ErrorFormat(
  1459. "[PRIM INVENTORY]: " +
  1460. "Could not rez script {0} into prim local ID {1} for user {2}"
  1461. + " because the prim could not be found in the region!",
  1462. item.Name, localID, agentID);
  1463. }
  1464. }
  1465. else
  1466. {
  1467. m_log.ErrorFormat(
  1468. "[PRIM INVENTORY]: Could not find script inventory item {0} to rez for {1}!",
  1469. fromItemID, agentID);
  1470. }
  1471. return null;
  1472. }
  1473. /// <summary>
  1474. /// Rez a new script from nothing.
  1475. /// </summary>
  1476. /// <param name="remoteClient"></param>
  1477. /// <param name="itemBase"></param>
  1478. /// <returns>The part where the script was rezzed if successful. False otherwise.</returns>
  1479. public SceneObjectPart RezNewScript(UUID agentID, InventoryItemBase itemBase)
  1480. {
  1481. // The part ID is the folder ID!
  1482. SceneObjectPart part = GetSceneObjectPart(itemBase.Folder);
  1483. if (part == null)
  1484. {
  1485. // m_log.DebugFormat(
  1486. // "[SCENE INVENTORY]: Could not find part with id {0} for {1} to rez new script",
  1487. // itemBase.Folder, agentID);
  1488. return null;
  1489. }
  1490. if (!Permissions.CanCreateObjectInventory(itemBase.InvType, part.UUID, agentID))
  1491. {
  1492. // m_log.DebugFormat(
  1493. // "[SCENE INVENTORY]: No permission to create new script in {0} for {1}", part.Name, agentID);
  1494. return null;
  1495. }
  1496. AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType,
  1497. Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"),
  1498. agentID);
  1499. AssetService.Store(asset);
  1500. TaskInventoryItem taskItem = new TaskInventoryItem();
  1501. taskItem.ResetIDs(itemBase.Folder);
  1502. taskItem.ParentID = itemBase.Folder;
  1503. taskItem.CreationDate = (uint)itemBase.CreationDate;
  1504. taskItem.Name = itemBase.Name;
  1505. taskItem.Description = itemBase.Description;
  1506. taskItem.Type = itemBase.AssetType;
  1507. taskItem.InvType = itemBase.InvType;
  1508. taskItem.OwnerID = itemBase.Owner;
  1509. taskItem.CreatorID = itemBase.CreatorIdAsUuid;
  1510. taskItem.BasePermissions = itemBase.BasePermissions;
  1511. taskItem.CurrentPermissions = itemBase.CurrentPermissions;
  1512. taskItem.EveryonePermissions = itemBase.EveryOnePermissions;
  1513. taskItem.GroupPermissions = itemBase.GroupPermissions;
  1514. taskItem.NextPermissions = itemBase.NextPermissions;
  1515. taskItem.GroupID = itemBase.GroupID;
  1516. taskItem.GroupPermissions = 0;
  1517. taskItem.Flags = itemBase.Flags;
  1518. taskItem.PermsGranter = UUID.Zero;
  1519. taskItem.PermsMask = 0;
  1520. taskItem.AssetID = asset.FullID;
  1521. part.Inventory.AddInventoryItem(taskItem, false);
  1522. part.Inventory.CreateScriptInstance(taskItem, 0, false, DefaultScriptEngine, 0);
  1523. // tell anyone managing scripts that a new script exists
  1524. EventManager.TriggerNewScript(agentID, part, taskItem.ItemID);
  1525. part.ParentGroup.ResumeScripts();
  1526. return part;
  1527. }
  1528. /// <summary>
  1529. /// Rez a script into a prim's inventory from another prim
  1530. /// </summary>
  1531. /// <param name="remoteClient"></param>
  1532. /// <param name="itemID"> </param>
  1533. /// <param name="localID"></param>
  1534. public void RezScriptFromPrim(UUID srcId, SceneObjectPart srcPart, UUID destId, int pin, int running, int start_param)
  1535. {
  1536. TaskInventoryItem srcTaskItem = srcPart.Inventory.GetInventoryItem(srcId);
  1537. if (srcTaskItem == null)
  1538. {
  1539. m_log.ErrorFormat(
  1540. "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for rezzing a script but the "
  1541. + " item does not exist in this inventory",
  1542. srcId, srcPart.Name, srcPart.UUID);
  1543. return;
  1544. }
  1545. SceneObjectPart destPart = GetSceneObjectPart(destId);
  1546. if (destPart == null)
  1547. {
  1548. m_log.ErrorFormat(
  1549. "[PRIM INVENTORY]: " +
  1550. "Could not find script for ID {0}",
  1551. destId);
  1552. return;
  1553. }
  1554. // Must own the object, and have modify rights
  1555. if (srcPart.OwnerID != destPart.OwnerID)
  1556. {
  1557. // Group permissions
  1558. if ((destPart.GroupID == UUID.Zero) || (destPart.GroupID != srcPart.GroupID) ||
  1559. ((destPart.GroupMask & (uint)PermissionMask.Modify) == 0))
  1560. return;
  1561. } else {
  1562. if ((destPart.OwnerMask & (uint)PermissionMask.Modify) == 0)
  1563. return;
  1564. }
  1565. if (destPart.ScriptAccessPin != pin)
  1566. {
  1567. m_log.WarnFormat(
  1568. "[PRIM INVENTORY]: " +
  1569. "Script in object {0} : {1}, attempted to load script {2} : {3} into object {4} : {5} with invalid pin {6}",
  1570. srcPart.Name, srcId, srcTaskItem.Name, srcTaskItem.ItemID, destPart.Name, destId, pin);
  1571. // the LSL Wiki says we are supposed to shout on the DEBUG_CHANNEL -
  1572. // "Object: Task Object trying to illegally load script onto task Other_Object!"
  1573. // How do we shout from in here?
  1574. return;
  1575. }
  1576. TaskInventoryItem destTaskItem = new TaskInventoryItem();
  1577. destTaskItem.ItemID = UUID.Random();
  1578. destTaskItem.CreatorID = srcTaskItem.CreatorID;
  1579. destTaskItem.CreatorData = srcTaskItem.CreatorData;
  1580. destTaskItem.AssetID = srcTaskItem.AssetID;
  1581. destTaskItem.GroupID = destPart.GroupID;
  1582. destTaskItem.OwnerID = destPart.OwnerID;
  1583. destTaskItem.ParentID = destPart.UUID;
  1584. destTaskItem.ParentPartID = destPart.UUID;
  1585. destTaskItem.BasePermissions = srcTaskItem.BasePermissions;
  1586. destTaskItem.EveryonePermissions = srcTaskItem.EveryonePermissions;
  1587. destTaskItem.GroupPermissions = srcTaskItem.GroupPermissions;
  1588. destTaskItem.CurrentPermissions = srcTaskItem.CurrentPermissions;
  1589. destTaskItem.NextPermissions = srcTaskItem.NextPermissions;
  1590. destTaskItem.Flags = srcTaskItem.Flags;
  1591. if (destPart.OwnerID != srcPart.OwnerID)
  1592. {
  1593. if (Permissions.PropagatePermissions())
  1594. {
  1595. destTaskItem.CurrentPermissions = srcTaskItem.CurrentPermissions &
  1596. srcTaskItem.NextPermissions;
  1597. destTaskItem.GroupPermissions = srcTaskItem.GroupPermissions &
  1598. srcTaskItem.NextPermissions;
  1599. destTaskItem.EveryonePermissions = srcTaskItem.EveryonePermissions &
  1600. srcTaskItem.NextPermissions;
  1601. destTaskItem.BasePermissions = srcTaskItem.BasePermissions &
  1602. srcTaskItem.NextPermissions;
  1603. destTaskItem.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm;
  1604. }
  1605. }
  1606. destTaskItem.Description = srcTaskItem.Description;
  1607. destTaskItem.Name = srcTaskItem.Name;
  1608. destTaskItem.InvType = srcTaskItem.InvType;
  1609. destTaskItem.Type = srcTaskItem.Type;
  1610. destPart.Inventory.AddInventoryItemExclusive(destTaskItem, false);
  1611. if (running > 0)
  1612. {
  1613. destPart.Inventory.CreateScriptInstance(destTaskItem, start_param, false, DefaultScriptEngine, 0);
  1614. }
  1615. destPart.ParentGroup.ResumeScripts();
  1616. ScenePresence avatar;
  1617. if (TryGetScenePresence(srcTaskItem.OwnerID, out avatar))
  1618. {
  1619. destPart.SendPropertiesToClient(avatar.ControllingClient);
  1620. }
  1621. }
  1622. public virtual void DeRezObjects(IClientAPI remoteClient, List<uint> localIDs,
  1623. UUID groupID, DeRezAction action, UUID destinationID)
  1624. {
  1625. // First, see of we can perform the requested action and
  1626. // build a list of eligible objects
  1627. List<uint> deleteIDs = new List<uint>();
  1628. List<SceneObjectGroup> deleteGroups = new List<SceneObjectGroup>();
  1629. // Start with true for both, then remove the flags if objects
  1630. // that we can't derez are part of the selection
  1631. bool permissionToTake = true;
  1632. bool permissionToTakeCopy = true;
  1633. bool permissionToDelete = true;
  1634. foreach (uint localID in localIDs)
  1635. {
  1636. // Invalid id
  1637. SceneObjectPart part = GetSceneObjectPart(localID);
  1638. if (part == null)
  1639. continue;
  1640. // Already deleted by someone else
  1641. if (part.ParentGroup.IsDeleted)
  1642. continue;
  1643. // Can't delete child prims
  1644. if (part != part.ParentGroup.RootPart)
  1645. continue;
  1646. SceneObjectGroup grp = part.ParentGroup;
  1647. deleteIDs.Add(localID);
  1648. deleteGroups.Add(grp);
  1649. if (remoteClient == null)
  1650. {
  1651. // Autoreturn has a null client. Nothing else does. So
  1652. // allow only returns
  1653. if (action != DeRezAction.Return)
  1654. {
  1655. m_log.WarnFormat(
  1656. "[AGENT INVENTORY]: Ignoring attempt to {0} {1} {2} without a client",
  1657. action, grp.Name, grp.UUID);
  1658. return;
  1659. }
  1660. permissionToTakeCopy = false;
  1661. }
  1662. else
  1663. {
  1664. if (!Permissions.CanTakeCopyObject(grp.UUID, remoteClient.AgentId))
  1665. permissionToTakeCopy = false;
  1666. if (!Permissions.CanTakeObject(grp.UUID, remoteClient.AgentId))
  1667. permissionToTake = false;
  1668. if (!Permissions.CanDeleteObject(grp.UUID, remoteClient.AgentId))
  1669. permissionToDelete = false;
  1670. }
  1671. }
  1672. // Handle god perms
  1673. if ((remoteClient != null) && Permissions.IsGod(remoteClient.AgentId))
  1674. {
  1675. permissionToTake = true;
  1676. permissionToTakeCopy = true;
  1677. permissionToDelete = true;
  1678. }
  1679. // If we're re-saving, we don't even want to delete
  1680. if (action == DeRezAction.SaveToExistingUserInventoryItem)
  1681. permissionToDelete = false;
  1682. // if we want to take a copy, we also don't want to delete
  1683. // Note: after this point, the permissionToTakeCopy flag
  1684. // becomes irrelevant. It already includes the permissionToTake
  1685. // permission and after excluding no copy items here, we can
  1686. // just use that.
  1687. if (action == DeRezAction.TakeCopy)
  1688. {
  1689. // If we don't have permission, stop right here
  1690. if (!permissionToTakeCopy)
  1691. return;
  1692. permissionToTake = true;
  1693. // Don't delete
  1694. permissionToDelete = false;
  1695. }
  1696. if (action == DeRezAction.Return)
  1697. {
  1698. if (remoteClient != null)
  1699. {
  1700. if (Permissions.CanReturnObjects(
  1701. null,
  1702. remoteClient.AgentId,
  1703. deleteGroups))
  1704. {
  1705. permissionToTake = true;
  1706. permissionToDelete = true;
  1707. foreach (SceneObjectGroup g in deleteGroups)
  1708. {
  1709. AddReturn(g.OwnerID == g.GroupID ? g.LastOwnerID : g.OwnerID, g.Name, g.AbsolutePosition, "parcel owner return");
  1710. }
  1711. }
  1712. }
  1713. else // Auto return passes through here with null agent
  1714. {
  1715. permissionToTake = true;
  1716. permissionToDelete = true;
  1717. }
  1718. }
  1719. if (permissionToTake)
  1720. {
  1721. m_asyncSceneObjectDeleter.DeleteToInventory(
  1722. action, destinationID, deleteGroups, remoteClient,
  1723. permissionToDelete);
  1724. }
  1725. else if (permissionToDelete)
  1726. {
  1727. foreach (SceneObjectGroup g in deleteGroups)
  1728. DeleteSceneObject(g, false);
  1729. }
  1730. }
  1731. /// <summary>
  1732. /// Event Handler Rez an object into a scene
  1733. /// Calls the non-void event handler
  1734. /// </summary>
  1735. /// <param name="remoteClient"></param>
  1736. /// <param name="itemID"></param>
  1737. /// <param name="RayEnd"></param>
  1738. /// <param name="RayStart"></param>
  1739. /// <param name="RayTargetID"></param>
  1740. /// <param name="BypassRayCast"></param>
  1741. /// <param name="RayEndIsIntersection"></param>
  1742. /// <param name="EveryoneMask"></param>
  1743. /// <param name="GroupMask"></param>
  1744. /// <param name="RezSelected"></param>
  1745. /// <param name="RemoveItem"></param>
  1746. /// <param name="fromTaskID"></param>
  1747. public virtual void RezObject(IClientAPI remoteClient, UUID itemID, Vector3 RayEnd, Vector3 RayStart,
  1748. UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
  1749. bool RezSelected, bool RemoveItem, UUID fromTaskID)
  1750. {
  1751. // m_log.DebugFormat(
  1752. // "[PRIM INVENTORY]: RezObject from {0} for item {1} from task id {2}",
  1753. // remoteClient.Name, itemID, fromTaskID);
  1754. if (fromTaskID == UUID.Zero)
  1755. {
  1756. IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
  1757. if (invAccess != null)
  1758. invAccess.RezObject(
  1759. remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection,
  1760. RezSelected, RemoveItem, fromTaskID, false);
  1761. }
  1762. else
  1763. {
  1764. SceneObjectPart part = GetSceneObjectPart(fromTaskID);
  1765. if (part == null)
  1766. {
  1767. m_log.ErrorFormat(
  1768. "[TASK INVENTORY]: {0} tried to rez item id {1} from object id {2} but there is no such scene object",
  1769. remoteClient.Name, itemID, fromTaskID);
  1770. return;
  1771. }
  1772. TaskInventoryItem item = part.Inventory.GetInventoryItem(itemID);
  1773. if (item == null)
  1774. {
  1775. m_log.ErrorFormat(
  1776. "[TASK INVENTORY]: {0} tried to rez item id {1} from object id {2} but there is no such item",
  1777. remoteClient.Name, itemID, fromTaskID);
  1778. return;
  1779. }
  1780. byte bRayEndIsIntersection = (byte)(RayEndIsIntersection ? 1 : 0);
  1781. Vector3 scale = new Vector3(0.5f, 0.5f, 0.5f);
  1782. Vector3 pos
  1783. = GetNewRezLocation(
  1784. RayStart, RayEnd, RayTargetID, Quaternion.Identity,
  1785. BypassRayCast, bRayEndIsIntersection, true, scale, false);
  1786. RezObject(part, item, pos, null, Vector3.Zero, 0);
  1787. }
  1788. }
  1789. /// <summary>
  1790. /// Rez an object into the scene from a prim's inventory.
  1791. /// </summary>
  1792. /// <param name="sourcePart"></param>
  1793. /// <param name="item"></param>
  1794. /// <param name="pos">The position of the rezzed object.</param>
  1795. /// <param name="rot">The rotation of the rezzed object. If null, then the rotation stored with the object
  1796. /// will be used if it exists.</param>
  1797. /// <param name="vel">The velocity of the rezzed object.</param>
  1798. /// <param name="param"></param>
  1799. /// <returns>The SceneObjectGroup rezzed or null if rez was unsuccessful</returns>
  1800. public virtual SceneObjectGroup RezObject(
  1801. SceneObjectPart sourcePart, TaskInventoryItem item, Vector3 pos, Quaternion? rot, Vector3 vel, int param)
  1802. {
  1803. if (null == item)
  1804. return null;
  1805. SceneObjectGroup group = sourcePart.Inventory.GetRezReadySceneObject(item);
  1806. if (null == group)
  1807. return null;
  1808. if (!Permissions.CanRezObject(group.PrimCount, item.OwnerID, pos))
  1809. return null;
  1810. if (!Permissions.BypassPermissions())
  1811. {
  1812. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  1813. sourcePart.Inventory.RemoveInventoryItem(item.ItemID);
  1814. }
  1815. AddNewSceneObject(group, true, pos, rot, vel);
  1816. // We can only call this after adding the scene object, since the scene object references the scene
  1817. // to find out if scripts should be activated at all.
  1818. group.CreateScriptInstances(param, true, DefaultScriptEngine, 3);
  1819. group.ScheduleGroupForFullUpdate();
  1820. return group;
  1821. }
  1822. public virtual bool returnObjects(SceneObjectGroup[] returnobjects,
  1823. UUID AgentId)
  1824. {
  1825. List<uint> localIDs = new List<uint>();
  1826. foreach (SceneObjectGroup grp in returnobjects)
  1827. {
  1828. AddReturn(grp.OwnerID, grp.Name, grp.AbsolutePosition,
  1829. "parcel owner return");
  1830. localIDs.Add(grp.RootPart.LocalId);
  1831. }
  1832. DeRezObjects(null, localIDs, UUID.Zero, DeRezAction.Return,
  1833. UUID.Zero);
  1834. return true;
  1835. }
  1836. public void SetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID, bool running)
  1837. {
  1838. SceneObjectPart part = GetSceneObjectPart(objectID);
  1839. if (part == null)
  1840. return;
  1841. if (running)
  1842. EventManager.TriggerStartScript(part.LocalId, itemID);
  1843. else
  1844. EventManager.TriggerStopScript(part.LocalId, itemID);
  1845. }
  1846. public void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID)
  1847. {
  1848. EventManager.TriggerGetScriptRunning(controllingClient, objectID, itemID);
  1849. }
  1850. void ObjectOwner(IClientAPI remoteClient, UUID ownerID, UUID groupID, List<uint> localIDs)
  1851. {
  1852. if (!Permissions.IsGod(remoteClient.AgentId))
  1853. {
  1854. if (ownerID != UUID.Zero)
  1855. return;
  1856. if (!Permissions.CanDeedObject(remoteClient.AgentId, groupID))
  1857. return;
  1858. }
  1859. List<SceneObjectGroup> groups = new List<SceneObjectGroup>();
  1860. foreach (uint localID in localIDs)
  1861. {
  1862. SceneObjectPart part = GetSceneObjectPart(localID);
  1863. if (part == null)
  1864. continue;
  1865. if (!groups.Contains(part.ParentGroup))
  1866. groups.Add(part.ParentGroup);
  1867. }
  1868. foreach (SceneObjectGroup sog in groups)
  1869. {
  1870. if (ownerID != UUID.Zero)
  1871. {
  1872. sog.SetOwnerId(ownerID);
  1873. sog.SetGroup(groupID, remoteClient);
  1874. sog.ScheduleGroupForFullUpdate();
  1875. SceneObjectPart[] partList = sog.Parts;
  1876. foreach (SceneObjectPart child in partList)
  1877. {
  1878. child.Inventory.ChangeInventoryOwner(ownerID);
  1879. child.TriggerScriptChangedEvent(Changed.OWNER);
  1880. }
  1881. }
  1882. else
  1883. {
  1884. if (!Permissions.CanEditObject(sog.UUID, remoteClient.AgentId))
  1885. continue;
  1886. if (sog.GroupID != groupID)
  1887. continue;
  1888. SceneObjectPart[] partList = sog.Parts;
  1889. foreach (SceneObjectPart child in partList)
  1890. {
  1891. child.LastOwnerID = child.OwnerID;
  1892. child.Inventory.ChangeInventoryOwner(groupID);
  1893. child.TriggerScriptChangedEvent(Changed.OWNER);
  1894. }
  1895. sog.SetOwnerId(groupID);
  1896. sog.ApplyNextOwnerPermissions();
  1897. }
  1898. }
  1899. foreach (uint localID in localIDs)
  1900. {
  1901. SceneObjectPart part = GetSceneObjectPart(localID);
  1902. if (part == null)
  1903. continue;
  1904. part.SendPropertiesToClient(remoteClient);
  1905. }
  1906. }
  1907. public void DelinkObjects(List<uint> primIds, IClientAPI client)
  1908. {
  1909. List<SceneObjectPart> parts = new List<SceneObjectPart>();
  1910. foreach (uint localID in primIds)
  1911. {
  1912. SceneObjectPart part = GetSceneObjectPart(localID);
  1913. if (part == null)
  1914. continue;
  1915. if (Permissions.CanDelinkObject(client.AgentId, part.ParentGroup.RootPart.UUID))
  1916. parts.Add(part);
  1917. }
  1918. m_sceneGraph.DelinkObjects(parts);
  1919. }
  1920. /// <summary>
  1921. /// Link the scene objects containing the indicated parts to a root object.
  1922. /// </summary>
  1923. /// <param name="client"></param>
  1924. /// <param name="parentPrimId">A root prim id of the object which will be the root prim of the resulting linkset.</param>
  1925. /// <param name="childPrimIds">A list of child prims for the objects that should be linked in.</param>
  1926. public void LinkObjects(IClientAPI client, uint parentPrimId, List<uint> childPrimIds)
  1927. {
  1928. LinkObjects(client.AgentId, parentPrimId, childPrimIds);
  1929. }
  1930. /// <summary>
  1931. /// Link the scene objects containing the indicated parts to a root object.
  1932. /// </summary>
  1933. /// <param name="agentId">The ID of the user linking.</param>
  1934. /// <param name="parentPrimId">A root prim id of the object which will be the root prim of the resulting linkset.</param>
  1935. /// <param name="childPrimIds">A list of child prims for the objects that should be linked in.</param>
  1936. public void LinkObjects(UUID agentId, uint parentPrimId, List<uint> childPrimIds)
  1937. {
  1938. List<UUID> owners = new List<UUID>();
  1939. List<SceneObjectPart> children = new List<SceneObjectPart>();
  1940. SceneObjectPart root = GetSceneObjectPart(parentPrimId);
  1941. if (root == null)
  1942. {
  1943. m_log.DebugFormat("[LINK]: Can't find linkset root prim {0}", parentPrimId);
  1944. return;
  1945. }
  1946. if (!Permissions.CanLinkObject(agentId, root.ParentGroup.RootPart.UUID))
  1947. {
  1948. m_log.DebugFormat("[LINK]: Refusing link. No permissions on root prim");
  1949. return;
  1950. }
  1951. foreach (uint localID in childPrimIds)
  1952. {
  1953. SceneObjectPart part = GetSceneObjectPart(localID);
  1954. if (part == null)
  1955. continue;
  1956. if (!owners.Contains(part.OwnerID))
  1957. owners.Add(part.OwnerID);
  1958. if (Permissions.CanLinkObject(agentId, part.ParentGroup.RootPart.UUID))
  1959. children.Add(part);
  1960. }
  1961. // Must be all one owner
  1962. //
  1963. if (owners.Count > 1)
  1964. {
  1965. m_log.DebugFormat("[LINK]: Refusing link. Too many owners");
  1966. return;
  1967. }
  1968. if (children.Count == 0)
  1969. {
  1970. m_log.DebugFormat("[LINK]: Refusing link. No permissions to link any of the children");
  1971. return;
  1972. }
  1973. m_sceneGraph.LinkObjects(root, children);
  1974. }
  1975. private string PermissionString(uint permissions)
  1976. {
  1977. PermissionMask perms = (PermissionMask)permissions &
  1978. (PermissionMask.Move |
  1979. PermissionMask.Copy |
  1980. PermissionMask.Transfer |
  1981. PermissionMask.Modify);
  1982. return perms.ToString();
  1983. }
  1984. }
  1985. }