RemoteGridUserServiceConnector.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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.Reflection;
  30. using OpenSim.Region.Framework.Interfaces;
  31. using OpenSim.Region.Framework.Scenes;
  32. using OpenSim.Server.Base;
  33. using OpenSim.Services.Interfaces;
  34. using OpenSim.Services.Connectors;
  35. using OpenMetaverse;
  36. using log4net;
  37. using Mono.Addins;
  38. using Nini.Config;
  39. namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser
  40. {
  41. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RemoteGridUserServicesConnector")]
  42. public class RemoteGridUserServicesConnector : ISharedRegionModule, IGridUserService
  43. {
  44. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  45. private const int KEEPTIME = 30; // 30 secs
  46. private ExpiringCache<string, GridUserInfo> m_Infos = new ExpiringCache<string, GridUserInfo>();
  47. #region ISharedRegionModule
  48. private bool m_Enabled = false;
  49. private ActivityDetector m_ActivityDetector;
  50. private IGridUserService m_RemoteConnector;
  51. public Type ReplaceableInterface
  52. {
  53. get { return null; }
  54. }
  55. public string Name
  56. {
  57. get { return "RemoteGridUserServicesConnector"; }
  58. }
  59. public void Initialise(IConfigSource source)
  60. {
  61. IConfig moduleConfig = source.Configs["Modules"];
  62. if (moduleConfig != null)
  63. {
  64. string name = moduleConfig.GetString("GridUserServices", "");
  65. if (name == Name)
  66. {
  67. m_RemoteConnector = new GridUserServicesConnector(source);
  68. m_Enabled = true;
  69. m_ActivityDetector = new ActivityDetector(this);
  70. m_log.Info("[REMOTE GRID USER CONNECTOR]: Remote grid user enabled");
  71. }
  72. }
  73. }
  74. public void PostInitialise()
  75. {
  76. }
  77. public void Close()
  78. {
  79. }
  80. public void AddRegion(Scene scene)
  81. {
  82. if (!m_Enabled)
  83. return;
  84. scene.RegisterModuleInterface<IGridUserService>(this);
  85. m_ActivityDetector.AddRegion(scene);
  86. m_log.InfoFormat("[REMOTE GRID USER CONNECTOR]: Enabled remote grid user for region {0}", scene.RegionInfo.RegionName);
  87. }
  88. public void RemoveRegion(Scene scene)
  89. {
  90. if (!m_Enabled)
  91. return;
  92. m_ActivityDetector.RemoveRegion(scene);
  93. }
  94. public void RegionLoaded(Scene scene)
  95. {
  96. if (!m_Enabled)
  97. return;
  98. }
  99. #endregion
  100. #region IGridUserService
  101. public GridUserInfo LoggedIn(string userID)
  102. {
  103. m_log.Warn("[REMOTE GRID USER CONNECTOR]: LoggedIn not implemented at the simulators");
  104. return null;
  105. }
  106. public bool LoggedOut(string userID, UUID sessionID, UUID region, Vector3 position, Vector3 lookat)
  107. {
  108. if (m_Infos.Contains(userID))
  109. m_Infos.Remove(userID);
  110. return m_RemoteConnector.LoggedOut(userID, sessionID, region, position, lookat);
  111. }
  112. public bool SetHome(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
  113. {
  114. if (m_RemoteConnector.SetHome(userID, regionID, position, lookAt))
  115. {
  116. // Update the cache too
  117. GridUserInfo info = null;
  118. if (m_Infos.TryGetValue(userID, out info))
  119. {
  120. info.HomeRegionID = regionID;
  121. info.HomePosition = position;
  122. info.HomeLookAt = lookAt;
  123. }
  124. return true;
  125. }
  126. return false;
  127. }
  128. public bool SetLastPosition(string userID, UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt)
  129. {
  130. if (m_RemoteConnector.SetLastPosition(userID, sessionID, regionID, position, lookAt))
  131. {
  132. // Update the cache too
  133. GridUserInfo info = null;
  134. if (m_Infos.TryGetValue(userID, out info))
  135. {
  136. info.LastRegionID = regionID;
  137. info.LastPosition = position;
  138. info.LastLookAt = lookAt;
  139. }
  140. return true;
  141. }
  142. return false;
  143. }
  144. public GridUserInfo GetGridUserInfo(string userID)
  145. {
  146. GridUserInfo info = null;
  147. if (m_Infos.TryGetValue(userID, out info))
  148. return info;
  149. info = m_RemoteConnector.GetGridUserInfo(userID);
  150. m_Infos.AddOrUpdate(userID, info, KEEPTIME);
  151. return info;
  152. }
  153. public GridUserInfo[] GetGridUserInfo(string[] userID)
  154. {
  155. return m_RemoteConnector.GetGridUserInfo(userID);
  156. }
  157. #endregion
  158. }
  159. }