Example #1
0
        /// <summary>Adds the <paramref name="target"/> user to <paramref name="listOwner"/>'s <paramref name="list"/> list, then sends out appropriate notifications if necessary.</summary>
        public AddListResult AddToList(User listOwner, String listName, User target, String customName)
        {
            lock (listOwner.Properties)
                lock (target.Properties) {
                    switch (listName)
                    {
                    case "FL":

                        // Add to the Forward List
                        // Add to the Reverse List of the target
                        // if the target is online send an async ADD notification to that user

                        // NOTE: adding to the Allow List is explicitly done by the client, there is no implicit AL add

                        listOwner.Properties.ForwardList.Add(target, customName);
                        listOwner.Properties.Serial++;

                        UserListEntry rlEntry =
                            target.Properties.ReverseList.Add(listOwner, listOwner.FriendlyName);
                        target.Properties.Serial++;

                        NotificationConnection targetC1 = GetConnectionForUser(target);
                        if (targetC1 != null && target.Status != Status.Fln)
                        {
                            targetC1.Protocol.ASNotifyAddRL(targetC1, rlEntry);
                        }

                        if (target.Status.AppearOnline() && target.Properties.GetResultantAS(listOwner) == AllowSetting.Allow)
                        {
                            // if listOwner is allowed to see target

                            NotificationConnection listOwnerC = GetConnectionForUser(listOwner);
                            listOwnerC.Protocol.ASNotifyIln(listOwnerC, target);
                        }

                        // TODO: If the added user is online, send ILN

                        return(AddListResult.Success);

                    case "AL":

                        // Check user isn't already on the BL, you can't be on both
                        // Then add to the AL
                        // If the target is online and has this user in their forward list, send ILN to the target

                        UserPermissionListEntry alEntry;
                        if (listOwner.Properties.PermissList.TryGetValue(target, out alEntry))
                        {
                            return(alEntry.Allowed == AllowSetting.Allow ? AddListResult.Success : AddListResult.MutexBL);
                        }
                        else
                        {
                            alEntry = new UserPermissionListEntry(target, customName, AllowSetting.Allow);

                            listOwner.Properties.PermissList.Add(target, alEntry);
                            listOwner.Properties.Serial++;

                            if (listOwner.Status.AppearOnline() && target.Properties.ForwardList.ContainsKey(listOwner))
                            {
                                NotificationConnection targetC2 = GetConnectionForUser(target);
                                if (targetC2 != null && target.Status != Status.Fln)
                                {
                                    targetC2.Protocol.ASNotifyNln(targetC2, listOwner);
                                }
                            }

                            return(AddListResult.Success);
                        }

                    case "BL":

                        // Same as AL, but with some tweaks for the different list

                        UserPermissionListEntry blEntry;
                        if (listOwner.Properties.PermissList.TryGetValue(target, out blEntry))
                        {
                            return(blEntry.Allowed == AllowSetting.Block ? AddListResult.Success : AddListResult.MutexAL);
                        }
                        else
                        {
                            blEntry = new UserPermissionListEntry(target, customName, AllowSetting.Block);

                            listOwner.Properties.PermissList.Add(target, blEntry);
                            listOwner.Properties.Serial++;

                            if (target.Properties.ForwardList.ContainsKey(listOwner))
                            {
                                NotificationConnection c2 = GetConnectionForUser(target);
                                if (listOwner.Status.AppearOnline() && c2 != null && target.Status != Status.Fln)
                                {
                                    c2.Protocol.ASNotifyFln(c2, listOwner);
                                }
                            }

                            return(AddListResult.Success);
                        }

                    case "RL":
                        return(AddListResult.CannotAddtoRL);

                    default:
                        return(AddListResult.UnknownList);
                    } //switch
                }     //lock
        }             //AddToList
Example #2
0
        private static void LoadUserProperties(SQLiteConnection c)
        {
            foreach (User user in AllUsers)
            {
                // get the user's ForwardList
                // get the user's ReverseList (since customNames are cached, dynamic regeneration isn't possible)
                // and the user's AllowList

                /////////////////////////////////////
                // ForwardList
                String        sql = "SELECT owner, target, customName FROM ForwardLists WHERE owner = ?";
                SQLiteCommand cmd = new SQLiteCommand(sql, c);
                cmd.Parameters.AddWithValue(null, user.UserHandle);

                using (SQLiteDataReader rdr = cmd.ExecuteReader()) {
                    while (rdr.Read())
                    {
                        User   target = GetUser(rdr.GetString(1));
                        String cusNom = rdr.IsDBNull(2) ? null : rdr.GetString(2);

                        user.Properties.ForwardList.Add(target, cusNom);
                    }
                }

                /////////////////////////////////////
                // ReverseList
                sql = "SELECT owner, target, customName FROM ReverseLists WHERE owner = ?";
                cmd = new SQLiteCommand(sql, c);
                cmd.Parameters.AddWithValue(null, user.UserHandle);

                using (SQLiteDataReader rdr = cmd.ExecuteReader()) {
                    while (rdr.Read())
                    {
                        User   target = GetUser(rdr.GetString(1));
                        String cusNom = rdr.IsDBNull(2) ? null : rdr.GetString(2);

                        user.Properties.ReverseList.Add(target, cusNom);
                    }
                }


                /////////////////////////////////////
                // AllowList
                sql = "SELECT owner, target, customName, isAllowed FROM AllowLists WHERE owner = ?";
                cmd = new SQLiteCommand(sql, c);
                cmd.Parameters.AddWithValue(null, user.UserHandle);

                using (SQLiteDataReader rdr = cmd.ExecuteReader()) {
                    while (rdr.Read())
                    {
                        User   target  = GetUser(rdr.GetString(1));
                        String cusName = rdr.GetString(2);
                        bool   allowed = rdr.GetBoolean(3);

                        UserPermissionListEntry entry = new UserPermissionListEntry(target, cusName, allowed ? AllowSetting.Allow : AllowSetting.Block);
                        user.Properties.PermissList.Add(target, entry);
                    }
                }
            }            //foreach

            // it might be an idea to do an integrity check on the ForwardList/ReverseLists to ensure they're all in-line
        }