aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Lure
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Lure')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs163
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs220
2 files changed, 71 insertions, 312 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs b/OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs
index 24286a4..3dc9bf5 100644
--- a/OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs
@@ -29,10 +29,9 @@ using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Reflection; 30using System.Reflection;
31using log4net; 31using log4net;
32using Mono.Addins;
32using Nini.Config; 33using Nini.Config;
33using OpenMetaverse; 34using OpenMetaverse;
34using Mono.Addins;
35
36using OpenSim.Framework; 35using OpenSim.Framework;
37using OpenSim.Region.Framework.Interfaces; 36using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes; 37using OpenSim.Region.Framework.Scenes;
@@ -45,13 +44,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Lure
45 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "HGLureModule")] 44 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "HGLureModule")]
46 public class HGLureModule : ISharedRegionModule 45 public class HGLureModule : ISharedRegionModule
47 { 46 {
48 private static readonly ILog m_log = LogManager.GetLogger( 47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 MethodBase.GetCurrentMethod().DeclaringType);
50 48
51 private readonly List<Scene> m_scenes = new List<Scene>(); 49 private readonly List<Scene> m_scenes = new List<Scene>();
52 50
53 private IMessageTransferModule m_TransferModule = null; 51 private IMessageTransferModule m_TransferModule = null;
54 private bool m_Enabled = false;
55 52
56 private string m_ThisGridURL; 53 private string m_ThisGridURL;
57 54
@@ -61,24 +58,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Lure
61 { 58 {
62 if (config.Configs["Messaging"] != null) 59 if (config.Configs["Messaging"] != null)
63 { 60 {
64 if (config.Configs["Messaging"].GetString("LureModule", string.Empty) == "HGLureModule") 61 m_ThisGridURL = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI", new string[] { "Startup", "Hypergrid", "Messaging" }, String.Empty);
65 { 62 // Legacy. Remove soon!
66 m_Enabled = true; 63//// m_ThisGridURL = config.Configs["Messaging"].GetString("Gatekeeper", m_ThisGridURL);
67 64 m_log.DebugFormat("[HG LURE MODULE]: {0} enabled", Name);
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 } 65 }
75 } 66 }
76 67
77 public void AddRegion(Scene scene) 68 public void AddRegion(Scene scene)
78 { 69 {
79 if (!m_Enabled)
80 return;
81
82 lock (m_scenes) 70 lock (m_scenes)
83 { 71 {
84 m_scenes.Add(scene); 72 m_scenes.Add(scene);
@@ -89,9 +77,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Lure
89 77
90 public void RegionLoaded(Scene scene) 78 public void RegionLoaded(Scene scene)
91 { 79 {
92 if (!m_Enabled)
93 return;
94
95 if (m_TransferModule == null) 80 if (m_TransferModule == null)
96 { 81 {
97 m_TransferModule = 82 m_TransferModule =
@@ -99,9 +84,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Lure
99 84
100 if (m_TransferModule == null) 85 if (m_TransferModule == null)
101 { 86 {
102 m_log.Error("[LURE MODULE]: No message transfer module, lures will not work!"); 87 m_log.Error("[HG LURE MODULE]: No message transfer module, lures will not work!");
103
104 m_Enabled = false;
105 m_scenes.Clear(); 88 m_scenes.Clear();
106 scene.EventManager.OnNewClient -= OnNewClient; 89 scene.EventManager.OnNewClient -= OnNewClient;
107 scene.EventManager.OnIncomingInstantMessage -= OnIncomingInstantMessage; 90 scene.EventManager.OnIncomingInstantMessage -= OnIncomingInstantMessage;
@@ -112,9 +95,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Lure
112 95
113 public void RemoveRegion(Scene scene) 96 public void RemoveRegion(Scene scene)
114 { 97 {
115 if (!m_Enabled)
116 return;
117
118 lock (m_scenes) 98 lock (m_scenes)
119 { 99 {
120 m_scenes.Remove(scene); 100 m_scenes.Remove(scene);
@@ -154,19 +134,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Lure
154 134
155 void OnIncomingInstantMessage(GridInstantMessage im) 135 void OnIncomingInstantMessage(GridInstantMessage im)
156 { 136 {
157 if (im.dialog == (byte)InstantMessageDialog.RequestTeleport 137 if (im.dialog == (byte)InstantMessageDialog.RequestTeleport || im.dialog == (byte)InstantMessageDialog.GodLikeRequestTeleport)
158 || im.dialog == (byte)InstantMessageDialog.GodLikeRequestTeleport)
159 { 138 {
160 UUID sessionID = new UUID(im.imSessionID); 139 UUID sessionID = new UUID(im.imSessionID);
161
162 if (!m_PendingLures.Contains(sessionID)) 140 if (!m_PendingLures.Contains(sessionID))
163 { 141 {
164 m_log.DebugFormat("[HG LURE MODULE]: RequestTeleport sessionID={0}, regionID={1}, message={2}", im.imSessionID, im.RegionID, im.message); 142 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 143 m_PendingLures.Add(sessionID, im, 7200); // 2 hours
166 } 144 }
167 145 // Forward. We do this, because the IM module explicitly rejects IMs of this type
168 // Forward. We do this, because the IM module explicitly rejects
169 // IMs of this type
170 if (m_TransferModule != null) 146 if (m_TransferModule != null)
171 m_TransferModule.SendInstantMessage(im, delegate(bool success) { }); 147 m_TransferModule.SendInstantMessage(im, delegate(bool success) { });
172 } 148 }
@@ -179,23 +155,34 @@ namespace OpenSim.Region.CoreModules.Avatar.Lure
179 155
180 Scene scene = (Scene)(client.Scene); 156 Scene scene = (Scene)(client.Scene);
181 ScenePresence presence = scene.GetScenePresence(client.AgentId); 157 ScenePresence presence = scene.GetScenePresence(client.AgentId);
158 ScenePresence target = scene.GetScenePresence(targetid);
159 Guid start = client.Scene.RegionInfo.RegionID.Guid;
160 UUID dest = UUID.Random();
161 byte reqType = (byte)InstantMessageDialog.RequestTeleport;
162 GridInstantMessage m;
182 163
183 message += "@" + m_ThisGridURL; 164 GridRegion region = scene.GridService.GetRegionByUUID(scene.RegionInfo.ScopeID, new UUID(start));
184 165 if (region != null)
185 m_log.DebugFormat("[HG LURE MODULE]: TP invite with message {0}", message); 166 {
186 167 if (scene.Permissions.IsAdministrator(client.AgentId) && presence.IsViewerUIGod && (!scene.Permissions.IsAdministrator(targetid)))
187 UUID sessionID = UUID.Random(); 168 {
169 reqType = (byte)InstantMessageDialog.GodLikeRequestTeleport;
170 m_log.DebugFormat("[HG LURE MODULE]: TP FORCE GOD LURE with message {0}, type {1}", message, lureType);
171 }
172 else
173 m_log.DebugFormat("[HG LURE MODULE]: TP lure with message {0}, type {1}", message, lureType);
174 }
175 else
176 {
177 m_log.DebugFormat("[HG LURE MODULE]: hypergrid TP lure with message {0}, type {1}", message, lureType);
178 message += "@" + m_ThisGridURL;
179 }
188 180
189 GridInstantMessage m = new GridInstantMessage(scene, client.AgentId, 181 m = new GridInstantMessage(scene, client.AgentId, client.FirstName+" "+client.LastName, targetid,
190 client.FirstName+" "+client.LastName, targetid, 182 reqType, false, message, dest, false, presence.AbsolutePosition, new Byte[0], true);
191 (byte)InstantMessageDialog.RequestTeleport, false, 183 m.RegionID = start;
192 message, sessionID, false, presence.AbsolutePosition, 184 m_PendingLures.Add(dest, m, 7200); // 2 hours
193 new Byte[0], true);
194 m.RegionID = client.Scene.RegionInfo.RegionID.Guid;
195 185
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) 186 if (m_TransferModule != null)
200 { 187 {
201 m_TransferModule.SendInstantMessage(m, 188 m_TransferModule.SendInstantMessage(m,
@@ -208,64 +195,56 @@ namespace OpenSim.Region.CoreModules.Avatar.Lure
208 if (!(client.Scene is Scene)) 195 if (!(client.Scene is Scene))
209 return; 196 return;
210 197
211// Scene scene = (Scene)(client.Scene); 198 Scene scene = (Scene)(client.Scene);
212
213 GridInstantMessage im = null; 199 GridInstantMessage im = null;
200
214 if (m_PendingLures.TryGetValue(lureID, out im)) 201 if (m_PendingLures.TryGetValue(lureID, out im))
215 { 202 {
203 im.Position = im.Position + new Vector3(0.5f, 0.5f, 2f);
216 m_PendingLures.Remove(lureID); 204 m_PendingLures.Remove(lureID);
217 Lure(client, teleportFlags, im); 205 GridRegion region = scene.GridService.GetRegionByUUID(scene.RegionInfo.ScopeID, new UUID(im.RegionID));
218 } 206 if (region != null)
219 else 207 scene.RequestTeleportLocation(client, region.RegionHandle, im.Position, Vector3.UnitX, teleportFlags);
220 m_log.DebugFormat("[HG LURE MODULE]: pending lure {0} not found", lureID); 208 else // we don't have that region here. Check if it's HG
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 { 209 {
235 string url = parts[parts.Length - 1]; // the last part 210 string[] parts = im.message.Split(new char[] { '@' });
236 if (url.Trim(new char[] {'/'}) != m_ThisGridURL.Trim(new char[] {'/'})) 211 if (parts.Length > 1)
237 { 212 {
238 m_log.DebugFormat("[HG LURE MODULE]: Luring agent to grid {0} region {1} position {2}", url, im.RegionID, im.Position); 213 string url = parts[parts.Length - 1]; // the last part
239 GatekeeperServiceConnector gConn = new GatekeeperServiceConnector(); 214 if (url.Trim(new char[] {'/'}) != m_ThisGridURL.Trim(new char[] {'/'}))
240 GridRegion gatekeeper = new GridRegion();
241 gatekeeper.ServerURI = url;
242 string homeURI = scene.GetAgentHomeURI(client.AgentId);
243
244 string message;
245 GridRegion finalDestination = gConn.GetHyperlinkRegion(gatekeeper, new UUID(im.RegionID), client.AgentId, homeURI, out message);
246 if (finalDestination != null)
247 { 215 {
248 ScenePresence sp = scene.GetScenePresence(client.AgentId); 216 m_log.DebugFormat("[HG LURE MODULE]: Luring agent to remote grid {0} region {1} position {2}", url, im.RegionID, im.Position);
249 IEntityTransferModule transferMod = scene.RequestModuleInterface<IEntityTransferModule>(); 217 GatekeeperServiceConnector gConn = new GatekeeperServiceConnector();
250 218 GridRegion gatekeeper = new GridRegion();
251 if (transferMod != null && sp != null) 219 gatekeeper.ServerURI = url;
220 string homeURI = scene.GetAgentHomeURI(client.AgentId);
221
222 string message;
223 GridRegion finalDestination = gConn.GetHyperlinkRegion(gatekeeper, new UUID(im.RegionID), client.AgentId, homeURI, out message);
224 if (finalDestination != null)
252 { 225 {
253 if (message != null) 226 ScenePresence sp = scene.GetScenePresence(client.AgentId);
254 sp.ControllingClient.SendAgentAlertMessage(message, true); 227 IEntityTransferModule transferMod = scene.RequestModuleInterface<IEntityTransferModule>();
228
229 if (transferMod != null && sp != null)
230 {
231 if (message != null)
232 sp.ControllingClient.SendAgentAlertMessage(message, true);
255 233
256 transferMod.DoTeleport( 234 transferMod.DoTeleport(sp, gatekeeper, finalDestination, im.Position, Vector3.UnitX, teleportFlags);
257 sp, gatekeeper, finalDestination, im.Position + new Vector3(0.5f, 0.5f, 0f), 235 }
258 Vector3.UnitX, teleportflags); 236 }
237 else
238 {
239 m_log.InfoFormat("[HG LURE MODULE]: Lure failed: {0}", message);
240 client.SendAgentAlertMessage(message, true);
259 } 241 }
260 }
261 else
262 {
263 m_log.InfoFormat("[HG LURE MODULE]: Lure failed: {0}", message);
264 client.SendAgentAlertMessage(message, true);
265 } 242 }
266 } 243 }
267 } 244 }
268 } 245 }
246 else
247 m_log.DebugFormat("[HG LURE MODULE]: pending lure {0} not found", lureID);
269 } 248 }
270 } 249 }
271} \ No newline at end of file 250}
diff --git a/OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs b/OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs
deleted file mode 100644
index 465ffbc..0000000
--- a/OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs
+++ /dev/null
@@ -1,220 +0,0 @@
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 Mono.Addins;
33using Nini.Config;
34using OpenMetaverse;
35using OpenSim.Framework;
36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes;
38
39namespace 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}