aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
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/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-58c53c41de2cae0bb041a2e8121792e136d1edb2.zip
opensim-SC_OLD-58c53c41de2cae0bb041a2e8121792e136d1edb2.tar.gz
opensim-SC_OLD-58c53c41de2cae0bb041a2e8121792e136d1edb2.tar.bz2
opensim-SC_OLD-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 'OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs259
1 files changed, 86 insertions, 173 deletions
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}