Esempio n. 1
0
        public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
        {
            FriendListItem newfriend = new FriendListItem();
            newfriend.FriendPerms = perms;
            newfriend.Friend = friend;
            newfriend.FriendListOwner = friendlistowner;

            if (!m_friendsListByUuid.ContainsKey(friendlistowner))
            {
                List<FriendListItem> friendslist = new List<FriendListItem>();
                m_friendsListByUuid[friendlistowner] = friendslist;

            }
            m_friendsListByUuid[friendlistowner].Add(newfriend);
        }
Esempio n. 2
0
        /// <summary>
        /// Get (fetch?) the friendlist for a user
        /// </summary>
        /// <param name="friendlistowner">UUID of the friendlist owner</param>
        /// <returns>The friendlist list</returns>
        override public List<FriendListItem> GetUserFriendList(UUID friendlistowner)
        {
            List<FriendListItem> returnlist = new List<FriendListItem>();

            using (SqliteCommand cmd = new SqliteCommand(SelectFriendsByUUID, g_conn))
            {
                cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.ToString()));

                try
                {
                    using (IDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            FriendListItem user = new FriendListItem();
                            user.FriendListOwner = friendlistowner;
                            user.Friend = new UUID((string)reader[0]);
                            user.FriendPerms = Convert.ToUInt32(reader[1]);
                            user.FriendListOwnerPerms = Convert.ToUInt32(reader[2]);
                            returnlist.Add(user);
                        }
                        reader.Close();
                    }
                }
                catch (Exception ex)
                {
                    m_log.Error("[USER DB]: Exception getting friends list for user: " + ex.ToString());
                }
            }

            return returnlist;
        }
Esempio n. 3
0
        public override List<FriendListItem> GetUserFriendList(UUID ownerId) 
        {
            List<FriendListItem> friendList=new List<FriendListItem>();
            Dictionary<UUID, FriendListItem> friendListItemDictionary = new Dictionary<UUID, FriendListItem>();

            using (ISession session = manager.GetSession())
            {
                    ICriteria criteria = session.CreateCriteria(typeof(UserFriend));
                    criteria.Add(Expression.Or(
                        Expression.Eq("OwnerID", ownerId),
                        Expression.Eq("FriendID", ownerId)
                        ));

                    foreach (UserFriend userFriend in criteria.List())
                    {
                        if (userFriend.OwnerID == ownerId)
                        {
                            FriendListItem friendListItem = new FriendListItem();
                            friendListItem.FriendListOwner = userFriend.OwnerID;
                            friendListItem.Friend = userFriend.FriendID;
                            friendListItem.FriendPerms = userFriend.FriendPermissions;
                            friendListItemDictionary.Add(userFriend.FriendID, friendListItem);
                            friendList.Add(friendListItem);
                        }
                    }

                    // Reading permissions to other direction
                    foreach (UserFriend userFriend in criteria.List())
                    {
                        if (userFriend.FriendID == ownerId)
                        {
                            //Ignore if there is no reverse relation existing.
                            //if (friendListItemDictionary.ContainsKey(userFriend.OwnerID))
                            {
                                FriendListItem friendListItem = friendListItemDictionary[userFriend.OwnerID];
                                friendListItem.FriendListOwnerPerms = userFriend.FriendPermissions;
                            }
                        }
                    }

            }

            return friendList; 
        }
