From 04ea34f379a1839e618ef1a7ba05a1be19f8e43c Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 17 Aug 2016 06:00:42 +0100 Subject: add GetUsersNames(string[] ids) to UserManagement. Make GetDisplayNames cap use it so several IDs are handle on a single call. Since there is no grid side suport, no much gain still --- .../UserManagement/UserManagementModule.cs | 116 ++++++++++++++++++++- 1 file changed, 115 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/CoreModules/Framework') diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs index b72593c..2fd9183 100644 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs @@ -481,6 +481,121 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement return user.FirstName + " " + user.LastName; } + public virtual Dictionary GetUsersNames(string[] ids) + { + Dictionary ret = new Dictionary(); + if(m_Scenes.Count <= 0) + return ret; + + List missing = new List(); + + // look in cache + UserData userdata = new UserData(); + UUID uuid = UUID.Zero; + foreach(string id in ids) + { + if(UUID.TryParse(id, out uuid)) + { + lock (m_UserCache) + { + if (m_UserCache.TryGetValue(uuid, out userdata) && + userdata.HasGridUserTried && + userdata.FirstName != "Unknown") + { + string name = userdata.FirstName + " " + userdata.LastName; + ret[uuid] = name; + } + else + missing.Add(id); + } + } + } + + if(missing.Count == 0) + return ret; + + // try user account service + List accounts = m_Scenes[0].UserAccountService.GetUserAccounts( + m_Scenes[0].RegionInfo.ScopeID, missing); + + if(accounts.Count != 0) + { + foreach(UserAccount uac in accounts) + { + if(uac != null) + { + string name = uac.FirstName + " " + uac.LastName; + ret[uac.PrincipalID] = name; + missing.Remove(uac.PrincipalID.ToString()); // slowww + + userdata = new UserData(); + userdata.Id = uac.PrincipalID; + userdata.FirstName = uac.FirstName; + userdata.LastName = uac.LastName; + userdata.HomeURL = string.Empty; + userdata.IsUnknownUser = false; + userdata.HasGridUserTried = true; + lock (m_UserCache) + m_UserCache[uac.PrincipalID] = userdata; + } + } + } + + if (missing.Count == 0 || m_Scenes[0].GridUserService == null) + return ret; + + // try grid user service + + GridUserInfo[] pinfos = m_Scenes[0].GridUserService.GetGridUserInfo(missing.ToArray()); + if(pinfos.Length > 0) + { + foreach(GridUserInfo uInfo in pinfos) + { + if (uInfo != null) + { + string url, first, last, tmp; + UUID u; + if(uInfo.UserID.Length <= 36) + continue; + + if (Util.ParseUniversalUserIdentifier(uInfo.UserID, out u, out url, out first, out last, out tmp)) + { + if (url != string.Empty) + { + try + { + string name = first.Replace(" ", ".") + "." + last.Replace(" ", ".") + " @" + new Uri(url).Authority; + ret[u] = name; + missing.Remove(u.ToString()); + } + catch + { + } + } + } + } + } + } + + // add the UMMthings ( not sure we should) + if(missing.Count > 0) + { + foreach(string id in missing) + { + if(UUID.TryParse(id, out uuid) && uuid != UUID.Zero) + { + if (m_Scenes[0].LibraryService != null && + (m_Scenes[0].LibraryService.LibraryRootFolder.Owner == uuid)) + ret[uuid] = "Mr OpenSim"; + else + ret[uuid] = "Unknown UserUMMAU43"; + } + } + } + + return ret; + } + public virtual string GetUserHomeURL(UUID userID) { UserData user; @@ -584,7 +699,6 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement else { userdata = new UserData(); - userdata.HasGridUserTried = false; userdata.Id = uuid; userdata.FirstName = "Unknown"; userdata.LastName = "UserUMMAU42"; -- cgit v1.1 From 7dbc5803a6321dc13fccb3d7eef31963e2e28278 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 18 Aug 2016 02:49:46 +0100 Subject: in GetUsersNames(string[] ids) dont loose names HGFriends may have cached --- .../UserManagement/UserManagementModule.cs | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/CoreModules/Framework') diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs index 2fd9183..640ca4e 100644 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs @@ -488,9 +488,10 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement return ret; List missing = new List(); - + Dictionary untried = new Dictionary(); // look in cache UserData userdata = new UserData(); + UUID uuid = UUID.Zero; foreach(string id in ids) { @@ -499,11 +500,17 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement lock (m_UserCache) { if (m_UserCache.TryGetValue(uuid, out userdata) && - userdata.HasGridUserTried && userdata.FirstName != "Unknown") { string name = userdata.FirstName + " " + userdata.LastName; - ret[uuid] = name; + + if(userdata.HasGridUserTried) + ret[uuid] = name; + else + { + untried[uuid] = name; + missing.Add(id); + } } else missing.Add(id); @@ -527,6 +534,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement string name = uac.FirstName + " " + uac.LastName; ret[uac.PrincipalID] = name; missing.Remove(uac.PrincipalID.ToString()); // slowww + untried.Remove(uac.PrincipalID); userdata = new UserData(); userdata.Id = uac.PrincipalID; @@ -567,6 +575,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement string name = first.Replace(" ", ".") + "." + last.Replace(" ", ".") + " @" + new Uri(url).Authority; ret[u] = name; missing.Remove(u.ToString()); + untried.Remove(u); } catch { @@ -577,6 +586,16 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement } } + // add the untried in cache that still failed + if(untried.Count > 0) + { + foreach(KeyValuePair kvp in untried) + { + ret[kvp.Key] = kvp.Value; + missing.Remove(kvp.Key.ToString()); + } + } + // add the UMMthings ( not sure we should) if(missing.Count > 0) { -- cgit v1.1 From fedc689170b433370dbea2c7248293bc829d1e80 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 18 Aug 2016 04:16:20 +0100 Subject: in GetUsersNames(string[] ids) why are empty names in cache? ignore them, cache also information found by GridUserService --- .../UserManagement/UserManagementModule.cs | 27 +++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'OpenSim/Region/CoreModules/Framework') diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs index 640ca4e..eabeaf1 100644 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs @@ -489,6 +489,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement List missing = new List(); Dictionary untried = new Dictionary(); + // look in cache UserData userdata = new UserData(); @@ -500,7 +501,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement lock (m_UserCache) { if (m_UserCache.TryGetValue(uuid, out userdata) && - userdata.FirstName != "Unknown") + userdata.FirstName != "Unknown" && userdata.FirstName != string.Empty) { string name = userdata.FirstName + " " + userdata.LastName; @@ -562,20 +563,30 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement if (uInfo != null) { string url, first, last, tmp; - UUID u; + if(uInfo.UserID.Length <= 36) continue; - if (Util.ParseUniversalUserIdentifier(uInfo.UserID, out u, out url, out first, out last, out tmp)) + if (Util.ParseUniversalUserIdentifier(uInfo.UserID, out uuid, out url, out first, out last, out tmp)) { if (url != string.Empty) { try { - string name = first.Replace(" ", ".") + "." + last.Replace(" ", ".") + " @" + new Uri(url).Authority; - ret[u] = name; - missing.Remove(u.ToString()); - untried.Remove(u); + userdata = new UserData(); + userdata.FirstName = first.Replace(" ", ".") + "." + last.Replace(" ", "."); + userdata.LastName = "@" + new Uri(url).Authority; + userdata.Id = uuid; + userdata.HomeURL = url; + userdata.IsUnknownUser = false; + userdata.HasGridUserTried = true; + lock (m_UserCache) + m_UserCache[uuid] = userdata; + + string name = userdata.FirstName + " " + userdata.LastName; + ret[uuid] = name; + missing.Remove(uuid.ToString()); + untried.Remove(uuid); } catch { @@ -592,7 +603,7 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement foreach(KeyValuePair kvp in untried) { ret[kvp.Key] = kvp.Value; - missing.Remove(kvp.Key.ToString()); + missing.Remove((kvp.Key).ToString()); } } -- cgit v1.1