Scene.Inventory.cs 124 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884
  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.Threading;
  33. using System.Timers;
  34. using System.Xml;
  35. using OpenMetaverse;
  36. using OpenMetaverse.Packets;
  37. using log4net;
  38. using OpenSim.Framework;
  39. using OpenSim.Framework.Serialization.External;
  40. using OpenSim.Region.Framework;
  41. using OpenSim.Framework.Client;
  42. using OpenSim.Region.Framework.Interfaces;
  43. using OpenSim.Region.Framework.Scenes.Serialization;
  44. using OpenSim.Services.Interfaces;
  45. using PermissionMask = OpenSim.Framework.PermissionMask;
  46. namespace OpenSim.Region.Framework.Scenes
  47. {
  48. public partial class Scene
  49. {
  50. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  51. //private static readonly string LogHeader = "[SCENE INVENTORY]";
  52. /// <summary>
  53. /// Allows asynchronous derezzing of objects from the scene into a client's inventory.
  54. /// </summary>
  55. protected AsyncSceneObjectGroupDeleter m_asyncSceneObjectDeleter;
  56. /// <summary>
  57. /// Allows inventory details to be sent to clients asynchronously
  58. /// </summary>
  59. protected AsyncInventorySender m_asyncInventorySender;
  60. /// <summary>
  61. /// Creates all the scripts in the scene which should be started.
  62. /// </summary>
  63. /// <returns>
  64. /// Number of scripts that were valid for starting. This does not guarantee that all these scripts
  65. /// were actually started, but just that the start could be attempt (e.g. the asset data for the script could be found)
  66. /// </returns>
  67. public int CreateScriptInstances()
  68. {
  69. m_log.InfoFormat("[SCENE]: Initializing script instances in {0}", RegionInfo.RegionName);
  70. int scriptsValidForStarting = 0;
  71. EntityBase[] entities = Entities.GetEntities();
  72. foreach (EntityBase group in entities)
  73. {
  74. if (group is SceneObjectGroup)
  75. {
  76. scriptsValidForStarting
  77. += ((SceneObjectGroup) group).CreateScriptInstances(0, false, DefaultScriptEngine, 0);
  78. ((SceneObjectGroup) group).ResumeScripts();
  79. }
  80. }
  81. m_log.InfoFormat(
  82. "[SCENE]: Initialized {0} script instances in {1}",
  83. scriptsValidForStarting, RegionInfo.RegionName);
  84. return scriptsValidForStarting;
  85. }
  86. /// <summary>
  87. /// Lets the script engines start processing scripts.
  88. /// </summary>
  89. public void StartScripts()
  90. {
  91. // m_log.InfoFormat("[SCENE]: Starting scripts in {0}, please wait.", RegionInfo.RegionName);
  92. IScriptModule[] engines = RequestModuleInterfaces<IScriptModule>();
  93. foreach (IScriptModule engine in engines)
  94. engine.StartProcessing();
  95. }
  96. public void AddUploadedInventoryItem(UUID agentID, InventoryItemBase item, uint cost)
  97. {
  98. IMoneyModule money = RequestModuleInterface<IMoneyModule>();
  99. if (money != null)
  100. {
  101. money.ApplyUploadCharge(agentID, (int)cost, "Asset upload");
  102. }
  103. AddInventoryItem(item);
  104. }
  105. public bool AddInventoryItemReturned(UUID AgentId, InventoryItemBase item)
  106. {
  107. if (AddInventoryItem(item))
  108. return true;
  109. else
  110. {
  111. m_log.WarnFormat(
  112. "[AGENT INVENTORY]: Unable to add item {1} to agent {2} inventory", item.Name, AgentId);
  113. return false;
  114. }
  115. }
  116. public bool AddInventoryItem(InventoryItemBase item)
  117. {
  118. return AddInventoryItem(item, true);
  119. }
  120. /// <summary>
  121. /// Add the given inventory item to a user's inventory.
  122. /// </summary>
  123. /// <param name="item"></param>
  124. public bool AddInventoryItem(InventoryItemBase item, bool trigger)
  125. {
  126. if (item.Folder != UUID.Zero && InventoryService.AddItem(item))
  127. {
  128. int userlevel = 0;
  129. if (Permissions.IsGod(item.Owner))
  130. {
  131. userlevel = 1;
  132. }
  133. if (trigger)
  134. EventManager.TriggerOnNewInventoryItemUploadComplete(item, userlevel);
  135. return true;
  136. }
  137. // OK so either the viewer didn't send a folderID or AddItem failed
  138. UUID originalFolder = item.Folder;
  139. InventoryFolderBase f = null;
  140. if (Enum.IsDefined(typeof(FolderType), (sbyte)item.AssetType))
  141. f = InventoryService.GetFolderForType(item.Owner, (FolderType)item.AssetType);
  142. if (f != null)
  143. {
  144. m_log.DebugFormat(
  145. "[AGENT INVENTORY]: Found folder {0} type {1} for item {2}",
  146. f.Name, (AssetType)f.Type, item.Name);
  147. item.Folder = f.ID;
  148. }
  149. else
  150. {
  151. f = InventoryService.GetRootFolder(item.Owner);
  152. if (f != null)
  153. {
  154. item.Folder = f.ID;
  155. }
  156. else
  157. {
  158. m_log.WarnFormat(
  159. "[AGENT INVENTORY]: Could not find root folder for {0} when trying to add item {1} with no parent folder specified",
  160. item.Owner, item.Name);
  161. return false;
  162. }
  163. }
  164. if (InventoryService.AddItem(item))
  165. {
  166. int userlevel = 0;
  167. if (Permissions.IsGod(item.Owner))
  168. {
  169. userlevel = 1;
  170. }
  171. if (trigger)
  172. EventManager.TriggerOnNewInventoryItemUploadComplete(item, userlevel);
  173. if (originalFolder != UUID.Zero)
  174. {
  175. // Tell the viewer that the item didn't go there
  176. ChangePlacement(item, f);
  177. }
  178. return true;
  179. }
  180. else
  181. {
  182. m_log.WarnFormat(
  183. "[AGENT INVENTORY]: Agent {0} could not add item {1} {2}",
  184. item.Owner, item.Name, item.ID);
  185. return false;
  186. }
  187. }
  188. private void ChangePlacement(InventoryItemBase item, InventoryFolderBase f)
  189. {
  190. ScenePresence sp = GetScenePresence(item.Owner);
  191. if (sp != null)
  192. {
  193. if (sp.ControllingClient is IClientCore)
  194. {
  195. IClientCore core = (IClientCore)sp.ControllingClient;
  196. IClientInventory inv;
  197. if (core.TryGet<IClientInventory>(out inv))
  198. {
  199. InventoryFolderBase parent = InventoryService.GetFolder(f.Owner, f.ParentID);
  200. inv.SendRemoveInventoryItems(new UUID[] { item.ID });
  201. inv.SendBulkUpdateInventory(new InventoryFolderBase[0], new InventoryItemBase[] { item });
  202. string message = "The item was placed in folder " + f.Name;
  203. if (parent != null)
  204. message += " under " + parent.Name;
  205. sp.ControllingClient.SendAgentAlertMessage(message, false);
  206. }
  207. }
  208. }
  209. }
  210. /// <summary>
  211. /// Add the given inventory item to a user's inventory.
  212. /// </summary>
  213. /// <param name="AgentID">
  214. /// A <see cref="UUID"/>
  215. /// </param>
  216. /// <param name="item">
  217. /// A <see cref="InventoryItemBase"/>
  218. /// </param>
  219. [Obsolete("Use AddInventoryItem(InventoryItemBase item) instead. This was deprecated in OpenSim 0.7.1")]
  220. public void AddInventoryItem(UUID AgentID, InventoryItemBase item)
  221. {
  222. AddInventoryItem(item);
  223. }
  224. /// <summary>
  225. /// Add an inventory item to an avatar's inventory.
  226. /// </summary>
  227. /// <param name="remoteClient">The remote client controlling the avatar</param>
  228. /// <param name="item">The item. This structure contains all the item metadata, including the folder
  229. /// in which the item is to be placed.</param>
  230. public void AddInventoryItem(IClientAPI remoteClient, InventoryItemBase item)
  231. {
  232. AddInventoryItem(item);
  233. remoteClient.SendInventoryItemCreateUpdate(item, 0);
  234. }
  235. /// <summary>
  236. /// <see>CapsUpdatedInventoryItemAsset(IClientAPI, UUID, byte[])</see>
  237. /// </summary>
  238. public UUID CapsUpdateInventoryItemAsset(UUID avatarId, UUID itemID, byte[] data)
  239. {
  240. ScenePresence avatar;
  241. if (TryGetScenePresence(avatarId, out avatar))
  242. {
  243. IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
  244. if (invAccess != null)
  245. return invAccess.CapsUpdateInventoryItemAsset(avatar.ControllingClient, itemID, data);
  246. }
  247. else
  248. {
  249. m_log.ErrorFormat(
  250. "[AGENT INVENTORY]: " +
  251. "Avatar {0} cannot be found to update its inventory item asset",
  252. avatarId);
  253. }
  254. return UUID.Zero;
  255. }
  256. /// <summary>
  257. /// Capability originating call to update the asset of a script in a prim's (task's) inventory
  258. /// </summary>
  259. /// <param name="remoteClient"></param>
  260. /// <param name="itemID"></param>
  261. /// <param name="primID">The prim which contains the item to update</param>
  262. /// <param name="isScriptRunning">Indicates whether the script to update is currently running</param>
  263. /// <param name="data"></param>
  264. public ArrayList CapsUpdateTaskInventoryScriptAsset(IClientAPI remoteClient, UUID itemId,
  265. UUID primId, bool isScriptRunning, byte[] data)
  266. {
  267. if (!Permissions.CanEditScript(itemId, primId, remoteClient.AgentId))
  268. {
  269. remoteClient.SendAgentAlertMessage("Insufficient permissions to edit script", false);
  270. return new ArrayList();
  271. }
  272. // Retrieve group
  273. SceneObjectPart part = GetSceneObjectPart(primId);
  274. if (part == null)
  275. return new ArrayList();
  276. SceneObjectGroup group = part.ParentGroup;
  277. // Retrieve item
  278. TaskInventoryItem item = group.GetInventoryItem(part.LocalId, itemId);
  279. if (null == item)
  280. {
  281. m_log.ErrorFormat(
  282. "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for caps script update "
  283. + " but the item does not exist in this inventory",
  284. itemId, part.Name, part.UUID);
  285. return new ArrayList();
  286. }
  287. AssetBase asset = CreateAsset(item.Name, item.Description, (sbyte)AssetType.LSLText, data, remoteClient.AgentId);
  288. AssetService.Store(asset);
  289. // m_log.DebugFormat(
  290. // "[PRIM INVENTORY]: Stored asset {0} when updating item {1} in prim {2} for {3}",
  291. // asset.ID, item.Name, part.Name, remoteClient.Name);
  292. if (isScriptRunning)
  293. {
  294. part.Inventory.RemoveScriptInstance(item.ItemID, false);
  295. }
  296. // Update item with new asset
  297. item.AssetID = asset.FullID;
  298. group.UpdateInventoryItem(item);
  299. group.InvalidateEffectivePerms();
  300. part.SendPropertiesToClient(remoteClient);
  301. // Trigger rerunning of script (use TriggerRezScript event, see RezScript)
  302. ArrayList errors = new ArrayList();
  303. if (isScriptRunning)
  304. {
  305. // Needs to determine which engine was running it and use that
  306. //
  307. errors = part.Inventory.CreateScriptInstanceEr(item.ItemID, 0, false, DefaultScriptEngine, 1);
  308. }
  309. // Tell anyone managing scripts that a script has been reloaded/changed
  310. EventManager.TriggerUpdateScript(remoteClient.AgentId, itemId, primId, isScriptRunning, item.AssetID);
  311. part.ParentGroup.ResumeScripts();
  312. return errors;
  313. }
  314. /// <summary>
  315. /// <see>CapsUpdateTaskInventoryScriptAsset(IClientAPI, UUID, UUID, bool, byte[])</see>
  316. /// </summary>
  317. public ArrayList CapsUpdateTaskInventoryScriptAsset(UUID avatarId, UUID itemId,
  318. UUID primId, bool isScriptRunning, byte[] data)
  319. {
  320. ScenePresence avatar;
  321. if (TryGetScenePresence(avatarId, out avatar))
  322. {
  323. return CapsUpdateTaskInventoryScriptAsset(
  324. avatar.ControllingClient, itemId, primId, isScriptRunning, data);
  325. }
  326. else
  327. {
  328. m_log.ErrorFormat(
  329. "[PRIM INVENTORY]: " +
  330. "Avatar {0} cannot be found to update its prim item asset",
  331. avatarId);
  332. return new ArrayList();
  333. }
  334. }
  335. /// <summary>
  336. /// Update an item which is either already in the client's inventory or is within
  337. /// a transaction
  338. /// </summary>
  339. /// <param name="remoteClient"></param>
  340. /// <param name="transactionID">The transaction ID. If this is UUID.Zero we will
  341. /// assume that we are not in a transaction</param>
  342. /// <param name="itemID">The ID of the updated item</param>
  343. /// <param name="name">The name of the updated item</param>
  344. /// <param name="description">The description of the updated item</param>
  345. /// <param name="nextOwnerMask">The permissions of the updated item</param>
  346. /* public void UpdateInventoryItemAsset(IClientAPI remoteClient, UUID transactionID,
  347. UUID itemID, string name, string description,
  348. uint nextOwnerMask)*/
  349. public void UpdateInventoryItemAsset(IClientAPI remoteClient, UUID transactionID,
  350. UUID itemID, InventoryItemBase itemUpd)
  351. {
  352. // m_log.DebugFormat(
  353. // "[USER INVENTORY]: Updating asset for item {0} {1}, transaction ID {2} for {3}",
  354. // itemID, itemUpd.Name, transactionID, remoteClient.Name);
  355. // This one will let people set next perms on items in agent
  356. // inventory. Rut-Roh. Whatever. Make this secure. Yeah.
  357. //
  358. // Passing something to another avatar or a an object will already
  359. InventoryItemBase item = InventoryService.GetItem(remoteClient.AgentId, itemID);
  360. if (item != null)
  361. {
  362. if (item.Owner != remoteClient.AgentId)
  363. return;
  364. item.Flags = (item.Flags & ~(uint)255) | (itemUpd.Flags & (uint)255);
  365. item.Name = itemUpd.Name;
  366. item.Description = itemUpd.Description;
  367. // m_log.DebugFormat(
  368. // "[USER INVENTORY]: itemUpd {0} {1} {2} {3}, item {4} {5} {6} {7}",
  369. // itemUpd.NextPermissions, itemUpd.GroupPermissions, itemUpd.EveryOnePermissions, item.Flags,
  370. // item.NextPermissions, item.GroupPermissions, item.EveryOnePermissions, item.CurrentPermissions);
  371. bool sendUpdate = false;
  372. if (itemUpd.NextPermissions != 0) // Use this to determine validity. Can never be 0 if valid
  373. {
  374. // Create a set of base permissions that will not include export if the user
  375. // is not allowed to change the export flag.
  376. bool denyExportChange = false;
  377. // m_log.DebugFormat("[XXX]: B: {0} O: {1} E: {2}", itemUpd.BasePermissions, itemUpd.CurrentPermissions, itemUpd.EveryOnePermissions);
  378. // If the user is not the creator or doesn't have "E" in both "B" and "O", deny setting export
  379. if ((item.BasePermissions & (uint)(PermissionMask.All | PermissionMask.Export)) != (uint)(PermissionMask.All | PermissionMask.Export) || (item.CurrentPermissions & (uint)PermissionMask.Export) == 0 || item.CreatorIdAsUuid != item.Owner)
  380. denyExportChange = true;
  381. // m_log.DebugFormat("[XXX]: Deny Export Update {0}", denyExportChange);
  382. // If it is already set, force it set and also force full perm
  383. // else prevent setting it. It can and should never be set unless
  384. // set in base, so the condition above is valid
  385. if (denyExportChange)
  386. {
  387. // If we are not allowed to change it, then force it to the
  388. // original item's setting and if it was on, also force full perm
  389. if ((item.EveryOnePermissions & (uint)PermissionMask.Export) != 0)
  390. {
  391. itemUpd.NextPermissions = (uint)(PermissionMask.All);
  392. itemUpd.EveryOnePermissions |= (uint)PermissionMask.Export;
  393. }
  394. else
  395. {
  396. itemUpd.EveryOnePermissions &= ~(uint)PermissionMask.Export;
  397. }
  398. }
  399. else
  400. {
  401. // If the new state is exportable, force full perm
  402. if ((itemUpd.EveryOnePermissions & (uint)PermissionMask.Export) != 0)
  403. {
  404. // m_log.DebugFormat("[XXX]: Force full perm");
  405. itemUpd.NextPermissions = (uint)(PermissionMask.All);
  406. }
  407. }
  408. if (item.NextPermissions != (itemUpd.NextPermissions & item.BasePermissions))
  409. item.Flags |= (uint)InventoryItemFlags.ObjectOverwriteNextOwner;
  410. item.NextPermissions = itemUpd.NextPermissions & item.BasePermissions;
  411. if (item.EveryOnePermissions != (itemUpd.EveryOnePermissions & item.BasePermissions))
  412. item.Flags |= (uint)InventoryItemFlags.ObjectOverwriteEveryone;
  413. item.EveryOnePermissions = itemUpd.EveryOnePermissions & item.BasePermissions;
  414. if (item.GroupPermissions != (itemUpd.GroupPermissions & item.BasePermissions))
  415. item.Flags |= (uint)InventoryItemFlags.ObjectOverwriteGroup;
  416. item.GroupPermissions = itemUpd.GroupPermissions & item.BasePermissions;
  417. item.GroupID = itemUpd.GroupID;
  418. item.GroupOwned = itemUpd.GroupOwned;
  419. item.CreationDate = itemUpd.CreationDate;
  420. // The client sends zero if its newly created?
  421. if (itemUpd.CreationDate == 0)
  422. item.CreationDate = Util.UnixTimeSinceEpoch();
  423. else
  424. item.CreationDate = itemUpd.CreationDate;
  425. // TODO: Check if folder changed and move item
  426. //item.NextPermissions = itemUpd.Folder;
  427. item.InvType = itemUpd.InvType;
  428. if (item.SalePrice != itemUpd.SalePrice ||
  429. item.SaleType != itemUpd.SaleType)
  430. item.Flags |= (uint)InventoryItemFlags.ObjectSlamSale;
  431. item.SalePrice = itemUpd.SalePrice;
  432. item.SaleType = itemUpd.SaleType;
  433. if (item.InvType == (int)InventoryType.Wearable && (item.Flags & 0xf) == 0 && (itemUpd.Flags & 0xf) != 0)
  434. {
  435. item.Flags = (uint)(item.Flags & 0xfffffff0) | (itemUpd.Flags & 0xf);
  436. sendUpdate = true;
  437. }
  438. InventoryService.UpdateItem(item);
  439. }
  440. if (UUID.Zero != transactionID)
  441. {
  442. if (AgentTransactionsModule != null)
  443. {
  444. AgentTransactionsModule.HandleItemUpdateFromTransaction(remoteClient, transactionID, item);
  445. }
  446. }
  447. else
  448. {
  449. // This MAY be problematic, if it is, another solution
  450. // needs to be found. If inventory item flags are updated
  451. // the viewer's notion of the item needs to be refreshed.
  452. //
  453. // In other situations we cannot send out a bulk update here, since this will cause editing of clothing to start
  454. // failing frequently. Possibly this is a race with a separate transaction that uploads the asset.
  455. if (sendUpdate)
  456. remoteClient.SendBulkUpdateInventory(item);
  457. }
  458. }
  459. else
  460. {
  461. m_log.ErrorFormat(
  462. "[AGENTINVENTORY]: Item id {0} not found for an inventory item update for {1}.",
  463. itemID, remoteClient.Name);
  464. }
  465. }
  466. /// <summary>
  467. /// Give an inventory item from one user to another
  468. /// </summary>
  469. /// <param name="recipientClient"></param>
  470. /// <param name="senderId">ID of the sender of the item</param>
  471. /// <param name="itemId"></param>
  472. public virtual void GiveInventoryItem(IClientAPI recipientClient, UUID senderId, UUID itemId, out string message)
  473. {
  474. InventoryItemBase itemCopy = GiveInventoryItem(recipientClient.AgentId, senderId, itemId, out message);
  475. if (itemCopy != null)
  476. recipientClient.SendBulkUpdateInventory(itemCopy);
  477. }
  478. /// <summary>
  479. /// Give an inventory item from one user to another
  480. /// </summary>
  481. /// <param name="recipient"></param>
  482. /// <param name="senderId">ID of the sender of the item</param>
  483. /// <param name="itemId"></param>
  484. /// <returns>The inventory item copy given, null if the give was unsuccessful</returns>
  485. public virtual InventoryItemBase GiveInventoryItem(UUID recipient, UUID senderId, UUID itemId, out string message)
  486. {
  487. return GiveInventoryItem(recipient, senderId, itemId, UUID.Zero, out message);
  488. }
  489. /// <summary>
  490. /// Give an inventory item from one user to another
  491. /// </summary>
  492. /// <param name="recipient"></param>
  493. /// <param name="senderId">ID of the sender of the item</param>
  494. /// <param name="itemId"></param>
  495. /// <param name="recipientFolderId">
  496. /// The id of the folder in which the copy item should go. If UUID.Zero then the item is placed in the most
  497. /// appropriate default folder.
  498. /// </param>
  499. /// <returns>
  500. /// The inventory item copy given, null if the give was unsuccessful
  501. /// </returns>
  502. public virtual InventoryItemBase GiveInventoryItem(
  503. UUID recipient, UUID senderId, UUID itemId, UUID recipientFolderId, out string message)
  504. {
  505. //Console.WriteLine("Scene.Inventory.cs: GiveInventoryItem");
  506. if (!Permissions.CanTransferUserInventory(itemId, senderId, recipient))
  507. {
  508. message = "Not allowed to transfer this item.";
  509. return null;
  510. }
  511. InventoryItemBase item = InventoryService.GetItem(senderId, itemId);
  512. if (item == null)
  513. {
  514. m_log.WarnFormat(
  515. "[AGENT INVENTORY]: Failed to find item {0} sent by {1} to {2}", itemId, senderId, recipient);
  516. message = string.Format("Item not found: {0}.", itemId);
  517. return null;
  518. }
  519. if (item.Owner != senderId)
  520. {
  521. m_log.WarnFormat(
  522. "[AGENT INVENTORY]: Attempt to send item {0} {1} to {2} failed because sender {3} did not match item owner {4}",
  523. item.Name, item.ID, recipient, senderId, item.Owner);
  524. message = "Sender did not match item owner.";
  525. return null;
  526. }
  527. IUserManagement uman = RequestModuleInterface<IUserManagement>();
  528. if (uman != null)
  529. uman.AddUser(item.CreatorIdAsUuid, item.CreatorData);
  530. if (!Permissions.BypassPermissions())
  531. {
  532. if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
  533. {
  534. message = "Item doesn't have the Transfer permission.";
  535. return null;
  536. }
  537. }
  538. // Insert a copy of the item into the recipient
  539. InventoryItemBase itemCopy = new InventoryItemBase();
  540. itemCopy.Owner = recipient;
  541. itemCopy.CreatorId = item.CreatorId;
  542. itemCopy.CreatorData = item.CreatorData;
  543. itemCopy.ID = UUID.Random();
  544. itemCopy.AssetID = item.AssetID;
  545. itemCopy.Description = item.Description;
  546. itemCopy.Name = item.Name;
  547. itemCopy.AssetType = item.AssetType;
  548. itemCopy.InvType = item.InvType;
  549. itemCopy.Folder = recipientFolderId;
  550. itemCopy.Flags = item.Flags;
  551. if (Permissions.PropagatePermissions() && recipient != senderId)
  552. {
  553. // Trying to do this right this time. This is evil. If
  554. // you believe in Good, go elsewhere. Vampires and other
  555. // evil creatores only beyond this point. You have been
  556. // warned.
  557. // We're going to mask a lot of things by the next perms
  558. // Tweak the next perms to be nicer to our data
  559. //
  560. // In this mask, all the bits we do NOT want to mess
  561. // with are set. These are:
  562. //
  563. // Transfer
  564. // Copy
  565. // Modify
  566. uint permsMask = ~ ((uint)PermissionMask.Copy |
  567. (uint)PermissionMask.Transfer |
  568. (uint)PermissionMask.Modify |
  569. (uint)PermissionMask.Export);
  570. // Now, reduce the next perms to the mask bits
  571. // relevant to the operation
  572. uint nextPerms = permsMask | (item.NextPermissions &
  573. ((uint)PermissionMask.Copy |
  574. (uint)PermissionMask.Transfer |
  575. (uint)PermissionMask.Modify));
  576. // nextPerms now has all bits set, except for the actual
  577. // next permission bits.
  578. // This checks for no mod, no copy, no trans.
  579. // This indicates an error or messed up item. Do it like
  580. // SL and assume trans
  581. if (nextPerms == permsMask)
  582. nextPerms |= (uint)PermissionMask.Transfer;
  583. // Inventory owner perms are the logical AND of the
  584. // folded perms and the root prim perms, however, if
  585. // the root prim is mod, the inventory perms will be
  586. // mod. This happens on "take" and is of little concern
  587. // here, save for preventing escalation
  588. // This hack ensures that items previously permalocked
  589. // get unlocked when they're passed or rezzed
  590. uint basePerms = item.BasePermissions |
  591. (uint)PermissionMask.Move;
  592. uint ownerPerms = item.CurrentPermissions;
  593. // These will be applied to the root prim at next rez.
  594. // The legacy slam bit (bit 3) and folded permission (bits 0-2)
  595. // are preserved due to the above mangling
  596. // ownerPerms &= nextPerms;
  597. // Mask the base permissions. This is a conservative
  598. // approach altering only the three main perms
  599. // basePerms &= nextPerms;
  600. // Mask out the folded portion of the base mask.
  601. // While the owner mask carries the actual folded
  602. // permissions, the base mask carries the original
  603. // base mask, before masking with the folded perms.
  604. // We need this later for rezzing.
  605. // basePerms &= ~(uint)PermissionMask.FoldedMask;
  606. // basePerms |= ((basePerms >> 13) & 7) | (((basePerms & (uint)PermissionMask.Export) != 0) ? (uint)PermissionMask.FoldedExport : 0);
  607. // If this is an object, root prim perms may be more
  608. // permissive than folded perms. Use folded perms as
  609. // a mask
  610. uint foldedPerms = (item.CurrentPermissions & (uint)PermissionMask.FoldedMask) << (int)PermissionMask.FoldingShift;
  611. if (foldedPerms != 0 && item.InvType == (int)InventoryType.Object)
  612. {
  613. foldedPerms |= permsMask;
  614. bool isRootMod = (item.CurrentPermissions &
  615. (uint)PermissionMask.Modify) != 0 ?
  616. true : false;
  617. // Mask the owner perms to the folded perms
  618. // Note that this is only to satisfy the viewer.
  619. // The effect of this will be reversed on rez.
  620. ownerPerms &= foldedPerms;
  621. basePerms &= foldedPerms;
  622. // If the root was mod, let the mask reflect that
  623. // We also need to adjust the base here, because
  624. // we should be able to edit in-inventory perms
  625. // for the root prim, if it's mod.
  626. if (isRootMod)
  627. {
  628. ownerPerms |= (uint)PermissionMask.Modify;
  629. basePerms |= (uint)PermissionMask.Modify;
  630. }
  631. }
  632. // move here so nextperms are mandatory
  633. ownerPerms &= nextPerms;
  634. basePerms &= nextPerms;
  635. basePerms &= ~(uint)PermissionMask.FoldedMask;
  636. basePerms |= ((basePerms >> 13) & 7) | (((basePerms & (uint)PermissionMask.Export) != 0) ? (uint)PermissionMask.FoldedExport : 0);
  637. // Assign to the actual item. Make sure the slam bit is
  638. // set, if it wasn't set before.
  639. itemCopy.BasePermissions = basePerms;
  640. itemCopy.CurrentPermissions = ownerPerms;
  641. itemCopy.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm;
  642. // Need to clear the other inventory slam options.
  643. // That is so we can handle the case where the recipient
  644. // changes the bits in inventory before rezzing
  645. itemCopy.Flags &= ~(uint)(InventoryItemFlags.ObjectOverwriteBase | InventoryItemFlags.ObjectOverwriteOwner | InventoryItemFlags.ObjectOverwriteGroup | InventoryItemFlags.ObjectOverwriteEveryone | InventoryItemFlags.ObjectOverwriteNextOwner);
  646. itemCopy.NextPermissions = item.NextPermissions;
  647. // This preserves "everyone can move"
  648. itemCopy.EveryOnePermissions = item.EveryOnePermissions &
  649. nextPerms;
  650. // Intentionally killing "share with group" here, as
  651. // the recipient will not have the group this is
  652. // set to
  653. itemCopy.GroupPermissions = 0;
  654. }
  655. else
  656. {
  657. itemCopy.CurrentPermissions = item.CurrentPermissions;
  658. itemCopy.NextPermissions = item.NextPermissions;
  659. itemCopy.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions;
  660. itemCopy.GroupPermissions = item.GroupPermissions & item.NextPermissions;
  661. itemCopy.BasePermissions = item.BasePermissions;
  662. }
  663. if (itemCopy.Folder == UUID.Zero)
  664. {
  665. InventoryFolderBase folder = null;
  666. if (Enum.IsDefined(typeof(FolderType), (sbyte)item.AssetType))
  667. folder = InventoryService.GetFolderForType(recipient, (FolderType)itemCopy.AssetType);
  668. if (folder != null)
  669. {
  670. itemCopy.Folder = folder.ID;
  671. }
  672. else
  673. {
  674. InventoryFolderBase root = InventoryService.GetRootFolder(recipient);
  675. if (root != null)
  676. {
  677. itemCopy.Folder = root.ID;
  678. }
  679. else
  680. {
  681. message = "Can't find a folder to add the item to.";
  682. return null;
  683. }
  684. }
  685. }
  686. itemCopy.GroupID = UUID.Zero;
  687. itemCopy.GroupOwned = false;
  688. itemCopy.SalePrice = 0; //item.SalePrice;
  689. itemCopy.SaleType = 0; //item.SaleType;
  690. IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
  691. if (invAccess != null)
  692. invAccess.TransferInventoryAssets(itemCopy, senderId, recipient);
  693. AddInventoryItem(itemCopy, false);
  694. if (!Permissions.BypassPermissions())
  695. {
  696. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  697. {
  698. List<UUID> items = new List<UUID>();
  699. items.Add(itemId);
  700. InventoryService.DeleteItems(senderId, items);
  701. }
  702. }
  703. message = null;
  704. return itemCopy;
  705. }
  706. /// <summary>
  707. /// Give an entire inventory folder from one user to another. The entire contents (including all descendent
  708. /// folders) is given.
  709. /// </summary>
  710. /// <param name="recipientId"></param>
  711. /// <param name="senderId">ID of the sender of the item</param>
  712. /// <param name="folderId"></param>
  713. /// <param name="recipientParentFolderId">
  714. /// The id of the receipient folder in which the send folder should be placed. If UUID.Zero then the
  715. /// recipient folder is the root folder
  716. /// </param>
  717. /// <returns>
  718. /// The inventory folder copy given, null if the copy was unsuccessful
  719. /// </returns>
  720. public virtual InventoryFolderBase GiveInventoryFolder(IClientAPI client,
  721. UUID recipientId, UUID senderId, UUID folderId, UUID recipientParentFolderId)
  722. {
  723. //// Retrieve the folder from the sender
  724. InventoryFolderBase folder = InventoryService.GetFolder(senderId, folderId);
  725. if (null == folder)
  726. {
  727. m_log.ErrorFormat(
  728. "[AGENT INVENTORY]: Could not find inventory folder {0} to give", folderId);
  729. return null;
  730. }
  731. if (recipientParentFolderId == UUID.Zero)
  732. {
  733. InventoryFolderBase recipientRootFolder = InventoryService.GetRootFolder(recipientId);
  734. if (recipientRootFolder != null)
  735. recipientParentFolderId = recipientRootFolder.ID;
  736. else
  737. {
  738. m_log.WarnFormat("[AGENT INVENTORY]: Unable to find root folder for receiving agent");
  739. return null;
  740. }
  741. }
  742. UUID newFolderId = UUID.Random();
  743. InventoryFolderBase newFolder
  744. = new InventoryFolderBase(
  745. newFolderId, folder.Name, recipientId, folder.Type, recipientParentFolderId, folder.Version);
  746. InventoryService.AddFolder(newFolder);
  747. // Give all the subfolders
  748. InventoryCollection contents = InventoryService.GetFolderContent(senderId, folderId);
  749. foreach (InventoryFolderBase childFolder in contents.Folders)
  750. {
  751. GiveInventoryFolder(client, recipientId, senderId, childFolder.ID, newFolder.ID);
  752. }
  753. // Give all the items
  754. foreach (InventoryItemBase item in contents.Items)
  755. {
  756. string message;
  757. if (GiveInventoryItem(recipientId, senderId, item.ID, newFolder.ID, out message) == null)
  758. {
  759. if (client != null)
  760. client.SendAgentAlertMessage(message, false);
  761. }
  762. }
  763. return newFolder;
  764. }
  765. public void CopyInventoryItem(IClientAPI remoteClient, uint callbackID, UUID oldAgentID, UUID oldItemID,
  766. UUID newFolderID, string newName)
  767. {
  768. m_log.DebugFormat(
  769. "[AGENT INVENTORY]: CopyInventoryItem received by {0} with oldAgentID {1}, oldItemID {2}, new FolderID {3}, newName {4}",
  770. remoteClient.AgentId, oldAgentID, oldItemID, newFolderID, newName);
  771. InventoryItemBase item = null;
  772. if (LibraryService != null && LibraryService.LibraryRootFolder != null)
  773. item = LibraryService.LibraryRootFolder.FindItem(oldItemID);
  774. if (item == null)
  775. {
  776. item = InventoryService.GetItem(remoteClient.AgentId, oldItemID);
  777. if (item == null)
  778. {
  779. m_log.Error("[AGENT INVENTORY]: Failed to find item " + oldItemID.ToString());
  780. return;
  781. }
  782. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  783. return;
  784. }
  785. if (newName == String.Empty)
  786. newName = item.Name;
  787. AssetBase asset = AssetService.Get(item.AssetID.ToString());
  788. if (asset != null)
  789. {
  790. if (newName != String.Empty)
  791. {
  792. asset.Name = newName;
  793. }
  794. else
  795. {
  796. newName = item.Name;
  797. }
  798. if (remoteClient.AgentId == oldAgentID
  799. || (LibraryService != null
  800. && LibraryService.LibraryRootFolder != null
  801. && oldAgentID == LibraryService.LibraryRootFolder.Owner))
  802. {
  803. CreateNewInventoryItem(
  804. remoteClient, item.CreatorId, item.CreatorData, newFolderID,
  805. newName, item.Description, item.Flags, callbackID, item.AssetID, (sbyte)item.AssetType, (sbyte)item.InvType,
  806. item.BasePermissions, item.CurrentPermissions, item.EveryOnePermissions,
  807. item.NextPermissions, item.GroupPermissions, Util.UnixTimeSinceEpoch(), false);
  808. }
  809. else
  810. {
  811. // If item is transfer or permissions are off or calling agent is allowed to copy item owner's inventory item.
  812. if (((item.CurrentPermissions & (uint)PermissionMask.Transfer) != 0)
  813. && (m_permissions.BypassPermissions()
  814. || m_permissions.CanCopyUserInventory(remoteClient.AgentId, oldItemID)))
  815. {
  816. CreateNewInventoryItem(
  817. remoteClient, item.CreatorId, item.CreatorData, newFolderID, newName, item.Description, item.Flags, callbackID,
  818. item.AssetID, (sbyte)item.AssetType, (sbyte) item.InvType,
  819. item.NextPermissions, item.NextPermissions, item.EveryOnePermissions & item.NextPermissions,
  820. item.NextPermissions, item.GroupPermissions, Util.UnixTimeSinceEpoch(), false);
  821. }
  822. }
  823. }
  824. else
  825. {
  826. m_log.ErrorFormat(
  827. "[AGENT INVENTORY]: Could not copy item {0} since asset {1} could not be found",
  828. item.Name, item.AssetID);
  829. }
  830. }
  831. /// <summary>
  832. /// Create a new asset data structure.
  833. /// </summary>
  834. public AssetBase CreateAsset(string name, string description, sbyte assetType, byte[] data, UUID creatorID)
  835. {
  836. AssetBase asset = new AssetBase(UUID.Random(), name, assetType, creatorID.ToString());
  837. asset.Description = description;
  838. asset.Data = (data == null) ? new byte[1] : data;
  839. return asset;
  840. }
  841. /// <summary>
  842. /// Move an item within the agent's inventory, and leave a copy (used in making a new outfit)
  843. /// </summary>
  844. public void MoveInventoryItemsLeaveCopy(IClientAPI remoteClient, List<InventoryItemBase> items, UUID destfolder)
  845. {
  846. List<InventoryItemBase> moveitems = new List<InventoryItemBase>();
  847. foreach (InventoryItemBase b in items)
  848. {
  849. CopyInventoryItem(remoteClient, 0, remoteClient.AgentId, b.ID, b.Folder, null);
  850. InventoryItemBase n = InventoryService.GetItem(b.Owner, b.ID);
  851. n.Folder = destfolder;
  852. moveitems.Add(n);
  853. remoteClient.SendInventoryItemCreateUpdate(n, 0);
  854. }
  855. MoveInventoryItem(remoteClient, moveitems);
  856. }
  857. /// <summary>
  858. /// Move an item within the agent's inventory.
  859. /// </summary>
  860. /// <param name="remoteClient"></param>
  861. /// <param name="folderID"></param>
  862. /// <param name="itemID"></param>
  863. /// <param name="length"></param>
  864. /// <param name="newName"></param>
  865. public void MoveInventoryItem(IClientAPI remoteClient, List<InventoryItemBase> items)
  866. {
  867. m_log.DebugFormat(
  868. "[AGENT INVENTORY]: Moving {0} items for user {1}", items.Count, remoteClient.AgentId);
  869. if (!InventoryService.MoveItems(remoteClient.AgentId, items))
  870. m_log.Warn("[AGENT INVENTORY]: Failed to move items for user " + remoteClient.AgentId);
  871. }
  872. /// <summary>
  873. /// Create a new Inventory Item
  874. /// </summary>
  875. /// <param name="remoteClient">Client creating this inventory item.</param>
  876. /// <param name="creatorID"></param>
  877. /// <param name="creatorData"></param>
  878. /// <param name="folderID">UUID of folder in which this item should be placed.</param>
  879. /// <param name="name">Item name.</para>
  880. /// <param name="description">Item description.</param>
  881. /// <param name="flags">Item flags</param>
  882. /// <param name="callbackID">Generated by the client.</para>
  883. /// <param name="asset">Asset to which this item refers.</param>
  884. /// <param name="invType">Type of inventory item.</param>
  885. /// <param name="baseMask">Base permissions mask.</param>
  886. /// <param name="currentMask">Current permissions mask.</param>
  887. /// <param name="everyoneMask">Everyone permissions mask.</param>
  888. /// <param name="nextOwnerMask">Next owner pemrissions mask.</param>
  889. /// <param name="groupMask">Group permissions mask.</param>
  890. /// <param name="creationDate">Unix timestamp at which this item was created.</param>
  891. public void CreateNewInventoryItem(
  892. IClientAPI remoteClient, string creatorID, string creatorData, UUID folderID,
  893. string name, string description, uint flags, uint callbackID, UUID assetID, sbyte assetType, sbyte invType,
  894. uint baseMask, uint currentMask, uint everyoneMask, uint nextOwnerMask, uint groupMask, int creationDate,
  895. bool assetUpload)
  896. {
  897. InventoryItemBase item = new InventoryItemBase();
  898. item.Owner = remoteClient.AgentId;
  899. item.CreatorId = creatorID;
  900. item.CreatorData = creatorData;
  901. item.ID = UUID.Random();
  902. item.AssetID = assetID;
  903. item.Name = name;
  904. item.Description = description;
  905. item.Flags = flags;
  906. item.AssetType = assetType;
  907. item.InvType = invType;
  908. item.Folder = folderID;
  909. item.CurrentPermissions = currentMask;
  910. item.NextPermissions = nextOwnerMask;
  911. item.EveryOnePermissions = everyoneMask;
  912. item.GroupPermissions = groupMask;
  913. item.BasePermissions = baseMask;
  914. item.CreationDate = creationDate;
  915. // special AnimationSet case
  916. if (item.InvType == (int)CustomInventoryType.AnimationSet)
  917. AnimationSet.enforceItemPermitions(item,true);
  918. if (AddInventoryItem(item))
  919. {
  920. remoteClient.SendInventoryItemCreateUpdate(item, callbackID);
  921. }
  922. else
  923. {
  924. m_dialogModule.SendAlertToUser(remoteClient, "Failed to create item");
  925. m_log.WarnFormat(
  926. "Failed to add item for {0} in CreateNewInventoryItem!",
  927. remoteClient.Name);
  928. }
  929. }
  930. /// <summary>
  931. /// Link an inventory item to an existing item.
  932. /// </summary>
  933. /// <remarks>
  934. /// The linkee item id is placed in the asset id slot. This appears to be what the viewer expects when
  935. /// it receives inventory information.
  936. /// </remarks>
  937. /// <param name="remoteClient"></param>
  938. /// <param name="transActionID"></param>
  939. /// <param name="folderID"></param>
  940. /// <param name="callbackID"></param>
  941. /// <param name="description"></param>
  942. /// <param name="name"></param>
  943. /// <param name="invType"></param>
  944. /// <param name="type">/param>
  945. /// <param name="olditemID"></param>
  946. private void HandleLinkInventoryItem(IClientAPI remoteClient, UUID transActionID, UUID folderID,
  947. uint callbackID, string description, string name,
  948. sbyte invType, sbyte type, UUID olditemID)
  949. {
  950. // m_log.DebugFormat(
  951. // "[AGENT INVENTORY]: Received request from {0} to create inventory item link {1} in folder {2} pointing to {3}, assetType {4}, inventoryType {5}",
  952. // remoteClient.Name, name, folderID, olditemID, (AssetType)type, (InventoryType)invType);
  953. if (!Permissions.CanCreateUserInventory(invType, remoteClient.AgentId))
  954. return;
  955. ScenePresence presence;
  956. if (TryGetScenePresence(remoteClient.AgentId, out presence))
  957. {
  958. // Disabled the check for duplicate links.
  959. //
  960. // When outfits are being adjusted, the viewer rapidly sends delete link messages followed by
  961. // create links. However, since these are handled asynchronously, the deletes do not complete before
  962. // the creates are handled. Therefore, we cannot enforce a duplicate link check.
  963. // InventoryItemBase existingLink = null;
  964. // List<InventoryItemBase> existingItems = InventoryService.GetFolderItems(remoteClient.AgentId, folderID);
  965. // foreach (InventoryItemBase item in existingItems)
  966. // if (item.AssetID == olditemID)
  967. // existingLink = item;
  968. //
  969. // if (existingLink != null)
  970. // {
  971. // m_log.WarnFormat(
  972. // "[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",
  973. // remoteClient.Name, name, folderID, olditemID, existingLink.Name, existingLink.ID);
  974. //
  975. // return;
  976. // }
  977. CreateNewInventoryItem(
  978. remoteClient, remoteClient.AgentId.ToString(), string.Empty, folderID,
  979. name, description, 0, callbackID, olditemID, type, invType,
  980. (uint)PermissionMask.All | (uint)PermissionMask.Export, (uint)PermissionMask.All | (uint)PermissionMask.Export, (uint)PermissionMask.All,
  981. (uint)PermissionMask.All | (uint)PermissionMask.Export, (uint)PermissionMask.All | (uint)PermissionMask.Export, Util.UnixTimeSinceEpoch(),
  982. false);
  983. }
  984. else
  985. {
  986. m_log.ErrorFormat(
  987. "ScenePresence for agent uuid {0} unexpectedly not found in HandleLinkInventoryItem",
  988. remoteClient.AgentId);
  989. }
  990. }
  991. /// <summary>
  992. /// Remove an inventory item for the client's inventory
  993. /// </summary>
  994. /// <param name="remoteClient"></param>
  995. /// <param name="itemID"></param>
  996. private void RemoveInventoryItem(IClientAPI remoteClient, List<UUID> itemIDs)
  997. {
  998. // m_log.DebugFormat(
  999. // "[AGENT INVENTORY]: Removing inventory items {0} for {1}",
  1000. // string.Join(",", itemIDs.ConvertAll<string>(uuid => uuid.ToString()).ToArray()),
  1001. // remoteClient.Name);
  1002. InventoryService.DeleteItems(remoteClient.AgentId, itemIDs);
  1003. }
  1004. /// <summary>
  1005. /// Removes an inventory folder. This packet is sent when the user
  1006. /// right-clicks a folder that's already in trash and chooses "purge"
  1007. /// </summary>
  1008. /// <param name="remoteClient"></param>
  1009. /// <param name="folderID"></param>
  1010. private void RemoveInventoryFolder(IClientAPI remoteClient, List<UUID> folderIDs)
  1011. {
  1012. m_log.DebugFormat("[SCENE INVENTORY]: RemoveInventoryFolders count {0}", folderIDs.Count);
  1013. InventoryService.DeleteFolders(remoteClient.AgentId, folderIDs);
  1014. }
  1015. /// <summary>
  1016. /// Send the details of a prim's inventory to the client.
  1017. /// </summary>
  1018. /// <param name="remoteClient"></param>
  1019. /// <param name="primLocalID"></param>
  1020. public void RequestTaskInventory(IClientAPI remoteClient, uint primLocalID)
  1021. {
  1022. SceneObjectPart part = GetSceneObjectPart(primLocalID);
  1023. if (part == null)
  1024. return;
  1025. if (XferManager != null)
  1026. part.Inventory.RequestInventoryFile(remoteClient, XferManager);
  1027. }
  1028. /// <summary>
  1029. /// Remove an item from a prim (task) inventory
  1030. /// </summary>
  1031. /// <param name="remoteClient">Unused at the moment but retained since the avatar ID might
  1032. /// be necessary for a permissions check at some stage.</param>
  1033. /// <param name="itemID"></param>
  1034. /// <param name="localID"></param>
  1035. public void RemoveTaskInventory(IClientAPI remoteClient, UUID itemID, uint localID)
  1036. {
  1037. SceneObjectPart part = GetSceneObjectPart(localID);
  1038. SceneObjectGroup group = null;
  1039. if (part != null)
  1040. {
  1041. group = part.ParentGroup;
  1042. }
  1043. if (part != null && group != null)
  1044. {
  1045. if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId))
  1046. return;
  1047. TaskInventoryItem item = group.GetInventoryItem(localID, itemID);
  1048. if (item == null)
  1049. return;
  1050. InventoryFolderBase destFolder = InventoryService.GetFolderForType(remoteClient.AgentId, FolderType.Trash);
  1051. // Move the item to trash. If this is a copyable item, only
  1052. // a copy will be moved and we will still need to delete
  1053. // the item from the prim. If it was no copy, it will be
  1054. // deleted by this method.
  1055. string message;
  1056. InventoryItemBase item2 = MoveTaskInventoryItem(remoteClient, destFolder.ID, part, itemID, out message);
  1057. if (item2 == null)
  1058. {
  1059. m_log.WarnFormat("[SCENE INVENTORY]: RemoveTaskInventory of item {0} failed: {1}", itemID, message);
  1060. remoteClient.SendAgentAlertMessage(message, false);
  1061. return;
  1062. }
  1063. if (group.GetInventoryItem(localID, itemID) != null)
  1064. {
  1065. if (item.Type == (int)InventoryType.LSL)
  1066. {
  1067. part.RemoveScriptEvents(itemID);
  1068. part.ParentGroup.AddActiveScriptCount(-1);
  1069. }
  1070. group.RemoveInventoryItem(localID, itemID);
  1071. group.InvalidateEffectivePerms();
  1072. }
  1073. part.SendPropertiesToClient(remoteClient);
  1074. }
  1075. }
  1076. /// <summary>
  1077. /// Creates (in memory only) a user inventory item that will contain a copy of a task inventory item.
  1078. /// </summary>
  1079. private InventoryItemBase CreateAgentInventoryItemFromTask(UUID destAgent, SceneObjectPart part, UUID itemId, out string message)
  1080. {
  1081. TaskInventoryItem taskItem = part.Inventory.GetInventoryItem(itemId);
  1082. if (null == taskItem)
  1083. {
  1084. m_log.ErrorFormat(
  1085. "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for creating an avatar"
  1086. + " inventory item from a prim's inventory item "
  1087. + " but the required item does not exist in the prim's inventory",
  1088. itemId, part.Name, part.UUID);
  1089. message = "Item not found: " + itemId;
  1090. return null;
  1091. }
  1092. if ((destAgent != taskItem.OwnerID) && ((taskItem.CurrentPermissions & (uint)PermissionMask.Transfer) == 0))
  1093. {
  1094. message = "Item doesn't have the Transfer permission.";
  1095. return null;
  1096. }
  1097. InventoryItemBase agentItem = new InventoryItemBase();
  1098. agentItem.ID = UUID.Random();
  1099. agentItem.CreatorId = taskItem.CreatorID.ToString();
  1100. agentItem.CreatorData = taskItem.CreatorData;
  1101. agentItem.Owner = destAgent;
  1102. agentItem.AssetID = taskItem.AssetID;
  1103. agentItem.Description = taskItem.Description;
  1104. agentItem.Name = taskItem.Name;
  1105. agentItem.AssetType = taskItem.Type;
  1106. agentItem.InvType = taskItem.InvType;
  1107. agentItem.Flags = taskItem.Flags;
  1108. // The code below isn't OK. It doesn't account for flags being changed
  1109. // in the object inventory, so it will break when you do it. That
  1110. // is the previous behaviour, so no matter at this moment. However, there is a lot
  1111. // TODO: Fix this after the inventory fixer exists and has beenr run
  1112. if ((part.OwnerID != destAgent) && Permissions.PropagatePermissions())
  1113. {
  1114. uint perms = taskItem.BasePermissions & taskItem.NextPermissions;
  1115. if (taskItem.InvType == (int)InventoryType.Object)
  1116. {
  1117. PermissionsUtil.ApplyFoldedPermissions(taskItem.CurrentPermissions, ref perms );
  1118. perms = PermissionsUtil.FixAndFoldPermissions(perms);
  1119. }
  1120. else
  1121. perms &= taskItem.CurrentPermissions;
  1122. // always unlock
  1123. perms |= (uint)PermissionMask.Move;
  1124. agentItem.BasePermissions = perms;
  1125. agentItem.CurrentPermissions = perms;
  1126. agentItem.NextPermissions = perms & taskItem.NextPermissions;
  1127. agentItem.EveryOnePermissions = perms & taskItem.EveryonePermissions;
  1128. agentItem.GroupPermissions = perms & taskItem.GroupPermissions;
  1129. agentItem.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm;
  1130. agentItem.Flags &= ~(uint)(InventoryItemFlags.ObjectOverwriteBase | InventoryItemFlags.ObjectOverwriteOwner | InventoryItemFlags.ObjectOverwriteGroup | InventoryItemFlags.ObjectOverwriteEveryone | InventoryItemFlags.ObjectOverwriteNextOwner);
  1131. }
  1132. else
  1133. {
  1134. agentItem.BasePermissions = taskItem.BasePermissions;
  1135. agentItem.CurrentPermissions = taskItem.CurrentPermissions;
  1136. agentItem.NextPermissions = taskItem.NextPermissions;
  1137. agentItem.EveryOnePermissions = taskItem.EveryonePermissions;
  1138. agentItem.GroupPermissions = taskItem.GroupPermissions;
  1139. }
  1140. message = null;
  1141. return agentItem;
  1142. }
  1143. /// <summary>
  1144. /// If the task item is not-copyable then remove it from the prim.
  1145. /// </summary>
  1146. private void RemoveNonCopyTaskItemFromPrim(SceneObjectPart part, UUID itemId)
  1147. {
  1148. TaskInventoryItem taskItem = part.Inventory.GetInventoryItem(itemId);
  1149. if (taskItem == null)
  1150. return;
  1151. if (!Permissions.BypassPermissions())
  1152. {
  1153. if ((taskItem.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  1154. {
  1155. if (taskItem.Type == (int)AssetType.LSLText)
  1156. {
  1157. part.RemoveScriptEvents(itemId);
  1158. part.ParentGroup.AddActiveScriptCount(-1);
  1159. }
  1160. part.Inventory.RemoveInventoryItem(itemId);
  1161. }
  1162. }
  1163. }
  1164. /// <summary>
  1165. /// Move the given item in the given prim to a folder in the client's inventory
  1166. /// </summary>
  1167. /// <param name="remoteClient"></param>
  1168. /// <param name="folderID"></param>
  1169. /// <param name="part"></param>
  1170. /// <param name="itemID"></param>
  1171. public InventoryItemBase MoveTaskInventoryItem(IClientAPI remoteClient, UUID folderId, SceneObjectPart part, UUID itemId, out string message)
  1172. {
  1173. m_log.DebugFormat(
  1174. "[PRIM INVENTORY]: Adding item {0} from {1} to folder {2} for {3}",
  1175. itemId, part.Name, folderId, remoteClient.Name);
  1176. InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(remoteClient.AgentId, part, itemId, out message);
  1177. if (agentItem == null)
  1178. return null;
  1179. agentItem.Folder = folderId;
  1180. AddInventoryItem(remoteClient, agentItem);
  1181. RemoveNonCopyTaskItemFromPrim(part, itemId);
  1182. message = null;
  1183. return agentItem;
  1184. }
  1185. /// <summary>
  1186. /// <see>ClientMoveTaskInventoryItem</see>
  1187. /// </summary>
  1188. /// <param name="remoteClient"></param>
  1189. /// <param name="folderID"></param>
  1190. /// <param name="primLocalID"></param>
  1191. /// <param name="itemID"></param>
  1192. public void ClientMoveTaskInventoryItem(IClientAPI remoteClient, UUID folderId, uint primLocalId, UUID itemId)
  1193. {
  1194. SceneObjectPart part = GetSceneObjectPart(primLocalId);
  1195. // Can't move a null item
  1196. if (itemId == UUID.Zero)
  1197. return;
  1198. if (null == part)
  1199. {
  1200. m_log.WarnFormat(
  1201. "[PRIM INVENTORY]: " +
  1202. "Move of inventory item {0} from prim with local id {1} failed because the prim could not be found",
  1203. itemId, primLocalId);
  1204. return;
  1205. }
  1206. TaskInventoryItem taskItem = part.Inventory.GetInventoryItem(itemId);
  1207. if (null == taskItem)
  1208. {
  1209. m_log.WarnFormat("[PRIM INVENTORY]: Move of inventory item {0} from prim with local id {1} failed"
  1210. + " because the inventory item could not be found",
  1211. itemId, primLocalId);
  1212. return;
  1213. }
  1214. if (!Permissions.CanCopyObjectInventory(itemId, part.UUID, remoteClient.AgentId))
  1215. return;
  1216. string message;
  1217. InventoryItemBase item = MoveTaskInventoryItem(remoteClient, folderId, part, itemId, out message);
  1218. if (item == null)
  1219. remoteClient.SendAgentAlertMessage(message, false);
  1220. }
  1221. /// <summary>
  1222. /// <see>MoveTaskInventoryItem</see>
  1223. /// </summary>
  1224. /// <param name="remoteClient"></param>
  1225. /// <param name="folderID">
  1226. /// The user inventory folder to move (or copy) the item to. If null, then the most
  1227. /// suitable system folder is used (e.g. the Objects folder for objects). If there is no suitable folder, then
  1228. /// the item is placed in the user's root inventory folder
  1229. /// </param>
  1230. /// <param name="part"></param>
  1231. /// <param name="itemID"></param>
  1232. public InventoryItemBase MoveTaskInventoryItem(UUID avatarId, UUID folderId, SceneObjectPart part, UUID itemId, out string message)
  1233. {
  1234. ScenePresence avatar;
  1235. if (TryGetScenePresence(avatarId, out avatar))
  1236. {
  1237. return MoveTaskInventoryItem(avatar.ControllingClient, folderId, part, itemId, out message);
  1238. }
  1239. else
  1240. {
  1241. InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(avatarId, part, itemId, out message);
  1242. if (agentItem == null)
  1243. return null;
  1244. agentItem.Folder = folderId;
  1245. AddInventoryItem(agentItem);
  1246. RemoveNonCopyTaskItemFromPrim(part, itemId);
  1247. return agentItem;
  1248. }
  1249. }
  1250. /// <summary>
  1251. /// Copy a task (prim) inventory item to another task (prim)
  1252. /// </summary>
  1253. /// <param name="destId">ID of destination part</param>
  1254. /// <param name="part">Source part</param>
  1255. /// <param name="itemId">Source item id to transfer</param>
  1256. public void MoveTaskInventoryItem(UUID destId, SceneObjectPart part, UUID itemId)
  1257. {
  1258. TaskInventoryItem srcTaskItem = part.Inventory.GetInventoryItem(itemId);
  1259. if (srcTaskItem == null)
  1260. {
  1261. m_log.ErrorFormat(
  1262. "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for moving"
  1263. + " but the item does not exist in this inventory",
  1264. itemId, part.Name, part.UUID);
  1265. return;
  1266. }
  1267. SceneObjectPart destPart = GetSceneObjectPart(destId);
  1268. if (destPart == null)
  1269. {
  1270. m_log.ErrorFormat(
  1271. "[PRIM INVENTORY]: " +
  1272. "Could not find prim for ID {0}",
  1273. destId);
  1274. return;
  1275. }
  1276. if(!Permissions.CanDoObjectInvToObjectInv(srcTaskItem, part, destPart))
  1277. return;
  1278. TaskInventoryItem destTaskItem = new TaskInventoryItem();
  1279. destTaskItem.ItemID = UUID.Random();
  1280. destTaskItem.CreatorID = srcTaskItem.CreatorID;
  1281. destTaskItem.CreatorData = srcTaskItem.CreatorData;
  1282. destTaskItem.AssetID = srcTaskItem.AssetID;
  1283. destTaskItem.GroupID = destPart.GroupID;
  1284. destTaskItem.OwnerID = destPart.OwnerID;
  1285. destTaskItem.ParentID = destPart.UUID;
  1286. destTaskItem.ParentPartID = destPart.UUID;
  1287. destTaskItem.BasePermissions = srcTaskItem.BasePermissions;
  1288. destTaskItem.EveryonePermissions = srcTaskItem.EveryonePermissions;
  1289. destTaskItem.GroupPermissions = srcTaskItem.GroupPermissions;
  1290. destTaskItem.CurrentPermissions = srcTaskItem.CurrentPermissions;
  1291. destTaskItem.NextPermissions = srcTaskItem.NextPermissions;
  1292. destTaskItem.Flags = srcTaskItem.Flags;
  1293. if (destPart.OwnerID != part.OwnerID)
  1294. {
  1295. if (Permissions.PropagatePermissions())
  1296. {
  1297. destTaskItem.CurrentPermissions = srcTaskItem.CurrentPermissions &
  1298. (srcTaskItem.NextPermissions | (uint)PermissionMask.Move);
  1299. destTaskItem.GroupPermissions = srcTaskItem.GroupPermissions &
  1300. (srcTaskItem.NextPermissions | (uint)PermissionMask.Move);
  1301. destTaskItem.EveryonePermissions = srcTaskItem.EveryonePermissions &
  1302. (srcTaskItem.NextPermissions | (uint)PermissionMask.Move);
  1303. destTaskItem.BasePermissions = srcTaskItem.BasePermissions &
  1304. (srcTaskItem.NextPermissions | (uint)PermissionMask.Move);
  1305. destTaskItem.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm;
  1306. }
  1307. }
  1308. destTaskItem.Description = srcTaskItem.Description;
  1309. destTaskItem.Name = srcTaskItem.Name;
  1310. destTaskItem.InvType = srcTaskItem.InvType;
  1311. destTaskItem.Type = srcTaskItem.Type;
  1312. destPart.Inventory.AddInventoryItem(destTaskItem, part.OwnerID != destPart.OwnerID);
  1313. if ((srcTaskItem.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  1314. {
  1315. part.Inventory.RemoveInventoryItem(itemId);
  1316. }
  1317. ScenePresence avatar;
  1318. if (TryGetScenePresence(srcTaskItem.OwnerID, out avatar))
  1319. {
  1320. destPart.SendPropertiesToClient(avatar.ControllingClient);
  1321. }
  1322. }
  1323. public UUID MoveTaskInventoryItems(UUID destID, string category, SceneObjectPart host, List<UUID> items)
  1324. {
  1325. ScenePresence avatar;
  1326. IClientAPI remoteClient = null;
  1327. if (TryGetScenePresence(destID, out avatar))
  1328. remoteClient = avatar.ControllingClient;
  1329. // ????
  1330. SceneObjectPart destPart = GetSceneObjectPart(destID);
  1331. if (destPart != null) // Move into a prim
  1332. {
  1333. foreach(UUID itemID in items)
  1334. MoveTaskInventoryItem(destID, host, itemID);
  1335. return destID; // Prim folder ID == prim ID
  1336. }
  1337. // /????
  1338. InventoryFolderBase rootFolder = InventoryService.GetRootFolder(destID);
  1339. UUID newFolderID = UUID.Random();
  1340. InventoryFolderBase newFolder = new InventoryFolderBase(newFolderID, category, destID, -1, rootFolder.ID, rootFolder.Version);
  1341. InventoryService.AddFolder(newFolder);
  1342. foreach (UUID itemID in items)
  1343. {
  1344. string message;
  1345. InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(destID, host, itemID, out message);
  1346. if (agentItem != null)
  1347. {
  1348. agentItem.Folder = newFolderID;
  1349. AddInventoryItem(agentItem);
  1350. RemoveNonCopyTaskItemFromPrim(host, itemID);
  1351. }
  1352. else
  1353. {
  1354. if (remoteClient != null)
  1355. remoteClient.SendAgentAlertMessage(message, false);
  1356. }
  1357. }
  1358. if (remoteClient != null)
  1359. {
  1360. SendInventoryUpdate(remoteClient, rootFolder, true, false);
  1361. SendInventoryUpdate(remoteClient, newFolder, false, true);
  1362. }
  1363. return newFolderID;
  1364. }
  1365. public void SendInventoryUpdate(IClientAPI client, InventoryFolderBase folder, bool fetchFolders, bool fetchItems)
  1366. {
  1367. if (folder == null)
  1368. return;
  1369. // TODO: This code for looking in the folder for the library should be folded somewhere else
  1370. // so that this class doesn't have to know the details (and so that multiple libraries, etc.
  1371. // can be handled transparently).
  1372. InventoryFolderImpl fold = null;
  1373. if (LibraryService != null && LibraryService.LibraryRootFolder != null)
  1374. {
  1375. if ((fold = LibraryService.LibraryRootFolder.FindFolder(folder.ID)) != null)
  1376. {
  1377. client.SendInventoryFolderDetails(
  1378. fold.Owner, folder.ID, fold.RequestListOfItems(),
  1379. fold.RequestListOfFolders(), fold.Version, fetchFolders, fetchItems);
  1380. return;
  1381. }
  1382. }
  1383. // Fetch the folder contents
  1384. InventoryCollection contents = InventoryService.GetFolderContent(client.AgentId, folder.ID);
  1385. // Fetch the folder itself to get its current version
  1386. InventoryFolderBase containingFolder = InventoryService.GetFolder(client.AgentId, folder.ID);
  1387. // m_log.DebugFormat("[AGENT INVENTORY]: Sending inventory folder contents ({0} nodes) for \"{1}\" to {2} {3}",
  1388. // contents.Folders.Count + contents.Items.Count, containingFolder.Name, client.FirstName, client.LastName);
  1389. if (containingFolder != null)
  1390. {
  1391. // If the folder requested contains links, then we need to send those folders first, otherwise the links
  1392. // will be broken in the viewer.
  1393. HashSet<UUID> linkedItemFolderIdsToSend = new HashSet<UUID>();
  1394. foreach (InventoryItemBase item in contents.Items)
  1395. {
  1396. if (item.AssetType == (int)AssetType.Link)
  1397. {
  1398. InventoryItemBase linkedItem = InventoryService.GetItem(client.AgentId, item.AssetID);
  1399. // Take care of genuinely broken links where the target doesn't exist
  1400. // HACK: Also, don't follow up links that just point to other links. In theory this is legitimate,
  1401. // but no viewer has been observed to set these up and this is the lazy way of avoiding cycles
  1402. // rather than having to keep track of every folder requested in the recursion.
  1403. if (linkedItem != null && linkedItem.AssetType != (int)AssetType.Link)
  1404. {
  1405. // We don't need to send the folder if source and destination of the link are in the same
  1406. // folder.
  1407. if (linkedItem.Folder != containingFolder.ID)
  1408. linkedItemFolderIdsToSend.Add(linkedItem.Folder);
  1409. }
  1410. }
  1411. }
  1412. foreach (UUID linkedItemFolderId in linkedItemFolderIdsToSend)
  1413. SendInventoryUpdate(client, new InventoryFolderBase(linkedItemFolderId), false, true);
  1414. client.SendInventoryFolderDetails(
  1415. client.AgentId, folder.ID, contents.Items, contents.Folders,
  1416. containingFolder.Version, fetchFolders, fetchItems);
  1417. }
  1418. }
  1419. /// <summary>
  1420. /// Update an item in a prim (task) inventory.
  1421. /// This method does not handle scripts, <see>RezScript(IClientAPI, UUID, unit)</see>
  1422. /// </summary>
  1423. /// <param name="remoteClient"></param>
  1424. /// <param name="transactionID"></param>
  1425. /// <param name="itemInfo"></param>
  1426. /// <param name="primLocalID"></param>
  1427. public void UpdateTaskInventory(IClientAPI remoteClient, UUID transactionID, TaskInventoryItem itemInfo,
  1428. uint primLocalID)
  1429. {
  1430. UUID itemID = itemInfo.ItemID;
  1431. if (itemID == UUID.Zero)
  1432. {
  1433. m_log.ErrorFormat(
  1434. "[PRIM INVENTORY]: UpdateTaskInventory called with item ID Zero on update for {1}!",
  1435. remoteClient.Name);
  1436. return;
  1437. }
  1438. // Find the prim we're dealing with
  1439. SceneObjectPart part = GetSceneObjectPart(primLocalID);
  1440. if(part == null)
  1441. {
  1442. m_log.WarnFormat(
  1443. "[PRIM INVENTORY]: " +
  1444. "Update with item {0} requested of prim {1} for {2} but this prim does not exist",
  1445. itemID, primLocalID, remoteClient.Name);
  1446. return;
  1447. }
  1448. TaskInventoryItem currentItem = part.Inventory.GetInventoryItem(itemID);
  1449. if (currentItem == null)
  1450. {
  1451. InventoryItemBase item = InventoryService.GetItem(remoteClient.AgentId, itemID);
  1452. // if not found Try library
  1453. if (item == null && LibraryService != null && LibraryService.LibraryRootFolder != null)
  1454. item = LibraryService.LibraryRootFolder.FindItem(itemID);
  1455. if(item == null)
  1456. {
  1457. m_log.ErrorFormat(
  1458. "[PRIM INVENTORY]: Could not find inventory item {0} to update for {1}!",
  1459. itemID, remoteClient.Name);
  1460. return;
  1461. }
  1462. if (!Permissions.CanDropInObjectInv(item, remoteClient, part))
  1463. return;
  1464. UUID copyID = UUID.Random();
  1465. bool modrights = Permissions.CanEditObject(part.ParentGroup, remoteClient);
  1466. part.ParentGroup.AddInventoryItem(remoteClient.AgentId, primLocalID, item, copyID, modrights);
  1467. m_log.InfoFormat(
  1468. "[PRIM INVENTORY]: Update with item {0} requested of prim {1} for {2}",
  1469. item.Name, primLocalID, remoteClient.Name);
  1470. part.SendPropertiesToClient(remoteClient);
  1471. if (!Permissions.BypassPermissions())
  1472. {
  1473. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  1474. {
  1475. List<UUID> uuids = new List<UUID>();
  1476. uuids.Add(itemID);
  1477. RemoveInventoryItem(remoteClient, uuids);
  1478. }
  1479. }
  1480. }
  1481. else // Updating existing item with new perms etc
  1482. {
  1483. // m_log.DebugFormat(
  1484. // "[PRIM INVENTORY]: Updating item {0} in {1} for UpdateTaskInventory()",
  1485. // currentItem.Name, part.Name);
  1486. if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId))
  1487. return;
  1488. // Only look for an uploaded updated asset if we are passed a transaction ID. This is only the
  1489. // case for updates uploded through UDP. Updates uploaded via a capability (e.g. a script update)
  1490. // will not pass in a transaction ID in the update message.
  1491. if (transactionID != UUID.Zero && AgentTransactionsModule != null)
  1492. {
  1493. AgentTransactionsModule.HandleTaskItemUpdateFromTransaction(
  1494. remoteClient, part, transactionID, currentItem);
  1495. // if ((InventoryType)itemInfo.InvType == InventoryType.Notecard)
  1496. // remoteClient.SendAgentAlertMessage("Notecard saved", false);
  1497. // else if ((InventoryType)itemInfo.InvType == InventoryType.LSL)
  1498. // remoteClient.SendAgentAlertMessage("Script saved", false);
  1499. // else
  1500. // remoteClient.SendAgentAlertMessage("Item saved", false);
  1501. }
  1502. // Base ALWAYS has move
  1503. currentItem.BasePermissions |= (uint)PermissionMask.Move;
  1504. itemInfo.Flags = currentItem.Flags;
  1505. // Check if we're allowed to mess with permissions
  1506. if (!Permissions.IsGod(remoteClient.AgentId)) // Not a god
  1507. {
  1508. bool noChange;
  1509. if (remoteClient.AgentId != part.OwnerID) // Not owner
  1510. {
  1511. noChange = true;
  1512. if(itemInfo.OwnerID == UUID.Zero && itemInfo.GroupID != UUID.Zero)
  1513. {
  1514. if(remoteClient.IsGroupMember(itemInfo.GroupID))
  1515. {
  1516. ulong powers = remoteClient.GetGroupPowers(itemInfo.GroupID);
  1517. if((powers & (ulong)GroupPowers.ObjectManipulate) != 0)
  1518. noChange = false;
  1519. }
  1520. }
  1521. }
  1522. else
  1523. noChange = false;
  1524. if(noChange)
  1525. {
  1526. // Friends and group members can't change any perms
  1527. itemInfo.BasePermissions = currentItem.BasePermissions;
  1528. itemInfo.EveryonePermissions = currentItem.EveryonePermissions;
  1529. itemInfo.GroupPermissions = currentItem.GroupPermissions;
  1530. itemInfo.NextPermissions = currentItem.NextPermissions;
  1531. itemInfo.CurrentPermissions = currentItem.CurrentPermissions;
  1532. }
  1533. else
  1534. {
  1535. // Owner can't change base, and can change other
  1536. // only up to base
  1537. itemInfo.BasePermissions = currentItem.BasePermissions;
  1538. if (itemInfo.EveryonePermissions != currentItem.EveryonePermissions)
  1539. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteEveryone;
  1540. if (itemInfo.GroupPermissions != currentItem.GroupPermissions)
  1541. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteGroup;
  1542. if (itemInfo.CurrentPermissions != currentItem.CurrentPermissions)
  1543. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteOwner;
  1544. if (itemInfo.NextPermissions != currentItem.NextPermissions)
  1545. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteNextOwner;
  1546. itemInfo.EveryonePermissions &= currentItem.BasePermissions;
  1547. itemInfo.GroupPermissions &= currentItem.BasePermissions;
  1548. itemInfo.CurrentPermissions &= currentItem.BasePermissions;
  1549. itemInfo.NextPermissions &= currentItem.BasePermissions;
  1550. }
  1551. }
  1552. else
  1553. {
  1554. if (itemInfo.BasePermissions != currentItem.BasePermissions)
  1555. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteBase;
  1556. if (itemInfo.EveryonePermissions != currentItem.EveryonePermissions)
  1557. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteEveryone;
  1558. if (itemInfo.GroupPermissions != currentItem.GroupPermissions)
  1559. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteGroup;
  1560. if (itemInfo.CurrentPermissions != currentItem.CurrentPermissions)
  1561. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteOwner;
  1562. if (itemInfo.NextPermissions != currentItem.NextPermissions)
  1563. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteNextOwner;
  1564. }
  1565. // Next ALWAYS has move
  1566. itemInfo.NextPermissions |= (uint)PermissionMask.Move;
  1567. if (part.Inventory.UpdateInventoryItem(itemInfo))
  1568. {
  1569. part.SendPropertiesToClient(remoteClient);
  1570. }
  1571. }
  1572. }
  1573. /// <summary>
  1574. /// Rez a script into a prim's inventory, either ex nihilo or from an existing avatar inventory
  1575. /// </summary>
  1576. /// <param name="remoteClient"></param>
  1577. /// <param name="itemBase"> </param>
  1578. /// <param name="transactionID"></param>
  1579. /// <param name="localID"></param>
  1580. public void RezScript(IClientAPI remoteClient, InventoryItemBase itemBase, UUID transactionID, uint localID)
  1581. {
  1582. SceneObjectPart partWhereRezzed;
  1583. if (itemBase.ID != UUID.Zero)
  1584. partWhereRezzed = RezScriptFromAgentInventory(remoteClient.AgentId, itemBase.ID, localID);
  1585. else
  1586. partWhereRezzed = RezNewScript(remoteClient.AgentId, itemBase);
  1587. if (partWhereRezzed != null)
  1588. partWhereRezzed.SendPropertiesToClient(remoteClient);
  1589. }
  1590. /// <summary>
  1591. /// Rez a script into a prim from an agent inventory.
  1592. /// </summary>
  1593. /// <param name="agentID"></param>
  1594. /// <param name="fromItemID"></param>
  1595. /// <param name="localID"></param>
  1596. /// <returns>The part where the script was rezzed if successful. False otherwise.</returns>
  1597. public SceneObjectPart RezScriptFromAgentInventory(UUID agentID, UUID fromItemID, uint localID)
  1598. {
  1599. UUID copyID = UUID.Random();
  1600. InventoryItemBase item = InventoryService.GetItem(agentID, fromItemID);
  1601. // Try library
  1602. // XXX clumsy, possibly should be one call
  1603. if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null)
  1604. {
  1605. item = LibraryService.LibraryRootFolder.FindItem(fromItemID);
  1606. }
  1607. if (item != null)
  1608. {
  1609. SceneObjectPart part = GetSceneObjectPart(localID);
  1610. if (part != null)
  1611. {
  1612. if (!Permissions.CanEditObjectInventory(part.UUID, agentID))
  1613. return null;
  1614. part.ParentGroup.AddInventoryItem(agentID, localID, item, copyID);
  1615. // TODO: switch to posting on_rez here when scripts
  1616. // have state in inventory
  1617. part.Inventory.CreateScriptInstance(copyID, 0, false, DefaultScriptEngine, 0);
  1618. // tell anyone watching that there is a new script in town
  1619. EventManager.TriggerNewScript(agentID, part, copyID);
  1620. // m_log.InfoFormat("[PRIMINVENTORY]: " +
  1621. // "Rezzed script {0} into prim local ID {1} for user {2}",
  1622. // item.inventoryName, localID, remoteClient.Name);
  1623. part.ParentGroup.ResumeScripts();
  1624. return part;
  1625. }
  1626. else
  1627. {
  1628. m_log.ErrorFormat(
  1629. "[PRIM INVENTORY]: " +
  1630. "Could not rez script {0} into prim local ID {1} for user {2}"
  1631. + " because the prim could not be found in the region!",
  1632. item.Name, localID, agentID);
  1633. }
  1634. }
  1635. else
  1636. {
  1637. m_log.ErrorFormat(
  1638. "[PRIM INVENTORY]: Could not find script inventory item {0} to rez for {1}!",
  1639. fromItemID, agentID);
  1640. }
  1641. return null;
  1642. }
  1643. /// <summary>
  1644. /// Rez a new script from nothing.
  1645. /// </summary>
  1646. /// <param name="remoteClient"></param>
  1647. /// <param name="itemBase"></param>
  1648. /// <returns>The part where the script was rezzed if successful. False otherwise.</returns>
  1649. public SceneObjectPart RezNewScript(UUID agentID, InventoryItemBase itemBase)
  1650. {
  1651. return RezNewScript(
  1652. agentID,
  1653. itemBase,
  1654. "default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}");
  1655. }
  1656. /// <summary>
  1657. /// Rez a new script from nothing with given script text.
  1658. /// </summary>
  1659. /// <param name="remoteClient"></param>
  1660. /// <param name="itemBase">Template item.</param>
  1661. /// <param name="scriptText"></param>
  1662. /// <returns>The part where the script was rezzed if successful. False otherwise.</returns>
  1663. public SceneObjectPart RezNewScript(UUID agentID, InventoryItemBase itemBase, string scriptText)
  1664. {
  1665. // The part ID is the folder ID!
  1666. SceneObjectPart part = GetSceneObjectPart(itemBase.Folder);
  1667. if (part == null)
  1668. {
  1669. // m_log.DebugFormat(
  1670. // "[SCENE INVENTORY]: Could not find part with id {0} for {1} to rez new script",
  1671. // itemBase.Folder, agentID);
  1672. return null;
  1673. }
  1674. if (!Permissions.CanCreateObjectInventory(itemBase.InvType, part.UUID, agentID))
  1675. {
  1676. // m_log.DebugFormat(
  1677. // "[SCENE INVENTORY]: No permission to create new script in {0} for {1}", part.Name, agentID);
  1678. return null;
  1679. }
  1680. AssetBase asset
  1681. = CreateAsset(
  1682. itemBase.Name,
  1683. itemBase.Description,
  1684. (sbyte)itemBase.AssetType,
  1685. Encoding.ASCII.GetBytes(scriptText),
  1686. agentID);
  1687. AssetService.Store(asset);
  1688. TaskInventoryItem taskItem = new TaskInventoryItem();
  1689. taskItem.ResetIDs(itemBase.Folder);
  1690. taskItem.ParentID = itemBase.Folder;
  1691. taskItem.CreationDate = (uint)itemBase.CreationDate;
  1692. taskItem.Name = itemBase.Name;
  1693. taskItem.Description = itemBase.Description;
  1694. taskItem.Type = itemBase.AssetType;
  1695. taskItem.InvType = itemBase.InvType;
  1696. taskItem.OwnerID = itemBase.Owner;
  1697. taskItem.CreatorID = itemBase.CreatorIdAsUuid;
  1698. taskItem.BasePermissions = itemBase.BasePermissions;
  1699. taskItem.CurrentPermissions = itemBase.CurrentPermissions;
  1700. taskItem.EveryonePermissions = itemBase.EveryOnePermissions;
  1701. taskItem.GroupPermissions = itemBase.GroupPermissions;
  1702. taskItem.NextPermissions = itemBase.NextPermissions;
  1703. taskItem.GroupID = itemBase.GroupID;
  1704. taskItem.GroupPermissions = 0;
  1705. taskItem.Flags = itemBase.Flags;
  1706. taskItem.PermsGranter = UUID.Zero;
  1707. taskItem.PermsMask = 0;
  1708. taskItem.AssetID = asset.FullID;
  1709. part.Inventory.AddInventoryItem(taskItem, false);
  1710. part.Inventory.CreateScriptInstance(taskItem, 0, false, DefaultScriptEngine, 0);
  1711. part.ParentGroup.InvalidateEffectivePerms();
  1712. // tell anyone managing scripts that a new script exists
  1713. EventManager.TriggerNewScript(agentID, part, taskItem.ItemID);
  1714. part.ParentGroup.ResumeScripts();
  1715. return part;
  1716. }
  1717. /// <summary>
  1718. /// Rez a script into a prim's inventory from another prim
  1719. /// </summary>
  1720. /// <param name="remoteClient"></param>
  1721. /// <param name="srcPart"> </param>
  1722. /// <param name="destId"> </param>
  1723. /// <param name="pin"></param>
  1724. /// <param name="running"></param>
  1725. /// <param name="start_param"></param>
  1726. public void RezScriptFromPrim(UUID srcId, SceneObjectPart srcPart, UUID destId, int pin, int running, int start_param)
  1727. {
  1728. TaskInventoryItem srcTaskItem = srcPart.Inventory.GetInventoryItem(srcId);
  1729. if (srcTaskItem == null)
  1730. {
  1731. m_log.ErrorFormat(
  1732. "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for rezzing a script but the "
  1733. + " item does not exist in this inventory",
  1734. srcId, srcPart.Name, srcPart.UUID);
  1735. return;
  1736. }
  1737. SceneObjectPart destPart = GetSceneObjectPart(destId);
  1738. if (destPart == null)
  1739. {
  1740. m_log.ErrorFormat(
  1741. "[PRIM INVENTORY]: Could not find part {0} to insert script item {1} from {2} {3} in {4}",
  1742. destId, srcId, srcPart.Name, srcPart.UUID, Name);
  1743. return;
  1744. }
  1745. // Must own the object, and have modify rights
  1746. if (srcPart.OwnerID != destPart.OwnerID)
  1747. {
  1748. // Group permissions
  1749. if ((destPart.GroupID == UUID.Zero) || (destPart.GroupID != srcPart.GroupID) ||
  1750. ((destPart.GroupMask & (uint)PermissionMask.Modify) == 0))
  1751. return;
  1752. }
  1753. else
  1754. {
  1755. if ((destPart.OwnerMask & (uint)PermissionMask.Modify) == 0)
  1756. return;
  1757. }
  1758. if (destPart.ScriptAccessPin == 0 || destPart.ScriptAccessPin != pin)
  1759. {
  1760. m_log.WarnFormat(
  1761. "[PRIM INVENTORY]: " +
  1762. "Script in object {0} : {1}, attempted to load script {2} : {3} into object {4} : {5} with invalid pin {6}",
  1763. srcPart.Name, srcId, srcTaskItem.Name, srcTaskItem.ItemID, destPart.Name, destId, pin);
  1764. // the LSL Wiki says we are supposed to shout on the DEBUG_CHANNEL -
  1765. // "Object: Task Object trying to illegally load script onto task Other_Object!"
  1766. // How do we shout from in here?
  1767. return;
  1768. }
  1769. TaskInventoryItem destTaskItem = new TaskInventoryItem();
  1770. destTaskItem.ItemID = UUID.Random();
  1771. destTaskItem.CreatorID = srcTaskItem.CreatorID;
  1772. destTaskItem.CreatorData = srcTaskItem.CreatorData;
  1773. destTaskItem.AssetID = srcTaskItem.AssetID;
  1774. destTaskItem.GroupID = destPart.GroupID;
  1775. destTaskItem.OwnerID = destPart.OwnerID;
  1776. destTaskItem.ParentID = destPart.UUID;
  1777. destTaskItem.ParentPartID = destPart.UUID;
  1778. destTaskItem.BasePermissions = srcTaskItem.BasePermissions;
  1779. destTaskItem.EveryonePermissions = srcTaskItem.EveryonePermissions;
  1780. destTaskItem.GroupPermissions = srcTaskItem.GroupPermissions;
  1781. destTaskItem.CurrentPermissions = srcTaskItem.CurrentPermissions;
  1782. destTaskItem.NextPermissions = srcTaskItem.NextPermissions;
  1783. destTaskItem.Flags = srcTaskItem.Flags;
  1784. if (destPart.OwnerID != srcPart.OwnerID)
  1785. {
  1786. if (Permissions.PropagatePermissions())
  1787. {
  1788. destTaskItem.CurrentPermissions = srcTaskItem.CurrentPermissions &
  1789. srcTaskItem.NextPermissions;
  1790. destTaskItem.GroupPermissions = srcTaskItem.GroupPermissions &
  1791. srcTaskItem.NextPermissions;
  1792. destTaskItem.EveryonePermissions = srcTaskItem.EveryonePermissions &
  1793. srcTaskItem.NextPermissions;
  1794. destTaskItem.BasePermissions = srcTaskItem.BasePermissions &
  1795. srcTaskItem.NextPermissions;
  1796. destTaskItem.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm;
  1797. }
  1798. }
  1799. destTaskItem.Description = srcTaskItem.Description;
  1800. destTaskItem.Name = srcTaskItem.Name;
  1801. destTaskItem.InvType = srcTaskItem.InvType;
  1802. destTaskItem.Type = srcTaskItem.Type;
  1803. destPart.Inventory.AddInventoryItemExclusive(destTaskItem, false);
  1804. if (running > 0)
  1805. {
  1806. destPart.Inventory.CreateScriptInstance(destTaskItem, start_param, false, DefaultScriptEngine, 0);
  1807. }
  1808. destPart.ParentGroup.ResumeScripts();
  1809. ScenePresence avatar;
  1810. if (TryGetScenePresence(srcTaskItem.OwnerID, out avatar))
  1811. {
  1812. destPart.SendPropertiesToClient(avatar.ControllingClient);
  1813. }
  1814. }
  1815. /// <summary>
  1816. /// Derez one or more objects from the scene.
  1817. /// </summary>
  1818. /// <remarks>
  1819. /// Won't actually remove the scene object in the case where the object is being copied to a user inventory.
  1820. /// </remarks>
  1821. /// <param name='remoteClient'>Client requesting derez</param>
  1822. /// <param name='localIDs'>Local ids of root parts of objects to delete.</param>
  1823. /// <param name='groupID'>Not currently used. Here because the client passes this to us.</param>
  1824. /// <param name='action'>DeRezAction</param>
  1825. /// <param name='destinationID'>User folder ID to place derezzed object</param>
  1826. public virtual void DeRezObjects(
  1827. IClientAPI remoteClient, List<uint> localIDs, UUID groupID, DeRezAction action, UUID destinationID, bool AddToReturns = true)
  1828. {
  1829. // First, see of we can perform the requested action and
  1830. // build a list of eligible objects
  1831. List<uint> deleteIDs = new List<uint>();
  1832. List<SceneObjectGroup> deleteGroups = new List<SceneObjectGroup>();
  1833. List<SceneObjectGroup> takeGroups = new List<SceneObjectGroup>();
  1834. List<SceneObjectGroup> takeDeleteGroups = new List<SceneObjectGroup>();
  1835. ScenePresence sp = null;
  1836. if(remoteClient != null)
  1837. sp = remoteClient.SceneAgent as ScenePresence;
  1838. else if(action != DeRezAction.Return)
  1839. return; // only Return can be called without a client
  1840. // Start with true for both, then remove the flags if objects
  1841. // that we can't derez are part of the selection
  1842. bool permissionToTake = true;
  1843. bool permissionToTakeCopy = true;
  1844. bool permissionToDelete = true;
  1845. foreach (uint localID in localIDs)
  1846. {
  1847. // Invalid id
  1848. SceneObjectPart part = GetSceneObjectPart(localID);
  1849. if (part == null)
  1850. {
  1851. //Client still thinks the object exists, kill it
  1852. deleteIDs.Add(localID);
  1853. continue;
  1854. }
  1855. // Already deleted by someone else
  1856. if (part.ParentGroup.IsDeleted)
  1857. {
  1858. //Client still thinks the object exists, kill it
  1859. deleteIDs.Add(localID);
  1860. continue;
  1861. }
  1862. // Can't delete child prims
  1863. if (part != part.ParentGroup.RootPart)
  1864. continue;
  1865. SceneObjectGroup grp = part.ParentGroup;
  1866. if (grp.IsAttachment)
  1867. continue;
  1868. // If child prims have invalid perms, fix them
  1869. grp.AdjustChildPrimPermissions(false);
  1870. if (remoteClient == null)
  1871. {
  1872. // Autoreturn has a null client. Nothing else does. So
  1873. // allow only returns
  1874. if (action != DeRezAction.Return)
  1875. {
  1876. m_log.WarnFormat(
  1877. "[AGENT INVENTORY]: Ignoring attempt to {0} {1} {2} without a client",
  1878. action, grp.Name, grp.UUID);
  1879. return;
  1880. }
  1881. permissionToTakeCopy = false;
  1882. }
  1883. else
  1884. {
  1885. if (action == DeRezAction.TakeCopy)
  1886. {
  1887. if (!Permissions.CanTakeCopyObject(grp, sp))
  1888. permissionToTakeCopy = false;
  1889. }
  1890. else
  1891. {
  1892. permissionToTakeCopy = false;
  1893. }
  1894. if (!Permissions.CanTakeObject(grp, sp))
  1895. permissionToTake = false;
  1896. if (!Permissions.CanDeleteObject(grp, remoteClient))
  1897. permissionToDelete = false;
  1898. }
  1899. // Handle god perms
  1900. if ((remoteClient != null) && Permissions.IsGod(remoteClient.AgentId))
  1901. {
  1902. permissionToTake = true;
  1903. permissionToTakeCopy = true;
  1904. permissionToDelete = true;
  1905. }
  1906. // If we're re-saving, we don't even want to delete
  1907. if (action == DeRezAction.SaveToExistingUserInventoryItem)
  1908. permissionToDelete = false;
  1909. // if we want to take a copy, we also don't want to delete
  1910. // Note: after this point, the permissionToTakeCopy flag
  1911. // becomes irrelevant. It already includes the permissionToTake
  1912. // permission and after excluding no copy items here, we can
  1913. // just use that.
  1914. if (action == DeRezAction.TakeCopy)
  1915. {
  1916. // If we don't have permission, stop right here
  1917. if (!permissionToTakeCopy)
  1918. {
  1919. remoteClient.SendAlertMessage("You don't have permission to take the object");
  1920. return;
  1921. }
  1922. permissionToTake = true;
  1923. // Don't delete
  1924. permissionToDelete = false;
  1925. }
  1926. if (action == DeRezAction.Return)
  1927. {
  1928. if (remoteClient != null)
  1929. {
  1930. if (Permissions.CanReturnObjects(
  1931. null,
  1932. remoteClient,
  1933. new List<SceneObjectGroup>() {grp}))
  1934. {
  1935. permissionToTake = true;
  1936. permissionToDelete = true;
  1937. if(AddToReturns)
  1938. AddReturn(grp.OwnerID == grp.GroupID ? grp.LastOwnerID : grp.OwnerID, grp.Name, grp.AbsolutePosition,
  1939. "parcel owner return");
  1940. }
  1941. }
  1942. else // Auto return passes through here with null agent
  1943. {
  1944. permissionToTake = true;
  1945. permissionToDelete = true;
  1946. }
  1947. }
  1948. if (permissionToDelete)
  1949. {
  1950. if (permissionToTake)
  1951. takeDeleteGroups.Add(grp);
  1952. else
  1953. deleteGroups.Add(grp);
  1954. deleteIDs.Add(grp.LocalId);
  1955. }
  1956. else if(permissionToTake)
  1957. takeGroups.Add(grp);
  1958. }
  1959. SendKillObject(deleteIDs);
  1960. if (takeDeleteGroups.Count > 0)
  1961. {
  1962. m_asyncSceneObjectDeleter.DeleteToInventory(
  1963. action, destinationID, takeDeleteGroups, remoteClient,
  1964. true);
  1965. }
  1966. if (takeGroups.Count > 0)
  1967. {
  1968. m_asyncSceneObjectDeleter.DeleteToInventory(
  1969. action, destinationID, takeGroups, remoteClient,
  1970. false);
  1971. }
  1972. if (deleteGroups.Count > 0)
  1973. {
  1974. foreach (SceneObjectGroup g in deleteGroups)
  1975. DeleteSceneObject(g, true);
  1976. }
  1977. }
  1978. public UUID attachObjectAssetStore(IClientAPI remoteClient, SceneObjectGroup grp, UUID AgentId, out UUID itemID)
  1979. {
  1980. itemID = UUID.Zero;
  1981. if (grp != null)
  1982. {
  1983. Vector3 inventoryStoredPosition = new Vector3(
  1984. Math.Min(grp.AbsolutePosition.X, RegionInfo.RegionSizeX - 6),
  1985. Math.Min(grp.AbsolutePosition.Y, RegionInfo.RegionSizeY - 6),
  1986. grp.AbsolutePosition.Z);
  1987. Vector3 originalPosition = grp.AbsolutePosition;
  1988. grp.AbsolutePosition = inventoryStoredPosition;
  1989. string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp);
  1990. grp.AbsolutePosition = originalPosition;
  1991. AssetBase asset = CreateAsset(
  1992. grp.GetPartName(grp.LocalId),
  1993. grp.GetPartDescription(grp.LocalId),
  1994. (sbyte)AssetType.Object,
  1995. Utils.StringToBytes(sceneObjectXml),
  1996. remoteClient.AgentId);
  1997. AssetService.Store(asset);
  1998. InventoryItemBase item = new InventoryItemBase();
  1999. item.CreatorId = grp.RootPart.CreatorID.ToString();
  2000. item.CreatorData = grp.RootPart.CreatorData;
  2001. item.Owner = remoteClient.AgentId;
  2002. item.ID = UUID.Random();
  2003. item.AssetID = asset.FullID;
  2004. item.Description = asset.Description;
  2005. item.Name = asset.Name;
  2006. item.AssetType = asset.Type;
  2007. item.InvType = (int)InventoryType.Object;
  2008. InventoryFolderBase folder = InventoryService.GetFolderForType(remoteClient.AgentId, FolderType.Object);
  2009. if (folder != null)
  2010. item.Folder = folder.ID;
  2011. else // oopsies
  2012. item.Folder = UUID.Zero;
  2013. // Set up base perms properly
  2014. uint permsBase = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify);
  2015. permsBase &= grp.RootPart.BaseMask;
  2016. permsBase |= (uint)PermissionMask.Move;
  2017. // Make sure we don't lock it
  2018. grp.RootPart.NextOwnerMask |= (uint)PermissionMask.Move;
  2019. if ((remoteClient.AgentId != grp.RootPart.OwnerID) && Permissions.PropagatePermissions())
  2020. {
  2021. item.BasePermissions = permsBase & grp.RootPart.NextOwnerMask;
  2022. item.CurrentPermissions = permsBase & grp.RootPart.NextOwnerMask;
  2023. item.NextPermissions = permsBase & grp.RootPart.NextOwnerMask;
  2024. item.EveryOnePermissions = permsBase & grp.RootPart.EveryoneMask & grp.RootPart.NextOwnerMask;
  2025. item.GroupPermissions = permsBase & grp.RootPart.GroupMask & grp.RootPart.NextOwnerMask;
  2026. }
  2027. else
  2028. {
  2029. item.BasePermissions = permsBase;
  2030. item.CurrentPermissions = permsBase & grp.RootPart.OwnerMask;
  2031. item.NextPermissions = permsBase & grp.RootPart.NextOwnerMask;
  2032. item.EveryOnePermissions = permsBase & grp.RootPart.EveryoneMask;
  2033. item.GroupPermissions = permsBase & grp.RootPart.GroupMask;
  2034. }
  2035. item.CreationDate = Util.UnixTimeSinceEpoch();
  2036. // sets itemID so client can show item as 'attached' in inventory
  2037. grp.FromItemID = item.ID;
  2038. if (AddInventoryItem(item))
  2039. remoteClient.SendInventoryItemCreateUpdate(item, 0);
  2040. else
  2041. m_dialogModule.SendAlertToUser(remoteClient, "Operation failed");
  2042. itemID = item.ID;
  2043. return item.AssetID;
  2044. }
  2045. return UUID.Zero;
  2046. }
  2047. /// <summary>
  2048. /// Returns the list of Scene Objects in an asset.
  2049. /// </summary>
  2050. /// <remarks>
  2051. /// Returns one object if the asset is a regular object, and multiple objects for a coalesced object.
  2052. /// </remarks>
  2053. /// <param name="assetData">Asset data</param>
  2054. /// <param name="isAttachment">True if the object is an attachment.</param>
  2055. /// <param name="objlist">The objects included in the asset</param>
  2056. /// <param name="veclist">Relative positions of the objects</param>
  2057. /// <param name="bbox">Bounding box of all the objects</param>
  2058. /// <param name="offsetHeight">Offset in the Z axis from the centre of the bounding box
  2059. /// to the centre of the root prim (relevant only when returning a single object)</param>
  2060. /// <returns>
  2061. /// true if returning a single object or deserialization fails, false if returning the coalesced
  2062. /// list of objects
  2063. /// </returns>
  2064. public bool GetObjectsToRez(
  2065. byte[] assetData, bool isAttachment, out List<SceneObjectGroup> objlist, out List<Vector3> veclist,
  2066. out Vector3 bbox, out float offsetHeight)
  2067. {
  2068. objlist = new List<SceneObjectGroup>();
  2069. veclist = new List<Vector3>();
  2070. bbox = Vector3.Zero;
  2071. offsetHeight = 0;
  2072. string xmlData = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(assetData));
  2073. try
  2074. {
  2075. using (XmlTextReader wrappedReader = new XmlTextReader(xmlData, XmlNodeType.Element, null))
  2076. {
  2077. using (XmlReader reader = XmlReader.Create(wrappedReader, new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment, DtdProcessing = DtdProcessing.Prohibit, XmlResolver = null }))
  2078. {
  2079. reader.Read();
  2080. bool isSingleObject = reader.Name != "CoalescedObject";
  2081. if (isSingleObject || isAttachment)
  2082. {
  2083. SceneObjectGroup g;
  2084. try
  2085. {
  2086. g = SceneObjectSerializer.FromOriginalXmlFormat(reader);
  2087. }
  2088. catch (Exception e)
  2089. {
  2090. m_log.Error("[AGENT INVENTORY]: Deserialization of xml failed ", e);
  2091. Util.LogFailedXML("[AGENT INVENTORY]:", xmlData);
  2092. g = null;
  2093. }
  2094. if (g != null)
  2095. {
  2096. objlist.Add(g);
  2097. veclist.Add(Vector3.Zero);
  2098. bbox = g.GetAxisAlignedBoundingBox(out offsetHeight);
  2099. }
  2100. return true;
  2101. }
  2102. else
  2103. {
  2104. XmlDocument doc = new XmlDocument();
  2105. doc.XmlResolver=null;
  2106. doc.LoadXml(xmlData);
  2107. XmlElement e = (XmlElement)doc.SelectSingleNode("/CoalescedObject");
  2108. XmlElement coll = (XmlElement)e;
  2109. float bx = Convert.ToSingle(coll.GetAttribute("x"));
  2110. float by = Convert.ToSingle(coll.GetAttribute("y"));
  2111. float bz = Convert.ToSingle(coll.GetAttribute("z"));
  2112. bbox = new Vector3(bx, by, bz);
  2113. offsetHeight = 0;
  2114. XmlNodeList groups = e.SelectNodes("SceneObjectGroup");
  2115. foreach (XmlNode n in groups)
  2116. {
  2117. SceneObjectGroup g = SceneObjectSerializer.FromOriginalXmlFormat(n.OuterXml);
  2118. if (g != null)
  2119. {
  2120. objlist.Add(g);
  2121. XmlElement el = (XmlElement)n;
  2122. string rawX = el.GetAttribute("offsetx");
  2123. string rawY = el.GetAttribute("offsety");
  2124. string rawZ = el.GetAttribute("offsetz");
  2125. float x = Convert.ToSingle(rawX);
  2126. float y = Convert.ToSingle(rawY);
  2127. float z = Convert.ToSingle(rawZ);
  2128. veclist.Add(new Vector3(x, y, z));
  2129. }
  2130. }
  2131. return false;
  2132. }
  2133. }
  2134. }
  2135. }
  2136. catch (Exception e)
  2137. {
  2138. m_log.Error("[AGENT INVENTORY]: Deserialization of xml failed when looking for CoalescedObject tag ", e);
  2139. Util.LogFailedXML("[AGENT INVENTORY]:", xmlData);
  2140. }
  2141. return true;
  2142. }
  2143. /// <summary>
  2144. /// Event Handler Rez an object into a scene
  2145. /// Calls the non-void event handler
  2146. /// </summary>
  2147. /// <param name="remoteClient"></param>
  2148. /// <param name="itemID"></param>
  2149. /// <param name="rezGroupID"></param>
  2150. /// <param name="RayEnd"></param>
  2151. /// <param name="RayStart"></param>
  2152. /// <param name="RayTargetID"></param>
  2153. /// <param name="BypassRayCast"></param>
  2154. /// <param name="RayEndIsIntersection"></param>
  2155. /// <param name="EveryoneMask"></param>
  2156. /// <param name="GroupMask"></param>
  2157. /// <param name="RezSelected"></param>
  2158. /// <param name="RemoveItem"></param>
  2159. /// <param name="fromTaskID"></param>
  2160. public virtual void RezObject(IClientAPI remoteClient, UUID itemID, UUID rezGroupID,
  2161. Vector3 RayEnd, Vector3 RayStart,
  2162. UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
  2163. bool RezSelected, bool RemoveItem, UUID fromTaskID)
  2164. {
  2165. // m_log.DebugFormat(
  2166. // "[PRIM INVENTORY]: RezObject from {0} for item {1} from task id {2}",
  2167. // remoteClient.Name, itemID, fromTaskID);
  2168. if (fromTaskID == UUID.Zero)
  2169. {
  2170. IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
  2171. if (invAccess != null)
  2172. invAccess.RezObject(
  2173. remoteClient, itemID, rezGroupID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection,
  2174. RezSelected, RemoveItem, fromTaskID, false);
  2175. }
  2176. else
  2177. {
  2178. SceneObjectPart part = GetSceneObjectPart(fromTaskID);
  2179. if (part == null)
  2180. {
  2181. m_log.ErrorFormat(
  2182. "[TASK INVENTORY]: {0} tried to rez item id {1} from object id {2} but there is no such scene object",
  2183. remoteClient.Name, itemID, fromTaskID);
  2184. return;
  2185. }
  2186. TaskInventoryItem item = part.Inventory.GetInventoryItem(itemID);
  2187. if (item == null)
  2188. {
  2189. m_log.ErrorFormat(
  2190. "[TASK INVENTORY]: {0} tried to rez item id {1} from object id {2} but there is no such item",
  2191. remoteClient.Name, itemID, fromTaskID);
  2192. return;
  2193. }
  2194. byte bRayEndIsIntersection = (byte)(RayEndIsIntersection ? 1 : 0);
  2195. Vector3 scale = new Vector3(0.5f, 0.5f, 0.5f);
  2196. Vector3 pos = GetNewRezLocation(
  2197. RayStart, RayEnd, RayTargetID, Quaternion.Identity,
  2198. BypassRayCast, bRayEndIsIntersection, true, scale, false);
  2199. RezObject(part, item, pos, null, Vector3.Zero, 0, false);
  2200. }
  2201. }
  2202. /// <summary>
  2203. /// Rez an object into the scene from a prim's inventory.
  2204. /// </summary>
  2205. /// <param name="sourcePart"></param>
  2206. /// <param name="item"></param>
  2207. /// <param name="pos">The position of the rezzed object.</param>
  2208. /// <param name="rot">The rotation of the rezzed object. If null, then the rotation stored with the object
  2209. /// will be used if it exists.</param>
  2210. /// <param name="vel">The velocity of the rezzed object.</param>
  2211. /// <param name="param"></param>
  2212. /// <returns>The SceneObjectGroup(s) rezzed, or null if rez was unsuccessful</returns>
  2213. public virtual List<SceneObjectGroup> RezObject(
  2214. SceneObjectPart sourcePart, TaskInventoryItem item, Vector3 pos, Quaternion? rot, Vector3 vel, int param, bool atRoot)
  2215. {
  2216. if (null == item)
  2217. return null;
  2218. List<SceneObjectGroup> objlist;
  2219. List<Vector3> veclist;
  2220. Vector3 bbox;
  2221. float offsetHeight;
  2222. bool success = sourcePart.Inventory.GetRezReadySceneObjects(item, out objlist, out veclist,out bbox, out offsetHeight);
  2223. if (!success)
  2224. return null;
  2225. int totalPrims = 0;
  2226. foreach (SceneObjectGroup group in objlist)
  2227. totalPrims += group.PrimCount;
  2228. if (!Permissions.CanRezObject(totalPrims, item.OwnerID, pos))
  2229. return null;
  2230. if (!Permissions.BypassPermissions())
  2231. {
  2232. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  2233. sourcePart.Inventory.RemoveInventoryItem(item.ItemID);
  2234. }
  2235. SceneObjectGroup sog;
  2236. bool fixrot = false;
  2237. Quaternion netRot = Quaternion.Identity;
  2238. // position adjust
  2239. if (totalPrims > 1) // nothing to do on a single prim
  2240. {
  2241. if (objlist.Count == 1)
  2242. {
  2243. // current object position is root position
  2244. if(!atRoot)
  2245. {
  2246. sog = objlist[0];
  2247. Quaternion orot;
  2248. if (rot == null)
  2249. orot = sog.RootPart.GetWorldRotation();
  2250. else
  2251. orot = rot.Value;
  2252. // possible should be bbox, but geometric center looks better
  2253. Vector3 off = sog.GetGeometricCenter();
  2254. // Vector3 off = bbox * 0.5f;
  2255. off *= orot;
  2256. pos -= off;
  2257. }
  2258. }
  2259. else
  2260. {
  2261. //veclist[] are relative to bbox corner with min X,Y and Z
  2262. // rez at root, and rot will be referenced to first object in list
  2263. if (rot == null)
  2264. {
  2265. // use original rotations
  2266. if (atRoot)
  2267. pos -= veclist[0];
  2268. else
  2269. pos -= bbox / 2;
  2270. }
  2271. else
  2272. {
  2273. fixrot = true;
  2274. sog = objlist[0];
  2275. netRot = Quaternion.Conjugate(sog.RootPart.GetWorldRotation());
  2276. netRot = netRot * rot.Value;
  2277. Vector3 off;
  2278. if (atRoot)
  2279. off = veclist[0];
  2280. else
  2281. off = bbox / 2;
  2282. off *= netRot;
  2283. pos -= off;
  2284. }
  2285. }
  2286. }
  2287. for (int i = 0; i < objlist.Count; i++)
  2288. {
  2289. SceneObjectGroup group = objlist[i];
  2290. Vector3 curpos;
  2291. if(fixrot)
  2292. curpos = pos + veclist[i] * netRot;
  2293. else
  2294. curpos = pos + veclist[i];
  2295. if (group.IsAttachment == false && group.RootPart.Shape.State != 0)
  2296. {
  2297. group.RootPart.AttachedPos = group.AbsolutePosition;
  2298. group.RootPart.Shape.LastAttachPoint = (byte)group.AttachmentPoint;
  2299. }
  2300. group.RezzerID = sourcePart.UUID;
  2301. if( i == 0)
  2302. AddNewSceneObject(group, true, curpos, rot, vel);
  2303. else
  2304. {
  2305. Quaternion crot = objlist[i].RootPart.GetWorldRotation();
  2306. if (fixrot)
  2307. {
  2308. crot *= netRot;
  2309. }
  2310. AddNewSceneObject(group, true, curpos, crot, vel);
  2311. }
  2312. // We can only call this after adding the scene object, since the scene object references the scene
  2313. // to find out if scripts should be activated at all.
  2314. group.InvalidateEffectivePerms();
  2315. group.CreateScriptInstances(param, true, DefaultScriptEngine, 3);
  2316. group.ScheduleGroupForFullUpdate();
  2317. }
  2318. return objlist;
  2319. }
  2320. public virtual bool returnObjects(SceneObjectGroup[] returnobjects,
  2321. IClientAPI client)
  2322. {
  2323. List<uint> localIDs = new List<uint>();
  2324. foreach (SceneObjectGroup grp in returnobjects)
  2325. {
  2326. AddReturn(grp.OwnerID, grp.Name, grp.AbsolutePosition,
  2327. "parcel owner return");
  2328. localIDs.Add(grp.RootPart.LocalId);
  2329. }
  2330. DeRezObjects(client, localIDs, UUID.Zero, DeRezAction.Return,
  2331. UUID.Zero, false);
  2332. return true;
  2333. }
  2334. public void SetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID, bool running)
  2335. {
  2336. if (!Permissions.CanEditScript(itemID, objectID, controllingClient.AgentId))
  2337. return;
  2338. SceneObjectPart part = GetSceneObjectPart(objectID);
  2339. if (part == null)
  2340. return;
  2341. if (running)
  2342. EventManager.TriggerStartScript(part.LocalId, itemID);
  2343. else
  2344. EventManager.TriggerStopScript(part.LocalId, itemID);
  2345. }
  2346. public void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID)
  2347. {
  2348. EventManager.TriggerGetScriptRunning(controllingClient, objectID, itemID);
  2349. }
  2350. void ObjectOwner(IClientAPI remoteClient, UUID ownerID, UUID groupID, List<uint> localIDs)
  2351. {
  2352. if (!Permissions.IsGod(remoteClient.AgentId))
  2353. {
  2354. if (ownerID != UUID.Zero)
  2355. return;
  2356. }
  2357. List<SceneObjectGroup> groups = new List<SceneObjectGroup>();
  2358. foreach (uint localID in localIDs)
  2359. {
  2360. SceneObjectPart part = GetSceneObjectPart(localID);
  2361. if (part == null)
  2362. continue;
  2363. if (!groups.Contains(part.ParentGroup))
  2364. groups.Add(part.ParentGroup);
  2365. }
  2366. foreach (SceneObjectGroup sog in groups)
  2367. {
  2368. if (ownerID != UUID.Zero)
  2369. {
  2370. sog.SetOwnerId(ownerID);
  2371. sog.SetGroup(groupID, remoteClient);
  2372. sog.ScheduleGroupForFullUpdate();
  2373. SceneObjectPart[] partList = sog.Parts;
  2374. foreach (SceneObjectPart child in partList)
  2375. {
  2376. child.Inventory.ChangeInventoryOwner(ownerID);
  2377. child.TriggerScriptChangedEvent(Changed.OWNER);
  2378. }
  2379. }
  2380. else // The object deeded to the group
  2381. {
  2382. if (!Permissions.CanDeedObject(remoteClient, sog, groupID))
  2383. continue;
  2384. sog.SetOwnerId(groupID);
  2385. // this is wrong, GroupMask is used for group sharing, still possible to set
  2386. // this whould give owner rights to users that are member of group but don't have role powers to edit
  2387. // sog.RootPart.GroupMask = sog.RootPart.OwnerMask;
  2388. // we should keep all permissions on deed to group
  2389. // and with this comented code, if user does not set next permissions on the object
  2390. // and on ALL contents of ALL prims, he may loose rights, making the object useless
  2391. sog.ApplyNextOwnerPermissions();
  2392. sog.InvalidateEffectivePerms();
  2393. sog.ScheduleGroupForFullUpdate();
  2394. SceneObjectPart[] partList = sog.Parts;
  2395. foreach (SceneObjectPart child in partList)
  2396. {
  2397. child.Inventory.ChangeInventoryOwner(groupID);
  2398. child.TriggerScriptChangedEvent(Changed.OWNER);
  2399. }
  2400. }
  2401. }
  2402. foreach (uint localID in localIDs)
  2403. {
  2404. SceneObjectPart part = GetSceneObjectPart(localID);
  2405. if (part == null)
  2406. continue;
  2407. part.SendPropertiesToClient(remoteClient);
  2408. }
  2409. }
  2410. public void DelinkObjects(List<uint> primIds, IClientAPI client)
  2411. {
  2412. List<SceneObjectPart> parts = new List<SceneObjectPart>();
  2413. foreach (uint localID in primIds)
  2414. {
  2415. SceneObjectPart part = GetSceneObjectPart(localID);
  2416. if (part == null)
  2417. continue;
  2418. if (Permissions.CanDelinkObject(client.AgentId, part.ParentGroup.RootPart.UUID))
  2419. parts.Add(part);
  2420. }
  2421. m_sceneGraph.DelinkObjects(parts);
  2422. }
  2423. /// <summary>
  2424. /// Link the scene objects containing the indicated parts to a root object.
  2425. /// </summary>
  2426. /// <param name="client"></param>
  2427. /// <param name="parentPrimId">A root prim id of the object which will be the root prim of the resulting linkset.</param>
  2428. /// <param name="childPrimIds">A list of child prims for the objects that should be linked in.</param>
  2429. public void LinkObjects(IClientAPI client, uint parentPrimId, List<uint> childPrimIds)
  2430. {
  2431. LinkObjects(client.AgentId, parentPrimId, childPrimIds);
  2432. }
  2433. /// <summary>
  2434. /// Link the scene objects containing the indicated parts to a root object.
  2435. /// </summary>
  2436. /// <param name="agentId">The ID of the user linking.</param>
  2437. /// <param name="parentPrimId">A root prim id of the object which will be the root prim of the resulting linkset.</param>
  2438. /// <param name="childPrimIds">A list of child prims for the objects that should be linked in.</param>
  2439. public void LinkObjects(UUID agentId, uint parentPrimId, List<uint> childPrimIds)
  2440. {
  2441. List<UUID> owners = new List<UUID>();
  2442. List<SceneObjectPart> children = new List<SceneObjectPart>();
  2443. SceneObjectPart root = GetSceneObjectPart(parentPrimId);
  2444. if (root == null)
  2445. {
  2446. m_log.DebugFormat("[LINK]: Can't find linkset root prim {0}", parentPrimId);
  2447. return;
  2448. }
  2449. if (!Permissions.CanLinkObject(agentId, root.ParentGroup.RootPart.UUID))
  2450. {
  2451. m_log.DebugFormat("[LINK]: Refusing link. No permissions on root prim");
  2452. return;
  2453. }
  2454. foreach (uint localID in childPrimIds)
  2455. {
  2456. SceneObjectPart part = GetSceneObjectPart(localID);
  2457. if (part == null)
  2458. continue;
  2459. if (!owners.Contains(part.OwnerID))
  2460. owners.Add(part.OwnerID);
  2461. if (Permissions.CanLinkObject(agentId, part.ParentGroup.RootPart.UUID))
  2462. children.Add(part);
  2463. }
  2464. // Must be all one owner
  2465. //
  2466. if (owners.Count > 1)
  2467. {
  2468. m_log.DebugFormat("[LINK]: Refusing link. Too many owners");
  2469. return;
  2470. }
  2471. if (children.Count == 0)
  2472. {
  2473. m_log.DebugFormat("[LINK]: Refusing link. No permissions to link any of the children");
  2474. return;
  2475. }
  2476. bool oldUsePhysics = (root.Flags & PrimFlags.Physics) != 0;
  2477. m_sceneGraph.LinkObjects(root, children);
  2478. ScenePresence sp;
  2479. if (TryGetScenePresence(agentId, out sp))
  2480. {
  2481. root.SendPropertiesToClient(sp.ControllingClient);
  2482. if (oldUsePhysics && (root.Flags & PrimFlags.Physics) == 0)
  2483. {
  2484. sp.ControllingClient.SendAlertMessage("Object physics cancelled");
  2485. }
  2486. }
  2487. }
  2488. private string PermissionString(uint permissions)
  2489. {
  2490. PermissionMask perms = (PermissionMask)permissions &
  2491. (PermissionMask.Move |
  2492. PermissionMask.Copy |
  2493. PermissionMask.Transfer |
  2494. PermissionMask.Modify);
  2495. return perms.ToString();
  2496. }
  2497. }
  2498. }