Beispiel #1
0
        /// <summary>
        /// Default WhoHandler. Simply makes sure all the users on the channel have
        /// valid masks and are known about.
        /// </summary>
        /// <param name="serverid">The server id.</param>
        /// <param name="c">The channel queried.</param>
        /// <param name="user">The user parsed.</param>
        /// <returns>The commands to execute.</returns>
        /*public static string[] WhoHandler(int serverid, Channel c, IRCHost user) {

            Server s = Server.GetServer( serverid );

            User u = null;

            try {
                u = s.UserDatabase[user.Nick];
            }
            catch ( KeyNotFoundException ) {
                u = new User( user );
                s.UserDatabase.AddUser( u );
                s.UserDatabase.Authenticate( u );
            }

            ChannelUser cu = null;
            try {
                cu = c[user.Nick];
                cu.InternalUser = u;
            }
            catch ( KeyNotFoundException ) {
                //THIS SHOULD NEVER HAPPEN DO NOTHING.
            }

            return null;
        }*/
        /// <summary>
        /// Default AuthModeHandler function.
        /// </summary>
        /// <param name="sid">The serverid of the event.</param>
        /// <param name="nick">The nickname of the user the message was sent to.</param>
        /// <param name="userhost">The userhost of the user the message was sent from.</param>
        /// <param name="text">The text the user wrote.</param>
        public static string[] AuthModeHandler(int sid, string nick, User userhost, string text)
        {
            Server s = Server.GetServer( sid );

            if ( s.IsInAuthMode && s.CurrentNickName == nick ) {

                Project2Q.SDK.UserSystem.RegisteredUser ru = new Project2Q.SDK.UserSystem.RegisteredUser();
                ru.HostList.Add( new Project2Q.SDK.UserSystem.IRCHost( userhost.CurrentHost.FullHost ) );
                ru.Privegeles.SetPriveleges( Project2Q.SDK.UserSystem.Priveleges.SuperUser );
                ru.Privegeles.NumericalLevel = 1000;
                s.UserDatabase.AddRegisteredUser( ru );
                s.UserDatabase.Authenticate( userhost );
                s.ExitAuthMode();
            }

            return null;
        }
Beispiel #2
0
 /// <summary>
 /// Creates a User associated with a Registered User.
 /// </summary>
 /// <param name="current">The current hostname of this user.</param>
 /// <param name="ru">The associated registered user.</param>
 public User(IRCHost current, RegisteredUser ru)
 {
     this.ru = ru;
     currentHost = current;
 }
