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); } }
internal UnknownCommandReceivedEventArgs(CtcpMessage message) { this.Channel = message.Channel; this.Sender = message.Sender; this.IsQuery = message.IsQuery; this.Command = message.Command; this.Content = message.Content; }
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); }
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); }
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); }
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)); } }
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); }
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); } }
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)); } }
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); } }
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); } }
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); } }
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); } }
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)); } }
/// <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); } }
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); } }
/// <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); } } }
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); } }
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; } } }
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); } }
/// <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)); }
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; } } }
public void TestToStringNoParams() { var ctcpMessage = new CtcpMessage("VERSION"); Assert.Equal("\u0001VERSION\u0001", ctcpMessage.ToString()); }
public void TestToStringParams() { var ctcpMessage = new CtcpMessage("ACTION", "waves"); Assert.Equal("\u0001ACTION waves\u0001", ctcpMessage.ToString()); }