Scene.Inventory.cs 102 KB

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