Наследование: IComparable, ChatTarget
Пример #1
1
        public IrcClient(Encoding encoding)
        {
            Reset();
            m_Users = new Dictionary<string, IrcUser>(StringComparer.InvariantCultureIgnoreCase);
            m_unbanTimers = new Dictionary<string, UnbanTimer>();

            m_me = new IrcUser(this);
            m_client = new Client(this);
            m_CommandHandler = new IrcCommandHandler(this);
            m_dcc = new Dcc.Dcc(this);
            protHandler = new IrcProtocolHandler(this, encoding);
        }
Пример #2
0
        internal void AuthNotify(IrcUser user)
        {
            var evt = AuthResolved;

            if (evt != null)
            {
                evt(user);
            }
        }
Пример #3
0
        /// <returns>Wether the given user has at least the given privs (or has even more privs).</returns>
        public bool IsUserAtLeast(IrcUser user, Privilege priv)
        {
            UserPrivSet set;

            if (Privileges.TryGetValue(user, out set))
            {
                return(set.HasAtLeast(priv));
            }
            return(false);
        }
Пример #4
0
        public Privilege GetHighestPriv(IrcUser user)
        {
            UserPrivSet privs = GetPrivs(user);

            if (privs != null)
            {
                return(privs.Highest);
            }
            return(Privilege.Regular);
        }
Пример #5
0
        internal void NickNotify(IrcUser user, string newNick)
        {
            string oldNick = user.Nick;

            user.ChangeNick(newNick);
            if (user == Me)
            {
                m_nicks[0] = newNick;
            }
            OnNick(user, oldNick, newNick);
        }
Пример #6
0
 internal void CtcpRequestNotify(IrcUser user, IrcChannel chan, string request, string text)
 {
     if (request.ToUpper() == "DCC" && chan == null)
     {
         Dcc.Handle(user, text);
     }
     if (request.ToUpper() == "ACTION")
     {
         ActionNotify(user, chan, new StringStream(text));
     }
     OnCtcpRequest(user, chan, request, text);
 }
Пример #7
0
 internal void NoticeNotify(IrcUser user, IrcChannel chan, StringStream text)
 {
     if (chan != null)
     {
         chan.NoticeReceivedNotify(user, text);
     }
     OnNotice(user, chan, text);
     if (TriggersCommand(user, chan, text))
     {
         Task.Factory.StartNew(() => m_CommandHandler.Execute(new NoticeCmdTrigger(text, user, chan)));
     }
 }
Пример #8
0
 public virtual bool TriggersCommand(IrcUser user, IrcChannel chan, StringStream input)
 {
     return(CommandHandler.RemoteCommandPrefixes.Iterate(prefix =>
     {
         if (input.String.StartsWith(prefix, StringComparison.CurrentCultureIgnoreCase))
         {
             input.Skip(prefix.Length);
             return false;
         }
         return true;
     }));
 }
Пример #9
0
        public IrcClient(Encoding encoding)
        {
            Reset();
            m_Users       = new Dictionary <string, IrcUser>(StringComparer.InvariantCultureIgnoreCase);
            m_unbanTimers = new Dictionary <string, UnbanTimer>();

            m_me             = new IrcUser(this);
            m_client         = new Client(this);
            m_CommandHandler = new IrcCommandHandler(this);
            m_dcc            = new Dcc.Dcc(this);
            protHandler      = new IrcProtocolHandler(this, encoding);
        }
Пример #10
0
 public AutoVoiceUser(IrcUser user,IrcChannel channel)
 {
     User = user;
     Channel = channel;
     _voiceTimer.Elapsed += delegate
                               {
                                   if(!user.Modes.Contains("v"))
                                   user.IrcClient.CommandHandler.Mode(Channel, "+v", User);
                                   _voiceTimer.Stop();
                               };
     _voiceTimer.Start();
 }
Пример #11
0
        internal void AddUser(IrcUser user)
        {
            string nick = user.Nick;

            if (!Users.ContainsKey(nick))
            {
                Users.Add(nick, user);
            }
            if (!Privileges.ContainsKey(user))
            {
                Privileges.Add(user, new UserPrivSet());
            }
        }
Пример #12
0
        internal void TextNotify(IrcUser user, IrcChannel chan, StringStream text)
        {
            if (chan != null)
            {
                chan.TextNotify(user, text);
            }
            OnText(user, chan, text);

            if (TriggersCommand(user, chan, text))
            {
                m_CommandHandler.Execute(new MsgCmdTrigger(text, user, chan));
            }
        }
