Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChannelUserEventArgs"/> class.
 /// </summary>
 /// <param name="channel">Channel.</param>
 /// <param name="user">User.</param>
 /// <param name="isOwned">Is owned.</param>
 /// <param name="message">Message.</param>
 /// <param name="messageType">Message type.</param>
 public ChannelUserEventArgs(
     string channel,
     IrcUser user,
     bool isOwned,
     string message,
     IrcMessageType messageType)
 {
     this.Channel     = channel;
     this.IsOwned     = isOwned;
     this.Message     = message;
     this.MessageType = messageType;
     this.User        = user;
 }
Example #2
0
/*/ Constructors /*/

        /// <summary>
        /// Initializes a new instance of the <see cref="UserEventArgs"/> class.
        /// </summary>
        /// <param name="user">User.</param>
        /// <param name="message">Message.</param>
        /// <param name="isOwned">Is owned.</param>
        public UserEventArgs(IrcUser user, string message, bool isOwned)
            : this(user, message, isOwned, IrcMessageType.None)
        {
        }
Example #3
0
        private void HandleReply(string message)
        {
            if (string.IsNullOrEmpty(message))
            {
                return;
            }

            var reply = new IrcReply(message);
            var cmd   = reply.Command.ToUpperInvariant();

            this.OnReplyReceived(reply);

            switch (cmd)
            {
            case "001":
            {
                this.OnConnected(EventArgs.Empty);
                break;
            }

            case "396":
            {
                // :<server> 396 <nickname> <new.hostname.tld> :is now your hidden host
                this.OnHostHidden(new HostHiddenEventArgs(reply.Params?[0] ?? string.Empty));
                break;
            }

            case "JOIN":
            {
                // :<nick>!<user>@<host> JOIN <channel>
                var user    = new IrcUser(reply.Prefix);
                var isOwned = false;

                if (user.Nickname == this.CurrentNickname)
                {
                    this.CurrentChannels.Add(reply.Target);
                    isOwned = true;
                }

                this.OnChannelJoined(new ChannelUserEventArgs(reply.Target, user, isOwned));
                break;
            }

            case "MODE":
            {
                // USER MODE -> :n!u@h MODE <target> :[+]modes[-]modes
                if (reply.TargetIsUser)
                {
                    var add  = string.Empty;
                    var rem  = string.Empty;
                    var plus = true;
                    for (var x = 0; x < reply.Trailing.Length; ++x)
                    {
                        var ch = reply.Trailing[x];
                        if (ch == '+')
                        {
                            plus = true;
                        }
                        else if (ch == '-')
                        {
                            plus = false;
                        }
                        else if (plus)
                        {
                            add += ch;
                        }
                        else if (!plus)
                        {
                            rem += ch;
                        }
                    }

                    this.OnUserModeChanged(
                        new UserModeChangedEventArgs(
                            this.LookupUserModes(add),
                            this.LookupUserModes(rem)));
                }
                else if (reply.TargetIsChannel)
                {
                    var add = new List <IrcChannelModeValue>(0);
                    var rem = new List <IrcChannelModeValue>(0);
                    var ops = reply.Params?[0];
                    var ctr = '\0';

                    for (int x = 0, c = 0; x < ops?.Length; ++x)
                    {
                        if ("-+".Contains(ops[x]))
                        {
                            ctr = ops[x];
                            continue;
                        }

                        var mode = this.LookupChannelMode(ops[x]);

                        if (ctr == '+')
                        {
                            var val = mode.HasAddParam ? reply.Params?[++c] : null;
                            add.Add(new IrcChannelModeValue(mode.Mode, val));
                        }
                        else if (ctr == '-')
                        {
                            var val = mode.HasRemParam ? reply.Params?[++c] : null;
                            rem.Add(new IrcChannelModeValue(mode.Mode, val));
                        }
                    }

                    this.OnChannelModeChanged(new ChannelModeChangedEventArgs(reply.Target, add, rem));
                }

                break;
            }

            case "PART":
            {
                // :<nick>!<user>@<host> PART <channel> :<message>
                var user    = new IrcUser(reply.Prefix);
                var isOwned = false;

                if (user.Nickname == this.CurrentNickname)
                {
                    this.CurrentChannels.Remove(reply.Target);
                    isOwned = true;
                }

                this.OnChannelParted(new ChannelUserEventArgs(reply.Target, user, isOwned, reply.Trailing, IrcMessageType.None));
                break;
            }

            case "PRIVMSG":
            case "NOTICE":
            {
                var user    = new IrcUser(reply.Prefix);
                var isOwned = user.Nickname == this.CurrentNickname;
                var msgType = (cmd == "PRIVMSG") ? IrcMessageType.PrivateMessage : IrcMessageType.Notice;

                if (reply.TargetIsChannel)
                {
                    this.OnChannelMessage(new ChannelUserEventArgs(
                                              reply.Target, user, isOwned, reply.Trailing, msgType));
                }
                else
                {
                    this.OnPrivateMessage(new UserEventArgs(
                                              user, reply.Trailing, isOwned, msgType));
                }

                break;
            }

            case "QUIT":
            {
                // :<nick>!<user>@<host> QUIT :<message>
                var user    = new IrcUser(reply.Prefix);
                var isOwned = user.Nickname == this.CurrentNickname;

                this.OnUserQuit(new UserEventArgs(user, reply.Trailing, isOwned));
                break;
            }
            }
        }