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 (m_UserCache) m_UserCache.TryGetValue(id, out oldUser); if (oldUser != null) { if (string.IsNullOrEmpty(creatorData)) { //ignore updates without creator data return; } //try update unknown users, but don't update anyone else if (oldUser.FirstName == "Unknown" && !creatorData.Contains("Unknown")) { lock (m_UserCache) m_UserCache.Remove(id); m_log.DebugFormat("[USER MANAGEMENT MODULE]: Re-adding user with id {0}, creatorData [{1}] and old HomeURL {2}", id, creatorData, oldUser.HomeURL); } else { //we have already a valid user within the cache return; } } UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, id); if (account != null) { AddUser(id, account.FirstName, account.LastName); } else { UserData user = new UserData(); user.Id = id; if (!string.IsNullOrEmpty(creatorData)) { //creatorData = <endpoint>;<name> string[] parts = creatorData.Split(';'); if (parts.Length >= 2) { user.FirstName = parts[1].Replace(' ', '.'); } if (parts.Length >= 1) { user.HomeURL = parts[0]; try { Uri uri = new Uri(parts[0]); user.LastName = "@" + uri.Authority; } catch (UriFormatException) { m_log.DebugFormat( "[USER MANAGEMENT MODULE]: Unable to parse home URL {0} for user name {1}, ID {2} from original creator data {3} when adding user info.", parts[0], user.FirstName ?? "Unknown", id, creatorData); user.LastName = "@unknown"; } } } else { // Temporarily add unknown user entries of this type into the cache so that we can distinguish // this source from other recent (hopefully resolved) bugs that fail to retrieve a user name binding // TODO: Can be removed when GUN* unknown users have definitely dropped significantly or // disappeared. user.FirstName = "Unknown"; user.LastName = "UserUMMAU4"; } AddUserInternal(user); } }
protected override void AddAdditionalUsers(string query, List <UserData> users) { if (query.Contains("@")) // [email protected], maybe? { string[] words = query.Split(new char[] { '@' }); if (words.Length != 2) { m_log.DebugFormat("[USER MANAGEMENT MODULE]: Malformed address {0}", query); return; } words[0] = words[0].Trim(); // it has at least 1 words[1] = words[1].Trim(); 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 // [email protected] ? foreach (UserData d in m_UserCache.Values) { if (d.LastName.StartsWith("@") && d.FirstName.ToLower().Equals(words[0].ToLower()) && d.LastName.ToLower().Equals("@" + words[1].ToLower())) { users.Add(d); // It's cached. We're done return; } } // 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]; // Let's check that the last name is a valid address try { new Uri(uriStr); } catch (UriFormatException) { m_log.DebugFormat("[USER MANAGEMENT MODULE]: Malformed address {0}", uriStr); return; } UserAgentServiceConnector uasConn = new UserAgentServiceConnector(uriStr); UUID userID = UUID.Zero; try { userID = uasConn.GetUUID(names[0], names[1]); } catch (Exception e) { m_log.Debug("[USER MANAGEMENT MODULE]: GetUUID call failed ", e); } if (!userID.Equals(UUID.Zero)) { UserData ud = new UserData(); ud.Id = userID; ud.FirstName = words[0]; ud.LastName = "@" + words[1]; users.Add(ud); // WARNING! that uriStr is not quite right... it may be missing the / at the end, // which will cause trouble (duplicate entries on some tables). We should // get the UUI instead from the UAS. TO BE FIXED. 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]); } } } } //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); // } //} }
public void AddUser(UUID id, string creatorData) { // m_log.InfoFormat("[USER MANAGEMENT MODULE]: Adding user with id {0}, creatorData {1}", id, creatorData); if (string.IsNullOrEmpty(creatorData)) { AddUser(id, string.Empty, string.Empty, string.Empty); } else { string homeURL; string firstname = string.Empty; string lastname = string.Empty; //creatorData = <endpoint>;<name> string[] parts = creatorData.Split(';'); if (parts.Length > 1) { string[] nameparts = parts[1].Split(' '); firstname = nameparts[0]; for (int xi = 1; xi < nameparts.Length; ++xi) { if (xi != 1) { lastname += " "; } lastname += nameparts[xi]; } } else { firstname = "Unknown"; lastname = "UserUMMAU5"; } if (parts.Length >= 1) { homeURL = parts[0]; if (Uri.IsWellFormedUriString(homeURL, UriKind.Absolute)) { AddUser(id, firstname, lastname, homeURL); } else { m_log.DebugFormat("[SCENE]: Unable to parse Uri {0} for CreatorID {1}", parts[0], creatorData); lock (m_UserCache) { if (!m_UserCache.ContainsKey(id)) { UserData newUser = new UserData(); newUser.Id = id; newUser.FirstName = firstname + "." + lastname.Replace(' ', '.'); newUser.LastName = "@unknown"; newUser.HomeURL = string.Empty; newUser.HasGridUserTried = false; newUser.IsUnknownUser = true; /* we mark those users as Unknown user so a re-retrieve may be activated */ m_UserCache.Add(id, newUser); } } } } else { lock (m_UserCache) { if (!m_UserCache.ContainsKey(id)) { UserData newUser = new UserData(); newUser.Id = id; newUser.FirstName = "Unknown"; newUser.LastName = "UserUMMAU4"; newUser.HomeURL = string.Empty; newUser.IsUnknownUser = true; newUser.HasGridUserTried = false; m_UserCache.Add(id, newUser); } } } } }
public bool GetUser(UUID uuid, out UserData userdata) { if (m_Scenes.Count <= 0) { userdata = new UserData(); return(false); } lock (m_UserCache) { if (m_UserCache.TryGetValue(uuid, out userdata)) { if (userdata.HasGridUserTried) { return(true); } } else { userdata = new UserData(); userdata.HasGridUserTried = false; userdata.Id = uuid; userdata.FirstName = "Unknown"; userdata.LastName = "UserUMMAU42"; userdata.HomeURL = string.Empty; userdata.IsUnknownUser = true; userdata.HasGridUserTried = false; } } /* BEGIN: do not wrap this code in any lock here * There are HTTP calls in here. */ if (!userdata.HasGridUserTried) { /* rewrite here */ UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, uuid); if (account != null) { userdata.FirstName = account.FirstName; userdata.LastName = account.LastName; userdata.HomeURL = string.Empty; userdata.IsUnknownUser = false; userdata.HasGridUserTried = true; } } if (!userdata.HasGridUserTried) { GridUserInfo uInfo = null; if (null != m_Scenes[0].GridUserService) { uInfo = m_Scenes[0].GridUserService.GetGridUserInfo(uuid.ToString()); } if (uInfo != null) { string url, first, last, tmp; UUID u; if (uInfo.UserID.Length <= 36) { /* not a UUI */ } else if (Util.ParseUniversalUserIdentifier(uInfo.UserID, out u, out url, out first, out last, out tmp)) { if (url != string.Empty) { userdata.FirstName = first.Replace(" ", ".") + "." + last.Replace(" ", "."); userdata.HomeURL = url; try { userdata.LastName = "@" + new Uri(url).Authority; userdata.IsUnknownUser = false; } catch { userdata.LastName = "@unknown"; } userdata.HasGridUserTried = true; } } else { m_log.DebugFormat("[USER MANAGEMENT MODULE]: Unable to parse UUI {0}", uInfo.UserID); } } } /* END: do not wrap this code in any lock here */ lock (m_UserCache) { m_UserCache[uuid] = userdata; } return(!userdata.IsUnknownUser); }
public virtual bool GetUser(UUID uuid, out UserData userdata) { return(GetUser(uuid, m_Scenes[0].RegionInfo.ScopeID, out userdata)); }
public virtual Dictionary <UUID, UserData> GetUserDatas(string[] ids, UUID scopeID, bool update_name = false) { Dictionary <UUID, UserData> ret = new Dictionary <UUID, UserData>(); if (m_Scenes.Count <= 0) { return(ret); } List <string> missing = new List <string>(); Dictionary <UUID, UserData> untried = new Dictionary <UUID, UserData>(); // 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.FirstName != "Unknown" && userdata.FirstName != string.Empty) { if (update_name) { if (userdata.HomeURL != string.Empty) { string name = string.Join(" ", userdata.FirstName.Split('.')); //m_log.InfoFormat("Adding {0};{1};{2} to missing", userdata.Id, userdata.HomeURL, name); missing.Add(string.Format("{0};{1};{2}", userdata.Id, userdata.HomeURL, name)); } else { missing.Add(id); } continue; } if (userdata.HasGridUserTried) { ret[uuid] = userdata; } else { untried[uuid] = userdata; missing.Add(id); } } else { missing.Add(id); } } } } if (missing.Count == 0) { return(ret); } // try user account service List <UserAccount> accounts = m_Scenes[0].UserAccountService.GetUserAccounts( scopeID, missing); if (accounts.Count != 0) { foreach (UserAccount uac in accounts) { if (uac != null) { string name = uac.FirstName + " " + uac.LastName; missing.Remove(uac.PrincipalID.ToString()); // slowww untried.Remove(uac.PrincipalID); userdata = new UserData(); userdata.Id = uac.PrincipalID; userdata.FirstName = uac.FirstName; userdata.LastName = uac.LastName; userdata.DisplayName = uac.DisplayName; userdata.NameChanged = Util.ToDateTime(uac.NameChanged); userdata.HomeURL = string.Empty; userdata.IsUnknownUser = false; userdata.HasGridUserTried = true; lock (m_UserCache) m_UserCache[uac.PrincipalID] = userdata; ret[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(), update_name); if (pinfos.Length > 0) { foreach (GridUserInfo uInfo in pinfos) { if (uInfo != null) { string url, first, last, tmp; if (uInfo.UserID.Length <= 36) { continue; } if (Util.ParseUniversalUserIdentifier(uInfo.UserID, out uuid, out url, out first, out last, out tmp)) { if (url != string.Empty) { try { userdata = new UserData(); userdata.FirstName = first.Replace(" ", ".") + "." + last.Replace(" ", "."); userdata.LastName = "@" + new Uri(url).Authority; userdata.DisplayName = uInfo.DisplayName; userdata.NameChanged = uInfo.NameCached; userdata.Id = uuid; userdata.HomeURL = url; userdata.IsUnknownUser = false; userdata.HasGridUserTried = true; lock (m_UserCache) m_UserCache[uuid] = userdata; ret[uuid] = userdata; missing.Remove(uuid.ToString()); untried.Remove(uuid); } catch { } } } } } } // add the untried in cache that still failed if (untried.Count > 0) { foreach (KeyValuePair <UUID, UserData> kvp in untried) { ret[kvp.Key] = kvp.Value; missing.Remove((kvp.Key).ToString()); } } // 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) { userdata = new UserData(); if (m_Scenes[0].LibraryService != null && (m_Scenes[0].LibraryService.LibraryRootFolder.Owner == uuid)) { userdata.FirstName = "Mr"; userdata.LastName = "OpenSim"; } else { userdata.FirstName = "Unknown"; userdata.LastName = "UserUMMAU43"; userdata.IsUnknownUser = true; } ret[uuid] = userdata; } } } return(ret); }