Scene.PacketHandlers.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  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. // This is wrong, wrong, wrong. Selection should not be
  222. // handled by group, but by prim. Legacy cruft.
  223. // TODO: Make selection flagging per prim!
  224. //
  225. part.ParentGroup.IsSelected = false;
  226. part.ParentGroup.ScheduleGroupForFullUpdate();
  227. // If it's not an attachment, and we are allowed to move it,
  228. // then we might have done so. If we moved across a parcel
  229. // boundary, we will need to recount prims on the parcels.
  230. // For attachments, that makes no sense.
  231. //
  232. if (!part.ParentGroup.IsAttachment)
  233. {
  234. if (Permissions.CanEditObject(
  235. part.UUID, remoteClient.AgentId)
  236. || Permissions.CanMoveObject(
  237. part.UUID, remoteClient.AgentId))
  238. EventManager.TriggerParcelPrimCountTainted();
  239. }
  240. }
  241. public virtual void ProcessMoneyTransferRequest(UUID source, UUID destination, int amount,
  242. int transactiontype, string description)
  243. {
  244. EventManager.MoneyTransferArgs args = new EventManager.MoneyTransferArgs(source, destination, amount,
  245. transactiontype, description);
  246. EventManager.TriggerMoneyTransfer(this, args);
  247. }
  248. public virtual void ProcessParcelBuy(UUID agentId, UUID groupId, bool final, bool groupOwned,
  249. bool removeContribution, int parcelLocalID, int parcelArea, int parcelPrice, bool authenticated)
  250. {
  251. EventManager.LandBuyArgs args = new EventManager.LandBuyArgs(agentId, groupId, final, groupOwned,
  252. removeContribution, parcelLocalID, parcelArea,
  253. parcelPrice, authenticated);
  254. // First, allow all validators a stab at it
  255. m_eventManager.TriggerValidateLandBuy(this, args);
  256. // Then, check validation and transfer
  257. m_eventManager.TriggerLandBuy(this, args);
  258. }
  259. public virtual void ProcessObjectGrab(uint localID, Vector3 offsetPos, IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs)
  260. {
  261. SceneObjectPart part = GetSceneObjectPart(localID);
  262. if (part == null)
  263. return;
  264. SceneObjectGroup obj = part.ParentGroup;
  265. SurfaceTouchEventArgs surfaceArg = null;
  266. if (surfaceArgs != null && surfaceArgs.Count > 0)
  267. surfaceArg = surfaceArgs[0];
  268. // Currently only grab/touch for the single prim
  269. // the client handles rez correctly
  270. obj.ObjectGrabHandler(localID, offsetPos, remoteClient);
  271. // If the touched prim handles touches, deliver it
  272. // If not, deliver to root prim
  273. if ((part.ScriptEvents & scriptEvents.touch_start) != 0)
  274. EventManager.TriggerObjectGrab(part.LocalId, 0, part.OffsetPosition, remoteClient, surfaceArg);
  275. // Deliver to the root prim if the touched prim doesn't handle touches
  276. // or if we're meant to pass on touches anyway. Don't send to root prim
  277. // if prim touched is the root prim as we just did it
  278. if (((part.ScriptEvents & scriptEvents.touch_start) == 0) ||
  279. (part.PassTouches && (part.LocalId != obj.RootPart.LocalId)))
  280. {
  281. EventManager.TriggerObjectGrab(obj.RootPart.LocalId, part.LocalId, part.OffsetPosition, remoteClient, surfaceArg);
  282. }
  283. }
  284. public virtual void ProcessObjectGrabUpdate(
  285. UUID objectID, Vector3 offset, Vector3 pos, IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs)
  286. {
  287. SceneObjectPart part = GetSceneObjectPart(objectID);
  288. if (part == null)
  289. return;
  290. SceneObjectGroup obj = part.ParentGroup;
  291. SurfaceTouchEventArgs surfaceArg = null;
  292. if (surfaceArgs != null && surfaceArgs.Count > 0)
  293. surfaceArg = surfaceArgs[0];
  294. // If the touched prim handles touches, deliver it
  295. // If not, deliver to root prim
  296. if ((part.ScriptEvents & scriptEvents.touch) != 0)
  297. EventManager.TriggerObjectGrabbing(part.LocalId, 0, part.OffsetPosition, remoteClient, surfaceArg);
  298. // Deliver to the root prim if the touched prim doesn't handle touches
  299. // or if we're meant to pass on touches anyway. Don't send to root prim
  300. // if prim touched is the root prim as we just did it
  301. if (((part.ScriptEvents & scriptEvents.touch) == 0) ||
  302. (part.PassTouches && (part.LocalId != obj.RootPart.LocalId)))
  303. {
  304. EventManager.TriggerObjectGrabbing(obj.RootPart.LocalId, part.LocalId, part.OffsetPosition, remoteClient, surfaceArg);
  305. }
  306. }
  307. public virtual void ProcessObjectDeGrab(uint localID, IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs)
  308. {
  309. SceneObjectPart part = GetSceneObjectPart(localID);
  310. if (part == null)
  311. return;
  312. SceneObjectGroup obj = part.ParentGroup;
  313. SurfaceTouchEventArgs surfaceArg = null;
  314. if (surfaceArgs != null && surfaceArgs.Count > 0)
  315. surfaceArg = surfaceArgs[0];
  316. // If the touched prim handles touches, deliver it
  317. // If not, deliver to root prim
  318. if ((part.ScriptEvents & scriptEvents.touch_end) != 0)
  319. EventManager.TriggerObjectDeGrab(part.LocalId, 0, remoteClient, surfaceArg);
  320. else
  321. EventManager.TriggerObjectDeGrab(obj.RootPart.LocalId, part.LocalId, remoteClient, surfaceArg);
  322. }
  323. public void ProcessScriptReset(IClientAPI remoteClient, UUID objectID,
  324. UUID itemID)
  325. {
  326. SceneObjectPart part=GetSceneObjectPart(objectID);
  327. if (part == null)
  328. return;
  329. if (Permissions.CanResetScript(objectID, itemID, remoteClient.AgentId))
  330. {
  331. EventManager.TriggerScriptReset(part.LocalId, itemID);
  332. }
  333. }
  334. void ProcessViewerEffect(IClientAPI remoteClient, List<ViewerEffectEventHandlerArg> args)
  335. {
  336. // TODO: don't create new blocks if recycling an old packet
  337. bool discardableEffects = true;
  338. ViewerEffectPacket.EffectBlock[] effectBlockArray = new ViewerEffectPacket.EffectBlock[args.Count];
  339. for (int i = 0; i < args.Count; i++)
  340. {
  341. ViewerEffectPacket.EffectBlock effect = new ViewerEffectPacket.EffectBlock();
  342. effect.AgentID = args[i].AgentID;
  343. effect.Color = args[i].Color;
  344. effect.Duration = args[i].Duration;
  345. effect.ID = args[i].ID;
  346. effect.Type = args[i].Type;
  347. effect.TypeData = args[i].TypeData;
  348. effectBlockArray[i] = effect;
  349. if ((EffectType)effect.Type != EffectType.LookAt && (EffectType)effect.Type != EffectType.Beam)
  350. discardableEffects = false;
  351. //m_log.DebugFormat("[YYY]: VE {0} {1} {2}", effect.AgentID, effect.Duration, (EffectType)effect.Type);
  352. }
  353. ForEachScenePresence(sp =>
  354. {
  355. if (sp.ControllingClient.AgentId != remoteClient.AgentId)
  356. {
  357. if (!discardableEffects ||
  358. (discardableEffects && ShouldSendDiscardableEffect(remoteClient, sp)))
  359. {
  360. //m_log.DebugFormat("[YYY]: Sending to {0}", sp.UUID);
  361. sp.ControllingClient.SendViewerEffect(effectBlockArray);
  362. }
  363. //else
  364. // m_log.DebugFormat("[YYY]: Not sending to {0}", sp.UUID);
  365. }
  366. });
  367. }
  368. private bool ShouldSendDiscardableEffect(IClientAPI thisClient, ScenePresence other)
  369. {
  370. return Vector3.Distance(other.CameraPosition, thisClient.SceneAgent.AbsolutePosition) < 10;
  371. }
  372. /// <summary>
  373. /// Tell the client about the various child items and folders contained in the requested folder.
  374. /// </summary>
  375. /// <param name="remoteClient"></param>
  376. /// <param name="folderID"></param>
  377. /// <param name="ownerID"></param>
  378. /// <param name="fetchFolders"></param>
  379. /// <param name="fetchItems"></param>
  380. /// <param name="sortOrder"></param>
  381. public void HandleFetchInventoryDescendents(IClientAPI remoteClient, UUID folderID, UUID ownerID,
  382. bool fetchFolders, bool fetchItems, int sortOrder)
  383. {
  384. // m_log.DebugFormat(
  385. // "[USER INVENTORY]: HandleFetchInventoryDescendents() for {0}, folder={1}, fetchFolders={2}, fetchItems={3}, sortOrder={4}",
  386. // remoteClient.Name, folderID, fetchFolders, fetchItems, sortOrder);
  387. if (folderID == UUID.Zero)
  388. return;
  389. // FIXME MAYBE: We're not handling sortOrder!
  390. // TODO: This code for looking in the folder for the library should be folded somewhere else
  391. // so that this class doesn't have to know the details (and so that multiple libraries, etc.
  392. // can be handled transparently).
  393. InventoryFolderImpl fold = null;
  394. if (LibraryService != null && LibraryService.LibraryRootFolder != null)
  395. {
  396. if ((fold = LibraryService.LibraryRootFolder.FindFolder(folderID)) != null)
  397. {
  398. remoteClient.SendInventoryFolderDetails(
  399. fold.Owner, folderID, fold.RequestListOfItems(),
  400. fold.RequestListOfFolders(), fold.Version, fetchFolders, fetchItems);
  401. return;
  402. }
  403. }
  404. // We're going to send the reply async, because there may be
  405. // an enormous quantity of packets -- basically the entire inventory!
  406. // We don't want to block the client thread while all that is happening.
  407. SendInventoryDelegate d = SendInventoryAsync;
  408. d.BeginInvoke(remoteClient, folderID, ownerID, fetchFolders, fetchItems, sortOrder, SendInventoryComplete, d);
  409. }
  410. delegate void SendInventoryDelegate(IClientAPI remoteClient, UUID folderID, UUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder);
  411. void SendInventoryAsync(IClientAPI remoteClient, UUID folderID, UUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder)
  412. {
  413. SendInventoryUpdate(remoteClient, new InventoryFolderBase(folderID), fetchFolders, fetchItems);
  414. }
  415. void SendInventoryComplete(IAsyncResult iar)
  416. {
  417. SendInventoryDelegate d = (SendInventoryDelegate)iar.AsyncState;
  418. d.EndInvoke(iar);
  419. }
  420. /// <summary>
  421. /// Handle an inventory folder creation request from the client.
  422. /// </summary>
  423. /// <param name="remoteClient"></param>
  424. /// <param name="folderID"></param>
  425. /// <param name="folderType"></param>
  426. /// <param name="folderName"></param>
  427. /// <param name="parentID"></param>
  428. public void HandleCreateInventoryFolder(IClientAPI remoteClient, UUID folderID, ushort folderType,
  429. string folderName, UUID parentID)
  430. {
  431. InventoryFolderBase folder = new InventoryFolderBase(folderID, folderName, remoteClient.AgentId, (short)folderType, parentID, 1);
  432. if (!InventoryService.AddFolder(folder))
  433. {
  434. m_log.WarnFormat(
  435. "[AGENT INVENTORY]: Failed to create folder for user {0} {1}",
  436. remoteClient.Name, remoteClient.AgentId);
  437. }
  438. }
  439. /// <summary>
  440. /// Handle a client request to update the inventory folder
  441. /// </summary>
  442. ///
  443. /// FIXME: We call add new inventory folder because in the data layer, we happen to use an SQL REPLACE
  444. /// so this will work to rename an existing folder. Needless to say, to rely on this is very confusing,
  445. /// and needs to be changed.
  446. ///
  447. /// <param name="remoteClient"></param>
  448. /// <param name="folderID"></param>
  449. /// <param name="type"></param>
  450. /// <param name="name"></param>
  451. /// <param name="parentID"></param>
  452. public void HandleUpdateInventoryFolder(IClientAPI remoteClient, UUID folderID, ushort type, string name,
  453. UUID parentID)
  454. {
  455. // m_log.DebugFormat(
  456. // "[AGENT INVENTORY]: Updating inventory folder {0} {1} for {2} {3}", folderID, name, remoteClient.Name, remoteClient.AgentId);
  457. InventoryFolderBase folder = new InventoryFolderBase(folderID, remoteClient.AgentId);
  458. folder = InventoryService.GetFolder(folder);
  459. if (folder != null)
  460. {
  461. folder.Name = name;
  462. folder.Type = (short)type;
  463. folder.ParentID = parentID;
  464. if (!InventoryService.UpdateFolder(folder))
  465. {
  466. m_log.ErrorFormat(
  467. "[AGENT INVENTORY]: Failed to update folder for user {0} {1}",
  468. remoteClient.Name, remoteClient.AgentId);
  469. }
  470. }
  471. }
  472. public void HandleMoveInventoryFolder(IClientAPI remoteClient, UUID folderID, UUID parentID)
  473. {
  474. InventoryFolderBase folder = new InventoryFolderBase(folderID, remoteClient.AgentId);
  475. folder = InventoryService.GetFolder(folder);
  476. if (folder != null)
  477. {
  478. folder.ParentID = parentID;
  479. if (!InventoryService.MoveFolder(folder))
  480. m_log.WarnFormat("[AGENT INVENTORY]: could not move folder {0}", folderID);
  481. else
  482. m_log.DebugFormat("[AGENT INVENTORY]: folder {0} moved to parent {1}", folderID, parentID);
  483. }
  484. else
  485. {
  486. m_log.WarnFormat("[AGENT INVENTORY]: request to move folder {0} but folder not found", folderID);
  487. }
  488. }
  489. delegate void PurgeFolderDelegate(UUID userID, UUID folder);
  490. /// <summary>
  491. /// This should delete all the items and folders in the given directory.
  492. /// </summary>
  493. /// <param name="remoteClient"></param>
  494. /// <param name="folderID"></param>
  495. public void HandlePurgeInventoryDescendents(IClientAPI remoteClient, UUID folderID)
  496. {
  497. PurgeFolderDelegate d = PurgeFolderAsync;
  498. try
  499. {
  500. d.BeginInvoke(remoteClient.AgentId, folderID, PurgeFolderCompleted, d);
  501. }
  502. catch (Exception e)
  503. {
  504. m_log.WarnFormat("[AGENT INVENTORY]: Exception on purge folder for user {0}: {1}", remoteClient.AgentId, e.Message);
  505. }
  506. }
  507. private void PurgeFolderAsync(UUID userID, UUID folderID)
  508. {
  509. InventoryFolderBase folder = new InventoryFolderBase(folderID, userID);
  510. if (InventoryService.PurgeFolder(folder))
  511. m_log.DebugFormat("[AGENT INVENTORY]: folder {0} purged successfully", folderID);
  512. else
  513. m_log.WarnFormat("[AGENT INVENTORY]: could not purge folder {0}", folderID);
  514. }
  515. private void PurgeFolderCompleted(IAsyncResult iar)
  516. {
  517. PurgeFolderDelegate d = (PurgeFolderDelegate)iar.AsyncState;
  518. d.EndInvoke(iar);
  519. }
  520. }
  521. }