Scene.PacketHandlers.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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.Framework.Communications.Cache;
  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. 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. void ProcessViewerEffect(IClientAPI remoteClient, List<ViewerEffectEventHandlerArg> args)
  347. {
  348. // TODO: don't create new blocks if recycling an old packet
  349. ViewerEffectPacket.EffectBlock[] effectBlockArray = new ViewerEffectPacket.EffectBlock[args.Count];
  350. for (int i = 0; i < args.Count; i++)
  351. {
  352. ViewerEffectPacket.EffectBlock effect = new ViewerEffectPacket.EffectBlock();
  353. effect.AgentID = args[i].AgentID;
  354. effect.Color = args[i].Color;
  355. effect.Duration = args[i].Duration;
  356. effect.ID = args[i].ID;
  357. effect.Type = args[i].Type;
  358. effect.TypeData = args[i].TypeData;
  359. effectBlockArray[i] = effect;
  360. }
  361. ForEachClient(
  362. delegate(IClientAPI client)
  363. {
  364. if (client.AgentId != remoteClient.AgentId)
  365. client.SendViewerEffect(effectBlockArray);
  366. }
  367. );
  368. }
  369. /// <summary>
  370. /// Handle a fetch inventory request from the client
  371. /// </summary>
  372. /// <param name="remoteClient"></param>
  373. /// <param name="itemID"></param>
  374. /// <param name="ownerID"></param>
  375. public void HandleFetchInventory(IClientAPI remoteClient, UUID itemID, UUID ownerID)
  376. {
  377. if (ownerID == CommsManager.UserProfileCacheService.LibraryRoot.Owner)
  378. {
  379. //m_log.Debug("request info for library item");
  380. return;
  381. }
  382. InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
  383. item = InventoryService.GetItem(item);
  384. if (item != null)
  385. {
  386. remoteClient.SendInventoryItemDetails(ownerID, item);
  387. }
  388. // else shouldn't we send an alert message?
  389. }
  390. /// <summary>
  391. /// Tell the client about the various child items and folders contained in the requested folder.
  392. /// </summary>
  393. /// <param name="remoteClient"></param>
  394. /// <param name="folderID"></param>
  395. /// <param name="ownerID"></param>
  396. /// <param name="fetchFolders"></param>
  397. /// <param name="fetchItems"></param>
  398. /// <param name="sortOrder"></param>
  399. public void HandleFetchInventoryDescendents(IClientAPI remoteClient, UUID folderID, UUID ownerID,
  400. bool fetchFolders, bool fetchItems, int sortOrder)
  401. {
  402. // FIXME MAYBE: We're not handling sortOrder!
  403. // TODO: This code for looking in the folder for the library should be folded back into the
  404. // CachedUserInfo so that this class doesn't have to know the details (and so that multiple libraries, etc.
  405. // can be handled transparently).
  406. InventoryFolderImpl fold = null;
  407. if ((fold = CommsManager.UserProfileCacheService.LibraryRoot.FindFolder(folderID)) != null)
  408. {
  409. remoteClient.SendInventoryFolderDetails(
  410. fold.Owner, folderID, fold.RequestListOfItems(),
  411. fold.RequestListOfFolders(), fold.Version, fetchFolders, fetchItems);
  412. return;
  413. }
  414. // We're going to send the reply async, because there may be
  415. // an enormous quantity of packets -- basically the entire inventory!
  416. // We don't want to block the client thread while all that is happening.
  417. SendInventoryDelegate d = SendInventoryAsync;
  418. d.BeginInvoke(remoteClient, folderID, ownerID, fetchFolders, fetchItems, sortOrder, SendInventoryComplete, d);
  419. }
  420. delegate void SendInventoryDelegate(IClientAPI remoteClient, UUID folderID, UUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder);
  421. void SendInventoryAsync(IClientAPI remoteClient, UUID folderID, UUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder)
  422. {
  423. SendInventoryUpdate(remoteClient, new InventoryFolderBase(folderID), fetchFolders, fetchItems);
  424. }
  425. void SendInventoryComplete(IAsyncResult iar)
  426. {
  427. SendInventoryDelegate d = (SendInventoryDelegate)iar.AsyncState;
  428. d.EndInvoke(iar);
  429. }
  430. /// <summary>
  431. /// Handle the caps inventory descendents fetch.
  432. ///
  433. /// Since the folder structure is sent to the client on login, I believe we only need to handle items.
  434. /// Diva comment 8/13/2009: what if someone gave us a folder in the meantime??
  435. /// </summary>
  436. /// <param name="agentID"></param>
  437. /// <param name="folderID"></param>
  438. /// <param name="ownerID"></param>
  439. /// <param name="fetchFolders"></param>
  440. /// <param name="fetchItems"></param>
  441. /// <param name="sortOrder"></param>
  442. /// <returns>null if the inventory look up failed</returns>
  443. public InventoryCollection HandleFetchInventoryDescendentsCAPS(UUID agentID, UUID folderID, UUID ownerID,
  444. bool fetchFolders, bool fetchItems, int sortOrder, out int version)
  445. {
  446. m_log.DebugFormat(
  447. "[INVENTORY CACHE]: Fetching folders ({0}), items ({1}) from {2} for agent {3}",
  448. fetchFolders, fetchItems, folderID, agentID);
  449. // FIXME MAYBE: We're not handling sortOrder!
  450. // TODO: This code for looking in the folder for the library should be folded back into the
  451. // CachedUserInfo so that this class doesn't have to know the details (and so that multiple libraries, etc.
  452. // can be handled transparently).
  453. InventoryFolderImpl fold;
  454. if ((fold = CommsManager.UserProfileCacheService.LibraryRoot.FindFolder(folderID)) != null)
  455. {
  456. version = 0;
  457. InventoryCollection ret = new InventoryCollection();
  458. ret.Folders = new List<InventoryFolderBase>();
  459. ret.Items = fold.RequestListOfItems();
  460. return ret;
  461. }
  462. InventoryCollection contents = new InventoryCollection();
  463. if (folderID != UUID.Zero)
  464. {
  465. contents = InventoryService.GetFolderContent(agentID, folderID);
  466. InventoryFolderBase containingFolder = new InventoryFolderBase();
  467. containingFolder.ID = folderID;
  468. containingFolder.Owner = agentID;
  469. containingFolder = InventoryService.GetFolder(containingFolder);
  470. version = containingFolder.Version;
  471. }
  472. else
  473. {
  474. // Lost itemsm don't really need a version
  475. version = 1;
  476. }
  477. return contents;
  478. }
  479. /// <summary>
  480. /// Handle an inventory folder creation request from the client.
  481. /// </summary>
  482. /// <param name="remoteClient"></param>
  483. /// <param name="folderID"></param>
  484. /// <param name="folderType"></param>
  485. /// <param name="folderName"></param>
  486. /// <param name="parentID"></param>
  487. public void HandleCreateInventoryFolder(IClientAPI remoteClient, UUID folderID, ushort folderType,
  488. string folderName, UUID parentID)
  489. {
  490. InventoryFolderBase folder = new InventoryFolderBase(folderID, folderName, remoteClient.AgentId, (short)folderType, parentID, 1);
  491. if (!InventoryService.AddFolder(folder))
  492. {
  493. m_log.WarnFormat(
  494. "[AGENT INVENTORY]: Failed to move create folder for user {0} {1}",
  495. remoteClient.Name, remoteClient.AgentId);
  496. }
  497. }
  498. /// <summary>
  499. /// Handle a client request to update the inventory folder
  500. /// </summary>
  501. ///
  502. /// FIXME: We call add new inventory folder because in the data layer, we happen to use an SQL REPLACE
  503. /// so this will work to rename an existing folder. Needless to say, to rely on this is very confusing,
  504. /// and needs to be changed.
  505. ///
  506. /// <param name="remoteClient"></param>
  507. /// <param name="folderID"></param>
  508. /// <param name="type"></param>
  509. /// <param name="name"></param>
  510. /// <param name="parentID"></param>
  511. public void HandleUpdateInventoryFolder(IClientAPI remoteClient, UUID folderID, ushort type, string name,
  512. UUID parentID)
  513. {
  514. // m_log.DebugFormat(
  515. // "[AGENT INVENTORY]: Updating inventory folder {0} {1} for {2} {3}", folderID, name, remoteClient.Name, remoteClient.AgentId);
  516. InventoryFolderBase folder = new InventoryFolderBase(folderID, remoteClient.AgentId);
  517. folder = InventoryService.GetFolder(folder);
  518. if (folder != null)
  519. {
  520. folder.Name = name;
  521. folder.Type = (short)type;
  522. folder.ParentID = parentID;
  523. if (!InventoryService.UpdateFolder(folder))
  524. {
  525. m_log.ErrorFormat(
  526. "[AGENT INVENTORY]: Failed to update folder for user {0} {1}",
  527. remoteClient.Name, remoteClient.AgentId);
  528. }
  529. }
  530. }
  531. public void HandleMoveInventoryFolder(IClientAPI remoteClient, UUID folderID, UUID parentID)
  532. {
  533. InventoryFolderBase folder = new InventoryFolderBase(folderID, remoteClient.AgentId);
  534. folder = InventoryService.GetFolder(folder);
  535. if (folder != null)
  536. {
  537. folder.ParentID = parentID;
  538. if (!InventoryService.MoveFolder(folder))
  539. m_log.WarnFormat("[AGENT INVENTORY]: could not move folder {0}", folderID);
  540. else
  541. m_log.DebugFormat("[AGENT INVENTORY]: folder {0} moved to parent {1}", folderID, parentID);
  542. }
  543. else
  544. {
  545. m_log.WarnFormat("[AGENT INVENTORY]: request to move folder {0} but folder not found", folderID);
  546. }
  547. }
  548. /// <summary>
  549. /// This should delete all the items and folders in the given directory.
  550. /// </summary>
  551. /// <param name="remoteClient"></param>
  552. /// <param name="folderID"></param>
  553. delegate void PurgeFolderDelegate(UUID userID, UUID folder);
  554. public void HandlePurgeInventoryDescendents(IClientAPI remoteClient, UUID folderID)
  555. {
  556. PurgeFolderDelegate d = PurgeFolderAsync;
  557. try
  558. {
  559. d.BeginInvoke(remoteClient.AgentId, folderID, PurgeFolderCompleted, d);
  560. }
  561. catch (Exception e)
  562. {
  563. m_log.WarnFormat("[AGENT INVENTORY]: Exception on purge folder for user {0}: {1}", remoteClient.AgentId, e.Message);
  564. }
  565. }
  566. private void PurgeFolderAsync(UUID userID, UUID folderID)
  567. {
  568. InventoryFolderBase folder = new InventoryFolderBase(folderID, userID);
  569. if (InventoryService.PurgeFolder(folder))
  570. m_log.DebugFormat("[AGENT INVENTORY]: folder {0} purged successfully", folderID);
  571. else
  572. m_log.WarnFormat("[AGENT INVENTORY]: could not purge folder {0}", folderID);
  573. }
  574. private void PurgeFolderCompleted(IAsyncResult iar)
  575. {
  576. PurgeFolderDelegate d = (PurgeFolderDelegate)iar.AsyncState;
  577. d.EndInvoke(iar);
  578. }
  579. }
  580. }