HGUserManagementModule.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. namespace OpenSim.Region.CoreModules.Framework.UserManagement
  43. {
  44. public class HGUserManagementModule : UserManagementModule, ISharedRegionModule, IUserManagement
  45. {
  46. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  47. #region ISharedRegionModule
  48. public new void Initialise(IConfigSource config)
  49. {
  50. string umanmod = config.Configs["Modules"].GetString("UserManagementModule", base.Name);
  51. if (umanmod == Name)
  52. {
  53. m_Enabled = true;
  54. RegisterConsoleCmds();
  55. m_log.DebugFormat("[USER MANAGEMENT MODULE]: {0} is enabled", Name);
  56. }
  57. }
  58. public override string Name
  59. {
  60. get { return "HGUserManagementModule"; }
  61. }
  62. #endregion ISharedRegionModule
  63. protected override void AddAdditionalUsers(UUID avatarID, string query, List<UserData> users)
  64. {
  65. if (query.Contains("@")) // [email protected], maybe?
  66. {
  67. string[] words = query.Split(new char[] { '@' });
  68. if (words.Length != 2)
  69. {
  70. m_log.DebugFormat("[USER MANAGEMENT MODULE]: Malformed address {0}", query);
  71. return;
  72. }
  73. words[0] = words[0].Trim(); // it has at least 1
  74. words[1] = words[1].Trim();
  75. if (words[0] == String.Empty) // query was @foo.com?
  76. {
  77. foreach (UserData d in m_UserCache.Values)
  78. {
  79. if (d.LastName.ToLower().StartsWith("@" + words[1].ToLower()))
  80. users.Add(d);
  81. }
  82. // We're done
  83. return;
  84. }
  85. // words.Length == 2 and words[0] != string.empty
  86. // [email protected] ?
  87. foreach (UserData d in m_UserCache.Values)
  88. {
  89. if (d.LastName.StartsWith("@") &&
  90. d.FirstName.ToLower().Equals(words[0].ToLower()) &&
  91. d.LastName.ToLower().Equals("@" + words[1].ToLower()))
  92. {
  93. users.Add(d);
  94. // It's cached. We're done
  95. return;
  96. }
  97. }
  98. // This is it! Let's ask the other world
  99. if (words[0].Contains("."))
  100. {
  101. string[] names = words[0].Split(new char[] { '.' });
  102. if (names.Length >= 2)
  103. {
  104. string uriStr = "http://" + words[1];
  105. // Let's check that the last name is a valid address
  106. try
  107. {
  108. new Uri(uriStr);
  109. }
  110. catch (UriFormatException)
  111. {
  112. m_log.DebugFormat("[USER MANAGEMENT MODULE]: Malformed address {0}", uriStr);
  113. return;
  114. }
  115. UserAgentServiceConnector uasConn = new UserAgentServiceConnector(uriStr);
  116. UUID userID = uasConn.GetUUID(names[0], names[1]);
  117. if (!userID.Equals(UUID.Zero))
  118. {
  119. UserData ud = new UserData();
  120. ud.Id = userID;
  121. ud.FirstName = words[0];
  122. ud.LastName = "@" + words[1];
  123. users.Add(ud);
  124. // WARNING! that uriStr is not quite right... it may be missing the / at the end,
  125. // which will cause trouble (duplicate entries on some tables). We should
  126. // get the UUI instead from the UAS. TO BE FIXED.
  127. AddUser(userID, names[0], names[1], uriStr);
  128. m_log.DebugFormat("[USER MANAGEMENT MODULE]: User {0}@{1} found", words[0], words[1]);
  129. }
  130. else
  131. m_log.DebugFormat("[USER MANAGEMENT MODULE]: User {0}@{1} not found", words[0], words[1]);
  132. }
  133. }
  134. }
  135. //else
  136. //{
  137. // foreach (UserData d in m_UserCache.Values)
  138. // {
  139. // if (d.LastName.StartsWith("@") &&
  140. // (d.FirstName.ToLower().StartsWith(query.ToLower()) ||
  141. // d.LastName.ToLower().StartsWith(query.ToLower())))
  142. // users.Add(d);
  143. // }
  144. //}
  145. }
  146. }
  147. }