PageRenderTime 31ms CodeModel.GetById 26ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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