Esempio n. 4
0
        /// <summary>
        /// Get (fetch?) the user's friendlist
        /// </summary>
        /// <param name="friendlistowner">UUID of the friendlist owner</param>
        /// <returns>Friendlist list</returns>
        override public List<FriendListItem> GetUserFriendList(UUID friendlistowner)
        {
            List<FriendListItem> friendList = new List<FriendListItem>();

            //Left Join userfriends to itself
            string sql = string.Format(@"SELECT a.ownerID, a.friendID, a.friendPerms, b.friendPerms AS ownerperms 
                                        FROM {0} as a, {0} as b
                                        WHERE a.ownerID = @ownerID 
                                        AND b.ownerID = a.friendID 
                                        AND b.friendID = a.ownerID", m_userFriendsTableName);
            using (AutoClosingSqlCommand command = database.Query(sql))
            {
                command.Parameters.Add(database.CreateParameter("@ownerID", friendlistowner));
                try
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            FriendListItem fli = new FriendListItem();
                            fli.FriendListOwner = new UUID((Guid)reader["ownerID"]);
                            fli.Friend = new UUID((Guid)reader["friendID"]);
                            fli.FriendPerms = (uint)Convert.ToInt32(reader["friendPerms"]);

                            // This is not a real column in the database table, it's a joined column from the opposite record
                            fli.FriendListOwnerPerms = (uint)Convert.ToInt32(reader["ownerperms"]);
                            friendList.Add(fli);
                        }
                    }
                }
                catch (Exception e)
                {
                    m_log.ErrorFormat("[USER DB] Error updating userfriend, error: {0}", e.Message);
                }
            }
            return friendList;
        }
Esempio n. 5
0
        protected List<FriendListItem> ConvertXMLRPCDataToFriendListItemList(Hashtable data)
        {
            List<FriendListItem> buddylist = new List<FriendListItem>();
            int buddycount = Convert.ToInt32((string)data["avcount"]);


            for (int i = 0; i < buddycount; i++)
            {
                FriendListItem buddylistitem = new FriendListItem();

                buddylistitem.FriendListOwner = new UUID((string)data["ownerID" + i.ToString()]);
                buddylistitem.Friend = new UUID((string)data["friendID" + i.ToString()]);
                buddylistitem.FriendListOwnerPerms = (uint)Convert.ToInt32((string)data["ownerPerms" + i.ToString()]);
                buddylistitem.FriendPerms = (uint)Convert.ToInt32((string)data["friendPerms" + i.ToString()]);

                buddylist.Add(buddylistitem);
            }

            return buddylist;
        }        