Пример #13
0
 internal void QuitNotify(IrcUser user, string reason)
 {
     foreach (var chan in user.Channels.Values)
     {
         chan.UserLeftNotify(user, reason);
     }
     OnQuit(user, reason);
     m_Users.Remove(user.Nick);
     if (user == Me)
     {
         m_client.Disconnect();
     }
 }
Пример #14
0
        internal void AddUser(IrcUser user, string flags)
        {
            string nick = user.Nick;

            if (!Users.ContainsKey(nick))
            {
                Users.Add(nick, user);
            }
            if (!Privileges.ContainsKey(user))
            {
                Privileges.Add(user, new UserPrivSet(flags));
            }
            else
            {
                Privileges[user].Set(flags);
            }
        }
Пример #15
0
 internal void NickNotify(IrcUser user, string newNick)
 {
     string oldNick = user.Nick;
     user.ChangeNick(newNick);
     if (user == Me)
     {
         m_nicks[0] = newNick;
     }
     OnNick(user, oldNick, newNick);
 }
Пример #16
0
 internal void InviteNotify(IrcUser user, string chan)
 {
     OnInvite(user, chan);
 }
Пример #17
0
 internal void KickNotify(IrcUser user, IrcChannel chan, IrcUser target, string reason)
 {
     OnKick(user, chan, target, reason);
     chan.UserKickedNotify(user, target, reason);
     target.DeleteChannel(chan.Name);
     CheckUserKnown(target);
 }
Пример #18
0
 internal void CtcpReplyNotify(IrcUser user, IrcChannel chan, string reply, string args)
 {
     OnCtcpReply(user, chan, reply, args);
 }
Пример #19
0
 internal void FlagDeletedNotify(IrcUser user, IrcChannel chan, Privilege priv, IrcUser target)
 {
     chan.FlagDeletedNotify(user, priv, target);
     OnFlagDeleted(user, chan, priv, target);
 }
Пример #20
0
 internal void QuitNotify(IrcUser user, string reason)
 {
     foreach (var chan in user.Channels.Values)
     {
         chan.UserLeftNotify(user, reason);
     }
     OnQuit(user, reason);
     m_Users.Remove(user.Nick);
     if (user == Me)
     {
         m_client.Disconnect();
     }
 }
Пример #21
0
 internal void UsersAddedNotify(IrcChannel chan, IrcUser[] users)
 {
     chan.UsersAddedNotify(users);
     OnUsersAdded(chan, users);
 }
Пример #22
0
 /// <summary>
 /// Fires when the Topic for a Channel has been sent. Either when joining a Channel or when modified by a User.
 /// </summary>
 protected virtual void OnTopic(IrcUser user, IrcChannel chan, string text, bool initial)
 {
 }
Пример #23
0
 /// <returns>Wether or not if the specific user is op on this channel (Has "@" flag)</returns>
 public bool HasOp(IrcUser user)
 {
     return(HasPriv(user, Privilege.Op));
 }
Пример #24
0
 /// <summary>
 /// Fires when a User parts from a Channel.
 /// </summary>
 protected virtual void OnPart(IrcUser user, IrcChannel chan, string reason)
 {
 }
Пример #25
0
 internal void TopicNotify(IrcUser user, IrcChannel chan, string text, bool initial)
 {
     chan.TopicChangedNotify(user, text, initial);
     OnTopic(user, chan, text, initial);
 }
Пример #26
0
 /// <summary>
 /// Fires when a User is kicked from a Channel.
 /// </summary>
 protected virtual void OnKick(IrcUser from, IrcChannel chan, IrcUser target, string reason)
 {
 }
Пример #27
0
 internal void FlagDeletedNotify(IrcUser user, IrcChannel chan, Privilege priv, IrcUser target)
 {
     chan.FlagDeletedNotify(user, priv, target);
     OnFlagDeleted(user, chan, priv, target);
 }
Пример #28
0
 /// <summary>
 /// Fires when a User deletes a Channel flag from another User.
 /// </summary>
 protected virtual void OnFlagDeleted(IrcUser user, IrcChannel chan, Privilege priv, IrcUser target)
 {
 }
Пример #29
0
 protected internal virtual void OnUserEncountered(IrcUser user)
 {
     m_Users.Remove(user.Nick);
     m_Users.Add(user.Nick, user);
     if (AuthMgr != null && AutoResolveAuth)
     {
         // resolve
         AuthMgr.ResolveAuth(user);
     }
 }
