29 using System.Collections.Generic;
30 using System.Collections.Specialized;
31 using System.Reflection;
35 using OpenMetaverse.StructuredData;
36 using OpenSim.Framework;
37 using OpenSim.Services.Interfaces;
41 namespace OpenSim.Services.Connectors.SimianGrid
48 private static readonly ILog m_log =
50 MethodBase.GetCurrentMethod().DeclaringType);
52 private string m_serverUrl = String.Empty;
61 IConfig gridConfig = source.Configs[
"FriendsService"];
62 if (gridConfig != null)
64 string serviceUrl = gridConfig.GetString(
"FriendsServerURI");
65 if (!String.IsNullOrEmpty(serviceUrl))
67 if (!serviceUrl.EndsWith(
"/") && !serviceUrl.EndsWith(
"="))
68 serviceUrl = serviceUrl +
'/';
69 m_serverUrl = serviceUrl;
73 if (String.IsNullOrEmpty(m_serverUrl))
74 m_log.Info(
"[SIMIAN FRIENDS CONNECTOR]: No FriendsServerURI specified, disabling connector");
77 #region IFriendsService
81 return GetFriends(principalID.ToString());
86 if (String.IsNullOrEmpty(m_serverUrl))
89 Dictionary<UUID, FriendInfo> friends =
new Dictionary<UUID, FriendInfo>();
91 OSDArray friendsArray = GetFriended(principalID);
92 OSDArray friendedMeArray = GetFriendedBy(principalID);
95 for (
int i = 0; i < friendsArray.Count; i++)
98 if (friendEntry != null)
100 UUID friendID = friendEntry[
"Key"].AsUUID();
103 if (!UUID.TryParse(principalID, out
friend.PrincipalID))
105 string tmp = string.Empty;
106 if (!Util.ParseUniversalUserIdentifier(principalID, out
friend.PrincipalID, out tmp, out tmp, out tmp, out tmp))
111 friend.Friend = friendID.ToString();
112 friend.MyFlags = friendEntry[
"Value"].AsInteger();
113 friend.TheirFlags = -1;
115 friends[friendID] =
friend;
120 for (
int i = 0; i < friendedMeArray.Count; i++)
123 if (friendedMeEntry != null)
125 UUID friendID = friendedMeEntry[
"OwnerID"].AsUUID();
128 if (friends.TryGetValue(friendID, out
friend))
129 friend.TheirFlags = friendedMeEntry[
"Value"].AsInteger();
142 public bool StoreFriend(
string principalID,
string friend,
int flags)
144 if (String.IsNullOrEmpty(m_serverUrl))
147 NameValueCollection requestArgs =
new NameValueCollection
149 {
"RequestMethod",
"AddGeneric" },
150 {
"OwnerID", principalID.ToString() },
151 {
"Type",
"Friend" },
153 {
"Value", flags.ToString() }
156 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
157 bool success = response[
"Success"].AsBoolean();
160 m_log.Error(
"[SIMIAN FRIENDS CONNECTOR]: Failed to store friend " +
friend +
" for user " + principalID +
": " + response[
"Message"].AsString());
165 public bool Delete(UUID principalID,
string friend)
167 return Delete(principalID.ToString(),
friend);
170 public bool Delete(
string principalID,
string friend)
172 if (String.IsNullOrEmpty(m_serverUrl))
175 NameValueCollection requestArgs =
new NameValueCollection
177 {
"RequestMethod",
"RemoveGeneric" },
178 {
"OwnerID", principalID.ToString() },
179 {
"Type",
"Friend" },
183 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
184 bool success = response[
"Success"].AsBoolean();
187 m_log.Error(
"[SIMIAN FRIENDS CONNECTOR]: Failed to remove friend " +
friend +
" for user " + principalID +
": " + response[
"Message"].AsString());
192 #endregion IFriendsService
194 private OSDArray GetFriended(
string ownerID)
196 NameValueCollection requestArgs =
new NameValueCollection
198 {
"RequestMethod",
"GetGenerics" },
199 {
"OwnerID", ownerID.ToString() },
203 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
204 if (response[
"Success"].AsBoolean() && response[
"Entries"] is
OSDArray)
206 return (
OSDArray)response[
"Entries"];
210 m_log.Warn(
"[SIMIAN FRIENDS CONNECTOR]: Failed to retrieve friends for user " + ownerID +
": " + response[
"Message"].AsString());
215 private OSDArray GetFriendedBy(
string ownerID)
217 NameValueCollection requestArgs =
new NameValueCollection
219 {
"RequestMethod",
"GetGenerics" },
220 {
"Key", ownerID.ToString() },
224 OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);
225 if (response[
"Success"].AsBoolean() && response[
"Entries"] is
OSDArray)
227 return (
OSDArray)response[
"Entries"];
231 m_log.Warn(
"[SIMIAN FRIENDS CONNECTOR]: Failed to retrieve reverse friends for user " + ownerID +
": " + response[
"Message"].AsString());
OpenSim.Services.Interfaces.FriendInfo FriendInfo
OpenMetaverse.StructuredData.OSDArray OSDArray
FriendInfo[] GetFriends(string principalID)
void Initialise(IConfigSource source)
OpenMetaverse.StructuredData.OSDMap OSDMap
bool StoreFriend(string principalID, string friend, int flags)
SimianFriendsServiceConnector(IConfigSource source)
bool Delete(string principalID, string friend)
bool Delete(UUID principalID, string friend)
Stores and retrieves friend lists from the SimianGrid backend
FriendInfo[] GetFriends(UUID principalID)