RemoteUserAccountServiceConnector.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 Nini.Config;
  29. using log4net;
  30. using System.Reflection;
  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. namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
  37. {
  38. public class RemoteUserAccountServicesConnector : UserAccountServicesConnector,
  39. ISharedRegionModule, IUserAccountService
  40. {
  41. private static readonly ILog m_log =
  42. LogManager.GetLogger(
  43. MethodBase.GetCurrentMethod().DeclaringType);
  44. private bool m_Enabled = false;
  45. private UserAccountCache m_Cache;
  46. public Type ReplaceableInterface
  47. {
  48. get { return null; }
  49. }
  50. public string Name
  51. {
  52. get { return "RemoteUserAccountServicesConnector"; }
  53. }
  54. public override void Initialise(IConfigSource source)
  55. {
  56. IConfig moduleConfig = source.Configs["Modules"];
  57. if (moduleConfig != null)
  58. {
  59. string name = moduleConfig.GetString("UserAccountServices", "");
  60. if (name == Name)
  61. {
  62. IConfig userConfig = source.Configs["UserAccountService"];
  63. if (userConfig == null)
  64. {
  65. m_log.Error("[USER CONNECTOR]: UserAccountService missing from OpenSim.ini");
  66. return;
  67. }
  68. m_Enabled = true;
  69. base.Initialise(source);
  70. m_Cache = new UserAccountCache();
  71. m_log.Info("[USER CONNECTOR]: Remote users enabled");
  72. }
  73. }
  74. }
  75. public void PostInitialise()
  76. {
  77. if (!m_Enabled)
  78. return;
  79. }
  80. public void Close()
  81. {
  82. if (!m_Enabled)
  83. return;
  84. }
  85. public void AddRegion(Scene scene)
  86. {
  87. if (!m_Enabled)
  88. return;
  89. scene.RegisterModuleInterface<IUserAccountService>(this);
  90. }
  91. public void RemoveRegion(Scene scene)
  92. {
  93. if (!m_Enabled)
  94. return;
  95. }
  96. public void RegionLoaded(Scene scene)
  97. {
  98. if (!m_Enabled)
  99. return;
  100. }
  101. #region Overwritten methods from IUserAccountService
  102. public override UserAccount GetUserAccount(UUID scopeID, UUID userID)
  103. {
  104. bool inCache = false;
  105. UserAccount account = m_Cache.Get(userID, out inCache);
  106. if (inCache)
  107. return account;
  108. account = base.GetUserAccount(scopeID, userID);
  109. m_Cache.Cache(userID, account);
  110. return account;
  111. }
  112. public override UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
  113. {
  114. bool inCache = false;
  115. UserAccount account = m_Cache.Get(firstName + " " + lastName, out inCache);
  116. if (inCache)
  117. return account;
  118. account = base.GetUserAccount(scopeID, firstName, lastName);
  119. if (account != null)
  120. m_Cache.Cache(account.PrincipalID, account);
  121. return account;
  122. }
  123. public override bool StoreUserAccount(UserAccount data)
  124. {
  125. // This remote connector refuses to serve this method
  126. return false;
  127. }
  128. #endregion
  129. }
  130. }