This class manages the user information.
only used with channel sync IrcClient.ActiveChannelSyncing
Exemplo n.º 1
0
        protected override void OnMessage(Channel channel, IrcUser from, string message)
        {
            //Due to Twitch architecture, a user can send a message before a JOIN.
            if (!_userDatabase.ContainsUser(from.Nick))
                OnJoin(channel, from.Nick);

            SendLastVisited(from.Nick);
            _statistics.UpdateOnMessage(from.Nick, message);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Event handler for join messages
        /// </summary>
        /// <param name="ircdata">Message data containing join information</param>
        private void _Event_JOIN(IrcMessageData ircdata)
        {
            string who = ircdata.Nick;
            string channelname = ircdata.Channel;

            if (IsMe(who)) {
                _JoinedChannels.Add(channelname);
            }

            if (ActiveChannelSyncing) {
                Channel channel;
                if (IsMe(who)) {
                    // we joined the channel
            #if LOG4NET
                    Logger.ChannelSyncing.Debug("joining channel: "+channelname);
            #endif
                    if (SupportNonRfc) {
                        channel = new NonRfcChannel(channelname);
                    } else {
                        channel = new Channel(channelname);
                    }
                    _Channels.Add(channelname, channel);
                    // request channel mode
                    RfcMode(channelname);
                    // request wholist
                    RfcWho(channelname);
                    // request banlist
                    Ban(channelname);
                } else {
                    // someone else joined the channel
                    // request the who data
                    RfcWho(who);
                }

            #if LOG4NET
                Logger.ChannelSyncing.Debug(who+" joins channel: "+channelname);
            #endif
                channel = GetChannel(channelname);
                IrcUser ircuser = GetIrcUser(who);

                if (ircuser == null) {
                    ircuser = new IrcUser(who, this);
                    ircuser.Ident = ircdata.Ident;
                    ircuser.Host  = ircdata.Host;
                    _IrcUsers.Add(who, ircuser);
                }

                ChannelUser channeluser;
                if (SupportNonRfc) {
                    channeluser = new NonRfcChannelUser(channelname, ircuser);
                } else {
                    channeluser = new ChannelUser(channelname, ircuser);
                }
                channel.UnsafeUsers.Add(who, channeluser);
            }

            if (OnJoin != null) {
                OnJoin(this, new JoinEventArgs(ircdata, channelname, who));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Event handler for name reply messages
        /// </summary>
        /// <param name="ircdata">Message data containing name reply information</param>
        private void _Event_RPL_NAMREPLY(IrcMessageData ircdata)
        {
            string   channelname  = ircdata.Channel;
            string[] userlist     = ircdata.MessageArray;
            if (ActiveChannelSyncing &&
                IsJoined(channelname)) {
                string nickname;
                bool   op;
                bool   halfop;
                bool   voice;
                foreach (string user in userlist) {
                    if (user.Length <= 0) {
                        continue;
                    }

                    op = false;
                    halfop = false;
                    voice = false;
                    switch (user[0]) {
                        case '@':
                            op = true;
                            nickname = user.Substring(1);
                        break;
                        case '+':
                            voice = true;
                            nickname = user.Substring(1);
                        break;
                        // RFC VIOLATION
                        // some IRC network do this and break our channel sync...
                        case '&':
                            nickname = user.Substring(1);
                        break;
                        case '%':
                            halfop = true;
                            nickname = user.Substring(1);
                        break;
                        case '~':
                            nickname = user.Substring(1);
                        break;
                        default:
                            nickname = user;
                        break;
                    }

                    IrcUser     ircuser     = GetIrcUser(nickname);
                    ChannelUser channeluser = GetChannelUser(channelname, nickname);

                    if (ircuser == null) {
            #if LOG4NET
                        Logger.ChannelSyncing.Debug("creating IrcUser: "******" because he doesn't exist yet");
            #endif
                        ircuser = new IrcUser(nickname, this);
                        _IrcUsers.Add(nickname, ircuser);
                    }

                    if (channeluser == null) {
            #if LOG4NET
                        Logger.ChannelSyncing.Debug("creating ChannelUser: "******" for Channel: "+channelname+" because he doesn't exist yet");
            #endif
                        if (SupportNonRfc) {
                            channeluser = new NonRfcChannelUser(channelname, ircuser);
                        } else {
                            channeluser = new ChannelUser(channelname, ircuser);
                        }
                        Channel channel = GetChannel(channelname);

                        channel.UnsafeUsers.Add(nickname, channeluser);
                        if (op) {
                            channel.UnsafeOps.Add(nickname, channeluser);
            #if LOG4NET
                            Logger.ChannelSyncing.Debug("added op: "+nickname+" to: "+channelname);
            #endif
                        }
                        if (SupportNonRfc && halfop)  {
                            ((NonRfcChannel)channel).UnsafeHalfops.Add(nickname, channeluser);
            #if LOG4NET
                            Logger.ChannelSyncing.Debug("added halfop: "+nickname+" to: "+channelname);
            #endif
                        }
                        if (voice) {
                            channel.UnsafeVoices.Add(nickname, channeluser);
            #if LOG4NET
                            Logger.ChannelSyncing.Debug("added voice: "+nickname+" to: "+channelname);
            #endif
                        }
                    }

                    channeluser.IsOp    = op;
                    channeluser.IsVoice = voice;
                    if (SupportNonRfc) {
                        ((NonRfcChannelUser)channeluser).IsHalfop = halfop;
                    }
                }
            }

            if (OnNames != null) {
                OnNames(this, new NamesEventArgs(ircdata, channelname, userlist));
            }
        }
Exemplo n.º 4
0
 protected virtual ChannelUser CreateChannelUser(string channel, IrcUser ircUser)
 {
     if (_SupportNonRfc) {
         return new NonRfcChannelUser(channel, ircUser);
     } else {
         return new ChannelUser(channel, ircUser);
     }
 }
Exemplo n.º 5
0
        private void _Event_RPL_NAMREPLY(IrcMessageData ircdata)
        {
            string   channelname  = ircdata.Channel;
            string[] userlist     = ircdata.MessageArray;
            // HACK: BIP skips the colon after the channel name even though
            // RFC 1459 and 2812 says it's mandantory in RPL_NAMREPLY
            if (userlist == null) {
                if (ircdata.RawMessageArray.Length > 5) {
                    userlist = new string[] { ircdata.RawMessageArray[5] };
                } else {
                    userlist = new string[] {};
                }
            }

            if (ActiveChannelSyncing &&
                IsJoined(channelname)) {
                string nickname;
                bool   owner;
                bool   chanadmin;
                bool   op;
                bool   halfop;
                bool   voice;
                foreach (string user in userlist) {
                    if (user.Length <= 0) {
                        continue;
                    }

                    owner = false;
                    chanadmin = false;
                    op = false;
                    halfop = false;
                    voice = false;

                    nickname = user;

                    char mode;

                    foreach (var kvp in _ServerProperties.ChannelPrivilegeModesPrefixes) {
                        if (nickname[0] == kvp.Value) {
                            nickname = nickname.Substring(1);

                            switch(kvp.Key) {
                                case 'q':
                                    owner = true;
                                    break;
                                case 'a':
                                    chanadmin = true;
                                    break;
                                case 'o':
                                    op = true;
                                    break;
                                case 'h':
                                    halfop = true;
                                    break;
                                case 'v':
                                    voice = true;
                                    break;
                            }
                        }
                    }

                    IrcUser     ircuser     = GetIrcUser(nickname);
                    ChannelUser channeluser = GetChannelUser(channelname, nickname);

                    if (ircuser == null) {
            #if LOG4NET
                        Logger.ChannelSyncing.Debug("creating IrcUser: "******" because he doesn't exist yet");
            #endif
                        ircuser = new IrcUser(nickname, this);
                        _IrcUsers.Add(nickname, ircuser);
                    }

                    if (channeluser == null) {
            #if LOG4NET
                        Logger.ChannelSyncing.Debug("creating ChannelUser: "******" for Channel: "+channelname+" because he doesn't exist yet");
            #endif

                        channeluser = CreateChannelUser(channelname, ircuser);
                        Channel channel = GetChannel(channelname);

                        channel.UnsafeUsers.Add(nickname, channeluser);
                        if (SupportNonRfc && owner) {
                            ((NonRfcChannel)channel).UnsafeOwners.Add(nickname, channeluser);
            #if LOG4NET
                            Logger.ChannelSyncing.Debug("added owner: "+nickname+" to: "+channelname);
            #endif
                        }
                        if (SupportNonRfc && chanadmin) {
                            ((NonRfcChannel)channel).UnsafeChannelAdmins.Add(nickname, channeluser);
            #if LOG4NET
                            Logger.ChannelSyncing.Debug("added channel admin: "+nickname+" to: "+channelname);
            #endif
                        }
                        if (op) {
                            channel.UnsafeOps.Add(nickname, channeluser);
            #if LOG4NET
                            Logger.ChannelSyncing.Debug("added op: "+nickname+" to: "+channelname);
            #endif
                        }
                        if (SupportNonRfc && halfop)  {
                            ((NonRfcChannel)channel).UnsafeHalfops.Add(nickname, channeluser);
            #if LOG4NET
                            Logger.ChannelSyncing.Debug("added halfop: "+nickname+" to: "+channelname);
            #endif
                        }
                        if (voice) {
                            channel.UnsafeVoices.Add(nickname, channeluser);
            #if LOG4NET
                            Logger.ChannelSyncing.Debug("added voice: "+nickname+" to: "+channelname);
            #endif
                        }
                    }

                    channeluser.IsOp    = op;
                    channeluser.IsVoice = voice;
                    if (SupportNonRfc) {
                        var nchanneluser = (NonRfcChannelUser)channeluser;
                        nchanneluser.IsOwner = owner;
                        nchanneluser.IsChannelAdmin = chanadmin;
                        nchanneluser.IsHalfop = halfop;
                    }
                }
            }

            var filteredUserlist = new List<string>(userlist.Length);
            // filter user modes from nicknames
            foreach (string user in userlist) {
                if (String.IsNullOrEmpty(user)) {
                    continue;
                }

                string temp = user;
                foreach (var kvp in _ServerProperties.ChannelPrivilegeModesPrefixes) {
                    if (temp[0] == kvp.Value) {
                        temp = temp.Substring(1);
                    }
                }
                filteredUserlist.Add(temp);

            }

            if (OnNames != null) {
                OnNames(this, new NamesEventArgs(ircdata, channelname,
                                                 filteredUserlist.ToArray(), userlist));
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Event handler for join messages
        /// </summary>
        /// <param name="ircdata">Message data containing join information</param>
        private void _Event_JOIN(IrcMessageData ircdata)
        {
            string who = ircdata.Nick;
            string channelname = ircdata.Channel;

            if (IsMe(who)) {
                _JoinedChannels.Add(channelname);
            }

            if (ActiveChannelSyncing) {
                Channel channel;
                if (IsMe(who)) {
                    // we joined the channel
            #if LOG4NET
                    Logger.ChannelSyncing.Debug("joining channel: "+channelname);
            #endif
                    channel = CreateChannel(channelname);
                    _Channels.Add(channelname, channel);
                    // request channel mode
                    RfcMode(channelname);
                    // request wholist
                    RfcWho(channelname);
                    // request ban exception list
                    if (_ServerProperties.BanExceptionCharacter.HasValue) {
                        BanException(channelname);
                    }
                    // request invite exception list
                    if (_ServerProperties.InviteExceptionCharacter.HasValue) {
                        InviteException(channelname);
                    }
                    // request banlist
                    Ban(channelname);
                } else {
                    // someone else joined the channel
                    // request the who data
                    RfcWho(who);
                }

            #if LOG4NET
                Logger.ChannelSyncing.Debug(who+" joins channel: "+channelname);
            #endif
                channel = GetChannel(channelname);
                IrcUser ircuser = GetIrcUser(who);

                if (ircuser == null) {
                    ircuser = new IrcUser(who, this);
                    ircuser.Ident = ircdata.Ident;
                    ircuser.Host  = ircdata.Host;
                    _IrcUsers.Add(who, ircuser);
                }

                // HACK: IRCnet's anonymous channel mode feature breaks our
                // channnel sync here as they use the same nick for ALL channel
                // users!
                // Example: :anonymous!anonymous@anonymous. JOIN :$channel
                if (who == "anonymous" &&
                    ircdata.Ident == "anonymous" &&
                    ircdata.Host == "anonymous." &&
                    IsJoined(channelname, who)) {
                    // ignore
                } else {
                    ChannelUser channeluser = CreateChannelUser(channelname, ircuser);
                    channel.UnsafeUsers[who] = channeluser;
                }
            }

            if (OnJoin != null) {
                OnJoin(this, new JoinEventArgs(ircdata, channelname, who));
            }
        }
Exemplo n.º 7
0
 protected override void OnAction(Channel channel, IrcUser from, string message)
 {
     //Treat the same as messages.
     OnMessage(channel, from, message);
 }
Exemplo n.º 8
0
 public static bool CompareIrcUser(IrcUser user1, IrcUser user2)
 {
     return (user1.Host == user2.Host && user1.Ident == user2.Ident && user1.Realname == user2.Realname);
 }
Exemplo n.º 9
0
        private void _Event_RPL_NAMREPLY(IrcMessageData ircdata)
        {
            string   channelname  = ircdata.Channel;
            string[] userlist     = ircdata.MessageArray;
            // HACK: BIP skips the colon after the channel name even though
            // RFC 1459 and 2812 says it's mandantory in RPL_NAMREPLY
            if (userlist == null) {
                if (ircdata.RawMessageArray.Length > 5) {
                    userlist = new string[] { ircdata.RawMessageArray[5] };
                } else {
                    userlist = new string[] {};
                }
            }

            if (ActiveChannelSyncing &&
                IsJoined(channelname)) {
                string nickname;
                bool   op;
                bool   halfop;
                bool   voice;
                foreach (string user in userlist) {
                    if (user.Length <= 0) {
                        continue;
                    }

                    op = false;
                    halfop = false;
                    voice = false;
                    switch (user[0]) {
                        case '@':
                            op = true;
                            nickname = user.Substring(1);
                        break;
                        case '+':
                            voice = true;
                            nickname = user.Substring(1);
                        break;
                        // RFC VIOLATION
                        // some IRC network do this and break our channel sync...
                        case '&':
                            nickname = user.Substring(1);
                        break;
                        case '%':
                            halfop = true;
                            nickname = user.Substring(1);
                        break;
                        case '~':
                            nickname = user.Substring(1);
                        break;
                        default:
                            nickname = user;
                        break;
                    }

                    IrcUser     ircuser     = GetIrcUser(nickname);
                    ChannelUser channeluser = GetChannelUser(channelname, nickname);

                    if (ircuser == null) {
            #if LOG4NET
                        Logger.ChannelSyncing.Debug("creating IrcUser: "******" because he doesn't exist yet");
            #endif
                        ircuser = new IrcUser(nickname, this);
                        _IrcUsers.Add(nickname, ircuser);
                    }

                    if (channeluser == null) {
            #if LOG4NET
                        Logger.ChannelSyncing.Debug("creating ChannelUser: "******" for Channel: "+channelname+" because he doesn't exist yet");
            #endif

                        channeluser = CreateChannelUser(channelname, ircuser);
                        Channel channel = GetChannel(channelname);

                        channel.UnsafeUsers.Add(nickname, channeluser);
                        if (op) {
                            channel.UnsafeOps.Add(nickname, channeluser);
            #if LOG4NET
                            Logger.ChannelSyncing.Debug("added op: "+nickname+" to: "+channelname);
            #endif
                        }
                        if (SupportNonRfc && halfop)  {
                            ((NonRfcChannel)channel).UnsafeHalfops.Add(nickname, channeluser);
            #if LOG4NET
                            Logger.ChannelSyncing.Debug("added halfop: "+nickname+" to: "+channelname);
            #endif
                        }
                        if (voice) {
                            channel.UnsafeVoices.Add(nickname, channeluser);
            #if LOG4NET
                            Logger.ChannelSyncing.Debug("added voice: "+nickname+" to: "+channelname);
            #endif
                        }
                    }

                    channeluser.IsOp    = op;
                    channeluser.IsVoice = voice;
                    if (SupportNonRfc) {
                        ((NonRfcChannelUser)channeluser).IsHalfop = halfop;
                    }
                }
            }

            var filteredUserlist = new List<string>(userlist.Length);
            // filter user modes from nicknames
            foreach (string user in userlist) {
                if (String.IsNullOrEmpty(user)) {
                    continue;
                }

                switch (user[0]) {
                    case '@':
                    case '+':
                    case '&':
                    case '%':
                    case '~':
                        filteredUserlist.Add(user.Substring(1));
                        break;
                    default:
                        filteredUserlist.Add(user);
                        break;
                }
            }

            if (OnNames != null) {
                OnNames(this, new NamesEventArgs(ircdata, channelname,
                                                 filteredUserlist.ToArray()));
            }
        }