aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Hypergrid/HGFriendsServicesConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/Connectors/Hypergrid/HGFriendsServicesConnector.cs')
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/HGFriendsServicesConnector.cs312
1 files changed, 312 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Hypergrid/HGFriendsServicesConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HGFriendsServicesConnector.cs
new file mode 100644
index 0000000..e984a54
--- /dev/null
+++ b/OpenSim/Services/Connectors/Hypergrid/HGFriendsServicesConnector.cs
@@ -0,0 +1,312 @@
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 : FriendsSimConnector
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)
58 {
59 m_ServerURI = serverURI.TrimEnd('/');
60 }
61
62 public HGFriendsServicesConnector(string serverURI, UUID sessionID, string serviceKey)
63 {
64 m_ServerURI = serverURI.TrimEnd('/');
65 m_ServiceKey = serviceKey;
66 m_SessionID = sessionID;
67 }
68
69 protected override string ServicePath()
70 {
71 return "hgfriends";
72 }
73
74 #region IFriendsService
75
76 public uint GetFriendPerms(UUID PrincipalID, UUID friendID)
77 {
78 Dictionary<string, object> sendData = new Dictionary<string, object>();
79
80 sendData["PRINCIPALID"] = PrincipalID.ToString();
81 sendData["FRIENDID"] = friendID.ToString();
82 sendData["METHOD"] = "getfriendperms";
83 sendData["KEY"] = m_ServiceKey;
84 sendData["SESSIONID"] = m_SessionID.ToString();
85
86 string reqString = ServerUtils.BuildQueryString(sendData);
87 string uri = m_ServerURI + "/hgfriends";
88
89 try
90 {
91 string reply = SynchronousRestFormsRequester.MakeRequest("POST",
92 uri,
93 reqString);
94 if (reply != string.Empty)
95 {
96 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
97
98 if ((replyData != null) && replyData.ContainsKey("Value") && (replyData["Value"] != null))
99 {
100 uint perms = 0;
101 uint.TryParse(replyData["Value"].ToString(), out perms);
102 return perms;
103 }
104 else
105 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: GetFriendPerms {0} received null response",
106 PrincipalID);
107
108 }
109 }
110 catch (Exception e)
111 {
112 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message);
113 }
114
115 return 0;
116
117 }
118
119 public bool NewFriendship(UUID PrincipalID, string Friend)
120 {
121 FriendInfo finfo = new FriendInfo();
122 finfo.PrincipalID = PrincipalID;
123 finfo.Friend = Friend;
124
125 Dictionary<string, object> sendData = finfo.ToKeyValuePairs();
126
127 sendData["METHOD"] = "newfriendship";
128 sendData["KEY"] = m_ServiceKey;
129 sendData["SESSIONID"] = m_SessionID.ToString();
130
131 string reply = string.Empty;
132 string uri = m_ServerURI + "/hgfriends";
133 try
134 {
135 reply = SynchronousRestFormsRequester.MakeRequest("POST",
136 uri,
137 ServerUtils.BuildQueryString(sendData));
138 }
139 catch (Exception e)
140 {
141 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message);
142 return false;
143 }
144
145 if (reply != string.Empty)
146 {
147 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
148
149 if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null))
150 {
151 bool success = false;
152 Boolean.TryParse(replyData["Result"].ToString(), out success);
153 return success;
154 }
155 else
156 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: StoreFriend {0} {1} received null response",
157 PrincipalID, Friend);
158 }
159 else
160 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: StoreFriend received null reply");
161
162 return false;
163
164 }
165
166 public bool DeleteFriendship(UUID PrincipalID, UUID Friend, string secret)
167 {
168 FriendInfo finfo = new FriendInfo();
169 finfo.PrincipalID = PrincipalID;
170 finfo.Friend = Friend.ToString();
171
172 Dictionary<string, object> sendData = finfo.ToKeyValuePairs();
173
174 sendData["METHOD"] = "deletefriendship";
175 sendData["SECRET"] = secret;
176
177 string reply = string.Empty;
178 string uri = m_ServerURI + "/hgfriends";
179 try
180 {
181 reply = SynchronousRestFormsRequester.MakeRequest("POST",
182 uri,
183 ServerUtils.BuildQueryString(sendData));
184 }
185 catch (Exception e)
186 {
187 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message);
188 return false;
189 }
190
191 if (reply != string.Empty)
192 {
193 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
194
195 if (replyData.ContainsKey("RESULT"))
196 {
197 if (replyData["RESULT"].ToString().ToLower() == "true")
198 return true;
199 else
200 return false;
201 }
202 else
203 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: reply data does not contain result field");
204
205 }
206 else
207 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: received empty reply");
208
209 return false;
210
211 }
212
213 public bool ValidateFriendshipOffered(UUID fromID, UUID toID)
214 {
215 FriendInfo finfo = new FriendInfo();
216 finfo.PrincipalID = fromID;
217 finfo.Friend = toID.ToString();
218
219 Dictionary<string, object> sendData = finfo.ToKeyValuePairs();
220
221 sendData["METHOD"] = "validate_friendship_offered";
222
223 string reply = string.Empty;
224 string uri = m_ServerURI + "/hgfriends";
225 try
226 {
227 reply = SynchronousRestFormsRequester.MakeRequest("POST",
228 uri,
229 ServerUtils.BuildQueryString(sendData));
230 }
231 catch (Exception e)
232 {
233 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message);
234 return false;
235 }
236
237 if (reply != string.Empty)
238 {
239 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
240
241 if (replyData.ContainsKey("RESULT"))
242 {
243 if (replyData["RESULT"].ToString().ToLower() == "true")
244 return true;
245 else
246 return false;
247 }
248 else
249 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: reply data does not contain result field");
250
251 }
252 else
253 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: received empty reply");
254
255 return false;
256
257 }
258
259 public List<UUID> StatusNotification(List<string> friends, UUID userID, bool online)
260 {
261 Dictionary<string, object> sendData = new Dictionary<string, object>();
262 List<UUID> friendsOnline = new List<UUID>();
263
264 sendData["METHOD"] = "statusnotification";
265 sendData["userID"] = userID.ToString();
266 sendData["online"] = online.ToString();
267 int i = 0;
268 foreach (string s in friends)
269 {
270 sendData["friend_" + i.ToString()] = s;
271 i++;
272 }
273
274 string reply = string.Empty;
275 string uri = m_ServerURI + "/hgfriends";
276 try
277 {
278 reply = SynchronousRestFormsRequester.MakeRequest("POST",
279 uri,
280 ServerUtils.BuildQueryString(sendData));
281 }
282 catch (Exception e)
283 {
284 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message);
285 return friendsOnline;
286 }
287
288 if (reply != string.Empty)
289 {
290 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
291
292 // Here is the actual response
293 foreach (string key in replyData.Keys)
294 {
295 if (key.StartsWith("friend_") && replyData[key] != null)
296 {
297 UUID uuid;
298 if (UUID.TryParse(replyData[key].ToString(), out uuid))
299 friendsOnline.Add(uuid);
300 }
301 }
302 }
303 else
304 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Received empty reply from remote StatusNotify");
305
306 return friendsOnline;
307
308 }
309
310 #endregion
311 }
312} \ No newline at end of file