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. --- .../Hypergrid/HGFriendsServerPostHandler.cs | 159 +++++++++++++++------ 1 file changed, 112 insertions(+), 47 deletions(-) (limited to 'OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs') 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 } } -- cgit v1.1 From 8ad426f329299ecb702189b1d56ffe7be186bd58 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 21 Mar 2012 08:08:43 -0700 Subject: Removed extraneous debug message --- OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs | 1 - 1 file changed, 1 deletion(-) (limited to 'OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs') diff --git a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs index ca566f2..e0876cd 100644 --- a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs @@ -197,7 +197,6 @@ namespace OpenSim.Server.Handlers.Hypergrid 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); -- cgit v1.1 From 4a9ca3ca8ff18f4fcf05c3983db5e6b1d49c97ee Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 21 Mar 2012 10:35:06 -0700 Subject: HG Friends: reroute the status notifications to the HGFriends service, so that they can scale better. They were previously being handled by the UAS; that is still there, but it's now obsolete and will be removed in a future release. --- .../Hypergrid/HGFriendsServerPostHandler.cs | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs') diff --git a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs index e0876cd..8ef03e7 100644 --- a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs @@ -105,6 +105,9 @@ namespace OpenSim.Server.Handlers.Hypergrid case "validate_friendship_offered": return ValidateFriendshipOffered(request); + + case "statusnotification": + return StatusNotification(request); /* case "friendship_approved": return FriendshipApproved(request); @@ -228,6 +231,59 @@ namespace OpenSim.Server.Handlers.Hypergrid return BoolResult(success); } + byte[] StatusNotification(Dictionary request) + { + UUID principalID = UUID.Zero; + if (request.ContainsKey("userID")) + UUID.TryParse(request["userID"].ToString(), out principalID); + else + { + m_log.WarnFormat("[HGFRIENDS HANDLER]: no userID in request to notify"); + return FailureResult(); + } + + bool online = true; + if (request.ContainsKey("online")) + Boolean.TryParse(request["online"].ToString(), out online); + else + { + m_log.WarnFormat("[HGFRIENDS HANDLER]: no online in request to notify"); + return FailureResult(); + } + + List friends = new List(); + int i = 0; + foreach (KeyValuePair kvp in request) + { + if (kvp.Key.Equals("friend_" + i.ToString())) + { + friends.Add(kvp.Value.ToString()); + i++; + } + } + + List onlineFriends = m_TheService.StatusNotification(friends, principalID, online); + + Dictionary result = new Dictionary(); + if ((onlineFriends == null) || ((onlineFriends != null) && (onlineFriends.Count == 0))) + result["RESULT"] = "NULL"; + else + { + i = 0; + foreach (UUID f in onlineFriends) + { + result["friend_" + i] = f.ToString(); + i++; + } + } + + string xmlString = ServerUtils.BuildXmlResponse(result); + //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); + UTF8Encoding encoding = new UTF8Encoding(); + return encoding.GetBytes(xmlString); + + } + #endregion -- cgit v1.1