RemoteGridUserServiceConnector.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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.Framework;
  31. using OpenSim.Region.Framework.Interfaces;
  32. using OpenSim.Region.Framework.Scenes;
  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 ExpiringCacheOS<string, GridUserInfo> m_Infos = new ExpiringCacheOS<string, GridUserInfo>(10000);
  47. ~RemoteGridUserServicesConnector()
  48. {
  49. Dispose(false);
  50. }
  51. public void Dispose()
  52. {
  53. Dispose(true);
  54. GC.SuppressFinalize(this);
  55. }
  56. private bool disposed = false;
  57. private void Dispose(bool disposing)
  58. {
  59. if (!disposed)
  60. {
  61. disposed = true;
  62. m_Infos.Dispose();
  63. }
  64. }
  65. #region ISharedRegionModule
  66. private bool m_Enabled = false;
  67. private ActivityDetector m_ActivityDetector;
  68. private IGridUserService m_RemoteConnector;
  69. public Type ReplaceableInterface
  70. {
  71. get { return null; }
  72. }
  73. public string Name
  74. {
  75. get { return "RemoteGridUserServicesConnector"; }
  76. }
  77. public void Initialise(IConfigSource source)
  78. {
  79. IConfig moduleConfig = source.Configs["Modules"];
  80. if (moduleConfig != null)
  81. {
  82. string name = moduleConfig.GetString("GridUserServices", "");
  83. if (name == Name)
  84. {
  85. m_RemoteConnector = new GridUserServicesConnector(source);
  86. m_Enabled = true;
  87. m_ActivityDetector = new ActivityDetector(this);
  88. m_log.Info("[REMOTE GRID USER CONNECTOR]: Remote grid user enabled");
  89. }
  90. }
  91. }
  92. public void PostInitialise()
  93. {
  94. }
  95. public void Close()
  96. {
  97. }
  98. public void AddRegion(Scene scene)
  99. {
  100. if (!m_Enabled)
  101. return;
  102. scene.RegisterModuleInterface<IGridUserService>(this);
  103. m_ActivityDetector.AddRegion(scene);
  104. m_log.InfoFormat("[REMOTE GRID USER CONNECTOR]: Enabled remote grid user for region {0}", scene.RegionInfo.RegionName);
  105. }
  106. public void RemoveRegion(Scene scene)
  107. {
  108. if (!m_Enabled)
  109. return;
  110. m_ActivityDetector.RemoveRegion(scene);
  111. }
  112. public void RegionLoaded(Scene scene)
  113. {
  114. if (!m_Enabled)
  115. return;
  116. }
  117. #endregion
  118. #region IGridUserService
  119. public GridUserInfo LoggedIn(string userID)
  120. {
  121. m_log.Warn("[REMOTE GRID USER CONNECTOR]: LoggedIn not implemented at the simulators");
  122. return null;
  123. }
  124. public bool LoggedOut(string userID, UUID sessionID, UUID region, Vector3 position, Vector3 lookat)
  125. {
  126. m_Infos.Remove(userID);
  127. return m_RemoteConnector.LoggedOut(userID, sessionID, region, position, lookat);
  128. }
  129. public bool SetHome(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
  130. {
  131. if (m_RemoteConnector.SetHome(userID, regionID, position, lookAt))
  132. {
  133. if (m_Infos.TryGetValue(userID, KEEPTIME * 1000, out GridUserInfo info))
  134. {
  135. info.HomeRegionID = regionID;
  136. info.HomePosition = position;
  137. info.HomeLookAt = lookAt;
  138. }
  139. return true;
  140. }
  141. return false;
  142. }
  143. public bool SetLastPosition(string userID, UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt)
  144. {
  145. if (m_RemoteConnector.SetLastPosition(userID, sessionID, regionID, position, lookAt))
  146. {
  147. if (m_Infos.TryGetValue(userID, KEEPTIME * 1000, out GridUserInfo info))
  148. {
  149. info.LastRegionID = regionID;
  150. info.LastPosition = position;
  151. info.LastLookAt = lookAt;
  152. }
  153. return true;
  154. }
  155. return false;
  156. }
  157. public GridUserInfo GetGridUserInfo(string userID)
  158. {
  159. if (m_Infos.TryGetValue(userID, KEEPTIME * 1000, out GridUserInfo info))
  160. return info;
  161. info = m_RemoteConnector.GetGridUserInfo(userID);
  162. m_Infos.AddOrUpdate(userID, info, KEEPTIME);
  163. return info;
  164. }
  165. public GridUserInfo[] GetGridUserInfo(string[] userID)
  166. {
  167. return m_RemoteConnector.GetGridUserInfo(userID);
  168. }
  169. #endregion
  170. }
  171. }