aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorDiva Canto2011-05-21 16:48:00 -0700
committerDiva Canto2011-05-21 16:48:00 -0700
commit58c53c41de2cae0bb041a2e8121792e136d1edb2 (patch)
treeb792158cd178f88234f86ab4d72c4224b45fe6ba /OpenSim
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC-58c53c41de2cae0bb041a2e8121792e136d1edb2.zip
opensim-SC-58c53c41de2cae0bb041a2e8121792e136d1edb2.tar.gz
opensim-SC-58c53c41de2cae0bb041a2e8121792e136d1edb2.tar.bz2
opensim-SC-58c53c41de2cae0bb041a2e8121792e136d1edb2.tar.xz
Fixed permissions bug related to friends in PermissionsModule. Added FriendsData[] GetFriends(string principalID) to IFriendsData and FriendInfo[] GetFriends(string PrincipalID) to IFriendsService. Refactored some more in the FriendsModule. Made client get notification of local friends permissions upon HGLogin. HG Friends object permissions work.
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/IFriendsData.cs1
-rw-r--r--OpenSim/Data/MSSQL/MSSQLFriendsData.cs6
-rw-r--r--OpenSim/Data/MySQL/MySQLFriendsData.cs5
-rw-r--r--OpenSim/Data/Null/NullFriendsData.cs7
-rw-r--r--OpenSim/Data/SQLite/SQLiteFriendsData.cs7
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs103
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs259
-rw-r--r--OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs41
-rw-r--r--OpenSim/Region/Framework/Interfaces/IFriendsModule.cs2
-rw-r--r--OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs23
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs112
-rw-r--r--OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs17
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs37
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianFriendsServiceConnector.cs18
-rw-r--r--OpenSim/Services/Friends/FriendsService.cs26
-rw-r--r--OpenSim/Services/HypergridService/HGFriendsService.cs4
-rw-r--r--OpenSim/Services/Interfaces/IFriendsService.cs1
17 files changed, 372 insertions, 297 deletions
diff --git a/OpenSim/Data/IFriendsData.cs b/OpenSim/Data/IFriendsData.cs
index 4da567e..52e7f14 100644
--- a/OpenSim/Data/IFriendsData.cs
+++ b/OpenSim/Data/IFriendsData.cs
@@ -47,5 +47,6 @@ namespace OpenSim.Data
47 bool Store(FriendsData data); 47 bool Store(FriendsData data);
48 bool Delete(UUID ownerID, string friend); 48 bool Delete(UUID ownerID, string friend);
49 FriendsData[] GetFriends(UUID principalID); 49 FriendsData[] GetFriends(UUID principalID);
50 FriendsData[] GetFriends(string principalID);
50 } 51 }
51} 52}
diff --git a/OpenSim/Data/MSSQL/MSSQLFriendsData.cs b/OpenSim/Data/MSSQL/MSSQLFriendsData.cs
index af4fd9b..ba1b085 100644
--- a/OpenSim/Data/MSSQL/MSSQLFriendsData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLFriendsData.cs
@@ -68,6 +68,11 @@ namespace OpenSim.Data.MSSQL
68 68
69 public FriendsData[] GetFriends(UUID principalID) 69 public FriendsData[] GetFriends(UUID principalID)
70 { 70 {
71 return GetFriends(principalID.ToString());
72 }
73
74 public FriendsData[] GetFriends(string principalID)
75 {
71 using (SqlConnection conn = new SqlConnection(m_ConnectionString)) 76 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
72 using (SqlCommand cmd = new SqlCommand()) 77 using (SqlCommand cmd = new SqlCommand())
73 { 78 {
@@ -79,5 +84,6 @@ namespace OpenSim.Data.MSSQL
79 return DoQuery(cmd); 84 return DoQuery(cmd);
80 } 85 }
81 } 86 }
87
82 } 88 }
83} 89}
diff --git a/OpenSim/Data/MySQL/MySQLFriendsData.cs b/OpenSim/Data/MySQL/MySQLFriendsData.cs
index 663fad6..69fac9d 100644
--- a/OpenSim/Data/MySQL/MySQLFriendsData.cs
+++ b/OpenSim/Data/MySQL/MySQLFriendsData.cs
@@ -57,6 +57,11 @@ namespace OpenSim.Data.MySQL
57 57
58 public FriendsData[] GetFriends(UUID principalID) 58 public FriendsData[] GetFriends(UUID principalID)
59 { 59 {
60 return GetFriends(principalID.ToString());
61 }
62
63 public FriendsData[] GetFriends(string principalID)
64 {
60 MySqlCommand cmd = new MySqlCommand(); 65 MySqlCommand cmd = new MySqlCommand();
61 66
62 cmd.CommandText = String.Format("select a.*,case when b.Flags is null then -1 else b.Flags end as TheirFlags from {0} as a left join {0} as b on a.PrincipalID = b.Friend and a.Friend = b.PrincipalID where a.PrincipalID = ?PrincipalID", m_Realm); 67 cmd.CommandText = String.Format("select a.*,case when b.Flags is null then -1 else b.Flags end as TheirFlags from {0} as a left join {0} as b on a.PrincipalID = b.Friend and a.Friend = b.PrincipalID where a.PrincipalID = ?PrincipalID", m_Realm);
diff --git a/OpenSim/Data/Null/NullFriendsData.cs b/OpenSim/Data/Null/NullFriendsData.cs
index 0c69bb1..2bfdc7a 100644
--- a/OpenSim/Data/Null/NullFriendsData.cs
+++ b/OpenSim/Data/Null/NullFriendsData.cs
@@ -42,6 +42,11 @@ namespace OpenSim.Data.Null
42 { 42 {
43 } 43 }
44 44
45 public FriendsData[] GetFriends(UUID principalID)
46 {
47 return GetFriends(principalID.ToString());
48 }
49
45 /// <summary> 50 /// <summary>
46 /// Tries to implement the Get [] semantics, but it cuts corners. 51 /// Tries to implement the Get [] semantics, but it cuts corners.
47 /// Specifically, it gets all friendships even if they weren't accepted yet. 52 /// Specifically, it gets all friendships even if they weren't accepted yet.
@@ -49,7 +54,7 @@ namespace OpenSim.Data.Null
49 /// <param name="fields"></param> 54 /// <param name="fields"></param>
50 /// <param name="values"></param> 55 /// <param name="values"></param>
51 /// <returns></returns> 56 /// <returns></returns>
52 public FriendsData[] GetFriends(UUID userID) 57 public FriendsData[] GetFriends(string userID)
53 { 58 {
54 List<FriendsData> lst = m_Data.FindAll(delegate (FriendsData fdata) 59 List<FriendsData> lst = m_Data.FindAll(delegate (FriendsData fdata)
55 { 60 {
diff --git a/OpenSim/Data/SQLite/SQLiteFriendsData.cs b/OpenSim/Data/SQLite/SQLiteFriendsData.cs
index 4bfd228..d925412 100644
--- a/OpenSim/Data/SQLite/SQLiteFriendsData.cs
+++ b/OpenSim/Data/SQLite/SQLiteFriendsData.cs
@@ -46,7 +46,12 @@ namespace OpenSim.Data.SQLite
46 { 46 {
47 } 47 }
48 48
49 public FriendsData[] GetFriends(UUID userID) 49 public FriendsData[] GetFriends(UUID principalID)
50 {
51 return GetFriends(principalID.ToString());
52 }
53
54 public FriendsData[] GetFriends(string userID)
50 { 55 {
51 SqliteCommand cmd = new SqliteCommand(); 56 SqliteCommand cmd = new SqliteCommand();
52 57
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
index 21cd924..4879d20 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
@@ -69,7 +69,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
69 } 69 }
70 } 70 }
71 71
72 private static readonly FriendInfo[] EMPTY_FRIENDS = new FriendInfo[0]; 72 protected static readonly FriendInfo[] EMPTY_FRIENDS = new FriendInfo[0];
73 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 73 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
74 74
75 protected List<Scene> m_Scenes = new List<Scene>(); 75 protected List<Scene> m_Scenes = new List<Scene>();
@@ -187,6 +187,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
187 { 187 {
188 if (!m_Enabled) 188 if (!m_Enabled)
189 return; 189 return;
190 m_log.DebugFormat("[FRIENDS MODULE]: AddRegion on {0}", Name);
190 191
191 m_Scenes.Add(scene); 192 m_Scenes.Add(scene);
192 scene.RegisterModuleInterface<IFriendsModule>(this); 193 scene.RegisterModuleInterface<IFriendsModule>(this);
@@ -221,13 +222,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
221 222
222 #endregion 223 #endregion
223 224
224 public uint GetFriendPerms(UUID principalID, UUID friendID) 225 public virtual uint GetFriendPerms(UUID principalID, UUID friendID)
225 { 226 {
226 FriendInfo[] friends = GetFriends(principalID); 227 FriendInfo[] friends = GetFriends(principalID);
227 foreach (FriendInfo fi in friends) 228 FriendInfo finfo = GetFriend(friends, friendID);
229 if (finfo != null)
228 { 230 {
229 if (fi.Friend == friendID.ToString()) 231 return (uint)finfo.TheirFlags;
230 return (uint)fi.TheirFlags;
231 } 232 }
232 233
233 return 0; 234 return 0;
@@ -241,14 +242,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
241 client.OnTerminateFriendship += OnTerminateFriendship; 242 client.OnTerminateFriendship += OnTerminateFriendship;
242 client.OnGrantUserRights += OnGrantUserRights; 243 client.OnGrantUserRights += OnGrantUserRights;
243 244
244 Util.FireAndForget(delegate { FetchFriendslist(client.AgentId); }); 245 Util.FireAndForget(delegate { FetchFriendslist(client); });
245 } 246 }
246 247
247 /// Fetch the friends list or increment the refcount for the existing 248 /// Fetch the friends list or increment the refcount for the existing
248 /// friends list 249 /// friends list
249 /// Returns true if the list was fetched, false if it wasn't 250 /// Returns true if the list was fetched, false if it wasn't
250 protected virtual bool FetchFriendslist(UUID agentID) 251 protected virtual bool FetchFriendslist(IClientAPI client)
251 { 252 {
253 UUID agentID = client.AgentId;
252 lock (m_Friends) 254 lock (m_Friends)
253 { 255 {
254 UserFriendData friendsData; 256 UserFriendData friendsData;
@@ -261,7 +263,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
261 { 263 {
262 friendsData = new UserFriendData(); 264 friendsData = new UserFriendData();
263 friendsData.PrincipalID = agentID; 265 friendsData.PrincipalID = agentID;
264 friendsData.Friends = FriendsService.GetFriends(agentID); 266 friendsData.Friends = GetFriendsFromService(client);
265 friendsData.Refcount = 1; 267 friendsData.Refcount = 1;
266 268
267 m_Friends[agentID] = friendsData; 269 m_Friends[agentID] = friendsData;
@@ -270,6 +272,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
270 } 272 }
271 } 273 }
272 274
275 protected virtual FriendInfo[] GetFriendsFromService(IClientAPI client)
276 {
277 return FriendsService.GetFriends(client.AgentId);
278 }
279
273 private void OnClientClosed(UUID agentID, Scene scene) 280 private void OnClientClosed(UUID agentID, Scene scene)
274 { 281 {
275 ScenePresence sp = scene.GetScenePresence(agentID); 282 ScenePresence sp = scene.GetScenePresence(agentID);
@@ -293,8 +300,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
293 300
294 private void OnMakeRootAgent(ScenePresence sp) 301 private void OnMakeRootAgent(ScenePresence sp)
295 { 302 {
296 UUID agentID = sp.ControllingClient.AgentId; 303 UpdateFriendsCache(sp.ControllingClient);
297 UpdateFriendsCache(agentID);
298 } 304 }
299 305
300 private void OnClientLogin(IClientAPI client) 306 private void OnClientLogin(IClientAPI client)
@@ -309,7 +315,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
309 m_NeedsListOfFriends.Add(agentID); 315 m_NeedsListOfFriends.Add(agentID);
310 } 316 }
311 317
312 public void SendFriendsOnlineIfNeeded(IClientAPI client) 318 public virtual bool SendFriendsOnlineIfNeeded(IClientAPI client)
313 { 319 {
314 UUID agentID = client.AgentId; 320 UUID agentID = client.AgentId;
315 321
@@ -317,7 +323,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
317 lock (m_NeedsListOfFriends) 323 lock (m_NeedsListOfFriends)
318 { 324 {
319 if (!m_NeedsListOfFriends.Remove(agentID)) 325 if (!m_NeedsListOfFriends.Remove(agentID))
320 return; 326 return false;
321 } 327 }
322 328
323 // Send the friends online 329 // Send the friends online
@@ -366,6 +372,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
366 // Finally 372 // Finally
367 LocalFriendshipOffered(agentID, im); 373 LocalFriendshipOffered(agentID, im);
368 } 374 }
375
376 return true;
369 } 377 }
370 378
371 protected virtual string FriendshipMessage(string friendID) 379 protected virtual string FriendshipMessage(string friendID)
@@ -579,7 +587,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
579 StoreFriendships(agentID, friendID); 587 StoreFriendships(agentID, friendID);
580 588
581 // Update the local cache 589 // Update the local cache
582 UpdateFriendsCache(agentID); 590 UpdateFriendsCache(client);
583 591
584 // 592 //
585 // Notify the friend 593 // Notify the friend
@@ -647,7 +655,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
647 DeleteFriendship(agentID, exfriendID); 655 DeleteFriendship(agentID, exfriendID);
648 656
649 // Update local cache 657 // Update local cache
650 UpdateFriendsCache(agentID); 658 UpdateFriendsCache(client);
651 659
652 client.SendTerminateFriend(exfriendID); 660 client.SendTerminateFriend(exfriendID);
653 661
@@ -679,23 +687,26 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
679 687
680 private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights) 688 private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights)
681 { 689 {
690 m_log.DebugFormat("[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}", requester, rights, target);
691
682 FriendInfo[] friends = GetFriends(remoteClient.AgentId); 692 FriendInfo[] friends = GetFriends(remoteClient.AgentId);
683 if (friends.Length == 0) 693 if (friends.Length == 0)
694 {
695 m_log.DebugFormat("[XXX]: agent {0} has no friends", requester);
684 return; 696 return;
697 }
685 698
686 m_log.DebugFormat("[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}", requester, rights, target);
687 // Let's find the friend in this user's friend list 699 // Let's find the friend in this user's friend list
688 FriendInfo friend = null; 700 FriendInfo friend = GetFriend(friends, target);
689 foreach (FriendInfo fi in friends)
690 {
691 if (fi.Friend == target.ToString())
692 friend = fi;
693 }
694 701
695 if (friend != null) // Found it 702 if (friend != null) // Found it
696 { 703 {
697 // Store it on the DB 704 // Store it on the DB
698 FriendsService.StoreFriend(requester.ToString(), target.ToString(), rights); 705 if (!SimpleStore(requester, target, rights))
706 {
707 remoteClient.SendAlertMessage("Unable to grant rights.");
708 return;
709 }
699 710
700 // Store it in the local cache 711 // Store it in the local cache
701 int myFlags = friend.MyFlags; 712 int myFlags = friend.MyFlags;
@@ -725,6 +736,24 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
725 } 736 }
726 } 737 }
727 } 738 }
739 else
740 m_log.DebugFormat("[FRIENDS MODULE]: friend {0} not found for {1}", target, requester);
741 }
742
743 protected virtual bool SimpleStore(UUID agentID, UUID friendID, int rights)
744 {
745 FriendsService.StoreFriend(agentID.ToString(), friendID.ToString(), rights);
746 return true;
747 }
748
749 protected virtual FriendInfo GetFriend(FriendInfo[] friends, UUID friendID)
750 {
751 foreach (FriendInfo fi in friends)
752 {
753 if (fi.Friend == friendID.ToString())
754 return fi;
755 }
756 return null;
728 } 757 }
729 758
730 #region Local 759 #region Local
@@ -753,7 +782,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
753 friendClient.SendInstantMessage(im); 782 friendClient.SendInstantMessage(im);
754 783
755 // Update the local cache 784 // Update the local cache
756 UpdateFriendsCache(friendID); 785 UpdateFriendsCache(friendClient);
757 786
758 // we're done 787 // we're done
759 return true; 788 return true;
@@ -786,7 +815,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
786 // the friend in this sim as root agent 815 // the friend in this sim as root agent
787 friendClient.SendTerminateFriend(exfriendID); 816 friendClient.SendTerminateFriend(exfriendID);
788 // update local cache 817 // update local cache
789 UpdateFriendsCache(exfriendID); 818 UpdateFriendsCache(friendClient);
790 // we're done 819 // we're done
791 return true; 820 return true;
792 } 821 }
@@ -816,15 +845,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
816 } 845 }
817 846
818 // Update local cache 847 // Update local cache
819 lock (m_Friends) 848 UpdateLocalCache(userID, friendID, rights);
820 {
821 FriendInfo[] friends = GetFriends(friendID);
822 foreach (FriendInfo finfo in friends)
823 {
824 if (finfo.Friend == userID.ToString())
825 finfo.TheirFlags = rights;
826 }
827 }
828 849
829 return true; 850 return true;
830 } 851 }
@@ -866,13 +887,25 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
866 return EMPTY_FRIENDS; 887 return EMPTY_FRIENDS;
867 } 888 }
868 889
869 private void UpdateFriendsCache(UUID agentID) 890 private void UpdateFriendsCache(IClientAPI client)
870 { 891 {
892 UUID agentID = client.AgentId;
871 lock (m_Friends) 893 lock (m_Friends)
872 { 894 {
873 UserFriendData friendsData; 895 UserFriendData friendsData;
874 if (m_Friends.TryGetValue(agentID, out friendsData)) 896 if (m_Friends.TryGetValue(agentID, out friendsData))
875 friendsData.Friends = FriendsService.GetFriends(agentID); 897 friendsData.Friends = GetFriendsFromService(client);
898 }
899 }
900
901 protected void UpdateLocalCache(UUID userID, UUID friendID, int rights)
902 {
903 // Update local cache
904 lock (m_Friends)
905 {
906 FriendInfo[] friends = GetFriends(friendID);
907 FriendInfo finfo = GetFriend(friends, userID);
908 finfo.TheirFlags = rights;
876 } 909 }
877 } 910 }
878 } 911 }
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
index 645ecdc..abffb94 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
@@ -58,129 +58,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
58 58
59 #endregion 59 #endregion
60 60
61 //public void SendFriendsOnlineIfNeeded(IClientAPI client) 61 protected override bool FetchFriendslist(IClientAPI client)
62 //{
63 // UUID agentID = client.AgentId;
64
65 // // Check if the online friends list is needed
66 // lock (m_NeedsListOfFriends)
67 // {
68 // if (!m_NeedsListOfFriends.Remove(agentID))
69 // return;
70 // }
71
72 // // Send the friends online
73 // List<UUID> online = GetOnlineFriends(agentID);
74 // if (online.Count > 0)
75 // {
76 // m_log.DebugFormat("[FRIENDS MODULE]: User {0} in region {1} has {2} friends online", client.AgentId, client.Scene.RegionInfo.RegionName, online.Count);
77 // client.SendAgentOnline(online.ToArray());
78 // }
79
80 // // Send outstanding friendship offers
81 // List<string> outstanding = new List<string>();
82 // FriendInfo[] friends = GetFriends(agentID);
83 // foreach (FriendInfo fi in friends)
84 // {
85 // if (fi.TheirFlags == -1)
86 // outstanding.Add(fi.Friend);
87 // }
88
89 // GridInstantMessage im = new GridInstantMessage(client.Scene, UUID.Zero, String.Empty, agentID, (byte)InstantMessageDialog.FriendshipOffered,
90 // "Will you be my friend?", true, Vector3.Zero);
91
92 // foreach (string fid in outstanding)
93 // {
94 // UUID fromAgentID;
95 // if (!UUID.TryParse(fid, out fromAgentID))
96 // continue;
97
98 // UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID, fromAgentID);
99
100 // PresenceInfo presence = null;
101 // PresenceInfo[] presences = PresenceService.GetAgents(new string[] { fid });
102 // if (presences != null && presences.Length > 0)
103 // presence = presences[0];
104 // if (presence != null)
105 // im.offline = 0;
106
107 // im.fromAgentID = fromAgentID.Guid;
108 // im.fromAgentName = account.FirstName + " " + account.LastName;
109 // im.offline = (byte)((presence == null) ? 1 : 0);
110 // im.imSessionID = im.fromAgentID;
111
112 // // Finally
113 // LocalFriendshipOffered(agentID, im);
114 // }
115 //}
116
117 //List<UUID> GetOnlineFriends(UUID userID)
118 //{
119 // List<string> friendList = new List<string>();
120 // List<UUID> online = new List<UUID>();
121
122 // FriendInfo[] friends = GetFriends(userID);
123 // foreach (FriendInfo fi in friends)
124 // {
125 // if (((fi.TheirFlags & 1) != 0) && (fi.TheirFlags != -1))
126 // friendList.Add(fi.Friend);
127 // }
128
129 // if (friendList.Count > 0)
130 // {
131 // PresenceInfo[] presence = PresenceService.GetAgents(friendList.ToArray());
132 // foreach (PresenceInfo pi in presence)
133 // {
134 // UUID presenceID;
135 // if (UUID.TryParse(pi.UserID, out presenceID))
136 // online.Add(presenceID);
137 // }
138 // }
139
140 // return online;
141 //}
142
143 //private void StatusNotify(FriendInfo friend, UUID userID, bool online)
144 //{
145 // UUID friendID;
146 // if (UUID.TryParse(friend.Friend, out friendID))
147 // {
148 // // Try local
149 // if (LocalStatusNotification(userID, friendID, online))
150 // return;
151
152 // // The friend is not here [as root]. Let's forward.
153 // PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() });
154 // if (friendSessions != null && friendSessions.Length > 0)
155 // {
156 // PresenceInfo friendSession = null;
157 // foreach (PresenceInfo pinfo in friendSessions)
158 // if (pinfo.RegionID != UUID.Zero) // let's guard against sessions-gone-bad
159 // {
160 // friendSession = pinfo;
161 // break;
162 // }
163
164 // if (friendSession != null)
165 // {
166 // GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID);
167 // //m_log.DebugFormat("[FRIENDS]: Remote Notify to region {0}", region.RegionName);
168 // m_FriendsSimConnector.StatusNotify(region, userID, friendID, online);
169 // }
170 // }
171
172 // // Friend is not online. Ignore.
173 // }
174 // else
175 // {
176 // m_log.WarnFormat("[FRIENDS]: Error parsing friend ID {0}", friend.Friend);
177 // }
178 //}
179
180 protected override bool FetchFriendslist(UUID agentID)
181 { 62 {
182 if (base.FetchFriendslist(agentID)) 63 if (base.FetchFriendslist(client))
183 { 64 {
65 UUID agentID = client.AgentId;
184 // We need to preload the user management cache with the names 66 // We need to preload the user management cache with the names
185 // of foreign friends, just like we do with SOPs' creators 67 // of foreign friends, just like we do with SOPs' creators
186 foreach (FriendInfo finfo in m_Friends[agentID].Friends) 68 foreach (FriendInfo finfo in m_Friends[agentID].Friends)
@@ -204,6 +86,39 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
204 return false; 86 return false;
205 } 87 }
206 88
89 public override bool SendFriendsOnlineIfNeeded(IClientAPI client)
90 {
91 if (base.SendFriendsOnlineIfNeeded(client))
92 {
93 UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID, client.AgentId);
94 if (account == null) // foreign
95 {
96 FriendInfo[] friends = GetFriends(client.AgentId);
97 foreach (FriendInfo f in friends)
98 {
99 client.SendChangeUserRights(new UUID(f.Friend), client.AgentId, f.TheirFlags);
100 }
101 }
102 }
103 return false;
104 }
105
106 protected override FriendInfo[] GetFriendsFromService(IClientAPI client)
107 {
108 UserAccount account1 = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, client.AgentId);
109 if (account1 != null)
110 return base.GetFriendsFromService(client);
111
112 // Foreigner
113 AgentCircuitData agentClientCircuit = ((Scene)(client.Scene)).AuthenticateHandler.GetAgentCircuitData(client.CircuitCode);
114 string agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit);
115
116 FriendInfo[] finfos = FriendsService.GetFriends(agentUUI);
117 m_log.DebugFormat("[HGFRIENDS MODULE]: Fetched {0} local friends for visitor {1}", finfos.Length, agentUUI);
118 return finfos;
119 }
120
121
207 protected override bool GetAgentInfo(UUID scopeID, string fid, out UUID agentID, out string first, out string last) 122 protected override bool GetAgentInfo(UUID scopeID, string fid, out UUID agentID, out string first, out string last)
208 { 123 {
209 first = "Unknown"; last = "User"; 124 first = "Unknown"; last = "User";
@@ -249,6 +164,45 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
249 return "Please confirm this friendship you made while you were away."; 164 return "Please confirm this friendship you made while you were away.";
250 } 165 }
251 166
167 protected override bool SimpleStore(UUID agentID, UUID friendID, int rights)
168 {
169 UserAccount account1 = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, agentID);
170 UserAccount account2 = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, friendID);
171 // Are they both local users?
172 if (account1 != null && account2 != null)
173 {
174 // local grid users
175 return base.SimpleStore(agentID, friendID, rights);
176 }
177
178 if (account1 != null)
179 {
180 FriendInfo[] finfos = GetFriends(agentID);
181 if (finfos.Length > 0)
182 {
183 FriendInfo finfo = GetFriend(finfos, friendID);
184 FriendsService.StoreFriend(agentID.ToString(), finfo.Friend, rights);
185 return true;
186 }
187 }
188 if (account2 != null)
189 {
190 IClientAPI client = LocateClientObject(agentID);
191 if (client != null)
192 {
193 AgentCircuitData acircuit = m_Scenes[0].AuthenticateHandler.GetAgentCircuitData(client.CircuitCode);
194 if (acircuit != null)
195 {
196 FriendsService.StoreFriend(Util.ProduceUserUniversalIdentifier(acircuit), friendID.ToString(), rights);
197 return true;
198 }
199 }
200 }
201
202 return false;
203
204 }
205
252 protected override void StoreBackwards(UUID friendID, UUID agentID) 206 protected override void StoreBackwards(UUID friendID, UUID agentID)
253 { 207 {
254 UserAccount account1 = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, agentID); 208 UserAccount account1 = UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, agentID);
@@ -366,6 +320,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
366 // my brain hurts now 320 // my brain hurts now
367 } 321 }
368 322
323 protected override FriendInfo GetFriend(FriendInfo[] friends, UUID friendID)
324 {
325 foreach (FriendInfo fi in friends)
326 {
327 if (fi.Friend.StartsWith(friendID.ToString()))
328 return fi;
329 }
330 return null;
331 }
332
369 protected override void DeleteFriendship(UUID agentID, UUID exfriendID) 333 protected override void DeleteFriendship(UUID agentID, UUID exfriendID)
370 { 334 {
371 base.DeleteFriendship(agentID, exfriendID); 335 base.DeleteFriendship(agentID, exfriendID);
@@ -374,7 +338,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
374 FriendInfo[] friends = GetFriends(agentID); 338 FriendInfo[] friends = GetFriends(agentID);
375 foreach (FriendInfo finfo in friends) 339 foreach (FriendInfo finfo in friends)
376 { 340 {
377 if (finfo.Friend != exfriendID.ToString() && finfo.Friend.EndsWith(exfriendID.ToString())) 341 if (finfo.Friend != exfriendID.ToString() && finfo.Friend.StartsWith(exfriendID.ToString()))
378 { 342 {
379 FriendsService.Delete(agentID, exfriendID.ToString()); 343 FriendsService.Delete(agentID, exfriendID.ToString());
380 // TODO: delete the friendship on the other side 344 // TODO: delete the friendship on the other side
@@ -383,56 +347,5 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
383 } 347 }
384 } 348 }
385 349
386 //private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights)
387 //{
388 // FriendInfo[] friends = GetFriends(remoteClient.AgentId);
389 // if (friends.Length == 0)
390 // return;
391
392 // m_log.DebugFormat("[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}", requester, rights, target);
393 // // Let's find the friend in this user's friend list
394 // FriendInfo friend = null;
395 // foreach (FriendInfo fi in friends)
396 // {
397 // if (fi.Friend == target.ToString())
398 // friend = fi;
399 // }
400
401 // if (friend != null) // Found it
402 // {
403 // // Store it on the DB
404 // FriendsService.StoreFriend(requester, target.ToString(), rights);
405
406 // // Store it in the local cache
407 // int myFlags = friend.MyFlags;
408 // friend.MyFlags = rights;
409
410 // // Always send this back to the original client
411 // remoteClient.SendChangeUserRights(requester, target, rights);
412
413 // //
414 // // Notify the friend
415 // //
416
417 // // Try local
418 // if (LocalGrantRights(requester, target, myFlags, rights))
419 // return;
420
421 // PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { target.ToString() });
422 // if (friendSessions != null && friendSessions.Length > 0)
423 // {
424 // PresenceInfo friendSession = friendSessions[0];
425 // if (friendSession != null)
426 // {
427 // GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID);
428 // // TODO: You might want to send the delta to save the lookup
429 // // on the other end!!
430 // m_FriendsSimConnector.GrantRights(region, requester, target, myFlags, rights);
431 // }
432 // }
433 // }
434 //}
435
436
437 } 350 }
438} 351}
diff --git a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
index 170c35f..d7324c6 100644
--- a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
+++ b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
@@ -548,18 +548,18 @@ namespace OpenSim.Region.CoreModules.World.Permissions
548 548
549 // libomv will moan about PrimFlags.ObjectYouOfficer being 549 // libomv will moan about PrimFlags.ObjectYouOfficer being
550 // deprecated 550 // deprecated
551 #pragma warning disable 0612 551#pragma warning disable 0612
552 objflags &= (uint) 552 objflags &= (uint)
553 ~(PrimFlags.ObjectCopy | // Tells client you can copy the object 553 ~(PrimFlags.ObjectCopy | // Tells client you can copy the object
554 PrimFlags.ObjectModify | // tells client you can modify the object 554 PrimFlags.ObjectModify | // tells client you can modify the object
555 PrimFlags.ObjectMove | // tells client that you can move the object (only, no mod) 555 PrimFlags.ObjectMove | // tells client that you can move the object (only, no mod)
556 PrimFlags.ObjectTransfer | // tells the client that you can /take/ the object if you don't own it 556 PrimFlags.ObjectTransfer | // tells the client that you can /take/ the object if you don't own it
557 PrimFlags.ObjectYouOwner | // Tells client that you're the owner of the object 557 PrimFlags.ObjectYouOwner | // Tells client that you're the owner of the object
558 PrimFlags.ObjectAnyOwner | // Tells client that someone owns the object 558 PrimFlags.ObjectAnyOwner | // Tells client that someone owns the object
559 PrimFlags.ObjectOwnerModify | // Tells client that you're the owner of the object 559 PrimFlags.ObjectOwnerModify | // Tells client that you're the owner of the object
560 PrimFlags.ObjectYouOfficer // Tells client that you've got group object editing permission. Used when ObjectGroupOwned is set 560 PrimFlags.ObjectYouOfficer // Tells client that you've got group object editing permission. Used when ObjectGroupOwned is set
561 ); 561 );
562 #pragma warning restore 0612 562#pragma warning restore 0612
563 563
564 // Creating the three ObjectFlags options for this method to choose from. 564 // Creating the three ObjectFlags options for this method to choose from.
565 // Customize the OwnerMask 565 // Customize the OwnerMask
@@ -576,22 +576,27 @@ namespace OpenSim.Region.CoreModules.World.Permissions
576 576
577 if (m_bypassPermissions) 577 if (m_bypassPermissions)
578 return objectOwnerMask; 578 return objectOwnerMask;
579 579
580 // Object owners should be able to edit their own content 580 // Object owners should be able to edit their own content
581 if (user == objectOwner) 581 if (user == objectOwner)
582 return objectOwnerMask; 582 return objectOwnerMask;
583 583
584 if (IsFriendWithPerms(user, objectOwner)) 584 if (IsFriendWithPerms(user, objectOwner))
585 {
585 return objectOwnerMask; 586 return objectOwnerMask;
586 587 }
587 // Estate users should be able to edit anything in the sim if RegionOwnerIsGod is set 588 // Estate users should be able to edit anything in the sim if RegionOwnerIsGod is set
588 if (m_RegionOwnerIsGod && IsEstateManager(user) && !IsAdministrator(objectOwner)) 589 if (m_RegionOwnerIsGod && IsEstateManager(user) && !IsAdministrator(objectOwner))
590 {
589 return objectOwnerMask; 591 return objectOwnerMask;
592 }
590 593
591 // Admin should be able to edit anything in the sim (including admin objects) 594 // Admin should be able to edit anything in the sim (including admin objects)
592 if (IsAdministrator(user)) 595 if (IsAdministrator(user))
596 {
593 return objectOwnerMask; 597 return objectOwnerMask;
594 598 }
599
595 // Users should be able to edit what is over their land. 600 // Users should be able to edit what is over their land.
596 Vector3 taskPos = task.AbsolutePosition; 601 Vector3 taskPos = task.AbsolutePosition;
597 ILandObject parcel = m_scene.LandChannel.GetLandObject(taskPos.X, taskPos.Y); 602 ILandObject parcel = m_scene.LandChannel.GetLandObject(taskPos.X, taskPos.Y);
@@ -599,13 +604,15 @@ namespace OpenSim.Region.CoreModules.World.Permissions
599 { 604 {
600 // Admin objects should not be editable by the above 605 // Admin objects should not be editable by the above
601 if (!IsAdministrator(objectOwner)) 606 if (!IsAdministrator(objectOwner))
607 {
602 return objectOwnerMask; 608 return objectOwnerMask;
609 }
603 } 610 }
604 611
605 // Group permissions 612 // Group permissions
606 if ((task.GroupID != UUID.Zero) && IsGroupMember(task.GroupID, user, 0)) 613 if ((task.GroupID != UUID.Zero) && IsGroupMember(task.GroupID, user, 0))
607 return objectGroupMask | objectEveryoneMask; 614 return objectGroupMask | objectEveryoneMask;
608 615
609 return objectEveryoneMask; 616 return objectEveryoneMask;
610 } 617 }
611 618
@@ -673,7 +680,6 @@ namespace OpenSim.Region.CoreModules.World.Permissions
673 // 680 //
674 // Nobody but the object owner can set permissions on an object 681 // Nobody but the object owner can set permissions on an object
675 // 682 //
676
677 if (locked && (!IsAdministrator(currentUser)) && denyOnLocked) 683 if (locked && (!IsAdministrator(currentUser)) && denyOnLocked)
678 { 684 {
679 return false; 685 return false;
@@ -704,6 +710,11 @@ namespace OpenSim.Region.CoreModules.World.Permissions
704 // Return immediately, so that the administrator can shares group objects 710 // Return immediately, so that the administrator can shares group objects
705 return true; 711 return true;
706 } 712 }
713
714 // Friends with benefits should be able to edit the objects too
715 if (IsFriendWithPerms(currentUser, objectOwner))
716 // Return immediately, so that the administrator can share objects with friends
717 return true;
707 718
708 // Users should be able to edit what is over their land. 719 // Users should be able to edit what is over their land.
709 ILandObject parcel = m_scene.LandChannel.GetLandObject(group.AbsolutePosition.X, group.AbsolutePosition.Y); 720 ILandObject parcel = m_scene.LandChannel.GetLandObject(group.AbsolutePosition.X, group.AbsolutePosition.Y);
diff --git a/OpenSim/Region/Framework/Interfaces/IFriendsModule.cs b/OpenSim/Region/Framework/Interfaces/IFriendsModule.cs
index 0ff7dee..d4a6857 100644
--- a/OpenSim/Region/Framework/Interfaces/IFriendsModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IFriendsModule.cs
@@ -34,6 +34,6 @@ namespace OpenSim.Region.Framework.Interfaces
34 public interface IFriendsModule 34 public interface IFriendsModule
35 { 35 {
36 uint GetFriendPerms(UUID PrincipalID, UUID FriendID); 36 uint GetFriendPerms(UUID PrincipalID, UUID FriendID);
37 void SendFriendsOnlineIfNeeded(IClientAPI client); 37 bool SendFriendsOnlineIfNeeded(IClientAPI client);
38 } 38 }
39} 39}
diff --git a/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs
index 64002e1..71c3c73 100644
--- a/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs
@@ -82,6 +82,9 @@ namespace OpenSim.Server.Handlers.Friends
82 case "getfriends": 82 case "getfriends":
83 return GetFriends(request); 83 return GetFriends(request);
84 84
85 case "getfriends_string":
86 return GetFriendsString(request);
87
85 case "storefriend": 88 case "storefriend":
86 return StoreFriend(request); 89 return StoreFriend(request);
87 90
@@ -111,7 +114,25 @@ namespace OpenSim.Server.Handlers.Friends
111 m_log.WarnFormat("[FRIENDS HANDLER]: no principalID in request to get friends"); 114 m_log.WarnFormat("[FRIENDS HANDLER]: no principalID in request to get friends");
112 115
113 FriendInfo[] finfos = m_FriendsService.GetFriends(principalID); 116 FriendInfo[] finfos = m_FriendsService.GetFriends(principalID);
114 //m_log.DebugFormat("[FRIENDS HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count); 117
118 return PackageFriends(finfos);
119 }
120
121 byte[] GetFriendsString(Dictionary<string, object> request)
122 {
123 string principalID = string.Empty;
124 if (request.ContainsKey("PRINCIPALID"))
125 principalID = request["PRINCIPALID"].ToString();
126 else
127 m_log.WarnFormat("[FRIENDS HANDLER]: no principalID in request to get friends");
128
129 FriendInfo[] finfos = m_FriendsService.GetFriends(principalID);
130
131 return PackageFriends(finfos);
132 }
133
134 private byte[] PackageFriends(FriendInfo[] finfos)
135 {
115 136
116 Dictionary<string, object> result = new Dictionary<string, object>(); 137 Dictionary<string, object> result = new Dictionary<string, object>();
117 if ((finfos == null) || ((finfos != null) && (finfos.Length == 0))) 138 if ((finfos == null) || ((finfos != null) && (finfos.Length == 0)))
diff --git a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs
index 13d1502..dde7875 100644
--- a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs
@@ -82,8 +82,8 @@ namespace OpenSim.Server.Handlers.Hypergrid
82 82
83 switch (method) 83 switch (method)
84 { 84 {
85 case "getfriends": 85 case "getfriendperms":
86 return GetFriends(request); 86 return GetFriendPerms(request);
87 87
88 case "newfriendship": 88 case "newfriendship":
89 return NewFriendship(request); 89 return NewFriendship(request);
@@ -102,58 +102,45 @@ namespace OpenSim.Server.Handlers.Hypergrid
102 102
103 #region Method-specific handlers 103 #region Method-specific handlers
104 104
105 byte[] GetFriends(Dictionary<string, object> request) 105 byte[] GetFriendPerms(Dictionary<string, object> request)
106 { 106 {
107 if (!VerifyServiceKey(request))
108 return FailureResult();
109
107 UUID principalID = UUID.Zero; 110 UUID principalID = UUID.Zero;
108 if (request.ContainsKey("PRINCIPALID")) 111 if (request.ContainsKey("PRINCIPALID"))
109 UUID.TryParse(request["PRINCIPALID"].ToString(), out principalID); 112 UUID.TryParse(request["PRINCIPALID"].ToString(), out principalID);
110 else 113 else
111 m_log.WarnFormat("[HGFRIENDS HANDLER]: no principalID in request to get friends"); 114 {
112 115 m_log.WarnFormat("[HGFRIENDS HANDLER]: no principalID in request to get friend perms");
113 FriendInfo[] finfos = m_FriendsService.GetFriends(principalID); 116 return FailureResult();
114 //m_log.DebugFormat("[FRIENDS HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count); 117 }
115 118
116 Dictionary<string, object> result = new Dictionary<string, object>(); 119 UUID friendID = UUID.Zero;
117 if ((finfos == null) || ((finfos != null) && (finfos.Length == 0))) 120 if (request.ContainsKey("FRIENDID"))
118 result["result"] = "null"; 121 UUID.TryParse(request["FRIENDID"].ToString(), out friendID);
119 else 122 else
120 { 123 {
121 int i = 0; 124 m_log.WarnFormat("[HGFRIENDS HANDLER]: no friendID in request to get friend perms");
122 foreach (FriendInfo finfo in finfos) 125 return FailureResult();
123 {
124 Dictionary<string, object> rinfoDict = finfo.ToKeyValuePairs();
125 result["friend" + i] = rinfoDict;
126 i++;
127 }
128 } 126 }
129 127
130 string xmlString = ServerUtils.BuildXmlResponse(result); 128 string perms = "0";
131 //m_log.DebugFormat("[FRIENDS HANDLER]: resp string: {0}", xmlString); 129 FriendInfo[] friendsInfo = m_FriendsService.GetFriends(principalID);
132 UTF8Encoding encoding = new UTF8Encoding(); 130 foreach (FriendInfo finfo in friendsInfo)
133 return encoding.GetBytes(xmlString); 131 {
132 if (finfo.Friend.StartsWith(friendID.ToString()))
133 return SuccessResult(finfo.TheirFlags.ToString());
134 }
134 135
136 return FailureResult("Friend not found");
135 } 137 }
136 138
137 byte[] NewFriendship(Dictionary<string, object> request) 139 byte[] NewFriendship(Dictionary<string, object> request)
138 { 140 {
139 if (!request.ContainsKey("KEY") || !request.ContainsKey("SESSIONID")) 141 if (!VerifyServiceKey(request))
140 {
141 m_log.WarnFormat("[HGFRIENDS HANDLER]: ignoring request without Key or SessionID");
142 return FailureResult();
143 }
144
145 string serviceKey = request["KEY"].ToString();
146 string sessionStr = request["SESSIONID"].ToString();
147 UUID sessionID;
148 UUID.TryParse(sessionStr, out sessionID);
149
150 if (!m_UserAgentService.VerifyAgent(sessionID, serviceKey))
151 {
152 m_log.WarnFormat("[HGFRIENDS HANDLER]: Key {0} for session {1} did not match existing key. Ignoring request", serviceKey, sessionID);
153 return FailureResult(); 142 return FailureResult();
154 }
155 143
156 m_log.DebugFormat("[XXX] Verification ok");
157 // OK, can proceed 144 // OK, can proceed
158 FriendInfo friend = new FriendInfo(request); 145 FriendInfo friend = new FriendInfo(request);
159 146
@@ -172,6 +159,29 @@ namespace OpenSim.Server.Handlers.Hypergrid
172 159
173 #region Misc 160 #region Misc
174 161
162 private bool VerifyServiceKey(Dictionary<string, object> request)
163 {
164 if (!request.ContainsKey("KEY") || !request.ContainsKey("SESSIONID"))
165 {
166 m_log.WarnFormat("[HGFRIENDS HANDLER]: ignoring request without Key or SessionID");
167 return false;
168 }
169
170 string serviceKey = request["KEY"].ToString();
171 string sessionStr = request["SESSIONID"].ToString();
172 UUID sessionID;
173 UUID.TryParse(sessionStr, out sessionID);
174
175 if (!m_UserAgentService.VerifyAgent(sessionID, serviceKey))
176 {
177 m_log.WarnFormat("[HGFRIENDS HANDLER]: Key {0} for session {1} did not match existing key. Ignoring request", serviceKey, sessionID);
178 return false;
179 }
180
181 m_log.DebugFormat("[XXX] Verification ok");
182 return true;
183 }
184
175 private byte[] SuccessResult() 185 private byte[] SuccessResult()
176 { 186 {
177 XmlDocument doc = new XmlDocument(); 187 XmlDocument doc = new XmlDocument();
@@ -194,6 +204,34 @@ namespace OpenSim.Server.Handlers.Hypergrid
194 return DocToBytes(doc); 204 return DocToBytes(doc);
195 } 205 }
196 206
207 private byte[] SuccessResult(string value)
208 {
209 XmlDocument doc = new XmlDocument();
210
211 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
212 "", "");
213
214 doc.AppendChild(xmlnode);
215
216 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
217 "");
218
219 doc.AppendChild(rootElement);
220
221 XmlElement result = doc.CreateElement("", "Result", "");
222 result.AppendChild(doc.CreateTextNode("Success"));
223
224 rootElement.AppendChild(result);
225
226 XmlElement message = doc.CreateElement("", "Value", "");
227 message.AppendChild(doc.CreateTextNode(value));
228
229 rootElement.AppendChild(message);
230
231 return DocToBytes(doc);
232 }
233
234
197 private byte[] FailureResult() 235 private byte[] FailureResult()
198 { 236 {
199 return FailureResult(String.Empty); 237 return FailureResult(String.Empty);
diff --git a/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs b/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs
index 52b80e1..d1afea2 100644
--- a/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs
@@ -84,7 +84,7 @@ namespace OpenSim.Services.Connectors.Friends
84 84
85 85
86 #region IFriendsService 86 #region IFriendsService
87 87
88 public FriendInfo[] GetFriends(UUID PrincipalID) 88 public FriendInfo[] GetFriends(UUID PrincipalID)
89 { 89 {
90 Dictionary<string, object> sendData = new Dictionary<string, object>(); 90 Dictionary<string, object> sendData = new Dictionary<string, object>();
@@ -92,6 +92,21 @@ namespace OpenSim.Services.Connectors.Friends
92 sendData["PRINCIPALID"] = PrincipalID.ToString(); 92 sendData["PRINCIPALID"] = PrincipalID.ToString();
93 sendData["METHOD"] = "getfriends"; 93 sendData["METHOD"] = "getfriends";
94 94
95 return GetFriends(sendData, PrincipalID.ToString());
96 }
97
98 public FriendInfo[] GetFriends(string PrincipalID)
99 {
100 Dictionary<string, object> sendData = new Dictionary<string, object>();
101
102 sendData["PRINCIPALID"] = PrincipalID;
103 sendData["METHOD"] = "getfriends_string";
104
105 return GetFriends(sendData, PrincipalID);
106 }
107
108 protected FriendInfo[] GetFriends(Dictionary<string, object> sendData, string PrincipalID)
109 {
95 string reqString = ServerUtils.BuildQueryString(sendData); 110 string reqString = ServerUtils.BuildQueryString(sendData);
96 111
97 try 112 try
diff --git a/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs
index 76f5f19..f823889 100644
--- a/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Hypergrid/HGFriendsServiceConnector.cs
@@ -63,12 +63,13 @@ namespace OpenSim.Services.Connectors.Hypergrid
63 63
64 #region IFriendsService 64 #region IFriendsService
65 65
66 public FriendInfo[] GetFriends(UUID PrincipalID) 66 public uint GetFriendPerms(UUID PrincipalID, UUID friendID)
67 { 67 {
68 Dictionary<string, object> sendData = new Dictionary<string, object>(); 68 Dictionary<string, object> sendData = new Dictionary<string, object>();
69 69
70 sendData["PRINCIPALID"] = PrincipalID.ToString(); 70 sendData["PRINCIPALID"] = PrincipalID.ToString();
71 sendData["METHOD"] = "getfriends"; 71 sendData["FRIENDID"] = friendID.ToString();
72 sendData["METHOD"] = "getfriendperms";
72 sendData["KEY"] = m_ServiceKey; 73 sendData["KEY"] = m_ServiceKey;
73 sendData["SESSIONID"] = m_SessionID.ToString(); 74 sendData["SESSIONID"] = m_SessionID.ToString();
74 75
@@ -83,34 +84,14 @@ namespace OpenSim.Services.Connectors.Hypergrid
83 { 84 {
84 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); 85 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
85 86
86 if (replyData != null) 87 if ((replyData != null) && replyData.ContainsKey("Value") && (replyData["Value"] != null))
87 { 88 {
88 if (replyData.ContainsKey("result") && (replyData["result"].ToString().ToLower() == "null")) 89 uint perms = 0;
89 { 90 uint.TryParse(replyData["Value"].ToString(), out perms);
90 return new FriendInfo[0]; 91 return perms;
91 }
92
93 List<FriendInfo> finfos = new List<FriendInfo>();
94 Dictionary<string, object>.ValueCollection finfosList = replyData.Values;
95 //m_log.DebugFormat("[FRIENDS CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count);
96 foreach (object f in finfosList)
97 {
98 if (f is Dictionary<string, object>)
99 {
100 FriendInfo finfo = new FriendInfo((Dictionary<string, object>)f);
101 finfos.Add(finfo);
102 }
103 else
104 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: GetFriends {0} received invalid response type {1}",
105 PrincipalID, f.GetType());
106 }
107
108 // Success
109 return finfos.ToArray();
110 } 92 }
111
112 else 93 else
113 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: GetFriends {0} received null response", 94 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: GetFriendPerms {0} received null response",
114 PrincipalID); 95 PrincipalID);
115 96
116 } 97 }
@@ -120,7 +101,7 @@ namespace OpenSim.Services.Connectors.Hypergrid
120 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server: {0}", e.Message); 101 m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server: {0}", e.Message);
121 } 102 }
122 103
123 return new FriendInfo[0]; 104 return 0;
124 105
125 } 106 }
126 107
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianFriendsServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianFriendsServiceConnector.cs
index f61ab29..b1c34dd 100644
--- a/OpenSim/Services/Connectors/SimianGrid/SimianFriendsServiceConnector.cs
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianFriendsServiceConnector.cs
@@ -78,6 +78,11 @@ namespace OpenSim.Services.Connectors.SimianGrid
78 78
79 public FriendInfo[] GetFriends(UUID principalID) 79 public FriendInfo[] GetFriends(UUID principalID)
80 { 80 {
81 return GetFriends(principalID.ToString());
82 }
83
84 public FriendInfo[] GetFriends(string principalID)
85 {
81 if (String.IsNullOrEmpty(m_serverUrl)) 86 if (String.IsNullOrEmpty(m_serverUrl))
82 return new FriendInfo[0]; 87 return new FriendInfo[0];
83 88
@@ -95,7 +100,14 @@ namespace OpenSim.Services.Connectors.SimianGrid
95 UUID friendID = friendEntry["Key"].AsUUID(); 100 UUID friendID = friendEntry["Key"].AsUUID();
96 101
97 FriendInfo friend = new FriendInfo(); 102 FriendInfo friend = new FriendInfo();
98 friend.PrincipalID = principalID; 103 if (!UUID.TryParse(principalID, out friend.PrincipalID))
104 {
105 string tmp = string.Empty;
106 if (!Util.ParseUniversalUserIdentifier(principalID, out friend.PrincipalID, out tmp, out tmp, out tmp))
107 // bad record. ignore this entry
108 continue;
109 }
110
99 friend.Friend = friendID.ToString(); 111 friend.Friend = friendID.ToString();
100 friend.MyFlags = friendEntry["Value"].AsInteger(); 112 friend.MyFlags = friendEntry["Value"].AsInteger();
101 friend.TheirFlags = -1; 113 friend.TheirFlags = -1;
@@ -174,7 +186,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
174 186
175 #endregion IFriendsService 187 #endregion IFriendsService
176 188
177 private OSDArray GetFriended(UUID ownerID) 189 private OSDArray GetFriended(string ownerID)
178 { 190 {
179 NameValueCollection requestArgs = new NameValueCollection 191 NameValueCollection requestArgs = new NameValueCollection
180 { 192 {
@@ -195,7 +207,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
195 } 207 }
196 } 208 }
197 209
198 private OSDArray GetFriendedBy(UUID ownerID) 210 private OSDArray GetFriendedBy(string ownerID)
199 { 211 {
200 NameValueCollection requestArgs = new NameValueCollection 212 NameValueCollection requestArgs = new NameValueCollection
201 { 213 {
diff --git a/OpenSim/Services/Friends/FriendsService.cs b/OpenSim/Services/Friends/FriendsService.cs
index 039dc0b..4664cb3 100644
--- a/OpenSim/Services/Friends/FriendsService.cs
+++ b/OpenSim/Services/Friends/FriendsService.cs
@@ -63,6 +63,32 @@ namespace OpenSim.Services.Friends
63 return info.ToArray(); 63 return info.ToArray();
64 } 64 }
65 65
66 public virtual FriendInfo[] GetFriends(string PrincipalID)
67 {
68 FriendsData[] data = m_Database.GetFriends(PrincipalID);
69 List<FriendInfo> info = new List<FriendInfo>();
70
71 foreach (FriendsData d in data)
72 {
73 FriendInfo i = new FriendInfo();
74
75 if (!UUID.TryParse(d.PrincipalID, out i.PrincipalID))
76 {
77 string tmp = string.Empty;
78 if (!Util.ParseUniversalUserIdentifier(d.PrincipalID, out i.PrincipalID, out tmp, out tmp, out tmp))
79 // bad record. ignore this entry
80 continue;
81 }
82 i.Friend = d.Friend;
83 i.MyFlags = Convert.ToInt32(d.Data["Flags"]);
84 i.TheirFlags = Convert.ToInt32(d.Data["TheirFlags"]);
85
86 info.Add(i);
87 }
88
89 return info.ToArray();
90 }
91
66 public virtual bool StoreFriend(string PrincipalID, string Friend, int flags) 92 public virtual bool StoreFriend(string PrincipalID, string Friend, int flags)
67 { 93 {
68 FriendsData d = new FriendsData(); 94 FriendsData d = new FriendsData();
diff --git a/OpenSim/Services/HypergridService/HGFriendsService.cs b/OpenSim/Services/HypergridService/HGFriendsService.cs
index fa4ec5d..3ffe889 100644
--- a/OpenSim/Services/HypergridService/HGFriendsService.cs
+++ b/OpenSim/Services/HypergridService/HGFriendsService.cs
@@ -62,7 +62,7 @@ namespace OpenSim.Services.HypergridService
62 UUID userID; 62 UUID userID;
63 if (UUID.TryParse(PrincipalID, out userID)) 63 if (UUID.TryParse(PrincipalID, out userID))
64 { 64 {
65 FriendsData[] friendsData = m_Database.GetFriends(userID); 65 FriendsData[] friendsData = m_Database.GetFriends(userID.ToString());
66 List<FriendsData> fList = new List<FriendsData>(friendsData); 66 List<FriendsData> fList = new List<FriendsData>(friendsData);
67 if (fList.Find(delegate(FriendsData fdata) 67 if (fList.Find(delegate(FriendsData fdata)
68 { 68 {
@@ -70,6 +70,8 @@ namespace OpenSim.Services.HypergridService
70 }) != null) 70 }) != null)
71 return false; 71 return false;
72 } 72 }
73 else
74 return false;
73 75
74 FriendsData d = new FriendsData(); 76 FriendsData d = new FriendsData();
75 d.PrincipalID = PrincipalID; 77 d.PrincipalID = PrincipalID;
diff --git a/OpenSim/Services/Interfaces/IFriendsService.cs b/OpenSim/Services/Interfaces/IFriendsService.cs
index 05e85f2..0a8efad 100644
--- a/OpenSim/Services/Interfaces/IFriendsService.cs
+++ b/OpenSim/Services/Interfaces/IFriendsService.cs
@@ -74,6 +74,7 @@ namespace OpenSim.Services.Interfaces
74 public interface IFriendsService 74 public interface IFriendsService
75 { 75 {
76 FriendInfo[] GetFriends(UUID PrincipalID); 76 FriendInfo[] GetFriends(UUID PrincipalID);
77 FriendInfo[] GetFriends(string PrincipalID);
77 bool StoreFriend(string PrincipalID, string Friend, int flags); 78 bool StoreFriend(string PrincipalID, string Friend, int flags);
78 bool Delete(UUID PrincipalID, string Friend); 79 bool Delete(UUID PrincipalID, string Friend);
79 } 80 }