Scene.PacketHandlers.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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.Threading;
  30. using OpenMetaverse;
  31. using OpenMetaverse.Packets;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Communications;
  34. using OpenSim.Services.Interfaces;
  35. namespace OpenSim.Region.Framework.Scenes
  36. {
  37. public partial class Scene
  38. {
  39. /// <summary>
  40. /// Send chat to listeners.
  41. /// </summary>
  42. /// <param name='message'></param>
  43. /// <param name='type'>/param>
  44. /// <param name='channel'></param>
  45. /// <param name='fromPos'></param>
  46. /// <param name='fromName'></param>
  47. /// <param name='fromID'></param>
  48. /// <param name='targetID'></param>
  49. /// <param name='fromAgent'></param>
  50. /// <param name='broadcast'></param>
  51. protected void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
  52. UUID fromID, UUID targetID, bool fromAgent, bool broadcast)
  53. {
  54. OSChatMessage args = new OSChatMessage();
  55. args.Message = Utils.BytesToString(message);
  56. args.Channel = channel;
  57. args.Type = type;
  58. args.Position = fromPos;
  59. args.SenderUUID = fromID;
  60. args.Scene = this;
  61. if (fromAgent)
  62. {
  63. ScenePresence user = GetScenePresence(fromID);
  64. if (user != null)
  65. args.Sender = user.ControllingClient;
  66. }
  67. else
  68. {
  69. SceneObjectPart obj = GetSceneObjectPart(fromID);
  70. args.SenderObject = obj;
  71. }
  72. args.From = fromName;
  73. args.TargetUUID = targetID;
  74. // m_log.DebugFormat(
  75. // "[SCENE]: Sending message {0} on channel {1}, type {2} from {3}, broadcast {4}",
  76. // args.Message.Replace("\n", "\\n"), args.Channel, args.Type, fromName, broadcast);
  77. if (broadcast)
  78. EventManager.TriggerOnChatBroadcast(this, args);
  79. else
  80. EventManager.TriggerOnChatFromWorld(this, args);
  81. }
  82. protected void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
  83. UUID fromID, bool fromAgent, bool broadcast)
  84. {
  85. SimChat(message, type, channel, fromPos, fromName, fromID, UUID.Zero, fromAgent, broadcast);
  86. }
  87. /// <summary>
  88. ///
  89. /// </summary>
  90. /// <param name="message"></param>
  91. /// <param name="type"></param>
  92. /// <param name="fromPos"></param>
  93. /// <param name="fromName"></param>
  94. /// <param name="fromAgentID"></param>
  95. public void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
  96. UUID fromID, bool fromAgent)
  97. {
  98. SimChat(message, type, channel, fromPos, fromName, fromID, fromAgent, false);
  99. }
  100. public void SimChat(string message, ChatTypeEnum type, Vector3 fromPos, string fromName, UUID fromID, bool fromAgent)
  101. {
  102. SimChat(Utils.StringToBytes(message), type, 0, fromPos, fromName, fromID, fromAgent);
  103. }
  104. public void SimChat(string message, string fromName)
  105. {
  106. SimChat(message, ChatTypeEnum.Broadcast, Vector3.Zero, fromName, UUID.Zero, false);
  107. }
  108. /// <summary>
  109. ///
  110. /// </summary>
  111. /// <param name="message"></param>
  112. /// <param name="type"></param>
  113. /// <param name="fromPos"></param>
  114. /// <param name="fromName"></param>
  115. /// <param name="fromAgentID"></param>
  116. public void SimChatBroadcast(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
  117. UUID fromID, bool fromAgent)
  118. {
  119. SimChat(message, type, channel, fromPos, fromName, fromID, fromAgent, true);
  120. }
  121. /// <summary>
  122. ///
  123. /// </summary>
  124. /// <param name="message"></param>
  125. /// <param name="type"></param>
  126. /// <param name="fromPos"></param>
  127. /// <param name="fromName"></param>
  128. /// <param name="fromAgentID"></param>
  129. /// <param name="targetID"></param>
  130. public void SimChatToAgent(UUID targetID, byte[] message, Vector3 fromPos, string fromName, UUID fromID, bool fromAgent)
  131. {
  132. SimChat(message, ChatTypeEnum.Say, 0, fromPos, fromName, fromID, targetID, fromAgent, false);
  133. }
  134. /// <summary>
  135. /// Invoked when the client requests a prim.
  136. /// </summary>
  137. /// <param name="primLocalID"></param>
  138. /// <param name="remoteClient"></param>
  139. public void RequestPrim(uint primLocalID, IClientAPI remoteClient)
  140. {
  141. SceneObjectGroup sog = GetGroupByPrim(primLocalID);
  142. if (sog != null)
  143. sog.SendFullUpdateToClient(remoteClient);
  144. }
  145. /// <summary>
  146. /// Invoked when the client selects a prim.
  147. /// </summary>
  148. /// <param name="primLocalID"></param>
  149. /// <param name="remoteClient"></param>
  150. public void SelectPrim(uint primLocalID, IClientAPI remoteClient)
  151. {
  152. SceneObjectPart part = GetSceneObjectPart(primLocalID);
  153. if (null == part)
  154. return;
  155. if (part.IsRoot)
  156. {
  157. SceneObjectGroup sog = part.ParentGroup;
  158. sog.SendPropertiesToClient(remoteClient);
  159. sog.IsSelected = true;
  160. // A prim is only tainted if it's allowed to be edited by the person clicking it.
  161. if (Permissions.CanEditObject(sog.UUID, remoteClient.AgentId)
  162. || Permissions.CanMoveObject(sog.UUID, remoteClient.AgentId))
  163. {
  164. EventManager.TriggerParcelPrimCountTainted();
  165. }
  166. }
  167. else
  168. {
  169. part.SendPropertiesToClient(remoteClient);
  170. }
  171. }
  172. /// <summary>
  173. /// Handle the update of an object's user group.
  174. /// </summary>
  175. /// <param name="remoteClient"></param>
  176. /// <param name="groupID"></param>
  177. /// <param name="objectLocalID"></param>
  178. /// <param name="Garbage"></param>
  179. private void HandleObjectGroupUpdate(
  180. IClientAPI remoteClient, UUID groupID, uint objectLocalID, UUID Garbage)
  181. {
  182. if (m_groupsModule == null)
  183. return;
  184. // XXX: Might be better to get rid of this special casing and have GetMembershipData return something
  185. // reasonable for a UUID.Zero group.
  186. if (groupID != UUID.Zero)
  187. {
  188. GroupMembershipData gmd = m_groupsModule.GetMembershipData(groupID, remoteClient.AgentId);
  189. if (gmd == null)
  190. {
  191. // m_log.WarnFormat(
  192. // "[GROUPS]: User {0} is not a member of group {1} so they can't update {2} to this group",
  193. // remoteClient.Name, GroupID, objectLocalID);
  194. return;
  195. }
  196. }
  197. SceneObjectGroup so = ((Scene)remoteClient.Scene).GetGroupByPrim(objectLocalID);
  198. if (so != null)
  199. {
  200. if (so.OwnerID == remoteClient.AgentId)
  201. {
  202. so.SetGroup(groupID, remoteClient);
  203. }
  204. }
  205. }
  206. /// <summary>
  207. /// Handle the deselection of a prim from the client.
  208. /// </summary>
  209. /// <param name="primLocalID"></param>
  210. /// <param name="remoteClient"></param>
  211. public void DeselectPrim(uint primLocalID, IClientAPI remoteClient)
  212. {
  213. SceneObjectPart part = GetSceneObjectPart(primLocalID);
  214. if (part == null)
  215. return;
  216. // A deselect packet contains all the local prims being deselected. However, since selection is still
  217. // group based we only want the root prim to trigger a full update - otherwise on objects with many prims
  218. // we end up sending many duplicate ObjectUpdates
  219. if (part.ParentGroup.RootPart.LocalId != part.LocalId)
  220. return;
  221. bool isAttachment = false;
  222. // This is wrong, wrong, wrong. Selection should not be
  223. // handled by group, but by prim. Legacy cruft.
  224. // TODO: Make selection flagging per prim!
  225. //
  226. part.ParentGroup.IsSelected = false;
  227. if (part.ParentGroup.IsAttachment)
  228. isAttachment = true;
  229. else
  230. part.ParentGroup.ScheduleGroupForFullUpdate();
  231. // If it's not an attachment, and we are allowed to move it,
  232. // then we might have done so. If we moved across a parcel
  233. // boundary, we will need to recount prims on the parcels.
  234. // For attachments, that makes no sense.
  235. //
  236. if (!isAttachment)
  237. {
  238. if (Permissions.CanEditObject(
  239. part.UUID, remoteClient.AgentId)
  240. || Permissions.CanMoveObject(
  241. part.UUID, remoteClient.AgentId))
  242. EventManager.TriggerParcelPrimCountTainted();
  243. }
  244. }
  245. public virtual void ProcessMoneyTransferRequest(UUID source, UUID destination, int amount,
  246. int transactiontype, string description)
  247. {
  248. EventManager.MoneyTransferArgs args = new EventManager.MoneyTransferArgs(source, destination, amount,
  249. transactiontype, description);
  250. EventManager.TriggerMoneyTransfer(this, args);
  251. }
  252. public virtual void ProcessParcelBuy(UUID agentId, UUID groupId, bool final, bool groupOwned,
  253. bool removeContribution, int parcelLocalID, int parcelArea, int parcelPrice, bool authenticated)
  254. {
  255. EventManager.LandBuyArgs args = new EventManager.LandBuyArgs(agentId, groupId, final, groupOwned,
  256. removeContribution, parcelLocalID, parcelArea,
  257. parcelPrice, authenticated);
  258. // First, allow all validators a stab at it
  259. m_eventManager.TriggerValidateLandBuy(this, args);
  260. // Then, check validation and transfer
  261. m_eventManager.TriggerLandBuy(this, args);
  262. }
  263. public virtual void ProcessObjectGrab(uint localID, Vector3 offsetPos, IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs)
  264. {
  265. SceneObjectPart part = GetSceneObjectPart(localID);
  266. if (part == null)
  267. return;
  268. SceneObjectGroup obj = part.ParentGroup;
  269. SurfaceTouchEventArgs surfaceArg = null;
  270. if (surfaceArgs != null && surfaceArgs.Count > 0)
  271. surfaceArg = surfaceArgs[0];
  272. // Currently only grab/touch for the single prim
  273. // the client handles rez correctly
  274. obj.ObjectGrabHandler(localID, offsetPos, remoteClient);
  275. // If the touched prim handles touches, deliver it
  276. // If not, deliver to root prim
  277. if ((part.ScriptEvents & scriptEvents.touch_start) != 0)
  278. EventManager.TriggerObjectGrab(part.LocalId, 0, part.OffsetPosition, remoteClient, surfaceArg);
  279. // Deliver to the root prim if the touched prim doesn't handle touches
  280. // or if we're meant to pass on touches anyway. Don't send to root prim
  281. // if prim touched is the root prim as we just did it
  282. if (((part.ScriptEvents & scriptEvents.touch_start) == 0) ||
  283. (part.PassTouches && (part.LocalId != obj.RootPart.LocalId)))
  284. {
  285. EventManager.TriggerObjectGrab(obj.RootPart.LocalId, part.LocalId, part.OffsetPosition, remoteClient, surfaceArg);
  286. }
  287. }
  288. public virtual void ProcessObjectGrabUpdate(
  289. UUID objectID, Vector3 offset, Vector3 pos, IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs)
  290. {
  291. SceneObjectPart part = GetSceneObjectPart(objectID);
  292. if (part == null)
  293. return;
  294. SceneObjectGroup obj = part.ParentGroup;
  295. SurfaceTouchEventArgs surfaceArg = null;
  296. if (surfaceArgs != null && surfaceArgs.Count > 0)
  297. surfaceArg = surfaceArgs[0];
  298. // If the touched prim handles touches, deliver it
  299. // If not, deliver to root prim
  300. if ((part.ScriptEvents & scriptEvents.touch) != 0)
  301. EventManager.TriggerObjectGrabbing(part.LocalId, 0, part.OffsetPosition, remoteClient, surfaceArg);
  302. // Deliver to the root prim if the touched prim doesn't handle touches
  303. // or if we're meant to pass on touches anyway. Don't send to root prim
  304. // if prim touched is the root prim as we just did it
  305. if (((part.ScriptEvents & scriptEvents.touch) == 0) ||
  306. (part.PassTouches && (part.LocalId != obj.RootPart.LocalId)))
  307. {
  308. EventManager.TriggerObjectGrabbing(obj.RootPart.LocalId, part.LocalId, part.OffsetPosition, remoteClient, surfaceArg);
  309. }
  310. }
  311. public virtual void ProcessObjectDeGrab(uint localID, IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs)
  312. {
  313. SceneObjectPart part = GetSceneObjectPart(localID);
  314. if (part == null)
  315. return;
  316. SceneObjectGroup obj = part.ParentGroup;
  317. SurfaceTouchEventArgs surfaceArg = null;
  318. if (surfaceArgs != null && surfaceArgs.Count > 0)
  319. surfaceArg = surfaceArgs[0];
  320. // If the touched prim handles touches, deliver it
  321. // If not, deliver to root prim
  322. if ((part.ScriptEvents & scriptEvents.touch_end) != 0)
  323. EventManager.TriggerObjectDeGrab(part.LocalId, 0, remoteClient, surfaceArg);
  324. else
  325. EventManager.TriggerObjectDeGrab(obj.RootPart.LocalId, part.LocalId, remoteClient, surfaceArg);
  326. }
  327. public void ProcessScriptReset(IClientAPI remoteClient, UUID objectID,
  328. UUID itemID)
  329. {
  330. SceneObjectPart part=GetSceneObjectPart(objectID);
  331. if (part == null)
  332. return;
  333. if (Permissions.CanResetScript(objectID, itemID, remoteClient.AgentId))
  334. {
  335. EventManager.TriggerScriptReset(part.LocalId, itemID);
  336. }
  337. }
  338. void ProcessViewerEffect(IClientAPI remoteClient, List<ViewerEffectEventHandlerArg> args)
  339. {
  340. // TODO: don't create new blocks if recycling an old packet
  341. bool discardableEffects = true;
  342. ViewerEffectPacket.EffectBlock[] effectBlockArray = new ViewerEffectPacket.EffectBlock[args.Count];
  343. for (int i = 0; i < args.Count; i++)
  344. {
  345. ViewerEffectPacket.EffectBlock effect = new ViewerEffectPacket.EffectBlock();
  346. effect.AgentID = args[i].AgentID;
  347. effect.Color = args[i].Color;
  348. effect.Duration = args[i].Duration;
  349. effect.ID = args[i].ID;
  350. effect.Type = args[i].Type;
  351. effect.TypeData = args[i].TypeData;
  352. effectBlockArray[i] = effect;
  353. if ((EffectType)effect.Type != EffectType.LookAt && (EffectType)effect.Type != EffectType.Beam)
  354. discardableEffects = false;
  355. //m_log.DebugFormat("[YYY]: VE {0} {1} {2}", effect.AgentID, effect.Duration, (EffectType)effect.Type);
  356. }
  357. ForEachScenePresence(sp =>
  358. {
  359. if (sp.ControllingClient.AgentId != remoteClient.AgentId)
  360. {
  361. if (!discardableEffects ||
  362. (discardableEffects && ShouldSendDiscardableEffect(remoteClient, sp)))
  363. {
  364. //m_log.DebugFormat("[YYY]: Sending to {0}", sp.UUID);
  365. sp.ControllingClient.SendViewerEffect(effectBlockArray);
  366. }
  367. //else
  368. // m_log.DebugFormat("[YYY]: Not sending to {0}", sp.UUID);
  369. }
  370. });
  371. }
  372. private bool ShouldSendDiscardableEffect(IClientAPI thisClient, ScenePresence other)
  373. {
  374. return Vector3.Distance(other.CameraPosition, thisClient.SceneAgent.AbsolutePosition) < 10;
  375. }
  376. /// <summary>
  377. /// Tell the client about the various child items and folders contained in the requested folder.
  378. /// </summary>
  379. /// <param name="remoteClient"></param>
  380. /// <param name="folderID"></param>
  381. /// <param name="ownerID"></param>
  382. /// <param name="fetchFolders"></param>
  383. /// <param name="fetchItems"></param>
  384. /// <param name="sortOrder"></param>
  385. public void HandleFetchInventoryDescendents(IClientAPI remoteClient, UUID folderID, UUID ownerID,
  386. bool fetchFolders, bool fetchItems, int sortOrder)
  387. {
  388. // m_log.DebugFormat(
  389. // "[USER INVENTORY]: HandleFetchInventoryDescendents() for {0}, folder={1}, fetchFolders={2}, fetchItems={3}, sortOrder={4}",
  390. // remoteClient.Name, folderID, fetchFolders, fetchItems, sortOrder);
  391. if (folderID == UUID.Zero)
  392. return;
  393. // FIXME MAYBE: We're not handling sortOrder!
  394. // TODO: This code for looking in the folder for the library should be folded somewhere else
  395. // so that this class doesn't have to know the details (and so that multiple libraries, etc.
  396. // can be handled transparently).
  397. InventoryFolderImpl fold = null;
  398. if (LibraryService != null && LibraryService.LibraryRootFolder != null)
  399. {
  400. if ((fold = LibraryService.LibraryRootFolder.FindFolder(folderID)) != null)
  401. {
  402. remoteClient.SendInventoryFolderDetails(
  403. fold.Owner, folderID, fold.RequestListOfItems(),
  404. fold.RequestListOfFolders(), fold.Version, fetchFolders, fetchItems);
  405. return;
  406. }
  407. }
  408. // We're going to send the reply async, because there may be
  409. // an enormous quantity of packets -- basically the entire inventory!
  410. // We don't want to block the client thread while all that is happening.
  411. SendInventoryDelegate d = SendInventoryAsync;
  412. d.BeginInvoke(remoteClient, folderID, ownerID, fetchFolders, fetchItems, sortOrder, SendInventoryComplete, d);
  413. }
  414. delegate void SendInventoryDelegate(IClientAPI remoteClient, UUID folderID, UUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder);
  415. void SendInventoryAsync(IClientAPI remoteClient, UUID folderID, UUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder)
  416. {
  417. SendInventoryUpdate(remoteClient, new InventoryFolderBase(folderID), fetchFolders, fetchItems);
  418. }
  419. void SendInventoryComplete(IAsyncResult iar)
  420. {
  421. SendInventoryDelegate d = (SendInventoryDelegate)iar.AsyncState;
  422. d.EndInvoke(iar);
  423. }
  424. /// <summary>
  425. /// Handle an inventory folder creation request from the client.
  426. /// </summary>
  427. /// <param name="remoteClient"></param>
  428. /// <param name="folderID"></param>
  429. /// <param name="folderType"></param>
  430. /// <param name="folderName"></param>
  431. /// <param name="parentID"></param>
  432. public void HandleCreateInventoryFolder(IClientAPI remoteClient, UUID folderID, ushort folderType,
  433. string folderName, UUID parentID)
  434. {
  435. InventoryFolderBase folder = new InventoryFolderBase(folderID, folderName, remoteClient.AgentId, (short)folderType, parentID, 1);
  436. if (!InventoryService.AddFolder(folder))
  437. {
  438. m_log.WarnFormat(
  439. "[AGENT INVENTORY]: Failed to create folder for user {0} {1}",
  440. remoteClient.Name, remoteClient.AgentId);
  441. }
  442. }
  443. /// <summary>
  444. /// Handle a client request to update the inventory folder
  445. /// </summary>
  446. ///
  447. /// FIXME: We call add new inventory folder because in the data layer, we happen to use an SQL REPLACE
  448. /// so this will work to rename an existing folder. Needless to say, to rely on this is very confusing,
  449. /// and needs to be changed.
  450. ///
  451. /// <param name="remoteClient"></param>
  452. /// <param name="folderID"></param>
  453. /// <param name="type"></param>
  454. /// <param name="name"></param>
  455. /// <param name="parentID"></param>
  456. public void HandleUpdateInventoryFolder(IClientAPI remoteClient, UUID folderID, ushort type, string name,
  457. UUID parentID)
  458. {
  459. // m_log.DebugFormat(
  460. // "[AGENT INVENTORY]: Updating inventory folder {0} {1} for {2} {3}", folderID, name, remoteClient.Name, remoteClient.AgentId);
  461. InventoryFolderBase folder = new InventoryFolderBase(folderID, remoteClient.AgentId);
  462. folder = InventoryService.GetFolder(folder);
  463. if (folder != null)
  464. {
  465. folder.Name = name;
  466. folder.Type = (short)type;
  467. folder.ParentID = parentID;
  468. if (!InventoryService.UpdateFolder(folder))
  469. {
  470. m_log.ErrorFormat(
  471. "[AGENT INVENTORY]: Failed to update folder for user {0} {1}",
  472. remoteClient.Name, remoteClient.AgentId);
  473. }
  474. }
  475. }
  476. public void HandleMoveInventoryFolder(IClientAPI remoteClient, UUID folderID, UUID parentID)
  477. {
  478. InventoryFolderBase folder = new InventoryFolderBase(folderID, remoteClient.AgentId);
  479. folder = InventoryService.GetFolder(folder);
  480. if (folder != null)
  481. {
  482. folder.ParentID = parentID;
  483. if (!InventoryService.MoveFolder(folder))
  484. m_log.WarnFormat("[AGENT INVENTORY]: could not move folder {0}", folderID);
  485. else
  486. m_log.DebugFormat("[AGENT INVENTORY]: folder {0} moved to parent {1}", folderID, parentID);
  487. }
  488. else
  489. {
  490. m_log.WarnFormat("[AGENT INVENTORY]: request to move folder {0} but folder not found", folderID);
  491. }
  492. }
  493. delegate void PurgeFolderDelegate(UUID userID, UUID folder);
  494. /// <summary>
  495. /// This should delete all the items and folders in the given directory.
  496. /// </summary>
  497. /// <param name="remoteClient"></param>
  498. /// <param name="folderID"></param>
  499. public void HandlePurgeInventoryDescendents(IClientAPI remoteClient, UUID folderID)
  500. {
  501. PurgeFolderDelegate d = PurgeFolderAsync;
  502. try
  503. {
  504. d.BeginInvoke(remoteClient.AgentId, folderID, PurgeFolderCompleted, d);
  505. }
  506. catch (Exception e)
  507. {
  508. m_log.WarnFormat("[AGENT INVENTORY]: Exception on purge folder for user {0}: {1}", remoteClient.AgentId, e.Message);
  509. }
  510. }
  511. private void PurgeFolderAsync(UUID userID, UUID folderID)
  512. {
  513. InventoryFolderBase folder = new InventoryFolderBase(folderID, userID);
  514. if (InventoryService.PurgeFolder(folder))
  515. m_log.DebugFormat("[AGENT INVENTORY]: folder {0} purged successfully", folderID);
  516. else
  517. m_log.WarnFormat("[AGENT INVENTORY]: could not purge folder {0}", folderID);
  518. }
  519. private void PurgeFolderCompleted(IAsyncResult iar)
  520. {
  521. PurgeFolderDelegate d = (PurgeFolderDelegate)iar.AsyncState;
  522. d.EndInvoke(iar);
  523. }
  524. }
  525. }