Exemple #1
0
        /// <summary>
        /// Adds a host to a user.
        /// </summary>
        /// <param name="repnick">The user that initiated the command.</param>
        /// <param name="host">The host to add.</param>
        /// <param name="user">The user to add the host to.</param>
        public void AddHost(string repnick, string host, string user)
        {
            User u = null;
            UserCollection uc = (UserCollection)mp.RequestVariable( Request.UserCollection, channelMessageData.sid );

            try {
                u = uc[user];
            }
            catch ( KeyNotFoundException ) {
                BoldNickNotice( repnick, "Error(Invalid User):", " User not in active user database." );
                return;
            }

            if ( u.UserAttributes == null ) {
                BoldNickNotice( repnick, "Error(Invalid User):", " User not in user database." );
                return;
            }

            IRCHost irch = null;
            try {
                irch = new IRCHost( host );
            }
            catch ( FormatException ) {
                BoldNickNotice( repnick, "Error(Invalid Host):", " The host must be in the form [nick]![username]@[host] where all fields can contain wildcard characters '?' and '*'." );
                return;
            }

            if ( uc.HasHost( irch ) ) {
                BoldNickNotice( repnick, "Error(Host Exists):", " The host specified already exists. Please use a wider subset of the host you require." );
                return;
            }

            if ( !u.UserAttributes.AddHost( irch ) ) {
                BoldNickNotice( repnick, "Error(Invalid Host):", " The host specified was rejected. Try a more specific subset of the host you require." );
                return;
            }

            BoldNickNotice( repnick, "Host Added:", " " + irch.ToString() + " to " + ( ( repnick.Equals( u.Nickname ) ) ? "your account." : u.Nickname ) );
        }
Exemple #2
0
        /// <summary>
        /// Removes a host from a user.
        /// </summary>
        /// <param name="repnick">The user that initiated the command.</param>
        /// <param name="host">The host to remove.</param>
        /// <param name="user">The user to remove the host from.</param>
        public void RemoveHost(string repnick, string host, string user)
        {
            User u = null;
            UserCollection uc = (UserCollection)mp.RequestVariable( Request.UserCollection, channelMessageData.sid );

            try {
                u = uc[user];
            }
            catch ( KeyNotFoundException ) {
                BoldNickNotice( repnick, "Error(Invalid User):", " User not in active user database." );
                return;
            }

            if ( u.UserAttributes == null ) {
                BoldNickNotice( repnick, "Error(Invalid User):", " User not in user database." );
                return;
            }

            if ( u.UserAttributes.HostList.Count <= 1 ) {
                BoldNickNotice( repnick, "Error(Invalid Operation):", " User will have no hosts remaining if you remove this one. (Try " + Configuration.ModuleConfig.ModulePrefix + "rmusr." );
                return;
            }

            IRCHost irch = null;
            try {
                irch = new IRCHost( host );
            }
            catch ( FormatException ) {
                BoldNickNotice( repnick, "Error(Invalid Host):", " The host must be in the form [nick]![username]@[host] where all fields can contain wildcard characters '?' and '*'." );
                return;
            }

            if ( !u.UserAttributes.RemoveHost( irch ) ) {
                BoldNickNotice( repnick, "Error(Host not Found):", " The host specified was not found on this user." );
                return;
            }

            BoldNickNotice( repnick, "Host Removed:", " " + irch.ToString() + " from " + ( ( repnick.Equals( u.Nickname ) ) ? "your account." : u.Nickname ) );
        }