29 using System.Collections;
30 using System.Collections.Generic;
32 using System.Reflection;
38 using OpenSim.Framework;
39 using OpenSim.Framework.Servers;
40 using OpenSim.Region.Framework.Interfaces;
41 using OpenSim.Region.Framework.Scenes;
44 using OpenSim.Services.Interfaces;
45 using OpenSim.Services.Connectors.InstantMessage;
46 using OpenSim.Services.Connectors.Hypergrid;
47 using OpenSim.Server.Handlers.Hypergrid;
51 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"HGMessageTransferModule")]
54 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
56 protected bool m_Enabled =
false;
57 protected List<Scene> m_Scenes =
new List<Scene>();
60 protected Dictionary<UUID, object> m_UserLocationMap =
new Dictionary<UUID, object>();
77 IConfig cnf = config.Configs[
"Messaging"];
78 if (cnf != null && cnf.GetString(
79 "MessageTransferModule",
"MessageTransferModule") != Name)
81 m_log.Debug(
"[HG MESSAGE TRANSFER]: Disabled by configuration");
86 m_IMService = imServer.GetService();
97 m_log.DebugFormat(
"[HG MESSAGE TRANSFER]: Message transfer module {0} active", Name);
121 m_Scenes.Remove(scene);
129 public virtual string Name
131 get {
return "HGMessageTransferModule"; }
134 public virtual Type ReplaceableInterface
144 foreach (
Scene scene
in m_Scenes)
154 sp.ControllingClient.SendInstantMessage(im);
163 foreach (
Scene scene
in m_Scenes)
173 sp.ControllingClient.SendInstantMessage(im);
183 string url = string.Empty;
184 bool foreigner =
false;
185 if (UserManagementModule != null && !UserManagementModule.IsLocalGridUser(toAgentID))
187 url = UserManagementModule.GetUserServerURL(toAgentID,
"IMServerURI");
191 Util.FireAndForget(delegate
193 bool success =
false;
194 if (foreigner && url ==
string.Empty)
196 string recipientUUI = TryGetRecipientUUI(
new UUID(im.fromAgentID), toAgentID);
197 m_log.DebugFormat(
"[HG MESSAGE TRANSFER]: Got UUI {0}", recipientUUI);
198 if (recipientUUI !=
string.Empty)
200 UUID id;
string u = string.Empty, first = string.Empty, last = string.Empty, secret = string.Empty;
201 if (Util.ParseUniversalUserIdentifier(recipientUUI, out
id, out u, out first, out last, out secret))
203 success = m_IMService.OutgoingInstantMessage(im, u,
true);
205 UserManagementModule.AddUser(toAgentID, u +
";" + first +
" " + last);
210 success = m_IMService.OutgoingInstantMessage(im, url, foreigner);
212 if (!success && !foreigner)
213 HandleUndeliverableMessage(im, result);
216 }, null,
"HGMessageTransferModule.SendInstantMessage");
223 bool successful =
false;
224 foreach (
Scene scene
in m_Scenes)
229 scene.EventManager.TriggerIncomingInstantMessage(gim);
243 m_Scenes[0].EventManager.TriggerUnhandledInstantMessage(gim);
256 if (handlerUndeliveredMessage != null)
258 handlerUndeliveredMessage(im);
259 if (im.
dialog == (byte)InstantMessageDialog.MessageFromAgent)
270 private string TryGetRecipientUUI(UUID fromAgent, UUID toAgent)
274 IClientAPI client = LocateClientObject(fromAgent);
277 AgentCircuitData circuit = m_Scenes[0].AuthenticateHandler.GetAgentCircuitData(client.AgentId);
282 string uasURL = circuit.ServiceURLs[
"HomeURI"].ToString();
283 m_log.DebugFormat(
"[HG MESSAGE TRANSFER]: getting UUI of user {0} from {1}", toAgent, uasURL);
286 string agentUUI = string.Empty;
289 agentUUI = uasConn.GetUUI(fromAgent, toAgent);
291 catch (Exception e) {
292 m_log.Debug(
"[HG MESSAGE TRANSFER]: GetUUI call failed ", e);
310 foreach (
Scene scene
in m_Scenes)
314 return presence.ControllingClient;
321 #region IInstantMessageSimConnector
326 return SendIMToScene(im, agentID);
virtual void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
virtual void Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...
delegate void UndeliveredMessage(GridInstantMessage im)
bool SendInstantMessage(GridInstantMessage im)
OpenSim.Services.Interfaces.PresenceInfo PresenceInfo
void HandleUndeliverableMessage(GridInstantMessage im, MessageResultNotification result)
Appropriately handle a known undeliverable message without attempting a send.
delegate void MessageResultNotification(bool success)
IInstantMessage m_IMService
Dictionary< string, object > ServiceURLs
OpenSim.Services.Interfaces.GridRegion GridRegion
virtual void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
virtual void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
void SendInstantMessage(GridInstantMessage im, MessageResultNotification result)
Attempt to send an instant message to a given destination.
IClientAPI LocateClientObject(UUID agentID)
Find the root client for a ID
Circuit data for an agent. Connection information shared between regions that accept UDP connections ...
UndeliveredMessage OnUndeliveredMessage
bool SendIMToScene(GridInstantMessage gim, UUID toAgentID)
Interactive OpenSim region server
static BaseHttpServer Instance
Set the main HTTP server instance.
virtual void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
virtual void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
This maintains the relationship between a UUID and a user name.