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 Nini.Config; |
||
33 | using OpenMetaverse; |
||
34 | using Mono.Addins; |
||
35 | |||
36 | using OpenSim.Framework; |
||
37 | using OpenSim.Region.Framework.Interfaces; |
||
38 | using OpenSim.Region.Framework.Scenes; |
||
39 | using OpenSim.Services.Connectors.Hypergrid; |
||
40 | |||
41 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
||
42 | |||
43 | namespace OpenSim.Region.CoreModules.Avatar.Lure |
||
44 | { |
||
45 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "HGLureModule")] |
||
46 | public class HGLureModule : ISharedRegionModule |
||
47 | { |
||
48 | private static readonly ILog m_log = LogManager.GetLogger( |
||
49 | MethodBase.GetCurrentMethod().DeclaringType); |
||
50 | |||
51 | private readonly List<Scene> m_scenes = new List<Scene>(); |
||
52 | |||
53 | private IMessageTransferModule m_TransferModule = null; |
||
54 | private bool m_Enabled = false; |
||
55 | |||
56 | private string m_ThisGridURL; |
||
57 | |||
58 | private ExpiringCache<UUID, GridInstantMessage> m_PendingLures = new ExpiringCache<UUID, GridInstantMessage>(); |
||
59 | |||
60 | public void Initialise(IConfigSource config) |
||
61 | { |
||
62 | if (config.Configs["Messaging"] != null) |
||
63 | { |
||
64 | if (config.Configs["Messaging"].GetString("LureModule", string.Empty) == "HGLureModule") |
||
65 | { |
||
66 | m_Enabled = true; |
||
67 | |||
68 | m_ThisGridURL = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI", |
||
69 | new string[] { "Startup", "Hypergrid", "Messaging" }, String.Empty); |
||
70 | // Legacy. Remove soon! |
||
71 | m_ThisGridURL = config.Configs["Messaging"].GetString("Gatekeeper", m_ThisGridURL); |
||
72 | m_log.DebugFormat("[LURE MODULE]: {0} enabled", Name); |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | |||
77 | public void AddRegion(Scene scene) |
||
78 | { |
||
79 | if (!m_Enabled) |
||
80 | return; |
||
81 | |||
82 | lock (m_scenes) |
||
83 | { |
||
84 | m_scenes.Add(scene); |
||
85 | scene.EventManager.OnIncomingInstantMessage += OnIncomingInstantMessage; |
||
86 | scene.EventManager.OnNewClient += OnNewClient; |
||
87 | } |
||
88 | } |
||
89 | |||
90 | public void RegionLoaded(Scene scene) |
||
91 | { |
||
92 | if (!m_Enabled) |
||
93 | return; |
||
94 | |||
95 | if (m_TransferModule == null) |
||
96 | { |
||
97 | m_TransferModule = |
||
98 | scene.RequestModuleInterface<IMessageTransferModule>(); |
||
99 | |||
100 | if (m_TransferModule == null) |
||
101 | { |
||
102 | m_log.Error("[LURE MODULE]: No message transfer module, lures will not work!"); |
||
103 | |||
104 | m_Enabled = false; |
||
105 | m_scenes.Clear(); |
||
106 | scene.EventManager.OnNewClient -= OnNewClient; |
||
107 | scene.EventManager.OnIncomingInstantMessage -= OnIncomingInstantMessage; |
||
108 | } |
||
109 | } |
||
110 | |||
111 | } |
||
112 | |||
113 | public void RemoveRegion(Scene scene) |
||
114 | { |
||
115 | if (!m_Enabled) |
||
116 | return; |
||
117 | |||
118 | lock (m_scenes) |
||
119 | { |
||
120 | m_scenes.Remove(scene); |
||
121 | scene.EventManager.OnNewClient -= OnNewClient; |
||
122 | scene.EventManager.OnIncomingInstantMessage -= OnIncomingInstantMessage; |
||
123 | } |
||
124 | } |
||
125 | |||
126 | void OnNewClient(IClientAPI client) |
||
127 | { |
||
128 | client.OnInstantMessage += OnInstantMessage; |
||
129 | client.OnStartLure += OnStartLure; |
||
130 | client.OnTeleportLureRequest += OnTeleportLureRequest; |
||
131 | } |
||
132 | |||
133 | public void PostInitialise() |
||
134 | { |
||
135 | } |
||
136 | |||
137 | public void Close() |
||
138 | { |
||
139 | } |
||
140 | |||
141 | public string Name |
||
142 | { |
||
143 | get { return "HGLureModule"; } |
||
144 | } |
||
145 | |||
146 | public Type ReplaceableInterface |
||
147 | { |
||
148 | get { return null; } |
||
149 | } |
||
150 | |||
151 | void OnInstantMessage(IClientAPI client, GridInstantMessage im) |
||
152 | { |
||
153 | } |
||
154 | |||
155 | void OnIncomingInstantMessage(GridInstantMessage im) |
||
156 | { |
||
157 | if (im.dialog == (byte)InstantMessageDialog.RequestTeleport |
||
158 | || im.dialog == (byte)InstantMessageDialog.GodLikeRequestTeleport) |
||
159 | { |
||
160 | UUID sessionID = new UUID(im.imSessionID); |
||
161 | |||
162 | if (!m_PendingLures.Contains(sessionID)) |
||
163 | { |
||
164 | m_log.DebugFormat("[HG LURE MODULE]: RequestTeleport sessionID={0}, regionID={1}, message={2}", im.imSessionID, im.RegionID, im.message); |
||
165 | m_PendingLures.Add(sessionID, im, 7200); // 2 hours |
||
166 | } |
||
167 | |||
168 | // Forward. We do this, because the IM module explicitly rejects |
||
169 | // IMs of this type |
||
170 | if (m_TransferModule != null) |
||
171 | m_TransferModule.SendInstantMessage(im, delegate(bool success) { }); |
||
172 | } |
||
173 | } |
||
174 | |||
175 | public void OnStartLure(byte lureType, string message, UUID targetid, IClientAPI client) |
||
176 | { |
||
177 | if (!(client.Scene is Scene)) |
||
178 | return; |
||
179 | |||
180 | Scene scene = (Scene)(client.Scene); |
||
181 | ScenePresence presence = scene.GetScenePresence(client.AgentId); |
||
182 | |||
183 | message += "@" + m_ThisGridURL; |
||
184 | |||
185 | m_log.DebugFormat("[HG LURE MODULE]: TP invite with message {0}", message); |
||
186 | |||
187 | UUID sessionID = UUID.Random(); |
||
188 | |||
189 | GridInstantMessage m = new GridInstantMessage(scene, client.AgentId, |
||
190 | client.FirstName+" "+client.LastName, targetid, |
||
191 | (byte)InstantMessageDialog.RequestTeleport, false, |
||
192 | message, sessionID, false, presence.AbsolutePosition, |
||
193 | new Byte[0], true); |
||
194 | m.RegionID = client.Scene.RegionInfo.RegionID.Guid; |
||
195 | |||
196 | m_log.DebugFormat("[HG LURE MODULE]: RequestTeleport sessionID={0}, regionID={1}, message={2}", m.imSessionID, m.RegionID, m.message); |
||
197 | m_PendingLures.Add(sessionID, m, 7200); // 2 hours |
||
198 | |||
199 | if (m_TransferModule != null) |
||
200 | { |
||
201 | m_TransferModule.SendInstantMessage(m, |
||
202 | delegate(bool success) { }); |
||
203 | } |
||
204 | } |
||
205 | |||
206 | public void OnTeleportLureRequest(UUID lureID, uint teleportFlags, IClientAPI client) |
||
207 | { |
||
208 | if (!(client.Scene is Scene)) |
||
209 | return; |
||
210 | |||
211 | // Scene scene = (Scene)(client.Scene); |
||
212 | |||
213 | GridInstantMessage im = null; |
||
214 | if (m_PendingLures.TryGetValue(lureID, out im)) |
||
215 | { |
||
216 | m_PendingLures.Remove(lureID); |
||
217 | Lure(client, teleportFlags, im); |
||
218 | } |
||
219 | else |
||
220 | m_log.DebugFormat("[HG LURE MODULE]: pending lure {0} not found", lureID); |
||
221 | |||
222 | } |
||
223 | |||
224 | private void Lure(IClientAPI client, uint teleportflags, GridInstantMessage im) |
||
225 | { |
||
226 | Scene scene = (Scene)(client.Scene); |
||
227 | GridRegion region = scene.GridService.GetRegionByUUID(scene.RegionInfo.ScopeID, new UUID(im.RegionID)); |
||
228 | if (region != null) |
||
229 | scene.RequestTeleportLocation(client, region.RegionHandle, im.Position + new Vector3(0.5f, 0.5f, 0f), Vector3.UnitX, teleportflags); |
||
230 | else // we don't have that region here. Check if it's HG |
||
231 | { |
||
232 | string[] parts = im.message.Split(new char[] { '@' }); |
||
233 | if (parts.Length > 1) |
||
234 | { |
||
235 | string url = parts[parts.Length - 1]; // the last part |
||
236 | if (url.Trim(new char[] {'/'}) != m_ThisGridURL.Trim(new char[] {'/'})) |
||
237 | { |
||
238 | m_log.DebugFormat("[HG LURE MODULE]: Luring agent to grid {0} region {1} position {2}", url, im.RegionID, im.Position); |
||
239 | GatekeeperServiceConnector gConn = new GatekeeperServiceConnector(); |
||
240 | GridRegion gatekeeper = new GridRegion(); |
||
241 | gatekeeper.ServerURI = url; |
||
242 | GridRegion finalDestination = gConn.GetHyperlinkRegion(gatekeeper, new UUID(im.RegionID)); |
||
243 | if (finalDestination != null) |
||
244 | { |
||
245 | ScenePresence sp = scene.GetScenePresence(client.AgentId); |
||
246 | IEntityTransferModule transferMod = scene.RequestModuleInterface<IEntityTransferModule>(); |
||
247 | |||
248 | if (transferMod != null && sp != null) |
||
249 | transferMod.DoTeleport( |
||
250 | sp, gatekeeper, finalDestination, im.Position + new Vector3(0.5f, 0.5f, 0f), |
||
251 | Vector3.UnitX, teleportflags); |
||
252 | } |
||
253 | } |
||
254 | } |
||
255 | } |
||
256 | } |
||
257 | } |
||
258 | } |