Scene.Inventory.cs 106 KB

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