RemoteUserAccountServiceConnector.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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;
  29. using System.Collections.Generic;
  30. using Nini.Config;
  31. using log4net;
  32. using Mono.Addins;
  33. using System.Reflection;
  34. using OpenSim.Region.Framework.Interfaces;
  35. using OpenSim.Region.Framework.Scenes;
  36. using OpenSim.Services.Interfaces;
  37. using OpenSim.Services.Connectors;
  38. using OpenSim.Framework;
  39. using OpenMetaverse;
  40. namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
  41. {
  42. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RemoteUserAccountServicesConnector")]
  43. public class RemoteUserAccountServicesConnector : UserAccountServicesConnector,
  44. ISharedRegionModule, IUserAccountService
  45. {
  46. private static readonly ILog m_log =
  47. LogManager.GetLogger(
  48. MethodBase.GetCurrentMethod().DeclaringType);
  49. private bool m_Enabled = false;
  50. private UserAccountCache m_Cache;
  51. public Type ReplaceableInterface
  52. {
  53. get { return null; }
  54. }
  55. public string Name
  56. {
  57. get { return "RemoteUserAccountServicesConnector"; }
  58. }
  59. public override void Initialise(IConfigSource source)
  60. {
  61. IConfig moduleConfig = source.Configs["Modules"];
  62. if (moduleConfig != null)
  63. {
  64. string name = moduleConfig.GetString("UserAccountServices", "");
  65. if (name == Name)
  66. {
  67. IConfig userConfig = source.Configs["UserAccountService"];
  68. if (userConfig == null)
  69. {
  70. m_log.Error("[USER CONNECTOR]: UserAccountService missing from OpenSim.ini");
  71. return;
  72. }
  73. m_Enabled = true;
  74. base.Initialise(source);
  75. m_Cache = new UserAccountCache();
  76. m_log.Info("[USER CONNECTOR]: Remote users enabled");
  77. }
  78. }
  79. }
  80. public void PostInitialise()
  81. {
  82. if (!m_Enabled)
  83. return;
  84. }
  85. public void Close()
  86. {
  87. if (!m_Enabled)
  88. return;
  89. }
  90. public void AddRegion(Scene scene)
  91. {
  92. if (!m_Enabled)
  93. return;
  94. scene.RegisterModuleInterface<IUserAccountService>(this);
  95. scene.RegisterModuleInterface<IUserAccountCacheModule>(m_Cache);
  96. scene.EventManager.OnNewClient += OnNewClient;
  97. }
  98. public void RemoveRegion(Scene scene)
  99. {
  100. if (!m_Enabled)
  101. return;
  102. }
  103. public void RegionLoaded(Scene scene)
  104. {
  105. if (!m_Enabled)
  106. return;
  107. }
  108. // When a user actually enters the sim, clear them from
  109. // cache so the sim will have the current values for
  110. // flags, title, etc. And country, don't forget country!
  111. private void OnNewClient(IClientAPI client)
  112. {
  113. m_Cache.Remove(client.Name);
  114. }
  115. #region Overwritten methods from IUserAccountService
  116. public override UserAccount GetUserAccount(UUID scopeID, UUID userID)
  117. {
  118. bool inCache = false;
  119. UserAccount account;
  120. account = m_Cache.Get(userID, out inCache);
  121. if (inCache)
  122. return account;
  123. account = base.GetUserAccount(scopeID, userID);
  124. m_Cache.Cache(userID, account);
  125. return account;
  126. }
  127. public override UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
  128. {
  129. bool inCache = false;
  130. UserAccount account;
  131. account = m_Cache.Get(firstName + " " + lastName, out inCache);
  132. if (inCache)
  133. return account;
  134. account = base.GetUserAccount(scopeID, firstName, lastName);
  135. if (account != null)
  136. m_Cache.Cache(account.PrincipalID, account);
  137. return account;
  138. }
  139. public override List<UserAccount> GetUserAccounts(UUID scopeID, List<string> IDs)
  140. {
  141. List<UserAccount> accs = new List<UserAccount>();
  142. List<string> missing = new List<string>();
  143. UUID uuid = UUID.Zero;
  144. UserAccount account;
  145. bool inCache = false;
  146. foreach(string id in IDs)
  147. {
  148. if(UUID.TryParse(id, out uuid))
  149. {
  150. account = m_Cache.Get(uuid, out inCache);
  151. if (inCache)
  152. accs.Add(account);
  153. else
  154. missing.Add(id);
  155. }
  156. }
  157. if(missing.Count > 0)
  158. {
  159. List<UserAccount> ext = base.GetUserAccounts(scopeID, missing);
  160. if(ext != null && ext.Count >0 )
  161. {
  162. foreach(UserAccount acc in ext)
  163. {
  164. if(acc != null)
  165. {
  166. accs.Add(acc);
  167. m_Cache.Cache(acc.PrincipalID, acc);
  168. }
  169. }
  170. }
  171. }
  172. return accs;
  173. }
  174. public override bool StoreUserAccount(UserAccount data)
  175. {
  176. // This remote connector refuses to serve this method
  177. return false;
  178. }
  179. #endregion
  180. }
  181. }