From d08ad6459a03a6a5a6a551fd2b275f1c7da94d8e Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Tue, 20 Mar 2012 17:14:19 -0700 Subject: HG Friends: allow the establishment of HG friendships without requiring co-presence in the same sim. Using avatar picker, users can now search for names such as "first.last@grid.com:9000", find them, and request friendship. Friendship requests are stored if target user is offline. TESTED ON STANDALONE ONLY. --- .../Handlers/Hypergrid/HGFriendServerConnector.cs | 26 ++-- .../Hypergrid/HGFriendsServerPostHandler.cs | 159 +++++++++++++++------ .../Handlers/Hypergrid/UserAgentServerConnector.cs | 5 + 3 files changed, 133 insertions(+), 57 deletions(-) (limited to 'OpenSim/Server/Handlers') diff --git a/OpenSim/Server/Handlers/Hypergrid/HGFriendServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/HGFriendServerConnector.cs index 82a7220..6c79c60 100644 --- a/OpenSim/Server/Handlers/Hypergrid/HGFriendServerConnector.cs +++ b/OpenSim/Server/Handlers/Hypergrid/HGFriendServerConnector.cs @@ -36,36 +36,42 @@ namespace OpenSim.Server.Handlers.Hypergrid { public class HGFriendsServerConnector : ServiceConnector { - private IFriendsService m_FriendsService; private IUserAgentService m_UserAgentService; + private IHGFriendsService m_TheService; private string m_ConfigName = "HGFriendsService"; + // Called from Robust public HGFriendsServerConnector(IConfigSource config, IHttpServer server, string configName) : - base(config, server, configName) + this(config, server, configName, null) { - if (configName != string.Empty) + + } + + // Called from standalone configurations + public HGFriendsServerConnector(IConfigSource config, IHttpServer server, string configName, IFriendsSimConnector localConn) + : base(config, server, configName) + { + if (configName != string.Empty) m_ConfigName = configName; + Object[] args = new Object[] { config, m_ConfigName, localConn }; + IConfig serverConfig = config.Configs[m_ConfigName]; if (serverConfig == null) throw new Exception(String.Format("No section {0} in config file", m_ConfigName)); string theService = serverConfig.GetString("LocalServiceModule", String.Empty); - if (theService == String.Empty) throw new Exception("No LocalServiceModule in config file"); - - Object[] args = new Object[] { config }; - m_FriendsService = ServerUtils.LoadPlugin(theService, args); + m_TheService = ServerUtils.LoadPlugin(theService, args); theService = serverConfig.GetString("UserAgentService", string.Empty); if (theService == String.Empty) throw new Exception("No UserAgentService in " + m_ConfigName); + m_UserAgentService = ServerUtils.LoadPlugin(theService, new Object[] { config, localConn }); - m_UserAgentService = ServerUtils.LoadPlugin(theService, args); - - server.AddStreamHandler(new HGFriendsServerPostHandler(m_FriendsService, m_UserAgentService)); + server.AddStreamHandler(new HGFriendsServerPostHandler(m_TheService, m_UserAgentService, localConn)); } } } diff --git a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs index 661507e..ca566f2 100644 --- a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs @@ -39,6 +39,7 @@ using System.Collections.Generic; using OpenSim.Server.Base; using OpenSim.Services.Interfaces; using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; using OpenSim.Framework; using OpenSim.Framework.Servers.HttpServer; using OpenMetaverse; @@ -49,15 +50,22 @@ namespace OpenSim.Server.Handlers.Hypergrid { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private IFriendsService m_FriendsService; private IUserAgentService m_UserAgentService; + private IFriendsSimConnector m_FriendsLocalSimConnector; + private IHGFriendsService m_TheService; - public HGFriendsServerPostHandler(IFriendsService service, IUserAgentService uservice) : + public HGFriendsServerPostHandler(IHGFriendsService service, IUserAgentService uas, IFriendsSimConnector friendsConn) : base("POST", "/hgfriends") { - m_FriendsService = service; - m_UserAgentService = uservice; - m_log.DebugFormat("[HGFRIENDS HANDLER]: HGFriendsServerPostHandler is On"); + m_TheService = service; + m_UserAgentService = uas; + m_FriendsLocalSimConnector = friendsConn; + + m_log.DebugFormat("[HGFRIENDS HANDLER]: HGFriendsServerPostHandler is On ({0})", + (m_FriendsLocalSimConnector == null ? "robust" : "standalone")); + + if (m_TheService == null) + m_log.ErrorFormat("[HGFRIENDS HANDLER]: TheService is null!"); } public override byte[] Handle(string path, Stream requestData, @@ -90,6 +98,26 @@ namespace OpenSim.Server.Handlers.Hypergrid case "deletefriendship": return DeleteFriendship(request); + + /* Same as inter-sim */ + case "friendship_offered": + return FriendshipOffered(request); + + case "validate_friendship_offered": + return ValidateFriendshipOffered(request); + /* + case "friendship_approved": + return FriendshipApproved(request); + + case "friendship_denied": + return FriendshipDenied(request); + + case "friendship_terminated": + return FriendshipTerminated(request); + + case "grant_rights": + return GrantRights(request); + */ } m_log.DebugFormat("[HGFRIENDS HANDLER]: unknown method {0} request {1}", method.Length, method); } @@ -126,39 +154,20 @@ namespace OpenSim.Server.Handlers.Hypergrid return FailureResult(); } - FriendInfo[] friendsInfo = m_FriendsService.GetFriends(principalID); - foreach (FriendInfo finfo in friendsInfo) - { - if (finfo.Friend.StartsWith(friendID.ToString())) - return SuccessResult(finfo.TheirFlags.ToString()); - } + int perms = m_TheService.GetFriendPerms(principalID, friendID); + if (perms < 0) + return FailureResult("Friend not found"); - return FailureResult("Friend not found"); + return SuccessResult(perms.ToString()); } byte[] NewFriendship(Dictionary request) { - if (!VerifyServiceKey(request)) - return FailureResult(); + bool verified = VerifyServiceKey(request); - // OK, can proceed FriendInfo friend = new FriendInfo(request); - UUID friendID; - string tmp = string.Empty; - if (!Util.ParseUniversalUserIdentifier(friend.Friend, out friendID, out tmp, out tmp, out tmp, out tmp)) - return FailureResult(); - - m_log.DebugFormat("[HGFRIENDS HANDLER]: New friendship {0} {1}", friend.PrincipalID, friend.Friend); - - // If the friendship already exists, return fail - FriendInfo[] finfos = m_FriendsService.GetFriends(friend.PrincipalID); - foreach (FriendInfo finfo in finfos) - if (finfo.Friend.StartsWith(friendID.ToString())) - return FailureResult(); - - // the user needs to confirm when he gets home - bool success = m_FriendsService.StoreFriend(friend.PrincipalID.ToString(), friend.Friend, 0); + bool success = m_TheService.NewFriendship(friend, verified); if (success) return SuccessResult(); @@ -174,25 +183,53 @@ namespace OpenSim.Server.Handlers.Hypergrid secret = request["SECRET"].ToString(); if (secret == string.Empty) - return FailureResult(); + return BoolResult(false); - FriendInfo[] finfos = m_FriendsService.GetFriends(friend.PrincipalID); - foreach (FriendInfo finfo in finfos) - { - // We check the secret here - if (finfo.Friend.StartsWith(friend.Friend) && finfo.Friend.EndsWith(secret)) - { - m_log.DebugFormat("[HGFRIENDS HANDLER]: Delete friendship {0} {1}", friend.PrincipalID, friend.Friend); - m_FriendsService.Delete(friend.PrincipalID, finfo.Friend); - m_FriendsService.Delete(finfo.Friend, friend.PrincipalID.ToString()); + bool success = m_TheService.DeleteFriendship(friend, secret); - return SuccessResult(); - } - } + return BoolResult(success); + } - return FailureResult(); + byte[] FriendshipOffered(Dictionary request) + { + UUID fromID = UUID.Zero; + UUID toID = UUID.Zero; + string message = string.Empty; + string name = string.Empty; + + m_log.DebugFormat("[HGFRIENDS HANDLER]: Friendship offered"); + if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID")) + return BoolResult(false); + + if (!UUID.TryParse(request["ToID"].ToString(), out toID)) + return BoolResult(false); + + message = request["Message"].ToString(); + + if (!UUID.TryParse(request["FromID"].ToString(), out fromID)) + return BoolResult(false); + + if (request.ContainsKey("FromName")) + name = request["FromName"].ToString(); + + bool success = m_TheService.FriendshipOffered(fromID, name, toID, message); + + return BoolResult(success); } + byte[] ValidateFriendshipOffered(Dictionary request) + { + FriendInfo friend = new FriendInfo(request); + UUID friendID = UUID.Zero; + if (!UUID.TryParse(friend.Friend, out friendID)) + return BoolResult(false); + + bool success = m_TheService.ValidateFriendshipOffered(friend.PrincipalID, friendID); + + return BoolResult(success); + } + + #endregion #region Misc @@ -205,10 +242,15 @@ namespace OpenSim.Server.Handlers.Hypergrid return false; } + if (request["KEY"] == null || request["SESSIONID"] == null) + return false; + string serviceKey = request["KEY"].ToString(); string sessionStr = request["SESSIONID"].ToString(); + UUID sessionID; - UUID.TryParse(sessionStr, out sessionID); + if (!UUID.TryParse(sessionStr, out sessionID) || serviceKey == string.Empty) + return false; if (!m_UserAgentService.VerifyAgent(sessionID, serviceKey)) { @@ -256,7 +298,7 @@ namespace OpenSim.Server.Handlers.Hypergrid doc.AppendChild(rootElement); - XmlElement result = doc.CreateElement("", "Result", ""); + XmlElement result = doc.CreateElement("", "RESULT", ""); result.AppendChild(doc.CreateTextNode("Success")); rootElement.AppendChild(result); @@ -289,7 +331,7 @@ namespace OpenSim.Server.Handlers.Hypergrid doc.AppendChild(rootElement); - XmlElement result = doc.CreateElement("", "Result", ""); + XmlElement result = doc.CreateElement("", "RESULT", ""); result.AppendChild(doc.CreateTextNode("Failure")); rootElement.AppendChild(result); @@ -302,6 +344,28 @@ namespace OpenSim.Server.Handlers.Hypergrid return DocToBytes(doc); } + private byte[] BoolResult(bool value) + { + XmlDocument doc = new XmlDocument(); + + XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, + "", ""); + + doc.AppendChild(xmlnode); + + XmlElement rootElement = doc.CreateElement("", "ServerResponse", + ""); + + doc.AppendChild(rootElement); + + XmlElement result = doc.CreateElement("", "RESULT", ""); + result.AppendChild(doc.CreateTextNode(value.ToString())); + + rootElement.AppendChild(result); + + return DocToBytes(doc); + } + private byte[] DocToBytes(XmlDocument doc) { MemoryStream ms = new MemoryStream(); @@ -313,6 +377,7 @@ namespace OpenSim.Server.Handlers.Hypergrid return ms.ToArray(); } + #endregion } } diff --git a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs index 7348368..9a0e27e 100644 --- a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs +++ b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs @@ -52,6 +52,11 @@ namespace OpenSim.Server.Handlers.Hypergrid // MethodBase.GetCurrentMethod().DeclaringType); private IUserAgentService m_HomeUsersService; + public IUserAgentService HomeUsersService + { + get { return m_HomeUsersService; } + } + private string[] m_AuthorizedCallers; private bool m_VerifyCallers = false; -- cgit v1.1