diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs | 117 |
1 files changed, 72 insertions, 45 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs index e5159b3..c0d3f31 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs | |||
@@ -37,21 +37,33 @@ using OpenSim.Framework; | |||
37 | using OpenSim.Region.Framework.Interfaces; | 37 | using OpenSim.Region.Framework.Interfaces; |
38 | using OpenSim.Region.Framework.Scenes; | 38 | using OpenSim.Region.Framework.Scenes; |
39 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | 39 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
40 | using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; | ||
41 | using OpenSim.Services.Interfaces; | ||
40 | 42 | ||
41 | namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | 43 | namespace OpenSim.Region.CoreModules.Avatar.InstantMessage |
42 | { | 44 | { |
43 | public class MessageTransferModule : IRegionModule, IMessageTransferModule | 45 | public class MessageTransferModule : ISharedRegionModule, IMessageTransferModule |
44 | { | 46 | { |
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
46 | 48 | ||
47 | // private bool m_Enabled = false; | 49 | private bool m_Enabled = false; |
48 | protected bool m_Gridmode = false; | ||
49 | protected List<Scene> m_Scenes = new List<Scene>(); | 50 | protected List<Scene> m_Scenes = new List<Scene>(); |
50 | protected Dictionary<UUID, ulong> m_UserRegionMap = new Dictionary<UUID, ulong>(); | 51 | protected Dictionary<UUID, UUID> m_UserRegionMap = new Dictionary<UUID, UUID>(); |
51 | 52 | ||
52 | public event UndeliveredMessage OnUndeliveredMessage; | 53 | public event UndeliveredMessage OnUndeliveredMessage; |
53 | 54 | ||
54 | public virtual void Initialise(Scene scene, IConfigSource config) | 55 | private IPresenceService m_PresenceService; |
56 | protected IPresenceService PresenceService | ||
57 | { | ||
58 | get | ||
59 | { | ||
60 | if (m_PresenceService == null) | ||
61 | m_PresenceService = m_Scenes[0].RequestModuleInterface<IPresenceService>(); | ||
62 | return m_PresenceService; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | public virtual void Initialise(IConfigSource config) | ||
55 | { | 67 | { |
56 | IConfig cnf = config.Configs["Messaging"]; | 68 | IConfig cnf = config.Configs["Messaging"]; |
57 | if (cnf != null && cnf.GetString( | 69 | if (cnf != null && cnf.GetString( |
@@ -62,20 +74,16 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
62 | return; | 74 | return; |
63 | } | 75 | } |
64 | 76 | ||
65 | cnf = config.Configs["Startup"]; | 77 | m_Enabled = true; |
66 | if (cnf != null) | 78 | } |
67 | m_Gridmode = cnf.GetBoolean("gridmode", false); | ||
68 | 79 | ||
69 | // m_Enabled = true; | 80 | public virtual void AddRegion(Scene scene) |
81 | { | ||
82 | if (!m_Enabled) | ||
83 | return; | ||
70 | 84 | ||
71 | lock (m_Scenes) | 85 | lock (m_Scenes) |
72 | { | 86 | { |
73 | if (m_Scenes.Count == 0) | ||
74 | { | ||
75 | MainServer.Instance.AddXmlRPCHandler( | ||
76 | "grid_instant_message", processXMLRPCGridInstantMessage); | ||
77 | } | ||
78 | |||
79 | m_log.Debug("[MESSAGE TRANSFER]: Message transfer module active"); | 87 | m_log.Debug("[MESSAGE TRANSFER]: Message transfer module active"); |
80 | scene.RegisterModuleInterface<IMessageTransferModule>(this); | 88 | scene.RegisterModuleInterface<IMessageTransferModule>(this); |
81 | m_Scenes.Add(scene); | 89 | m_Scenes.Add(scene); |
@@ -84,6 +92,26 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
84 | 92 | ||
85 | public virtual void PostInitialise() | 93 | public virtual void PostInitialise() |
86 | { | 94 | { |
95 | if (!m_Enabled) | ||
96 | return; | ||
97 | |||
98 | MainServer.Instance.AddXmlRPCHandler( | ||
99 | "grid_instant_message", processXMLRPCGridInstantMessage); | ||
100 | } | ||
101 | |||
102 | public virtual void RegionLoaded(Scene scene) | ||
103 | { | ||
104 | } | ||
105 | |||
106 | public virtual void RemoveRegion(Scene scene) | ||
107 | { | ||
108 | if (!m_Enabled) | ||
109 | return; | ||
110 | |||
111 | lock(m_Scenes) | ||
112 | { | ||
113 | m_Scenes.Remove(scene); | ||
114 | } | ||
87 | } | 115 | } |
88 | 116 | ||
89 | public virtual void Close() | 117 | public virtual void Close() |
@@ -95,9 +123,9 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
95 | get { return "MessageTransferModule"; } | 123 | get { return "MessageTransferModule"; } |
96 | } | 124 | } |
97 | 125 | ||
98 | public virtual bool IsSharedModule | 126 | public virtual Type ReplaceableInterface |
99 | { | 127 | { |
100 | get { return true; } | 128 | get { return null; } |
101 | } | 129 | } |
102 | 130 | ||
103 | public virtual void SendInstantMessage(GridInstantMessage im, MessageResultNotification result) | 131 | public virtual void SendInstantMessage(GridInstantMessage im, MessageResultNotification result) |
@@ -148,15 +176,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
148 | } | 176 | } |
149 | } | 177 | } |
150 | 178 | ||
151 | if (m_Gridmode) | 179 | SendGridInstantMessageViaXMLRPC(im, result); |
152 | { | ||
153 | //m_log.DebugFormat("[INSTANT MESSAGE]: Delivering via grid"); | ||
154 | // Still here, try send via Grid | ||
155 | SendGridInstantMessageViaXMLRPC(im, result); | ||
156 | return; | ||
157 | } | ||
158 | |||
159 | HandleUndeliveredMessage(im, result); | ||
160 | 180 | ||
161 | return; | 181 | return; |
162 | } | 182 | } |
@@ -409,7 +429,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
409 | /// <summary> | 429 | /// <summary> |
410 | /// delegate for sending a grid instant message asynchronously | 430 | /// delegate for sending a grid instant message asynchronously |
411 | /// </summary> | 431 | /// </summary> |
412 | public delegate void GridInstantMessageDelegate(GridInstantMessage im, MessageResultNotification result, ulong prevRegionHandle); | 432 | public delegate void GridInstantMessageDelegate(GridInstantMessage im, MessageResultNotification result, UUID prevRegionID); |
413 | 433 | ||
414 | protected virtual void GridInstantMessageCompleted(IAsyncResult iar) | 434 | protected virtual void GridInstantMessageCompleted(IAsyncResult iar) |
415 | { | 435 | { |
@@ -423,7 +443,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
423 | { | 443 | { |
424 | GridInstantMessageDelegate d = SendGridInstantMessageViaXMLRPCAsync; | 444 | GridInstantMessageDelegate d = SendGridInstantMessageViaXMLRPCAsync; |
425 | 445 | ||
426 | d.BeginInvoke(im, result, 0, GridInstantMessageCompleted, d); | 446 | d.BeginInvoke(im, result, UUID.Zero, GridInstantMessageCompleted, d); |
427 | } | 447 | } |
428 | 448 | ||
429 | /// <summary> | 449 | /// <summary> |
@@ -438,11 +458,11 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
438 | /// Pass in 0 the first time this method is called. It will be called recursively with the last | 458 | /// Pass in 0 the first time this method is called. It will be called recursively with the last |
439 | /// regionhandle tried | 459 | /// regionhandle tried |
440 | /// </param> | 460 | /// </param> |
441 | protected virtual void SendGridInstantMessageViaXMLRPCAsync(GridInstantMessage im, MessageResultNotification result, ulong prevRegionHandle) | 461 | protected virtual void SendGridInstantMessageViaXMLRPCAsync(GridInstantMessage im, MessageResultNotification result, UUID prevRegionID) |
442 | { | 462 | { |
443 | UUID toAgentID = new UUID(im.toAgentID); | 463 | UUID toAgentID = new UUID(im.toAgentID); |
444 | 464 | ||
445 | UserAgentData upd = null; | 465 | PresenceInfo upd = null; |
446 | 466 | ||
447 | bool lookupAgent = false; | 467 | bool lookupAgent = false; |
448 | 468 | ||
@@ -450,13 +470,13 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
450 | { | 470 | { |
451 | if (m_UserRegionMap.ContainsKey(toAgentID)) | 471 | if (m_UserRegionMap.ContainsKey(toAgentID)) |
452 | { | 472 | { |
453 | upd = new UserAgentData(); | 473 | upd = new PresenceInfo(); |
454 | upd.AgentOnline = true; | 474 | upd.Online = true; |
455 | upd.Handle = m_UserRegionMap[toAgentID]; | 475 | upd.RegionID = m_UserRegionMap[toAgentID]; |
456 | 476 | ||
457 | // We need to compare the current regionhandle with the previous region handle | 477 | // We need to compare the current regionhandle with the previous region handle |
458 | // or the recursive loop will never end because it will never try to lookup the agent again | 478 | // or the recursive loop will never end because it will never try to lookup the agent again |
459 | if (prevRegionHandle == upd.Handle) | 479 | if (prevRegionID == upd.RegionID) |
460 | { | 480 | { |
461 | lookupAgent = true; | 481 | lookupAgent = true; |
462 | } | 482 | } |
@@ -472,14 +492,23 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
472 | if (lookupAgent) | 492 | if (lookupAgent) |
473 | { | 493 | { |
474 | // Non-cached user agent lookup. | 494 | // Non-cached user agent lookup. |
475 | upd = m_Scenes[0].CommsManager.UserService.GetAgentByUUID(toAgentID); | 495 | PresenceInfo[] presences = PresenceService.GetAgents(new string[] { toAgentID.ToString() }); |
496 | if (presences != null) | ||
497 | { | ||
498 | foreach (PresenceInfo p in presences) | ||
499 | if (p.Online) | ||
500 | { | ||
501 | upd = presences[0]; | ||
502 | break; | ||
503 | } | ||
504 | } | ||
476 | 505 | ||
477 | if (upd != null) | 506 | if (upd != null) |
478 | { | 507 | { |
479 | // check if we've tried this before.. | 508 | // check if we've tried this before.. |
480 | // This is one way to end the recursive loop | 509 | // This is one way to end the recursive loop |
481 | // | 510 | // |
482 | if (upd.Handle == prevRegionHandle) | 511 | if (upd.RegionID == prevRegionID) |
483 | { | 512 | { |
484 | m_log.Error("[GRID INSTANT MESSAGE]: Unable to deliver an instant message"); | 513 | m_log.Error("[GRID INSTANT MESSAGE]: Unable to deliver an instant message"); |
485 | HandleUndeliveredMessage(im, result); | 514 | HandleUndeliveredMessage(im, result); |
@@ -496,12 +525,10 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
496 | 525 | ||
497 | if (upd != null) | 526 | if (upd != null) |
498 | { | 527 | { |
499 | if (upd.AgentOnline) | 528 | if (upd.Online) |
500 | { | 529 | { |
501 | uint x = 0, y = 0; | 530 | GridRegion reginfo = m_Scenes[0].GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, |
502 | Utils.LongToUInts(upd.Handle, out x, out y); | 531 | upd.RegionID); |
503 | GridRegion reginfo = m_Scenes[0].GridService.GetRegionByPosition(m_Scenes[0].RegionInfo.ScopeID, | ||
504 | (int)x, (int)y); | ||
505 | if (reginfo != null) | 532 | if (reginfo != null) |
506 | { | 533 | { |
507 | Hashtable msgdata = ConvertGridInstantMessageToXMLRPC(im); | 534 | Hashtable msgdata = ConvertGridInstantMessageToXMLRPC(im); |
@@ -517,11 +544,11 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
517 | { | 544 | { |
518 | if (m_UserRegionMap.ContainsKey(toAgentID)) | 545 | if (m_UserRegionMap.ContainsKey(toAgentID)) |
519 | { | 546 | { |
520 | m_UserRegionMap[toAgentID] = upd.Handle; | 547 | m_UserRegionMap[toAgentID] = upd.RegionID; |
521 | } | 548 | } |
522 | else | 549 | else |
523 | { | 550 | { |
524 | m_UserRegionMap.Add(toAgentID, upd.Handle); | 551 | m_UserRegionMap.Add(toAgentID, upd.RegionID); |
525 | } | 552 | } |
526 | } | 553 | } |
527 | result(true); | 554 | result(true); |
@@ -536,12 +563,12 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
536 | 563 | ||
537 | // This is recursive!!!!! | 564 | // This is recursive!!!!! |
538 | SendGridInstantMessageViaXMLRPCAsync(im, result, | 565 | SendGridInstantMessageViaXMLRPCAsync(im, result, |
539 | upd.Handle); | 566 | upd.RegionID); |
540 | } | 567 | } |
541 | } | 568 | } |
542 | else | 569 | else |
543 | { | 570 | { |
544 | m_log.WarnFormat("[GRID INSTANT MESSAGE]: Unable to find region {0}", upd.Handle); | 571 | m_log.WarnFormat("[GRID INSTANT MESSAGE]: Unable to find region {0}", upd.RegionID); |
545 | HandleUndeliveredMessage(im, result); | 572 | HandleUndeliveredMessage(im, result); |
546 | } | 573 | } |
547 | } | 574 | } |