Esempio n. 6
0
        public override List<FriendListItem> GetUserFriendList(UUID friendlistowner)
        {
            List<FriendListItem> Lfli = new List<FriendListItem>();

            Dictionary<string, object> param = new Dictionary<string, object>();
            param["?ownerID"] = friendlistowner.ToString();

            try
            {
                using (ISimpleDB conn = _connFactory.GetConnection())
                {
                    string query = "select a.ownerID,a.friendID,a.friendPerms,b.friendPerms as ownerperms from " +
                            m_userFriendsTableName + " as a, " + m_userFriendsTableName + " as b" +
                            " where a.ownerID = ?ownerID and b.ownerID = a.friendID and b.friendID = a.ownerID";

                    using (IDataReader reader = conn.QueryAndUseReader(query, param))
                    {
                        while (reader.Read())
                        {
                            FriendListItem fli = new FriendListItem();
                            fli.FriendListOwner = new UUID(Convert.ToString(reader["ownerID"]));
                            fli.Friend = new UUID(Convert.ToString(reader["friendID"]));
                            fli.FriendPerms = (uint)Convert.ToInt32(reader["friendPerms"]);

                            // This is not a real column in the database table, it's a joined column from the opposite record
                            fli.FriendListOwnerPerms = (uint)Convert.ToInt32(reader["ownerperms"]);

                            Lfli.Add(fli);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                m_log.Error(e.ToString());
                return Lfli;
            }

            return Lfli;
        }
Esempio n. 7
0
        public override List<FriendListItem> GetUserFriendList(UUID friendlistowner)
        {
            List<FriendListItem> Lfli = new List<FriendListItem>();

            Dictionary<string, object> param = new Dictionary<string, object>();
            param["?ownerID"] = friendlistowner.ToString();

            MySQLSuperManager dbm = GetLockedConnection("GetUserFriendList");

            try
            {
                //Left Join userfriends to itself
                using (IDbCommand result = dbm.Manager.Query(
                    "select a.ownerID,a.friendID,a.friendPerms,b.friendPerms as ownerperms from " +
                    m_userFriendsTableName + " as a, " + m_userFriendsTableName + " as b" +
                    " where a.ownerID = ?ownerID and b.ownerID = a.friendID and b.friendID = a.ownerID",
                    param))
                {
                    using (IDataReader reader = result.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            FriendListItem fli = new FriendListItem();
                            fli.FriendListOwner = new UUID((string)reader["ownerID"]);
                            fli.Friend = new UUID((string)reader["friendID"]);
                            fli.FriendPerms = (uint)Convert.ToInt32(reader["friendPerms"]);

                            // This is not a real column in the database table, it's a joined column from the opposite record
                            fli.FriendListOwnerPerms = (uint)Convert.ToInt32(reader["ownerperms"]);

                            Lfli.Add(fli);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                dbm.Manager.Reconnect();
                m_log.Error(e.Message, e);
                return Lfli;
            }
            finally
            {
                dbm.Release();
            }

            return Lfli;
        }
Esempio n. 8
0
        /// <summary>
        /// Converts XMLRPC Friend List to FriendListItem Object
        /// </summary>
        /// <param name="data">XMLRPC response data Hashtable</param>
        /// <returns></returns>
        public Dictionary<UUID, FriendListItem> ConvertXMLRPCDataToFriendListItemList(Hashtable data)
        {
            Dictionary<UUID, FriendListItem> buddies = new Dictionary<UUID,FriendListItem>();
            int buddycount = Convert.ToInt32((string)data["avcount"]);

            for (int i = 0; i < buddycount; i++)
            {
                FriendListItem buddylistitem = new FriendListItem();

                buddylistitem.FriendListOwner = new UUID((string)data["ownerID" + i.ToString()]);
                buddylistitem.Friend = new UUID((string)data["friendID" + i.ToString()]);
                buddylistitem.FriendListOwnerPerms = (uint)Convert.ToInt32((string)data["ownerPerms" + i.ToString()]);
                buddylistitem.FriendPerms = (uint)Convert.ToInt32((string)data["friendPerms" + i.ToString()]);

                buddies.Add(buddylistitem.Friend, buddylistitem);
            }

            return buddies;
        }
Esempio n. 9
0
        /// <summary>
        /// Does the necessary work to subscribe one agent to another's presence notifications
        /// Gets called by ProcessFriendListSubscriptions.  You shouldn't call this directly
        /// unless you know what you're doing
        /// </summary>
        /// <param name="userpresence">P1</param>
        /// <param name="friendpresence">P2</param>
        /// <param name="uFriendListItem"></param>
        private void SubscribeToPresenceUpdates(UserPresenceData userpresence,
                                               UserPresenceData friendpresence,
                                               FriendListItem uFriendListItem)
        {
            // Can the friend see me online?
            if ((uFriendListItem.FriendListOwnerPerms & (uint)FriendRights.CanSeeOnline) != 0)
            {
                // tell user to update friend about user's presence changes
                if (!userpresence.subscriptionData.Contains(friendpresence.agentData.AgentID))
                {
                   userpresence.subscriptionData.Add(friendpresence.agentData.AgentID);
                }

                // send an update about user's presence to the friend
                enqueuePresenceUpdate(userpresence, friendpresence);
            }

            // Can I see the friend online?
            if ((uFriendListItem.FriendPerms & (uint)FriendRights.CanSeeOnline) != 0)
            {
                // tell friend to update user about friend's presence changes
                if (!friendpresence.subscriptionData.Contains(userpresence.agentData.AgentID))
                {
                    friendpresence.subscriptionData.Add(userpresence.agentData.AgentID);
                }

                // send an update about friend's presence to user.
                enqueuePresenceUpdate(friendpresence, userpresence);
            }
        }