30 using System.Collections.Generic;
32 using System.Reflection;
34 using OpenSim.Framework;
35 using OpenSim.Framework.ServiceAuth;
37 using OpenSim.Services.Interfaces;
39 using OpenSim.Server.Base;
42 namespace OpenSim.Services.Connectors.Friends
46 private static readonly ILog m_log =
48 MethodBase.GetCurrentMethod().DeclaringType);
50 private string m_ServerURI = String.Empty;
58 m_ServerURI = serverURI.TrimEnd(
'/');
68 IConfig gridConfig = source.Configs[
"FriendsService"];
69 if (gridConfig == null)
71 m_log.Error(
"[FRIENDS SERVICE CONNECTOR]: FriendsService missing from OpenSim.ini");
72 throw new Exception(
"Friends connector init error");
75 string serviceURI = gridConfig.GetString(
"FriendsServerURI",
78 if (serviceURI == String.Empty)
80 m_log.Error(
"[FRIENDS SERVICE CONNECTOR]: No Server URI named in section FriendsService");
81 throw new Exception(
"Friends connector init error");
83 m_ServerURI = serviceURI;
84 base.Initialise(source,
"FriendsService");
88 #region IFriendsService
92 Dictionary<string, object> sendData =
new Dictionary<string, object>();
94 sendData[
"PRINCIPALID"] = PrincipalID.ToString();
95 sendData[
"METHOD"] =
"getfriends";
97 return GetFriends(sendData, PrincipalID.ToString());
102 Dictionary<string, object> sendData =
new Dictionary<string, object>();
104 sendData[
"PRINCIPALID"] = PrincipalID;
105 sendData[
"METHOD"] =
"getfriends_string";
107 return GetFriends(sendData, PrincipalID);
112 string reqString = ServerUtils.BuildQueryString(sendData);
113 string uri = m_ServerURI +
"/friends";
117 string reply = SynchronousRestFormsRequester.MakeRequest(
"POST", uri, reqString, m_Auth);
118 if (reply !=
string.Empty)
120 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
122 if (replyData != null)
124 if (replyData.ContainsKey(
"result") && (replyData[
"result"].ToString().ToLower() ==
"null"))
129 List<FriendInfo> finfos =
new List<FriendInfo>();
130 Dictionary<string, object>.ValueCollection finfosList = replyData.Values;
132 foreach (
object f
in finfosList)
134 if (f is Dictionary<string, object>)
140 m_log.DebugFormat(
"[FRIENDS SERVICE CONNECTOR]: GetFriends {0} received invalid response type {1}",
141 PrincipalID, f.GetType());
145 return finfos.ToArray();
148 m_log.DebugFormat(
"[FRIENDS SERVICE CONNECTOR]: GetFriends {0} received null response",
155 m_log.DebugFormat(
"[FRIENDS SERVICE CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message);
162 public bool StoreFriend(
string PrincipalID,
string Friend,
int flags)
165 Dictionary<string, object> sendData = ToKeyValuePairs(PrincipalID, Friend, flags);
167 sendData[
"METHOD"] =
"storefriend";
169 string reply = string.Empty;
170 string uri = m_ServerURI +
"/friends";
173 reply = SynchronousRestFormsRequester.MakeRequest(
"POST", uri, ServerUtils.BuildQueryString(sendData), m_Auth);
177 m_log.DebugFormat(
"[FRIENDS SERVICE CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message);
181 if (reply !=
string.Empty)
183 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
185 if ((replyData != null) && replyData.ContainsKey(
"Result") && (replyData[
"Result"] != null))
187 bool success =
false;
188 Boolean.TryParse(replyData[
"Result"].ToString(), out success);
192 m_log.DebugFormat(
"[FRIENDS SERVICE CONNECTOR]: StoreFriend {0} {1} received null response",
193 PrincipalID, Friend);
196 m_log.DebugFormat(
"[FRIENDS SERVICE CONNECTOR]: StoreFriend received null reply");
202 public bool Delete(
string PrincipalID,
string Friend)
204 Dictionary<string, object> sendData =
new Dictionary<string, object>();
205 sendData[
"PRINCIPALID"] = PrincipalID.ToString();
206 sendData[
"FRIEND"] = Friend;
207 sendData[
"METHOD"] =
"deletefriend_string";
209 return Delete(sendData, PrincipalID, Friend);
212 public bool Delete(UUID PrincipalID,
string Friend)
214 Dictionary<string, object> sendData =
new Dictionary<string, object>();
215 sendData[
"PRINCIPALID"] = PrincipalID.ToString();
216 sendData[
"FRIEND"] = Friend;
217 sendData[
"METHOD"] =
"deletefriend";
219 return Delete(sendData, PrincipalID.ToString(), Friend);
222 public bool Delete(Dictionary<string, object> sendData,
string PrincipalID,
string Friend)
224 string reply = string.Empty;
225 string uri = m_ServerURI +
"/friends";
228 reply = SynchronousRestFormsRequester.MakeRequest(
"POST", uri, ServerUtils.BuildQueryString(sendData), m_Auth);
232 m_log.DebugFormat(
"[FRIENDS SERVICE CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message);
236 if (reply !=
string.Empty)
238 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
240 if ((replyData != null) && replyData.ContainsKey(
"Result") && (replyData[
"Result"] != null))
242 bool success =
false;
243 Boolean.TryParse(replyData[
"Result"].ToString(), out success);
247 m_log.DebugFormat(
"[FRIENDS SERVICE CONNECTOR]: DeleteFriend {0} {1} received null response",
248 PrincipalID, Friend);
251 m_log.DebugFormat(
"[FRIENDS SERVICE CONNECTOR]: DeleteFriend received null reply");
258 public Dictionary<string, object>
ToKeyValuePairs(
string principalID,
string friend,
int flags)
260 Dictionary<string, object> result =
new Dictionary<string, object>();
261 result[
"PrincipalID"] = principalID;
262 result[
"Friend"] =
friend;
263 result[
"MyFlags"] = flags;
FriendInfo[] GetFriends(UUID PrincipalID)
FriendsServicesConnector()
bool Delete(string PrincipalID, string Friend)
FriendInfo[] GetFriends(string PrincipalID)
OpenSim.Services.Interfaces.FriendInfo FriendInfo
FriendInfo[] GetFriends(Dictionary< string, object > sendData, string PrincipalID)
virtual void Initialise(IConfigSource source)
bool StoreFriend(string PrincipalID, string Friend, int flags)
FriendsServicesConnector(IConfigSource source)
FriendsServicesConnector(string serverURI)
Interactive OpenSim region server
bool Delete(UUID PrincipalID, string Friend)
bool Delete(Dictionary< string, object > sendData, string PrincipalID, string Friend)
Dictionary< string, object > ToKeyValuePairs(string principalID, string friend, int flags)