/// <summary> /// Asynchronously connects using the specified information. /// </summary> /// <param name="nickname">The desired nickname.</param> /// <param name="realName">The desired real name.</param> /// <param name="mode">The desired mode. Most modes must be set after connecting.</param> /// <param name="password">Optional. The password, if any.</param> /// <returns>True if the connection attempt was successful; false otherwise.</returns> public async Task <bool> ConnectAsync(string nickname, string realName, IrcUserLoginModes mode, string password = "") { Validate.IsNotDisposed(this._disposed); Validate.HasText(nickname, "nickname"); Validate.HasText(realName, "realName"); Validate.IsEnumValue(mode, "mode"); Validate.IsNotNull(password, "password"); IrcValidate.IsNotConnected(this.IsConnected); if (await this.Client.ConnectAsync()) { this.IsConnected = true; if (password.HasText()) { this.SendPassword(password); } this.SendUserNames(nickname, realName, mode); this.ChangeNickname(nickname); this.CurrentUser.Nickname = nickname; return(true); } return(false); }
/// <summary> /// Leaves all channels, but does not quit the <see cref="IrcNetwork"/>. /// </summary> public void LeaveAllChannels() { Validate.IsNotDisposed(this._disposed); IrcValidate.IsConnected(this.IsConnected); // JOIN 0 // It means "part all channels but do not disconnect". Go figure. this.Send("JOIN", "0"); }
/// <summary> /// Requests operator rights to the server. /// Optional part of the authentication process. /// </summary> /// <param name="userName">The username.</param> /// <param name="password">The operator password.</param> public void AuthenticateAsOperator(string userName, string password) { Validate.IsNotDisposed(this._disposed); Validate.HasText(userName, "userName"); Validate.HasText(password, "password"); IrcValidate.IsConnected(this.IsConnected); // OPER <user name> <password> this.Send("OPER", userName, password); }
/// <summary> /// Sends raw data. Be careful. /// </summary> /// <param name="data">The data to be sent. Newlines are not allowed.</param> public void SendRawData(string data) { Validate.HasText(data, "data"); Validate.IsNotDisposed(this._disposed); IrcValidate.IsConnected(this.Network.IsConnected); data = data.TrimEnd().Replace(Environment.NewLine, string.Empty); this._client.SendLine(data); this.OnRawDataSent(data); }
/// <summary> /// Requests a nickname change to the server. /// </summary> /// <param name="newNickname">The desired nickname.</param> public void ChangeNickname(string newNickname) { Validate.IsNotDisposed(this._disposed); Validate.HasText(newNickname, "newNickname"); IrcValidate.IsConnected(this.IsConnected); this.PreviousNickname = this.CurrentUser.Nickname ?? newNickname; this.CurrentUser.Nickname = newNickname; // NICK <new nick> this.Send("NICK", newNickname); }
/// <summary> /// Gets a known <see cref="IrcChannel"/> from its name. /// </summary> /// <param name="name">The channel name.</param> /// <returns>The <see cref="IrcChannel"/>.</returns> public IrcChannel GetChannel(string name) { Validate.IsNotDisposed(this._disposed); Validate.HasText(name, "name"); IrcValidate.IsChannelName(name, this.Parameters, "name"); IrcValidate.IsConnected(this.IsConnected); var channel = this.KnownChannels.FirstOrDefault(chan => this.Parameters.CaseMapping.AreEqual(chan.FullName, name)); if (channel == null) { channel = new IrcChannel(this.Client, this, name); this.KnownChannelsInternal.Add(channel); } return(channel); }
/// <summary> /// Quits the <see cref="IrcNetwork"/>. /// </summary> /// <param name="reason">Optional. The reason, if any.</param> public void Quit(string reason = "") { Validate.IsNotDisposed(this._disposed); Validate.IsNotNull(reason, "reason"); IrcValidate.IsConnected(this.IsConnected); // QUIT[ :reason] if (reason.HasText()) { this.Send("QUIT", ":", reason); } else { this.Send("QUIT"); } this.Client.Stop(false); }
/// <summary> /// Gets a known <see cref="IrcUser"/> from their name. /// </summary> /// <param name="nickname">The user name.</param> /// <returns>The <see cref="IrcUser"/>.</returns> public IrcUser GetUser(string nickname) { Validate.IsNotDisposed(this._disposed); Validate.HasText(nickname, "nickname"); IrcValidate.IsConnected(this.IsConnected); var user = this.KnownUsers.FirstOrDefault(u => this.Parameters.CaseMapping.AreEqual(u.Nickname, nickname)); if (user == null) { user = new IrcUser(this.Client, this) { Nickname = nickname }; this.KnownUsersInternal.Add(user); } return(user); }
/// <summary> /// Attempts to connect as a service. /// </summary> /// <param name="nickname">The nickname of the service.</param> /// <param name="distribution">A mask specifying which hosts have access to the service.</param> /// <param name="type">The service type.</param> /// <param name="info">Information about the service.</param> /// <returns>True if the connection attempt was successful; false otherwise.</returns> /// <remarks>This method should be called instead of <see cref="ConnectAsync"/> if you are a service.</remarks> public async Task <bool> ConnectAsServiceAsync(string nickname, string distribution, string type, string info) { Validate.IsNotDisposed(this._disposed); Validate.HasText(nickname, "nickname"); Validate.HasText(distribution, "distribution"); Validate.HasText(type, "type"); Validate.HasText(info, "info"); IrcValidate.IsNotConnected(this.IsConnected); if (await this.Client.ConnectAsync()) { // SERVICE <nickname> * <distribution> <type> * :<info> // RFC 2812 doesn't say there is a ':' char before the "info" parameter, but the example has one, and it seems logical this.Send("SERVICE", nickname, "*", distribution, type, "*", ":", info); return(true); } return(false); }
public void IsChannelName_NotChannelName() { IrcValidate.IsChannelName("aaa", new IrcNetworkParameters(), "N/A"); }
public void IsChannelName_Empty() { IrcValidate.IsChannelName(string.Empty, new IrcNetworkParameters(), "N/A"); }
public void IsChannelName_Null() { IrcValidate.IsChannelName(null, new IrcNetworkParameters(), "N/A"); }
public void IsNotConnected_Connected() { IrcValidate.IsNotConnected(true); }
public void IsNotConnected_NotConnected() { IrcValidate.IsNotConnected(false); }