public string GetUUI(UUID userID, UUID targetUserID)
        {
            // Let's see if it's a local user
            UserAccount account = m_UserAccountService.GetUserAccount(null, targetUserID);

            if (account != null)
            {
                return(targetUserID.ToString() + ";" + m_GridName + ";" + account.FirstName + " " + account.LastName);
            }

            // Let's try the list of friends
            List <FriendInfo> friends = m_FriendsService.GetFriends(userID);

            if (friends != null && friends.Count > 0)
            {
                foreach (FriendInfo f in friends)
                {
                    if (f.Friend.StartsWith(targetUserID.ToString()))
                    {
                        // Let's remove the secret
                        UUID   id;
                        string tmp = string.Empty, secret = string.Empty;
                        if (HGUtil.ParseUniversalUserIdentifier(f.Friend, out id, out tmp, out tmp, out tmp, out secret))
                        {
                            return(f.Friend.Replace(secret, "0"));
                        }
                    }
                }
            }

            return(string.Empty);
        }
        public List <UUID> GetOnlineFriends(UUID foreignUserID, List <string> friends)
        {
            List <UUID> online = new List <UUID> ();

            if (m_FriendsService == null || m_PresenceService == null)
            {
                MainConsole.Instance.WarnFormat("[USER AGENT SERVICE]: Unable to get online friends because friends or presence services are missing");
                return(online);
            }

            MainConsole.Instance.DebugFormat("[USER AGENT SERVICE]: Foreign user {0} wants to know status of {1} local friends", foreignUserID, friends.Count);

            // First, let's double check that the reported friends are, indeed, friends of that user
            // And let's check that the secret matches and the rights
            List <string> usersToBeNotified = new List <string> ();

            foreach (string uui in friends)
            {
                UUID   localUserID;
                string secret = string.Empty, tmp = string.Empty;
                if (HGUtil.ParseUniversalUserIdentifier(uui, out localUserID, out tmp, out tmp, out tmp, out secret))
                {
                    List <FriendInfo> friendInfos = m_FriendsService.GetFriends(localUserID);
                    foreach (FriendInfo finfo in friendInfos)
                    {
                        if (finfo.Friend.StartsWith(foreignUserID.ToString()) && finfo.Friend.EndsWith(secret) &&
                            (finfo.TheirFlags & (int)FriendRights.CanSeeOnline) != 0 && (finfo.TheirFlags != -1))
                        {
                            // great!
                            usersToBeNotified.Add(localUserID.ToString());
                        }
                    }
                }
            }

            // Now, let's find out their status
            MainConsole.Instance.DebugFormat("[USER AGENT SERVICE]: GetOnlineFriends: user has {0} local friends with status rights", usersToBeNotified.Count);

            // First, let's send notifications to local users who are online in the home grid
            List <UserInfo> friendSessions = m_PresenceService.GetUserInfos(usersToBeNotified);

            if (friendSessions != null && friendSessions.Count > 0)
            {
                foreach (UserInfo pi in friendSessions)
                {
                    UUID presenceID;
                    if (UUID.TryParse(pi.UserID, out presenceID))
                    {
                        online.Add(presenceID);
                    }
                }
            }

            return(online);
        }
        public bool RemoteStatusNotification(FriendInfo friend, UUID userID, bool online)
        {
            string url, first, last, secret;
            UUID   FriendToInform;

            if (HGUtil.ParseUniversalUserIdentifier(friend.Friend, out FriendToInform, out url, out first, out last, out secret))
            {
                UserAgentServiceConnector connector = new UserAgentServiceConnector(url);
                List <UUID> informedFriends         = connector.StatusNotification(new List <string> (new string[1] {
                    FriendToInform.ToString()
                }),
                                                                                   userID, online);
                return(informedFriends.Count > 0);
            }
            return(false);
        }
        byte[] NewFriendship(Dictionary <string, object> request)
        {
            if (!VerifyServiceKey(request))
            {
                return(FailureResult());
            }

            // OK, can proceed
            FriendInfo friend = new FriendInfo(request);
            UUID       friendID;
            string     tmp = string.Empty;

            if (!HGUtil.ParseUniversalUserIdentifier(friend.Friend, out friendID, out tmp, out tmp, out tmp, out tmp))
            {
                return(FailureResult());
            }


            MainConsole.Instance.DebugFormat("[HGFRIENDS HANDLER]: New friendship {0} {1}", friend.PrincipalID, friend.Friend);

            // If the friendship already exists, return fail
            List <FriendInfo> finfos = m_FriendsService.GetFriends(friend.PrincipalID);

            foreach (FriendInfo finfo in finfos)
            {
                if (finfo.Friend.StartsWith(friendID.ToString()))
                {
                    return(FailureResult());
                }
            }

            // the user needs to confirm when he gets home
            bool success = m_FriendsService.StoreFriend(friend.PrincipalID, friend.Friend, 0);

            if (success)
            {
                return(SuccessResult());
            }
            else
            {
                return(FailureResult());
            }
        }
        public void OfflineFriendRequest(IClientAPI client)
        {
            // Barrowed a few lines from SendFriendsOnlineIfNeeded() above.
            UUID agentID = client.AgentId;

            FriendInfo[]       friends = FriendsService.GetFriendsRequest(agentID).ToArray();
            GridInstantMessage im      = new GridInstantMessage(client.Scene, UUID.Zero, String.Empty, agentID,
                                                                (byte)InstantMessageDialog.FriendshipOffered,
                                                                "Will you be my friend?", true, Vector3.Zero);

            foreach (FriendInfo fi in friends)
            {
                if (fi.MyFlags == 0)
                {
                    UUID   fromAgentID;
                    string url = "", first = "", last = "", secret = "";
                    if (!UUID.TryParse(fi.Friend, out fromAgentID))
                    {
                        if (
                            !HGUtil.ParseUniversalUserIdentifier(fi.Friend, out fromAgentID, out url, out first, out last, out secret))
                        {
                            continue;
                        }
                    }

                    UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.AllScopeIDs, fromAgentID);
                    im.fromAgentID = fromAgentID;
                    if (account != null)
                    {
                        im.fromAgentName = account.Name;
                    }
                    else
                    {
                        im.fromAgentName = first + " " + last;
                    }
                    im.offline     = 1;
                    im.imSessionID = im.fromAgentID;

                    LocalFriendshipOffered(agentID, im);
                }
            }
        }
        private void OnDenyFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List <UUID> callingCardFolders)
        {
            MainConsole.Instance.DebugFormat("[FRIENDS]: {0} denied friendship to {1}", agentID, friendID);


            FriendInfo[] friends = FriendsService.GetFriendsRequest(agentID).ToArray();
            foreach (FriendInfo fi in friends)
            {
                if (fi.MyFlags == 0)
                {
                    UUID   fromAgentID;
                    string url = "", first = "", last = "", secret = "";
                    if (!UUID.TryParse(fi.Friend, out fromAgentID))
                    {
                        if (
                            !HGUtil.ParseUniversalUserIdentifier(fi.Friend, out fromAgentID, out url, out first, out last, out secret))
                        {
                            continue;
                        }
                    }
                    if (fromAgentID == friendID)//Get those pesky HG travelers as well
                    {
                        FriendsService.Delete(agentID, fi.Friend);
                    }
                }
            }
            FriendsService.Delete(friendID, agentID.ToString());

            //
            // Notify the friend
            //

            // Try local
            if (LocalFriendshipDenied(agentID, client.Name, friendID))
            {
                return;
            }
            SyncMessagePosterService.Post(SyncMessageHelper.FriendshipDenied(
                                              agentID, client.Name, friendID, m_Scenes[0].RegionInfo.RegionHandle),
                                          m_Scenes[0].RegionInfo.RegionHandle);
        }
