Example #1
0
        /// <summary>
        /// Removes a user from the server
        /// </summary>
        /// <param name="user"></param>
        /// <returns>TRUE if the user is succesfully removed</returns>
        public bool RemoveUser(IUser user)
        {
            lock (lockObject)
            {
                if (!users.Remove(user.Numeric))
                {
                    return false;
                }

                foreach (var pair in ChannelEntries.ToArray())
                {
                    if (user.IsOnChannel(pair.Key.Name))
                    {
                        var list = pair.Value as List<ChannelEntry>;
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (list[i].User == user)
                            {
                                (user as User).OnRemoveFromChannel(pair.Key);
                                list.RemoveAt(i);
                                break;
                            }
                        }

                        (pair.Key as Channel).RemoveInvitation(user);

                        if (list.Count < 1)
                        {
                            ChannelEntries.Remove(pair.Key);
                            channels.Remove(pair.Key.Name);
                        }
                    }
                }
                
                return true;
            }
        }
Example #2
0
        /// <summary>
        /// Invites a user to a channel
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool InviteUserToChannel(string channel, IUser user)
        {
            if (channel.Length < 2 || channel[0] != '#')
            {
                throw new InvalidChannelException();
            }
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            ChannelEntry currentEntry = User.GetChannelEntry(channel);
            if (currentEntry == null)
            {
                throw new NotOnChannelException();
            }
            if ((currentEntry.Op == false) && (currentEntry.HalfOp == false))
            {
                throw new NotAChannelOperatorException();
            }
            if (user.IsOnChannel(channel))
            {
                throw new UserAlreadyOnChannelException();
            }

            var command =
                Plugin.Service.CommandFactory.CreateInviteUserCommand();
            command.From = User;
            command.User = user;
            command.Channel = currentEntry.Channel;
            Plugin.Service.SendCommand(command);
            return true;
        }        
Example #3
0
        /// <summary>
        /// Adds a user to the channel
        /// </summary>
        /// <param name="user"></param>
        /// <param name="op"></param>
        /// <param name="voice"></param>
        /// <param name="halfop"></param>
        /// <returns>TRUE if the user is successfully added</returns>
        public bool AddUser(IUser user, bool op, bool voice, bool halfop)
        {
            lock (lockObject)
            {
                if (user.IsOnChannel(Name))
                {
                    return false;
                }
                ChannelEntry entry = new ChannelEntry(this, user);
                entry.Op = op;
                entry.Voice = voice;
                entry.HalfOp = halfop;

                var list = user.Server.ChannelEntries[this] as List<ChannelEntry>;
                list.Add(entry);
                (user as User).OnAddToChannel(entry);

                if (Service.BurstCompleted)
                {
                    RemoveInvitation(user);
                }
                return true;
            }
        }