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. --- .../Connectors/Friends/FriendsSimConnector.cs | 20 ++++++- .../Hypergrid/HGFriendsServiceConnector.cs | 67 +++++++++++++++++++--- 2 files changed, 76 insertions(+), 11 deletions(-) (limited to 'OpenSim/Services/Connectors') diff --git a/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs b/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs index eea9853..3fd0c53 100644 --- a/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs +++ b/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs @@ -43,8 +43,18 @@ namespace OpenSim.Services.Connectors.Friends { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + protected virtual string ServicePath() + { + return "friends"; + } + public bool FriendshipOffered(GridRegion region, UUID userID, UUID friendID, string message) { + return FriendshipOffered(region, userID, friendID, message, String.Empty); + } + + public virtual bool FriendshipOffered(GridRegion region, UUID userID, UUID friendID, string message, string userName) + { Dictionary sendData = new Dictionary(); //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); @@ -53,9 +63,10 @@ namespace OpenSim.Services.Connectors.Friends sendData["FromID"] = userID.ToString(); sendData["ToID"] = friendID.ToString(); sendData["Message"] = message; + if (userName != String.Empty) + sendData["FromName"] = userName; return Call(region, sendData); - } public bool FriendshipApproved(GridRegion region, UUID userID, string userName, UUID friendID) @@ -138,8 +149,11 @@ namespace OpenSim.Services.Connectors.Friends if (region == null) return false; - m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: region: {0}", region.ExternalHostName + ":" + region.HttpPort); - string uri = "http://" + region.ExternalHostName + ":" + region.HttpPort + "/friends"; + string path = ServicePath(); + if (!region.ServerURI.EndsWith("/")) + path = "/" + path; + string uri = region.ServerURI + path; + m_log.DebugFormat("[FRIENDS SIM CONNECTOR]: calling {0}", uri); try { diff --git a/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs index af4b0da..e3f3260 100644 --- a/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs +++ b/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs @@ -40,7 +40,7 @@ using OpenMetaverse; namespace OpenSim.Services.Connectors.Hypergrid { - public class HGFriendsServicesConnector + public class HGFriendsServicesConnector : FriendsSimConnector { private static readonly ILog m_log = LogManager.GetLogger( @@ -66,6 +66,11 @@ namespace OpenSim.Services.Connectors.Hypergrid m_SessionID = sessionID; } + protected override string ServicePath() + { + return "hgfriends"; + } + #region IFriendsService public uint GetFriendPerms(UUID PrincipalID, UUID friendID) @@ -187,23 +192,69 @@ namespace OpenSim.Services.Connectors.Hypergrid { Dictionary replyData = ServerUtils.ParseXmlResponse(reply); - if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null)) + if (replyData.ContainsKey("RESULT")) { - bool success = false; - Boolean.TryParse(replyData["Result"].ToString(), out success); - return success; + if (replyData["RESULT"].ToString().ToLower() == "true") + return true; + else + return false; } else - m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Delete {0} {1} received null response", - PrincipalID, Friend); + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: reply data does not contain result field"); + } else - m_log.DebugFormat("[HGFRIENDS CONNECTOR]: DeleteFriend received null reply"); + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: received empty reply"); return false; } + public bool ValidateFriendshipOffered(UUID fromID, UUID toID) + { + FriendInfo finfo = new FriendInfo(); + finfo.PrincipalID = fromID; + finfo.Friend = toID.ToString(); + + Dictionary sendData = finfo.ToKeyValuePairs(); + + sendData["METHOD"] = "validate_friendship_offered"; + + string reply = string.Empty; + string uri = m_ServerURI + "/hgfriends"; + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + uri, + ServerUtils.BuildQueryString(sendData)); + } + catch (Exception e) + { + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); + return false; + } + + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.ContainsKey("RESULT")) + { + if (replyData["RESULT"].ToString().ToLower() == "true") + return true; + else + return false; + } + else + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: reply data does not contain result field"); + + } + else + m_log.DebugFormat("[HGFRIENDS CONNECTOR]: received empty reply"); + + return false; + + } #endregion } } \ No newline at end of file -- cgit v1.1