From 2153a01cc7eb8667fa0c9fc76a36b178566bf444 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Fri, 7 Aug 2015 11:34:52 +0300 Subject: Have osAvatarName2Key check the cache first, even for foreign users Another change: removed the second call to userManager.AddUser(). UserManagementModule won't modify an existing record. --- .../Shared/Api/Implementation/OSSL_Api.cs | 45 +++++++++++----------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 1c404bb..123f8ca 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2053,47 +2053,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key"); m_host.AddScriptLPS(1); - if (lastname.Contains("@")) + IUserManagement userManager = World.RequestModuleInterface(); + if (userManager == null) { - String realFirstName; String realLastName; String serverURI; + OSSLShoutError("osAvatarName2Key: UserManagement module not available"); + return string.Empty; + } + + // Check if the user is already cached + + UUID userID = userManager.GetUserIdByName(firstname, lastname); + if (userID != UUID.Zero) + return userID.ToString(); - realFirstName = firstname.Split('.')[0]; - realLastName = firstname.Split('.')[1]; - serverURI = new Uri("http://" + lastname.Replace("@", "")).ToString(); + // Query for the user + String realFirstName; String realLastName; String serverURI; + if (Util.ParseForeignAvatarName(firstname, lastname, out realFirstName, out realLastName, out serverURI)) + { try { UserAgentServiceConnector userConnection = new UserAgentServiceConnector(serverURI, true); if (userConnection != null) { - UUID ruserid = userConnection.GetUUID(realFirstName, realLastName); - - if (ruserid != null) + userID = userConnection.GetUUID(realFirstName, realLastName); + if (userID != UUID.Zero) { - IUserManagement userManager = m_ScriptEngine.World.RequestModuleInterface(); - - if (userManager != null) - { - //Use the HomeURI from the script to get user infos and then ask the remote gridserver for the real HomeURI. - userManager.AddUser(ruserid, realFirstName, realLastName, serverURI); - serverURI = userManager.GetUserServerURL(ruserid, "HomeURI"); - userManager.AddUser(ruserid, realFirstName, realLastName, serverURI); - - return ruserid.ToString(); - } + userManager.AddUser(userID, realFirstName, realLastName, serverURI); + return userID.ToString(); } } } - catch (Exception osAvatarException) + catch (Exception /*e*/) { - //m_log.Warn("[osAvatarName2Key] UserAgentServiceConnector - Unable to connect to destination grid\n" + osAvatarException.Message); + // m_log.Warn("[osAvatarName2Key] UserAgentServiceConnector - Unable to connect to destination grid ", e); } } else { UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, firstname, lastname); - if (account != null) return account.PrincipalID.ToString(); + if (account != null) + return account.PrincipalID.ToString(); } return UUID.Zero.ToString(); -- cgit v1.1