Scene.Inventory.cs 123 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861
  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. List<InventoryItemBase> its = fold.RequestListOfItems();
  1378. List<InventoryFolderBase> fds = fold.RequestListOfFolders();
  1379. client.SendInventoryFolderDetails(
  1380. fold.Owner, folder.ID, its, fds,
  1381. fold.Version, its.Count + fds.Count, fetchFolders, fetchItems);
  1382. return;
  1383. }
  1384. }
  1385. // Fetch the folder contents
  1386. InventoryCollection contents = InventoryService.GetFolderContent(client.AgentId, folder.ID);
  1387. // Fetch the folder itself to get its current version
  1388. InventoryFolderBase containingFolder = InventoryService.GetFolder(client.AgentId, folder.ID);
  1389. // m_log.DebugFormat("[AGENT INVENTORY]: Sending inventory folder contents ({0} nodes) for \"{1}\" to {2} {3}",
  1390. // contents.Folders.Count + contents.Items.Count, containingFolder.Name, client.FirstName, client.LastName);
  1391. if (containingFolder != null )
  1392. {
  1393. int descendents = contents.Folders.Count + contents.Items.Count;
  1394. if(fetchItems && contents.Items.Count > 0)
  1395. {
  1396. var linksIDs = new HashSet<UUID>();
  1397. var links = new List<InventoryItemBase>();
  1398. for (int i = 0; i < contents.Items.Count; ++i)
  1399. {
  1400. InventoryItemBase item = contents.Items[i];
  1401. if (item.AssetType == (int)AssetType.Link)
  1402. {
  1403. UUID linkid = item.AssetID;
  1404. if(linksIDs.Contains(linkid))
  1405. continue;
  1406. InventoryItemBase linkedItem = InventoryService.GetItem(item.Owner, linkid);
  1407. if (linkedItem != null && linkedItem.AssetType != (int)AssetType.Link && linkedItem.AssetType != (int)AssetType.LinkFolder)
  1408. {
  1409. links.Add(linkedItem);
  1410. linksIDs.Add(linkedItem.ID);
  1411. }
  1412. }
  1413. }
  1414. if(links.Count > 0)
  1415. {
  1416. links.AddRange(contents.Items);
  1417. contents.Items = links;
  1418. }
  1419. }
  1420. client.SendInventoryFolderDetails(
  1421. client.AgentId, folder.ID, contents.Items, contents.Folders,
  1422. containingFolder.Version, descendents, fetchFolders, fetchItems);
  1423. }
  1424. }
  1425. /// <summary>
  1426. /// Update an item in a prim (task) inventory.
  1427. /// This method does not handle scripts, <see>RezScript(IClientAPI, UUID, unit)</see>
  1428. /// </summary>
  1429. /// <param name="remoteClient"></param>
  1430. /// <param name="transactionID"></param>
  1431. /// <param name="itemInfo"></param>
  1432. /// <param name="primLocalID"></param>
  1433. public void UpdateTaskInventory(IClientAPI remoteClient, UUID transactionID, TaskInventoryItem itemInfo,
  1434. uint primLocalID)
  1435. {
  1436. UUID itemID = itemInfo.ItemID;
  1437. if (itemID == UUID.Zero)
  1438. {
  1439. m_log.ErrorFormat(
  1440. "[PRIM INVENTORY]: UpdateTaskInventory called with item ID Zero on update for {1}!",
  1441. remoteClient.Name);
  1442. return;
  1443. }
  1444. // Find the prim we're dealing with
  1445. SceneObjectPart part = GetSceneObjectPart(primLocalID);
  1446. if(part == null)
  1447. {
  1448. m_log.WarnFormat(
  1449. "[PRIM INVENTORY]: " +
  1450. "Update with item {0} requested of prim {1} for {2} but this prim does not exist",
  1451. itemID, primLocalID, remoteClient.Name);
  1452. return;
  1453. }
  1454. TaskInventoryItem currentItem = part.Inventory.GetInventoryItem(itemID);
  1455. if (currentItem == null)
  1456. {
  1457. InventoryItemBase item = InventoryService.GetItem(remoteClient.AgentId, itemID);
  1458. // if not found Try library
  1459. if (item == null && LibraryService != null && LibraryService.LibraryRootFolder != null)
  1460. item = LibraryService.LibraryRootFolder.FindItem(itemID);
  1461. if(item == null)
  1462. {
  1463. m_log.ErrorFormat(
  1464. "[PRIM INVENTORY]: Could not find inventory item {0} to update for {1}!",
  1465. itemID, remoteClient.Name);
  1466. return;
  1467. }
  1468. if (!Permissions.CanDropInObjectInv(item, remoteClient, part))
  1469. return;
  1470. UUID copyID = UUID.Random();
  1471. bool modrights = Permissions.CanEditObject(part.ParentGroup, remoteClient);
  1472. part.ParentGroup.AddInventoryItem(remoteClient.AgentId, primLocalID, item, copyID, modrights);
  1473. m_log.InfoFormat(
  1474. "[PRIM INVENTORY]: Update with item {0} requested of prim {1} for {2}",
  1475. item.Name, primLocalID, remoteClient.Name);
  1476. part.SendPropertiesToClient(remoteClient);
  1477. if (!Permissions.BypassPermissions())
  1478. {
  1479. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  1480. {
  1481. List<UUID> uuids = new List<UUID>();
  1482. uuids.Add(itemID);
  1483. RemoveInventoryItem(remoteClient, uuids);
  1484. }
  1485. }
  1486. }
  1487. else // Updating existing item with new perms etc
  1488. {
  1489. // m_log.DebugFormat(
  1490. // "[PRIM INVENTORY]: Updating item {0} in {1} for UpdateTaskInventory()",
  1491. // currentItem.Name, part.Name);
  1492. if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId))
  1493. return;
  1494. // Only look for an uploaded updated asset if we are passed a transaction ID. This is only the
  1495. // case for updates uploded through UDP. Updates uploaded via a capability (e.g. a script update)
  1496. // will not pass in a transaction ID in the update message.
  1497. if (transactionID != UUID.Zero && AgentTransactionsModule != null)
  1498. {
  1499. AgentTransactionsModule.HandleTaskItemUpdateFromTransaction(
  1500. remoteClient, part, transactionID, currentItem);
  1501. // if ((InventoryType)itemInfo.InvType == InventoryType.Notecard)
  1502. // remoteClient.SendAgentAlertMessage("Notecard saved", false);
  1503. // else if ((InventoryType)itemInfo.InvType == InventoryType.LSL)
  1504. // remoteClient.SendAgentAlertMessage("Script saved", false);
  1505. // else
  1506. // remoteClient.SendAgentAlertMessage("Item saved", false);
  1507. }
  1508. // Base ALWAYS has move
  1509. currentItem.BasePermissions |= (uint)PermissionMask.Move;
  1510. itemInfo.Flags = currentItem.Flags;
  1511. // Check if we're allowed to mess with permissions
  1512. if (!Permissions.IsGod(remoteClient.AgentId)) // Not a god
  1513. {
  1514. bool noChange;
  1515. if (remoteClient.AgentId != part.OwnerID) // Not owner
  1516. {
  1517. noChange = true;
  1518. if(itemInfo.OwnerID == UUID.Zero && itemInfo.GroupID != UUID.Zero)
  1519. {
  1520. if(remoteClient.IsGroupMember(itemInfo.GroupID))
  1521. {
  1522. ulong powers = remoteClient.GetGroupPowers(itemInfo.GroupID);
  1523. if((powers & (ulong)GroupPowers.ObjectManipulate) != 0)
  1524. noChange = false;
  1525. }
  1526. }
  1527. }
  1528. else
  1529. noChange = false;
  1530. if(noChange)
  1531. {
  1532. // Friends and group members can't change any perms
  1533. itemInfo.BasePermissions = currentItem.BasePermissions;
  1534. itemInfo.EveryonePermissions = currentItem.EveryonePermissions;
  1535. itemInfo.GroupPermissions = currentItem.GroupPermissions;
  1536. itemInfo.NextPermissions = currentItem.NextPermissions;
  1537. itemInfo.CurrentPermissions = currentItem.CurrentPermissions;
  1538. }
  1539. else
  1540. {
  1541. // Owner can't change base, and can change other
  1542. // only up to base
  1543. itemInfo.BasePermissions = currentItem.BasePermissions;
  1544. if (itemInfo.EveryonePermissions != currentItem.EveryonePermissions)
  1545. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteEveryone;
  1546. if (itemInfo.GroupPermissions != currentItem.GroupPermissions)
  1547. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteGroup;
  1548. if (itemInfo.CurrentPermissions != currentItem.CurrentPermissions)
  1549. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteOwner;
  1550. if (itemInfo.NextPermissions != currentItem.NextPermissions)
  1551. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteNextOwner;
  1552. itemInfo.EveryonePermissions &= currentItem.BasePermissions;
  1553. itemInfo.GroupPermissions &= currentItem.BasePermissions;
  1554. itemInfo.CurrentPermissions &= currentItem.BasePermissions;
  1555. itemInfo.NextPermissions &= currentItem.BasePermissions;
  1556. }
  1557. }
  1558. else
  1559. {
  1560. if (itemInfo.BasePermissions != currentItem.BasePermissions)
  1561. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteBase;
  1562. if (itemInfo.EveryonePermissions != currentItem.EveryonePermissions)
  1563. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteEveryone;
  1564. if (itemInfo.GroupPermissions != currentItem.GroupPermissions)
  1565. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteGroup;
  1566. if (itemInfo.CurrentPermissions != currentItem.CurrentPermissions)
  1567. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteOwner;
  1568. if (itemInfo.NextPermissions != currentItem.NextPermissions)
  1569. itemInfo.Flags |= (uint)InventoryItemFlags.ObjectOverwriteNextOwner;
  1570. }
  1571. // Next ALWAYS has move
  1572. itemInfo.NextPermissions |= (uint)PermissionMask.Move;
  1573. if (part.Inventory.UpdateInventoryItem(itemInfo))
  1574. {
  1575. part.SendPropertiesToClient(remoteClient);
  1576. }
  1577. }
  1578. }
  1579. /// <summary>
  1580. /// Rez a script into a prim's inventory, either ex nihilo or from an existing avatar inventory
  1581. /// </summary>
  1582. /// <param name="remoteClient"></param>
  1583. /// <param name="itemBase"> </param>
  1584. /// <param name="transactionID"></param>
  1585. /// <param name="localID"></param>
  1586. public void RezScript(IClientAPI remoteClient, InventoryItemBase itemBase, UUID transactionID, uint localID)
  1587. {
  1588. SceneObjectPart partWhereRezzed;
  1589. if (itemBase.ID != UUID.Zero)
  1590. partWhereRezzed = RezScriptFromAgentInventory(remoteClient.AgentId, itemBase.ID, localID);
  1591. else
  1592. partWhereRezzed = RezNewScript(remoteClient.AgentId, itemBase);
  1593. if (partWhereRezzed != null)
  1594. partWhereRezzed.SendPropertiesToClient(remoteClient);
  1595. }
  1596. /// <summary>
  1597. /// Rez a script into a prim from an agent inventory.
  1598. /// </summary>
  1599. /// <param name="agentID"></param>
  1600. /// <param name="fromItemID"></param>
  1601. /// <param name="localID"></param>
  1602. /// <returns>The part where the script was rezzed if successful. False otherwise.</returns>
  1603. public SceneObjectPart RezScriptFromAgentInventory(UUID agentID, UUID fromItemID, uint localID)
  1604. {
  1605. UUID copyID = UUID.Random();
  1606. InventoryItemBase item = InventoryService.GetItem(agentID, fromItemID);
  1607. // Try library
  1608. // XXX clumsy, possibly should be one call
  1609. if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null)
  1610. {
  1611. item = LibraryService.LibraryRootFolder.FindItem(fromItemID);
  1612. }
  1613. if (item != null)
  1614. {
  1615. SceneObjectPart part = GetSceneObjectPart(localID);
  1616. if (part != null)
  1617. {
  1618. if (!Permissions.CanEditObjectInventory(part.UUID, agentID))
  1619. return null;
  1620. part.ParentGroup.AddInventoryItem(agentID, localID, item, copyID);
  1621. // TODO: switch to posting on_rez here when scripts
  1622. // have state in inventory
  1623. part.Inventory.CreateScriptInstance(copyID, 0, false, DefaultScriptEngine, 0);
  1624. // tell anyone watching that there is a new script in town
  1625. EventManager.TriggerNewScript(agentID, part, copyID);
  1626. // m_log.InfoFormat("[PRIMINVENTORY]: " +
  1627. // "Rezzed script {0} into prim local ID {1} for user {2}",
  1628. // item.inventoryName, localID, remoteClient.Name);
  1629. part.ParentGroup.ResumeScripts();
  1630. return part;
  1631. }
  1632. else
  1633. {
  1634. m_log.ErrorFormat(
  1635. "[PRIM INVENTORY]: " +
  1636. "Could not rez script {0} into prim local ID {1} for user {2}"
  1637. + " because the prim could not be found in the region!",
  1638. item.Name, localID, agentID);
  1639. }
  1640. }
  1641. else
  1642. {
  1643. m_log.ErrorFormat(
  1644. "[PRIM INVENTORY]: Could not find script inventory item {0} to rez for {1}!",
  1645. fromItemID, agentID);
  1646. }
  1647. return null;
  1648. }
  1649. /// <summary>
  1650. /// Rez a new script from nothing.
  1651. /// </summary>
  1652. /// <param name="remoteClient"></param>
  1653. /// <param name="itemBase"></param>
  1654. /// <returns>The part where the script was rezzed if successful. False otherwise.</returns>
  1655. public SceneObjectPart RezNewScript(UUID agentID, InventoryItemBase itemBase)
  1656. {
  1657. return RezNewScript(
  1658. agentID,
  1659. itemBase,
  1660. "default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}");
  1661. }
  1662. /// <summary>
  1663. /// Rez a new script from nothing with given script text.
  1664. /// </summary>
  1665. /// <param name="remoteClient"></param>
  1666. /// <param name="itemBase">Template item.</param>
  1667. /// <param name="scriptText"></param>
  1668. /// <returns>The part where the script was rezzed if successful. False otherwise.</returns>
  1669. public SceneObjectPart RezNewScript(UUID agentID, InventoryItemBase itemBase, string scriptText)
  1670. {
  1671. // The part ID is the folder ID!
  1672. SceneObjectPart part = GetSceneObjectPart(itemBase.Folder);
  1673. if (part == null)
  1674. {
  1675. // m_log.DebugFormat(
  1676. // "[SCENE INVENTORY]: Could not find part with id {0} for {1} to rez new script",
  1677. // itemBase.Folder, agentID);
  1678. return null;
  1679. }
  1680. if (!Permissions.CanCreateObjectInventory(itemBase.InvType, part.UUID, agentID))
  1681. {
  1682. // m_log.DebugFormat(
  1683. // "[SCENE INVENTORY]: No permission to create new script in {0} for {1}", part.Name, agentID);
  1684. return null;
  1685. }
  1686. AssetBase asset
  1687. = CreateAsset(
  1688. itemBase.Name,
  1689. itemBase.Description,
  1690. (sbyte)itemBase.AssetType,
  1691. Encoding.ASCII.GetBytes(scriptText),
  1692. agentID);
  1693. AssetService.Store(asset);
  1694. TaskInventoryItem taskItem = new TaskInventoryItem();
  1695. taskItem.ResetIDs(itemBase.Folder);
  1696. taskItem.ParentID = itemBase.Folder;
  1697. taskItem.CreationDate = (uint)itemBase.CreationDate;
  1698. taskItem.Name = itemBase.Name;
  1699. taskItem.Description = itemBase.Description;
  1700. taskItem.Type = itemBase.AssetType;
  1701. taskItem.InvType = itemBase.InvType;
  1702. taskItem.OwnerID = itemBase.Owner;
  1703. taskItem.CreatorID = itemBase.CreatorIdAsUuid;
  1704. taskItem.BasePermissions = itemBase.BasePermissions;
  1705. taskItem.CurrentPermissions = itemBase.CurrentPermissions;
  1706. taskItem.EveryonePermissions = itemBase.EveryOnePermissions;
  1707. taskItem.GroupPermissions = itemBase.GroupPermissions;
  1708. taskItem.NextPermissions = itemBase.NextPermissions;
  1709. taskItem.GroupID = itemBase.GroupID;
  1710. taskItem.GroupPermissions = 0;
  1711. taskItem.Flags = itemBase.Flags;
  1712. taskItem.PermsGranter = UUID.Zero;
  1713. taskItem.PermsMask = 0;
  1714. taskItem.AssetID = asset.FullID;
  1715. part.Inventory.AddInventoryItem(taskItem, false);
  1716. part.Inventory.CreateScriptInstance(taskItem, 0, false, DefaultScriptEngine, 0);
  1717. part.ParentGroup.InvalidateEffectivePerms();
  1718. // tell anyone managing scripts that a new script exists
  1719. EventManager.TriggerNewScript(agentID, part, taskItem.ItemID);
  1720. part.ParentGroup.ResumeScripts();
  1721. return part;
  1722. }
  1723. /// <summary>
  1724. /// Rez a script into a prim's inventory from another prim
  1725. /// </summary>
  1726. /// <param name="remoteClient"></param>
  1727. /// <param name="srcPart"> </param>
  1728. /// <param name="destId"> </param>
  1729. /// <param name="pin"></param>
  1730. /// <param name="running"></param>
  1731. /// <param name="start_param"></param>
  1732. public void RezScriptFromPrim(UUID srcId, SceneObjectPart srcPart, UUID destId, int pin, int running, int start_param)
  1733. {
  1734. TaskInventoryItem srcTaskItem = srcPart.Inventory.GetInventoryItem(srcId);
  1735. if (srcTaskItem == null)
  1736. {
  1737. m_log.ErrorFormat(
  1738. "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for rezzing a script but the "
  1739. + " item does not exist in this inventory",
  1740. srcId, srcPart.Name, srcPart.UUID);
  1741. return;
  1742. }
  1743. SceneObjectPart destPart = GetSceneObjectPart(destId);
  1744. if (destPart == null)
  1745. {
  1746. m_log.ErrorFormat(
  1747. "[PRIM INVENTORY]: Could not find part {0} to insert script item {1} from {2} {3} in {4}",
  1748. destId, srcId, srcPart.Name, srcPart.UUID, Name);
  1749. return;
  1750. }
  1751. // Must own the object, and have modify rights
  1752. if (srcPart.OwnerID != destPart.OwnerID)
  1753. {
  1754. // Group permissions
  1755. if ((destPart.GroupID == UUID.Zero) || (destPart.GroupID != srcPart.GroupID) ||
  1756. ((destPart.GroupMask & (uint)PermissionMask.Modify) == 0))
  1757. return;
  1758. }
  1759. else
  1760. {
  1761. if ((destPart.OwnerMask & (uint)PermissionMask.Modify) == 0)
  1762. return;
  1763. }
  1764. if (destPart.ScriptAccessPin == 0 || destPart.ScriptAccessPin != pin)
  1765. {
  1766. m_log.WarnFormat(
  1767. "[PRIM INVENTORY]: " +
  1768. "Script in object {0} : {1}, attempted to load script {2} : {3} into object {4} : {5} with invalid pin {6}",
  1769. srcPart.Name, srcId, srcTaskItem.Name, srcTaskItem.ItemID, destPart.Name, destId, pin);
  1770. // the LSL Wiki says we are supposed to shout on the DEBUG_CHANNEL -
  1771. // "Object: Task Object trying to illegally load script onto task Other_Object!"
  1772. // How do we shout from in here?
  1773. return;
  1774. }
  1775. TaskInventoryItem destTaskItem = new TaskInventoryItem();
  1776. destTaskItem.ItemID = UUID.Random();
  1777. destTaskItem.CreatorID = srcTaskItem.CreatorID;
  1778. destTaskItem.CreatorData = srcTaskItem.CreatorData;
  1779. destTaskItem.AssetID = srcTaskItem.AssetID;
  1780. destTaskItem.GroupID = destPart.GroupID;
  1781. destTaskItem.OwnerID = destPart.OwnerID;
  1782. destTaskItem.ParentID = destPart.UUID;
  1783. destTaskItem.ParentPartID = destPart.UUID;
  1784. destTaskItem.BasePermissions = srcTaskItem.BasePermissions;
  1785. destTaskItem.EveryonePermissions = srcTaskItem.EveryonePermissions;
  1786. destTaskItem.GroupPermissions = srcTaskItem.GroupPermissions;
  1787. destTaskItem.CurrentPermissions = srcTaskItem.CurrentPermissions;
  1788. destTaskItem.NextPermissions = srcTaskItem.NextPermissions;
  1789. destTaskItem.Flags = srcTaskItem.Flags;
  1790. if (destPart.OwnerID != srcPart.OwnerID)
  1791. {
  1792. if (Permissions.PropagatePermissions())
  1793. {
  1794. destTaskItem.CurrentPermissions = srcTaskItem.CurrentPermissions &
  1795. srcTaskItem.NextPermissions;
  1796. destTaskItem.GroupPermissions = srcTaskItem.GroupPermissions &
  1797. srcTaskItem.NextPermissions;
  1798. destTaskItem.EveryonePermissions = srcTaskItem.EveryonePermissions &
  1799. srcTaskItem.NextPermissions;
  1800. destTaskItem.BasePermissions = srcTaskItem.BasePermissions &
  1801. srcTaskItem.NextPermissions;
  1802. destTaskItem.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm;
  1803. }
  1804. }
  1805. destTaskItem.Description = srcTaskItem.Description;
  1806. destTaskItem.Name = srcTaskItem.Name;
  1807. destTaskItem.InvType = srcTaskItem.InvType;
  1808. destTaskItem.Type = srcTaskItem.Type;
  1809. destPart.Inventory.AddInventoryItemExclusive(destTaskItem, false);
  1810. if (running > 0)
  1811. {
  1812. destPart.Inventory.CreateScriptInstance(destTaskItem, start_param, false, DefaultScriptEngine, 0);
  1813. }
  1814. destPart.ParentGroup.ResumeScripts();
  1815. ScenePresence avatar;
  1816. if (TryGetScenePresence(srcTaskItem.OwnerID, out avatar))
  1817. {
  1818. destPart.SendPropertiesToClient(avatar.ControllingClient);
  1819. }
  1820. }
  1821. /// <summary>
  1822. /// Derez one or more objects from the scene.
  1823. /// </summary>
  1824. /// <remarks>
  1825. /// Won't actually remove the scene object in the case where the object is being copied to a user inventory.
  1826. /// </remarks>
  1827. /// <param name='remoteClient'>Client requesting derez</param>
  1828. /// <param name='localIDs'>Local ids of root parts of objects to delete.</param>
  1829. /// <param name='groupID'>Not currently used. Here because the client passes this to us.</param>
  1830. /// <param name='action'>DeRezAction</param>
  1831. /// <param name='destinationID'>User folder ID to place derezzed object</param>
  1832. public virtual void DeRezObjects(
  1833. IClientAPI remoteClient, List<uint> localIDs, UUID groupID, DeRezAction action, UUID destinationID, bool AddToReturns = true)
  1834. {
  1835. // First, see of we can perform the requested action and
  1836. // build a list of eligible objects
  1837. List<uint> deleteIDs = new List<uint>();
  1838. List<SceneObjectGroup> deleteGroups = new List<SceneObjectGroup>();
  1839. List<SceneObjectGroup> takeCopyGroups = new List<SceneObjectGroup>();
  1840. List<SceneObjectGroup> takeDeleteGroups = new List<SceneObjectGroup>();
  1841. ScenePresence sp = null;
  1842. if(remoteClient != null)
  1843. sp = remoteClient.SceneAgent as ScenePresence;
  1844. else if(action != DeRezAction.Return)
  1845. return; // only Return can be called without a client
  1846. // this is not as 0.8x code
  1847. // 0.8x did refuse all operation is not allowed on all objects
  1848. // this will do it on allowed objects
  1849. // current viewers only ask if all allowed
  1850. foreach (uint localID in localIDs)
  1851. {
  1852. // Invalid id
  1853. SceneObjectPart part = GetSceneObjectPart(localID);
  1854. if (part == null)
  1855. {
  1856. //Client still thinks the object exists, kill it
  1857. deleteIDs.Add(localID);
  1858. continue;
  1859. }
  1860. SceneObjectGroup grp = part.ParentGroup;
  1861. if (grp == null || grp.IsDeleted)
  1862. {
  1863. //Client still thinks the object exists, kill it
  1864. deleteIDs.Add(localID);
  1865. continue;
  1866. }
  1867. // Can't delete child prims
  1868. if (part != grp.RootPart)
  1869. continue;
  1870. if (grp.IsAttachment)
  1871. {
  1872. if(!sp.IsGod || action != DeRezAction.Return || action != DeRezAction.Delete)
  1873. continue;
  1874. // this may break the attachment, but its a security action
  1875. // viewers don't allow it anyways
  1876. }
  1877. // If child prims have invalid perms, fix them
  1878. grp.AdjustChildPrimPermissions(false);
  1879. switch (action)
  1880. {
  1881. case DeRezAction.SaveToExistingUserInventoryItem:
  1882. {
  1883. if (Permissions.CanTakeCopyObject(grp, sp))
  1884. takeCopyGroups.Add(grp);
  1885. break;
  1886. }
  1887. case DeRezAction.TakeCopy:
  1888. {
  1889. if (Permissions.CanTakeCopyObject(grp, sp))
  1890. takeCopyGroups.Add(grp);
  1891. break;
  1892. }
  1893. case DeRezAction.Take:
  1894. {
  1895. if (Permissions.CanTakeObject(grp, sp))
  1896. takeDeleteGroups.Add(grp);
  1897. break;
  1898. }
  1899. case DeRezAction.GodTakeCopy:
  1900. {
  1901. if((remoteClient != null) && Permissions.IsGod(remoteClient.AgentId))
  1902. takeCopyGroups.Add(grp);
  1903. break;
  1904. }
  1905. case DeRezAction.Delete:
  1906. {
  1907. if (Permissions.CanDeleteObject(grp, remoteClient))
  1908. {
  1909. if(m_useTrashOnDelete || (sp.IsGod && grp.OwnerID != sp.UUID))
  1910. takeDeleteGroups.Add(grp);
  1911. else
  1912. deleteGroups.Add(grp);
  1913. }
  1914. break;
  1915. }
  1916. case DeRezAction.Return:
  1917. {
  1918. if (remoteClient != null)
  1919. {
  1920. if (Permissions.CanReturnObjects( null, remoteClient, new List<SceneObjectGroup>() {grp}))
  1921. {
  1922. takeDeleteGroups.Add(grp);
  1923. if (AddToReturns)
  1924. AddReturn(grp.OwnerID == grp.GroupID ? grp.LastOwnerID : grp.OwnerID, grp.Name, grp.AbsolutePosition,
  1925. "parcel owner return");
  1926. }
  1927. }
  1928. else // Auto return passes through here with null agent
  1929. {
  1930. takeDeleteGroups.Add(grp);
  1931. }
  1932. break;
  1933. }
  1934. default:
  1935. break;
  1936. }
  1937. }
  1938. if(deleteIDs.Count > 0)
  1939. SendKillObject(deleteIDs);
  1940. if (takeDeleteGroups.Count > 0)
  1941. {
  1942. m_asyncSceneObjectDeleter.DeleteToInventory(action, destinationID, takeDeleteGroups,
  1943. remoteClient, true);
  1944. }
  1945. if (takeCopyGroups.Count > 0)
  1946. {
  1947. m_asyncSceneObjectDeleter.DeleteToInventory(action, destinationID, takeCopyGroups,
  1948. remoteClient, false);
  1949. }
  1950. if (deleteGroups.Count > 0)
  1951. {
  1952. foreach (SceneObjectGroup g in deleteGroups)
  1953. DeleteSceneObject(g, false);
  1954. }
  1955. }
  1956. public UUID attachObjectAssetStore(IClientAPI remoteClient, SceneObjectGroup grp, UUID AgentId, out UUID itemID)
  1957. {
  1958. itemID = UUID.Zero;
  1959. if (grp != null)
  1960. {
  1961. Vector3 inventoryStoredPosition = new Vector3(
  1962. Math.Min(grp.AbsolutePosition.X, RegionInfo.RegionSizeX - 6),
  1963. Math.Min(grp.AbsolutePosition.Y, RegionInfo.RegionSizeY - 6),
  1964. grp.AbsolutePosition.Z);
  1965. Vector3 originalPosition = grp.AbsolutePosition;
  1966. grp.AbsolutePosition = inventoryStoredPosition;
  1967. string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp);
  1968. grp.AbsolutePosition = originalPosition;
  1969. AssetBase asset = CreateAsset(
  1970. grp.GetPartName(grp.LocalId),
  1971. grp.GetPartDescription(grp.LocalId),
  1972. (sbyte)AssetType.Object,
  1973. Utils.StringToBytes(sceneObjectXml),
  1974. remoteClient.AgentId);
  1975. AssetService.Store(asset);
  1976. InventoryItemBase item = new InventoryItemBase();
  1977. item.CreatorId = grp.RootPart.CreatorID.ToString();
  1978. item.CreatorData = grp.RootPart.CreatorData;
  1979. item.Owner = remoteClient.AgentId;
  1980. item.ID = UUID.Random();
  1981. item.AssetID = asset.FullID;
  1982. item.Description = asset.Description;
  1983. item.Name = asset.Name;
  1984. item.AssetType = asset.Type;
  1985. item.InvType = (int)InventoryType.Object;
  1986. InventoryFolderBase folder = InventoryService.GetFolderForType(remoteClient.AgentId, FolderType.Object);
  1987. if (folder != null)
  1988. item.Folder = folder.ID;
  1989. else // oopsies
  1990. item.Folder = UUID.Zero;
  1991. // Set up base perms properly
  1992. uint permsBase = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify);
  1993. permsBase &= grp.RootPart.BaseMask;
  1994. permsBase |= (uint)PermissionMask.Move;
  1995. // Make sure we don't lock it
  1996. grp.RootPart.NextOwnerMask |= (uint)PermissionMask.Move;
  1997. if ((remoteClient.AgentId != grp.RootPart.OwnerID) && Permissions.PropagatePermissions())
  1998. {
  1999. item.BasePermissions = permsBase & grp.RootPart.NextOwnerMask;
  2000. item.CurrentPermissions = permsBase & grp.RootPart.NextOwnerMask;
  2001. item.NextPermissions = permsBase & grp.RootPart.NextOwnerMask;
  2002. item.EveryOnePermissions = permsBase & grp.RootPart.EveryoneMask & grp.RootPart.NextOwnerMask;
  2003. item.GroupPermissions = permsBase & grp.RootPart.GroupMask & grp.RootPart.NextOwnerMask;
  2004. }
  2005. else
  2006. {
  2007. item.BasePermissions = permsBase;
  2008. item.CurrentPermissions = permsBase & grp.RootPart.OwnerMask;
  2009. item.NextPermissions = permsBase & grp.RootPart.NextOwnerMask;
  2010. item.EveryOnePermissions = permsBase & grp.RootPart.EveryoneMask;
  2011. item.GroupPermissions = permsBase & grp.RootPart.GroupMask;
  2012. }
  2013. item.CreationDate = Util.UnixTimeSinceEpoch();
  2014. // sets itemID so client can show item as 'attached' in inventory
  2015. grp.FromItemID = item.ID;
  2016. if (AddInventoryItem(item))
  2017. remoteClient.SendInventoryItemCreateUpdate(item, 0);
  2018. else
  2019. m_dialogModule.SendAlertToUser(remoteClient, "Operation failed");
  2020. itemID = item.ID;
  2021. return item.AssetID;
  2022. }
  2023. return UUID.Zero;
  2024. }
  2025. /// <summary>
  2026. /// Returns the list of Scene Objects in an asset.
  2027. /// </summary>
  2028. /// <remarks>
  2029. /// Returns one object if the asset is a regular object, and multiple objects for a coalesced object.
  2030. /// </remarks>
  2031. /// <param name="assetData">Asset data</param>
  2032. /// <param name="isAttachment">True if the object is an attachment.</param>
  2033. /// <param name="objlist">The objects included in the asset</param>
  2034. /// <param name="veclist">Relative positions of the objects</param>
  2035. /// <param name="bbox">Bounding box of all the objects</param>
  2036. /// <param name="offsetHeight">Offset in the Z axis from the centre of the bounding box
  2037. /// to the centre of the root prim (relevant only when returning a single object)</param>
  2038. /// <returns>
  2039. /// true if returning a single object or deserialization fails, false if returning the coalesced
  2040. /// list of objects
  2041. /// </returns>
  2042. public bool GetObjectsToRez(
  2043. byte[] assetData, bool isAttachment, out List<SceneObjectGroup> objlist, out List<Vector3> veclist,
  2044. out Vector3 bbox, out float offsetHeight)
  2045. {
  2046. objlist = new List<SceneObjectGroup>();
  2047. veclist = new List<Vector3>();
  2048. bbox = Vector3.Zero;
  2049. offsetHeight = 0;
  2050. string xmlData = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(assetData));
  2051. try
  2052. {
  2053. using (XmlTextReader wrappedReader = new XmlTextReader(xmlData, XmlNodeType.Element, null))
  2054. {
  2055. using (XmlReader reader = XmlReader.Create(wrappedReader, new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment}))
  2056. {
  2057. reader.Read();
  2058. bool isSingleObject = reader.Name != "CoalescedObject";
  2059. if (isSingleObject || isAttachment)
  2060. {
  2061. SceneObjectGroup g;
  2062. try
  2063. {
  2064. g = SceneObjectSerializer.FromOriginalXmlFormat(reader);
  2065. }
  2066. catch (Exception e)
  2067. {
  2068. m_log.Error("[AGENT INVENTORY]: Deserialization of xml failed ", e);
  2069. Util.LogFailedXML("[AGENT INVENTORY]:", xmlData);
  2070. g = null;
  2071. }
  2072. if (g != null)
  2073. {
  2074. objlist.Add(g);
  2075. veclist.Add(Vector3.Zero);
  2076. bbox = g.GetAxisAlignedBoundingBox(out offsetHeight);
  2077. }
  2078. return true;
  2079. }
  2080. else
  2081. {
  2082. XmlDocument doc = new XmlDocument();
  2083. doc.LoadXml(xmlData);
  2084. XmlElement e = (XmlElement)doc.SelectSingleNode("/CoalescedObject");
  2085. XmlElement coll = (XmlElement)e;
  2086. float bx = Convert.ToSingle(coll.GetAttribute("x"));
  2087. float by = Convert.ToSingle(coll.GetAttribute("y"));
  2088. float bz = Convert.ToSingle(coll.GetAttribute("z"));
  2089. bbox = new Vector3(bx, by, bz);
  2090. offsetHeight = 0;
  2091. XmlNodeList groups = e.SelectNodes("SceneObjectGroup");
  2092. foreach (XmlNode n in groups)
  2093. {
  2094. SceneObjectGroup g = SceneObjectSerializer.FromOriginalXmlFormat(n.OuterXml);
  2095. if (g != null)
  2096. {
  2097. objlist.Add(g);
  2098. XmlElement el = (XmlElement)n;
  2099. string rawX = el.GetAttribute("offsetx");
  2100. string rawY = el.GetAttribute("offsety");
  2101. string rawZ = el.GetAttribute("offsetz");
  2102. float x = Convert.ToSingle(rawX);
  2103. float y = Convert.ToSingle(rawY);
  2104. float z = Convert.ToSingle(rawZ);
  2105. veclist.Add(new Vector3(x, y, z));
  2106. }
  2107. }
  2108. return false;
  2109. }
  2110. }
  2111. }
  2112. }
  2113. catch (Exception e)
  2114. {
  2115. m_log.Error("[AGENT INVENTORY]: Deserialization of xml failed when looking for CoalescedObject tag ", e);
  2116. Util.LogFailedXML("[AGENT INVENTORY]:", xmlData);
  2117. }
  2118. return true;
  2119. }
  2120. /// <summary>
  2121. /// Event Handler Rez an object into a scene
  2122. /// Calls the non-void event handler
  2123. /// </summary>
  2124. /// <param name="remoteClient"></param>
  2125. /// <param name="itemID"></param>
  2126. /// <param name="rezGroupID"></param>
  2127. /// <param name="RayEnd"></param>
  2128. /// <param name="RayStart"></param>
  2129. /// <param name="RayTargetID"></param>
  2130. /// <param name="BypassRayCast"></param>
  2131. /// <param name="RayEndIsIntersection"></param>
  2132. /// <param name="EveryoneMask"></param>
  2133. /// <param name="GroupMask"></param>
  2134. /// <param name="RezSelected"></param>
  2135. /// <param name="RemoveItem"></param>
  2136. /// <param name="fromTaskID"></param>
  2137. public virtual void RezObject(IClientAPI remoteClient, UUID itemID, UUID rezGroupID,
  2138. Vector3 RayEnd, Vector3 RayStart,
  2139. UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
  2140. bool RezSelected, bool RemoveItem, UUID fromTaskID)
  2141. {
  2142. // m_log.DebugFormat(
  2143. // "[PRIM INVENTORY]: RezObject from {0} for item {1} from task id {2}",
  2144. // remoteClient.Name, itemID, fromTaskID);
  2145. if (fromTaskID == UUID.Zero)
  2146. {
  2147. IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
  2148. if (invAccess != null)
  2149. invAccess.RezObject(
  2150. remoteClient, itemID, rezGroupID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection,
  2151. RezSelected, RemoveItem, fromTaskID, false);
  2152. }
  2153. else
  2154. {
  2155. SceneObjectPart part = GetSceneObjectPart(fromTaskID);
  2156. if (part == null)
  2157. {
  2158. m_log.ErrorFormat(
  2159. "[TASK INVENTORY]: {0} tried to rez item id {1} from object id {2} but there is no such scene object",
  2160. remoteClient.Name, itemID, fromTaskID);
  2161. return;
  2162. }
  2163. TaskInventoryItem item = part.Inventory.GetInventoryItem(itemID);
  2164. if (item == null)
  2165. {
  2166. m_log.ErrorFormat(
  2167. "[TASK INVENTORY]: {0} tried to rez item id {1} from object id {2} but there is no such item",
  2168. remoteClient.Name, itemID, fromTaskID);
  2169. return;
  2170. }
  2171. byte bRayEndIsIntersection = (byte)(RayEndIsIntersection ? 1 : 0);
  2172. Vector3 scale = new Vector3(0.5f, 0.5f, 0.5f);
  2173. Vector3 pos = GetNewRezLocation(
  2174. RayStart, RayEnd, RayTargetID, Quaternion.Identity,
  2175. BypassRayCast, bRayEndIsIntersection, true, scale, false);
  2176. RezObject(part, item, pos, null, Vector3.Zero, 0, false);
  2177. }
  2178. }
  2179. /// <summary>
  2180. /// Rez an object into the scene from a prim's inventory.
  2181. /// </summary>
  2182. /// <param name="sourcePart"></param>
  2183. /// <param name="item"></param>
  2184. /// <param name="pos">The position of the rezzed object.</param>
  2185. /// <param name="rot">The rotation of the rezzed object. If null, then the rotation stored with the object
  2186. /// will be used if it exists.</param>
  2187. /// <param name="vel">The velocity of the rezzed object.</param>
  2188. /// <param name="param"></param>
  2189. /// <returns>The SceneObjectGroup(s) rezzed, or null if rez was unsuccessful</returns>
  2190. public virtual List<SceneObjectGroup> RezObject(
  2191. SceneObjectPart sourcePart, TaskInventoryItem item, Vector3 pos, Quaternion? rot, Vector3 vel, int param, bool atRoot)
  2192. {
  2193. if (null == item)
  2194. return null;
  2195. List<SceneObjectGroup> objlist;
  2196. List<Vector3> veclist;
  2197. Vector3 bbox;
  2198. float offsetHeight;
  2199. bool success = sourcePart.Inventory.GetRezReadySceneObjects(item, out objlist, out veclist,out bbox, out offsetHeight);
  2200. if (!success)
  2201. return null;
  2202. int totalPrims = 0;
  2203. foreach (SceneObjectGroup group in objlist)
  2204. totalPrims += group.PrimCount;
  2205. if (!Permissions.CanRezObject(totalPrims, item.OwnerID, pos))
  2206. return null;
  2207. if (!Permissions.BypassPermissions())
  2208. {
  2209. if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
  2210. sourcePart.Inventory.RemoveInventoryItem(item.ItemID);
  2211. }
  2212. SceneObjectGroup sog;
  2213. bool fixrot = false;
  2214. Quaternion netRot = Quaternion.Identity;
  2215. // position adjust
  2216. if (totalPrims > 1) // nothing to do on a single prim
  2217. {
  2218. if (objlist.Count == 1)
  2219. {
  2220. // current object position is root position
  2221. if(!atRoot)
  2222. {
  2223. sog = objlist[0];
  2224. Quaternion orot;
  2225. if (rot == null)
  2226. orot = sog.RootPart.GetWorldRotation();
  2227. else
  2228. orot = rot.Value;
  2229. // possible should be bbox, but geometric center looks better
  2230. Vector3 off = sog.GetGeometricCenter();
  2231. // Vector3 off = bbox * 0.5f;
  2232. off *= orot;
  2233. pos -= off;
  2234. }
  2235. }
  2236. else
  2237. {
  2238. //veclist[] are relative to bbox corner with min X,Y and Z
  2239. // rez at root, and rot will be referenced to first object in list
  2240. if (rot == null)
  2241. {
  2242. // use original rotations
  2243. if (atRoot)
  2244. pos -= veclist[0];
  2245. else
  2246. pos -= bbox / 2;
  2247. }
  2248. else
  2249. {
  2250. fixrot = true;
  2251. sog = objlist[0];
  2252. netRot = Quaternion.Conjugate(sog.RootPart.GetWorldRotation());
  2253. netRot = netRot * rot.Value;
  2254. Vector3 off;
  2255. if (atRoot)
  2256. off = veclist[0];
  2257. else
  2258. off = bbox / 2;
  2259. off *= netRot;
  2260. pos -= off;
  2261. }
  2262. }
  2263. }
  2264. for (int i = 0; i < objlist.Count; i++)
  2265. {
  2266. SceneObjectGroup group = objlist[i];
  2267. Vector3 curpos;
  2268. if(fixrot)
  2269. curpos = pos + veclist[i] * netRot;
  2270. else
  2271. curpos = pos + veclist[i];
  2272. if (group.IsAttachment == false && group.RootPart.Shape.State != 0)
  2273. {
  2274. group.RootPart.AttachedPos = group.AbsolutePosition;
  2275. group.RootPart.Shape.LastAttachPoint = (byte)group.AttachmentPoint;
  2276. }
  2277. group.RezzerID = sourcePart.UUID;
  2278. if( i == 0)
  2279. AddNewSceneObject(group, true, curpos, rot, vel);
  2280. else
  2281. {
  2282. Quaternion crot = objlist[i].RootPart.GetWorldRotation();
  2283. if (fixrot)
  2284. {
  2285. crot *= netRot;
  2286. }
  2287. AddNewSceneObject(group, true, curpos, crot, vel);
  2288. }
  2289. // We can only call this after adding the scene object, since the scene object references the scene
  2290. // to find out if scripts should be activated at all.
  2291. group.InvalidateEffectivePerms();
  2292. group.CreateScriptInstances(param, true, DefaultScriptEngine, 3);
  2293. group.ScheduleGroupForFullUpdate();
  2294. }
  2295. return objlist;
  2296. }
  2297. public virtual bool returnObjects(SceneObjectGroup[] returnobjects,
  2298. IClientAPI client)
  2299. {
  2300. List<uint> localIDs = new List<uint>();
  2301. foreach (SceneObjectGroup grp in returnobjects)
  2302. {
  2303. AddReturn(grp.OwnerID, grp.Name, grp.AbsolutePosition,
  2304. "parcel owner return");
  2305. localIDs.Add(grp.RootPart.LocalId);
  2306. }
  2307. DeRezObjects(client, localIDs, UUID.Zero, DeRezAction.Return,
  2308. UUID.Zero, false);
  2309. return true;
  2310. }
  2311. public void SetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID, bool running)
  2312. {
  2313. if (!Permissions.CanEditScript(itemID, objectID, controllingClient.AgentId))
  2314. return;
  2315. SceneObjectPart part = GetSceneObjectPart(objectID);
  2316. if (part == null)
  2317. return;
  2318. if (running)
  2319. EventManager.TriggerStartScript(part.LocalId, itemID);
  2320. else
  2321. EventManager.TriggerStopScript(part.LocalId, itemID);
  2322. }
  2323. public void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID)
  2324. {
  2325. EventManager.TriggerGetScriptRunning(controllingClient, objectID, itemID);
  2326. }
  2327. void ObjectOwner(IClientAPI remoteClient, UUID ownerID, UUID groupID, List<uint> localIDs)
  2328. {
  2329. if (!Permissions.IsGod(remoteClient.AgentId))
  2330. {
  2331. if (ownerID != UUID.Zero)
  2332. return;
  2333. }
  2334. List<SceneObjectGroup> groups = new List<SceneObjectGroup>();
  2335. foreach (uint localID in localIDs)
  2336. {
  2337. SceneObjectPart part = GetSceneObjectPart(localID);
  2338. if (part == null)
  2339. continue;
  2340. if (!groups.Contains(part.ParentGroup))
  2341. groups.Add(part.ParentGroup);
  2342. }
  2343. foreach (SceneObjectGroup sog in groups)
  2344. {
  2345. if (ownerID != UUID.Zero)
  2346. {
  2347. sog.SetOwnerId(ownerID);
  2348. sog.SetGroup(groupID, remoteClient);
  2349. sog.ScheduleGroupForFullUpdate();
  2350. SceneObjectPart[] partList = sog.Parts;
  2351. foreach (SceneObjectPart child in partList)
  2352. {
  2353. child.Inventory.ChangeInventoryOwner(ownerID);
  2354. child.TriggerScriptChangedEvent(Changed.OWNER);
  2355. }
  2356. }
  2357. else // The object deeded to the group
  2358. {
  2359. if (!Permissions.CanDeedObject(remoteClient, sog, groupID))
  2360. continue;
  2361. sog.SetOwnerId(groupID);
  2362. // this is wrong, GroupMask is used for group sharing, still possible to set
  2363. // this whould give owner rights to users that are member of group but don't have role powers to edit
  2364. // sog.RootPart.GroupMask = sog.RootPart.OwnerMask;
  2365. // we should keep all permissions on deed to group
  2366. // and with this comented code, if user does not set next permissions on the object
  2367. // and on ALL contents of ALL prims, he may loose rights, making the object useless
  2368. sog.ApplyNextOwnerPermissions();
  2369. sog.InvalidateEffectivePerms();
  2370. sog.ScheduleGroupForFullUpdate();
  2371. SceneObjectPart[] partList = sog.Parts;
  2372. foreach (SceneObjectPart child in partList)
  2373. {
  2374. child.Inventory.ChangeInventoryOwner(groupID);
  2375. child.TriggerScriptChangedEvent(Changed.OWNER);
  2376. }
  2377. }
  2378. }
  2379. foreach (uint localID in localIDs)
  2380. {
  2381. SceneObjectPart part = GetSceneObjectPart(localID);
  2382. if (part == null)
  2383. continue;
  2384. part.SendPropertiesToClient(remoteClient);
  2385. }
  2386. }
  2387. public void DelinkObjects(List<uint> primIds, IClientAPI client)
  2388. {
  2389. List<SceneObjectPart> parts = new List<SceneObjectPart>();
  2390. foreach (uint localID in primIds)
  2391. {
  2392. SceneObjectPart part = GetSceneObjectPart(localID);
  2393. if (part == null)
  2394. continue;
  2395. if (Permissions.CanDelinkObject(client.AgentId, part.ParentGroup.RootPart.UUID))
  2396. parts.Add(part);
  2397. }
  2398. m_sceneGraph.DelinkObjects(parts);
  2399. }
  2400. /// <summary>
  2401. /// Link the scene objects containing the indicated parts to a root object.
  2402. /// </summary>
  2403. /// <param name="client"></param>
  2404. /// <param name="parentPrimId">A root prim id of the object which will be the root prim of the resulting linkset.</param>
  2405. /// <param name="childPrimIds">A list of child prims for the objects that should be linked in.</param>
  2406. public void LinkObjects(IClientAPI client, uint parentPrimId, List<uint> childPrimIds)
  2407. {
  2408. LinkObjects(client.AgentId, parentPrimId, childPrimIds);
  2409. }
  2410. /// <summary>
  2411. /// Link the scene objects containing the indicated parts to a root object.
  2412. /// </summary>
  2413. /// <param name="agentId">The ID of the user linking.</param>
  2414. /// <param name="parentPrimId">A root prim id of the object which will be the root prim of the resulting linkset.</param>
  2415. /// <param name="childPrimIds">A list of child prims for the objects that should be linked in.</param>
  2416. public void LinkObjects(UUID agentId, uint parentPrimId, List<uint> childPrimIds)
  2417. {
  2418. List<UUID> owners = new List<UUID>();
  2419. List<SceneObjectPart> children = new List<SceneObjectPart>();
  2420. SceneObjectPart root = GetSceneObjectPart(parentPrimId);
  2421. if (root == null)
  2422. {
  2423. m_log.DebugFormat("[LINK]: Can't find linkset root prim {0}", parentPrimId);
  2424. return;
  2425. }
  2426. if (!Permissions.CanLinkObject(agentId, root.ParentGroup.RootPart.UUID))
  2427. {
  2428. m_log.DebugFormat("[LINK]: Refusing link. No permissions on root prim");
  2429. return;
  2430. }
  2431. foreach (uint localID in childPrimIds)
  2432. {
  2433. SceneObjectPart part = GetSceneObjectPart(localID);
  2434. if (part == null)
  2435. continue;
  2436. if (!owners.Contains(part.OwnerID))
  2437. owners.Add(part.OwnerID);
  2438. if (Permissions.CanLinkObject(agentId, part.ParentGroup.RootPart.UUID))
  2439. children.Add(part);
  2440. }
  2441. // Must be all one owner
  2442. //
  2443. if (owners.Count > 1)
  2444. {
  2445. m_log.DebugFormat("[LINK]: Refusing link. Too many owners");
  2446. return;
  2447. }
  2448. if (children.Count == 0)
  2449. {
  2450. m_log.DebugFormat("[LINK]: Refusing link. No permissions to link any of the children");
  2451. return;
  2452. }
  2453. bool oldUsePhysics = (root.Flags & PrimFlags.Physics) != 0;
  2454. m_sceneGraph.LinkObjects(root, children);
  2455. ScenePresence sp;
  2456. if (TryGetScenePresence(agentId, out sp))
  2457. {
  2458. root.SendPropertiesToClient(sp.ControllingClient);
  2459. if (oldUsePhysics && (root.Flags & PrimFlags.Physics) == 0)
  2460. {
  2461. sp.ControllingClient.SendAlertMessage("Object physics cancelled");
  2462. }
  2463. }
  2464. }
  2465. private string PermissionString(uint permissions)
  2466. {
  2467. PermissionMask perms = (PermissionMask)permissions &
  2468. (PermissionMask.Move |
  2469. PermissionMask.Copy |
  2470. PermissionMask.Transfer |
  2471. PermissionMask.Modify);
  2472. return perms.ToString();
  2473. }
  2474. }
  2475. }