Scene.PacketHandlers.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Threading;
  30. using OpenMetaverse;
  31. using OpenMetaverse.Packets;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Communications;
  34. using OpenSim.Services.Interfaces;
  35. namespace OpenSim.Region.Framework.Scenes
  36. {
  37. public partial class Scene
  38. {
  39. protected void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
  40. UUID fromID, bool fromAgent, bool broadcast)
  41. {
  42. OSChatMessage args = new OSChatMessage();
  43. args.Message = Utils.BytesToString(message);
  44. args.Channel = channel;
  45. args.Type = type;
  46. args.Position = fromPos;
  47. args.SenderUUID = fromID;
  48. args.Scene = this;
  49. if (fromAgent)
  50. {
  51. ScenePresence user = GetScenePresence(fromID);
  52. if (user != null)
  53. args.Sender = user.ControllingClient;
  54. }
  55. else
  56. {
  57. SceneObjectPart obj = GetSceneObjectPart(fromID);
  58. args.SenderObject = obj;
  59. }
  60. args.From = fromName;
  61. //args.
  62. if (broadcast)
  63. EventManager.TriggerOnChatBroadcast(this, args);
  64. else
  65. EventManager.TriggerOnChatFromWorld(this, args);
  66. }
  67. /// <summary>
  68. ///
  69. /// </summary>
  70. /// <param name="message"></param>
  71. /// <param name="type"></param>
  72. /// <param name="fromPos"></param>
  73. /// <param name="fromName"></param>
  74. /// <param name="fromAgentID"></param>
  75. public void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
  76. UUID fromID, bool fromAgent)
  77. {
  78. SimChat(message, type, channel, fromPos, fromName, fromID, fromAgent, false);
  79. }
  80. public void SimChat(string message, ChatTypeEnum type, Vector3 fromPos, string fromName, UUID fromID, bool fromAgent)
  81. {
  82. SimChat(Utils.StringToBytes(message), type, 0, fromPos, fromName, fromID, fromAgent);
  83. }
  84. public void SimChat(string message, string fromName)
  85. {
  86. SimChat(message, ChatTypeEnum.Broadcast, Vector3.Zero, fromName, UUID.Zero, false);
  87. }
  88. /// <summary>
  89. ///
  90. /// </summary>
  91. /// <param name="message"></param>
  92. /// <param name="type"></param>
  93. /// <param name="fromPos"></param>
  94. /// <param name="fromName"></param>
  95. /// <param name="fromAgentID"></param>
  96. public void SimChatBroadcast(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName,
  97. UUID fromID, bool fromAgent)
  98. {
  99. SimChat(message, type, channel, fromPos, fromName, fromID, fromAgent, true);
  100. }
  101. /// <summary>
  102. /// Invoked when the client requests a prim.
  103. /// </summary>
  104. /// <param name="primLocalID"></param>
  105. /// <param name="remoteClient"></param>
  106. public void RequestPrim(uint primLocalID, IClientAPI remoteClient)
  107. {
  108. SceneObjectGroup sog = GetGroupByPrim(primLocalID);
  109. if (sog != null)
  110. sog.SendFullUpdateToClient(remoteClient);
  111. }
  112. /// <summary>
  113. /// Invoked when the client selects a prim.
  114. /// </summary>
  115. /// <param name="primLocalID"></param>
  116. /// <param name="remoteClient"></param>
  117. public void SelectPrim(uint primLocalID, IClientAPI remoteClient)
  118. {
  119. SceneObjectPart part = GetSceneObjectPart(primLocalID);
  120. if (null == part)
  121. return;
  122. if (part.IsRoot)
  123. {
  124. SceneObjectGroup sog = part.ParentGroup;
  125. sog.SendPropertiesToClient(remoteClient);
  126. sog.IsSelected = true;
  127. // A prim is only tainted if it's allowed to be edited by the person clicking it.
  128. if (Permissions.CanEditObject(sog.UUID, remoteClient.AgentId)
  129. || Permissions.CanMoveObject(sog.UUID, remoteClient.AgentId))
  130. {
  131. EventManager.TriggerParcelPrimCountTainted();
  132. }
  133. }
  134. else
  135. {
  136. part.SendPropertiesToClient(remoteClient);
  137. }
  138. }
  139. /// <summary>
  140. /// Handle the deselection of a prim from the client.
  141. /// </summary>
  142. /// <param name="primLocalID"></param>
  143. /// <param name="remoteClient"></param>
  144. public void DeselectPrim(uint primLocalID, IClientAPI remoteClient)
  145. {
  146. SceneObjectPart part = GetSceneObjectPart(primLocalID);
  147. if (part == null)
  148. return;
  149. // A deselect packet contains all the local prims being deselected. However, since selection is still
  150. // group based we only want the root prim to trigger a full update - otherwise on objects with many prims
  151. // we end up sending many duplicate ObjectUpdates
  152. if (part.ParentGroup.RootPart.LocalId != part.LocalId)
  153. return;
  154. bool isAttachment = false;
  155. // This is wrong, wrong, wrong. Selection should not be
  156. // handled by group, but by prim. Legacy cruft.
  157. // TODO: Make selection flagging per prim!
  158. //
  159. part.ParentGroup.IsSelected = false;
  160. if (part.ParentGroup.IsAttachment)
  161. isAttachment = true;
  162. else
  163. part.ParentGroup.ScheduleGroupForFullUpdate();
  164. // If it's not an attachment, and we are allowed to move it,
  165. // then we might have done so. If we moved across a parcel
  166. // boundary, we will need to recount prims on the parcels.
  167. // For attachments, that makes no sense.
  168. //
  169. if (!isAttachment)
  170. {
  171. if (Permissions.CanEditObject(
  172. part.UUID, remoteClient.AgentId)
  173. || Permissions.CanMoveObject(
  174. part.UUID, remoteClient.AgentId))
  175. EventManager.TriggerParcelPrimCountTainted();
  176. }
  177. }
  178. public virtual void ProcessMoneyTransferRequest(UUID source, UUID destination, int amount,
  179. int transactiontype, string description)
  180. {
  181. EventManager.MoneyTransferArgs args = new EventManager.MoneyTransferArgs(source, destination, amount,
  182. transactiontype, description);
  183. EventManager.TriggerMoneyTransfer(this, args);
  184. }
  185. public virtual void ProcessParcelBuy(UUID agentId, UUID groupId, bool final, bool groupOwned,
  186. bool removeContribution, int parcelLocalID, int parcelArea, int parcelPrice, bool authenticated)
  187. {
  188. EventManager.LandBuyArgs args = new EventManager.LandBuyArgs(agentId, groupId, final, groupOwned,
  189. removeContribution, parcelLocalID, parcelArea,
  190. parcelPrice, authenticated);
  191. // First, allow all validators a stab at it
  192. m_eventManager.TriggerValidateLandBuy(this, args);
  193. // Then, check validation and transfer
  194. m_eventManager.TriggerLandBuy(this, args);
  195. }
  196. public virtual void ProcessObjectGrab(uint localID, Vector3 offsetPos, IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs)
  197. {
  198. SceneObjectPart part = GetSceneObjectPart(localID);
  199. if (part == null)
  200. return;
  201. SceneObjectGroup obj = part.ParentGroup;
  202. SurfaceTouchEventArgs surfaceArg = null;
  203. if (surfaceArgs != null && surfaceArgs.Count > 0)
  204. surfaceArg = surfaceArgs[0];
  205. // Currently only grab/touch for the single prim
  206. // the client handles rez correctly
  207. obj.ObjectGrabHandler(localID, offsetPos, remoteClient);
  208. // If the touched prim handles touches, deliver it
  209. // If not, deliver to root prim
  210. if ((part.ScriptEvents & scriptEvents.touch_start) != 0)
  211. EventManager.TriggerObjectGrab(part.LocalId, 0, part.OffsetPosition, remoteClient, surfaceArg);
  212. // Deliver to the root prim if the touched prim doesn't handle touches
  213. // or if we're meant to pass on touches anyway. Don't send to root prim
  214. // if prim touched is the root prim as we just did it
  215. if (((part.ScriptEvents & scriptEvents.touch_start) == 0) ||
  216. (part.PassTouches && (part.LocalId != obj.RootPart.LocalId)))
  217. {
  218. EventManager.TriggerObjectGrab(obj.RootPart.LocalId, part.LocalId, part.OffsetPosition, remoteClient, surfaceArg);
  219. }
  220. }
  221. public virtual void ProcessObjectGrabUpdate(
  222. UUID objectID, Vector3 offset, Vector3 pos, IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs)
  223. {
  224. SceneObjectPart part = GetSceneObjectPart(objectID);
  225. if (part == null)
  226. return;
  227. SceneObjectGroup obj = part.ParentGroup;
  228. SurfaceTouchEventArgs surfaceArg = null;
  229. if (surfaceArgs != null && surfaceArgs.Count > 0)
  230. surfaceArg = surfaceArgs[0];
  231. // If the touched prim handles touches, deliver it
  232. // If not, deliver to root prim
  233. if ((part.ScriptEvents & scriptEvents.touch) != 0)
  234. EventManager.TriggerObjectGrabbing(part.LocalId, 0, part.OffsetPosition, remoteClient, surfaceArg);
  235. // Deliver to the root prim if the touched prim doesn't handle touches
  236. // or if we're meant to pass on touches anyway. Don't send to root prim
  237. // if prim touched is the root prim as we just did it
  238. if (((part.ScriptEvents & scriptEvents.touch) == 0) ||
  239. (part.PassTouches && (part.LocalId != obj.RootPart.LocalId)))
  240. {
  241. EventManager.TriggerObjectGrabbing(obj.RootPart.LocalId, part.LocalId, part.OffsetPosition, remoteClient, surfaceArg);
  242. }
  243. }
  244. public virtual void ProcessObjectDeGrab(uint localID, IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs)
  245. {
  246. SceneObjectPart part = GetSceneObjectPart(localID);
  247. if (part == null)
  248. return;
  249. SceneObjectGroup obj = part.ParentGroup;
  250. SurfaceTouchEventArgs surfaceArg = null;
  251. if (surfaceArgs != null && surfaceArgs.Count > 0)
  252. surfaceArg = surfaceArgs[0];
  253. // If the touched prim handles touches, deliver it
  254. // If not, deliver to root prim
  255. if ((part.ScriptEvents & scriptEvents.touch_end) != 0)
  256. EventManager.TriggerObjectDeGrab(part.LocalId, 0, remoteClient, surfaceArg);
  257. else
  258. EventManager.TriggerObjectDeGrab(obj.RootPart.LocalId, part.LocalId, remoteClient, surfaceArg);
  259. }
  260. public void ProcessAvatarPickerRequest(IClientAPI client, UUID avatarID, UUID RequestID, string query)
  261. {
  262. //EventManager.TriggerAvatarPickerRequest();
  263. List<UserAccount> accounts = UserAccountService.GetUserAccounts(RegionInfo.ScopeID, query);
  264. if (accounts == null)
  265. return;
  266. AvatarPickerReplyPacket replyPacket = (AvatarPickerReplyPacket) PacketPool.Instance.GetPacket(PacketType.AvatarPickerReply);
  267. // TODO: don't create new blocks if recycling an old packet
  268. AvatarPickerReplyPacket.DataBlock[] searchData =
  269. new AvatarPickerReplyPacket.DataBlock[accounts.Count];
  270. AvatarPickerReplyPacket.AgentDataBlock agentData = new AvatarPickerReplyPacket.AgentDataBlock();
  271. agentData.AgentID = avatarID;
  272. agentData.QueryID = RequestID;
  273. replyPacket.AgentData = agentData;
  274. //byte[] bytes = new byte[AvatarResponses.Count*32];
  275. int i = 0;
  276. foreach (UserAccount item in accounts)
  277. {
  278. UUID translatedIDtem = item.PrincipalID;
  279. searchData[i] = new AvatarPickerReplyPacket.DataBlock();
  280. searchData[i].AvatarID = translatedIDtem;
  281. searchData[i].FirstName = Utils.StringToBytes((string) item.FirstName);
  282. searchData[i].LastName = Utils.StringToBytes((string) item.LastName);
  283. i++;
  284. }
  285. if (accounts.Count == 0)
  286. {
  287. searchData = new AvatarPickerReplyPacket.DataBlock[0];
  288. }
  289. replyPacket.Data = searchData;
  290. AvatarPickerReplyAgentDataArgs agent_data = new AvatarPickerReplyAgentDataArgs();
  291. agent_data.AgentID = replyPacket.AgentData.AgentID;
  292. agent_data.QueryID = replyPacket.AgentData.QueryID;
  293. List<AvatarPickerReplyDataArgs> data_args = new List<AvatarPickerReplyDataArgs>();
  294. for (i = 0; i < replyPacket.Data.Length; i++)
  295. {
  296. AvatarPickerReplyDataArgs data_arg = new AvatarPickerReplyDataArgs();
  297. data_arg.AvatarID = replyPacket.Data[i].AvatarID;
  298. data_arg.FirstName = replyPacket.Data[i].FirstName;
  299. data_arg.LastName = replyPacket.Data[i].LastName;
  300. data_args.Add(data_arg);
  301. }
  302. client.SendAvatarPickerReply(agent_data, data_args);
  303. }
  304. public void ProcessScriptReset(IClientAPI remoteClient, UUID objectID,
  305. UUID itemID)
  306. {
  307. SceneObjectPart part=GetSceneObjectPart(objectID);
  308. if (part == null)
  309. return;
  310. if (Permissions.CanResetScript(objectID, itemID, remoteClient.AgentId))
  311. {
  312. EventManager.TriggerScriptReset(part.LocalId, itemID);
  313. }
  314. }
  315. void ProcessViewerEffect(IClientAPI remoteClient, List<ViewerEffectEventHandlerArg> args)
  316. {
  317. // TODO: don't create new blocks if recycling an old packet
  318. ViewerEffectPacket.EffectBlock[] effectBlockArray = new ViewerEffectPacket.EffectBlock[args.Count];
  319. for (int i = 0; i < args.Count; i++)
  320. {
  321. ViewerEffectPacket.EffectBlock effect = new ViewerEffectPacket.EffectBlock();
  322. effect.AgentID = args[i].AgentID;
  323. effect.Color = args[i].Color;
  324. effect.Duration = args[i].Duration;
  325. effect.ID = args[i].ID;
  326. effect.Type = args[i].Type;
  327. effect.TypeData = args[i].TypeData;
  328. effectBlockArray[i] = effect;
  329. }
  330. ForEachClient(
  331. delegate(IClientAPI client)
  332. {
  333. if (client.AgentId != remoteClient.AgentId)
  334. client.SendViewerEffect(effectBlockArray);
  335. }
  336. );
  337. }
  338. /// <summary>
  339. /// Tell the client about the various child items and folders contained in the requested folder.
  340. /// </summary>
  341. /// <param name="remoteClient"></param>
  342. /// <param name="folderID"></param>
  343. /// <param name="ownerID"></param>
  344. /// <param name="fetchFolders"></param>
  345. /// <param name="fetchItems"></param>
  346. /// <param name="sortOrder"></param>
  347. public void HandleFetchInventoryDescendents(IClientAPI remoteClient, UUID folderID, UUID ownerID,
  348. bool fetchFolders, bool fetchItems, int sortOrder)
  349. {
  350. // m_log.DebugFormat(
  351. // "[USER INVENTORY]: HandleFetchInventoryDescendents() for {0}, folder={1}, fetchFolders={2}, fetchItems={3}, sortOrder={4}",
  352. // remoteClient.Name, folderID, fetchFolders, fetchItems, sortOrder);
  353. if (folderID == UUID.Zero)
  354. return;
  355. // FIXME MAYBE: We're not handling sortOrder!
  356. // TODO: This code for looking in the folder for the library should be folded somewhere else
  357. // so that this class doesn't have to know the details (and so that multiple libraries, etc.
  358. // can be handled transparently).
  359. InventoryFolderImpl fold = null;
  360. if (LibraryService != null && LibraryService.LibraryRootFolder != null)
  361. if ((fold = LibraryService.LibraryRootFolder.FindFolder(folderID)) != null)
  362. {
  363. remoteClient.SendInventoryFolderDetails(
  364. fold.Owner, folderID, fold.RequestListOfItems(),
  365. fold.RequestListOfFolders(), fold.Version, fetchFolders, fetchItems);
  366. return;
  367. }
  368. // We're going to send the reply async, because there may be
  369. // an enormous quantity of packets -- basically the entire inventory!
  370. // We don't want to block the client thread while all that is happening.
  371. SendInventoryDelegate d = SendInventoryAsync;
  372. d.BeginInvoke(remoteClient, folderID, ownerID, fetchFolders, fetchItems, sortOrder, SendInventoryComplete, d);
  373. }
  374. delegate void SendInventoryDelegate(IClientAPI remoteClient, UUID folderID, UUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder);
  375. void SendInventoryAsync(IClientAPI remoteClient, UUID folderID, UUID ownerID, bool fetchFolders, bool fetchItems, int sortOrder)
  376. {
  377. SendInventoryUpdate(remoteClient, new InventoryFolderBase(folderID), fetchFolders, fetchItems);
  378. }
  379. void SendInventoryComplete(IAsyncResult iar)
  380. {
  381. SendInventoryDelegate d = (SendInventoryDelegate)iar.AsyncState;
  382. d.EndInvoke(iar);
  383. }
  384. /// <summary>
  385. /// Handle the caps inventory descendents fetch.
  386. ///
  387. /// Since the folder structure is sent to the client on login, I believe we only need to handle items.
  388. /// Diva comment 8/13/2009: what if someone gave us a folder in the meantime??
  389. /// </summary>
  390. /// <param name="agentID"></param>
  391. /// <param name="folderID"></param>
  392. /// <param name="ownerID"></param>
  393. /// <param name="fetchFolders"></param>
  394. /// <param name="fetchItems"></param>
  395. /// <param name="sortOrder"></param>
  396. /// <returns>null if the inventory look up failed</returns>
  397. public InventoryCollection HandleFetchInventoryDescendentsCAPS(UUID agentID, UUID folderID, UUID ownerID,
  398. bool fetchFolders, bool fetchItems, int sortOrder, out int version)
  399. {
  400. m_log.DebugFormat(
  401. "[INVENTORY CACHE]: Fetching folders ({0}), items ({1}) from {2} for agent {3}",
  402. fetchFolders, fetchItems, folderID, agentID);
  403. // FIXME MAYBE: We're not handling sortOrder!
  404. // TODO: This code for looking in the folder for the library should be folded back into the
  405. // CachedUserInfo 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;
  408. if (LibraryService != null && LibraryService.LibraryRootFolder != null)
  409. if ((fold = LibraryService.LibraryRootFolder.FindFolder(folderID)) != null)
  410. {
  411. version = 0;
  412. InventoryCollection ret = new InventoryCollection();
  413. ret.Folders = new List<InventoryFolderBase>();
  414. ret.Items = fold.RequestListOfItems();
  415. return ret;
  416. }
  417. InventoryCollection contents = new InventoryCollection();
  418. if (folderID != UUID.Zero)
  419. {
  420. contents = InventoryService.GetFolderContent(agentID, folderID);
  421. InventoryFolderBase containingFolder = new InventoryFolderBase();
  422. containingFolder.ID = folderID;
  423. containingFolder.Owner = agentID;
  424. containingFolder = InventoryService.GetFolder(containingFolder);
  425. version = containingFolder.Version;
  426. }
  427. else
  428. {
  429. // Lost itemsm don't really need a version
  430. version = 1;
  431. }
  432. return contents;
  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 move 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. /// <summary>
  504. /// This should delete all the items and folders in the given directory.
  505. /// </summary>
  506. /// <param name="remoteClient"></param>
  507. /// <param name="folderID"></param>
  508. delegate void PurgeFolderDelegate(UUID userID, UUID folder);
  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. }