示例#1
0
        private void ReadMessage(CtcpMessage message)
        {
            OnRawMessageReceived(new CtcpRawMessageEventArgs(message));

            // Try to find corresponding message processor for command of given message.
            MessageProcessor messageProcessor;

            if (this.messageProcessors.TryGetValue(message.Tag, out messageProcessor))
            {
                try
                {
                    messageProcessor(message);
                }
#if !DEBUG
                catch (Exception ex)
                {
                    OnError(new IrcErrorEventArgs(ex));
                }
#endif
                finally
                {
                }
            }
            else
            {
                // Command is unknown.
                DebugUtilities.WriteEvent("Unknown CTCP message tag '{0}'.", message.Tag);
            }
        }
示例#2
0
 internal UnknownCommandReceivedEventArgs(CtcpMessage message)
 {
     this.Channel = message.Channel;
     this.Sender  = message.Sender;
     this.IsQuery = message.IsQuery;
     this.Command = message.Command;
     this.Content = message.Content;
 }
示例#3
0
        public void TestOldStyle()
        {
            var ctcpMessage = new CtcpMessage();

            ctcpMessage.ParseFrom("\u0001ACTION stop\u0001\u0001ACTION spamming\u0001");

            Assert.Equal("ACTION", ctcpMessage.Command);
            Assert.Equal("stop\u0001\u0001ACTION spamming", ctcpMessage.Parameters);
        }
示例#4
0
        public void TestParseParams()
        {
            var ctcpMessage = new CtcpMessage();

            ctcpMessage.ParseFrom("\u0001ACTION writes some specs!\u0001");

            Assert.Equal("ACTION", ctcpMessage.Command);
            Assert.Equal("writes some specs!", ctcpMessage.Parameters);
        }
示例#5
0
        public void TestParseWithoutTrailingDelim()
        {
            var ctcpMessage = new CtcpMessage();

            ctcpMessage.ParseFrom("\u0001ACTION writes some specs!");

            Assert.Equal("ACTION", ctcpMessage.Command);
            Assert.Equal("writes some specs!", ctcpMessage.Parameters);
        }
示例#6
0
        public void TestParseNoParams()
        {
            var ctcpMessage = new CtcpMessage();

            ctcpMessage.ParseFrom("\u0001VERSION\u0001");

            Assert.Equal("VERSION", ctcpMessage.Command);
            Assert.Equal("", ctcpMessage.Parameters);
        }
        protected internal void ProcessMessageAction(CtcpMessage message)
        {
            if (!message.IsResponse)
            {
                var text = message.Data;

                OnActionReceived(new CtcpMessageEventArgs(message.Source, message.Targets, text));
            }
        }
示例#8
0
        public void TestNoCommand()
        {
            var ctcpMessage = new CtcpMessage();

            ctcpMessage.ParseFrom("\u0001\u0001");

            Assert.Equal("", ctcpMessage.Command);
            Assert.Equal("", ctcpMessage.Parameters);
        }
 private bool OnUnknownCommandReceived(CtcpMessage message)
 {
     if (this.UnknownCommandReceived != null)
     {
         var e = new UnknownCommandReceivedEventArgs(message);
         this.UnknownCommandReceived(this, e);
         return(e.Handled);
     }
     return(false);
 }
示例#10
0
 public static void Time(CtcpClient client, CtcpMessage message)
 {
     if (message.IsQuery)
     {
         message.Sender.Ctcp.SendNotice("TIME :" + DateTime.Now.ToString("F"));
     }
     else
     {
         message.Sender.Ctcp.OnLocalTimeReceived(message.Content);
     }
 }
示例#11
0
        protected void ProcessMessageAction(CtcpMessage message)
        {
            Debug.Assert(message.Data != null);

            if (!message.IsResponse)
            {
                var text = message.Data;

                OnActionReceived(new CtcpMessageEventArgs(message.Source, message.Targets, text));
            }
        }
        protected internal void ProcessMessageAction(CtcpMessage message)
        {
            Debug.Assert(message.Data != null);

            if (!message.IsResponse)
            {
                var text = message.Data;

                OnActionReceived(new CtcpMessageEventArgs(message.Source, message.Targets, text));
            }
        }
示例#13
0
 public static void Action(CtcpClient client, CtcpMessage message)
 {
     if (message.Channel == null)
     {
         message.Sender.Ctcp.OnActionReceived(message.Content);
     }
     else
     {
         message.Channel.Ctcp.OnActionReceived(message.Sender, message.Content);
     }
 }
