From e8a2eff2e83cba74e84970136dd486beededc1de Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Thu, 24 Apr 2014 14:20:48 +0300 Subject: [PATCH] Changed how UserProfile performs a fallback call using the OpenProfile API, because now JsonRpcRequest() returns an error result instead of throwing an exception --- .../Avatar/UserProfiles/UserProfileModule.cs | 67 ++++++++++--------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs index 3d45f1d57d..1ee2a7bb84 100644 --- a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs @@ -65,6 +65,8 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles Dictionary m_classifiedCache = new Dictionary(); Dictionary m_classifiedInterest = new Dictionary(); + private JsonRpcRequestManager rpc = new JsonRpcRequestManager(); + public Scene Scene { get; private set; @@ -114,7 +116,6 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles set; } - JsonRpcRequestManager rpc = new JsonRpcRequestManager(); #region IRegionModuleBase implementation /// @@ -920,7 +921,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles public void RequestAvatarProperties(IClientAPI remoteClient, UUID avatarID) { - if ( String.IsNullOrEmpty(avatarID.ToString()) || String.IsNullOrEmpty(remoteClient.AgentId.ToString())) + if (String.IsNullOrEmpty(avatarID.ToString()) || String.IsNullOrEmpty(remoteClient.AgentId.ToString())) { // Looking for a reason that some viewers are sending null Id's m_log.DebugFormat("[PROFILES]: This should not happen remoteClient.AgentId {0} - avatarID {1}", remoteClient.AgentId, avatarID); @@ -998,29 +999,10 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles props.UserId = avatarID; - try + if (!GetProfileData(ref props, foreign, out result)) { - GetProfileData(ref props, out result); - } - catch (Exception e) - { - if (foreign) - { - // Check if the foreign grid is using OpenProfile. - // If any error occurs then discard it, and report the original error. - try - { - OpenProfileClient client = new OpenProfileClient(serverURI); - if (!client.RequestAvatarPropertiesUsingOpenProfile(ref props)) - throw e; - } - catch (Exception) - { - throw e; - } - } - else - throw; + m_log.DebugFormat("Error getting profile for {0}: {1}", avatarID, result); + return; } remoteClient.SendAvatarProperties(props.UserId, props.AboutText, born, charterMember , props.FirstLifeText, flags, @@ -1074,10 +1056,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles /// /// The profile data. /// - /// - /// User I. - /// - bool GetProfileData(ref UserProfileProperties properties, out string message) + bool GetProfileData(ref UserProfileProperties properties, bool foreign, out string message) { // Can't handle NPC yet... ScenePresence p = FindPresence(properties.UserId); @@ -1096,14 +1075,42 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles // This is checking a friend on the home grid // Not HG friend - if ( String.IsNullOrEmpty(serverURI)) + if (String.IsNullOrEmpty(serverURI)) { message = "No Presence - foreign friend"; return false; } object Prop = (object)properties; - rpc.JsonRpcRequest(ref Prop, "avatar_properties_request", serverURI, UUID.Random().ToString()); + if (!rpc.JsonRpcRequest(ref Prop, "avatar_properties_request", serverURI, UUID.Random().ToString())) + { + // If it's a foreign user then try again using OpenProfile, in case that's what the grid is using + bool secondChanceSuccess = false; + if (foreign) + { + try + { + OpenProfileClient client = new OpenProfileClient(serverURI); + if (client.RequestAvatarPropertiesUsingOpenProfile(ref properties)) + secondChanceSuccess = true; + } + catch (Exception e) + { + m_log.Debug(string.Format("Request using the OpenProfile API to {0} failed", serverURI), e); + // Allow the return 'message' to say "JsonRpcRequest" and not "OpenProfile", because + // the most likely reason that OpenProfile failed is that the remote server + // doesn't support OpenProfile, and that's not very interesting. + } + } + + if (!secondChanceSuccess) + { + message = string.Format("JsonRpcRequest to {0} failed", serverURI); + return false; + } + // else, continue below + } + properties = (UserProfileProperties)Prop; message = "Success";