aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs31
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs290
2 files changed, 202 insertions, 119 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
index c266fe5..f6a31b5 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
@@ -550,7 +550,19 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
550 UUID principalID = new UUID(im.fromAgentID); 550 UUID principalID = new UUID(im.fromAgentID);
551 UUID friendID = new UUID(im.toAgentID); 551 UUID friendID = new UUID(im.toAgentID);
552 552
553 m_log.DebugFormat("[FRIENDS]: {0} ({1}) offered friendship to {2}", principalID, im.fromAgentName, friendID); 553 m_log.DebugFormat("[FRIENDS]: {0} ({1}) offered friendship to {2} ({3})", principalID, client.FirstName + client.LastName, friendID, im.fromAgentName);
554
555 // Check that the friendship doesn't exist yet
556 FriendInfo[] finfos = GetFriends(principalID);
557 if (finfos != null)
558 {
559 FriendInfo f = GetFriend(finfos, friendID);
560 if (f != null)
561 {
562 client.SendAgentAlertMessage("This person is already your friend. Please delete it first if you want to reestablish the friendship.", false);
563 return;
564 }
565 }
554 566
555 // This user wants to be friends with the other user. 567 // This user wants to be friends with the other user.
556 // Let's add the relation backwards, in case the other is not online 568 // Let's add the relation backwards, in case the other is not online
@@ -561,7 +573,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
561 } 573 }
562 } 574 }
563 575
564 private void ForwardFriendshipOffer(UUID agentID, UUID friendID, GridInstantMessage im) 576 protected virtual bool ForwardFriendshipOffer(UUID agentID, UUID friendID, GridInstantMessage im)
565 { 577 {
566 // !!!!!!!! This is a hack so that we don't have to keep state (transactionID/imSessionID) 578 // !!!!!!!! This is a hack so that we don't have to keep state (transactionID/imSessionID)
567 // We stick this agent's ID as imSession, so that it's directly available on the receiving end 579 // We stick this agent's ID as imSession, so that it's directly available on the receiving end
@@ -570,7 +582,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
570 582
571 // Try the local sim 583 // Try the local sim
572 if (LocalFriendshipOffered(friendID, im)) 584 if (LocalFriendshipOffered(friendID, im))
573 return; 585 {
586 m_log.DebugFormat("[XXX]: LocalFriendshipOffered successes");
587 return true;
588 }
574 589
575 // The prospective friend is not here [as root]. Let's forward. 590 // The prospective friend is not here [as root]. Let's forward.
576 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); 591 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() });
@@ -581,9 +596,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
581 { 596 {
582 GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); 597 GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID);
583 m_FriendsSimConnector.FriendshipOffered(region, agentID, friendID, im.message); 598 m_FriendsSimConnector.FriendshipOffered(region, agentID, friendID, im.message);
599 return true;
584 } 600 }
585 } 601 }
586 // If the prospective friend is not online, he'll get the message upon login. 602 // If the prospective friend is not online, he'll get the message upon login.
603 return false;
587 } 604 }
588 605
589 protected virtual string GetFriendshipRequesterName(UUID agentID) 606 protected virtual string GetFriendshipRequesterName(UUID agentID)
@@ -592,7 +609,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
592 return (account == null) ? "Unknown" : account.FirstName + " " + account.LastName; 609 return (account == null) ? "Unknown" : account.FirstName + " " + account.LastName;
593 } 610 }
594 611
595 private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) 612 protected virtual void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders)
596 { 613 {
597 m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", client.AgentId, friendID); 614 m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", client.AgentId, friendID);
598 615
@@ -603,7 +620,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
603 { 620 {
604 StoreFriendships(client.AgentId, friendID); 621 StoreFriendships(client.AgentId, friendID);
605 622
606 // Update the local cache 623 // Update the local cache.
607 RecacheFriends(client); 624 RecacheFriends(client);
608 625
609 // 626 //
@@ -756,7 +773,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
756 773
757 #region Local 774 #region Local
758 775
759 public bool LocalFriendshipOffered(UUID toID, GridInstantMessage im) 776 public virtual bool LocalFriendshipOffered(UUID toID, GridInstantMessage im)
760 { 777 {
761 IClientAPI friendClient = LocateClientObject(toID); 778 IClientAPI friendClient = LocateClientObject(toID);
762 if (friendClient != null) 779 if (friendClient != null)
@@ -912,7 +929,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
912 return FriendsService.GetFriends(client.AgentId); 929 return FriendsService.GetFriends(client.AgentId);
913 } 930 }
914 931
915 private void RecacheFriends(IClientAPI client) 932 protected void RecacheFriends(IClientAPI client)
916 { 933 {
917 // FIXME: Ideally, we want to avoid doing this here since it sits the EventManager.OnMakeRootAgent event 934 // FIXME: Ideally, we want to avoid doing this here since it sits the EventManager.OnMakeRootAgent event
918 // is on the critical path for transferring an avatar from one region to another. 935 // is on the critical path for transferring an avatar from one region to another.
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
index 9c53fc4..0fe1134 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
@@ -61,6 +61,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
61 } 61 }
62 } 62 }
63 63
64 protected HGFriendsServicesConnector m_HGFriendsConnector = new HGFriendsServicesConnector();
65
64 #region ISharedRegionModule 66 #region ISharedRegionModule
65 public override string Name 67 public override string Name
66 { 68 {
@@ -94,6 +96,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
94 96
95 #endregion 97 #endregion
96 98
99 protected override void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders)
100 {
101 // Update the local cache. Yes, we need to do it right here
102 // because the HGFriendsService placed something on the DB
103 // from under the sim
104 base.OnApproveFriendRequest(client, agentID, friendID, callingCardFolders);
105 }
106
97 protected override bool CacheFriends(IClientAPI client) 107 protected override bool CacheFriends(IClientAPI client)
98 { 108 {
99// m_log.DebugFormat("[HGFRIENDS MODULE]: Entered CacheFriends for {0}", client.Name); 109// m_log.DebugFormat("[HGFRIENDS MODULE]: Entered CacheFriends for {0}", client.Name);
@@ -183,91 +193,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
183// m_log.DebugFormat("[HGFRIENDS MODULE]: Exiting GetOnlineFriends for {0}", userID); 193// m_log.DebugFormat("[HGFRIENDS MODULE]: Exiting GetOnlineFriends for {0}", userID);
184 } 194 }
185 195
186 //protected override void GetOnlineFriends(UUID userID, List<string> friendList, /*collector*/ List<UUID> online)
187 //{
188 // // Let's single out the UUIs
189 // List<string> localFriends = new List<string>();
190 // List<string> foreignFriends = new List<string>();
191 // string tmp = string.Empty;
192
193 // foreach (string s in friendList)
194 // {
195 // UUID id;
196 // if (UUID.TryParse(s, out id))
197 // localFriends.Add(s);
198 // else if (Util.ParseUniversalUserIdentifier(s, out id, out tmp, out tmp, out tmp, out tmp))
199 // {
200 // foreignFriends.Add(s);
201 // // add it here too, who knows maybe the foreign friends happens to be on this grid
202 // localFriends.Add(id.ToString());
203 // }
204 // }
205
206 // // OK, see who's present on this grid
207 // List<string> toBeRemoved = new List<string>();
208 // PresenceInfo[] presence = PresenceService.GetAgents(localFriends.ToArray());
209 // foreach (PresenceInfo pi in presence)
210 // {
211 // UUID presenceID;
212 // if (UUID.TryParse(pi.UserID, out presenceID))
213 // {
214 // online.Add(presenceID);
215 // foreach (string s in foreignFriends)
216 // if (s.StartsWith(pi.UserID))
217 // toBeRemoved.Add(s);
218 // }
219 // }
220
221 // foreach (string s in toBeRemoved)
222 // foreignFriends.Remove(s);
223
224 // // OK, let's send this up the stack, and leave a closure here
225 // // collecting online friends in other grids
226 // Util.FireAndForget(delegate { CollectOnlineFriendsElsewhere(userID, foreignFriends); });
227
228 //}
229
230 //private void CollectOnlineFriendsElsewhere(UUID userID, List<string> foreignFriends)
231 //{
232 // // let's divide the friends on a per-domain basis
233 // Dictionary<string, List<string>> friendsPerDomain = new Dictionary<string, List<string>>();
234 // foreach (string friend in foreignFriends)
235 // {
236 // UUID friendID;
237 // if (!UUID.TryParse(friend, out friendID))
238 // {
239 // // it's a foreign friend
240 // string url = string.Empty, tmp = string.Empty;
241 // if (Util.ParseUniversalUserIdentifier(friend, out friendID, out url, out tmp, out tmp, out tmp))
242 // {
243 // if (!friendsPerDomain.ContainsKey(url))
244 // friendsPerDomain[url] = new List<string>();
245 // friendsPerDomain[url].Add(friend);
246 // }
247 // }
248 // }
249
250 // // Now, call those worlds
251
252 // foreach (KeyValuePair<string, List<string>> kvp in friendsPerDomain)
253 // {
254 // List<string> ids = new List<string>();
255 // foreach (string f in kvp.Value)
256 // ids.Add(f);
257 // UserAgentServiceConnector uConn = new UserAgentServiceConnector(kvp.Key);
258 // List<UUID> online = uConn.GetOnlineFriends(userID, ids);
259 // // Finally send the notifications to the user
260 // // this whole process may take a while, so let's check at every
261 // // iteration that the user is still here
262 // IClientAPI client = LocateClientObject(userID);
263 // if (client != null)
264 // client.SendAgentOnline(online.ToArray());
265 // else
266 // break;
267 // }
268
269 //}
270
271 protected override void StatusNotify(List<FriendInfo> friendList, UUID userID, bool online) 196 protected override void StatusNotify(List<FriendInfo> friendList, UUID userID, bool online)
272 { 197 {
273// m_log.DebugFormat("[HGFRIENDS MODULE]: Entering StatusNotify for {0}", userID); 198// m_log.DebugFormat("[HGFRIENDS MODULE]: Entering StatusNotify for {0}", userID);
@@ -335,12 +260,25 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
335 return true; 260 return true;
336 261
337 // fid is not a UUID... 262 // fid is not a UUID...
338 string url = string.Empty, tmp = string.Empty; 263 string url = string.Empty, tmp = string.Empty, f = string.Empty, l = string.Empty;
339 if (Util.ParseUniversalUserIdentifier(fid, out agentID, out url, out first, out last, out tmp)) 264 m_log.DebugFormat("[YYY]: FID {0}", fid);
265 if (Util.ParseUniversalUserIdentifier(fid, out agentID, out url, out f, out l, out tmp))
340 { 266 {
341 IUserManagement userMan = m_Scenes[0].RequestModuleInterface<IUserManagement>(); 267 m_log.DebugFormat("[YYY]: Adding user {0} {1} {2}", f, l, url);
342 userMan.AddUser(agentID, first, last, url); 268 m_uMan.AddUser(agentID, f, l, url);
343 269
270 string name = m_uMan.GetUserName(agentID);
271 string[] parts = name.Trim().Split(new char[] {' '});
272 if (parts.Length == 2)
273 {
274 first = parts[0];
275 last = parts[1];
276 }
277 else
278 {
279 first = f;
280 last = l;
281 }
344 return true; 282 return true;
345 } 283 }
346 return false; 284 return false;
@@ -348,13 +286,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
348 286
349 protected override string GetFriendshipRequesterName(UUID agentID) 287 protected override string GetFriendshipRequesterName(UUID agentID)
350 { 288 {
351 // For the time being we assume that HG friendship requests can only happen 289 return m_uMan.GetUserName(agentID);
352 // when avies are on the same region.
353 IClientAPI client = LocateClientObject(agentID);
354 if (client != null)
355 return client.FirstName + " " + client.LastName;
356 else
357 return base.GetFriendshipRequesterName(agentID);
358 } 290 }
359 291
360 protected override string FriendshipMessage(string friendID) 292 protected override string FriendshipMessage(string friendID)
@@ -392,10 +324,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
392 AgentCircuitData agentClientCircuit = ((Scene)(client.Scene)).AuthenticateHandler.GetAgentCircuitData(client.CircuitCode); 324 AgentCircuitData agentClientCircuit = ((Scene)(client.Scene)).AuthenticateHandler.GetAgentCircuitData(client.CircuitCode);
393 if (agentClientCircuit != null) 325 if (agentClientCircuit != null)
394 { 326 {
395 string agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit); 327 //[XXX] string agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit);
396 328
397 finfos = FriendsService.GetFriends(agentUUI); 329 finfos = FriendsService.GetFriends(client.AgentId.ToString());
398 m_log.DebugFormat("[HGFRIENDS MODULE]: Fetched {0} local friends for visitor {1}", finfos.Length, agentUUI); 330 m_log.DebugFormat("[HGFRIENDS MODULE]: Fetched {0} local friends for visitor {1}", finfos.Length, client.AgentId.ToString());
399 } 331 }
400 332
401// m_log.DebugFormat("[HGFRIENDS MODULE]: Exiting GetFriendsFromService for {0}", client.Name); 333// m_log.DebugFormat("[HGFRIENDS MODULE]: Exiting GetFriendsFromService for {0}", client.Name);
@@ -454,16 +386,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
454 friendIsLocal = UserManagementModule.IsLocalGridUser(friendID); 386 friendIsLocal = UserManagementModule.IsLocalGridUser(friendID);
455 } 387 }
456 388
457 // Are they both local users? 389 // Is the requester a local user?
458 if (agentIsLocal && friendIsLocal) 390 if (agentIsLocal)
459 { 391 {
460 // local grid users 392 // local grid users
461 m_log.DebugFormat("[HGFRIENDS MODULE]: Users are both local"); 393 m_log.DebugFormat("[HGFRIENDS MODULE]: Friendship requester is local. Storing backwards.");
394
462 base.StoreBackwards(friendID, agentID); 395 base.StoreBackwards(friendID, agentID);
463 return; 396 return;
464 } 397 }
465 398
466 // no provision for this temporary friendship state 399 // no provision for this temporary friendship state when user is not local
467 //FriendsService.StoreFriend(friendID.ToString(), agentID.ToString(), 0); 400 //FriendsService.StoreFriend(friendID.ToString(), agentID.ToString(), 0);
468 } 401 }
469 402
@@ -501,12 +434,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
501 agentClientCircuit = ((Scene)(agentClient.Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.CircuitCode); 434 agentClientCircuit = ((Scene)(agentClient.Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.CircuitCode);
502 agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit); 435 agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit);
503 agentFriendService = agentClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); 436 agentFriendService = agentClientCircuit.ServiceURLs["FriendsServerURI"].ToString();
437 RecacheFriends(agentClient);
504 } 438 }
505 if (friendClient != null) 439 if (friendClient != null)
506 { 440 {
507 friendClientCircuit = ((Scene)(friendClient.Scene)).AuthenticateHandler.GetAgentCircuitData(friendClient.CircuitCode); 441 friendClientCircuit = ((Scene)(friendClient.Scene)).AuthenticateHandler.GetAgentCircuitData(friendClient.CircuitCode);
508 friendUUI = Util.ProduceUserUniversalIdentifier(friendClientCircuit); 442 friendUUI = Util.ProduceUserUniversalIdentifier(friendClientCircuit);
509 friendFriendService = friendClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); 443 friendFriendService = friendClientCircuit.ServiceURLs["FriendsServerURI"].ToString();
444 RecacheFriends(friendClient);
510 } 445 }
511 446
512 m_log.DebugFormat("[HGFRIENDS MODULE] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}", 447 m_log.DebugFormat("[HGFRIENDS MODULE] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}",
@@ -515,14 +450,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
515 // Generate a random 8-character hex number that will sign this friendship 450 // Generate a random 8-character hex number that will sign this friendship
516 string secret = UUID.Random().ToString().Substring(0, 8); 451 string secret = UUID.Random().ToString().Substring(0, 8);
517 452
453 string theFriendUUID = friendUUI + ";" + secret;
454 string agentUUID = agentUUI + ";" + secret;
455
518 if (agentIsLocal) // agent is local, 'friend' is foreigner 456 if (agentIsLocal) // agent is local, 'friend' is foreigner
519 { 457 {
520 // This may happen when the agent returned home, in which case the friend is not there 458 // This may happen when the agent returned home, in which case the friend is not there
521 // We need to look for its information in the friends list itself 459 // We need to look for its information in the friends list itself
460 FriendInfo[] finfos = null;
522 bool confirming = false; 461 bool confirming = false;
523 if (friendUUI == string.Empty) 462 if (friendUUI == string.Empty)
524 { 463 {
525 FriendInfo[] finfos = GetFriends(agentID); 464 finfos = GetFriends(agentID);
526 foreach (FriendInfo finfo in finfos) 465 foreach (FriendInfo finfo in finfos)
527 { 466 {
528 if (finfo.TheirFlags == -1) 467 if (finfo.TheirFlags == -1)
@@ -530,29 +469,57 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
530 if (finfo.Friend.StartsWith(friendID.ToString())) 469 if (finfo.Friend.StartsWith(friendID.ToString()))
531 { 470 {
532 friendUUI = finfo.Friend; 471 friendUUI = finfo.Friend;
472 theFriendUUID = friendUUI;
473 UUID utmp = UUID.Zero; String url = String.Empty; String first = String.Empty, last = String.Empty, tmp = String.Empty;
474 // If it's confirming the friendship, we already have the full UUI with the secret
475 if (Util.ParseUniversalUserIdentifier(theFriendUUID, out utmp, out url, out first, out last, out secret))
476 {
477 agentUUID = agentUUI + ";" + secret;
478 m_uMan.AddUser(utmp, first, last, url);
479 }
533 confirming = true; 480 confirming = true;
481 break;
534 } 482 }
535 } 483 }
536 } 484 }
537 } 485 if (!confirming)
486 {
487 friendUUI = m_uMan.GetUserUUI(friendID);
488 theFriendUUID = friendUUI + ";" + secret;
489 }
490
491 friendFriendService = m_uMan.GetUserServerURL(friendID, "FriendsServerURI");
538 492
539 // If it's confirming the friendship, we already have the full friendUUI with the secret 493 // m_log.DebugFormat("[HGFRIENDS MODULE] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}",
540 string theFriendUUID = confirming ? friendUUI : friendUUI + ";" + secret; 494 // agentUUI, friendUUI, agentFriendService, friendFriendService);
495
496 }
497
498 // Delete any previous friendship relations
499 DeletePreviousRelations(agentID, friendID);
541 500
542 // store in the local friends service a reference to the foreign friend 501 // store in the local friends service a reference to the foreign friend
543 FriendsService.StoreFriend(agentID.ToString(), theFriendUUID, 1); 502 FriendsService.StoreFriend(agentID.ToString(), theFriendUUID, 1);
544 // and also the converse 503 // and also the converse
545 FriendsService.StoreFriend(theFriendUUID, agentID.ToString(), 1); 504 FriendsService.StoreFriend(theFriendUUID, agentID.ToString(), 1);
546 505
547 if (!confirming && friendClientCircuit != null) 506 //if (!confirming)
548 { 507 //{
549 // store in the foreign friends service a reference to the local agent 508 // store in the foreign friends service a reference to the local agent
550 HGFriendsServicesConnector friendsConn = new HGFriendsServicesConnector(friendFriendService, friendClientCircuit.SessionID, friendClientCircuit.ServiceSessionID); 509 HGFriendsServicesConnector friendsConn = null;
551 friendsConn.NewFriendship(friendID, agentUUI + ";" + secret); 510 if (friendClientCircuit != null) // the friend is here, validate session
552 } 511 friendsConn = new HGFriendsServicesConnector(friendFriendService, friendClientCircuit.SessionID, friendClientCircuit.ServiceSessionID);
512 else // the friend is not here, he initiated the request in his home world
513 friendsConn = new HGFriendsServicesConnector(friendFriendService);
514
515 friendsConn.NewFriendship(friendID, agentUUID);
516 //}
553 } 517 }
554 else if (friendIsLocal) // 'friend' is local, agent is foreigner 518 else if (friendIsLocal) // 'friend' is local, agent is foreigner
555 { 519 {
520 // Delete any previous friendship relations
521 DeletePreviousRelations(agentID, friendID);
522
556 // store in the local friends service a reference to the foreign agent 523 // store in the local friends service a reference to the foreign agent
557 FriendsService.StoreFriend(friendID.ToString(), agentUUI + ";" + secret, 1); 524 FriendsService.StoreFriend(friendID.ToString(), agentUUI + ";" + secret, 1);
558 // and also the converse 525 // and also the converse
@@ -582,6 +549,36 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
582 // my brain hurts now 549 // my brain hurts now
583 } 550 }
584 551
552 private void DeletePreviousRelations(UUID a1, UUID a2)
553 {
554 // Delete any previous friendship relations
555 FriendInfo[] finfos = null;
556 FriendInfo f = null;
557 finfos = GetFriends(a1);
558 if (finfos != null)
559 {
560 f = GetFriend(finfos, a2);
561 if (f != null)
562 {
563 FriendsService.Delete(a1, f.Friend);
564 // and also the converse
565 FriendsService.Delete(f.Friend, a1.ToString());
566 }
567 }
568
569 finfos = GetFriends(a2);
570 if (finfos != null)
571 {
572 f = GetFriend(finfos, a1);
573 if (f != null)
574 {
575 FriendsService.Delete(a2, f.Friend);
576 // and also the converse
577 FriendsService.Delete(f.Friend, a2.ToString());
578 }
579 }
580 }
581
585 protected override bool DeleteFriendship(UUID agentID, UUID exfriendID) 582 protected override bool DeleteFriendship(UUID agentID, UUID exfriendID)
586 { 583 {
587 Boolean agentIsLocal = true; 584 Boolean agentIsLocal = true;
@@ -684,5 +681,74 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
684 friendConn.DeleteFriendship(foreignUser, localUser, secret); 681 friendConn.DeleteFriendship(foreignUser, localUser, secret);
685 } 682 }
686 } 683 }
684
685 protected override bool ForwardFriendshipOffer(UUID agentID, UUID friendID, GridInstantMessage im)
686 {
687 if (base.ForwardFriendshipOffer(agentID, friendID, im))
688 return true;
689
690 // OK, that didn't work, so let's try to find this user somewhere
691 if (!m_uMan.IsLocalGridUser(friendID))
692 {
693 string friendsURL = m_uMan.GetUserServerURL(friendID, "FriendsServerURI");
694 if (friendsURL != string.Empty)
695 {
696 m_log.DebugFormat("[HGFRIENDS MODULE]: Forwading friendship from {0} to {1} @ {2}", agentID, friendID, friendsURL);
697 GridRegion region = new GridRegion();
698 region.ServerURI = friendsURL;
699
700 string name = im.fromAgentName;
701 if (m_uMan.IsLocalGridUser(agentID))
702 {
703 IClientAPI agentClient = LocateClientObject(agentID);
704 AgentCircuitData agentClientCircuit = ((Scene)(agentClient.Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.CircuitCode);
705 string agentHomeService = string.Empty;
706 try
707 {
708 agentHomeService = agentClientCircuit.ServiceURLs["HomeURI"].ToString();
709 string lastname = "@" + new Uri(agentHomeService).Authority;
710 string firstname = im.fromAgentName.Replace(" ", ".");
711 name = firstname + lastname;
712 }
713 catch (KeyNotFoundException)
714 {
715 m_log.DebugFormat("[HGFRIENDS MODULE]: Key HomeURI not found for user {0}", agentID);
716 return false;
717 }
718 catch (NullReferenceException)
719 {
720 m_log.DebugFormat("[HGFRIENDS MODULE]: Null HomeUri for local user {0}", agentID);
721 return false;
722 }
723 catch (UriFormatException)
724 {
725 m_log.DebugFormat("[HGFRIENDS MODULE]: Malformed HomeUri {0} for local user {1}", agentHomeService, agentID);
726 return false;
727 }
728 }
729
730 m_HGFriendsConnector.FriendshipOffered(region, agentID, friendID, im.message, name);
731
732 return true;
733 }
734 }
735
736 return false;
737 }
738
739 public override bool LocalFriendshipOffered(UUID toID, GridInstantMessage im)
740 {
741 if (base.LocalFriendshipOffered(toID, im))
742 {
743 if (im.fromAgentName.Contains("@"))
744 {
745 string[] parts = im.fromAgentName.Split(new char[] { '@' });
746 if (parts.Length == 2)
747 m_uMan.AddUser(new UUID(im.fromAgentID), parts[0], "http://" + parts[1]);
748 }
749 return true;
750 }
751 return false;
752 }
687 } 753 }
688} \ No newline at end of file 754} \ No newline at end of file