OpenSim.Region.CoreModules.Avatar.Friends.FriendsModule.SendFriendsOnlineIfNeeded C# (CSharp) Method

SendFriendsOnlineIfNeeded() public method

public SendFriendsOnlineIfNeeded ( IClientAPI client ) : void
client IClientAPI
return void
        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);
            }
        }