opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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 | |||
28 | using System; |
||
29 | using System.Collections.Generic; |
||
30 | using System.Reflection; |
||
31 | using log4net; |
||
32 | using Mono.Addins; |
||
33 | using Nini.Config; |
||
34 | using OpenMetaverse; |
||
35 | using OpenSim.Framework; |
||
36 | using OpenSim.Region.Framework.Interfaces; |
||
37 | using OpenSim.Region.Framework.Scenes; |
||
38 | |||
39 | namespace OpenSim.Region.CoreModules.Avatar.Lure |
||
40 | { |
||
41 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LureModule")] |
||
42 | public class LureModule : ISharedRegionModule |
||
43 | { |
||
44 | private static readonly ILog m_log = LogManager.GetLogger( |
||
45 | MethodBase.GetCurrentMethod().DeclaringType); |
||
46 | |||
47 | private readonly List<Scene> m_scenes = new List<Scene>(); |
||
48 | |||
49 | private IMessageTransferModule m_TransferModule = null; |
||
50 | private bool m_Enabled = false; |
||
51 | |||
52 | public void Initialise(IConfigSource config) |
||
53 | { |
||
54 | if (config.Configs["Messaging"] != null) |
||
55 | { |
||
56 | if (config.Configs["Messaging"].GetString( |
||
57 | "LureModule", "LureModule") == |
||
58 | "LureModule") |
||
59 | { |
||
60 | m_Enabled = true; |
||
61 | m_log.DebugFormat("[LURE MODULE]: {0} enabled", Name); |
||
62 | } |
||
63 | } |
||
64 | } |
||
65 | |||
66 | public void AddRegion(Scene scene) |
||
67 | { |
||
68 | if (!m_Enabled) |
||
69 | return; |
||
70 | |||
71 | lock (m_scenes) |
||
72 | { |
||
73 | m_scenes.Add(scene); |
||
74 | scene.EventManager.OnNewClient += OnNewClient; |
||
75 | scene.EventManager.OnIncomingInstantMessage += |
||
76 | OnGridInstantMessage; |
||
77 | } |
||
78 | } |
||
79 | |||
80 | public void RegionLoaded(Scene scene) |
||
81 | { |
||
82 | if (!m_Enabled) |
||
83 | return; |
||
84 | |||
85 | if (m_TransferModule == null) |
||
86 | { |
||
87 | m_TransferModule = |
||
88 | scene.RequestModuleInterface<IMessageTransferModule>(); |
||
89 | |||
90 | if (m_TransferModule == null) |
||
91 | { |
||
92 | m_log.Error("[INSTANT MESSAGE]: No message transfer module, "+ |
||
93 | "lures will not work!"); |
||
94 | |||
95 | m_Enabled = false; |
||
96 | m_scenes.Clear(); |
||
97 | scene.EventManager.OnNewClient -= OnNewClient; |
||
98 | scene.EventManager.OnIncomingInstantMessage -= |
||
99 | OnGridInstantMessage; |
||
100 | } |
||
101 | } |
||
102 | |||
103 | } |
||
104 | |||
105 | public void RemoveRegion(Scene scene) |
||
106 | { |
||
107 | if (!m_Enabled) |
||
108 | return; |
||
109 | |||
110 | lock (m_scenes) |
||
111 | { |
||
112 | m_scenes.Remove(scene); |
||
113 | scene.EventManager.OnNewClient -= OnNewClient; |
||
114 | scene.EventManager.OnIncomingInstantMessage -= |
||
115 | OnGridInstantMessage; |
||
116 | } |
||
117 | } |
||
118 | |||
119 | void OnNewClient(IClientAPI client) |
||
120 | { |
||
121 | client.OnInstantMessage += OnInstantMessage; |
||
122 | client.OnStartLure += OnStartLure; |
||
123 | client.OnTeleportLureRequest += OnTeleportLureRequest; |
||
124 | } |
||
125 | |||
126 | public void PostInitialise() |
||
127 | { |
||
128 | } |
||
129 | |||
130 | public void Close() |
||
131 | { |
||
132 | } |
||
133 | |||
134 | public string Name |
||
135 | { |
||
136 | get { return "LureModule"; } |
||
137 | } |
||
138 | |||
139 | public Type ReplaceableInterface |
||
140 | { |
||
141 | get { return null; } |
||
142 | } |
||
143 | |||
144 | public void OnInstantMessage(IClientAPI client, GridInstantMessage im) |
||
145 | { |
||
146 | } |
||
147 | |||
148 | public void OnStartLure(byte lureType, string message, UUID targetid, IClientAPI client) |
||
149 | { |
||
150 | if (!(client.Scene is Scene)) |
||
151 | return; |
||
152 | |||
153 | Scene scene = (Scene)(client.Scene); |
||
154 | ScenePresence presence = scene.GetScenePresence(client.AgentId); |
||
155 | |||
156 | // Round up Z co-ordinate rather than round-down by casting. This stops tall avatars from being given |
||
157 | // a teleport Z co-ordinate by short avatars that drops them through or embeds them in thin floors on |
||
158 | // arrival. |
||
159 | // |
||
160 | // Ideally we would give the exact float position adjusting for the relative height of the two avatars |
||
161 | // but it looks like a float component isn't possible with a parcel ID. |
||
162 | UUID dest = Util.BuildFakeParcelID( |
||
163 | scene.RegionInfo.RegionHandle, |
||
164 | (uint)presence.AbsolutePosition.X, |
||
165 | (uint)presence.AbsolutePosition.Y, |
||
166 | (uint)Math.Ceiling(presence.AbsolutePosition.Z)); |
||
167 | |||
168 | m_log.DebugFormat("[LURE MODULE]: TP invite with message {0}, type {1}", message, lureType); |
||
169 | |||
170 | GridInstantMessage m = new GridInstantMessage(scene, client.AgentId, |
||
171 | client.FirstName+" "+client.LastName, targetid, |
||
172 | (byte)InstantMessageDialog.RequestTeleport, false, |
||
173 | message, dest, false, presence.AbsolutePosition, |
||
174 | new Byte[0], true); |
||
175 | |||
176 | if (m_TransferModule != null) |
||
177 | { |
||
178 | m_TransferModule.SendInstantMessage(m, |
||
179 | delegate(bool success) { }); |
||
180 | } |
||
181 | } |
||
182 | |||
183 | public void OnTeleportLureRequest(UUID lureID, uint teleportFlags, IClientAPI client) |
||
184 | { |
||
185 | if (!(client.Scene is Scene)) |
||
186 | return; |
||
187 | |||
188 | Scene scene = (Scene)(client.Scene); |
||
189 | |||
190 | ulong handle = 0; |
||
191 | uint x = 128; |
||
192 | uint y = 128; |
||
193 | uint z = 70; |
||
194 | |||
195 | Util.ParseFakeParcelID(lureID, out handle, out x, out y, out z); |
||
196 | |||
197 | Vector3 position = new Vector3(); |
||
198 | position.X = (float)x; |
||
199 | position.Y = (float)y; |
||
200 | position.Z = (float)z; |
||
201 | |||
202 | scene.RequestTeleportLocation(client, handle, position, |
||
203 | Vector3.Zero, teleportFlags); |
||
204 | } |
||
205 | |||
206 | private void OnGridInstantMessage(GridInstantMessage msg) |
||
207 | { |
||
208 | // Forward remote teleport requests |
||
209 | // |
||
210 | if (msg.dialog != 22) |
||
211 | return; |
||
212 | |||
213 | if (m_TransferModule != null) |
||
214 | { |
||
215 | m_TransferModule.SendInstantMessage(msg, |
||
216 | delegate(bool success) { }); |
||
217 | } |
||
218 | } |
||
219 | } |
||
220 | } |