PageRenderTime 22ms CodeModel.GetById 10ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/Aurora/Modules/Avatar/AuroraChat/LureModule.cs

https://bitbucket.org/VirtualReality/software-testing
C# | 205 lines | 139 code | 32 blank | 34 comment | 18 complexity | bc38c214073d6e99285b7a6024d976ae MD5 | raw file
  1/*
  2 * Copyright (c) Contributors, http://aurora-sim.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.ClientInterfaces;
 30using Aurora.Framework.ConsoleFramework;
 31using Aurora.Framework.Modules;
 32using Aurora.Framework.PresenceInfo;
 33using Aurora.Framework.SceneInfo;
 34using Aurora.Framework.Utilities;
 35using Nini.Config;
 36using OpenMetaverse;
 37using System;
 38
 39namespace Aurora.Modules.Chat
 40{
 41    /// <summary>
 42    ///     This just supports god TP's and thats about it
 43    /// </summary>
 44    public class LureModule : INonSharedRegionModule
 45    {
 46        #region Declares
 47
 48        private IScene m_scene;
 49
 50        private IMessageTransferModule m_TransferModule;
 51        private bool m_Enabled = true;
 52        private bool m_allowGodTeleports = true;
 53
 54        #endregion
 55
 56        #region INonSharedRegionModule
 57
 58        public void Initialise(IConfigSource source)
 59        {
 60            IConfig ccmModuleConfig = source.Configs["Messaging"];
 61            if (ccmModuleConfig != null)
 62            {
 63                m_Enabled = ccmModuleConfig.GetString("LureModule", Name) == Name;
 64                m_allowGodTeleports = ccmModuleConfig.GetBoolean("AllowGodTeleports", m_allowGodTeleports);
 65            }
 66        }
 67
 68        public void AddRegion(IScene scene)
 69        {
 70            if (!m_Enabled)
 71                return;
 72
 73            m_scene = scene;
 74
 75            scene.EventManager.OnNewClient += OnNewClient;
 76            scene.EventManager.OnClosingClient += OnClosingClient;
 77            scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage;
 78        }
 79
 80        public void RemoveRegion(IScene scene)
 81        {
 82            if (!m_Enabled)
 83                return;
 84
 85            m_scene = null;
 86
 87            scene.EventManager.OnNewClient -= OnNewClient;
 88            scene.EventManager.OnClosingClient -= OnClosingClient;
 89            scene.EventManager.OnIncomingInstantMessage -= OnGridInstantMessage;
 90        }
 91
 92        public void RegionLoaded(IScene scene)
 93        {
 94            if (!m_Enabled)
 95                return;
 96            m_TransferModule = m_scene.RequestModuleInterface<IMessageTransferModule>();
 97
 98            if (m_TransferModule == null)
 99                MainConsole.Instance.Error("[INSTANT MESSAGE]: No message transfer module, " +
100                                           "lures will not work!");
101        }
102
103        public Type ReplaceableInterface
104        {
105            get { return null; }
106        }
107
108        public void Close()
109        {
110        }
111
112        public string Name
113        {
114            get { return "AuroraLureModule"; }
115        }
116
117        #endregion
118
119        #region Client
120
121        private void OnNewClient(IClientAPI client)
122        {
123            client.OnStartLure += OnStartLure;
124            client.OnTeleportLureRequest += OnTeleportLureRequest;
125        }
126
127        private void OnClosingClient(IClientAPI client)
128        {
129            client.OnStartLure -= OnStartLure;
130            client.OnTeleportLureRequest -= OnTeleportLureRequest;
131        }
132
133        public void OnStartLure(byte lureType, string message, UUID targetid, IClientAPI client)
134        {
135            IScenePresence presence = client.Scene.GetScenePresence(client.AgentId);
136            Vector3 position = presence.AbsolutePosition + new Vector3(2, 0, 0)*presence.Rotation;
137            UUID dest = Util.BuildFakeParcelID(
138                client.Scene.RegionInfo.RegionHandle,
139                (uint) position.X,
140                (uint) position.Y,
141                (uint) position.Z);
142
143            GridInstantMessage m;
144
145            if (m_allowGodTeleports && client.Scene.Permissions.CanGodTeleport(client.AgentId, targetid))
146                //if we are an admin and are in god mode
147            {
148                //God tp them
149                m = new GridInstantMessage(client.Scene, client.AgentId,
150                                           client.FirstName + " " + client.LastName, targetid,
151                                           (byte) InstantMessageDialog.GodLikeRequestTeleport, false,
152                                           "", dest, false, presence.AbsolutePosition,
153                                           new Byte[0]);
154            }
155            else
156            {
157                //Not a god, so no god tp
158                m = new GridInstantMessage(client.Scene, client.AgentId,
159                                           client.FirstName + " " + client.LastName, targetid,
160                                           (byte) InstantMessageDialog.RequestTeleport, false,
161                                           message, dest, false, presence.AbsolutePosition,
162                                           new Byte[0]);
163            }
164
165            if (m_TransferModule != null)
166                m_TransferModule.SendInstantMessage(m);
167        }
168
169        public void OnTeleportLureRequest(UUID lureID, uint teleportFlags, IClientAPI client)
170        {
171            ulong handle;
172            uint x;
173            uint y;
174            uint z;
175
176            Util.ParseFakeParcelID(lureID, out handle, out x, out y, out z);
177
178            Vector3 position = new Vector3 {X = x, Y = y, Z = z};
179            IEntityTransferModule entityTransfer = client.Scene.RequestModuleInterface<IEntityTransferModule>();
180            if (entityTransfer != null)
181            {
182                entityTransfer.RequestTeleportLocation(client, handle, position,
183                                                       Vector3.Zero, teleportFlags);
184            }
185        }
186
187        private void OnGridInstantMessage(GridInstantMessage im)
188        {
189            if (im.dialog == (byte) InstantMessageDialog.RequestTeleport)
190            {
191                UUID sessionID = new UUID(im.imSessionID);
192                MainConsole.Instance.DebugFormat(
193                    "[HG LURE MODULE]: RequestTeleport sessionID={0}, regionID={1}, message={2}", im.imSessionID,
194                    im.RegionID, im.message);
195
196                // Forward. We do this, because the IM module explicitly rejects
197                // IMs of this type
198                if (m_TransferModule != null)
199                    m_TransferModule.SendInstantMessage(im);
200            }
201        }
202
203        #endregion
204    }
205}