Example #7
0
        /// <summary>
        /// Look up the given user id to check whether it's one that is valid for this grid.
        /// </summary>
        /// <param name="uuid"></param>
        /// <param name="creatorID"></param>
        /// <param name="creatorData"></param>
        /// <param name="location"></param>
        /// <param name="parcels"></param>
        /// <returns></returns>
        private UUID ResolveUserUuid(UUID uuid, UUID creatorID, string creatorData, Vector3 location, IEnumerable <LandData> parcels)
        {
            UUID u;

            if (!m_validUserUuids.TryGetValue(uuid, out u))
            {
                UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.AllScopeIDs, uuid);
                if (account != null)
                {
                    m_validUserUuids.Add(uuid, uuid);
                    return(uuid);
                }
                if (uuid == creatorID)
                {
                    UUID   hid;
                    string first, last, url, secret;
                    if (HGUtil.ParseUniversalUserIdentifier(creatorData, out hid, out url, out first, out last, out secret))
                    {
                        account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.AllScopeIDs, first, last);
                        if (account != null)
                        {
                            m_validUserUuids.Add(uuid, account.PrincipalID);
                            return(account.PrincipalID);//Fix the UUID
                        }
                    }
                }
                IUserFinder uf = m_scene.RequestModuleInterface <IUserFinder>();
                if (uf != null)
                {
                    if (!uf.IsLocalGridUser(uuid))//Foreign user, don't remove their info
                    {
                        m_validUserUuids.Add(uuid, uuid);
                        return(uuid);
                    }
                }
                UUID id = UUID.Zero;
                if (m_checkOwnership || (m_useParcelOwnership && parcels == null))//parcels == null is a parcel owner, ask for it if useparcel is on
                {
tryAgain:
                    string ownerName = MainConsole.Instance.Prompt(string.Format("User Name to use instead of UUID '{0}'", uuid), "");
                    account          = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.AllScopeIDs, ownerName);
                    if (account != null)
                    {
                        id = account.PrincipalID;
                    }
                    else if (ownerName != "")
                    {
                        if ((ownerName = MainConsole.Instance.Prompt("User was not found, do you want to try again?", "no", new List <string>(new[] { "no", "yes" }))) == "yes")
                        {
                            goto tryAgain;
                        }
                    }
                }
                if (m_useParcelOwnership && id == UUID.Zero && location != Vector3.Zero && parcels != null)
                {
                    foreach (LandData data in parcels)
                    {
                        if (ContainsPoint(data, (int)location.X + m_offsetX, (int)location.Y + m_offsetY))
                        {
                            if (uuid != data.OwnerID)
                            {
                                id = data.OwnerID;
                            }
                        }
                    }
                }
                if (id == UUID.Zero)
                {
                    id = m_scene.RegionInfo.EstateSettings.EstateOwner;
                }
                m_validUserUuids.Add(uuid, id);

                return(m_validUserUuids[uuid]);
            }

            return(u);
        }
