public async Task ConnectAsync(ServerInformation serverInfo, RegistrationInformation registrationInfo) { IsConnected = false; ServerInformation = serverInfo; Nickname = registrationInfo.Nickname; _client.Connect(ServerInformation.HostName, ServerInformation.Port); await HandleConnectionAsync(registrationInfo); }
/// <summary> /// Sends registration information to the server by executing the PASS, NICK, /// and USER commands. /// </summary> /// <param name="info">An object containing the necessary registration information</param> internal virtual async Task SendRegistrationInfoAsync(RegistrationInformation info) { if (info == null) { throw new ArgumentNullException("info", "The registration info object was null."); } await SendMessageToServerAsync(new IrcMessage { Command = "PASS", Parameters = { info.Password } }); await SendMessageToServerAsync(new IrcMessage { Command = "NICK", Parameters = { info.Nickname } }); await SendMessageToServerAsync(new IrcMessage { Command = "USER", Parameters = { info.Username, "none", "none", info.RealName } }); }
/// <summary> /// Handles a successful connection to an IRC server. Completes the /// connection by sending registration information. /// </summary> /// <param name="info">The registration info used to register with the server</param> internal virtual async Task HandleConnectionAsync(RegistrationInformation info) { _clientStream = _client.GetStream(); _reader = new StreamReader(_clientStream, Encoding.Default); IsConnected = true; await SendRegistrationInfoAsync(info); BeginReadAsync(); }