示例#14
0
 public static void Version(CtcpClient client, CtcpMessage message)
 {
     if (message.IsQuery)
     {
         message.Sender.Ctcp.SendNotice("VERSION " + CtcpClient.ClientSoftware.ToString());
     }
     else
     {
         message.Sender.Ctcp.OnVersionReplyReceived(message.Content);
     }
 }
示例#15
0
 public static void UserInfo(CtcpClient client, CtcpMessage message)
 {
     if (message.IsQuery)
     {
         message.Sender.Ctcp.SendNotice("USERINFO :" + client.CurrentUserInformation);
     }
     else
     {
         message.Sender.Ctcp.OnInformationReceived(message.Content);
     }
 }
示例#16
0
 public static void Source(CtcpClient client, CtcpMessage message)
 {
     if (message.IsQuery)
     {
         message.Sender.Ctcp.SendNotice("SOURCE :" + CtcpClient.ClientSoftware.DownloadLocation);
     }
     else
     {
         message.Sender.Ctcp.OnSourceReplyReceived(message.Content);
     }
 }
示例#17
0
 public static void Ping(CtcpClient client, CtcpMessage message)
 {
     if (message.IsQuery)
     {
         message.Sender.Ctcp.SendNotice("PING " + message.Content);
     }
     else if (message.Sender.Ctcp.PingTimes.Any())
     {
         long pingTime = TimeHelper.DateTimeToUnixMilliseconds(DateTime.UtcNow) - message.Sender.Ctcp.PingTimes.Dequeue();
         message.Sender.Ctcp.OnPingReplyReceived(TimeSpan.FromMilliseconds(pingTime));
     }
 }
示例#18
0
        /// <inheritdoc cref="WriteMessage(IList{IIrcMessageTarget}, string, bool)"/>
        /// <param name="message">The message to write.</param>
        /// <exception cref="ArgumentException"><paramref name="message"/> contains more than 15 many parameters.
        /// </exception>
        /// <exception cref="ArgumentException">The value of <see cref="CtcpMessage.Tag"/> of <paramref name="message"/>
        /// is invalid.</exception>
        protected void WriteMessage(IList <IIrcMessageTarget> targets, CtcpMessage message)
        {
            if (message.Tag == null)
            {
                throw new ArgumentException("MessageInvalidTag", "message");
            }

            var tag        = message.Tag.ToUpper();
            var taggedData = message.Data == null ? tag : tag + " :" + message.Data;

            WriteMessage(targets, taggedData, message.IsResponse);
            OnRawMessageSent(new CtcpRawMessageEventArgs(message));
        }
        protected internal void ProcessMessageTime(CtcpMessage message)
        {
            if (message.IsResponse)
            {
                var dateTime = message.Data;

                OnTimeResponseReceived(new CtcpTimeResponseReceivedEventArgs(message.Source, dateTime));
            }
            else
            {
                var localDateTime = DateTimeOffset.Now.ToString("o");

                SendMessageTime(new[] { message.Source }, localDateTime, true);
            }
        }
示例#20
0
        protected void ProcessMessageTime(CtcpMessage message)
        {
            if (message.IsResponse)
            {
                var dateTime = message.Data;

                OnTimeResponseReceived(new CtcpTimeResponseReceivedEventArgs(message.Source, dateTime));
            }
            else
            {
                var localDateTime = DateTimeOffset.Now.ToString("o");

                SendMessageTime(new[] { message.Source }, localDateTime, true);
            }
        }
示例#21
0
 /// <summary>
 /// Handles a <see cref="CtcpMessage"/>.
 /// </summary>
 private void HandleMessage(CtcpMessage message)
 {
     if (_commandHandlers.ContainsKey(message.Command))
     {
         _commandHandlers[message.Command].Invoke(this, message);
     }
     else
     {
         bool handled = this.OnUnknownCommandReceived(message);
         if (!handled && message.IsQuery)
         {
             message.Sender.Ctcp.SendErrorMessage(string.Format(UnknownCommandMessage, message.Command));
         }
     }
 }
        protected internal void ProcessMessagePing(CtcpMessage message)
        {
            if (message.IsResponse)
            {
                // Calculate time elapsed since the ping request was sent.
                var sendTime = new DateTime(long.Parse(message.Data));
                var pingTime = DateTime.Now - sendTime;

                OnPingResponseReceived(new CtcpPingResponseReceivedEventArgs(message.Source, pingTime));
            }
            else
            {
                SendMessagePing(new[] { message.Source }, message.Data, true);
            }
        }
        protected internal void ProcessMessageVersion(CtcpMessage message)
        {
            if (message.IsResponse)
            {
                var versionInfo = message.Data;

                OnVersionResponseReceived(new CtcpVersionResponseReceivedEventArgs(message.Source, versionInfo));
            }
            else
            {
                if (this.ClientVersion != null)
                {
                    SendMessageVersion(new[] { message.Source }, this.ClientVersion, true);
                }
            }
        }
