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. protected void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
  40. UUID fromID, bool fromAgent, bool broadcast)
  41. {
  42. OSChatMessage args = new OSChatMessage();
  43. args.Message = Utils.BytesToString(message);
  44. args.Channel = channel;
  45. args.Type = type;
  46. args.Position = fromPos;
  47. args.SenderUUID = fromID;
  48. args.Scene = this;
  49. if (fromAgent)
  50. {
  51. ScenePresence user = GetScenePresence(fromID);
  52. if (user != null)
  53. args.Sender = user.ControllingClient;
  54. }
  55. else
  56. {
  57. SceneObjectPart obj = GetSceneObjectPart(fromID);
  58. args.SenderObject = obj;
  59. }
  60. args.From = fromName;
  61. //args.
  62. if (broadcast)
  63. EventManager.TriggerOnChatBroadcast(this, args);
  64. else
  65. EventManager.TriggerOnChatFromWorld(this, args);
  66. }
  67. /// <summary>
  68. ///
  69. /// </summary>
  70. /// <param name="message"></param>
  71. /// <param name="type"></param>
  72. /// <param name="fromPos"></param>
  73. /// <param name="fromName"></param>
  74. /// <param name="fromAgentID"></param>
  75. public void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
  76. UUID fromID, bool fromAgent)
  77. {
  78. SimChat(message, type, channel, fromPos, fromName, fromID, fromAgent, false);
  79. }
  80. public void SimChat(string message, ChatTypeEnum type, Vector3 fromPos, string fromName, UUID fromID, bool fromAgent)
  81. {
  82. SimChat(Utils.StringToBytes(message), type, 0, fromPos, fromName, fromID, fromAgent);
  83. }
  84. public void SimChat(string message, string fromName)
  85. {
  86. SimChat(message, ChatTypeEnum.Broadcast, Vector3.Zero, fromName, UUID.Zero, false);
  87. }
  88. /// <summary>
  89. ///
  90. /// </summary>
  91. /// <param name="message"></param>
  92. /// <param name="type"></param>
  93. /// <param name="fromPos"></param>
  94. /// <param name="fromName"></param>
  95. /// <param name="fromAgentID"></param>
  96. public void SimChatBroadcast(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
  97. UUID fromID, bool fromAgent)
  98. {
  99. SimChat(message, type, channel, fromPos, fromName, fromID, fromAgent, true);
  100. }
  101. /// <summary>
  102. /// Invoked when the client requests a prim.
  103. /// </summary>
  104. /// <param name="primLocalID"></param>
  105. /// <param name="remoteClient"></param>
  106. public void RequestPrim(uint primLocalID, IClientAPI remoteClient)
  107. {
  108. SceneObjectGroup sog = GetGroupByPrim(primLocalID);
  109. if (sog != null)
  110. sog.SendFullUpdateToClient(remoteClient);
  111. }
  112. /// <summary>
  113. /// Invoked when the client selects a prim.
  114. /// </summary>
  115. /// <param name="primLocalID"></param>
  116. /// <param name="remoteClient"></param>
  117. public void SelectPrim(uint primLocalID, IClientAPI remoteClient)
  118. {
  119. SceneObjectPart part = GetSceneObjectPart(primLocalID);
  120. if (null == part)
  121. return;
  122. if (part.IsRoot)
  123. {
  124. SceneObjectGroup sog = part.ParentGroup;
  125. sog.SendPropertiesToClient(remoteClient);
  126. sog.IsSelected = true;
  127. // A prim is only tainted if it's allowed to be edited by the person clicking it.
  128. if (Permissions.CanEditObject(sog.UUID, remoteClient.AgentId)
  129. || Permissions.CanMoveObject(sog.UUID, remoteClient.AgentId))
  130. {
  131. EventManager.TriggerParcelPrimCountTainted();
  132. }
  133. }
  134. else
  135. {
  136. part.SendPropertiesToClient(remoteClient);
  137. }
  138. }
  139. /// <summary>
  140. /// Handle the update of an object's user group.
  141. /// </summary>
  142. /// <param name="remoteClient"></param>
  143. /// <param name="groupID"></param>
  144. /// <param name="objectLocalID"></param>
  145. /// <param name="Garbage"></param>
  146. private void HandleObjectGroupUpdate(
  147. IClientAPI remoteClient, UUID groupID, uint objectLocalID, UUID Garbage)
  148. {
  149. if (m_groupsModule == null)
  150. return;
  151. // XXX: Might be better to get rid of this special casing and have GetMembershipData return something
  152. // reasonable for a UUID.Zero group.
  153. if (groupID != UUID.Zero)
  154. {
  155. GroupMembershipData gmd = m_groupsModule.GetMembershipData(groupID, remoteClient.AgentId);
  156. if (gmd == null)
  157. {
  158. // m_log.WarnFormat(
  159. // "[GROUPS]: User {0} is not a member of group {1} so they can't update {2} to this group",
  160. // remoteClient.Name, GroupID, objectLocalID);
  161. return;
  162. }
  163. }
  164. SceneObjectGroup so = ((Scene)remoteClient.Scene).GetGroupByPrim(objectLocalID);
  165. if (so != null)
  166. {
  167. if (so.OwnerID == remoteClient.AgentId)
  168. {
  169. so.SetGroup(groupID, remoteClient);
  170. }
  171. }
  172. }
  173. /// <summary>
  174. /// Handle the deselection of a prim from the client.
  175. /// </summary>
  176. /// <param name="primLocalID"></param>
  177. /// <param name="remoteClient"></param>
  178. public void DeselectPrim(uint primLocalID, IClientAPI remoteClient)
  179. {
  180. SceneObjectPart part = GetSceneObjectPart(primLocalID);
  181. if (part == null)
  182. return;
  183. // A deselect packet contains all the local prims being deselected. However, since selection is still
  184. // group based we only want the root prim to trigger a full update - otherwise on objects with many prims
  185. // we end up sending many duplicate ObjectUpdates
  186. if (part.ParentGroup.RootPart.LocalId != part.LocalId)
  187. return;
  188. bool isAttachment = false;
  189. // This is wrong, wrong, wrong. Selection should not be
  190. // handled by group, but by prim. Legacy cruft.
  191. // TODO: Make selection flagging per prim!
  192. //
  193. part.ParentGroup.IsSelected = false;
  194. if (part.ParentGroup.IsAttachment)
  195. isAttachment = true;
  196. else
  197. part.ParentGroup.ScheduleGroupForFullUpdate();
  198. // If it's not an attachment, and we are allowed to move it,
  199. // then we might have done so. If we moved across a parcel
  200. // boundary, we will need to recount prims on the parcels.
  201. // For attachments, that makes no sense.
  202. //
  203. if (!isAttachment)
  204. {
  205. if (Permissions.CanEditObject(
  206. part.UUID, remoteClient.AgentId)
  207. || Permissions.CanMoveObject(
  208. part.UUID, remoteClient.AgentId))
  209. EventManager.TriggerParcelPrimCountTainted();
  210. }
  211. }
  212. public virtual void ProcessMoneyTransferRequest(UUID source, UUID destination, int amount,
  213. int transactiontype, string description)
  214. {
  215. EventManager.MoneyTransferArgs args = new EventManager.MoneyTransferArgs(source, destination, amount,
  216. transactiontype, description);
  217. EventManager.TriggerMoneyTransfer(this, args);
  218. }
  219. public virtual void ProcessParcelBuy(UUID agentId, UUID groupId, bool final, bool groupOwned,
  220. bool removeContribution, int parcelLocalID, int parcelArea, int parcelPrice, bool authenticated)
  221. {
  222. EventManager.LandBuyArgs args = new EventManager.LandBuyArgs(agentId, groupId, final, groupOwned,
  223. removeContribution, parcelLocalID, parcelArea,
  224. parcelPrice, authenticated);
  225. // First, allow all validators a stab at it
  226. m_eventManager.TriggerValidateLandBuy(this, args);
  227. // Then, check validation and transfer
  228. m_eventManager.TriggerLandBuy(this, args);
  229. }
  230. public virtual void ProcessObjectGrab(uint localID, Vector3 offsetPos, IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs)
  231. {
  232. SceneObjectPart part = GetSceneObjectPart(localID);
  233. if (part == null)
  234. return;
  235. SceneObjectGroup obj = part.ParentGroup;
  236. SurfaceTouchEventArgs surfaceArg = null;
  237. if (surfaceArgs != null && surfaceArgs.Count > 0)
  238. surfaceArg = surfaceArgs[0];
  239. // Currently only grab/touch for the single prim
  240. // the client handles rez correctly
  241. obj.ObjectGrabHandler(localID, offsetPos, remoteClient);
  242. // If the touched prim handles touches, deliver it
  243. // If not, deliver to root prim
  244. if ((part.ScriptEvents & scriptEvents.touch_start) != 0)
  245. EventManager.TriggerObjectGrab(part.LocalId, 0, part.OffsetPosition, remoteClient, surfaceArg);
  246. // Deliver to the root prim if the touched prim doesn't handle touches
  247. // or if we're meant to pass on touches anyway. Don't send to root prim
  248. // if prim touched is the root prim as we just did it
  249. if (((part.ScriptEvents & scriptEvents.touch_start) == 0) ||
  250. (part.PassTouches && (part.LocalId != obj.RootPart.LocalId)))
  251. {
  252. EventManager.TriggerObjectGrab(obj.RootPart.LocalId, part.LocalId, part.OffsetPosition, remoteClient, surfaceArg);
  253. }
  254. }
  255. public virtual void ProcessObjectGrabUpdate(
  256. UUID objectID, Vector3 offset, Vector3 pos, IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs)
  257. {
  258. SceneObjectPart part = GetSceneObjectPart(objectID);
  259. if (part == null)
  260. return;
  261. SceneObjectGroup obj = part.ParentGroup;
  262. SurfaceTouchEventArgs surfaceArg = null;
  263. if (surfaceArgs != null && surfaceArgs.Count > 0)
  264. surfaceArg = surfaceArgs[0];
  265. // If the touched prim handles touches, deliver it
  266. // If not, deliver to root prim
  267. if ((part.ScriptEvents & scriptEvents.touch) != 0)
  268. EventManager.TriggerObjectGrabbing(part.LocalId, 0, part.OffsetPosition, remoteClient, surfaceArg);
  269. // Deliver to the root prim if the touched prim doesn't handle touches
  270. // or if we're meant to pass on touches anyway. Don't send to root prim
  271. // if prim touched is the root prim as we just did it
  272. if (((part.ScriptEvents & scriptEvents.touch) == 0) ||
  273. (part.PassTouches && (part.LocalId != obj.RootPart.LocalId)))
  274. {
  275. EventManager.TriggerObjectGrabbing(obj.RootPart.LocalId, part.LocalId, part.OffsetPosition, remoteClient, surfaceArg);
  276. }
  277. }
  278. public virtual void ProcessObjectDeGrab(uint localID, IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs)
  279. {
  280. SceneObjectPart part = GetSceneObjectPart(localID);
  281. if (part == null)
  282. return;
  283. SceneObjectGroup obj = part.ParentGroup;
  284. SurfaceTouchEventArgs surfaceArg = null;
  285. if (surfaceArgs != null && surfaceArgs.Count > 0)
  286. surfaceArg = surfaceArgs[0];
  287. // If the touched prim handles touches, deliver it
  288. // If not, deliver to root prim
  289. if ((part.ScriptEvents & scriptEvents.touch_end) != 0)
  290. EventManager.TriggerObjectDeGrab(part.LocalId, 0, remoteClient, surfaceArg);
  291. else
  292. EventManager.TriggerObjectDeGrab(obj.RootPart.LocalId, part.LocalId, remoteClient, surfaceArg);
  293. }
  294. public void ProcessAvatarPickerRequest(IClientAPI client, UUID avatarID, UUID RequestID, string query)
  295. {
  296. //EventManager.TriggerAvatarPickerRequest();
  297. List<UserAccount> accounts = UserAccountService.GetUserAccounts(RegionInfo.ScopeID, query);
  298. if (accounts == null)
  299. return;
  300. AvatarPickerReplyPacket replyPacket = (AvatarPickerReplyPacket) PacketPool.Instance.GetPacket(PacketType.AvatarPickerReply);
  301. // TODO: don't create new blocks if recycling an old packet
  302. AvatarPickerReplyPacket.DataBlock[] searchData =
  303. new AvatarPickerReplyPacket.DataBlock[accounts.Count];
  304. AvatarPickerReplyPacket.AgentDataBlock agentData = new AvatarPickerReplyPacket.AgentDataBlock();
  305. agentData.AgentID = avatarID;
  306. agentData.QueryID = RequestID;
  307. replyPacket.AgentData = agentData;
  308. //byte[] bytes = new byte[AvatarResponses.Count*32];
  309. int i = 0;
  310. foreach (UserAccount item in accounts)
  311. {
  312. UUID translatedIDtem = item.PrincipalID;
  313. searchData[i] = new AvatarPickerReplyPacket.DataBlock();
  314. searchData[i].AvatarID = translatedIDtem;
  315. searchData[i].FirstName = Utils.StringToBytes((string) item.FirstName);
  316. searchData[i].LastName = Utils.StringToBytes((string) item.LastName);
  317. i++;
  318. }
  319. if (accounts.Count == 0)
  320. {
  321. searchData = new AvatarPickerReplyPacket.DataBlock[0];
  322. }
  323. replyPacket.Data = searchData;
  324. AvatarPickerReplyAgentDataArgs agent_data = new AvatarPickerReplyAgentDataArgs();
  325. agent_data.AgentID = replyPacket.AgentData.AgentID;
  326. agent_data.QueryID = replyPacket.AgentData.QueryID;
  327. List<AvatarPickerReplyDataArgs> data_args = new List<AvatarPickerReplyDataArgs>();
  328. for (i = 0; i < replyPacket.Data.Length; i++)
  329. {
  330. AvatarPickerReplyDataArgs data_arg = new AvatarPickerReplyDataArgs();
  331. data_arg.AvatarID = replyPacket.Data[i].AvatarID;
  332. data_arg.FirstName = replyPacket.Data[i].FirstName;
  333. data_arg.LastName = replyPacket.Data[i].LastName;
  334. data_args.Add(data_arg);
  335. }
  336. client.SendAvatarPickerReply(agent_data, data_args);
  337. }
  338. public void ProcessScriptReset(IClientAPI remoteClient, UUID objectID,
  339. UUID itemID)
  340. {
  341. SceneObjectPart part=GetSceneObjectPart(objectID);
  342. if (part == null)
  343. return;
  344. if (Permissions.CanResetScript(objectID, itemID, remoteClient.AgentId))
  345. {
  346. EventManager.TriggerScriptReset(part.LocalId, itemID);
  347. }
  348. }
  349. void ProcessViewerEffect(IClientAPI remoteClient, List<ViewerEffectEventHandlerArg> args)
  350. {
  351. // TODO: don't create new blocks if recycling an old packet
  352. ViewerEffectPacket.EffectBlock[] effectBlockArray = new ViewerEffectPacket.EffectBlock[args.Count];
  353. for (int i = 0; i < args.Count; i++)
  354. {
  355. ViewerEffectPacket.EffectBlock effect = new ViewerEffectPacket.EffectBlock();
  356. effect.AgentID = args[i].AgentID;
  357. effect.Color = args[i].Color;
  358. effect.Duration = args[i].Duration;
  359. effect.ID = args[i].ID;
  360. effect.Type = args[i].Type;
  361. effect.TypeData = args[i].TypeData;
  362. effectBlockArray[i] = effect;
  363. }
  364. ForEachClient(
  365. delegate(IClientAPI client)
  366. {
  367. if (client.AgentId != remoteClient.AgentId)
  368. client.SendViewerEffect(effectBlockArray);
  369. }
  370. );
  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 move 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. }