Scene.PacketHandlers.cs 30 KB

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