Example #8
0
        public void SendFriendsOnlineIfNeeded(IClientAPI client)
        {
            UUID agentID = client.AgentId;

            // 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);
                }
                UUID   friendID;
                string url = "", first = "", last = "", secret = "";
                if (HGUtil.ParseUniversalUserIdentifier(fi.Friend, out friendID, out url, out first, out last,
                                                        out secret))
                {
                    IUserManagement userManagement = m_Scenes[0].RequestModuleInterface <IUserManagement>();
                    if (userManagement != null)
                    {
                        userManagement.AddUser(friendID, 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 url = "", first = "", last = "", secret = "";
                if (!UUID.TryParse(fid, out fromAgentID))
                {
                    if (
                        !HGUtil.ParseUniversalUserIdentifier(fid, out fromAgentID, out url, out first, out last,
                                                             out secret))
                    {
                        continue;
                    }
                }

                UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID,
                                                                                    fromAgentID);

                im.fromAgentID = fromAgentID;
                if (account != null)
                {
                    im.fromAgentName = account.Name;
                }
                else
                {
                    im.fromAgentName = first + " " + last;
                }
                im.offline     = 1;
                im.imSessionID = im.fromAgentID;

                // Finally
                LocalFriendshipOffered(agentID, im);
            }

            lock (m_friendsToInformOfStatusChanges)
            {
                if (m_friendsToInformOfStatusChanges.ContainsKey(agentID))
                {
                    List <UUID> onlineFriends = new List <UUID>(m_friendsToInformOfStatusChanges[agentID]);
                    foreach (UUID friend in onlineFriends)
                    {
                        SendFriendsStatusMessage(agentID, friend, true);
                    }
                    m_friendsToInformOfStatusChanges.Remove(agentID);
                }
            }
        }
