Scene.Inventory.cs 101 KB

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