Beispiel #3
0
        /// <summary>
        /// Adds a user to the database.
        /// </summary>
        /// <param name="splits">The raw data to parse.</param>
        public void AddUser( string[] splits )
        {
            string text = channelMessageData.text;
            string user = channelMessageData.channelUser.InternalUser.Nickname;
            string channel = channelMessageData.channel.Name;

            //Parse format:
            //*adduser (nickname) [privlist] [numericallevel]
            //  [0]        [1]       [2]           [3]

            if ( splits.Length < 3 || splits.Length > 4 ) {
                BoldNickNotice( user, "Error(Malformed command):",
                " Arguments expected: 2-3, arguments given " + ( splits.Length - 1 ).ToString() + "." );
                return;
            }

            LinkedList<string> ll = new LinkedList<string>();
            StringBuilder errprivs = new StringBuilder();
            StringBuilder neaprivs = new StringBuilder();

            uint numlevel = 0;
            ulong addprivs = 0;
            bool privthur = false, numthur = false;
            int chn;

            User u = null;
            UserCollection uc = (UserCollection)mp.RequestVariable( Request.UserCollection, channelMessageData.sid );

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

            if ( u.UserAttributes != null ) {
                BoldNickNotice( user, "Error(Invalid User):",
                " User " + splits[1] + " already authenticated. (Did you mean " + Configuration.ModuleConfig.ModulePrefix + "chusr?)" );
                return;
            }

            //first arg - mandatory
            try {
                numlevel = uint.Parse( splits[2] );
                if ( !channelMessageData.channelUser.InternalUser.UserAttributes.Privegeles.HasPrivelege( Priveleges.SuperUser ) &&
                    numlevel >= channelMessageData.channelUser.InternalUser.UserAttributes.Privegeles.NumericalLevel ) {
                    ll.AddLast( BoldNickNoticeHelper( user, "Error(Invalid Numerical Level):",
                        " The numerical level: " + splits[2] + " is greater or equal to your own." ) );
                }
                else
                    numthur = true;
            }
            catch ( FormatException ) {
                foreach ( char c in splits[2] ) {
                    chn = (int)c;
                    if ( ( chn > (int)'A' && chn < (int)'z' ) && ( chn > (int)'a' || chn < (int)'Z' ) ) {
                        ulong modemask = PrivelegeContainer.GetModeMask( c );
                        if ( !channelMessageData.channelUser.InternalUser.UserAttributes.Privegeles.HasPrivelege( Priveleges.SuperUser ) &&
                            !channelMessageData.channelUser.InternalUser.UserAttributes.Privegeles.HasPrivelege( modemask ) ) {
                            neaprivs.Append( c );
                        }
                        else {
                            privthur = true;
                            addprivs |= modemask;
                        }
                    }
                    else
                        errprivs.Append( c );
                }
            }

            //second arg - optional, check for length
            if ( splits.Length > 3 )
                //If the priveleges is already there. We can only look for a numerical userlevel.
                if ( privthur )
                    try {
                        numlevel = uint.Parse( splits[3] );
                        if ( numlevel >= channelMessageData.channelUser.InternalUser.UserAttributes.Privegeles.NumericalLevel &&
                            !channelMessageData.channelUser.InternalUser.UserAttributes.Privegeles.HasPrivelege( Priveleges.SuperUser ) ) {
                            ll.AddLast( BoldNickNoticeHelper( user, "Error(Invalid Numerical Level):",
                                " The numerical level: " + splits[3] + " is greater or equal to your own." ) );
                        }
                        else
                            numthur = true;
                    }
                    catch ( FormatException ) {
                        ll.AddLast( BoldNickNoticeHelper( user, "Error(Invalid Argument):",
                            " The argument: " + splits[3] + " is not a valid numerical user level." ) );
                    }
                //If the priveleges aren't there, we can only look for a privelege set.
                else {
                    foreach ( char c in splits[3] ) {
                        chn = (int)c;
                        if ( ( chn > (int)'A' && chn < (int)'z' ) && ( chn > (int)'a' || chn < (int)'Z' ) ) {
                            ulong modemask = PrivelegeContainer.GetModeMask( c );
                            if ( !channelMessageData.channelUser.InternalUser.UserAttributes.Privegeles.HasPrivelege( Priveleges.SuperUser ) &&
                                !channelMessageData.channelUser.InternalUser.UserAttributes.Privegeles.HasPrivelege( modemask ) ) {
                                neaprivs.Append( c );
                            }
                            else {
                                privthur = true;
                                addprivs |= modemask;
                            }
                        }
                        else
                            errprivs.Append( c );
                    }
                }

            if ( errprivs.Length != 0 ) {
                ll.AddLast( BoldNickNoticeHelper( user, "Error(Invalid Argument):",
                    " The arguments: " + errprivs.ToString() + " are not valid mode characters." ) );
            }
            if ( neaprivs.Length != 0 ) {
                ll.AddLast( BoldNickNoticeHelper( user, "Error(Invalid Argument):",
                    " You must have the following modes: " + neaprivs.ToString() + " to give those modes to others." ) );
            }

            RegisteredUser ru = new RegisteredUser();
            ru.AddHost( u.CurrentHost );

            uc.AddRegisteredUser( ru );
            u.UserAttributes = ru;

            if ( privthur ) {
                u.UserAttributes.Privegeles.AddPriveleges( addprivs );
            }
            if ( numthur ) {
                u.UserAttributes.Privegeles.NumericalLevel = numlevel;
            }

            if ( privthur || numthur ) {
                StringBuilder sb = new StringBuilder();
                sb.Append( " [" );
                if ( privthur ) {
                    sb.Append( u.UserAttributes.Privegeles.PrivelegeString );
                    if ( numthur )
                        sb.Append( ":" + u.UserAttributes.Privegeles.NumericalLevel );
                }
                else if ( numthur )
                    sb.Append( u.UserAttributes.Privegeles.NumericalLevel );
                sb.Append( "]" );

                ll.AddLast( BoldNickNoticeHelper( user, "User Added: ", u.Nickname + sb.ToString() ) );
            }

            if ( ll.Count != 0 ) {
                returns = new string[ll.Count];
                ll.CopyTo( returns, 0 );
            }
        }
Beispiel #4
0
 /// <summary>
 /// Creates a User.
 /// </summary>
 /// <param name="current">The current hostname of this user.</param>
 public User(IRCHost current)
 {
     ru = null;
     currentHost = current;
 }