Пример #30
0
 /// <returns>Wether or not if the given user is voiced on this channel (Has "+" flag)</returns>
 public bool HasVoice(IrcUser user)
 {
     return(HasPriv(user, Privilege.Voice));
 }
Пример #31
0
 internal void PartNotify(IrcUser user, IrcChannel chan, string reason)
 {
     OnPart(user, chan, reason);
     chan.UserPartedNotify(user, reason);
     user.DeleteChannel(chan.Name);
     CheckUserKnown(user);
 }
Пример #32
0
 /// <returns>Wether the given user exists and has the given priv.</returns>
 public bool IsUser(IrcUser user, Privilege priv)
 {
     return(HasPriv(user, priv));
 }
Пример #33
0
 internal void TopicNotify(IrcUser user, IrcChannel chan, string text, bool initial)
 {
     chan.TopicChangedNotify(user, text, initial);
     OnTopic(user, chan, text, initial);
 }
Пример #34
0
 /// <summary>
 /// Fires when the Client receives any kind of NOTICE.
 /// </summary>
 /// <param name="user">The User who sent the text</param>
 /// <param name="channel">The Channel where it was sent (can be null)</param>
 /// <param name="text">The text which was sent</param>
 protected virtual void OnNotice(IrcUser user, IrcChannel channel, StringStream text)
 {
 }
Пример #35
0
 internal void ModeDeletedNotify(IrcUser user, IrcChannel chan, string mode, string param)
 {
     chan.ModeDeletedNotify(user, mode, param);
     OnModeDeleted(user, chan, mode, param);
 }
Пример #36
0
 internal void NoticeNotify(IrcUser user, IrcChannel channel, StringStream text)
 {
     OnNotice(user, channel, text);
 }
Пример #37
0
 internal void CtcpRequestNotify(IrcUser user, IrcChannel chan, string request, string text)
 {
     if (request.ToUpper() == "DCC" && chan == null)
     {
         Dcc.Handle(user, text);
     }
     OnCtcpRequest(user, chan, request, text);
 }
Пример #38
0
 /// <summary>
 /// Fires when the specified User joins the specified Channel.
 /// </summary>
 protected virtual void OnJoin(IrcUser user, IrcChannel chan)
 {
 }
Пример #39
0
 /// <summary>
 /// Fires when the Client receives any kind of CTCP reply.
 /// </summary>
 /// <param name="user">The User who sent the text</param>
 /// <param name="channel">The Channel where it was sent (can be null)</param>
 /// <param name="reply">The reply type (such as VERSION)</param>
 /// <param name="args">The text which was sent in addition to the reply</param>
 protected virtual void OnCtcpReply(IrcUser user, IrcChannel chan, string reply, string args)
 {
 }
Пример #40
0
 /// <summary>
 /// Fires when the Client receives any kind of CTCP reply.
 /// </summary>
 /// <param name="user">The User who sent the text</param>
 /// <param name="channel">The Channel where it was sent (can be null)</param>
 /// <param name="reply">The reply type (such as VERSION)</param>
 /// <param name="args">The text which was sent in addition to the reply</param>
 protected virtual void OnCtcpReply(IrcUser user, IrcChannel chan, string reply, string args)
 {
 }
Пример #41
0
 internal void JoinNotify(IrcUser user, string name)
 {
     if (!m_loggedIn)
         m_loggedIn = true;
     IrcChannel chan;
     if (user == Me)
     {
         Me.DeleteChannel(name);
     }
     if ((chan = GetChannel(name)) == null)
     {
         Send("mode " + name);
         if (user != m_me)
         {
             foreach (IrcChannel c in m_me)
             {
                 user.AddChannel(c);
                 c.AddUser(user);
                 c.DeleteUser(user);
             }
             m_me = user;
             m_Users.Remove(m_me.Nick);
         }
         chan = new IrcChannel(this, name);
     }
     user.AddChannel(chan);
     chan.UserJoinedNotify(user);
     OnJoin(user, chan);
 }
Пример #42
0
 /// <summary>
 /// Fires when a User deletes a Channel flag from another User.
 /// </summary>
 protected virtual void OnFlagDeleted(IrcUser user, IrcChannel chan, Privilege priv, IrcUser target)
 {
 }
Пример #43
0
 internal void ModeDeletedNotify(IrcUser user, IrcChannel chan, string mode, string param)
 {
     chan.ModeDeletedNotify(user, mode, param);
     OnModeDeleted(user, chan, mode, param);
 }
Пример #44
0
 internal void CtcpReplyNotify(IrcUser user, IrcChannel chan, string reply, string args)
 {
     OnCtcpReply(user, chan, reply, args);
 }