示例#24
0
        protected void ProcessMessageVersion(CtcpMessage message)
        {
            if (message.IsResponse)
            {
                var versionInfo = message.Data;

                OnVersionResponseReceived(new CtcpVersionResponseReceivedEventArgs(message.Source, versionInfo));
            }
            else
            {
                if (this.ClientVersion != null)
                {
                    SendMessageVersion(new[] { message.Source }, this.ClientVersion, true);
                }
            }
        }
        protected internal void ProcessMessageErrMsg(CtcpMessage message)
        {
            if (message.IsResponse)
            {
                // Get failed query and error message from data.
                var parts        = message.Data.SplitIntoPair(" :");
                var failedQuery  = parts.Item1;
                var errorMessage = parts.Item2;

                OnErrorMessageResponseReceived(new CtcpErrorMessageReceivedEventArgs(message.Source,
                                                                                     failedQuery, errorMessage));
            }
            else
            {
                SendMessageErrMsg(new[] { message.Source }, message.Data + " :" + messageNoError, true);
            }
        }
        protected void ProcessMessagePing(CtcpMessage message)
        {
            Debug.Assert(message.Data != null);

            if (message.IsResponse)
            {
                // Calculate time elapsed since the ping request was sent.
                var sendTime = new DateTime(long.Parse(message.Data));
                var pingTime = DateTime.Now - sendTime;

                OnPingResponseReceived(new CtcpPingResponseReceivedEventArgs(message.Source, pingTime));
            }
            else
            {
                SendMessagePing(new[] { message.Source }, message.Data, true);
            }
        }
        protected internal void ProcessMessageErrMsg(CtcpMessage message)
        {
            Debug.Assert(message.Data != null);

            if (message.IsResponse)
            {
                // Get failed query and error message from data.
                var parts = message.Data.SplitIntoPair(" :");
                var failedQuery = parts.Item1;
                var errorMessage = parts.Item2;

                OnErrorMessageResponseReceived(new CtcpErrorMessageReceivedEventArgs(message.Source,
                    failedQuery, errorMessage));
            }
            else
            {
                SendMessageErrMsg(new[] { message.Source }, message.Data + " :" + messageNoError, true);
            }
        }
示例#28
0
        private void ReadMessage(IrcPreviewMessageEventArgs previewMessageEventArgs, bool isNotice)
        {
            if (!(previewMessageEventArgs.Source is IrcUser))
            {
                return;
            }

            // Check if message represents tagged data.
            if (previewMessageEventArgs.Text.First() == taggedDataDelimeterChar &&
                previewMessageEventArgs.Text.Last() == taggedDataDelimeterChar)
            {
                if (previewMessageEventArgs.Source is IrcUser)
                {
                    var message = new CtcpMessage();
                    message.Source     = (IrcUser)previewMessageEventArgs.Source;
                    message.Targets    = previewMessageEventArgs.Targets;
                    message.IsResponse = isNotice;

                    // Parse tagged data into message.
                    var dequotedText = LowLevelDequote(CtcpDequote(previewMessageEventArgs.Text.Substring(
                                                                       1, previewMessageEventArgs.Text.Length - 2)));
                    var firstSpaceIndex = dequotedText.IndexOf(' ');
                    if (firstSpaceIndex == -1)
                    {
                        message.Tag  = dequotedText;
                        message.Data = null;
                    }
                    else
                    {
                        message.Tag  = dequotedText.Substring(0, firstSpaceIndex);
                        message.Data = dequotedText.Substring(firstSpaceIndex + 1).TrimStart(':');
                    }

                    ReadMessage(message);
                    previewMessageEventArgs.Handled = true;
                }
            }
        }
示例#29
0
 public static void ClientInfo(CtcpClient client, CtcpMessage message)
 {
     if (message.IsQuery)
     {
         string command = message.Content.GetFirstWord();
         if (command.HasText())
         {
             string text;
             if (!CtcpClient.CommandDescriptions.TryGetValue(command, out text))
             {
                 text = "N/A";
             }
             message.Sender.Ctcp.SendNotice("CLIENTINFO :" + command + ": " + text);
         }
         else
         {
             message.Sender.Ctcp.SendNotice("CLIENTINFO :" + string.Join(", ", CtcpClient._commandHandlers.Keys));
         }
     }
     else
     {
         message.Sender.Ctcp.OnCapabilitiesReceived(message.Content);
     }
 }
