/// <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); }
public void Connect(string serverString, IrcRegistrationInfo registrationInfo) { _logger.Info("[BALLOUBOT] Attempting to connect"); using (var registeredEvent = new ManualResetEventSlim(false)) { using (var connectedEvent = new ManualResetEventSlim(false)) { Client.Connected += (sender, args) => connectedEvent.Set(); Client.Registered += (sender, args) => registeredEvent.Set(); Client.Connect(serverString, false, registrationInfo); if (!connectedEvent.Wait(1000)) { Client.Dispose(); throw new Exception("[BALLOUBOT] Could not connect."); } } if (!registeredEvent.Wait(10000)) { Client.Dispose(); throw new Exception("[BALLOUBOT] Could not register."); } } IsConnected = true; _logger.Info("[BALLOUBOT] Connected and Registered."); }
protected override void HandleClientConnected(IrcRegistrationInfo regInfo) { DebugUtilities.WriteEvent(string.Format("Connected to server at '{0}'.", ((IPEndPoint)this.socket.RemoteEndPoint).Address)); base.HandleClientConnected(regInfo); }
protected void Connect(string server, IrcRegistrationInfo registrationInfo) { // Create new IRC client and connect to given server. var client = new StandardIrcClient(); client.FloodPreventer = new IrcStandardFloodPreventer(4, 2000); client.Connected += IrcClient_Connected; client.Disconnected += IrcClient_Disconnected; client.Registered += IrcClient_Registered; // Wait until connection has succeeded or timed out. using (var connectedEvent = new ManualResetEventSlim(false)) { client.Connected += (sender2, e2) => connectedEvent.Set(); client.Connect(server, false, registrationInfo); if (!connectedEvent.Wait(10000)) { client.Dispose(); ConsoleUtilities.WriteError("Connection to '{0}' timed out.", server); return; } } // Add new client to collection. this.allClients.Add(client); Console.Out.WriteLine("Now connected to '{0}'.", server); }
/// <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) { Connect(registrationInfo); // Connect socket to remote host. ConnectAsync(remoteEndPoint, Tuple.Create(useSsl, string.Empty, registrationInfo)); HandleClientConnecting(); }
/// <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(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(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="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(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"); } #if NETSTANDARD1_5 var dnsTask = Dns.GetHostAddressesAsync(hostName); var addresses = dnsTask.Result; Connect(new IPEndPoint(addresses[0], port), useSsl, registrationInfo); #else Connect(new DnsEndPoint(hostName, port), useSsl, registrationInfo); #endif }
/// <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(); }
/// <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); }
/// <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); }
/// <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(); }
/// <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(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); }
protected void Connect(string server, IrcRegistrationInfo registrationInfo) { var client = new IrcClient(); client.FloodPreventer = new IrcStandardFloodPreventer(4, 2000); client.Connected += IrcClient_Connected; client.Disconnected += IrcClient_Disconnected; client.Registered += IrcClient_Registered; client.PingReceived += IrcClient_PingReceived; client.NetworkInformationReceived += IrcClient_OnNetworkInformationReceived; client.RawMessageReceived += IrcClient_OnRawMessageReceived; client.RawMessageSent += IrcClient_OnRawMessageSent; clientCount++; // Wait until connection has succeeded or timed out. using (var connectedEvent = new ManualResetEventSlim(false)) { client.Connected += (sender2, e2) => connectedEvent.Set(); client.Connect(server, false, registrationInfo); // client.Id = clientCount++; if (!connectedEvent.Wait(10000)) { client.Dispose(); Console.WriteLine("Connection to '{0}' timed out.", server); return; } } // Add new client to collection this.allClients.Add(client); Console.Out.WriteLine("Now connected to '{0}'.", server); }
protected 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); } }
private void HandleClientConnected(IrcRegistrationInfo regInfo) { Logger.WriteLine("Connected to server at '{0}'.", TraceEventType.Verbose,((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()); }
protected void Connect(IrcRegistrationInfo registrationInfo) { CheckDisposed(); if (registrationInfo == null) throw new ArgumentNullException("registrationInfo"); CheckRegistrationInfo(registrationInfo, "registrationInfo"); ResetState(); }
protected 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(ResourceLoader.GetForCurrentView("IrcDotNet/Resources").GetString("MessageInvalidUserRegistrationInfo"), registrationInfoParamName); } else if (registrationInfo is IrcServiceRegistrationInfo) { if (registrationInfo.NickName == null || ((IrcServiceRegistrationInfo)registrationInfo).Description == null) throw new ArgumentException(ResourceLoader.GetForCurrentView("IrcDotNet/Resources").GetString("MessageInvalidServiceRegistrationInfo"), registrationInfoParamName); } else { throw new ArgumentException(ResourceLoader.GetForCurrentView("IrcDotNet/Resources").GetString("MessageInvalidRegistrationInfoObject"), registrationInfoParamName); } }
/// <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); }
public override void Connect(EndPoint remoteEndPoint, bool useSsl, IrcRegistrationInfo registrationInfo) { registrationInfo.NickName = registrationInfo.NickName.ToLower(); base.Connect(remoteEndPoint, 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"); IPHostEntry host; host = Dns.GetHostEntry(hostName); Debug.Assert(host.AddressList.Length > 0); foreach (IPAddress ad in host.AddressList) { Console.WriteLine(ad.ToString()); } Connect(host.AddressList[0], port, useSsl, registrationInfo); }
protected virtual void HandleClientConnected(IrcRegistrationInfo regInfo) { 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()); }
/// <summary> /// </summary> /// <param name="server"> /// </param> /// <param name="registrationInfo"> /// </param> protected void Connect(string server, IrcRegistrationInfo registrationInfo) { // Create new IRC client and connect to given server. var client = new IrcClient(); client.FloodPreventer = new IrcStandardFloodPreventer(4, 2000); client.Connected += this.IrcClient_Connected; client.Disconnected += this.IrcClient_Disconnected; client.Registered += this.IrcClient_Registered; client.ProtocolError += this.IrcClient_ProtocolError; client.ChannelListReceived += this.client_ChannelListReceived; // Wait until connection has succeeded or timed out. using (var connectedEvent = new ManualResetEventSlim(false)) { client.Connected += (sender2, e2) => connectedEvent.Set(); client.Connect(server, false, registrationInfo); if (!connectedEvent.Wait(10000)) { client.Dispose(); ConsoleUtilities.WriteError("Connection to '{0}' timed out.", server); return; } } // Add new client to collection. this.allClients.Add(client); Console.Out.WriteLine("Now connected to '{0}'.", server); }
public void Connect(string server, IrcRegistrationInfo registrationInfo) { // Create new IRC client and connect to given server. var client = new StandardIrcClient(); client.FloodPreventer = new IrcStandardFloodPreventer(2, 5000); client.Connected += IrcClient_Connected; client.Disconnected += IrcClient_Disconnected; client.Registered += IrcClient_Registered; // Wait until connection has succeeded or timed out. using (var connectedEvent = new ManualResetEventSlim(false)) { client.Connected += (sender2, e2) => connectedEvent.Set(); client.Connect(server, false, registrationInfo); if (!connectedEvent.Wait(50000)) { client.Dispose(); return; } } // Add new client to collection. this.allClients.Add(client); Console.Out.WriteLine("Now connected to '{0}'.", server); }