private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List <UUID> callingCardFolders) { m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", agentID, friendID); FriendsService.StoreFriend(agentID, friendID.ToString(), 1); FriendsService.StoreFriend(friendID, agentID.ToString(), 1); // Update the local cache UpdateFriendsCache(agentID); // // Notify the friend // // Try Local if (LocalFriendshipApproved(agentID, client.Name, friendID)) { client.SendAgentOnline(new UUID[] { friendID }); return; } // The friend is not here PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); if (friendSessions != null && friendSessions.Length > 0) { PresenceInfo friendSession = friendSessions[0]; if (friendSession != null) { GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); m_FriendsSimConnector.FriendshipApproved(region, agentID, client.Name, friendID); client.SendAgentOnline(new UUID[] { friendID }); } } }
public void AddFriendship(IClientAPI client, UUID friendID) { StoreFriendships(client.AgentId, friendID); // Update the local cache RecacheFriends(client); // // Notify the friend // // Try Local if (LocalFriendshipApproved(client.AgentId, client.Name, friendID)) { client.SendAgentOnline(new UUID[] { friendID }); return; } // The friend is not here PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); if (friendSessions != null && friendSessions.Length > 0) { PresenceInfo friendSession = friendSessions[0]; if (friendSession != null) { GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); m_FriendsSimConnector.FriendshipApproved(region, client.AgentId, client.Name, friendID); client.SendAgentOnline(new UUID[] { friendID }); } } }
public void SendFriendsStatusMessage(UUID FriendToInformID, UUID userID, bool online) { // Try local IClientAPI friendClient = LocateClientObject(FriendToInformID); if (friendClient != null) { //MainConsole.Instance.DebugFormat("[FRIENDS]: Local Status Notify {0} that user {1} is {2}", friendID, userID, online); // the friend in this sim as root agent if (online) { friendClient.SendAgentOnline(new[] { userID }); } else { friendClient.SendAgentOffline(new[] { userID }); } // we're done return; } lock (m_friendsToInformOfStatusChanges) { if (!m_friendsToInformOfStatusChanges.ContainsKey(FriendToInformID)) { m_friendsToInformOfStatusChanges.Add(FriendToInformID, new List <UUID>()); } m_friendsToInformOfStatusChanges[FriendToInformID].Add(userID); } // Friend is not online. Ignore. }
public bool LocalGrantRights(UUID userID, UUID friendID, int oldRights, int newRights) { IClientAPI friendClient = LocateClientObject(friendID); if (friendClient != null) { int changedRights = newRights ^ oldRights; bool onlineBitChanged = (changedRights & (int)FriendRights.CanSeeOnline) != 0; if (onlineBitChanged) { if ((newRights & (int)FriendRights.CanSeeOnline) == 1) { friendClient.SendAgentOnline(new UUID[] { userID }); } else { friendClient.SendAgentOffline(new UUID[] { userID }); } } if (changedRights != 0) { friendClient.SendChangeUserRights(userID, friendID, newRights); } // Update local cache UpdateLocalCache(userID, friendID, newRights); return(true); } return(false); }
public void SendFriendsStatusMessage(UUID FriendToInformID, UUID[] userIDs, bool online) { // Try local IClientAPI friendClient = LocateClientObject(FriendToInformID); if (friendClient != null) { MainConsole.Instance.InfoFormat("[FriendsModule]: Local Status Notify {0} that {1} users are {2}", FriendToInformID, userIDs.Length, online); // the friend in this sim as root agent if (online) { friendClient.SendAgentOnline(userIDs); } else { friendClient.SendAgentOffline(userIDs); } // we're done return; } else { MainConsole.Instance.ErrorFormat("[FriendsModule]: Could not send status update to non-existant client {0}.", FriendToInformID); } }
public bool LocalGrantRights(UUID userID, UUID friendID, int userFlags, int rights) { IClientAPI friendClient = LocateClientObject(friendID); if (friendClient != null) { bool onlineBitChanged = ((rights ^ userFlags) & (int)FriendRights.CanSeeOnline) != 0; if (onlineBitChanged) { if ((rights & (int)FriendRights.CanSeeOnline) == 1) { friendClient.SendAgentOnline(new UUID[] { userID }); } else { friendClient.SendAgentOffline(new UUID[] { userID }); } } else { bool canEditObjectsChanged = ((rights ^ userFlags) & (int)FriendRights.CanModifyObjects) != 0; if (canEditObjectsChanged) { friendClient.SendChangeUserRights(userID, friendID, rights); } } // Update local cache UpdateLocalCache(userID, friendID, rights); return(true); } return(false); }
public virtual bool SendFriendsOnlineIfNeeded(IClientAPI client) { UUID agentID = client.AgentId; // Check if the online friends list is needed lock (m_NeedsListOfOnlineFriends) { if (!m_NeedsListOfOnlineFriends.Remove(agentID)) { return(false); } } // Send the friends online List <UUID> online = GetOnlineFriends(agentID); if (online.Count > 0) { client.SendAgentOnline(online.ToArray()); } // Send outstanding friendship offers List <string> outstanding = new List <string>(); FriendInfo[] friends = GetFriendsFromCache(agentID); foreach (FriendInfo fi in friends) { if (fi.TheirFlags == -1) { outstanding.Add(fi.Friend); } } GridInstantMessage im = new GridInstantMessage(client.Scene, UUID.Zero, String.Empty, agentID, (byte)InstantMessageDialog.FriendshipOffered, "Will you be my friend?", true, Vector3.Zero); foreach (string fid in outstanding) { UUID fromAgentID; string firstname = "Unknown", lastname = "UserFMSFOIN"; if (!GetAgentInfo(client.Scene.RegionInfo.ScopeID, fid, out fromAgentID, out firstname, out lastname)) { m_log.DebugFormat("[FRIENDS MODULE]: skipping malformed friend {0}", fid); continue; } im.offline = 0; im.fromAgentID = fromAgentID.Guid; im.fromAgentName = firstname + " " + lastname; im.imSessionID = im.fromAgentID; im.message = FriendshipMessage(fid); LocalFriendshipOffered(agentID, im); } return(true); }
public bool LocalGrantRights(UUID userID, UUID friendID, int userFlags, int rights) { IClientAPI friendClient = LocateClientObject(friendID); if (friendClient != null) { bool onlineBitChanged = ((rights ^ userFlags) & (int)FriendRights.CanSeeOnline) != 0; if (onlineBitChanged) { if ((rights & (int)FriendRights.CanSeeOnline) == 1) { friendClient.SendAgentOnline(new[] { new UUID(userID) }); } else { friendClient.SendAgentOffline(new[] { new UUID(userID) }); } } else { bool canEditObjectsChanged = ((rights ^ userFlags) & (int)FriendRights.CanModifyObjects) != 0; if (canEditObjectsChanged) { friendClient.SendChangeUserRights(userID, friendID, rights); } } // Update local cache FriendInfo[] friends = GetFriends(friendID); foreach (FriendInfo finfo in friends.Where(finfo => finfo.Friend == userID.ToString())) { finfo.TheirFlags = rights; } friends = GetFriends(userID); foreach (FriendInfo finfo in friends.Where(finfo => finfo.Friend == friendID.ToString())) { finfo.MyFlags = rights; } //Add primFlag updates for all the prims in the sim with the owner, so that the new permissions are set up correctly IScenePresence friendSP = friendClient.Scene.GetScenePresence(friendClient.AgentId); foreach ( ISceneEntity entity in friendClient.Scene.Entities.GetEntities().Where(entity => entity.OwnerID == userID)) { entity.ScheduleGroupUpdateToAvatar(friendSP, PrimUpdateFlags.PrimFlags); } return(true); } return(false); }
public bool LocalFriendshipApproved(UUID userID, string name, IClientAPI us, UUID friendID) { IClientAPI friendClient = LocateClientObject(friendID); if (friendClient != null) { //They are online, send the online message if (us != null) { us.SendAgentOnline(new[] { friendID }); } // the prospective friend in this sim as root agent GridInstantMessage im = new GridInstantMessage() { FromAgentID = userID, FromAgentName = name, ToAgentID = friendID, Dialog = (byte)InstantMessageDialog.FriendshipAccepted, Message = userID.ToString(), Offline = 0, RegionID = us.Scene.RegionInfo.RegionID }; friendClient.SendInstantMessage(im); // Update the local cache UpdateFriendsCache(friendID); // // put a calling card into the inventory of the friend // ICallingCardModule ccmodule = friendClient.Scene.RequestModuleInterface <ICallingCardModule>(); if (ccmodule != null) { UserAccount account = friendClient.Scene.UserAccountService.GetUserAccount(friendClient.AllScopeIDs, userID); UUID folderID = friendClient.Scene.InventoryService.GetFolderForType(friendID, InventoryType.Unknown, AssetType.CallingCard).ID; ccmodule.CreateCallingCard(friendClient, userID, folderID, account.Name); } // we're done return(true); } return(false); }
public bool LocalGrantRights(UUID userID, UUID friendID, int userFlags, int rights) { IClientAPI friendClient = LocateClientObject(friendID); if (friendClient != null) { bool onlineBitChanged = ((rights ^ userFlags) & (int)FriendRights.CanSeeOnline) != 0; if (onlineBitChanged) { if ((rights & (int)FriendRights.CanSeeOnline) == 1) { friendClient.SendAgentOnline(new UUID[] { new UUID(userID) }); } else { friendClient.SendAgentOffline(new UUID[] { new UUID(userID) }); } } else { bool canEditObjectsChanged = ((rights ^ userFlags) & (int)FriendRights.CanModifyObjects) != 0; if (canEditObjectsChanged) { friendClient.SendChangeUserRights(userID, friendID, rights); } } // Update local cache lock (m_Friends) { FriendInfo[] friends = GetFriends(friendID); foreach (FriendInfo finfo in friends) { if (finfo.Friend == userID.ToString()) { finfo.TheirFlags = rights; } } } return(true); } return(false); }
public void Notify(UUID userID, Dictionary <string, List <FriendInfo> > friendsPerDomain, bool online) { foreach (KeyValuePair <string, List <FriendInfo> > kvp in friendsPerDomain) { if (kvp.Key != "local") { // For the others, call the user agent service List <string> ids = new List <string>(); foreach (FriendInfo f in kvp.Value) { ids.Add(f.Friend); } if (ids.Count == 0) { continue; // no one to notify. caller don't do this } m_log.DebugFormat("[HG STATUS NOTIFIER]: Notifying {0} friends in {1}", ids.Count, kvp.Key); // ASSUMPTION: we assume that all users for one home domain // have exactly the same set of service URLs. // If this is ever not true, we need to change this. UUID friendID = UUID.Zero; String tmp = String.Empty; if (Util.ParseUniversalUserIdentifier(ids[0], out friendID, out tmp, out tmp, out tmp, out tmp)) { string friendsServerURI = m_FriendsModule.UserManagementModule.GetUserServerURL(friendID, "FriendsServerURI"); if (friendsServerURI != string.Empty) { HGFriendsServicesConnector fConn = new HGFriendsServicesConnector(friendsServerURI); List <UUID> friendsOnline = fConn.StatusNotification(ids, userID, online); if (online && friendsOnline.Count > 0) { IClientAPI client = m_FriendsModule.LocateClientObject(userID); if (client != null) { client.SendAgentOnline(friendsOnline.ToArray()); } } } } } } }
public void OnRequestOnlineNotification(object sender, string method, List <string> args) { if (!(sender is IClientAPI)) { return; } IClientAPI client = (IClientAPI)sender; MainConsole.Instance.DebugFormat("[PRESENCE MODULE]: OnlineNotification requested by {0}", client.Name); List <UserInfo> status = m_Scene.RequestModuleInterface <IAgentInfoService> ().GetUserInfos(args); if (status == null) { return; } List <UUID> online = new List <UUID> (); List <UUID> offline = new List <UUID> (); foreach (UserInfo pi in status) { UUID uuid = new UUID(pi.UserID); if (pi.IsOnline && !online.Contains(uuid)) { online.Add(uuid); } if (!pi.IsOnline && !offline.Contains(uuid)) { offline.Add(uuid); } } if (online.Count > 0) { client.SendAgentOnline(online.ToArray()); } if (offline.Count > 0) { client.SendAgentOffline(offline.ToArray()); } }
public void OnRequestOnlineNotification(Object sender, string method, List <String> args) { if (!(sender is IClientAPI)) { return; } IClientAPI client = (IClientAPI)sender; m_log.DebugFormat("[PRESENCE MODULE]: OnlineNotification requested by {0}", client.Name); PresenceInfo[] status = PresenceService.GetAgents(args.ToArray()); List <UUID> online = new List <UUID>(); List <UUID> offline = new List <UUID>(); foreach (PresenceInfo pi in status) { UUID uuid = new UUID(pi.UserID); if (!online.Contains(uuid)) { online.Add(uuid); } } foreach (string s in args) { UUID uuid = new UUID(s); if (!online.Contains(uuid) && !offline.Contains(uuid)) { offline.Add(uuid); } } if (online.Count > 0) { client.SendAgentOnline(online.ToArray()); } if (offline.Count > 0) { client.SendAgentOffline(offline.ToArray()); } }
public void SendFriendsStatusMessage(UUID FriendToInformID, UUID userID, bool online) { // Try local IClientAPI friendClient = LocateClientObject(FriendToInformID); if (friendClient != null) { //MainConsole.Instance.DebugFormat("[FRIENDS]: Local Status Notify {0} that user {1} is {2}", friendID, userID, online); // the friend in this sim as root agent if (online) { friendClient.SendAgentOnline(new[] { userID }); } else { friendClient.SendAgentOffline(new[] { userID }); } // we're done return; } }
public bool LocalStatusNotification(UUID userID, UUID friendID, bool online) { IClientAPI friendClient = LocateClientObject(friendID); if (friendClient != null) { //m_log.DebugFormat("[FRIENDS]: Local Status Notify {0} that user {1} is {2}", friendID, userID, online); // the friend in this sim as root agent if (online) { friendClient.SendAgentOnline(new UUID[] { userID }); } else { friendClient.SendAgentOffline(new UUID[] { userID }); } // we're done return(true); } return(false); }
public bool LocalFriendshipApproved(UUID userID, string name, IClientAPI us, UUID friendID) { IClientAPI friendClient = LocateClientObject(friendID); if (friendClient != null) { //They are online, send the online message if (us != null) { us.SendAgentOnline(new UUID[] { friendID }); } // the prospective friend in this sim as root agent GridInstantMessage im = new GridInstantMessage(m_Scenes[0], userID, name, friendID, (byte)OpenMetaverse.InstantMessageDialog.FriendshipAccepted, userID.ToString(), false, Vector3.Zero); friendClient.SendInstantMessage(im); // Update the local cache UpdateFriendsCache(friendID); // // put a calling card into the inventory of the friend // ICallingCardModule ccmodule = friendClient.Scene.RequestModuleInterface <ICallingCardModule>(); if (ccmodule != null) { UserAccount account = ((Scene)friendClient.Scene).UserAccountService.GetUserAccount(UUID.Zero, userID); UUID folderID = ((Scene)friendClient.Scene).InventoryService.GetFolderForType(friendID, AssetType.CallingCard).ID; ccmodule.CreateCallingCard(friendClient, userID, folderID, account.Name); } // we're done return(true); } return(false); }
public void SendFriendsOnlineIfNeeded(IClientAPI client) { UUID agentID = client.AgentId; if (m_NeedsListOfFriends.Contains(agentID)) { if (!m_Friends.ContainsKey(agentID)) { m_log.DebugFormat("[FRIENDS MODULE]: agent {0} not found in local cache", agentID); return; } // // Send the friends online // List<UUID> online = GetOnlineFriends(agentID); if (online.Count > 0) { m_log.DebugFormat("[FRIENDS MODULE]: User {0} in region {1} has {2} friends online", client.AgentId, client.Scene.RegionInfo.RegionName, online.Count); client.SendAgentOnline(online.ToArray()); } // // Send outstanding friendship offers // if (m_Friends.ContainsKey(agentID)) { List<string> outstanding = new List<string>(); foreach (FriendInfo fi in m_Friends[agentID].Friends) if (fi.TheirFlags == -1) outstanding.Add(fi.Friend); GridInstantMessage im = new GridInstantMessage(client.Scene, UUID.Zero, "", agentID, (byte)InstantMessageDialog.FriendshipOffered, "Will you be my friend?", true, Vector3.Zero); foreach (string fid in outstanding) { try { im.fromAgentID = new Guid(fid); } catch { continue; } UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID, new UUID(im.fromAgentID)); im.fromAgentName = account.FirstName + " " + account.LastName; PresenceInfo[] presences = PresenceService.GetAgents(new string[] { fid }); PresenceInfo presence = PresenceInfo.GetOnlinePresence(presences); if (presence != null) im.offline = 0; im.imSessionID = im.fromAgentID; // Finally LocalFriendshipOffered(agentID, im); } } lock (m_NeedsListOfFriends) m_NeedsListOfFriends.Remove(agentID); } }
private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) { FriendsService.StoreFriend(agentID, friendID.ToString(), 1); FriendsService.StoreFriend(friendID, agentID.ToString(), 1); // update the local cache m_Friends[agentID].Friends = FriendsService.GetFriends(agentID); m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", agentID, friendID); // // Notify the friend // // Try Local if (LocalFriendshipApproved(agentID, client.Name, friendID)) { client.SendAgentOnline(new UUID[] { friendID }); return; } // The friend is not here PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); if (friendSession != null) { GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); m_FriendsSimConnector.FriendshipApproved(region, agentID, client.Name, friendID); client.SendAgentOnline(new UUID[] { friendID }); } }
private void SendOnlineFriendsToClient(UUID[] candidateFriendIDsToReceive, IClientAPI client) { System.Threading.Thread.Sleep(3000); //TODO: FIXME KLUDGE! client.SendAgentOnline(candidateFriendIDsToReceive); }
public void SendFriendsOnlineIfNeeded(IClientAPI client) { UUID agentID = client.AgentId; if (m_NeedsListOfFriends.Contains(agentID)) { if (!m_Friends.ContainsKey(agentID)) { m_log.DebugFormat("[FRIENDS MODULE]: agent {0} not found in local cache", agentID); return; } // // Send the friends online // List <UUID> online = GetOnlineFriends(agentID); if (online.Count > 0) { m_log.DebugFormat("[FRIENDS MODULE]: User {0} in region {1} has {2} friends online", client.AgentId, client.Scene.RegionInfo.RegionName, online.Count); client.SendAgentOnline(online.ToArray()); } // // Send outstanding friendship offers // if (m_Friends.ContainsKey(agentID)) { List <string> outstanding = new List <string>(); foreach (FriendInfo fi in m_Friends[agentID].Friends) { if (fi.TheirFlags == -1) { outstanding.Add(fi.Friend); } } GridInstantMessage im = new GridInstantMessage(client.Scene, UUID.Zero, "", agentID, (byte)InstantMessageDialog.FriendshipOffered, "Will you be my friend?", true, Vector3.Zero); foreach (string fid in outstanding) { try { im.fromAgentID = new Guid(fid); } catch { continue; } UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID, new UUID(im.fromAgentID)); im.fromAgentName = account.FirstName + " " + account.LastName; PresenceInfo presence = null; PresenceInfo[] presences = PresenceService.GetAgents(new string[] { fid }); if (presences != null && presences.Length > 0) { presence = presences[0]; } if (presence != null) { im.offline = 0; } im.imSessionID = im.fromAgentID; // Finally LocalFriendshipOffered(agentID, im); } } lock (m_NeedsListOfFriends) m_NeedsListOfFriends.Remove(agentID); } }
private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) { m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", agentID, friendID); FriendsService.StoreFriend(agentID, friendID.ToString(), 1); FriendsService.StoreFriend(friendID, agentID.ToString(), 1); // Update the local cache UpdateFriendsCache(agentID); // // Notify the friend // client.SendAgentOnline(new UUID[] { friendID }); // // Send calling card to the local user // ICallingCardModule ccmodule = client.Scene.RequestModuleInterface<ICallingCardModule>(); if (ccmodule != null) { UUID folderID = ((Scene)client.Scene).InventoryService.GetFolderForType(agentID, AssetType.CallingCard).ID; ccmodule.CreateCallingCard(client, friendID, folderID, client.Name); } // Try Local if (LocalFriendshipApproved(agentID, client.Name, friendID)) return; // The friend is not here PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); if (friendSessions != null && friendSessions.Length > 0) { PresenceInfo friendSession = friendSessions[0]; if (friendSession != null) { GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); m_FriendsSimConnector.FriendshipApproved(region, agentID, client.Name, friendID); } } }
public void SendFriendsOnlineIfNeeded(IClientAPI client) { UUID agentID = client.AgentId; // Check if the online friends list is needed lock (m_NeedsListOfFriends) { if (!m_NeedsListOfFriends.Remove(agentID)) return; } // Send the friends online List<UUID> online = GetOnlineFriends(agentID); if (online.Count > 0) { m_log.DebugFormat("[FRIENDS MODULE]: User {0} in region {1} has {2} friends online", client.AgentId, client.Scene.RegionInfo.RegionName, online.Count); client.SendAgentOnline(online.ToArray()); } // Send outstanding friendship offers List<string> outstanding = new List<string>(); FriendInfo[] friends = GetFriends(agentID); foreach (FriendInfo fi in friends) { if (fi.TheirFlags == -1) outstanding.Add(fi.Friend); } GridInstantMessage im = new GridInstantMessage(client.Scene, UUID.Zero, String.Empty, agentID, (byte)InstantMessageDialog.FriendshipOffered, "Will you be my friend?", true, Vector3.Zero); foreach (string fid in outstanding) { UUID fromAgentID; if (!UUID.TryParse(fid, out fromAgentID)) continue; UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID, fromAgentID); PresenceInfo presence = null; PresenceInfo[] presences = PresenceService.GetAgents(new string[] { fid }); if (presences != null && presences.Length > 0) presence = presences[0]; if (presence != null) im.offline = 0; im.fromAgentID = fromAgentID.Guid; im.fromAgentName = account.FirstName + " " + account.LastName; im.offline = (byte)((presence == null) ? 1 : 0); im.imSessionID = im.fromAgentID; // Finally LocalFriendshipOffered(agentID, im); } }
/// <summary> /// Send presence information about a client to other clients in both this region and others. /// </summary> /// <param name="client"></param> /// <param name="friendList"></param> /// <param name="iAmOnline"></param> private void SendPresenceState(IClientAPI client, List<FriendListItem> friendList, bool iAmOnline) { //m_log.DebugFormat("[FRIEND]: {0} logged {1}; sending presence updates", client.Name, iAmOnline ? "in" : "out"); if (friendList == null || friendList.Count == 0) { //m_log.DebugFormat("[FRIEND]: {0} doesn't have friends.", client.Name); return; // nothing we can do if she doesn't have friends... } // collect sets of friendIDs; to send to (online and offline), and to receive from // TODO: If we ever switch to .NET >= 3, replace those Lists with HashSets. // I can't believe that we have Dictionaries, but no Sets, considering Java introduced them years ago... List<UUID> friendIDsToSendTo = new List<UUID>(); List<UUID> candidateFriendIDsToReceive = new List<UUID>(); foreach (FriendListItem item in friendList) { if (((item.FriendListOwnerPerms | item.FriendPerms) & (uint)FriendRights.CanSeeOnline) != 0) { // friend is allowed to see my presence => add if ((item.FriendListOwnerPerms & (uint)FriendRights.CanSeeOnline) != 0) friendIDsToSendTo.Add(item.Friend); if ((item.FriendPerms & (uint)FriendRights.CanSeeOnline) != 0) candidateFriendIDsToReceive.Add(item.Friend); } } // we now have a list of "interesting" friends (which we have to find out on-/offline state for), // friends we want to send our online state to (if *they* are online, too), and // friends we want to receive online state for (currently unknown whether online or not) // as this processing might take some time and friends might TP away, we try up to three times to // reach them. Most of the time, we *will* reach them, and this loop won't loop int retry = 0; do { // build a list of friends to look up region-information and on-/offline-state for List<UUID> friendIDsToLookup = new List<UUID>(friendIDsToSendTo); foreach (UUID uuid in candidateFriendIDsToReceive) { if (!friendIDsToLookup.Contains(uuid)) friendIDsToLookup.Add(uuid); } m_log.DebugFormat( "[FRIEND]: {0} to lookup, {1} to send to, {2} candidates to receive from for agent {3}", friendIDsToLookup.Count, friendIDsToSendTo.Count, candidateFriendIDsToReceive.Count, client.Name); // we have to fetch FriendRegionInfos, as the (cached) FriendListItems don't // necessarily contain the correct online state... Dictionary<UUID, FriendRegionInfo> friendRegions = m_initialScene.GetFriendRegionInfos(friendIDsToLookup); m_log.DebugFormat( "[FRIEND]: Found {0} regionInfos for {1} friends of {2}", friendRegions.Count, friendIDsToLookup.Count, client.Name); // argument for SendAgentOn/Offline; we shouldn't generate that repeatedly within loops. UUID[] agentArr = new UUID[] { client.AgentId }; // first, send to friend presence state to me, if I'm online... if (iAmOnline) { List<UUID> friendIDsToReceive = new List<UUID>(); for (int i = candidateFriendIDsToReceive.Count - 1; i >= 0; --i) { UUID uuid = candidateFriendIDsToReceive[i]; FriendRegionInfo info; if (friendRegions.TryGetValue(uuid, out info) && info != null && info.isOnline) { friendIDsToReceive.Add(uuid); } } m_log.DebugFormat( "[FRIEND]: Sending {0} online friends to {1}", friendIDsToReceive.Count, client.Name); if (friendIDsToReceive.Count > 0) client.SendAgentOnline(friendIDsToReceive.ToArray()); // clear them for a possible second iteration; we don't have to repeat this candidateFriendIDsToReceive.Clear(); } // now, send my presence state to my friends for (int i = friendIDsToSendTo.Count - 1; i >= 0; --i) { UUID uuid = friendIDsToSendTo[i]; FriendRegionInfo info; if (friendRegions.TryGetValue(uuid, out info) && info != null && info.isOnline) { // any client is good enough, root or child... ScenePresence agent = GetAnyPresenceFromAgentID(uuid); if (agent != null) { //m_log.DebugFormat("[FRIEND]: Found local agent {0}", agent.Name); // friend is online and on this server... if (iAmOnline) agent.ControllingClient.SendAgentOnline(agentArr); else agent.ControllingClient.SendAgentOffline(agentArr); // done, remove it friendIDsToSendTo.RemoveAt(i); } } else { //m_log.DebugFormat("[FRIEND]: Friend {0} ({1}) is offline; not sending.", uuid, i); // friend is offline => no need to try sending friendIDsToSendTo.RemoveAt(i); } } m_log.DebugFormat("[FRIEND]: Have {0} friends to contact via inter-region comms.", friendIDsToSendTo.Count); // we now have all the friends left that are online (we think), but not on this region-server if (friendIDsToSendTo.Count > 0) { // sort them into regions Dictionary<ulong, List<UUID>> friendsInRegion = new Dictionary<ulong,List<UUID>>(); foreach (UUID uuid in friendIDsToSendTo) { ulong handle = friendRegions[uuid].regionHandle; // this can't fail as we filtered above already List<UUID> friends; if (!friendsInRegion.TryGetValue(handle, out friends)) { friends = new List<UUID>(); friendsInRegion[handle] = friends; } friends.Add(uuid); } m_log.DebugFormat("[FRIEND]: Found {0} regions to send to.", friendRegions.Count); // clear uuids list and collect missed friends in it for the next retry friendIDsToSendTo.Clear(); // send bulk updates to the region foreach (KeyValuePair<ulong, List<UUID>> pair in friendsInRegion) { //m_log.DebugFormat("[FRIEND]: Inform {0} friends in region {1} that user {2} is {3}line", // pair.Value.Count, pair.Key, client.Name, iAmOnline ? "on" : "off"); friendIDsToSendTo.AddRange(InformFriendsInOtherRegion(client.AgentId, pair.Key, pair.Value, iAmOnline)); } } // now we have in friendIDsToSendTo only the agents left that TPed away while we tried to contact them. // In most cases, it will be empty, and it won't loop here. But sometimes, we have to work harder and try again... } while (++retry < 3 && friendIDsToSendTo.Count > 0); }
public bool LocalFriendshipApproved(UUID userID, string name, IClientAPI us, UUID friendID) { IClientAPI friendClient = LocateClientObject(friendID); if (friendClient != null) { //They are online, send the online message if (us != null) us.SendAgentOnline(new[] {friendID}); // the prospective friend in this sim as root agent GridInstantMessage im = new GridInstantMessage(m_Scenes[0], userID, name, friendID, (byte) InstantMessageDialog.FriendshipAccepted, userID.ToString(), false, Vector3.Zero); friendClient.SendInstantMessage(im); // Update the local cache UpdateFriendsCache(friendID); // // put a calling card into the inventory of the friend // ICallingCardModule ccmodule = friendClient.Scene.RequestModuleInterface<ICallingCardModule>(); if (ccmodule != null) { UserAccount account = friendClient.Scene.UserAccountService.GetUserAccount(UUID.Zero, userID); UUID folderID = friendClient.Scene.InventoryService.GetFolderForType(friendID, InventoryType.Unknown, AssetType.CallingCard).ID; ccmodule.CreateCallingCard(friendClient, userID, folderID, account.Name); } // we're done return true; } return false; }
private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) { m_log.DebugFormat("[FRIEND]: Got approve friendship from {0} {1}, agentID {2}, tid {3}", client.Name, client.AgentId, agentID, friendID); // store the new friend persistently for both avatars m_initialScene.StoreAddFriendship(friendID, agentID, (uint) FriendRights.CanSeeOnline); // The cache entries aren't valid anymore either, as we just added a friend to both sides. lock (m_friendLists) { m_friendLists.Invalidate(agentID.ToString()); m_friendLists.Invalidate(friendID.ToString()); } // if it's a local friend, we don't have to do the lookup ScenePresence friendPresence = GetAnyPresenceFromAgentID(friendID); if (friendPresence != null) { m_log.Debug("[FRIEND]: Local agent detected."); // create calling card CreateCallingCard(client, friendID, callingCardFolders[0], friendPresence.Name); // local message means OnGridInstantMessage won't be triggered, so do the work here. friendPresence.ControllingClient.SendInstantMessage( new GridInstantMessage(client.Scene, agentID, client.Name, friendID, (byte)InstantMessageDialog.FriendshipAccepted, agentID.ToString(), false, Vector3.Zero)); ApproveFriendship(agentID, friendID, client.Name); } else { m_log.Debug("[FRIEND]: Remote agent detected."); // fetch the friend's name for the calling card. CachedUserInfo info = m_initialScene.CommsManager.UserProfileCacheService.GetUserDetails(friendID); // create calling card CreateCallingCard(client, friendID, callingCardFolders[0], info.UserProfile.FirstName + " " + info.UserProfile.SurName); // Compose (remote) response to friend. GridInstantMessage msg = new GridInstantMessage(client.Scene, agentID, client.Name, friendID, (byte)InstantMessageDialog.FriendshipAccepted, agentID.ToString(), false, Vector3.Zero); if (m_TransferModule != null) { m_TransferModule.SendInstantMessage(msg, delegate(bool success) { m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success); } ); } } // tell client that new friend is online client.SendAgentOnline(new UUID[] { friendID }); }
public void SendFriendsOnlineIfNeeded(IClientAPI client) { UUID agentID = client.AgentId; // Check if the online friends list is needed lock (m_NeedsListOfFriends) { if (!m_NeedsListOfFriends.Remove(agentID)) { return; } } // Send the friends online List <UUID> online = GetOnlineFriends(agentID); if (online.Count > 0) { m_log.DebugFormat("[FRIENDS MODULE]: User {0} in region {1} has {2} friends online", client.AgentId, client.Scene.RegionInfo.RegionName, online.Count); client.SendAgentOnline(online.ToArray()); } // Send outstanding friendship offers List <string> outstanding = new List <string>(); FriendInfo[] friends = GetFriends(agentID); foreach (FriendInfo fi in friends) { if (fi.TheirFlags == -1) { outstanding.Add(fi.Friend); } } GridInstantMessage im = new GridInstantMessage(client.Scene, UUID.Zero, String.Empty, agentID, (byte)InstantMessageDialog.FriendshipOffered, "Will you be my friend?", true, Vector3.Zero); foreach (string fid in outstanding) { UUID fromAgentID; if (!UUID.TryParse(fid, out fromAgentID)) { continue; } UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID, fromAgentID); PresenceInfo presence = null; PresenceInfo[] presences = PresenceService.GetAgents(new string[] { fid }); if (presences != null && presences.Length > 0) { presence = presences[0]; } if (presence != null) { im.offline = 0; } im.fromAgentID = fromAgentID.Guid; im.fromAgentName = account.FirstName + " " + account.LastName; im.offline = (byte)((presence == null) ? 1 : 0); im.imSessionID = im.fromAgentID; // Finally LocalFriendshipOffered(agentID, im); } }
//protected override void GetOnlineFriends(UUID userID, List<string> friendList, /*collector*/ List<UUID> online) //{ // // Let's single out the UUIs // List<string> localFriends = new List<string>(); // List<string> foreignFriends = new List<string>(); // string tmp = string.Empty; // foreach (string s in friendList) // { // UUID id; // if (UUID.TryParse(s, out id)) // localFriends.Add(s); // else if (Util.ParseUniversalUserIdentifier(s, out id, out tmp, out tmp, out tmp, out tmp)) // { // foreignFriends.Add(s); // // add it here too, who knows maybe the foreign friends happens to be on this grid // localFriends.Add(id.ToString()); // } // } // // OK, see who's present on this grid // List<string> toBeRemoved = new List<string>(); // PresenceInfo[] presence = PresenceService.GetAgents(localFriends.ToArray()); // foreach (PresenceInfo pi in presence) // { // UUID presenceID; // if (UUID.TryParse(pi.UserID, out presenceID)) // { // online.Add(presenceID); // foreach (string s in foreignFriends) // if (s.StartsWith(pi.UserID)) // toBeRemoved.Add(s); // } // } // foreach (string s in toBeRemoved) // foreignFriends.Remove(s); // // OK, let's send this up the stack, and leave a closure here // // collecting online friends in other grids // Util.FireAndForget(delegate { CollectOnlineFriendsElsewhere(userID, foreignFriends); }); //} //private void CollectOnlineFriendsElsewhere(UUID userID, List<string> foreignFriends) //{ // // let's divide the friends on a per-domain basis // Dictionary<string, List<string>> friendsPerDomain = new Dictionary<string, List<string>>(); // foreach (string friend in foreignFriends) // { // UUID friendID; // if (!UUID.TryParse(friend, out friendID)) // { // // it's a foreign friend // string url = string.Empty, tmp = string.Empty; // if (Util.ParseUniversalUserIdentifier(friend, out friendID, out url, out tmp, out tmp, out tmp)) // { // if (!friendsPerDomain.ContainsKey(url)) // friendsPerDomain[url] = new List<string>(); // friendsPerDomain[url].Add(friend); // } // } // } // // Now, call those worlds // foreach (KeyValuePair<string, List<string>> kvp in friendsPerDomain) // { // List<string> ids = new List<string>(); // foreach (string f in kvp.Value) // ids.Add(f); // UserAgentServiceConnector uConn = new UserAgentServiceConnector(kvp.Key); // List<UUID> online = uConn.GetOnlineFriends(userID, ids); // // Finally send the notifications to the user // // this whole process may take a while, so let's check at every // // iteration that the user is still here // IClientAPI client = LocateClientObject(userID); // if (client != null) // client.SendAgentOnline(online.ToArray()); // else // break; // } //} protected override void StatusNotify(List <FriendInfo> friendList, UUID userID, bool online) { // m_log.DebugFormat("[HGFRIENDS MODULE]: Entering StatusNotify for {0}", userID); // First, let's divide the friends on a per-domain basis Dictionary <string, List <FriendInfo> > friendsPerDomain = new Dictionary <string, List <FriendInfo> >(); foreach (FriendInfo friend in friendList) { UUID friendID; if (UUID.TryParse(friend.Friend, out friendID)) { if (!friendsPerDomain.ContainsKey("local")) { friendsPerDomain["local"] = new List <FriendInfo>(); } friendsPerDomain["local"].Add(friend); } else { // it's a foreign friend string url = string.Empty, tmp = string.Empty; if (Util.ParseUniversalUserIdentifier(friend.Friend, out friendID, out url, out tmp, out tmp, out tmp)) { // Let's try our luck in the local sim. Who knows, maybe it's here if (LocalStatusNotification(userID, friendID, online)) { continue; } if (!friendsPerDomain.ContainsKey(url)) { friendsPerDomain[url] = new List <FriendInfo>(); } friendsPerDomain[url].Add(friend); } } } // For the local friends, just call the base method // Let's do this first of all if (friendsPerDomain.ContainsKey("local")) { base.StatusNotify(friendsPerDomain["local"], userID, online); } foreach (KeyValuePair <string, List <FriendInfo> > kvp in friendsPerDomain) { if (kvp.Key != "local") { // For the others, call the user agent service List <string> ids = new List <string>(); foreach (FriendInfo f in kvp.Value) { ids.Add(f.Friend); } UserAgentServiceConnector uConn = new UserAgentServiceConnector(kvp.Key); List <UUID> friendsOnline = uConn.StatusNotification(ids, userID, online); if (online && friendsOnline.Count > 0) { IClientAPI client = LocateClientObject(userID); if (client != null) { client.SendAgentOnline(friendsOnline.ToArray()); } } } } // m_log.DebugFormat("[HGFRIENDS MODULE]: Exiting StatusNotify for {0}", userID); }
public void AddFriendship(IClientAPI client, UUID friendID) { StoreFriendships(client.AgentId, friendID); ICallingCardModule ccm = client.Scene.RequestModuleInterface<ICallingCardModule>(); if (ccm != null) { ccm.CreateCallingCard(client.AgentId, friendID, UUID.Zero); } // Update the local cache. RecacheFriends(client); // // Notify the friend // // Try Local if (LocalFriendshipApproved(client.AgentId, client.Name, friendID)) { client.SendAgentOnline(new UUID[] { friendID }); return; } // The friend is not here PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); if (friendSessions != null && friendSessions.Length > 0) { PresenceInfo friendSession = friendSessions[0]; if (friendSession != null) { GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); m_FriendsSimConnector.FriendshipApproved(region, client.AgentId, client.Name, friendID); client.SendAgentOnline(new UUID[] { friendID }); } } }
public virtual bool SendFriendsOnlineIfNeeded(IClientAPI client) { UUID agentID = client.AgentId; // Check if the online friends list is needed lock (m_NeedsListOfOnlineFriends) { if (!m_NeedsListOfOnlineFriends.Remove(agentID)) return false; } // Send the friends online List<UUID> online = GetOnlineFriends(agentID); if (online.Count > 0) client.SendAgentOnline(online.ToArray()); // Send outstanding friendship offers List<string> outstanding = new List<string>(); FriendInfo[] friends = GetFriendsFromCache(agentID); foreach (FriendInfo fi in friends) { if (fi.TheirFlags == -1) outstanding.Add(fi.Friend); } GridInstantMessage im = new GridInstantMessage(client.Scene, UUID.Zero, String.Empty, agentID, (byte)InstantMessageDialog.FriendshipOffered, "Will you be my friend?", true, Vector3.Zero); foreach (string fid in outstanding) { UUID fromAgentID; string firstname = "Unknown", lastname = "User"; if (!GetAgentInfo(client.Scene.RegionInfo.ScopeID, fid, out fromAgentID, out firstname, out lastname)) { m_log.DebugFormat("[FRIENDS MODULE]: skipping malformed friend {0}", fid); continue; } im.offline = 0; im.fromAgentID = fromAgentID.Guid; im.fromAgentName = firstname + " " + lastname; im.imSessionID = im.fromAgentID; im.message = FriendshipMessage(fid); LocalFriendshipOffered(agentID, im); } return true; }