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
parent
72876fc683
commit
04ea34f379
|
@ -29,8 +29,6 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
|
@ -38,12 +36,7 @@ using log4net;
|
|||
using Nini.Config;
|
||||
using OpenMetaverse;
|
||||
using OpenMetaverse.StructuredData;
|
||||
using OpenMetaverse.Imaging;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Capabilities;
|
||||
using OpenSim.Framework.Servers;
|
||||
using OpenSim.Framework.Servers.HttpServer;
|
||||
using OpenSim.Region.Framework.Interfaces;
|
||||
using OpenSim.Services.Interfaces;
|
||||
using Caps = OpenSim.Framework.Capabilities.Caps;
|
||||
using OSDMap = OpenMetaverse.StructuredData.OSDMap;
|
||||
|
@ -70,7 +63,6 @@ namespace OpenSim.Capabilities.Handlers
|
|||
NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query);
|
||||
string[] ids = query.GetValues("ids");
|
||||
|
||||
|
||||
if (m_UserManagement == null)
|
||||
{
|
||||
m_log.Error("[GET_DISPLAY_NAMES]: Cannot fetch display names without a user management component");
|
||||
|
@ -78,35 +70,39 @@ namespace OpenSim.Capabilities.Handlers
|
|||
return new byte[0];
|
||||
}
|
||||
|
||||
Dictionary<UUID,string> names = m_UserManagement.GetUsersNames(ids);
|
||||
|
||||
OSDMap osdReply = new OSDMap();
|
||||
OSDArray agents = new OSDArray();
|
||||
|
||||
osdReply["agents"] = agents;
|
||||
foreach (string id in ids)
|
||||
foreach (KeyValuePair<UUID,string> kvp in names)
|
||||
{
|
||||
UUID uuid = UUID.Zero;
|
||||
if (UUID.TryParse(id, out uuid))
|
||||
{
|
||||
string name = m_UserManagement.GetUserName(uuid);
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
string[] parts = name.Split(new char[] {' '});
|
||||
OSDMap osdname = new OSDMap();
|
||||
// a date that is valid
|
||||
// osdname["display_name_next_update"] = OSD.FromDate(new DateTime(1970,1,1));
|
||||
// but send one that blocks edition, since we actually don't suport this
|
||||
osdname["display_name_next_update"] = OSD.FromDate(DateTime.UtcNow.AddDays(8));
|
||||
osdname["display_name_expires"] = OSD.FromDate(DateTime.UtcNow.AddMonths(1));
|
||||
osdname["display_name"] = OSD.FromString(name);
|
||||
osdname["legacy_first_name"] = parts[0];
|
||||
osdname["legacy_last_name"] = parts[1];
|
||||
osdname["username"] = OSD.FromString(name);
|
||||
osdname["id"] = OSD.FromUUID(uuid);
|
||||
osdname["is_display_name_default"] = OSD.FromBoolean(true);
|
||||
if (string.IsNullOrEmpty(kvp.Value))
|
||||
continue;
|
||||
if(kvp.Key == UUID.Zero)
|
||||
continue;
|
||||
|
||||
agents.Add(osdname);
|
||||
}
|
||||
string[] parts = kvp.Value.Split(new char[] {' '});
|
||||
OSDMap osdname = new OSDMap();
|
||||
if(parts[0] == "Unknown")
|
||||
{
|
||||
osdname["display_name_next_update"] = OSD.FromDate(DateTime.UtcNow.AddHours(1));
|
||||
osdname["display_name_expires"] = OSD.FromDate(DateTime.UtcNow.AddHours(2));
|
||||
}
|
||||
else
|
||||
{
|
||||
osdname["display_name_next_update"] = OSD.FromDate(DateTime.UtcNow.AddDays(8));
|
||||
osdname["display_name_expires"] = OSD.FromDate(DateTime.UtcNow.AddMonths(1));
|
||||
}
|
||||
osdname["display_name"] = OSD.FromString(kvp.Value);
|
||||
osdname["legacy_first_name"] = parts[0];
|
||||
osdname["legacy_last_name"] = parts[1];
|
||||
osdname["username"] = OSD.FromString(kvp.Value);
|
||||
osdname["id"] = OSD.FromUUID(kvp.Key);
|
||||
osdname["is_display_name_default"] = OSD.FromBoolean(true);
|
||||
|
||||
agents.Add(osdname);
|
||||
}
|
||||
|
||||
// Full content request
|
||||
|
@ -116,8 +112,6 @@ namespace OpenSim.Capabilities.Handlers
|
|||
|
||||
string reply = OSDParser.SerializeLLSDXmlString(osdReply);
|
||||
return System.Text.Encoding.UTF8.GetBytes(reply);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,8 +61,6 @@ namespace OpenSim.Capabilities.Handlers
|
|||
|
||||
if (m_UserManagement == null)
|
||||
throw new Exception(String.Format("Failed to load UserManagement from {0}; config is {1}", umService, m_ConfigName));
|
||||
|
||||
string rurl = serverConfig.GetString("GetTextureRedirectURL");
|
||||
|
||||
server.AddStreamHandler(
|
||||
new GetDisplayNamesHandler("/CAPS/agents/", m_UserManagement, "GetDisplayNames", null));
|
||||
|
|
|
@ -481,6 +481,121 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
|
|||
return user.FirstName + " " + user.LastName;
|
||||
}
|
||||
|
||||
public virtual Dictionary<UUID,string> GetUsersNames(string[] ids)
|
||||
{
|
||||
Dictionary<UUID,string> ret = new Dictionary<UUID,string>();
|
||||
if(m_Scenes.Count <= 0)
|
||||
return ret;
|
||||
|
||||
List<string> missing = new List<string>();
|
||||
|
||||
// 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<UserAccount> 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";
|
||||
|
|
|
@ -165,7 +165,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
|
|||
List<UserAccount> accs = new List<UserAccount>();
|
||||
List<string> missing = new List<string>();
|
||||
|
||||
UUID uuid = UUID.Zero;;
|
||||
UUID uuid = UUID.Zero;
|
||||
UserAccount account;
|
||||
bool inCache = false;
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ namespace OpenSim.Services.Interfaces
|
|||
string GetUserUUI(UUID uuid);
|
||||
bool GetUserUUI(UUID userID, out string uui);
|
||||
string GetUserServerURL(UUID uuid, string serverType);
|
||||
Dictionary<UUID,string> GetUsersNames(string[] ids);
|
||||
|
||||
/// <summary>
|
||||
/// Get user ID by the given name.
|
||||
|
|
Loading…
Reference in New Issue