private void HandleClientConnected(IrcRegistrationInfo regInfo) { DebugUtilities.WriteEvent(string.Format("Connected to server at '{0}'.", ((IPEndPoint)this.socket.RemoteEndPoint).Address)); if (regInfo.Password != null) // Authenticate with server using password. SendMessagePassword(regInfo.Password); // Check if client is registering as service or normal user. if (regInfo is IrcServiceRegistrationInfo) { // Register client as service. var serviceRegInfo = (IrcServiceRegistrationInfo)regInfo; SendMessageService(serviceRegInfo.NickName, serviceRegInfo.Distribution, serviceRegInfo.Description); this.localUser = new IrcLocalUser(serviceRegInfo.NickName, serviceRegInfo.Distribution, serviceRegInfo.Description); } else { // Register client as normal user. var userRegInfo = (IrcUserRegistrationInfo)regInfo; SendMessageNick(userRegInfo.NickName); SendMessageUser(userRegInfo.UserName, GetNumericUserMode(userRegInfo.UserModes), userRegInfo.RealName); this.localUser = new IrcLocalUser(userRegInfo.NickName, userRegInfo.UserName, userRegInfo.RealName, userRegInfo.UserModes); } this.localUser.Client = this; // Add local user to list of known users. lock (((ICollection)this.usersReadOnly).SyncRoot) this.users.Add(this.localUser); OnConnected(new EventArgs()); }
private void Reconnect() { if (IrcClient != null) { IrcClient.Disconnect(); IrcClient = null; } IrcClient = new IrcClient(); IrcClient.Connected += IrcClient_Connected; IrcClient.ProtocolError += IrcClient_ProtocolError; IrcClient.Error += IrcClient_Error; IrcClient.Disconnected += IrcClient_Disconnected; IrcClient.RawMessageReceived += IrcClient_RawMessageReceived; IrcClient.ConnectFailed += IrcClient_ConnectFailed; Random rnd = new Random(); string s = "justinfan" + rnd.Next(100000000); regInfo = new IrcUserRegistrationInfo() { NickName = s, UserName = s, Password = "******", RealName = s }; Header = "http://twitch.tv, Подключаемся к " + StreamerNick; if (!string.IsNullOrEmpty(_directAdress)) { string[] dat = _directAdress.Split(':'); try { int port = int.Parse(dat[1]); IrcClient.Connect(dat[0], port, false, regInfo); } catch { Header = "http://twitch.tv, Ошибка " + StreamerNick; } } else { IrcClient.Connect(StreamerNick + ".jtvirc.com", 6667, false, regInfo); } }
/// <summary> /// Connects asynchronously to the specified server. /// </summary> /// <param name="remoteEndPoint">The network endpoint (IP address and port) of the server to which to connect. /// </param> /// <param name="useSsl"><see langword="true"/> to connect to the server via SSL; <see langword="false"/>, /// otherwise</param> /// <param name="registrationInfo">The information used for registering the client. /// The type of the object may be either <see cref="IrcUserRegistrationInfo"/> or /// <see cref="IrcServiceRegistrationInfo"/>.</param> /// <exception cref="ArgumentNullException"><paramref name="registrationInfo"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"><paramref name="registrationInfo"/> does not specify valid registration /// information.</exception> /// <exception cref="ObjectDisposedException">The current instance has already been disposed.</exception> public void Connect(EndPoint remoteEndPoint, bool useSsl, IrcRegistrationInfo registrationInfo) { CheckDisposed(); if (registrationInfo == null) throw new ArgumentNullException("registrationInfo"); CheckRegistrationInfo(registrationInfo, "registrationInfo"); ResetState(); // Connect socket to remote host. ConnectAsync(remoteEndPoint, Tuple.Create(useSsl, string.Empty, registrationInfo)); HandleClientConnecting(); }
private void CheckRegistrationInfo(IrcRegistrationInfo registrationInfo, string registrationInfoParamName) { // Check that given registration info is valid. if (registrationInfo is IrcUserRegistrationInfo) { if (registrationInfo.NickName == null || ((IrcUserRegistrationInfo)registrationInfo).UserName == null) throw new ArgumentException(Properties.Resources.MessageInvalidUserRegistrationInfo, registrationInfoParamName); } else if (registrationInfo is IrcServiceRegistrationInfo) { if (registrationInfo.NickName == null || ((IrcServiceRegistrationInfo)registrationInfo).Description == null) throw new ArgumentException(Properties.Resources.MessageInvalidServiceRegistrationInfo, registrationInfoParamName); } else { throw new ArgumentException(Properties.Resources.MessageInvalidRegistrationInfoObject, registrationInfoParamName); } }
/// <inheritdoc cref="Connect(EndPoint, bool, IrcRegistrationInfo)"/> /// <param name="address">An IP addresses that designates the remote host.</param> /// <param name="port">The port number of the remote host.</param> public void Connect(IPAddress address, int port, bool useSsl, IrcRegistrationInfo registrationInfo) { CheckDisposed(); if (registrationInfo == null) throw new ArgumentNullException("registrationInfo"); Connect(new IPEndPoint(address, port), useSsl, registrationInfo); }
/// <inheritdoc cref="Connect(IPAddress, int, bool, IrcRegistrationInfo)"/> public void Connect(IPAddress address, bool useSsl, IrcRegistrationInfo registrationInfo) { CheckDisposed(); if (registrationInfo == null) throw new ArgumentNullException("registrationInfo"); Connect(address, defaultPort, useSsl, registrationInfo); }
/// <inheritdoc cref="Connect(EndPoint, bool, IrcRegistrationInfo)"/> /// <param name="hostName">The name of the remote host.</param> /// <param name="port">The port number of the remote host.</param> public void Connect(string hostName, int port, bool useSsl, IrcRegistrationInfo registrationInfo) { CheckDisposed(); if (registrationInfo == null) throw new ArgumentNullException("registrationInfo"); Connect(new DnsEndPoint(hostName, port), useSsl, registrationInfo); }
/// <inheritdoc cref="Connect(string, int, bool, IrcRegistrationInfo)"/> public void Connect(string hostName, bool useSsl, IrcRegistrationInfo registrationInfo) { CheckDisposed(); if (registrationInfo == null) throw new ArgumentNullException("registrationInfo"); Connect(hostName, defaultPort, useSsl, registrationInfo); }
/// <inheritdoc cref="Connect(string, int, bool, IrcRegistrationInfo)"/> /// <summary> /// Connects to a server using the specified URL and user information. /// </summary> public void Connect(Uri url, IrcRegistrationInfo registrationInfo) { CheckDisposed(); if (registrationInfo == null) throw new ArgumentNullException("registrationInfo"); // Check URL scheme and decide whether to use SSL. bool useSsl; if (url.Scheme == "irc") useSsl = false; else if (url.Scheme == "ircs") useSsl = true; else throw new ArgumentException(string.Format(Properties.Resources.MessageInvalidUrlScheme, url.Scheme), "url"); Connect(url.Host, url.Port == -1 ? defaultPort : url.Port, useSsl, registrationInfo); }