aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs
diff options
context:
space:
mode:
authorDiva Canto2011-05-19 16:54:46 -0700
committerDiva Canto2011-05-19 16:54:46 -0700
commitd21e9c755f004d8fe03b11bc57b810dbd401435a (patch)
tree1efd9e48308192d21ca73d8ff12d6a48c186077c /OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs
parentAccidentally committed too early (diff)
downloadopensim-SC-d21e9c755f004d8fe03b11bc57b810dbd401435a.zip
opensim-SC-d21e9c755f004d8fe03b11bc57b810dbd401435a.tar.gz
opensim-SC-d21e9c755f004d8fe03b11bc57b810dbd401435a.tar.bz2
opensim-SC-d21e9c755f004d8fe03b11bc57b810dbd401435a.tar.xz
HG Friends working to some extent: friendships offered and accepted correctly handled. Friends list showing correct foreign names. TODO: GrantRights.
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs175
1 files changed, 175 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs
new file mode 100644
index 0000000..76f5f19
--- /dev/null
+++ b/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs
@@ -0,0 +1,175 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using log4net;
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Services.Interfaces;
36using OpenSim.Services.Connectors.Friends;
37using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
38using OpenSim.Server.Base;
39using OpenMetaverse;
40
41namespace OpenSim.Services.Connectors.Hypergrid
42{
43 public class HGFriendsServicesConnector
44 {
45 private static readonly ILog m_log =
46 LogManager.GetLogger(
47 MethodBase.GetCurrentMethod().DeclaringType);
48
49 private string m_ServerURI = String.Empty;
50 private string m_ServiceKey = String.Empty;
51 private UUID m_SessionID;
52
53 public HGFriendsServicesConnector()
54 {
55 }
56
57 public HGFriendsServicesConnector(string serverURI, UUID sessionID, string serviceKey)
58 {
59 m_ServerURI = serverURI.TrimEnd('/');
60 m_ServiceKey = serviceKey;
61 m_SessionID = sessionID;
62 }
63
64 #region IFriendsService
65
66 public FriendInfo[] GetFriends(UUID PrincipalID)
67 {
68 Dictionary<string, object> sendData = new Dictionary<string, object>();
69
70 sendData["PRINCIPALID"] = PrincipalID.ToString();
71 sendData["METHOD"] = "getfriends";
72 sendData["KEY"] = m_ServiceKey;
73 sendData["SESSIONID"] = m_SessionID.ToString();
74
75 string reqString = ServerUtils.BuildQueryString(sendData);
76
77 try
78 {
79 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
80 m_ServerURI + "/hgfriends",
81 reqString);
82 if (reply != string.Empty)
83 {
84 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
85
86 if (replyData != null)
87 {
88 if (replyData.ContainsKey("result") && (replyData["result"].ToString().ToLower() == "null"))
89 {
90 return new FriendInfo[0];
91 }
92
93 List<FriendInfo> finfos = new List<FriendInfo>();
94 Dictionary<string, object>.ValueCollection finfosList = replyData.Values;
95 //m_log.DebugFormat("[FRIENDS CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count);
96 foreach (object f in finfosList)
97 {
98 if (f is Dictionary<string, object>)
99 {
100 FriendInfo finfo = new FriendInfo((Dictionary<string, object>)f);
101 finfos.Add(finfo);
102 }
103 else
104 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: GetFriends {0} received invalid response type {1}",
105 PrincipalID, f.GetType());
106 }
107
108 // Success
109 return finfos.ToArray();
110 }
111
112 else
113 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: GetFriends {0} received null response",
114 PrincipalID);
115
116 }
117 }
118 catch (Exception e)
119 {
120 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server: {0}", e.Message);
121 }
122
123 return new FriendInfo[0];
124
125 }
126
127 public bool NewFriendship(UUID PrincipalID, string Friend)
128 {
129 FriendInfo finfo = new FriendInfo();
130 finfo.PrincipalID = PrincipalID;
131 finfo.Friend = Friend;
132
133 Dictionary<string, object> sendData = finfo.ToKeyValuePairs();
134
135 sendData["METHOD"] = "newfriendship";
136 sendData["KEY"] = m_ServiceKey;
137 sendData["SESSIONID"] = m_SessionID.ToString();
138
139 string reply = string.Empty;
140 try
141 {
142 reply = SynchronousRestFormsRequester.MakeRequest("POST",
143 m_ServerURI + "/hgfriends",
144 ServerUtils.BuildQueryString(sendData));
145 }
146 catch (Exception e)
147 {
148 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server: {0}", e.Message);
149 return false;
150 }
151
152 if (reply != string.Empty)
153 {
154 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
155
156 if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null))
157 {
158 bool success = false;
159 Boolean.TryParse(replyData["Result"].ToString(), out success);
160 return success;
161 }
162 else
163 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: StoreFriend {0} {1} received null response",
164 PrincipalID, Friend);
165 }
166 else
167 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: StoreFriend received null reply");
168
169 return false;
170
171 }
172
173 #endregion
174 }
175} \ No newline at end of file