From d08ad6459a03a6a5a6a551fd2b275f1c7da94d8e Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Tue, 20 Mar 2012 17:14:19 -0700 Subject: HG Friends: allow the establishment of HG friendships without requiring co-presence in the same sim. Using avatar picker, users can now search for names such as "first.last@grid.com:9000", find them, and request friendship. Friendship requests are stored if target user is offline. TESTED ON STANDALONE ONLY. --- .../UserManagement/HGUserManagementModule.cs | 76 ++++++++++++---------- .../UserManagement/UserManagementModule.cs | 20 +++--- 2 files changed, 54 insertions(+), 42 deletions(-) (limited to 'OpenSim/Region/CoreModules/Framework') diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/HGUserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/HGUserManagementModule.cs index 66de8e4..4eecaa2 100644 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/HGUserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/HGUserManagementModule.cs @@ -71,43 +71,52 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement protected override void AddAdditionalUsers(UUID avatarID, string query, List users) { - string[] words = query.Split(new char[] { ' ' }); - - for (int i = 0; i < words.Length; i++) + if (query.Contains("@")) // First.Last@foo.com, maybe? { - if (words[i].Length < 3) + string[] words = query.Split(new char[] { '@' }); + if (words.Length != 2) { - if (i != words.Length - 1) - Array.Copy(words, i + 1, words, i, words.Length - i - 1); - Array.Resize(ref words, words.Length - 1); + m_log.DebugFormat("[USER MANAGEMENT MODULE]: Malformed address {0}", query); + return; } - } - if (words.Length == 0 || words.Length > 2) - return; + words[0] = words[0].Trim(); // it has at least 1 + words[1] = words[1].Trim(); - if (words.Length == 2) // First.Last @foo.com, maybe? - { - bool found = false; + if (words[0] == String.Empty) // query was @foo.com? + { + foreach (UserData d in m_UserCache.Values) + { + if (d.LastName.ToLower().StartsWith("@" + words[1].ToLower())) + users.Add(d); + } + + // We're done + return; + } + + // words.Length == 2 and words[0] != string.empty + // first.last@foo.com ? foreach (UserData d in m_UserCache.Values) { - if (d.LastName.StartsWith("@") && + if (d.LastName.StartsWith("@") && d.FirstName.ToLower().Equals(words[0].ToLower()) && - d.LastName.ToLower().Equals(words[1].ToLower())) + d.LastName.ToLower().Equals("@" + words[1].ToLower())) { users.Add(d); - found = true; - break; + // It's cached. We're done + return; } } - if (!found && words[1].StartsWith("@") && words[0].Contains(".")) // This is it! Let's ask the other world + // This is it! Let's ask the other world + if (words[0].Contains(".")) { string[] names = words[0].Split(new char[] { '.' }); if (names.Length >= 2) { - string uriStr = "http://" + words[1].Substring(1); // remove the @ + string uriStr = "http://" + words[1]; // Let's check that the last name is a valid address try { @@ -115,6 +124,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement } catch (UriFormatException) { + m_log.DebugFormat("[USER MANAGEMENT MODULE]: Malformed address {0}", uriStr); return; } @@ -125,26 +135,26 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement UserData ud = new UserData(); ud.Id = userID; ud.FirstName = words[0]; - ud.LastName = words[1]; + ud.LastName = "@" + words[1]; users.Add(ud); - AddUser(userID, ud.FirstName, ud.LastName, uriStr); - m_log.DebugFormat("[USER MANAGEMENT MODULE]: User {0} {1} found", words[0], words[1]); + AddUser(userID, names[0], names[1], uriStr); + m_log.DebugFormat("[USER MANAGEMENT MODULE]: User {0}@{1} found", words[0], words[1]); } else - m_log.DebugFormat("[USER MANAGEMENT MODULE]: User {0} {1} not found", words[0], words[1]); + m_log.DebugFormat("[USER MANAGEMENT MODULE]: User {0}@{1} not found", words[0], words[1]); } } } - else - { - foreach (UserData d in m_UserCache.Values) - { - if (d.LastName.StartsWith("@") && - (d.FirstName.ToLower().StartsWith(query.ToLower()) || - d.LastName.ToLower().StartsWith(query.ToLower()))) - users.Add(d); - } - } + //else + //{ + // foreach (UserData d in m_UserCache.Values) + // { + // if (d.LastName.StartsWith("@") && + // (d.FirstName.ToLower().StartsWith(query.ToLower()) || + // d.LastName.ToLower().StartsWith(query.ToLower()))) + // users.Add(d); + // } + //} } } diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs index cb562a2..0397478 100644 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs @@ -299,7 +299,6 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement public string GetUserName(UUID uuid) { - //m_log.DebugFormat("[XXX] GetUserName {0}", uuid); string[] names = GetUserNames(uuid); if (names.Length == 2) { @@ -340,9 +339,9 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement if (userdata.HomeURL != null && userdata.HomeURL != string.Empty) { - m_log.DebugFormat( - "[USER MANAGEMENT MODULE]: Did not find url type {0} so requesting urls from '{1}' for {2}", - serverType, userdata.HomeURL, userID); + //m_log.DebugFormat( + // "[USER MANAGEMENT MODULE]: Did not find url type {0} so requesting urls from '{1}' for {2}", + // serverType, userdata.HomeURL, userID); UserAgentServiceConnector uConn = new UserAgentServiceConnector(userdata.HomeURL); userdata.ServerURLs = uConn.GetServerURLs(userID); @@ -401,11 +400,15 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement public void AddUser(UUID uuid, string first, string last, string homeURL) { + // m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, first {1}, last {2}, url {3}", uuid, first, last, homeURL); + AddUser(uuid, homeURL + ";" + first + " " + last); } public void AddUser (UUID id, string creatorData) { + //m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, creatorData {1}", id, creatorData); + UserData oldUser; //lock the whole block - prevent concurrent update lock (m_UserCache) @@ -431,9 +434,8 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement return; } } -// m_log.DebugFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, creatorData {1}", id, creatorData); - UserAccount account = m_Scenes [0].UserAccountService.GetUserAccount (m_Scenes [0].RegionInfo.ScopeID, id); + UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount (m_Scenes [0].RegionInfo.ScopeID, id); if (account != null) { @@ -482,9 +484,9 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement lock (m_UserCache) m_UserCache[user.Id] = user; -// m_log.DebugFormat( -// "[USER MANAGEMENT MODULE]: Added user {0} {1} {2} {3}", -// user.Id, user.FirstName, user.LastName, user.HomeURL); + //m_log.DebugFormat( + // "[USER MANAGEMENT MODULE]: Added user {0} {1} {2} {3}", + // user.Id, user.FirstName, user.LastName, user.HomeURL); } public bool IsLocalGridUser(UUID uuid) -- cgit v1.1