Scene.Inventory.cs 123 KB

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