public void BaseLine() { UserInfo info = new UserInfo(client, "[email protected]"); Assert.IsNull(info.BaseLine); IrcLine line = new IrcLine(client, ":[email protected] CMD :test"); info = new UserInfo(line); Assert.AreSame(line, info.BaseLine); }
/// <summary> /// Initializes a new instance of the KickReceivedEventArgs class. /// </summary> /// <param name="line">The line with the kick command.</param> public KickReceivedEventArgs(IrcLine line) : base(line) { kicker = new UserInfo(line); kickedName = line.Parameters[1]; channelName = line.Parameters[0]; reason = line.Parameters[2]; }
/// <summary> /// Initializes a new instance of the PartReceivedEventArgs class. /// </summary> /// <param name="line">The line to create the event args from.</param> public PartReceivedEventArgs(IrcLine line) : base(line) { user = new UserInfo(line); channelName = line.Parameters[0]; if (line.Parameters.Length > 1) { partMessage = line.Parameters[1]; } }
/// <summary> /// Initializes a new instance of the QuitReceivedEventArgs class. /// </summary> /// <param name="line">The line containing the quit command.</param> public QuitReceivedEventArgs(IrcLine line) : base(line) { user = new UserInfo(line); if (line.Parameters.Length > 0) { quitMessage = line.Parameters[0]; } else { quitMessage = string.Empty; } }
/// <summary> /// Initializes a new instance of the BadNickEventArgs class. /// </summary> /// <param name="baseLine">The line, what created the bad nick event.</param> /// <param name="inLogin">Determines if the event was fired in the login state.</param> public BadNickEventArgs(IrcLine baseLine, bool inLogin) : base(baseLine) { switch (baseLine.Numeric) { case 432: reason = BadNickReasons.ErroneusNickname; break; case 433: reason = BadNickReasons.NicknameInUse; break; default: throw new ArgumentException("The given line is no 432 or 433 numeric", "baseLine"); } isLogin = inLogin; }
public void Constructor() { IrcClient client = new IrcClient(); IrcLine erroneousNick = new IrcLine(client, ":prefix 432 :Erroneous nickname"); IrcLine nickInUse = new IrcLine(client, ":prefix 433 :Nickname is already in use"); BadNickEventArgs args = new BadNickEventArgs(erroneousNick, true); Assert.IsTrue(args.IsLogin); Assert.AreEqual(BadNickReasons.ErroneusNickname, args.Reason); args = new BadNickEventArgs(nickInUse, false); Assert.IsFalse(args.IsLogin); Assert.AreEqual(BadNickReasons.NicknameInUse, args.Reason); args = new BadNickEventArgs(erroneousNick, false); Assert.IsFalse(args.IsLogin); Assert.AreEqual(BadNickReasons.ErroneusNickname, args.Reason); args = new BadNickEventArgs(nickInUse, true); Assert.IsTrue(args.IsLogin); Assert.AreEqual(BadNickReasons.NicknameInUse, args.Reason); }
/// <summary> /// Initializes a new instance of the MessageReceivedEventArgs class. /// </summary> /// <param name="line">The line with the message.</param> public MessageReceivedEventArgs(IrcLine line) : base(line) { sender = new UserInfo(line); string l; l = Message; if (l[0] == '\x01' && l[l.Length - 1] == '\x01') { l = l.Substring(1, l.Length - 2); ctcpCommandString = l; int firstSpace = l.IndexOf(' '); if (firstSpace > 0) { ctcpCommandString = l.Substring(0, firstSpace); ctcpParameters = l.Substring(firstSpace + 1); } switch (ctcpCommandString) { case "ACTION": ctcpCommand = CtcpCommands.Action; break; case "VERSION": ctcpCommand = CtcpCommands.Version; break; default: ctcpCommand = CtcpCommands.Unkown; break; } } else { ctcpCommand = CtcpCommands.None; } }
/// <summary> /// Initializes a new instance of the UserInfo class based on the given <see cref="IrcLine" />. /// </summary> /// <param name="baseLine"> /// The <see cref="IrcLine"/> this UserInfo was build from. /// </param> public UserInfo(IrcLine baseLine) { this.baseLine = baseLine; Match hostPieces; hostPieces = hostRegex.Match(BaseLine.Prefix); if (hostPieces.Success) { nickName = hostPieces.Groups[1].Value; ident = hostPieces.Groups[2].Value; this.host = hostPieces.Groups[3].Value; this.client = BaseLine.Client; } else { throw new ArgumentException("Malformed userhost can't be parsed correctly", "baseLine"); } }
/// <summary> /// Initializes a new instance of the UserInfo class, based on an existing UserInfo. /// </summary> /// <param name="source">The UserInfo instance to copy from.</param> public UserInfo(UserInfo source) { baseLine = source.BaseLine; client = source.Client; host = source.Host; ident = source.Ident; nickName = source.NickName; }
/// <summary> /// Initializes a new instance of the PingReceivedEventArgs class. /// </summary> /// <param name="line">The line what holds the ping event.</param> public PingReceivedEventArgs(IrcLine line) : base(line) { }
/// <summary> /// Initializes a new instance of the IrcEventArgs class. /// </summary> /// <param name="line">The line, the EventArgs where created from.</param> public IrcEventArgs(IrcLine line) { client = line.Client; this.line = line; }
/// <summary> /// Fires the LineReceived event. /// </summary> /// <param name="line">The line that was received.</param> protected virtual void OnLineReceived(IrcLine line) { KickReceivedEventArgs kickArgs = new KickReceivedEventArgs(line); if (KickReceived != null) { KickReceived(this, kickArgs); } }
/// <summary> /// Initializes a new instance of the JoinReceivedEventArgs class. /// </summary> /// <param name="line">The line to create the event args from.</param> public JoinReceivedEventArgs(IrcLine line) : base(line) { user = new UserInfo(line); channelName = line.Parameters[0]; }
/// <summary> /// Initializes a new instance of the NumericReceivedEventArgs class. /// </summary> /// <param name="line">The line with the numeric command.</param> public NumericReceivedEventArgs(IrcLine line) : base(line) { }
/// <summary> /// Initializes a new instance of the IrcLine class as a copy of another IrcLine object. /// </summary> /// <param name="source"> /// The <see cref="IrcLine"/> to copy. /// </param> public IrcLine(IrcLine source) { prefix = source.Prefix; command = source.Command; parameters = source.Parameters; client = source.Client; numeric = source.Numeric; }
/// <summary> /// Initializes a new instance of the NoticeReceivedEventArgs class. /// </summary> /// <param name="line">The line creating the notice event.</param> public NoticeReceivedEventArgs(IrcLine line) : base(line) { }
/// <summary> /// Reads a new line from the server. /// </summary> /// <remarks> /// This method blocks the calling thread until a new line was received from server. /// Only use this method, if you want to bypass the automatically raised events and kine handling. /// If you want to have this features use <see cref="IrcClient.ReceiveLine" /> instead. /// </remarks> /// <returns>The received line.</returns> public IrcLine ReadLine() { string line; if (Connected) { try { if (inStream == null) { return null; } line = inStream.ReadLine(); if (line != null) { IrcLine ircLine = new IrcLine(this, line); return ircLine; } } catch (InvalidLineFormatException ex) { OnError(ex.Message, ex); } catch (Exception ex) { OnError("Couldn't receive line", ex); } } return null; }