aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs
diff options
context:
space:
mode:
authorDiva Canto2011-05-27 13:07:18 -0700
committerDiva Canto2011-05-27 13:07:18 -0700
commit76525be7b2cb1a72c45a72801dac871c4a338bcb (patch)
treefd7d22e2b7dfae7d5041b8b6be36a5fe892c7344 /OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs
parentAvoid a scary warning message about null replies from the user agent service. (diff)
downloadopensim-SC_OLD-76525be7b2cb1a72c45a72801dac871c4a338bcb.zip
opensim-SC_OLD-76525be7b2cb1a72c45a72801dac871c4a338bcb.tar.gz
opensim-SC_OLD-76525be7b2cb1a72c45a72801dac871c4a338bcb.tar.bz2
opensim-SC_OLD-76525be7b2cb1a72c45a72801dac871c4a338bcb.tar.xz
HG lures working! Friends can offer friends HG teleports via the profile. WARNING: additional configuration for HG inis -- see *Common.ini.example
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs244
1 files changed, 244 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs b/OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs
new file mode 100644
index 0000000..c82cfd2
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs
@@ -0,0 +1,244 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using log4net;
32using Nini.Config;
33using OpenMetaverse;
34using Mono.Addins;
35
36using OpenSim.Framework;
37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes;
39using OpenSim.Services.Connectors.Hypergrid;
40
41using GridRegion = OpenSim.Services.Interfaces.GridRegion;
42
43namespace OpenSim.Region.CoreModules.Avatar.Lure
44{
45 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
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 = config.Configs["Messaging"].GetString("Gatekeeper", string.Empty);
69 m_log.DebugFormat("[LURE MODULE]: {0} enabled", Name);
70 }
71 }
72 }
73
74 public void AddRegion(Scene scene)
75 {
76 if (!m_Enabled)
77 return;
78
79 lock (m_scenes)
80 {
81 m_scenes.Add(scene);
82 scene.EventManager.OnIncomingInstantMessage += OnIncomingInstantMessage;
83 scene.EventManager.OnNewClient += OnNewClient;
84 }
85 }
86
87 public void RegionLoaded(Scene scene)
88 {
89 if (!m_Enabled)
90 return;
91
92 if (m_TransferModule == null)
93 {
94 m_TransferModule =
95 scene.RequestModuleInterface<IMessageTransferModule>();
96
97 if (m_TransferModule == null)
98 {
99 m_log.Error("[LURE MODULE]: No message transfer module, lures will not work!");
100
101 m_Enabled = false;
102 m_scenes.Clear();
103 scene.EventManager.OnNewClient -= OnNewClient;
104 scene.EventManager.OnIncomingInstantMessage -= OnIncomingInstantMessage;
105 }
106 }
107
108 }
109
110 public void RemoveRegion(Scene scene)
111 {
112 if (!m_Enabled)
113 return;
114
115 lock (m_scenes)
116 {
117 m_scenes.Remove(scene);
118 scene.EventManager.OnNewClient -= OnNewClient;
119 scene.EventManager.OnIncomingInstantMessage -= OnIncomingInstantMessage;
120 }
121 }
122
123 void OnNewClient(IClientAPI client)
124 {
125 client.OnInstantMessage += OnInstantMessage;
126 client.OnStartLure += OnStartLure;
127 client.OnTeleportLureRequest += OnTeleportLureRequest;
128 }
129
130 public void PostInitialise()
131 {
132 }
133
134 public void Close()
135 {
136 }
137
138 public string Name
139 {
140 get { return "HGLureModule"; }
141 }
142
143 public Type ReplaceableInterface
144 {
145 get { return null; }
146 }
147
148 void OnInstantMessage(IClientAPI client, GridInstantMessage im)
149 {
150 }
151
152 void OnIncomingInstantMessage(GridInstantMessage im)
153 {
154 if (im.dialog == (byte)InstantMessageDialog.RequestTeleport)
155 {
156 UUID sessionID = new UUID(im.imSessionID);
157 m_log.DebugFormat("[HG LURE MODULE]: RequestTeleport sessionID={0}, regionID={1}, message={2}", im.imSessionID, im.RegionID, im.message);
158 m_PendingLures.Add(sessionID, im, 7200); // 2 hours
159
160 // Forward. We do this, because the IM module explicitly rejects
161 // IMs of this type
162 if (m_TransferModule != null)
163 m_TransferModule.SendInstantMessage(im, delegate(bool success) { });
164
165 }
166 }
167
168 public void OnStartLure(byte lureType, string message, UUID targetid, IClientAPI client)
169 {
170 if (!(client.Scene is Scene))
171 return;
172
173 Scene scene = (Scene)(client.Scene);
174 ScenePresence presence = scene.GetScenePresence(client.AgentId);
175
176 message += "@" + m_ThisGridURL;
177
178 m_log.DebugFormat("[HG LURE MODULE]: TP invite with message {0}", message);
179
180 GridInstantMessage m = new GridInstantMessage(scene, client.AgentId,
181 client.FirstName+" "+client.LastName, targetid,
182 (byte)InstantMessageDialog.RequestTeleport, false,
183 message, UUID.Random(), false, presence.AbsolutePosition,
184 new Byte[0]);
185 m.RegionID = client.Scene.RegionInfo.RegionID.Guid;
186
187 if (m_TransferModule != null)
188 {
189 m_TransferModule.SendInstantMessage(m,
190 delegate(bool success) { });
191 }
192 }
193
194 public void OnTeleportLureRequest(UUID lureID, uint teleportFlags, IClientAPI client)
195 {
196 if (!(client.Scene is Scene))
197 return;
198
199 Scene scene = (Scene)(client.Scene);
200
201 GridInstantMessage im = null;
202 if (m_PendingLures.TryGetValue(lureID, out im))
203 {
204 m_PendingLures.Remove(lureID);
205 Lure(client, teleportFlags, im);
206 }
207 else
208 m_log.DebugFormat("[HG LURE MODULE]: pending lure {0} not found", lureID);
209
210 }
211
212 private void Lure(IClientAPI client, uint teleportflags, GridInstantMessage im)
213 {
214 Scene scene = (Scene)(client.Scene);
215 GridRegion region = scene.GridService.GetRegionByUUID(scene.RegionInfo.ScopeID, new UUID(im.RegionID));
216 if (region != null)
217 scene.RequestTeleportLocation(client, region.RegionHandle, im.Position + new Vector3(0.5f, 0.5f, 0f), Vector3.UnitX, teleportflags);
218 else // we don't have that region here. Check if it's HG
219 {
220 string[] parts = im.message.Split(new char[] { '@' });
221 if (parts.Length > 1)
222 {
223 string url = parts[parts.Length - 1]; // the last part
224 if (url.Trim(new char[] {'/'}) != m_ThisGridURL.Trim(new char[] {'/'}))
225 {
226 m_log.DebugFormat("[HG LURE MODULE]: Luring agent to grid {0} region {1} position {2}", url, im.RegionID, im.Position);
227 GatekeeperServiceConnector gConn = new GatekeeperServiceConnector();
228 GridRegion gatekeeper = new GridRegion();
229 gatekeeper.ServerURI = url;
230 GridRegion finalDestination = gConn.GetHyperlinkRegion(gatekeeper, new UUID(im.RegionID));
231 if (finalDestination != null)
232 {
233 ScenePresence sp = scene.GetScenePresence(client.AgentId);
234 IEntityTransferModule transferMod = scene.RequestModuleInterface<IEntityTransferModule>();
235 IEventQueue eq = sp.Scene.RequestModuleInterface<IEventQueue>();
236 if (transferMod != null && sp != null && eq != null)
237 transferMod.DoTeleport(sp, gatekeeper, finalDestination, im.Position + new Vector3(0.5f, 0.5f, 0f), Vector3.UnitX, teleportflags, eq);
238 }
239 }
240 }
241 }
242 }
243 }
244}