From 58c53c41de2cae0bb041a2e8121792e136d1edb2 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 21 May 2011 16:48:00 -0700 Subject: Fixed permissions bug related to friends in PermissionsModule. Added FriendsData[] GetFriends(string principalID) to IFriendsData and FriendInfo[] GetFriends(string PrincipalID) to IFriendsService. Refactored some more in the FriendsModule. Made client get notification of local friends permissions upon HGLogin. HG Friends object permissions work. --- .../Handlers/Friends/FriendsServerPostHandler.cs | 23 ++++- .../Hypergrid/HGFriendsServerPostHandler.cs | 112 ++++++++++++++------- 2 files changed, 97 insertions(+), 38 deletions(-) (limited to 'OpenSim/Server') diff --git a/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs index 64002e1..71c3c73 100644 --- a/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs @@ -82,6 +82,9 @@ namespace OpenSim.Server.Handlers.Friends case "getfriends": return GetFriends(request); + case "getfriends_string": + return GetFriendsString(request); + case "storefriend": return StoreFriend(request); @@ -111,7 +114,25 @@ namespace OpenSim.Server.Handlers.Friends m_log.WarnFormat("[FRIENDS HANDLER]: no principalID in request to get friends"); FriendInfo[] finfos = m_FriendsService.GetFriends(principalID); - //m_log.DebugFormat("[FRIENDS HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count); + + return PackageFriends(finfos); + } + + byte[] GetFriendsString(Dictionary request) + { + string principalID = string.Empty; + if (request.ContainsKey("PRINCIPALID")) + principalID = request["PRINCIPALID"].ToString(); + else + m_log.WarnFormat("[FRIENDS HANDLER]: no principalID in request to get friends"); + + FriendInfo[] finfos = m_FriendsService.GetFriends(principalID); + + return PackageFriends(finfos); + } + + private byte[] PackageFriends(FriendInfo[] finfos) + { Dictionary result = new Dictionary(); if ((finfos == null) || ((finfos != null) && (finfos.Length == 0))) diff --git a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs index 13d1502..dde7875 100644 --- a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs @@ -82,8 +82,8 @@ namespace OpenSim.Server.Handlers.Hypergrid switch (method) { - case "getfriends": - return GetFriends(request); + case "getfriendperms": + return GetFriendPerms(request); case "newfriendship": return NewFriendship(request); @@ -102,58 +102,45 @@ namespace OpenSim.Server.Handlers.Hypergrid #region Method-specific handlers - byte[] GetFriends(Dictionary request) + byte[] GetFriendPerms(Dictionary request) { + if (!VerifyServiceKey(request)) + return FailureResult(); + UUID principalID = UUID.Zero; if (request.ContainsKey("PRINCIPALID")) UUID.TryParse(request["PRINCIPALID"].ToString(), out principalID); else - m_log.WarnFormat("[HGFRIENDS HANDLER]: no principalID in request to get friends"); - - FriendInfo[] finfos = m_FriendsService.GetFriends(principalID); - //m_log.DebugFormat("[FRIENDS HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count); + { + m_log.WarnFormat("[HGFRIENDS HANDLER]: no principalID in request to get friend perms"); + return FailureResult(); + } - Dictionary result = new Dictionary(); - if ((finfos == null) || ((finfos != null) && (finfos.Length == 0))) - result["result"] = "null"; + UUID friendID = UUID.Zero; + if (request.ContainsKey("FRIENDID")) + UUID.TryParse(request["FRIENDID"].ToString(), out friendID); else { - int i = 0; - foreach (FriendInfo finfo in finfos) - { - Dictionary rinfoDict = finfo.ToKeyValuePairs(); - result["friend" + i] = rinfoDict; - i++; - } + m_log.WarnFormat("[HGFRIENDS HANDLER]: no friendID in request to get friend perms"); + return FailureResult(); } - string xmlString = ServerUtils.BuildXmlResponse(result); - //m_log.DebugFormat("[FRIENDS HANDLER]: resp string: {0}", xmlString); - UTF8Encoding encoding = new UTF8Encoding(); - return encoding.GetBytes(xmlString); + string perms = "0"; + FriendInfo[] friendsInfo = m_FriendsService.GetFriends(principalID); + foreach (FriendInfo finfo in friendsInfo) + { + if (finfo.Friend.StartsWith(friendID.ToString())) + return SuccessResult(finfo.TheirFlags.ToString()); + } + return FailureResult("Friend not found"); } byte[] NewFriendship(Dictionary request) { - if (!request.ContainsKey("KEY") || !request.ContainsKey("SESSIONID")) - { - m_log.WarnFormat("[HGFRIENDS HANDLER]: ignoring request without Key or SessionID"); - return FailureResult(); - } - - string serviceKey = request["KEY"].ToString(); - string sessionStr = request["SESSIONID"].ToString(); - UUID sessionID; - UUID.TryParse(sessionStr, out sessionID); - - if (!m_UserAgentService.VerifyAgent(sessionID, serviceKey)) - { - m_log.WarnFormat("[HGFRIENDS HANDLER]: Key {0} for session {1} did not match existing key. Ignoring request", serviceKey, sessionID); + if (!VerifyServiceKey(request)) return FailureResult(); - } - m_log.DebugFormat("[XXX] Verification ok"); // OK, can proceed FriendInfo friend = new FriendInfo(request); @@ -172,6 +159,29 @@ namespace OpenSim.Server.Handlers.Hypergrid #region Misc + private bool VerifyServiceKey(Dictionary request) + { + if (!request.ContainsKey("KEY") || !request.ContainsKey("SESSIONID")) + { + m_log.WarnFormat("[HGFRIENDS HANDLER]: ignoring request without Key or SessionID"); + return false; + } + + string serviceKey = request["KEY"].ToString(); + string sessionStr = request["SESSIONID"].ToString(); + UUID sessionID; + UUID.TryParse(sessionStr, out sessionID); + + if (!m_UserAgentService.VerifyAgent(sessionID, serviceKey)) + { + m_log.WarnFormat("[HGFRIENDS HANDLER]: Key {0} for session {1} did not match existing key. Ignoring request", serviceKey, sessionID); + return false; + } + + m_log.DebugFormat("[XXX] Verification ok"); + return true; + } + private byte[] SuccessResult() { XmlDocument doc = new XmlDocument(); @@ -194,6 +204,34 @@ namespace OpenSim.Server.Handlers.Hypergrid return DocToBytes(doc); } + private byte[] SuccessResult(string 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("Success")); + + rootElement.AppendChild(result); + + XmlElement message = doc.CreateElement("", "Value", ""); + message.AppendChild(doc.CreateTextNode(value)); + + rootElement.AppendChild(message); + + return DocToBytes(doc); + } + + private byte[] FailureResult() { return FailureResult(String.Empty); -- cgit v1.1