diff options
author | Diva Canto | 2011-05-19 16:54:46 -0700 |
---|---|---|
committer | Diva Canto | 2011-05-19 16:54:46 -0700 |
commit | d21e9c755f004d8fe03b11bc57b810dbd401435a (patch) | |
tree | 1efd9e48308192d21ca73d8ff12d6a48c186077c /OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs | |
parent | Accidentally committed too early (diff) | |
download | opensim-SC_OLD-d21e9c755f004d8fe03b11bc57b810dbd401435a.zip opensim-SC_OLD-d21e9c755f004d8fe03b11bc57b810dbd401435a.tar.gz opensim-SC_OLD-d21e9c755f004d8fe03b11bc57b810dbd401435a.tar.bz2 opensim-SC_OLD-d21e9c755f004d8fe03b11bc57b810dbd401435a.tar.xz |
HG Friends working to some extent: friendships offered and accepted correctly handled. Friends list showing correct foreign names. TODO: GrantRights.
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs | 151 |
1 files changed, 112 insertions, 39 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 5baf078..21cd924 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs | |||
@@ -49,6 +49,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
49 | { | 49 | { |
50 | public class FriendsModule : ISharedRegionModule, IFriendsModule | 50 | public class FriendsModule : ISharedRegionModule, IFriendsModule |
51 | { | 51 | { |
52 | protected bool m_Enabled = false; | ||
53 | |||
52 | protected class UserFriendData | 54 | protected class UserFriendData |
53 | { | 55 | { |
54 | public UUID PrincipalID; | 56 | public UUID PrincipalID; |
@@ -130,8 +132,26 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
130 | } | 132 | } |
131 | } | 133 | } |
132 | 134 | ||
135 | #region ISharedRegionModule | ||
133 | public void Initialise(IConfigSource config) | 136 | public void Initialise(IConfigSource config) |
134 | { | 137 | { |
138 | IConfig moduleConfig = config.Configs["Modules"]; | ||
139 | if (moduleConfig != null) | ||
140 | { | ||
141 | string name = moduleConfig.GetString("FriendsModule", "FriendsModule"); | ||
142 | m_log.DebugFormat("[XXX] {0} compared to {1}", name, Name); | ||
143 | if (name == Name) | ||
144 | { | ||
145 | InitModule(config); | ||
146 | |||
147 | m_Enabled = true; | ||
148 | m_log.InfoFormat("[FRIENDS MODULE]: {0} enabled.", Name); | ||
149 | } | ||
150 | } | ||
151 | } | ||
152 | |||
153 | protected void InitModule(IConfigSource config) | ||
154 | { | ||
135 | IConfig friendsConfig = config.Configs["Friends"]; | 155 | IConfig friendsConfig = config.Configs["Friends"]; |
136 | if (friendsConfig != null) | 156 | if (friendsConfig != null) |
137 | { | 157 | { |
@@ -153,7 +173,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
153 | m_log.Error("[FRIENDS]: No Connector defined in section Friends, or failed to load, cannot continue"); | 173 | m_log.Error("[FRIENDS]: No Connector defined in section Friends, or failed to load, cannot continue"); |
154 | throw new Exception("Connector load error"); | 174 | throw new Exception("Connector load error"); |
155 | } | 175 | } |
156 | |||
157 | } | 176 | } |
158 | 177 | ||
159 | public void PostInitialise() | 178 | public void PostInitialise() |
@@ -166,6 +185,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
166 | 185 | ||
167 | public void AddRegion(Scene scene) | 186 | public void AddRegion(Scene scene) |
168 | { | 187 | { |
188 | if (!m_Enabled) | ||
189 | return; | ||
190 | |||
169 | m_Scenes.Add(scene); | 191 | m_Scenes.Add(scene); |
170 | scene.RegisterModuleInterface<IFriendsModule>(this); | 192 | scene.RegisterModuleInterface<IFriendsModule>(this); |
171 | 193 | ||
@@ -181,10 +203,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
181 | 203 | ||
182 | public void RemoveRegion(Scene scene) | 204 | public void RemoveRegion(Scene scene) |
183 | { | 205 | { |
206 | if (!m_Enabled) | ||
207 | return; | ||
208 | |||
184 | m_Scenes.Remove(scene); | 209 | m_Scenes.Remove(scene); |
185 | } | 210 | } |
186 | 211 | ||
187 | public string Name | 212 | public virtual string Name |
188 | { | 213 | { |
189 | get { return "FriendsModule"; } | 214 | get { return "FriendsModule"; } |
190 | } | 215 | } |
@@ -194,6 +219,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
194 | get { return null; } | 219 | get { return null; } |
195 | } | 220 | } |
196 | 221 | ||
222 | #endregion | ||
223 | |||
197 | public uint GetFriendPerms(UUID principalID, UUID friendID) | 224 | public uint GetFriendPerms(UUID principalID, UUID friendID) |
198 | { | 225 | { |
199 | FriendInfo[] friends = GetFriends(principalID); | 226 | FriendInfo[] friends = GetFriends(principalID); |
@@ -214,30 +241,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
214 | client.OnTerminateFriendship += OnTerminateFriendship; | 241 | client.OnTerminateFriendship += OnTerminateFriendship; |
215 | client.OnGrantUserRights += OnGrantUserRights; | 242 | client.OnGrantUserRights += OnGrantUserRights; |
216 | 243 | ||
217 | // Asynchronously fetch the friends list or increment the refcount for the existing | 244 | Util.FireAndForget(delegate { FetchFriendslist(client.AgentId); }); |
218 | // friends list | 245 | } |
219 | Util.FireAndForget( | 246 | |
220 | delegate(object o) | 247 | /// Fetch the friends list or increment the refcount for the existing |
248 | /// friends list | ||
249 | /// Returns true if the list was fetched, false if it wasn't | ||
250 | protected virtual bool FetchFriendslist(UUID agentID) | ||
251 | { | ||
252 | lock (m_Friends) | ||
253 | { | ||
254 | UserFriendData friendsData; | ||
255 | if (m_Friends.TryGetValue(agentID, out friendsData)) | ||
221 | { | 256 | { |
222 | lock (m_Friends) | 257 | friendsData.Refcount++; |
223 | { | 258 | return false; |
224 | UserFriendData friendsData; | 259 | } |
225 | if (m_Friends.TryGetValue(client.AgentId, out friendsData)) | 260 | else |
226 | { | 261 | { |
227 | friendsData.Refcount++; | 262 | friendsData = new UserFriendData(); |
228 | } | 263 | friendsData.PrincipalID = agentID; |
229 | else | 264 | friendsData.Friends = FriendsService.GetFriends(agentID); |
230 | { | 265 | friendsData.Refcount = 1; |
231 | friendsData = new UserFriendData(); | ||
232 | friendsData.PrincipalID = client.AgentId; | ||
233 | friendsData.Friends = FriendsService.GetFriends(client.AgentId); | ||
234 | friendsData.Refcount = 1; | ||
235 | 266 | ||
236 | m_Friends[client.AgentId] = friendsData; | 267 | m_Friends[agentID] = friendsData; |
237 | } | 268 | return true; |
238 | } | ||
239 | } | 269 | } |
240 | ); | 270 | } |
241 | } | 271 | } |
242 | 272 | ||
243 | private void OnClientClosed(UUID agentID, Scene scene) | 273 | private void OnClientClosed(UUID agentID, Scene scene) |
@@ -313,10 +343,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
313 | foreach (string fid in outstanding) | 343 | foreach (string fid in outstanding) |
314 | { | 344 | { |
315 | UUID fromAgentID; | 345 | UUID fromAgentID; |
316 | if (!UUID.TryParse(fid, out fromAgentID)) | 346 | string firstname = "Unknown", lastname = "User"; |
347 | if (!GetAgentInfo(client.Scene.RegionInfo.ScopeID, fid, out fromAgentID, out firstname, out lastname)) | ||
348 | { | ||
349 | m_log.DebugFormat("[FRIENDS MODULE]: skipping malformed friend {0}", fid); | ||
317 | continue; | 350 | continue; |
318 | 351 | } | |
319 | UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID, fromAgentID); | ||
320 | 352 | ||
321 | PresenceInfo presence = null; | 353 | PresenceInfo presence = null; |
322 | PresenceInfo[] presences = PresenceService.GetAgents(new string[] { fid }); | 354 | PresenceInfo[] presences = PresenceService.GetAgents(new string[] { fid }); |
@@ -326,15 +358,37 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
326 | im.offline = 0; | 358 | im.offline = 0; |
327 | 359 | ||
328 | im.fromAgentID = fromAgentID.Guid; | 360 | im.fromAgentID = fromAgentID.Guid; |
329 | im.fromAgentName = account.FirstName + " " + account.LastName; | 361 | im.fromAgentName = firstname + " " + lastname; |
330 | im.offline = (byte)((presence == null) ? 1 : 0); | 362 | im.offline = (byte)((presence == null) ? 1 : 0); |
331 | im.imSessionID = im.fromAgentID; | 363 | im.imSessionID = im.fromAgentID; |
364 | im.message = FriendshipMessage(fid); | ||
332 | 365 | ||
333 | // Finally | 366 | // Finally |
334 | LocalFriendshipOffered(agentID, im); | 367 | LocalFriendshipOffered(agentID, im); |
335 | } | 368 | } |
336 | } | 369 | } |
337 | 370 | ||
371 | protected virtual string FriendshipMessage(string friendID) | ||
372 | { | ||
373 | return "Will you be my friend?"; | ||
374 | } | ||
375 | |||
376 | protected virtual bool GetAgentInfo(UUID scopeID, string fid, out UUID agentID, out string first, out string last) | ||
377 | { | ||
378 | first = "Unknown"; last = "User"; | ||
379 | if (!UUID.TryParse(fid, out agentID)) | ||
380 | return false; | ||
381 | |||
382 | UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(scopeID, agentID); | ||
383 | if (account != null) | ||
384 | { | ||
385 | first = account.FirstName; | ||
386 | last = account.LastName; | ||
387 | } | ||
388 | |||
389 | return true; | ||
390 | } | ||
391 | |||
338 | List<UUID> GetOnlineFriends(UUID userID) | 392 | List<UUID> GetOnlineFriends(UUID userID) |
339 | { | 393 | { |
340 | List<string> friendList = new List<string>(); | 394 | List<string> friendList = new List<string>(); |
@@ -475,23 +529,26 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
475 | 529 | ||
476 | // This user wants to be friends with the other user. | 530 | // This user wants to be friends with the other user. |
477 | // Let's add the relation backwards, in case the other is not online | 531 | // Let's add the relation backwards, in case the other is not online |
478 | FriendsService.StoreFriend(friendID, principalID.ToString(), 0); | 532 | StoreBackwards(friendID, principalID); |
479 | 533 | ||
480 | // Now let's ask the other user to be friends with this user | 534 | // Now let's ask the other user to be friends with this user |
481 | ForwardFriendshipOffer(principalID, friendID, im); | 535 | ForwardFriendshipOffer(principalID, friendID, im); |
482 | } | 536 | } |
483 | } | 537 | } |
484 | 538 | ||
539 | protected virtual void StoreBackwards(UUID friendID, UUID agentID) | ||
540 | { | ||
541 | FriendsService.StoreFriend(friendID.ToString(), agentID.ToString(), 0); | ||
542 | } | ||
543 | |||
485 | private void ForwardFriendshipOffer(UUID agentID, UUID friendID, GridInstantMessage im) | 544 | private void ForwardFriendshipOffer(UUID agentID, UUID friendID, GridInstantMessage im) |
486 | { | 545 | { |
487 | // !!!!!!!! This is a hack so that we don't have to keep state (transactionID/imSessionID) | 546 | // !!!!!!!! This is a hack so that we don't have to keep state (transactionID/imSessionID) |
488 | // We stick this agent's ID as imSession, so that it's directly available on the receiving end | 547 | // We stick this agent's ID as imSession, so that it's directly available on the receiving end |
489 | im.imSessionID = im.fromAgentID; | 548 | im.imSessionID = im.fromAgentID; |
549 | im.fromAgentName = GetFriendshipRequesterName(agentID); | ||
490 | 550 | ||
491 | // Try the local sim | 551 | // Try the local sim |
492 | UserAccount account = UserAccountService.GetUserAccount(UUID.Zero, agentID); | ||
493 | im.fromAgentName = (account == null) ? "Unknown" : account.FirstName + " " + account.LastName; | ||
494 | |||
495 | if (LocalFriendshipOffered(friendID, im)) | 552 | if (LocalFriendshipOffered(friendID, im)) |
496 | return; | 553 | return; |
497 | 554 | ||
@@ -509,12 +566,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
509 | // If the prospective friend is not online, he'll get the message upon login. | 566 | // If the prospective friend is not online, he'll get the message upon login. |
510 | } | 567 | } |
511 | 568 | ||
569 | protected virtual string GetFriendshipRequesterName(UUID agentID) | ||
570 | { | ||
571 | UserAccount account = UserAccountService.GetUserAccount(UUID.Zero, agentID); | ||
572 | return (account == null) ? "Unknown" : account.FirstName + " " + account.LastName; | ||
573 | } | ||
574 | |||
512 | private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) | 575 | private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) |
513 | { | 576 | { |
514 | m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", agentID, friendID); | 577 | m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", agentID, friendID); |
515 | 578 | ||
516 | FriendsService.StoreFriend(agentID, friendID.ToString(), 1); | 579 | StoreFriendships(agentID, friendID); |
517 | FriendsService.StoreFriend(friendID, agentID.ToString(), 1); | ||
518 | 580 | ||
519 | // Update the local cache | 581 | // Update the local cache |
520 | UpdateFriendsCache(agentID); | 582 | UpdateFriendsCache(agentID); |
@@ -544,6 +606,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
544 | } | 606 | } |
545 | } | 607 | } |
546 | 608 | ||
609 | protected virtual void StoreFriendships(UUID agentID, UUID friendID) | ||
610 | { | ||
611 | FriendsService.StoreFriend(agentID.ToString(), friendID.ToString(), 1); | ||
612 | FriendsService.StoreFriend(friendID.ToString(), agentID.ToString(), 1); | ||
613 | } | ||
614 | |||
547 | private void OnDenyFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) | 615 | private void OnDenyFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) |
548 | { | 616 | { |
549 | m_log.DebugFormat("[FRIENDS]: {0} denied friendship to {1}", agentID, friendID); | 617 | m_log.DebugFormat("[FRIENDS]: {0} denied friendship to {1}", agentID, friendID); |
@@ -576,8 +644,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
576 | 644 | ||
577 | private void OnTerminateFriendship(IClientAPI client, UUID agentID, UUID exfriendID) | 645 | private void OnTerminateFriendship(IClientAPI client, UUID agentID, UUID exfriendID) |
578 | { | 646 | { |
579 | FriendsService.Delete(agentID, exfriendID.ToString()); | 647 | DeleteFriendship(agentID, exfriendID); |
580 | FriendsService.Delete(exfriendID, agentID.ToString()); | ||
581 | 648 | ||
582 | // Update local cache | 649 | // Update local cache |
583 | UpdateFriendsCache(agentID); | 650 | UpdateFriendsCache(agentID); |
@@ -604,6 +671,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
604 | } | 671 | } |
605 | } | 672 | } |
606 | 673 | ||
674 | protected virtual void DeleteFriendship(UUID agentID, UUID exfriendID) | ||
675 | { | ||
676 | FriendsService.Delete(agentID, exfriendID.ToString()); | ||
677 | FriendsService.Delete(exfriendID, agentID.ToString()); | ||
678 | } | ||
679 | |||
607 | private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights) | 680 | private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights) |
608 | { | 681 | { |
609 | FriendInfo[] friends = GetFriends(remoteClient.AgentId); | 682 | FriendInfo[] friends = GetFriends(remoteClient.AgentId); |
@@ -622,7 +695,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
622 | if (friend != null) // Found it | 695 | if (friend != null) // Found it |
623 | { | 696 | { |
624 | // Store it on the DB | 697 | // Store it on the DB |
625 | FriendsService.StoreFriend(requester, target.ToString(), rights); | 698 | FriendsService.StoreFriend(requester.ToString(), target.ToString(), rights); |
626 | 699 | ||
627 | // Store it in the local cache | 700 | // Store it in the local cache |
628 | int myFlags = friend.MyFlags; | 701 | int myFlags = friend.MyFlags; |
@@ -780,7 +853,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
780 | 853 | ||
781 | #endregion | 854 | #endregion |
782 | 855 | ||
783 | private FriendInfo[] GetFriends(UUID agentID) | 856 | protected FriendInfo[] GetFriends(UUID agentID) |
784 | { | 857 | { |
785 | UserFriendData friendsData; | 858 | UserFriendData friendsData; |
786 | 859 | ||