29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Reflection;
32 using System.Threading;
38 using OpenSim.Framework;
39 using OpenSim.Region.Framework.Interfaces;
40 using OpenSim.Region.Framework.Scenes;
41 using OpenSim.Services.Interfaces;
42 using OpenSim.Services.Connectors.Hypergrid;
49 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"HGFriendsModule")]
52 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54 private int m_levelHGFriends = 0;
70 #region ISharedRegionModule
71 public override string Name
73 get {
return "HGFriendsModule"; }
81 base.AddRegion(scene);
89 if (m_StatusNotifier == null)
95 base.InitModule(config);
98 IConfig friendsConfig = config.Configs[
"HGFriendsModule"];
99 if (friendsConfig != null)
101 m_levelHGFriends = friendsConfig.GetInt(
"LevelHGFriends", 0);
110 #region IFriendsSimConnector
121 return LocalStatusNotification(friendID, userID, online);
128 if ((InstantMessageDialog)im.
dialog == InstantMessageDialog.FriendshipOffered)
136 if (!UserManagementModule.IsLocalGridUser(friendID))
139 ((
Scene)client.
Scene).TryGetScenePresence(principalID, out avatar);
146 client.SendAgentAlertMessage(
"Unable to send friendship invitation to foreigner. Insufficient permissions.",
false);
152 base.OnInstantMessage(client, im);
160 base.OnApproveFriendRequest(client, friendID, callingCardFolders);
167 if (base.CacheFriends(client))
169 UUID agentID = client.AgentId;
171 if (m_Friends[agentID].Refcount == 1)
175 foreach (
FriendInfo finfo
in m_Friends[agentID].Friends)
182 string url = string.Empty, first = string.Empty, last = string.Empty, tmp = string.Empty;
183 if (Util.ParseUniversalUserIdentifier(finfo.
Friend, out
id, out url, out first, out last, out tmp))
186 m_log.DebugFormat(
"[HGFRIENDS MODULE]: caching {0}", finfo.Friend);
187 uMan.AddUser(id, url +
";" + first +
" " + last);
206 if (base.SendFriendsOnlineIfNeeded(client))
209 if (aCircuit != null && (aCircuit.
teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0)
211 UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID, client.AgentId);
217 client.SendChangeUserRights(
new UUID(f.
Friend), client.AgentId, f.TheirFlags);
227 protected override void GetOnlineFriends(UUID userID, List<string> friendList, List<UUID> online)
231 List<string> fList =
new List<string>();
232 foreach (
string s
in friendList)
236 "[HGFRIENDS MODULE]: Ignoring friend {0} ({1} chars) for {2} since identifier too short",
237 s, s.Length, userID);
239 fList.Add(s.Substring(0, 36));
244 PresenceInfo[] presence = PresenceService.GetAgents(fList.ToArray());
249 online.Add(presenceID);
255 protected override void StatusNotify(List<FriendInfo> friendList, UUID userID,
bool online)
260 Dictionary<string, List<FriendInfo>> friendsPerDomain =
new Dictionary<string, List<FriendInfo>>();
264 if (
UUID.TryParse(
friend.Friend, out friendID))
266 if (!friendsPerDomain.ContainsKey(
"local"))
267 friendsPerDomain[
"local"] =
new List<FriendInfo>();
268 friendsPerDomain[
"local"].Add(
friend);
273 string url = string.Empty, tmp = string.Empty;
274 if (Util.ParseUniversalUserIdentifier(
friend.Friend, out friendID, out url, out tmp, out tmp, out tmp))
277 if (LocalStatusNotification(userID, friendID, online))
280 if (!friendsPerDomain.ContainsKey(url))
281 friendsPerDomain[url] =
new List<FriendInfo>();
282 friendsPerDomain[url].Add(
friend);
289 if (friendsPerDomain.ContainsKey(
"local"))
290 base.StatusNotify(friendsPerDomain[
"local"], userID, online);
292 m_StatusNotifier.Notify(userID, friendsPerDomain, online);
297 protected override bool GetAgentInfo(UUID scopeID,
string fid, out UUID agentID, out
string first, out
string last)
299 first =
"Unknown"; last =
"UserHGGAI";
300 if (base.GetAgentInfo(scopeID, fid, out agentID, out first, out last))
304 string url = string.Empty, tmp = string.Empty, f = string.Empty, l = string.Empty;
305 if (Util.ParseUniversalUserIdentifier(fid, out agentID, out url, out f, out l, out tmp))
307 if (!agentID.Equals(
UUID.Zero))
309 m_uMan.AddUser(agentID, f, l, url);
311 string name = m_uMan.GetUserName(agentID);
312 string[] parts = name.Trim().Split(
new char[] {
' ' });
313 if (parts.Length == 2)
331 return m_uMan.GetUserName(agentID);
337 if (
UUID.TryParse(friendID, out
id))
338 return base.FriendshipMessage(friendID);
340 return "Please confirm this friendship you made while you were away.";
347 if (fi.
Friend.StartsWith(friendID.ToString()))
357 if (UserManagementModule != null)
358 agentIsLocal = UserManagementModule.IsLocalGridUser(client.AgentId);
361 return base.GetFriendsFromService(client);
366 if (agentClientCircuit != null)
369 finfos = FriendsService.GetFriends(client.AgentId.ToString());
370 m_log.DebugFormat(
"[HGFRIENDS MODULE]: Fetched {0} local friends for visitor {1}", finfos.Length, client.AgentId.ToString());
378 protected override bool StoreRights(UUID agentID, UUID friendID,
int rights)
382 if (UserManagementModule != null)
384 agentIsLocal = UserManagementModule.IsLocalGridUser(agentID);
385 friendIsLocal = UserManagementModule.IsLocalGridUser(friendID);
389 if (agentIsLocal && friendIsLocal)
392 return base.StoreRights(agentID, friendID, rights);
397 FriendInfo[] finfos = GetFriendsFromCache(agentID);
398 FriendInfo finfo = GetFriend(finfos, friendID);
401 FriendsService.StoreFriend(agentID.ToString(), finfo.
Friend, rights);
408 string agentUUI = GetUUI(friendID, agentID);
409 if (agentUUI !=
string.Empty)
411 FriendsService.StoreFriend(agentUUI, friendID.ToString(), rights);
421 bool agentIsLocal =
true;
424 if (UserManagementModule != null)
426 agentIsLocal = UserManagementModule.IsLocalGridUser(agentID);
434 m_log.DebugFormat(
"[HGFRIENDS MODULE]: Friendship requester is local. Storing backwards.");
436 base.StoreBackwards(friendID, agentID);
448 if (UserManagementModule != null)
450 agentIsLocal = UserManagementModule.IsLocalGridUser(agentID);
451 friendIsLocal = UserManagementModule.IsLocalGridUser(friendID);
455 if (agentIsLocal && friendIsLocal)
458 m_log.DebugFormat(
"[HGFRIENDS MODULE]: Users are both local");
459 base.StoreFriendships(agentID, friendID);
464 IClientAPI agentClient = LocateClientObject(agentID);
465 IClientAPI friendClient = LocateClientObject(friendID);
468 string agentUUI = string.Empty;
469 string friendUUI = string.Empty;
470 string agentFriendService = string.Empty;
471 string friendFriendService = string.Empty;
473 if (agentClient != null)
475 agentClientCircuit = ((
Scene)(agentClient.
Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.
CircuitCode);
476 agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit);
477 agentFriendService = agentClientCircuit.ServiceURLs[
"FriendsServerURI"].ToString();
478 RecacheFriends(agentClient);
480 if (friendClient != null)
482 friendClientCircuit = ((
Scene)(friendClient.
Scene)).AuthenticateHandler.GetAgentCircuitData(friendClient.
CircuitCode);
483 friendUUI = Util.ProduceUserUniversalIdentifier(friendClientCircuit);
484 friendFriendService = friendClientCircuit.ServiceURLs[
"FriendsServerURI"].ToString();
485 RecacheFriends(friendClient);
488 m_log.DebugFormat(
"[HGFRIENDS MODULE] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}",
489 agentUUI, friendUUI, agentFriendService, friendFriendService);
492 string secret = UUID.Random().ToString().Substring(0, 8);
494 string theFriendUUID = friendUUI +
";" + secret;
495 string agentUUID = agentUUI +
";" + secret;
502 bool confirming =
false;
503 if (friendUUI ==
string.Empty)
505 finfos = GetFriendsFromCache(agentID);
510 if (finfo.
Friend.StartsWith(friendID.ToString()))
512 friendUUI = finfo.Friend;
513 theFriendUUID = friendUUI;
514 UUID utmp = UUID.Zero;
515 string url = String.Empty;
516 string first = String.Empty;
517 string last = String.Empty;
520 if (Util.ParseUniversalUserIdentifier(theFriendUUID, out utmp, out url, out first, out last, out secret))
522 agentUUID = agentUUI +
";" + secret;
523 m_uMan.AddUser(utmp, first, last, url);
532 friendUUI = m_uMan.GetUserUUI(friendID);
533 theFriendUUID = friendUUI +
";" + secret;
536 friendFriendService = m_uMan.GetUserServerURL(friendID,
"FriendsServerURI");
544 DeletePreviousRelations(agentID, friendID);
547 FriendsService.StoreFriend(agentID.ToString(), theFriendUUID, 1);
549 FriendsService.StoreFriend(theFriendUUID, agentID.ToString(), 1);
555 if (friendClientCircuit != null)
560 friendsConn.NewFriendship(friendID, agentUUID);
563 else if (friendIsLocal)
566 DeletePreviousRelations(agentID, friendID);
569 FriendsService.StoreFriend(friendID.ToString(), agentUUI +
";" + secret, 1);
571 FriendsService.StoreFriend(agentUUI +
";" + secret, friendID.ToString(), 1);
573 if (agentClientCircuit != null)
577 friendsConn.NewFriendship(agentID, friendUUI +
";" + secret);
583 if (agentClientCircuit != null)
586 friendsConn.NewFriendship(agentID, friendUUI +
";" + secret);
588 if (friendClientCircuit != null)
591 friendsConn.NewFriendship(friendID, agentUUI +
";" + secret);
597 private void DeletePreviousRelations(UUID a1, UUID a2)
602 finfos = GetFriendsFromCache(a1);
605 f = GetFriend(finfos, a2);
608 FriendsService.Delete(a1, f.Friend);
610 FriendsService.Delete(f.Friend, a1.ToString());
614 finfos = GetFriendsFromCache(a2);
617 f = GetFriend(finfos, a1);
620 FriendsService.Delete(a2, f.Friend);
622 FriendsService.Delete(f.Friend, a2.ToString());
631 if (UserManagementModule != null)
633 agentIsLocal = UserManagementModule.IsLocalGridUser(agentID);
634 friendIsLocal = UserManagementModule.IsLocalGridUser(exfriendID);
638 if (agentIsLocal && friendIsLocal)
641 return base.DeleteFriendship(agentID, exfriendID);
645 string agentUUI = string.Empty;
646 string friendUUI = string.Empty;
651 FriendInfo[] finfos = GetFriendsFromCache(agentID);
652 FriendInfo finfo = GetFriend(finfos, exfriendID);
655 friendUUI = finfo.Friend;
658 FriendsService.Delete(agentID, friendUUI);
660 FriendsService.Delete(friendUUI, agentID.ToString());
664 delegate {
Delete(exfriendID, agentID, friendUUI); }, null,
"HGFriendsModule.DeleteFriendshipForeignFriend");
666 m_log.DebugFormat(
"[HGFRIENDS MODULE]: {0} terminated {1}", agentID, friendUUI);
670 else if (friendIsLocal)
672 agentUUI = GetUUI(exfriendID, agentID);
674 if (agentUUI !=
string.Empty)
677 FriendsService.Delete(exfriendID, agentUUI);
679 FriendsService.Delete(agentUUI, exfriendID.ToString());
683 delegate {
Delete(agentID, exfriendID, agentUUI); }, null,
"HGFriendsModule.DeleteFriendshipLocalFriend");
685 m_log.DebugFormat(
"[HGFRIENDS MODULE]: {0} terminated {1}", agentUUI, exfriendID);
694 private string GetUUI(UUID localUser, UUID foreignUser)
697 FriendInfo[] finfos = GetFriendsFromCache(localUser);
698 if (finfos != EMPTY_FRIENDS)
700 FriendInfo finfo = GetFriend(finfos, foreignUser);
708 finfos = FriendsService.GetFriends(localUser);
711 if (finfo.
Friend.StartsWith(foreignUser.ToString()))
720 private void Delete(UUID foreignUser, UUID localUser,
string uui)
723 string url = string.Empty, secret = string.Empty, tmp = string.Empty;
724 if (Util.ParseUniversalUserIdentifier(uui, out
id, out url, out tmp, out tmp, out secret))
726 m_log.DebugFormat(
"[HGFRIENDS MODULE]: Deleting friendship from {0}", url);
728 friendConn.DeleteFriendship(foreignUser, localUser, secret);
734 if (base.ForwardFriendshipOffer(agentID, friendID, im))
738 if (!m_uMan.IsLocalGridUser(friendID))
740 string friendsURL = m_uMan.GetUserServerURL(friendID,
"FriendsServerURI");
741 if (friendsURL !=
string.Empty)
743 m_log.DebugFormat(
"[HGFRIENDS MODULE]: Forwading friendship from {0} to {1} @ {2}", agentID, friendID, friendsURL);
745 region.ServerURI = friendsURL;
747 string name = im.fromAgentName;
748 if (m_uMan.IsLocalGridUser(agentID))
750 IClientAPI agentClient = LocateClientObject(agentID);
752 string agentHomeService = string.Empty;
755 agentHomeService = agentClientCircuit.ServiceURLs[
"HomeURI"].ToString();
756 string lastname =
"@" +
new Uri(agentHomeService).Authority;
757 string firstname = im.fromAgentName.Replace(
" ",
".");
758 name = firstname + lastname;
760 catch (KeyNotFoundException)
762 m_log.DebugFormat(
"[HGFRIENDS MODULE]: Key HomeURI not found for user {0}", agentID);
765 catch (NullReferenceException)
767 m_log.DebugFormat(
"[HGFRIENDS MODULE]: Null HomeUri for local user {0}", agentID);
770 catch (UriFormatException)
772 m_log.DebugFormat(
"[HGFRIENDS MODULE]: Malformed HomeUri {0} for local user {1}", agentHomeService, agentID);
777 m_HGFriendsConnector.FriendshipOffered(region, agentID, friendID, im.message, name);
788 if (base.LocalFriendshipOffered(toID, im))
792 string[] parts = im.fromAgentName.Split(
new char[] {
'@' });
793 if (parts.Length == 2)
795 string[] fl = parts[0].Trim().Split(
new char[] {
'.' });
797 m_uMan.AddUser(
new UUID(im.
fromAgentID), fl[0], fl[1],
"http://" + parts[1]);
799 m_uMan.AddUser(
new UUID(im.
fromAgentID), fl[0],
"",
"http://" + parts[1]);
string ServiceSessionID
Hypergrid service token; generated by the user domain, consumed by the receiving grid. There is one such unique token for each grid visited.
override void StoreFriendships(UUID agentID, UUID friendID)
override void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
override bool ForwardFriendshipOffer(UUID agentID, UUID friendID, GridInstantMessage im)
override void InitModule(IConfigSource config)
override void OnInstantMessage(IClientAPI client, GridInstantMessage im)
OpenSim.Services.Interfaces.FriendInfo FriendInfo
override void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
OpenSim.Services.Interfaces.GridRegion GridRegion
override string FriendshipMessage(string friendID)
override bool StoreRights(UUID agentID, UUID friendID, int rights)
UUID SessionID
Non secure Session ID
bool StatusNotify(UUID friendID, UUID userID, bool online)
Notify the user that the friend's status changed
override bool GetAgentInfo(UUID scopeID, string fid, out UUID agentID, out string first, out string last)
HGStatusNotifier m_StatusNotifier
override bool CacheFriends(IClientAPI client)
Cache the friends list or increment the refcount for the existing friends list.
override void OnApproveFriendRequest(IClientAPI client, UUID friendID, List< UUID > callingCardFolders)
override FriendInfo[] GetFriendsFromService(IClientAPI client)
override void GetOnlineFriends(UUID userID, List< string > friendList, List< UUID > online)
Circuit data for an agent. Connection information shared between regions that accept UDP connections ...
override bool SendFriendsOnlineIfNeeded(IClientAPI client)
override FriendInfo GetFriend(FriendInfo[] friends, UUID friendID)
override string GetFriendshipRequesterName(UUID agentID)
override bool DeleteFriendship(UUID agentID, UUID exfriendID)
OpenSim.Services.Interfaces.PresenceInfo PresenceInfo
override void StatusNotify(List< FriendInfo > friendList, UUID userID, bool online)
int TheirFlags
The permissions that the friend has granted to this user.
uint teleportFlags
How this agent got here
This maintains the relationship between a UUID and a user name.
override void StoreBackwards(UUID friendID, UUID agentID)
override bool LocalFriendshipOffered(UUID toID, GridInstantMessage im)