UserServerEventDispatchModule.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Reflection;
  31. using log4net;
  32. using log4net.Config;
  33. using OpenMetaverse;
  34. using OpenSim.Data;
  35. using OpenSim.Framework;
  36. using OpenSim.Framework.Communications;
  37. using OpenSim.Framework.Communications.Cache;
  38. using OpenSim.Framework.Console;
  39. using OpenSim.Framework.Servers;
  40. using OpenSim.Framework.Servers.HttpServer;
  41. using OpenSim.Framework.Statistics;
  42. using OpenSim.Grid.Communications.OGS1;
  43. using OpenSim.Grid.Framework;
  44. using OpenSim.Grid.UserServer.Modules;
  45. namespace OpenSim.Grid.UserServer
  46. {
  47. //Do we actually need these event dispatchers?
  48. //shouldn't the other modules just directly register event handlers to each other?
  49. public class UserServerEventDispatchModule
  50. {
  51. protected UserManager m_userManager;
  52. protected MessageServersConnector m_messagesService;
  53. protected UserLoginService m_loginService;
  54. public UserServerEventDispatchModule(UserManager userManager, MessageServersConnector messagesService, UserLoginService loginService)
  55. {
  56. m_userManager = userManager;
  57. m_messagesService = messagesService;
  58. m_loginService = loginService;
  59. }
  60. public void Initialise(IGridServiceCore core)
  61. {
  62. }
  63. public void PostInitialise()
  64. {
  65. m_loginService.OnUserLoggedInAtLocation += NotifyMessageServersUserLoggedInToLocation;
  66. m_userManager.OnLogOffUser += NotifyMessageServersUserLoggOff;
  67. m_messagesService.OnAgentLocation += HandleAgentLocation;
  68. m_messagesService.OnAgentLeaving += HandleAgentLeaving;
  69. m_messagesService.OnRegionStartup += HandleRegionStartup;
  70. m_messagesService.OnRegionShutdown += HandleRegionShutdown;
  71. }
  72. public void RegisterHandlers(BaseHttpServer httpServer)
  73. {
  74. }
  75. public void Close()
  76. {
  77. m_loginService.OnUserLoggedInAtLocation -= NotifyMessageServersUserLoggedInToLocation;
  78. }
  79. #region Event Handlers
  80. public void NotifyMessageServersUserLoggOff(UUID agentID)
  81. {
  82. m_messagesService.TellMessageServersAboutUserLogoff(agentID);
  83. }
  84. public void NotifyMessageServersUserLoggedInToLocation(UUID agentID, UUID sessionID, UUID RegionID,
  85. ulong regionhandle, float positionX, float positionY,
  86. float positionZ, string firstname, string lastname)
  87. {
  88. m_messagesService.TellMessageServersAboutUser(agentID, sessionID, RegionID, regionhandle, positionX,
  89. positionY, positionZ, firstname, lastname);
  90. }
  91. public void HandleAgentLocation(UUID agentID, UUID regionID, ulong regionHandle)
  92. {
  93. m_userManager.HandleAgentLocation(agentID, regionID, regionHandle);
  94. }
  95. public void HandleAgentLeaving(UUID agentID, UUID regionID, ulong regionHandle)
  96. {
  97. m_userManager.HandleAgentLeaving(agentID, regionID, regionHandle);
  98. }
  99. public void HandleRegionStartup(UUID regionID)
  100. {
  101. // This might seem strange, that we send this back to the
  102. // server it came from. But there is method to the madness.
  103. // There can be multiple user servers on the same database,
  104. // and each can have multiple messaging servers. So, we send
  105. // it to all known user servers, who send it to all known
  106. // message servers. That way, we should be able to finally
  107. // update presence to all regions and thereby all friends
  108. //
  109. m_userManager.HandleRegionStartup(regionID);
  110. m_messagesService.TellMessageServersAboutRegionShutdown(regionID);
  111. }
  112. public void HandleRegionShutdown(UUID regionID)
  113. {
  114. // This might seem strange, that we send this back to the
  115. // server it came from. But there is method to the madness.
  116. // There can be multiple user servers on the same database,
  117. // and each can have multiple messaging servers. So, we send
  118. // it to all known user servers, who send it to all known
  119. // message servers. That way, we should be able to finally
  120. // update presence to all regions and thereby all friends
  121. //
  122. m_userManager.HandleRegionShutdown(regionID);
  123. m_messagesService.TellMessageServersAboutRegionShutdown(regionID);
  124. }
  125. #endregion
  126. }
  127. }