Scene.PacketHandlers.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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.Collections.Generic;
  28. using System.Threading;
  29. using OpenMetaverse;
  30. using OpenMetaverse.Packets;
  31. using OpenSim.Framework;
  32. using OpenSim.Framework.Communications;
  33. using OpenSim.Framework.Communications.Cache;
  34. namespace OpenSim.Region.Framework.Scenes
  35. {
  36. public partial class Scene
  37. {
  38. protected void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
  39. UUID fromID, bool fromAgent, bool broadcast)
  40. {
  41. OSChatMessage args = new OSChatMessage();
  42. args.Message = Utils.BytesToString(message);
  43. args.Channel = channel;
  44. args.Type = type;
  45. args.Position = fromPos;
  46. args.SenderUUID = fromID;
  47. args.Scene = this;
  48. if (fromAgent)
  49. {
  50. ScenePresence user = GetScenePresence(fromID);
  51. if (user != null)
  52. args.Sender = user.ControllingClient;
  53. }
  54. else
  55. {
  56. SceneObjectPart obj = GetSceneObjectPart(fromID);
  57. args.SenderObject = obj;
  58. }
  59. args.From = fromName;
  60. //args.
  61. if (broadcast)
  62. EventManager.TriggerOnChatBroadcast(this, args);
  63. else
  64. EventManager.TriggerOnChatFromWorld(this, args);
  65. }
  66. /// <summary>
  67. ///
  68. /// </summary>
  69. /// <param name="message"></param>
  70. /// <param name="type"></param>
  71. /// <param name="fromPos"></param>
  72. /// <param name="fromName"></param>
  73. /// <param name="fromAgentID"></param>
  74. public void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
  75. UUID fromID, bool fromAgent)
  76. {
  77. SimChat(message, type, channel, fromPos, fromName, fromID, fromAgent, false);
  78. }
  79. public void SimChat(string message, ChatTypeEnum type, Vector3 fromPos, string fromName, UUID fromID, bool fromAgent)
  80. {
  81. SimChat(Utils.StringToBytes(message), type, 0, fromPos, fromName, fromID, fromAgent);
  82. }
  83. public void SimChat(string message, string fromName)
  84. {
  85. SimChat(message, ChatTypeEnum.Broadcast, Vector3.Zero, fromName, UUID.Zero, false);
  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 SimChatBroadcast(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, true);
  99. }
  100. /// <summary>
  101. /// Invoked when the client selects a prim.
  102. /// </summary>
  103. /// <param name="primLocalID"></param>
  104. /// <param name="remoteClient"></param>
  105. public void SelectPrim(uint primLocalID, IClientAPI remoteClient)
  106. {
  107. List<EntityBase> EntityList = GetEntities();
  108. foreach (EntityBase ent in EntityList)
  109. {
  110. if (ent is SceneObjectGroup)
  111. {
  112. if (((SceneObjectGroup) ent).LocalId == primLocalID)
  113. {
  114. ((SceneObjectGroup) ent).GetProperties(remoteClient);
  115. ((SceneObjectGroup) ent).IsSelected = true;
  116. // A prim is only tainted if it's allowed to be edited by the person clicking it.
  117. if (Permissions.CanEditObject(((SceneObjectGroup)ent).UUID, remoteClient.AgentId)
  118. || Permissions.CanMoveObject(((SceneObjectGroup)ent).UUID, remoteClient.AgentId))
  119. {
  120. EventManager.TriggerParcelPrimCountTainted();
  121. }
  122. break;
  123. }
  124. else
  125. {
  126. // We also need to check the children of this prim as they
  127. // can be selected as well and send property information
  128. bool foundPrim = false;
  129. foreach (KeyValuePair<UUID, SceneObjectPart> child in ((SceneObjectGroup) ent).Children)
  130. {
  131. if (child.Value.LocalId == primLocalID)
  132. {
  133. child.Value.GetProperties(remoteClient);
  134. foundPrim = true;
  135. break;
  136. }
  137. }
  138. if (foundPrim) break;
  139. }
  140. }
  141. }
  142. }
  143. /// <summary>
  144. /// Handle the deselection of a prim from the client.
  145. /// </summary>
  146. /// <param name="primLocalID"></param>
  147. /// <param name="remoteClient"></param>
  148. public void DeselectPrim(uint primLocalID, IClientAPI remoteClient)
  149. {
  150. SceneObjectPart part = GetSceneObjectPart(primLocalID);
  151. if (part == null)
  152. return;
  153. // The prim is in the process of being deleted.
  154. if (null == part.ParentGroup.RootPart)
  155. return;
  156. // A deselect packet contains all the local prims being deselected. However, since selection is still
  157. // group based we only want the root prim to trigger a full update - otherwise on objects with many prims
  158. // we end up sending many duplicate ObjectUpdates
  159. if (part.ParentGroup.RootPart.LocalId != part.LocalId)
  160. return;
  161. bool isAttachment = false;
  162. // This is wrong, wrong, wrong. Selection should not be
  163. // handled by group, but by prim. Legacy cruft.
  164. // TODO: Make selection flagging per prim!
  165. //
  166. part.ParentGroup.IsSelected = false;
  167. if (part.ParentGroup.IsAttachment)
  168. isAttachment = true;
  169. else
  170. part.ParentGroup.ScheduleGroupForFullUpdate();
  171. // If it's not an attachment, and we are allowed to move it,
  172. // then we might have done so. If we moved across a parcel
  173. // boundary, we will need to recount prims on the parcels.
  174. // For attachments, that makes no sense.
  175. //
  176. if (!isAttachment)
  177. {
  178. if (Permissions.CanEditObject(
  179. part.UUID, remoteClient.AgentId)
  180. || Permissions.CanMoveObject(
  181. part.UUID, remoteClient.AgentId))
  182. EventManager.TriggerParcelPrimCountTainted();
  183. }
  184. }
  185. public virtual void ProcessMoneyTransferRequest(UUID source, UUID destination, int amount,
  186. int transactiontype, string description)
  187. {
  188. EventManager.MoneyTransferArgs args = new EventManager.MoneyTransferArgs(source, destination, amount,
  189. transactiontype, description);
  190. EventManager.TriggerMoneyTransfer(this, args);
  191. }
  192. public virtual void ProcessParcelBuy(UUID agentId, UUID groupId, bool final, bool groupOwned,
  193. bool removeContribution, int parcelLocalID, int parcelArea, int parcelPrice, bool authenticated)
  194. {
  195. EventManager.LandBuyArgs args = new EventManager.LandBuyArgs(agentId, groupId, final, groupOwned,
  196. removeContribution, parcelLocalID, parcelArea,
  197. parcelPrice, authenticated);
  198. // First, allow all validators a stab at it
  199. m_eventManager.TriggerValidateLandBuy(this, args);
  200. // Then, check validation and transfer
  201. m_eventManager.TriggerLandBuy(this, args);
  202. }
  203. public virtual void ProcessObjectGrab(uint localID, Vector3 offsetPos, IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs)
  204. {
  205. List<EntityBase> EntityList = GetEntities();
  206. SurfaceTouchEventArgs surfaceArg = null;
  207. if (surfaceArgs != null && surfaceArgs.Count > 0)
  208. surfaceArg = surfaceArgs[0];
  209. foreach (EntityBase ent in EntityList)
  210. {
  211. if (ent is SceneObjectGroup)
  212. {
  213. SceneObjectGroup obj = ent as SceneObjectGroup;
  214. if (obj != null)
  215. {
  216. // Is this prim part of the group
  217. if (obj.HasChildPrim(localID))
  218. {
  219. // Currently only grab/touch for the single prim
  220. // the client handles rez correctly
  221. obj.ObjectGrabHandler(localID, offsetPos, remoteClient);
  222. SceneObjectPart part = obj.GetChildPart(localID);
  223. // If the touched prim handles touches, deliver it
  224. // If not, deliver to root prim
  225. if ((part.ScriptEvents & scriptEvents.touch_start) != 0)
  226. EventManager.TriggerObjectGrab(part.LocalId, 0, part.OffsetPosition, remoteClient, surfaceArg);
  227. // Deliver to the root prim if the touched prim doesn't handle touches
  228. // or if we're meant to pass on touches anyway. Don't send to root prim
  229. // if prim touched is the root prim as we just did it
  230. if (((part.ScriptEvents & scriptEvents.touch_start) == 0) ||
  231. (part.PassTouches && (part.LocalId != obj.RootPart.LocalId)))
  232. {
  233. EventManager.TriggerObjectGrab(obj.RootPart.LocalId, part.LocalId, part.OffsetPosition, remoteClient, surfaceArg);
  234. }
  235. return;
  236. }
  237. }
  238. }
  239. }
  240. }
  241. public virtual void ProcessObjectDeGrab(uint localID, IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs)
  242. {
  243. List<EntityBase> EntityList = GetEntities();
  244. SurfaceTouchEventArgs surfaceArg = null;
  245. if (surfaceArgs != null && surfaceArgs.Count > 0)
  246. surfaceArg = surfaceArgs[0];
  247. foreach (EntityBase ent in EntityList)
  248. {
  249. if (ent is SceneObjectGroup)
  250. {
  251. SceneObjectGroup obj = ent as SceneObjectGroup;
  252. // Is this prim part of the group
  253. if (obj.HasChildPrim(localID))
  254. {
  255. SceneObjectPart part=obj.GetChildPart(localID);
  256. if (part != null)
  257. {
  258. // If the touched prim handles touches, deliver it
  259. // If not, deliver to root prim
  260. if ((part.ScriptEvents & scriptEvents.touch_end) != 0)
  261. EventManager.TriggerObjectDeGrab(part.LocalId, 0, remoteClient, surfaceArg);
  262. else
  263. EventManager.TriggerObjectDeGrab(obj.RootPart.LocalId, part.LocalId, remoteClient, surfaceArg);
  264. return;
  265. }
  266. return;
  267. }
  268. }
  269. }
  270. }
  271. public void ProcessAvatarPickerRequest(IClientAPI client, UUID avatarID, UUID RequestID, string query)
  272. {
  273. //EventManager.TriggerAvatarPickerRequest();
  274. List<AvatarPickerAvatar> AvatarResponses = new List<AvatarPickerAvatar>();
  275. AvatarResponses = m_sceneGridService.GenerateAgentPickerRequestResponse(RequestID, query);
  276. AvatarPickerReplyPacket replyPacket = (AvatarPickerReplyPacket) PacketPool.Instance.GetPacket(PacketType.AvatarPickerReply);
  277. // TODO: don't create new blocks if recycling an old packet
  278. AvatarPickerReplyPacket.DataBlock[] searchData =
  279. new AvatarPickerReplyPacket.DataBlock[AvatarResponses.Count];
  280. AvatarPickerReplyPacket.AgentDataBlock agentData = new AvatarPickerReplyPacket.AgentDataBlock();
  281. agentData.AgentID = avatarID;
  282. agentData.QueryID = RequestID;
  283. replyPacket.AgentData = agentData;
  284. //byte[] bytes = new byte[AvatarResponses.Count*32];
  285. int i = 0;
  286. foreach (AvatarPickerAvatar item in AvatarResponses)
  287. {
  288. UUID translatedIDtem = item.AvatarID;
  289. searchData[i] = new AvatarPickerReplyPacket.DataBlock();
  290. searchData[i].AvatarID = translatedIDtem;
  291. searchData[i].FirstName = Utils.StringToBytes((string) item.firstName);
  292. searchData[i].LastName = Utils.StringToBytes((string) item.lastName);
  293. i++;
  294. }
  295. if (AvatarResponses.Count == 0)
  296. {
  297. searchData = new AvatarPickerReplyPacket.DataBlock[0];
  298. }
  299. replyPacket.Data = searchData;
  300. AvatarPickerReplyAgentDataArgs agent_data = new AvatarPickerReplyAgentDataArgs();
  301. agent_data.AgentID = replyPacket.AgentData.AgentID;
  302. agent_data.QueryID = replyPacket.AgentData.QueryID;
  303. List<AvatarPickerReplyDataArgs> data_args = new List<AvatarPickerReplyDataArgs>();
  304. for (i = 0; i < replyPacket.Data.Length; i++)
  305. {
  306. AvatarPickerReplyDataArgs data_arg = new AvatarPickerReplyDataArgs();
  307. data_arg.AvatarID = replyPacket.Data[i].AvatarID;
  308. data_arg.FirstName = replyPacket.Data[i].FirstName;
  309. data_arg.LastName = replyPacket.Data[i].LastName;
  310. data_args.Add(data_arg);
  311. }
  312. client.SendAvatarPickerReply(agent_data, data_args);
  313. }
  314. public void ProcessScriptReset(IClientAPI remoteClient, UUID objectID,
  315. UUID itemID)
  316. {
  317. SceneObjectPart part=GetSceneObjectPart(objectID);
  318. if (part == null)
  319. return;
  320. if (Permissions.CanResetScript(objectID, itemID, remoteClient.AgentId))
  321. {
  322. EventManager.TriggerScriptReset(part.LocalId, itemID);
  323. }
  324. }
  325. /// <summary>
  326. /// Handle a fetch inventory request from the client
  327. /// </summary>
  328. /// <param name="remoteClient"></param>
  329. /// <param name="itemID"></param>
  330. /// <param name="ownerID"></param>
  331. public void HandleFetchInventory(IClientAPI remoteClient, UUID itemID, UUID ownerID)
  332. {
  333. if (ownerID == CommsManager.UserProfileCacheService.LibraryRoot.Owner)
  334. {
  335. //m_log.Debug("request info for library item");
  336. return;
  337. }
  338. CachedUserInfo userProfile = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  339. if (null == userProfile)
  340. {
  341. m_log.ErrorFormat(
  342. "[AGENT INVENTORY]: Could not find user profile for {0} {1}",
  343. remoteClient.Name, remoteClient.AgentId);
  344. return;
  345. }
  346. if (userProfile.HasReceivedInventory)
  347. {
  348. InventoryItemBase item = null;
  349. if (userProfile.RootFolder == null)
  350. m_log.ErrorFormat(
  351. "[AGENT INVENTORY]: User {0} {1} does not have a root folder.",
  352. remoteClient.Name, remoteClient.AgentId);
  353. else
  354. item = userProfile.RootFolder.FindItem(itemID);
  355. if (item != null)
  356. {
  357. remoteClient.SendInventoryItemDetails(ownerID, item);
  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. // FIXME MAYBE: We're not handling sortOrder!
  374. // TODO: This code for looking in the folder for the library should be folded back into the
  375. // CachedUserInfo so that this class doesn't have to know the details (and so that multiple libraries, etc.
  376. // can be handled transparently).
  377. InventoryFolderImpl fold = null;
  378. if ((fold = CommsManager.UserProfileCacheService.LibraryRoot.FindFolder(folderID)) != null)
  379. {
  380. remoteClient.SendInventoryFolderDetails(
  381. fold.Owner, folderID, fold.RequestListOfItems(),
  382. fold.RequestListOfFolders(), fetchFolders, fetchItems);
  383. return;
  384. }
  385. CachedUserInfo userProfile = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  386. if (null == userProfile)
  387. {
  388. m_log.ErrorFormat(
  389. "[AGENT INVENTORY]: Could not find user profile for {0} {1}",
  390. remoteClient.Name, remoteClient.AgentId);
  391. return;
  392. }
  393. userProfile.SendInventoryDecendents(remoteClient, folderID, fetchFolders, fetchItems);
  394. }
  395. /// <summary>
  396. /// Handle the caps inventory descendents fetch.
  397. ///
  398. /// Since the folder structure is sent to the client on login, I believe we only need to handle items.
  399. /// </summary>
  400. /// <param name="agentID"></param>
  401. /// <param name="folderID"></param>
  402. /// <param name="ownerID"></param>
  403. /// <param name="fetchFolders"></param>
  404. /// <param name="fetchItems"></param>
  405. /// <param name="sortOrder"></param>
  406. /// <returns>null if the inventory look up failed</returns>
  407. public List<InventoryItemBase> HandleFetchInventoryDescendentsCAPS(UUID agentID, UUID folderID, UUID ownerID,
  408. bool fetchFolders, bool fetchItems, int sortOrder)
  409. {
  410. // m_log.DebugFormat(
  411. // "[INVENTORY CACHE]: Fetching folders ({0}), items ({1}) from {2} for agent {3}",
  412. // fetchFolders, fetchItems, folderID, agentID);
  413. // FIXME MAYBE: We're not handling sortOrder!
  414. // TODO: This code for looking in the folder for the library should be folded back into the
  415. // CachedUserInfo so that this class doesn't have to know the details (and so that multiple libraries, etc.
  416. // can be handled transparently).
  417. InventoryFolderImpl fold;
  418. if ((fold = CommsManager.UserProfileCacheService.LibraryRoot.FindFolder(folderID)) != null)
  419. {
  420. return fold.RequestListOfItems();
  421. }
  422. CachedUserInfo userProfile = CommsManager.UserProfileCacheService.GetUserDetails(agentID);
  423. if (null == userProfile)
  424. {
  425. m_log.ErrorFormat("[AGENT INVENTORY]: Could not find user profile for {0}", agentID);
  426. return null;
  427. }
  428. // XXX: When a client crosses into a scene, their entire inventory is fetched
  429. // asynchronously. If the client makes a request before the inventory is received, we need
  430. // to give the inventory a chance to come in.
  431. //
  432. // This is a crude way of dealing with that by retrying the lookup. It's not quite as bad
  433. // in CAPS as doing this with the udp request, since here it won't hold up other packets.
  434. // In fact, here we'll be generous and try for longer.
  435. if (!userProfile.HasReceivedInventory)
  436. {
  437. int attempts = 0;
  438. while (attempts++ < 30)
  439. {
  440. m_log.DebugFormat(
  441. "[INVENTORY CACHE]: Poll number {0} for inventory items in folder {1} for user {2}",
  442. attempts, folderID, agentID);
  443. Thread.Sleep(2000);
  444. if (userProfile.HasReceivedInventory)
  445. {
  446. break;
  447. }
  448. }
  449. }
  450. if (userProfile.HasReceivedInventory)
  451. {
  452. if ((fold = userProfile.RootFolder.FindFolder(folderID)) != null)
  453. {
  454. return fold.RequestListOfItems();
  455. }
  456. else
  457. {
  458. m_log.WarnFormat(
  459. "[AGENT INVENTORY]: Could not find folder {0} requested by user {1}",
  460. folderID, agentID);
  461. return null;
  462. }
  463. }
  464. else
  465. {
  466. m_log.ErrorFormat("[INVENTORY CACHE]: Could not find root folder for user {0}", agentID);
  467. return null;
  468. }
  469. }
  470. /// <summary>
  471. /// Handle an inventory folder creation request from the client.
  472. /// </summary>
  473. /// <param name="remoteClient"></param>
  474. /// <param name="folderID"></param>
  475. /// <param name="folderType"></param>
  476. /// <param name="folderName"></param>
  477. /// <param name="parentID"></param>
  478. public void HandleCreateInventoryFolder(IClientAPI remoteClient, UUID folderID, ushort folderType,
  479. string folderName, UUID parentID)
  480. {
  481. CachedUserInfo userProfile = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  482. if (null == userProfile)
  483. {
  484. m_log.ErrorFormat(
  485. "[AGENT INVENTORY]: Could not find user profile for {0} {1}",
  486. remoteClient.Name, remoteClient.AgentId);
  487. return;
  488. }
  489. if (!userProfile.CreateFolder(folderName, folderID, folderType, parentID))
  490. {
  491. m_log.ErrorFormat(
  492. "[AGENT INVENTORY]: Failed to move create folder for user {0} {1}",
  493. remoteClient.Name, remoteClient.AgentId);
  494. }
  495. }
  496. /// <summary>
  497. /// Handle a client request to update the inventory folder
  498. /// </summary>
  499. ///
  500. /// FIXME: We call add new inventory folder because in the data layer, we happen to use an SQL REPLACE
  501. /// so this will work to rename an existing folder. Needless to say, to rely on this is very confusing,
  502. /// and needs to be changed.
  503. ///
  504. /// <param name="remoteClient"></param>
  505. /// <param name="folderID"></param>
  506. /// <param name="type"></param>
  507. /// <param name="name"></param>
  508. /// <param name="parentID"></param>
  509. public void HandleUpdateInventoryFolder(IClientAPI remoteClient, UUID folderID, ushort type, string name,
  510. UUID parentID)
  511. {
  512. // m_log.DebugFormat(
  513. // "[AGENT INVENTORY]: Updating inventory folder {0} {1} for {2} {3}", folderID, name, remoteClient.Name, remoteClient.AgentId);
  514. CachedUserInfo userProfile = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  515. if (null == userProfile)
  516. {
  517. m_log.ErrorFormat(
  518. "[AGENT INVENTORY]: Could not find user profile for {0} {1}",
  519. remoteClient.Name, remoteClient.AgentId);
  520. return;
  521. }
  522. if (!userProfile.UpdateFolder(name, folderID, type, parentID))
  523. {
  524. m_log.ErrorFormat(
  525. "[AGENT INVENTORY]: Failed to update folder for user {0} {1}",
  526. remoteClient.Name, remoteClient.AgentId);
  527. }
  528. }
  529. /// <summary>
  530. /// Handle an inventory folder move request from the client.
  531. /// </summary>
  532. /// <param name="remoteClient"></param>
  533. /// <param name="folderID"></param>
  534. /// <param name="parentID"></param>
  535. public void HandleMoveInventoryFolder(IClientAPI remoteClient, UUID folderID, UUID parentID)
  536. {
  537. CachedUserInfo userProfile = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  538. if (null == userProfile)
  539. {
  540. m_log.ErrorFormat(
  541. "[AGENT INVENTORY]: Could not find user profile for {0} {1}",
  542. remoteClient.Name, remoteClient.AgentId);
  543. return;
  544. }
  545. if (!userProfile.MoveFolder(folderID, parentID))
  546. {
  547. m_log.ErrorFormat(
  548. "[AGENT INVENTORY]: Failed to move folder {0} to {1} for user {2}",
  549. folderID, parentID, remoteClient.Name);
  550. }
  551. }
  552. /// <summary>
  553. /// This should delete all the items and folders in the given directory.
  554. /// </summary>
  555. /// <param name="remoteClient"></param>
  556. /// <param name="folderID"></param>
  557. public void HandlePurgeInventoryDescendents(IClientAPI remoteClient, UUID folderID)
  558. {
  559. CachedUserInfo userProfile = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  560. if (null == userProfile)
  561. {
  562. m_log.ErrorFormat(
  563. "[AGENT INVENTORY]: Could not find user profile for {0} {1}",
  564. remoteClient.Name, remoteClient.AgentId);
  565. return;
  566. }
  567. if (!userProfile.PurgeFolder(folderID))
  568. {
  569. m_log.ErrorFormat(
  570. "[AGENT INVENTORY]: Failed to purge folder for user {0} {1}",
  571. remoteClient.Name, remoteClient.AgentId);
  572. }
  573. }
  574. }
  575. }