Scene.PacketHandlers.cs 26 KB

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