Пример #45
0
 internal void NoticeNotify(IrcUser user, IrcChannel chan, StringStream text)
 {
     if (chan != null)
         chan.NoticeReceivedNotify(user, text);
     OnNotice(user, chan, text);
     if (TriggersCommand(user, chan, text))
     {
         m_CommandHandler.ReactTo(new NoticeCmdTrigger(text, user, chan));
     }
 }
Пример #46
0
        public IrcUser GetOrCreateUser(string mask)
        {
            IrcUser user = null;
            var nick = "";
            if (mask.IndexOf("!") > -1)
                nick = mask.Split('!')[0];
            else
                nick = mask;

            user = GetUser(nick);

            if (user == null)
            {
                user = new IrcUser(this, mask);
                OnUserEncountered(user);
            }
            else if (!user.IsParsed)
            {
                user.Parse(mask);
            }

            return user;
        }
Пример #47
0
 internal void OnUserParsed(IrcUser user)
 {
     AuthMgr.OnNewUser(user);
 }
Пример #48
0
 public virtual bool TriggersCommand(IrcUser user, IrcChannel chan, StringStream input)
 {
     return input.ConsumeNext(CommandHandler.RemoteCommandPrefix);
 }
Пример #49
0
 internal void QueryMsgNotify(IrcUser user, StringStream text)
 {
     OnQueryMsg(user, text);
 }
Пример #50
0
 internal void AuthNotify(IrcUser user)
 {
     var evt = AuthResolved;
     if (evt != null)
     {
         evt(user);
     }
 }
Пример #51
0
        internal void TextNotify(IrcUser user, IrcChannel chan, StringStream text)
        {
            if (chan != null)
                chan.TextNotify(user, text);
            OnText(user, chan, text);

            if (TriggersCommand(user, chan, text))
            {
                m_CommandHandler.ReactTo(new MsgCmdTrigger(text, user, chan));
            }
        }
Пример #52
0
 internal void ChannelMsgNotify(IrcUser user, IrcChannel chan, StringStream text)
 {
     chan.MsgReceivedNotify(user, text);
     OnChannelMsg(user, chan, text);
 }
Пример #53
0
 internal void UserLeftChannelNotify(IrcChannel chan, IrcUser user, string reason)
 {
     OnUserLeftChannel(chan, user, reason);
 }
Пример #54
0
 internal void CheckUserKnown(IrcUser user)
 {
     if (user.Channels.Count == 0)
     {
         OnUserDisappeared(user);
         m_Users.Remove(user.Nick);
     }
 }
Пример #55
0
 /// <summary>
 /// Fires when the Client receives a PRIVMSG which was directed to a Channel.
 /// </summary>
 protected virtual void OnChannelMsg(IrcUser user, IrcChannel chan, StringStream text)
 {
 }
Пример #56
0
 /// <summary>
 /// Fures when a User deletes a Channel mode.
 /// </summary>
 /// <param name="user">The User who has added the mode</param>
 /// <param name="channel">The channel on which the mode has been changed</param>
 /// <param name="mode">The mode which has been changed</param>
 /// <param name="param">"" if the mode does not have any parameter</param>
 protected virtual void OnModeDeleted(IrcUser user, IrcChannel chan, string mode, string param)
 {
 }
Пример #57
0
 /// <summary>
 /// Fires when the Client receives any kind of CTCP request. 
 /// Automatically replies to the VERSION request with the content of the Version variable
 /// if not overridden.
 /// </summary>
 /// <param name="user">The User who sent the text</param>
 /// <param name="chan">The Channel where it was sent (can be null)</param>
 /// <param name="request">The request type (such as VERSION)</param>
 /// <param name="args">The text which was sent in addition to the request</param>
 protected virtual void OnCtcpRequest(IrcUser user, IrcChannel chan, string request, string args)
 {
     if (request.ToUpper() == "VERSION" && Version != "")
         CommandHandler.CtcpReply(user.Nick, "VERSION", Version);
 }
Пример #58
0
 internal void DeleteUser(IrcUser user)
 {
     Users.Remove(user.Nick);
     Privileges.Remove(user);
 }
Пример #59
0
 protected override void OnJoin(IrcUser user, IrcChannel chan)
 {
     base.OnJoin(user, chan);
     new AutoVoiceUser(user, chan);
 }
Пример #60
0
 internal void OnNickChange(IrcUser user, string oldNick)
 {
     Users.Remove(oldNick);
     Users[user.Nick] = user;
 }