Scene.Inventory.cs 101 KB

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