HGUserManagementModule.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 OpenSim.Framework;
  32. using OpenSim.Framework.Console;
  33. using OpenSim.Region.Framework;
  34. using OpenSim.Region.Framework.Interfaces;
  35. using OpenSim.Region.Framework.Scenes;
  36. using OpenSim.Services.Interfaces;
  37. using OpenSim.Services.Connectors.Hypergrid;
  38. using OpenMetaverse;
  39. using OpenMetaverse.Packets;
  40. using log4net;
  41. using Nini.Config;
  42. using Mono.Addins;
  43. namespace OpenSim.Region.CoreModules.Framework.UserManagement
  44. {
  45. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "HGUserManagementModule")]
  46. public class HGUserManagementModule : UserManagementModule, ISharedRegionModule, IUserManagement
  47. {
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. #region ISharedRegionModule
  50. public override void Initialise(IConfigSource config)
  51. {
  52. string umanmod = config.Configs["Modules"].GetString("UserManagementModule", null);
  53. if (umanmod == Name)
  54. {
  55. m_Enabled = true;
  56. base.Init(config);
  57. m_log.DebugFormat("[USER MANAGEMENT MODULE]: {0} is enabled", Name);
  58. }
  59. }
  60. public override string Name
  61. {
  62. get { return "HGUserManagementModule"; }
  63. }
  64. #endregion ISharedRegionModule
  65. protected override void AddAdditionalUsers(string query, List<UserData> users, HashSet<UUID> found)
  66. {
  67. if (query.Contains("@")) // [email protected], maybe?
  68. {
  69. string[] words = query.Split(new char[] { '@' });
  70. if (words.Length != 2)
  71. {
  72. m_log.DebugFormat("[USER MANAGEMENT MODULE]: Malformed address {0}", query);
  73. return;
  74. }
  75. words[0] = words[0].Trim(); // it has at least 1
  76. words[1] = words[1].Trim().ToLower();
  77. string match1 = "@" + words[1];
  78. if (String.IsNullOrWhiteSpace(words[0])) // query was @foo.com?
  79. {
  80. foreach (UserData d in m_userCacheByID.Values)
  81. {
  82. if(found.Contains(d.Id))
  83. continue;
  84. if (d.LastName.ToLower().StartsWith(match1))
  85. users.Add(d);
  86. }
  87. // We're done
  88. return;
  89. }
  90. string match0 = words[0].ToLower();
  91. // words.Length == 2 and words[0] != string.empty
  92. // [email protected] ?
  93. foreach (UserData d in m_userCacheByID.Values)
  94. {
  95. if (found.Contains(d.Id))
  96. continue;
  97. if (d.LastName.ToLower().Equals(match1) &&
  98. d.FirstName.ToLower().Equals(match0))
  99. {
  100. users.Add(d);
  101. // It's cached. We're done
  102. return;
  103. }
  104. }
  105. // This is it! Let's ask the other world
  106. if (words[0].Contains("."))
  107. {
  108. string[] names = words[0].Split(new char[] { '.' });
  109. if (names.Length >= 2)
  110. {
  111. string uriStr = "http://" + words[1];
  112. // Let's check that the last name is a valid address
  113. try
  114. {
  115. new Uri(uriStr);
  116. }
  117. catch (UriFormatException)
  118. {
  119. m_log.DebugFormat("[USER MANAGEMENT MODULE]: Malformed address {0}", uriStr);
  120. return;
  121. }
  122. UUID userID = UUID.Zero;
  123. uriStr = uriStr.ToLower();
  124. if(!WebUtil.GlobalExpiringBadURLs.ContainsKey(uriStr))
  125. {
  126. UserAgentServiceConnector uasConn = new UserAgentServiceConnector(uriStr);
  127. try
  128. {
  129. userID = uasConn.GetUUID(names[0], names[1]);
  130. }
  131. catch (Exception e)
  132. {
  133. m_log.Debug("[USER MANAGEMENT MODULE]: GetUUID call failed ", e);
  134. }
  135. }
  136. if (!userID.Equals(UUID.Zero))
  137. {
  138. UserData ud = new UserData();
  139. ud.Id = userID;
  140. ud.FirstName = words[0];
  141. ud.LastName = "@" + words[1];
  142. users.Add(ud);
  143. AddUser(userID, names[0], names[1], uriStr);
  144. m_log.DebugFormat("[USER MANAGEMENT MODULE]: User {0}@{1} found", words[0], words[1]);
  145. }
  146. else
  147. m_log.DebugFormat("[USER MANAGEMENT MODULE]: User {0}@{1} not found", words[0], words[1]);
  148. }
  149. }
  150. }
  151. }
  152. }
  153. }