/Aurora/Modules/Avatar/Gestures/GesturesModule.cs

https://bitbucket.org/VirtualReality/software-testing · C# · 127 lines · 83 code · 18 blank · 26 comment · 4 complexity · 5c12ef7a68bf6b7529189906cdafbd20 MD5 · raw file

  1. /*
  2. * Copyright (c) Contributors, http://aurora-sim.org/, 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 Aurora-Sim 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 Aurora.Framework;
  28. using Aurora.Framework.ConsoleFramework;
  29. using Aurora.Framework.Modules;
  30. using Aurora.Framework.PresenceInfo;
  31. using Aurora.Framework.SceneInfo;
  32. using Aurora.Framework.Services;
  33. using Aurora.Framework.Services.ClassHelpers.Inventory;
  34. using Nini.Config;
  35. using OpenMetaverse;
  36. using System;
  37. namespace Aurora.Modules.Gestures
  38. {
  39. public class GesturesModule : INonSharedRegionModule
  40. {
  41. protected IScene m_scene;
  42. #region INonSharedRegionModule Members
  43. public void Initialise(IConfigSource source)
  44. {
  45. }
  46. public void AddRegion(IScene scene)
  47. {
  48. m_scene = scene;
  49. m_scene.EventManager.OnNewClient += OnNewClient;
  50. m_scene.EventManager.OnClosingClient += OnClosingClient;
  51. }
  52. public void RemoveRegion(IScene scene)
  53. {
  54. m_scene.EventManager.OnNewClient -= OnNewClient;
  55. m_scene.EventManager.OnClosingClient -= OnClosingClient;
  56. }
  57. public void RegionLoaded(IScene scene)
  58. {
  59. }
  60. public Type ReplaceableInterface
  61. {
  62. get { return null; }
  63. }
  64. public void Close()
  65. {
  66. }
  67. public string Name
  68. {
  69. get { return "Gestures Module"; }
  70. }
  71. #endregion
  72. private void OnNewClient(IClientAPI client)
  73. {
  74. client.OnActivateGesture += ActivateGesture;
  75. client.OnDeactivateGesture += DeactivateGesture;
  76. }
  77. private void OnClosingClient(IClientAPI client)
  78. {
  79. client.OnActivateGesture -= ActivateGesture;
  80. client.OnDeactivateGesture -= DeactivateGesture;
  81. }
  82. public virtual void ActivateGesture(IClientAPI client, UUID assetId, UUID gestureId)
  83. {
  84. IInventoryService invService = m_scene.InventoryService;
  85. InventoryItemBase item = invService.GetItem(client.AgentId, gestureId);
  86. if (item != null)
  87. {
  88. item.Flags |= (uint) 1;
  89. invService.UpdateItem(item);
  90. }
  91. else
  92. MainConsole.Instance.WarnFormat(
  93. "[GESTURES]: Unable to find gesture {0} to activate for {1}", gestureId, client.Name);
  94. }
  95. public virtual void DeactivateGesture(IClientAPI client, UUID gestureId)
  96. {
  97. IInventoryService invService = m_scene.InventoryService;
  98. InventoryItemBase item = invService.GetItem(client.AgentId, gestureId);
  99. if (item != null)
  100. {
  101. item.Flags &= ~(uint) 1;
  102. invService.UpdateItem(item);
  103. }
  104. else
  105. MainConsole.Instance.ErrorFormat(
  106. "[GESTURES]: Unable to find gesture to deactivate {0} for {1}", gestureId, client.Name);
  107. }
  108. }
  109. }