Example #9
0
        protected object OnGenericEvent(string FunctionName, object parameters)
        {
            if (FunctionName == "UserStatusChange")
            {
                //A user has logged in or out... we need to update friends lists across the grid

                IAsyncMessagePostService asyncPoster    = m_registry.RequestModuleInterface <IAsyncMessagePostService>();
                IFriendsService          friendsService = m_registry.RequestModuleInterface <IFriendsService>();
                ICapsService             capsService    = m_registry.RequestModuleInterface <ICapsService>();
                IGridService             gridService    = m_registry.RequestModuleInterface <IGridService>();
                if (asyncPoster != null && friendsService != null && capsService != null && gridService != null)
                {
                    //Get all friends
                    object[] info     = (object[])parameters;
                    UUID     us       = UUID.Parse(info[0].ToString());
                    bool     isOnline = bool.Parse(info[1].ToString());

                    List <FriendInfo> friends                 = friendsService.GetFriends(us);
                    List <UUID>       OnlineFriends           = new List <UUID>();
                    List <string>     previouslyContactedURLs = new List <string>();
                    foreach (FriendInfo friend in friends)
                    {
                        if (friend.TheirFlags == -1 || friend.MyFlags == -1)
                        {
                            continue; //Not validiated yet!
                        }
                        UUID   FriendToInform = UUID.Zero;
                        string url, first, last, secret;
                        if (!UUID.TryParse(friend.Friend, out FriendToInform))
                        {
                            HGUtil.ParseUniversalUserIdentifier(friend.Friend, out FriendToInform, out url, out first,
                                                                out last, out secret);
                        }
                        //Now find their caps service so that we can find where they are root (and if they are logged in)
                        IClientCapsService clientCaps = capsService.GetClientCapsService(FriendToInform);
                        if (clientCaps != null)
                        {
                            //Find the root agent
                            IRegionClientCapsService regionClientCaps = clientCaps.GetRootCapsService();
                            if (regionClientCaps != null)
                            {
                                OnlineFriends.Add(FriendToInform);
                                //Post!
                                asyncPoster.Post(regionClientCaps.RegionHandle,
                                                 SyncMessageHelper.AgentStatusChange(us, FriendToInform, isOnline));
                            }
                            else
                            {
                                //If they don't have a root agent, wtf happened?
                                capsService.RemoveCAPS(clientCaps.AgentID);
                            }
                        }
                        else
                        {
                            IAgentInfoService agentInfoService = m_registry.RequestModuleInterface <IAgentInfoService>();
                            if (agentInfoService != null)
                            {
                                UserInfo friendinfo = agentInfoService.GetUserInfo(FriendToInform.ToString());
                                if (friendinfo != null && friendinfo.IsOnline)
                                {
                                    OnlineFriends.Add(FriendToInform);
                                    //Post!
                                    GridRegion r = gridService.GetRegionByUUID(UUID.Zero, friendinfo.CurrentRegionID);
                                    if (r != null)
                                    {
                                        asyncPoster.Post(r.RegionHandle,
                                                         SyncMessageHelper.AgentStatusChange(us, FriendToInform,
                                                                                             isOnline));
                                    }
                                }
                                else
                                {
                                    IUserAgentService uas = m_registry.RequestModuleInterface <IUserAgentService>();
                                    if (uas != null)
                                    {
                                        bool online = uas.RemoteStatusNotification(friend, us, isOnline);
                                        if (online)
                                        {
                                            OnlineFriends.Add(FriendToInform);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    //If the user is coming online, send all their friends online statuses to them
                    if (isOnline)
                    {
                        GridRegion ourRegion = gridService.GetRegionByUUID(UUID.Zero, UUID.Parse(info[2].ToString()));
                        if (ourRegion != null)
                        {
                            foreach (UUID onlineFriend in OnlineFriends)
                            {
                                asyncPoster.Post(ourRegion.RegionHandle,
                                                 SyncMessageHelper.AgentStatusChange(onlineFriend, us, isOnline));
                            }
                        }
                    }
                }
            }
            return(null);
        }
        public List <UUID> StatusNotification(List <string> friends, UUID foreignUserID, bool online)
        {
            if (m_FriendsService == null || m_PresenceService == null)
            {
                MainConsole.Instance.WarnFormat("[USER AGENT SERVICE]: Unable to perform status notifications because friends or presence services are missing");
                return(new List <UUID> ());
            }

            List <UUID> localFriendsOnline = new List <UUID> ();

            MainConsole.Instance.DebugFormat("[USER AGENT SERVICE]: Status notification: foreign user {0} wants to notify {1} local friends", foreignUserID, friends.Count);

            // First, let's double check that the reported friends are, indeed, friends of that user
            // And let's check that the secret matches
            List <string> usersToBeNotified = new List <string> ();

            foreach (string uui in friends)
            {
                UUID   localUserID;
                string secret = string.Empty, tmp = string.Empty;
                if (HGUtil.ParseUniversalUserIdentifier(uui, out localUserID, out tmp, out tmp, out tmp, out secret))
                {
                    List <FriendInfo> friendInfos = m_FriendsService.GetFriends(localUserID);
                    foreach (FriendInfo finfo in friendInfos)
                    {
                        if (finfo.Friend.StartsWith(foreignUserID.ToString()) && finfo.Friend.EndsWith(secret))
                        {
                            // great!
                            usersToBeNotified.Add(localUserID.ToString());
                        }
                    }
                }
            }

            // Now, let's send the notifications
            MainConsole.Instance.DebugFormat("[USER AGENT SERVICE]: Status notification: user has {0} local friends", usersToBeNotified.Count);

            // First, let's send notifications to local users who are online in the home grid

            //Send "" because if we pass the UUID, it will get the locations for all friends, even on the grid they came from
            List <UserInfo> friendSessions = m_PresenceService.GetUserInfos(usersToBeNotified);

            foreach (UserInfo friend in friendSessions)
            {
                if (friend.IsOnline)
                {
                    GridRegion ourRegion = m_GridService.GetRegionByUUID(null, friend.CurrentRegionID);
                    if (ourRegion != null)
                    {
                        m_asyncPostService.Post(ourRegion.RegionHandle,
                                                SyncMessageHelper.AgentStatusChange(foreignUserID, UUID.Parse(friend.UserID), true));
                    }
                }
            }

            // Lastly, let's notify the rest who may be online somewhere else
            foreach (string user in usersToBeNotified)
            {
                UUID id = new UUID(user);
                if (m_TravelingAgents.ContainsKey(id) && m_TravelingAgents[id].GridExternalName != m_GridName)
                {
                    string url = m_TravelingAgents[id].GridExternalName;
                    // forward
                    MainConsole.Instance.WarnFormat("[USER AGENT SERVICE]: User {0} is visiting {1}. HG Status notifications still not implemented.", user, url);
                }
            }

            // and finally, let's send the online friends
            if (online)
            {
                return(localFriendsOnline);
            }
            else
            {
                return(new List <UUID> ());
            }
        }