From 6941058824e418bcdc2932c35f226bbcc5cea2ad Mon Sep 17 00:00:00 2001 From: BlueWall Date: Sun, 1 Jan 2012 14:57:13 -0500 Subject: [PATCH] Profile Updates Update basic profile to use the replaceable interface, making configuration less error-prone. Add support to query avatar's home user account and profile service for regions usng the updated OpenProfileModule with Hypergrid. --- OpenSim/Framework/IProfileModule.cs | 37 ++++++++ .../Avatar/Profile/BasicProfileModule.cs | 12 ++- .../UserManagement/UserManagementModule.cs | 93 +++++++++++++++++++ .../Framework/Interfaces/IUserManagement.cs | 3 + .../Hypergrid/UserAgentServerConnector.cs | 33 +++++++ .../Hypergrid/UserAgentServiceConnector.cs | 54 +++++++++++ .../HypergridService/UserAgentService.cs | 25 +++++ .../Services/Interfaces/IHypergridServices.cs | 1 + 8 files changed, 253 insertions(+), 5 deletions(-) create mode 100644 OpenSim/Framework/IProfileModule.cs diff --git a/OpenSim/Framework/IProfileModule.cs b/OpenSim/Framework/IProfileModule.cs new file mode 100644 index 0000000000..ef03d4a62a --- /dev/null +++ b/OpenSim/Framework/IProfileModule.cs @@ -0,0 +1,37 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using OpenMetaverse; + +namespace OpenSim.Framework +{ + public interface IProfileModule + { + void RequestAvatarProperties(IClientAPI remoteClient, UUID avatarID); + + } +} diff --git a/OpenSim/Region/CoreModules/Avatar/Profile/BasicProfileModule.cs b/OpenSim/Region/CoreModules/Avatar/Profile/BasicProfileModule.cs index dee0ad4bfc..eb1e4b5f13 100644 --- a/OpenSim/Region/CoreModules/Avatar/Profile/BasicProfileModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Profile/BasicProfileModule.cs @@ -43,7 +43,7 @@ using OpenSim.Services.Interfaces; namespace OpenSim.Region.CoreModules.Avatar.Profile { [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] - public class BasicProfileModule : ISharedRegionModule + public class BasicProfileModule : IProfileModule, ISharedRegionModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -57,6 +57,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Profile public void Initialise(IConfigSource config) { + // This can be reduced later as the loader will determine + // whether we are needed if (config.Configs["Profile"] != null) { if (config.Configs["Profile"].GetString("Module", string.Empty) != "BasicProfileModule") @@ -65,14 +67,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Profile m_log.DebugFormat("[PROFILE MODULE]: Basic Profile Module enabled"); m_Enabled = true; - } public void AddRegion(Scene scene) { if (!m_Enabled) return; - + lock (m_Scenes) { if (!m_Scenes.Contains(scene)) @@ -80,6 +81,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Profile m_Scenes.Add(scene); // Hook up events scene.EventManager.OnNewClient += OnNewClient; + scene.RegisterModuleInterface(this); } } } @@ -116,7 +118,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Profile public Type ReplaceableInterface { - get { return null; } + get { return typeof(IProfileModule); } } #endregion @@ -170,4 +172,4 @@ namespace OpenSim.Region.CoreModules.Avatar.Profile } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs index dbe2560493..37292d66fd 100644 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs @@ -50,6 +50,9 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement public string LastName { get; set; } public string HomeURL { get; set; } public Dictionary ServerURLs { get; set; } + public string Title { get; set; } + public int Flags { get; set; } + public int Created { get; set; } } public class UserManagementModule : ISharedRegionModule, IUserManagement @@ -281,6 +284,94 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement return string.Empty; } + public int GetUserFlags(UUID userID) + { + UserData userdata; + lock (m_UserCache) + m_UserCache.TryGetValue(userID, out userdata); + + if (userdata.Flags == -1) + GetUserInfo(userID); + + if (userdata.Flags != -1) + return userdata.Flags; + + return 0; + } + + public int GetUserCreated(UUID userID) + { + UserData userdata; + lock (m_UserCache) + m_UserCache.TryGetValue(userID, out userdata); + + if (userdata.Flags == -1) + GetUserInfo(userID); + + if (userdata.Created != -1) + return userdata.Created; + + return 0; + } + + public string GetUserTitle(UUID userID) + { + UserData userdata; + lock (m_UserCache) + m_UserCache.TryGetValue(userID, out userdata); + + if (userdata.Flags == -1) + GetUserInfo(userID); + + if (userdata.Created != -1) + return userdata.Title; + + return string.Empty; + } + + // This will cache the user data + // Change this to return bool + private bool GetUserInfo(UUID userID) + { + UserData userdata; + lock (m_UserCache) + m_UserCache.TryGetValue(userID, out userdata); + + if (userdata != null) + { +// m_log.DebugFormat("[USER MANAGEMENT MODULE]: Requested url type {0} for {1}", serverType, userID); + + if (userdata.Flags >= 0) + { + // This is already populated + return true; + } + + if (userdata.HomeURL != null && userdata.HomeURL != string.Empty) + { + m_log.DebugFormat( + "[USER MANAGEMENT MODULE]: Requesting user flags from '{0}' for {1}", + userdata.HomeURL, userID); + + UserAgentServiceConnector uConn = new UserAgentServiceConnector(userdata.HomeURL); + Dictionary info = uConn.GetUserInfo(userID); + + // Pull our data now + if (info["result"].ToString() == "success") + { + userdata.Flags = (int)info["user_flags"]; + userdata.Created = (int)info["user_created"]; + userdata.Title = (string)info["user_title"]; + + return true; + } + } + } + + return false; + } + + public string GetUserUUI(UUID userID) { UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, userID); @@ -352,6 +443,8 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement { UserData user = new UserData(); user.Id = id; + user.Flags = -1; + user.Created = -1; if (creatorData != null && creatorData != string.Empty) { diff --git a/OpenSim/Region/Framework/Interfaces/IUserManagement.cs b/OpenSim/Region/Framework/Interfaces/IUserManagement.cs index ea0ba5935b..54dfaf4c63 100644 --- a/OpenSim/Region/Framework/Interfaces/IUserManagement.cs +++ b/OpenSim/Region/Framework/Interfaces/IUserManagement.cs @@ -14,6 +14,9 @@ namespace OpenSim.Region.Framework.Interfaces string GetUserHomeURL(UUID uuid); string GetUserUUI(UUID uuid); string GetUserServerURL(UUID uuid, string serverType); + int GetUserFlags(UUID userID); + int GetUserCreated(UUID userID); + string GetUserTitle(UUID userID); /// /// Add a user. diff --git a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs index 07c69624b7..1bd37062db 100644 --- a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs +++ b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs @@ -91,6 +91,7 @@ namespace OpenSim.Server.Handlers.Hypergrid server.AddXmlRPCHandler("status_notification", StatusNotification, false); server.AddXmlRPCHandler("get_online_friends", GetOnlineFriends, false); + server.AddXmlRPCHandler("get_user_info", GetUserInfo, false); server.AddXmlRPCHandler("get_server_urls", GetServerURLs, false); server.AddXmlRPCHandler("locate_user", LocateUser, false); @@ -299,6 +300,38 @@ namespace OpenSim.Server.Handlers.Hypergrid } + public XmlRpcResponse GetUserInfo(XmlRpcRequest request, IPEndPoint remoteClient) + { + Hashtable hash = new Hashtable(); + Hashtable requestData = (Hashtable)request.Params[0]; + + // This needs checking! + if (requestData.ContainsKey("userID")) + { + string userID_str = (string)requestData["userID"]; + UUID userID = UUID.Zero; + UUID.TryParse(userID_str, out userID); + + //int userFlags = m_HomeUsersService.GetUserFlags(userID); + Dictionary userInfo = m_HomeUsersService.GetUserInfo(userID); + if (userInfo.Count > 0) + { + foreach (KeyValuePair kvp in userInfo) + { + hash[kvp.Key] = kvp.Value; + } + } + else + { + hash["result"] = "failure"; + } + } + + XmlRpcResponse response = new XmlRpcResponse(); + response.Value = hash; + return response; + } + public XmlRpcResponse GetServerURLs(XmlRpcRequest request, IPEndPoint remoteClient) { Hashtable hash = new Hashtable(); diff --git a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs index 57b6d16fe5..5b27cf6427 100644 --- a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs +++ b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs @@ -561,6 +561,60 @@ namespace OpenSim.Services.Connectors.Hypergrid return online; } + public Dictionary GetUserInfo (UUID userID) + { + Hashtable hash = new Hashtable(); + hash["userID"] = userID.ToString(); + + IList paramList = new ArrayList(); + paramList.Add(hash); + + XmlRpcRequest request = new XmlRpcRequest("get_user_info", paramList); + + Dictionary info = new Dictionary(); + XmlRpcResponse response = null; + try + { + response = request.Send(m_ServerURL, 10000); + } + catch + { + m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetUserInfo", m_ServerURL); + return info; + } + + if (response.IsFault) + { + m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetServerURLs returned an error: {1}", m_ServerURL, response.FaultString); + return info; + } + + hash = (Hashtable)response.Value; + try + { + if (hash == null) + { + m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetUserInfo Got null response from {0}! THIS IS BAAAAD", m_ServerURL); + return info; + } + + // Here is the actual response + foreach (object key in hash.Keys) + { + if (hash[key] != null) + { + info.Add(key.ToString(), hash[key]); + } + } + } + catch + { + m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response."); + } + + return info; + } + public Dictionary GetServerURLs(UUID userID) { Hashtable hash = new Hashtable(); diff --git a/OpenSim/Services/HypergridService/UserAgentService.cs b/OpenSim/Services/HypergridService/UserAgentService.cs index 85386602d5..f681df4243 100644 --- a/OpenSim/Services/HypergridService/UserAgentService.cs +++ b/OpenSim/Services/HypergridService/UserAgentService.cs @@ -488,6 +488,31 @@ namespace OpenSim.Services.HypergridService return online; } + public Dictionary GetUserInfo(UUID userID) + { + Dictionary info = new Dictionary(); + + if (m_UserAccountService == null) + { + m_log.WarnFormat("[USER AGENT SERVICE]: Unable to get user flags because user account service is missing"); + info["result"] = "fail"; + info["message"] = "UserAccountService is missing!"; + return info; + } + + UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero /*!!!*/, userID); + + if (account != null) + { + info.Add("user_flags", (object)account.UserFlags); + info.Add("user_created", (object)account.Created); + info.Add("user_title", (object)account.UserTitle); + info.Add("result", "success"); + } + + return info; + } + public Dictionary GetServerURLs(UUID userID) { if (m_UserAccountService == null) diff --git a/OpenSim/Services/Interfaces/IHypergridServices.cs b/OpenSim/Services/Interfaces/IHypergridServices.cs index e86ec519e5..5b293acbee 100644 --- a/OpenSim/Services/Interfaces/IHypergridServices.cs +++ b/OpenSim/Services/Interfaces/IHypergridServices.cs @@ -55,6 +55,7 @@ namespace OpenSim.Services.Interfaces void LogoutAgent(UUID userID, UUID sessionID); GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt); Dictionary GetServerURLs(UUID userID); + Dictionary GetUserInfo(UUID userID); string LocateUser(UUID userID); // Tries to get the universal user identifier for the targetUserId