29 using System.Collections.Generic;
30 using System.Reflection;
36 using OpenSim.Framework;
37 using OpenSim.Region.Framework.Interfaces;
38 using OpenSim.Region.Framework.Scenes;
39 using OpenSim.Services.Connectors.Hypergrid;
45 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"HGLureModule")]
48 private static readonly ILog m_log = LogManager.GetLogger(
49 MethodBase.GetCurrentMethod().DeclaringType);
51 private readonly List<Scene> m_scenes =
new List<Scene>();
54 private bool m_Enabled =
false;
56 private string m_ThisGridURL;
58 private ExpiringCache<UUID, GridInstantMessage> m_PendingLures =
new ExpiringCache<UUID, GridInstantMessage>();
62 if (config.Configs[
"Messaging"] != null)
64 if (config.Configs[
"Messaging"].GetString(
"LureModule",
string.Empty) ==
"HGLureModule")
68 m_ThisGridURL = Util.GetConfigVarFromSections<
string>(config,
"GatekeeperURI",
69 new string[] {
"Startup",
"Hypergrid",
"Messaging" }, String.Empty);
71 m_ThisGridURL = config.Configs[
"Messaging"].GetString(
"Gatekeeper", m_ThisGridURL);
72 m_log.DebugFormat(
"[LURE MODULE]: {0} enabled", Name);
85 scene.EventManager.OnIncomingInstantMessage += OnIncomingInstantMessage;
86 scene.EventManager.OnNewClient += OnNewClient;
95 if (m_TransferModule == null)
100 if (m_TransferModule == null)
102 m_log.Error(
"[LURE MODULE]: No message transfer module, lures will not work!");
106 scene.EventManager.OnNewClient -= OnNewClient;
107 scene.EventManager.OnIncomingInstantMessage -= OnIncomingInstantMessage;
120 m_scenes.Remove(scene);
121 scene.EventManager.OnNewClient -= OnNewClient;
122 scene.EventManager.OnIncomingInstantMessage -= OnIncomingInstantMessage;
128 client.OnInstantMessage += OnInstantMessage;
129 client.OnStartLure += OnStartLure;
130 client.OnTeleportLureRequest += OnTeleportLureRequest;
143 get {
return "HGLureModule"; }
146 public Type ReplaceableInterface
157 if (im.
dialog == (byte)InstantMessageDialog.RequestTeleport
158 || im.
dialog == (byte)InstantMessageDialog.GodLikeRequestTeleport)
162 if (!m_PendingLures.Contains(sessionID))
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);
170 if (m_TransferModule != null)
171 m_TransferModule.SendInstantMessage(im, delegate(
bool success) { });
180 Scene scene = (Scene)(client.
Scene);
181 ScenePresence presence = scene.GetScenePresence(client.AgentId);
183 message +=
"@" + m_ThisGridURL;
185 m_log.DebugFormat(
"[HG LURE MODULE]: TP invite with message {0}", message);
187 UUID sessionID = UUID.Random();
191 (byte)InstantMessageDialog.RequestTeleport,
false,
194 m.RegionID = client.Scene.RegionInfo.RegionID.Guid;
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);
199 if (m_TransferModule != null)
201 m_TransferModule.SendInstantMessage(m,
202 delegate(
bool success) { });
214 if (m_PendingLures.TryGetValue(lureID, out im))
216 m_PendingLures.Remove(lureID);
217 Lure(client, teleportFlags, im);
220 m_log.DebugFormat(
"[HG LURE MODULE]: pending lure {0} not found", lureID);
229 scene.RequestTeleportLocation(client, region.RegionHandle, im.Position +
new Vector3(0.5f, 0.5f, 0f), Vector3.UnitX, teleportflags);
232 string[] parts = im.message.Split(
new char[] {
'@' });
233 if (parts.Length > 1)
235 string url = parts[parts.Length - 1];
236 if (url.Trim(
new char[] {
'/'}) != m_ThisGridURL.Trim(
new char[] {
'/'}))
238 m_log.DebugFormat(
"[HG LURE MODULE]: Luring agent to grid {0} region {1} position {2}", url, im.RegionID, im.Position);
241 gatekeeper.ServerURI = url;
242 string homeURI = scene.GetAgentHomeURI(client.AgentId);
245 GridRegion finalDestination = gConn.GetHyperlinkRegion(gatekeeper,
new UUID(im.
RegionID), client.AgentId, homeURI, out message);
246 if (finalDestination != null)
251 if (transferMod != null && sp != null)
254 sp.ControllingClient.SendAgentAlertMessage(message,
true);
256 transferMod.DoTeleport(
257 sp, gatekeeper, finalDestination, im.Position +
new Vector3(0.5f, 0.5f, 0f),
258 Vector3.UnitX, teleportflags);
263 m_log.InfoFormat(
"[HG LURE MODULE]: Lure failed: {0}", message);
264 client.SendAgentAlertMessage(message,
true);
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
void OnTeleportLureRequest(UUID lureID, uint teleportFlags, IClientAPI client)
void OnStartLure(byte lureType, string message, UUID targetid, IClientAPI client)
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
override Vector3 AbsolutePosition
Position of this avatar relative to the region the avatar is in
Interactive OpenSim region server
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
OpenSim.Services.Interfaces.GridRegion GridRegion
void Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...
OpenSim.Services.Interfaces.GridRegion GridRegion