diff options
Diffstat (limited to 'OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs')
-rw-r--r-- | OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs | 119 |
1 files changed, 111 insertions, 8 deletions
diff --git a/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs index af4b0da..e984a54 100644 --- a/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs +++ b/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs | |||
@@ -40,7 +40,7 @@ using OpenMetaverse; | |||
40 | 40 | ||
41 | namespace OpenSim.Services.Connectors.Hypergrid | 41 | namespace OpenSim.Services.Connectors.Hypergrid |
42 | { | 42 | { |
43 | public class HGFriendsServicesConnector | 43 | public class HGFriendsServicesConnector : FriendsSimConnector |
44 | { | 44 | { |
45 | private static readonly ILog m_log = | 45 | private static readonly ILog m_log = |
46 | LogManager.GetLogger( | 46 | LogManager.GetLogger( |
@@ -66,6 +66,11 @@ namespace OpenSim.Services.Connectors.Hypergrid | |||
66 | m_SessionID = sessionID; | 66 | m_SessionID = sessionID; |
67 | } | 67 | } |
68 | 68 | ||
69 | protected override string ServicePath() | ||
70 | { | ||
71 | return "hgfriends"; | ||
72 | } | ||
73 | |||
69 | #region IFriendsService | 74 | #region IFriendsService |
70 | 75 | ||
71 | public uint GetFriendPerms(UUID PrincipalID, UUID friendID) | 76 | public uint GetFriendPerms(UUID PrincipalID, UUID friendID) |
@@ -187,23 +192,121 @@ namespace OpenSim.Services.Connectors.Hypergrid | |||
187 | { | 192 | { |
188 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | 193 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); |
189 | 194 | ||
190 | if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null)) | 195 | if (replyData.ContainsKey("RESULT")) |
191 | { | 196 | { |
192 | bool success = false; | 197 | if (replyData["RESULT"].ToString().ToLower() == "true") |
193 | Boolean.TryParse(replyData["Result"].ToString(), out success); | 198 | return true; |
194 | return success; | 199 | else |
200 | return false; | ||
195 | } | 201 | } |
196 | else | 202 | else |
197 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Delete {0} {1} received null response", | 203 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: reply data does not contain result field"); |
198 | PrincipalID, Friend); | 204 | |
199 | } | 205 | } |
200 | else | 206 | else |
201 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: DeleteFriend received null reply"); | 207 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: received empty reply"); |
202 | 208 | ||
203 | return false; | 209 | return false; |
204 | 210 | ||
205 | } | 211 | } |
206 | 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 | |||
207 | #endregion | 310 | #endregion |
208 | } | 311 | } |
209 | } \ No newline at end of file | 312 | } \ No newline at end of file |