示例#30
0
        /// <inheritdoc cref="WriteMessage(IList{IIrcMessageTarget}, string, bool)"/>
        /// <param name="message">The message to write.</param>
        /// <exception cref="ArgumentException"><paramref name="message"/> contains more than 15 many parameters.
        /// </exception>
        /// <exception cref="ArgumentException">The value of <see cref="CtcpMessage.Tag"/> of <paramref name="message"/>
        /// is invalid.</exception>
        protected void WriteMessage(IList<IIrcMessageTarget> targets, CtcpMessage message)
        {
            if (message.Tag == null)
                throw new ArgumentException(ResourceLoader.GetForCurrentView("IrcDotNet/Resources").GetString("MessageInvalidTag"), "message");

            var tag = message.Tag.ToUpper();
            var taggedData = message.Data == null ? tag : tag + " :" + message.Data;
            WriteMessage(targets, taggedData, message.IsResponse);
            OnRawMessageSent(new CtcpRawMessageEventArgs(message));
        }
示例#31
0
 public static void ErrMsg(CtcpClient client, CtcpMessage message)
 {
     message.Sender.Ctcp.OnErrorMessageReceived(message.Content);
 }
        /// <inheritdoc cref="WriteMessage(IList{IIrcMessageTarget}, string, bool)"/>
        /// <param name="message">The message to write.</param>
        /// <exception cref="ArgumentException">
        /// <paramref name="message"/> contains more than 15 many parameters. -or-
        /// The value of <see cref="CtcpMessage.Tag"/> of <paramref name="message"/> is invalid.
        /// </exception>
        protected void WriteMessage(IList<IIrcMessageTarget> targets, CtcpMessage message)
        {
            if (message.Tag == null)
                throw new ArgumentException(Properties.Resources.ErrorMessageInvalidTag, "message");

            var tag = message.Tag.ToUpper();
            var taggedData = message.Data == null ? tag : tag + " :" + message.Data;
            WriteMessage(targets, taggedData, message.IsResponse);
            OnRawMessageSent(new CtcpRawMessageEventArgs(message));
        }
        private void ReadMessage(CtcpMessage message)
        {
            OnRawMessageReceived(new CtcpRawMessageEventArgs(message));

            // Try to find corresponding message processor for command of given message.
            MessageProcessor messageProcessor;
            if (this.messageProcessors.TryGetValue(message.Tag, out messageProcessor))
            {
                try
                {
                    messageProcessor(message);
                }
#if !DEBUG
                catch (Exception ex)
                {
                    OnError(new IrcErrorEventArgs(ex));
                }
#endif
                finally
                {
                }
            }
            else
            {
                // Unknown command.
                Debug.WriteLine(string.Format("Unknown CTCP message tag '{0}'.", message.Tag));
            }
        }
        private void ReadMessage(IrcPreviewMessageEventArgs previewMessageEventArgs, bool isNotice)
        {
            if (!(previewMessageEventArgs.Source is IrcUser))
                return;

            // Check if message represents tagged data.
            if (previewMessageEventArgs.Text.First() == taggedDataDelimeterChar &&
                previewMessageEventArgs.Text.Last() == taggedDataDelimeterChar)
            {
                if (previewMessageEventArgs.Source is IrcUser)
                {
                    var message = new CtcpMessage();
                    message.Source = (IrcUser)previewMessageEventArgs.Source;
                    message.Targets = previewMessageEventArgs.Targets;
                    message.IsResponse = isNotice;

                    // Parse tagged data into message.
                    var dequotedText = LowLevelDequote(CtcpDequote(previewMessageEventArgs.Text.Substring(
                        1, previewMessageEventArgs.Text.Length - 2)));
                    var firstSpaceIndex = dequotedText.IndexOf(' ');
                    if (firstSpaceIndex == -1)
                    {
                        message.Tag = dequotedText;
                        message.Data = null;
                    }
                    else
                    {
                        message.Tag = dequotedText.Substring(0, firstSpaceIndex);
                        message.Data = dequotedText.Substring(firstSpaceIndex + 1).TrimStart(':');
                    }

                    ReadMessage(message);
                    previewMessageEventArgs.Handled = true;
                }
            }
        }
示例#35
0
        public void TestToStringNoParams()
        {
            var ctcpMessage = new CtcpMessage("VERSION");

            Assert.Equal("\u0001VERSION\u0001", ctcpMessage.ToString());
        }
示例#36
0
        public void TestToStringParams()
        {
            var ctcpMessage = new CtcpMessage("ACTION", "waves");

            Assert.Equal("\u0001ACTION waves\u0001", ctcpMessage.ToString());
        }