HGUserManagementModule.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. Init();
  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)
  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();
  77. if (words[0] == String.Empty) // query was @foo.com?
  78. {
  79. foreach (UserData d in m_UserCache.Values)
  80. {
  81. if (d.LastName.ToLower().StartsWith("@" + words[1].ToLower()))
  82. users.Add(d);
  83. }
  84. // We're done
  85. return;
  86. }
  87. // words.Length == 2 and words[0] != string.empty
  88. // [email protected] ?
  89. foreach (UserData d in m_UserCache.Values)
  90. {
  91. if (d.LastName.StartsWith("@") &&
  92. d.FirstName.ToLower().Equals(words[0].ToLower()) &&
  93. d.LastName.ToLower().Equals("@" + words[1].ToLower()))
  94. {
  95. users.Add(d);
  96. // It's cached. We're done
  97. return;
  98. }
  99. }
  100. // This is it! Let's ask the other world
  101. if (words[0].Contains("."))
  102. {
  103. string[] names = words[0].Split(new char[] { '.' });
  104. if (names.Length >= 2)
  105. {
  106. string uriStr = "http://" + words[1];
  107. // Let's check that the last name is a valid address
  108. try
  109. {
  110. new Uri(uriStr);
  111. }
  112. catch (UriFormatException)
  113. {
  114. m_log.DebugFormat("[USER MANAGEMENT MODULE]: Malformed address {0}", uriStr);
  115. return;
  116. }
  117. UserAgentServiceConnector uasConn = new UserAgentServiceConnector(uriStr);
  118. UUID userID = UUID.Zero;
  119. try
  120. {
  121. userID = uasConn.GetUUID(names[0], names[1]);
  122. }
  123. catch (Exception e)
  124. {
  125. m_log.Debug("[USER MANAGEMENT MODULE]: GetUUID call failed ", e);
  126. }
  127. if (!userID.Equals(UUID.Zero))
  128. {
  129. UserData ud = new UserData();
  130. ud.Id = userID;
  131. ud.FirstName = words[0];
  132. ud.LastName = "@" + words[1];
  133. users.Add(ud);
  134. // WARNING! that uriStr is not quite right... it may be missing the / at the end,
  135. // which will cause trouble (duplicate entries on some tables). We should
  136. // get the UUI instead from the UAS. TO BE FIXED.
  137. AddUser(userID, names[0], names[1], uriStr);
  138. m_log.DebugFormat("[USER MANAGEMENT MODULE]: User {0}@{1} found", words[0], words[1]);
  139. }
  140. else
  141. m_log.DebugFormat("[USER MANAGEMENT MODULE]: User {0}@{1} not found", words[0], words[1]);
  142. }
  143. }
  144. }
  145. //else
  146. //{
  147. // foreach (UserData d in m_UserCache.Values)
  148. // {
  149. // if (d.LastName.StartsWith("@") &&
  150. // (d.FirstName.ToLower().StartsWith(query.ToLower()) ||
  151. // d.LastName.ToLower().StartsWith(query.ToLower())))
  152. // users.Add(d);
  153. // }
  154. //}
  155. }
  156. }
  157. }