Scene.PacketHandlers.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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. ViewerEffectPacket.EffectBlock[] effectBlockArray = new ViewerEffectPacket.EffectBlock[args.Count];
  342. for (int i = 0; i < args.Count; i++)
  343. {
  344. ViewerEffectPacket.EffectBlock effect = new ViewerEffectPacket.EffectBlock();
  345. effect.AgentID = args[i].AgentID;
  346. effect.Color = args[i].Color;
  347. effect.Duration = args[i].Duration;
  348. effect.ID = args[i].ID;
  349. effect.Type = args[i].Type;
  350. effect.TypeData = args[i].TypeData;
  351. effectBlockArray[i] = effect;
  352. }
  353. ForEachClient(
  354. delegate(IClientAPI client)
  355. {
  356. if (client.AgentId != remoteClient.AgentId)
  357. client.SendViewerEffect(effectBlockArray);
  358. }
  359. );
  360. }
  361. /// <summary>
  362. /// Tell the client about the various child items and folders contained in the requested folder.
  363. /// </summary>
  364. /// <param name="remoteClient"></param>
  365. /// <param name="folderID"></param>
  366. /// <param name="ownerID"></param>
  367. /// <param name="fetchFolders"></param>
  368. /// <param name="fetchItems"></param>
  369. /// <param name="sortOrder"></param>
  370. public void HandleFetchInventoryDescendents(IClientAPI remoteClient, UUID folderID, UUID ownerID,
  371. bool fetchFolders, bool fetchItems, int sortOrder)
  372. {
  373. // m_log.DebugFormat(
  374. // "[USER INVENTORY]: HandleFetchInventoryDescendents() for {0}, folder={1}, fetchFolders={2}, fetchItems={3}, sortOrder={4}",
  375. // remoteClient.Name, folderID, fetchFolders, fetchItems, sortOrder);
  376. if (folderID == UUID.Zero)
  377. return;
  378. // FIXME MAYBE: We're not handling sortOrder!
  379. // TODO: This code for looking in the folder for the library should be folded somewhere else
  380. // so that this class doesn't have to know the details (and so that multiple libraries, etc.
  381. // can be handled transparently).
  382. InventoryFolderImpl fold = null;
  383. if (LibraryService != null && LibraryService.LibraryRootFolder != null)
  384. {
  385. if ((fold = LibraryService.LibraryRootFolder.FindFolder(folderID)) != null)
  386. {
  387. remoteClient.SendInventoryFolderDetails(
  388. fold.Owner, folderID, fold.RequestListOfItems(),
  389. fold.RequestListOfFolders(), fold.Version, fetchFolders, fetchItems);
  390. return;
  391. }
  392. }
  393. // We're going to send the reply async, because there may be
  394. // an enormous quantity of packets -- basically the entire inventory!
  395. // We don't want to block the client thread while all that is happening.
  396. SendInventoryDelegate d = SendInventoryAsync;
  397. d.BeginInvoke(remoteClient, folderID, ownerID, fetchFolders, fetchItems, sortOrder, SendInventoryComplete, d);
  398. }
  399. delegate void SendInventoryDelegate(IClientAPI remoteClient, UUID folderID, UUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder);
  400. void SendInventoryAsync(IClientAPI remoteClient, UUID folderID, UUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder)
  401. {
  402. SendInventoryUpdate(remoteClient, new InventoryFolderBase(folderID), fetchFolders, fetchItems);
  403. }
  404. void SendInventoryComplete(IAsyncResult iar)
  405. {
  406. SendInventoryDelegate d = (SendInventoryDelegate)iar.AsyncState;
  407. d.EndInvoke(iar);
  408. }
  409. /// <summary>
  410. /// Handle an inventory folder creation request from the client.
  411. /// </summary>
  412. /// <param name="remoteClient"></param>
  413. /// <param name="folderID"></param>
  414. /// <param name="folderType"></param>
  415. /// <param name="folderName"></param>
  416. /// <param name="parentID"></param>
  417. public void HandleCreateInventoryFolder(IClientAPI remoteClient, UUID folderID, ushort folderType,
  418. string folderName, UUID parentID)
  419. {
  420. InventoryFolderBase folder = new InventoryFolderBase(folderID, folderName, remoteClient.AgentId, (short)folderType, parentID, 1);
  421. if (!InventoryService.AddFolder(folder))
  422. {
  423. m_log.WarnFormat(
  424. "[AGENT INVENTORY]: Failed to create folder for user {0} {1}",
  425. remoteClient.Name, remoteClient.AgentId);
  426. }
  427. }
  428. /// <summary>
  429. /// Handle a client request to update the inventory folder
  430. /// </summary>
  431. ///
  432. /// FIXME: We call add new inventory folder because in the data layer, we happen to use an SQL REPLACE
  433. /// so this will work to rename an existing folder. Needless to say, to rely on this is very confusing,
  434. /// and needs to be changed.
  435. ///
  436. /// <param name="remoteClient"></param>
  437. /// <param name="folderID"></param>
  438. /// <param name="type"></param>
  439. /// <param name="name"></param>
  440. /// <param name="parentID"></param>
  441. public void HandleUpdateInventoryFolder(IClientAPI remoteClient, UUID folderID, ushort type, string name,
  442. UUID parentID)
  443. {
  444. // m_log.DebugFormat(
  445. // "[AGENT INVENTORY]: Updating inventory folder {0} {1} for {2} {3}", folderID, name, remoteClient.Name, remoteClient.AgentId);
  446. InventoryFolderBase folder = new InventoryFolderBase(folderID, remoteClient.AgentId);
  447. folder = InventoryService.GetFolder(folder);
  448. if (folder != null)
  449. {
  450. folder.Name = name;
  451. folder.Type = (short)type;
  452. folder.ParentID = parentID;
  453. if (!InventoryService.UpdateFolder(folder))
  454. {
  455. m_log.ErrorFormat(
  456. "[AGENT INVENTORY]: Failed to update folder for user {0} {1}",
  457. remoteClient.Name, remoteClient.AgentId);
  458. }
  459. }
  460. }
  461. public void HandleMoveInventoryFolder(IClientAPI remoteClient, UUID folderID, UUID parentID)
  462. {
  463. InventoryFolderBase folder = new InventoryFolderBase(folderID, remoteClient.AgentId);
  464. folder = InventoryService.GetFolder(folder);
  465. if (folder != null)
  466. {
  467. folder.ParentID = parentID;
  468. if (!InventoryService.MoveFolder(folder))
  469. m_log.WarnFormat("[AGENT INVENTORY]: could not move folder {0}", folderID);
  470. else
  471. m_log.DebugFormat("[AGENT INVENTORY]: folder {0} moved to parent {1}", folderID, parentID);
  472. }
  473. else
  474. {
  475. m_log.WarnFormat("[AGENT INVENTORY]: request to move folder {0} but folder not found", folderID);
  476. }
  477. }
  478. delegate void PurgeFolderDelegate(UUID userID, UUID folder);
  479. /// <summary>
  480. /// This should delete all the items and folders in the given directory.
  481. /// </summary>
  482. /// <param name="remoteClient"></param>
  483. /// <param name="folderID"></param>
  484. public void HandlePurgeInventoryDescendents(IClientAPI remoteClient, UUID folderID)
  485. {
  486. PurgeFolderDelegate d = PurgeFolderAsync;
  487. try
  488. {
  489. d.BeginInvoke(remoteClient.AgentId, folderID, PurgeFolderCompleted, d);
  490. }
  491. catch (Exception e)
  492. {
  493. m_log.WarnFormat("[AGENT INVENTORY]: Exception on purge folder for user {0}: {1}", remoteClient.AgentId, e.Message);
  494. }
  495. }
  496. private void PurgeFolderAsync(UUID userID, UUID folderID)
  497. {
  498. InventoryFolderBase folder = new InventoryFolderBase(folderID, userID);
  499. if (InventoryService.PurgeFolder(folder))
  500. m_log.DebugFormat("[AGENT INVENTORY]: folder {0} purged successfully", folderID);
  501. else
  502. m_log.WarnFormat("[AGENT INVENTORY]: could not purge folder {0}", folderID);
  503. }
  504. private void PurgeFolderCompleted(IAsyncResult iar)
  505. {
  506. PurgeFolderDelegate d = (PurgeFolderDelegate)iar.AsyncState;
  507. d.EndInvoke(iar);
  508. }
  509. }
  510. }