30 using System.Collections.Generic;
32 using System.Reflection;
34 using OpenSim.Framework;
35 using OpenSim.Services.Interfaces;
36 using OpenSim.Services.Connectors.Friends;
38 using OpenSim.Server.Base;
41 namespace OpenSim.Services.Connectors.Hypergrid
45 private static readonly ILog m_log =
47 MethodBase.GetCurrentMethod().DeclaringType);
49 private string m_ServerURI = String.Empty;
50 private string m_ServiceKey = String.Empty;
51 private UUID m_SessionID;
59 m_ServerURI = serverURI.TrimEnd(
'/');
64 m_ServerURI = serverURI.TrimEnd(
'/');
65 m_ServiceKey = serviceKey;
66 m_SessionID = sessionID;
74 #region IFriendsService
78 Dictionary<string, object> sendData =
new Dictionary<string, object>();
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();
86 string reqString = ServerUtils.BuildQueryString(sendData);
87 string uri = m_ServerURI +
"/hgfriends";
91 string reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
94 if (reply !=
string.Empty)
96 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
98 if ((replyData != null) && replyData.ContainsKey(
"Value") && (replyData[
"Value"] != null))
101 uint.TryParse(replyData[
"Value"].ToString(), out perms);
105 m_log.DebugFormat(
"[HGFRIENDS CONNECTOR]: GetFriendPerms {0} received null response",
112 m_log.DebugFormat(
"[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message);
122 finfo.PrincipalID = PrincipalID;
123 finfo.Friend = Friend;
125 Dictionary<string, object> sendData = finfo.ToKeyValuePairs();
127 sendData[
"METHOD"] =
"newfriendship";
128 sendData[
"KEY"] = m_ServiceKey;
129 sendData[
"SESSIONID"] = m_SessionID.ToString();
131 string reply = string.Empty;
132 string uri = m_ServerURI +
"/hgfriends";
135 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
137 ServerUtils.BuildQueryString(sendData));
141 m_log.DebugFormat(
"[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message);
145 if (reply !=
string.Empty)
147 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
149 if ((replyData != null) && replyData.ContainsKey(
"Result") && (replyData[
"Result"] != null))
151 bool success =
false;
152 Boolean.TryParse(replyData[
"Result"].ToString(), out success);
156 m_log.DebugFormat(
"[HGFRIENDS CONNECTOR]: StoreFriend {0} {1} received null response",
157 PrincipalID, Friend);
160 m_log.DebugFormat(
"[HGFRIENDS CONNECTOR]: StoreFriend received null reply");
169 finfo.PrincipalID = PrincipalID;
170 finfo.Friend = Friend.ToString();
172 Dictionary<string, object> sendData = finfo.ToKeyValuePairs();
174 sendData[
"METHOD"] =
"deletefriendship";
175 sendData[
"SECRET"] = secret;
177 string reply = string.Empty;
178 string uri = m_ServerURI +
"/hgfriends";
181 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
183 ServerUtils.BuildQueryString(sendData));
187 m_log.DebugFormat(
"[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message);
191 if (reply !=
string.Empty)
193 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
195 if (replyData.ContainsKey(
"RESULT"))
197 if (replyData[
"RESULT"].ToString().ToLower() ==
"true")
203 m_log.DebugFormat(
"[HGFRIENDS CONNECTOR]: reply data does not contain result field");
207 m_log.DebugFormat(
"[HGFRIENDS CONNECTOR]: received empty reply");
216 finfo.PrincipalID = fromID;
217 finfo.Friend = toID.ToString();
219 Dictionary<string, object> sendData = finfo.ToKeyValuePairs();
221 sendData[
"METHOD"] =
"validate_friendship_offered";
223 string reply = string.Empty;
224 string uri = m_ServerURI +
"/hgfriends";
227 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
229 ServerUtils.BuildQueryString(sendData));
233 m_log.DebugFormat(
"[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message);
237 if (reply !=
string.Empty)
239 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
241 if (replyData.ContainsKey(
"RESULT"))
243 if (replyData[
"RESULT"].ToString().ToLower() ==
"true")
249 m_log.DebugFormat(
"[HGFRIENDS CONNECTOR]: reply data does not contain result field");
253 m_log.DebugFormat(
"[HGFRIENDS CONNECTOR]: received empty reply");
261 Dictionary<string, object> sendData =
new Dictionary<string, object>();
262 List<UUID> friendsOnline =
new List<UUID>();
264 sendData[
"METHOD"] =
"statusnotification";
265 sendData[
"userID"] = userID.ToString();
266 sendData[
"online"] = online.ToString();
268 foreach (
string s
in friends)
270 sendData[
"friend_" + i.ToString()] = s;
274 string reply = string.Empty;
275 string uri = m_ServerURI +
"/hgfriends";
278 reply = SynchronousRestFormsRequester.MakeRequest(
"POST",
280 ServerUtils.BuildQueryString(sendData), 15);
284 m_log.DebugFormat(
"[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message);
285 return friendsOnline;
288 if (reply !=
string.Empty)
290 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
293 foreach (
string key in replyData.Keys)
295 if (key.StartsWith(
"friend_") && replyData[
key] != null)
298 if (UUID.TryParse(replyData[key].ToString(), out uuid))
299 friendsOnline.Add(uuid);
304 m_log.DebugFormat(
"[HGFRIENDS CONNECTOR]: Received empty reply from remote StatusNotify");
306 return friendsOnline;
uint GetFriendPerms(UUID PrincipalID, UUID friendID)
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString key
bool ValidateFriendshipOffered(UUID fromID, UUID toID)
HGFriendsServicesConnector(string serverURI, UUID sessionID, string serviceKey)
bool NewFriendship(UUID PrincipalID, string Friend)
bool DeleteFriendship(UUID PrincipalID, UUID Friend, string secret)
HGFriendsServicesConnector(string serverURI)
override string ServicePath()
List< UUID > StatusNotification(List< string > friends, UUID userID, bool online)
OpenSim.Services.Interfaces.FriendInfo FriendInfo
HGFriendsServicesConnector()